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

Deprecate getCollections in favor of listCollections #373

Merged
merged 8 commits into from
Oct 2, 2018
19 changes: 16 additions & 3 deletions dev/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<Array.<CollectionReference>>} A Promise that resolves
* with an array of CollectionReferences.
*/
getCollections() {
let rootDocument = new DocumentReference(this, this._referencePath);
return rootDocument.getCollections();
return this.listCollections();
}

/**
Expand Down
16 changes: 14 additions & 2 deletions dev/src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CollectionReference[]> {
listCollections(): Promise<CollectionReference[]> {
const request = {parent: this._path.formattedName};

return this._firestore.request('listCollectionIds', request, requestTag())
Expand All @@ -279,6 +279,18 @@ export class DocumentReference {
});
}

/**
* Fetches the subcollections that are direct children of this document.
*
* @deprecated Use `.listCollections()`.
*
* @returns {Promise.<Array.<CollectionReference>>} A Promise that resolves
* with an array of CollectionReferences.
*/
getCollections(): Promise<CollectionReference[]> {
return this.listCollections();
}

/**
* Create a document with the provided object values. This will fail the write
* if a document exists at its location.
Expand Down
4 changes: 2 additions & 2 deletions dev/system-test/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<{}>[] = [];

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion dev/test/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion dev/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions dev/test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ xdescribe('firestore.d.ts', function() {
});
firestore.getCollections().then((collections:CollectionReference[]) => {
});
firestore.listCollections().then((collections:CollectionReference[]) => {
});
const transactionResult: Promise<string> = firestore.runTransaction(
(updateFunction: Transaction) => {
return Promise.resolve("string")
Expand Down Expand Up @@ -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(
Expand Down
19 changes: 19 additions & 0 deletions types/firestore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CollectionReference[]>;

/**
* Fetches the root collections that are associated with this Firestore
* database.
*
* @returns A Promise that resolves with an array of CollectionReferences.
*/
listCollections() : Promise<CollectionReference[]>;

/**
* Executes the given updateFunction and commits the changes applied within
* the transaction.
Expand Down Expand Up @@ -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<CollectionReference[]>;

/**
* Fetches the subcollections that are direct children of this document.
*
* @returns A Promise that resolves with an array of CollectionReferences.
*/
listCollections() : Promise<CollectionReference[]>;

/**
* Creates a document referred to by this `DocumentReference` with the
* provided object values. The write fails if the document already exists
Expand Down