From 1fc15a1a1ed73f72ba1ef011b9d9016d5aee9d9a Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 2 Oct 2018 11:57:12 -0700 Subject: [PATCH 1/4] Deprecate getCollections in favor of listCollections --- dev/src/index.js | 24 ++++++++++++++++++++++-- dev/src/reference.ts | 25 +++++++++++++++++++++++-- dev/system-test/firestore.ts | 4 ++-- dev/test/document.js | 3 ++- dev/test/index.js | 3 ++- dev/test/typescript.ts | 4 ++++ types/firestore.d.ts | 19 +++++++++++++++++++ 7 files changed, 74 insertions(+), 8 deletions(-) diff --git a/dev/src/index.js b/dev/src/index.js index 9da190fb1..fe9ebabca 100644 --- a/dev/src/index.js +++ b/dev/src/index.js @@ -591,6 +591,27 @@ class Firestore { * with an array of CollectionReferences. * * @example + * firestore.listCollections().then(collections => { + * for (let collection of collections) { + * console.log(`Found collection with id: ${collection.id}`); + * } + * }); + */ + listCollections() { + let 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. + * + * @example * firestore.getCollections().then(collections => { * for (let collection of collections) { * console.log(`Found collection with id: ${collection.id}`); @@ -598,8 +619,7 @@ class Firestore { * }); */ 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 f01092948..c4d6c44f4 100644 --- a/dev/src/reference.ts +++ b/dev/src/reference.ts @@ -256,13 +256,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()) @@ -281,6 +281,27 @@ 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. + * + * @example + * let documentRef = firestore.doc('col/doc'); + * + * documentRef.getCollections().then(collections => { + * for (let collection of collections) { + * console.log(`Found subcollection with id: ${collection.id}`); + * } + * }); + */ + 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 dc77d7d80..d7de09f2c 100644 --- a/dev/system-test/firestore.ts +++ b/dev/system-test/firestore.ts @@ -426,7 +426,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<{}>[] = []; @@ -436,7 +436,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..99a42f8ee 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 From bc7b1619e434341ef456f07cf1499103e7a95966 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 2 Oct 2018 12:30:59 -0700 Subject: [PATCH 2/4] Add dots to API doc --- dev/src/index.js | 2 +- dev/src/reference.ts | 2 +- types/firestore.d.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/src/index.js b/dev/src/index.js index fe9ebabca..380d936c5 100644 --- a/dev/src/index.js +++ b/dev/src/index.js @@ -606,7 +606,7 @@ class Firestore { * Fetches the root collections that are associated with this Firestore * database. * - * @deprecated Use `listCollections()`. + * @deprecated Use `.listCollections()`. * * @returns {Promise.>} A Promise that resolves * with an array of CollectionReferences. diff --git a/dev/src/reference.ts b/dev/src/reference.ts index c4d6c44f4..a73829e79 100644 --- a/dev/src/reference.ts +++ b/dev/src/reference.ts @@ -284,7 +284,7 @@ export class DocumentReference { /** * Fetches the subcollections that are direct children of this document. * - * @deprecated Use `listCollections()`. + * @deprecated Use `.listCollections()`. * * @returns {Promise.>} A Promise that resolves * with an array of CollectionReferences. diff --git a/types/firestore.d.ts b/types/firestore.d.ts index 99a42f8ee..a55a23067 100644 --- a/types/firestore.d.ts +++ b/types/firestore.d.ts @@ -135,7 +135,7 @@ declare namespace FirebaseFirestore { * Fetches the root collections that are associated with this Firestore * database. * - * @deprecated Use `listCollections()`. + * @deprecated Use `.listCollections()`. * * @returns A Promise that resolves with an array of CollectionReferences. */ @@ -511,7 +511,7 @@ declare namespace FirebaseFirestore { /** * Fetches the subcollections that are direct children of this document. * - * @deprecated Use `listCollections()`. + * @deprecated Use `.listCollections()`. * * @returns A Promise that resolves with an array of CollectionReferences. */ From 89029eb4db2338b9f3f154b7b13e2f2b0ddb1dec Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 2 Oct 2018 12:33:43 -0700 Subject: [PATCH 3/4] Add dots to API doc --- dev/src/index.js | 7 ------- dev/src/reference.ts | 9 --------- 2 files changed, 16 deletions(-) diff --git a/dev/src/index.js b/dev/src/index.js index 380d936c5..4706c7eb9 100644 --- a/dev/src/index.js +++ b/dev/src/index.js @@ -610,13 +610,6 @@ class Firestore { * * @returns {Promise.>} A Promise that resolves * with an array of CollectionReferences. - * - * @example - * firestore.getCollections().then(collections => { - * for (let collection of collections) { - * console.log(`Found collection with id: ${collection.id}`); - * } - * }); */ getCollections() { return this.listCollections(); diff --git a/dev/src/reference.ts b/dev/src/reference.ts index 46a888952..293eb05ab 100644 --- a/dev/src/reference.ts +++ b/dev/src/reference.ts @@ -286,15 +286,6 @@ export class DocumentReference { * * @returns {Promise.>} A Promise that resolves * with an array of CollectionReferences. - * - * @example - * let documentRef = firestore.doc('col/doc'); - * - * documentRef.getCollections().then(collections => { - * for (let collection of collections) { - * console.log(`Found subcollection with id: ${collection.id}`); - * } - * }); */ getCollections(): Promise { return this.listCollections(); From 2f9ddc346e431ab8d0e222d5915eb7efbddb87fc Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 2 Oct 2018 12:35:19 -0700 Subject: [PATCH 4/4] Use const instead of let --- dev/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/src/index.js b/dev/src/index.js index 4706c7eb9..12bd64d5e 100644 --- a/dev/src/index.js +++ b/dev/src/index.js @@ -598,7 +598,7 @@ class Firestore { * }); */ listCollections() { - let rootDocument = new DocumentReference(this, this._referencePath); + const rootDocument = new DocumentReference(this, this._referencePath); return rootDocument.listCollections(); }