Skip to content

Commit 346272c

Browse files
fix(firestore)!: DocumentSnapshot.exists() should be a method not a property (#8483)
Make DataSnapshot.exists a method from property BREAKING CHANGE: alter all use of DocumentSnapshot `exists` to `exists()` - should be a method not a property
1 parent 3785690 commit 346272c

File tree

8 files changed

+42
-42
lines changed

8 files changed

+42
-42
lines changed

packages/firestore/e2e/CollectionReference/add.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('firestore.collection().add()', function () {
4949
should.equal(docRef.constructor.name, 'FirestoreDocumentReference');
5050
const docSnap = await docRef.get();
5151
docSnap.data().should.eql(jet.contextify(data));
52-
docSnap.exists.should.eql(true);
52+
docSnap.exists().should.eql(true);
5353
await docRef.delete();
5454
});
5555
});
@@ -75,7 +75,7 @@ describe('firestore.collection().add()', function () {
7575
should.equal(docRef.constructor.name, 'FirestoreDocumentReference');
7676
const docSnap = await getDoc(docRef);
7777
docSnap.data().should.eql(jet.contextify(data));
78-
docSnap.exists.should.eql(true);
78+
docSnap.exists().should.eql(true);
7979
await deleteDoc(docRef);
8080
});
8181
});

packages/firestore/e2e/DocumentReference/delete.e2e.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ describe('firestore.doc().delete()', function () {
3838
await ref.set({ foo: 'bar' });
3939
const snapshot1 = await ref.get();
4040
snapshot1.id.should.equal('deleteme');
41-
snapshot1.exists.should.equal(true);
41+
snapshot1.exists().should.equal(true);
4242
await ref.delete();
4343
const snapshot2 = await ref.get();
4444
snapshot2.id.should.equal('deleteme');
45-
snapshot2.exists.should.equal(false);
45+
snapshot2.exists().should.equal(false);
4646
});
4747
});
4848

@@ -54,11 +54,11 @@ describe('firestore.doc().delete()', function () {
5454
await setDoc(ref, { foo: 'bar' });
5555
const snapshot1 = await getDoc(ref);
5656
snapshot1.id.should.equal('deleteme');
57-
snapshot1.exists.should.equal(true);
57+
snapshot1.exists().should.equal(true);
5858
await deleteDoc(ref);
5959
const snapshot2 = await getDoc(ref);
6060
snapshot2.id.should.equal('deleteme');
61-
snapshot2.exists.should.equal(false);
61+
snapshot2.exists().should.equal(false);
6262
});
6363
});
6464
});

packages/firestore/e2e/DocumentSnapshot/properties.e2e.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ describe('firestore().doc() -> snapshot', function () {
4040
const snapshot1 = await ref1.get();
4141
const snapshot2 = await ref2.get();
4242

43-
snapshot1.exists.should.equal(true);
44-
snapshot2.exists.should.equal(false);
43+
snapshot1.exists().should.equal(true);
44+
snapshot2.exists().should.equal(false);
4545
await ref1.delete();
4646
});
4747

@@ -87,8 +87,8 @@ describe('firestore().doc() -> snapshot', function () {
8787
const snapshot1 = await getDoc(ref1);
8888
const snapshot2 = await getDoc(ref2);
8989

90-
snapshot1.exists.should.equal(true);
91-
snapshot2.exists.should.equal(false);
90+
snapshot1.exists().should.equal(true);
91+
snapshot2.exists().should.equal(false);
9292
await deleteDoc(ref1);
9393
});
9494

packages/firestore/e2e/SecondDatabase/second.Transation.e2e.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('Second Database', function () {
114114
await firestore.runTransaction(async t => {
115115
const docSnapshot = await t.get(docRef);
116116
docSnapshot.constructor.name.should.eql('FirestoreDocumentSnapshot');
117-
docSnapshot.exists.should.eql(true);
117+
docSnapshot.exists().should.eql(true);
118118
docSnapshot.id.should.eql('get-delete');
119119

120120
t.delete(docRef);
@@ -148,10 +148,10 @@ describe('Second Database', function () {
148148
});
149149

150150
const snapshot1 = await docRef1.get();
151-
snapshot1.exists.should.eql(false);
151+
snapshot1.exists().should.eql(false);
152152

153153
const snapshot2 = await docRef2.get();
154-
snapshot2.exists.should.eql(false);
154+
snapshot2.exists().should.eql(false);
155155
});
156156
});
157157

@@ -210,11 +210,11 @@ describe('Second Database', function () {
210210
};
211211

212212
const snapshot1 = await docRef1.get();
213-
snapshot1.exists.should.eql(true);
213+
snapshot1.exists().should.eql(true);
214214
snapshot1.data().should.eql(jet.contextify(expected));
215215

216216
const snapshot2 = await docRef2.get();
217-
snapshot2.exists.should.eql(true);
217+
snapshot2.exists().should.eql(true);
218218
snapshot2.data().should.eql(jet.contextify(expected));
219219
});
220220
});
@@ -487,7 +487,7 @@ describe('Second Database', function () {
487487
await runTransaction(db, async t => {
488488
const docSnapshot = await t.get(docRef);
489489
docSnapshot.constructor.name.should.eql('FirestoreDocumentSnapshot');
490-
docSnapshot.exists.should.eql(true);
490+
docSnapshot.exists().should.eql(true);
491491
docSnapshot.id.should.eql('get-delete');
492492

493493
t.delete(docRef);
@@ -524,10 +524,10 @@ describe('Second Database', function () {
524524
});
525525

526526
const snapshot1 = await getDoc(docRef1);
527-
snapshot1.exists.should.eql(false);
527+
snapshot1.exists().should.eql(false);
528528

529529
const snapshot2 = await getDoc(docRef2);
530-
snapshot2.exists.should.eql(false);
530+
snapshot2.exists().should.eql(false);
531531
});
532532
});
533533

@@ -591,11 +591,11 @@ describe('Second Database', function () {
591591
};
592592

593593
const snapshot1 = await getDoc(docRef1);
594-
snapshot1.exists.should.eql(true);
594+
snapshot1.exists().should.eql(true);
595595
snapshot1.data().should.eql(jet.contextify(expected));
596596

597597
const snapshot2 = await getDoc(docRef2);
598-
snapshot2.exists.should.eql(true);
598+
snapshot2.exists().should.eql(true);
599599
snapshot2.data().should.eql(jet.contextify(expected));
600600
});
601601
});

packages/firestore/e2e/Transaction.e2e.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('firestore.Transaction', function () {
108108
await firebase.firestore().runTransaction(async t => {
109109
const docSnapshot = await t.get(docRef);
110110
docSnapshot.constructor.name.should.eql('FirestoreDocumentSnapshot');
111-
docSnapshot.exists.should.eql(true);
111+
docSnapshot.exists().should.eql(true);
112112
docSnapshot.id.should.eql('get-delete');
113113

114114
t.delete(docRef);
@@ -146,10 +146,10 @@ describe('firestore.Transaction', function () {
146146
});
147147

148148
const snapshot1 = await docRef1.get();
149-
snapshot1.exists.should.eql(false);
149+
snapshot1.exists().should.eql(false);
150150

151151
const snapshot2 = await docRef2.get();
152-
snapshot2.exists.should.eql(false);
152+
snapshot2.exists().should.eql(false);
153153
});
154154
});
155155

@@ -212,11 +212,11 @@ describe('firestore.Transaction', function () {
212212
};
213213

214214
const snapshot1 = await docRef1.get();
215-
snapshot1.exists.should.eql(true);
215+
snapshot1.exists().should.eql(true);
216216
snapshot1.data().should.eql(jet.contextify(expected));
217217

218218
const snapshot2 = await docRef2.get();
219-
snapshot2.exists.should.eql(true);
219+
snapshot2.exists().should.eql(true);
220220
snapshot2.data().should.eql(jet.contextify(expected));
221221
});
222222
});
@@ -484,7 +484,7 @@ describe('firestore.Transaction', function () {
484484
await runTransaction(db, async t => {
485485
const docSnapshot = await t.get(docRef);
486486
docSnapshot.constructor.name.should.eql('FirestoreDocumentSnapshot');
487-
docSnapshot.exists.should.eql(true);
487+
docSnapshot.exists().should.eql(true);
488488
docSnapshot.id.should.eql('get-delete');
489489

490490
t.delete(docRef);
@@ -521,10 +521,10 @@ describe('firestore.Transaction', function () {
521521
});
522522

523523
const snapshot1 = await getDoc(docRef1);
524-
snapshot1.exists.should.eql(false);
524+
snapshot1.exists().should.eql(false);
525525

526526
const snapshot2 = await getDoc(docRef2);
527-
snapshot2.exists.should.eql(false);
527+
snapshot2.exists().should.eql(false);
528528
});
529529
});
530530

@@ -588,11 +588,11 @@ describe('firestore.Transaction', function () {
588588
};
589589

590590
const snapshot1 = await getDoc(docRef1);
591-
snapshot1.exists.should.eql(true);
591+
snapshot1.exists().should.eql(true);
592592
snapshot1.data().should.eql(jet.contextify(expected));
593593

594594
const snapshot2 = await getDoc(docRef2);
595-
snapshot2.exists.should.eql(true);
595+
snapshot2.exists().should.eql(true);
596596
snapshot2.data().should.eql(jet.contextify(expected));
597597
});
598598
});

packages/firestore/e2e/WriteBatch/commit.e2e.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ describe('firestore.WriteBatch.commit()', function () {
181181

182182
const [lDoc, nycDoc, sDoc] = await Promise.all([lRef.get(), nycRef.get(), sfRef.get()]);
183183

184-
lDoc.exists.should.be.False();
185-
nycDoc.exists.should.be.False();
186-
sDoc.exists.should.be.False();
184+
lDoc.exists().should.be.False();
185+
nycDoc.exists().should.be.False();
186+
sDoc.exists().should.be.False();
187187
});
188188

189189
it('should update & commit', async function () {
@@ -376,9 +376,9 @@ describe('firestore.WriteBatch.commit()', function () {
376376

377377
const [lDoc, nycDoc, sDoc] = await Promise.all([getDoc(lRef), getDoc(nycRef), getDoc(sfRef)]);
378378

379-
lDoc.exists.should.be.False();
380-
nycDoc.exists.should.be.False();
381-
sDoc.exists.should.be.False();
379+
lDoc.exists().should.be.False();
380+
nycDoc.exists().should.be.False();
381+
sDoc.exists().should.be.False();
382382
});
383383

384384
it('should update & commit', async function () {

packages/firestore/lib/FirestoreDocumentSnapshot.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ export default class FirestoreDocumentSnapshot {
3333
this._exists = nativeData.exists;
3434
}
3535

36-
get exists() {
37-
return this._exists;
38-
}
39-
4036
get id() {
4137
return this._ref.id;
4238
}
@@ -49,6 +45,10 @@ export default class FirestoreDocumentSnapshot {
4945
return this._ref;
5046
}
5147

48+
exists() {
49+
return this._exists;
50+
}
51+
5252
data() {
5353
// TODO: ehesp: Figure out how to handle this.
5454
// const snapshotOptions = {};
@@ -114,7 +114,7 @@ export default class FirestoreDocumentSnapshot {
114114
}
115115

116116
if (
117-
this.exists !== other.exists ||
117+
this.exists() !== other.exists() ||
118118
!this.metadata.isEqual(other.metadata) ||
119119
!this.ref.isEqual(other.ref)
120120
) {

packages/firestore/lib/FirestoreQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class FirestoreQuery {
6565

6666
const documentSnapshot = docOrField;
6767

68-
if (!documentSnapshot.exists) {
68+
if (!documentSnapshot.exists()) {
6969
throw new Error(
7070
`firebase.firestore().collection().${cursor}(*) Can't use a DocumentSnapshot that doesn't exist.`,
7171
);

0 commit comments

Comments
 (0)