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

Return Firestore Classic types from Transaction API #4233

Merged
merged 4 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/slimy-mugs-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

Fixes an issue in the Transaction API that caused the SDK to return invalid DocumentReferences through `DocumentSnapshot.data()` calls.
18 changes: 17 additions & 1 deletion packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,14 @@ export function setLogLevel(level: PublicLogLevel): void {
export class Transaction
extends Compat<ExpTransaction>
implements PublicTransaction {
private _userDataWriter: UserDataWriter;

constructor(
private readonly _firestore: Firestore,
delegate: ExpTransaction
) {
super(delegate);
this._userDataWriter = new UserDataWriter(_firestore);
}

get<T>(
Expand All @@ -419,7 +422,20 @@ export class Transaction
const ref = castReference(documentRef);
return this._delegate
.get(ref)
.then(result => new DocumentSnapshot(this._firestore, result));
.then(
result =>
new DocumentSnapshot(
this._firestore,
new ExpDocumentSnapshot<T>(
this._firestore._delegate,
this._userDataWriter,
result._key,
result._document,
result.metadata,
ref._converter
)
)
);
}

set<T>(
Expand Down
6 changes: 6 additions & 0 deletions packages/firestore/test/integration/api/type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ apiDescribe('Firestore', (persistence: boolean) => {
let docSnapshot = await doc.get();
expect(docSnapshot.data()).to.deep.equal(data);

// Validate that the transaction API returns the same types
await db.runTransaction(async transaction => {
docSnapshot = await transaction.get(doc);
expect(docSnapshot.data()).to.deep.equal(data);
});

if (validateSnapshots) {
let querySnapshot = await collection.get();
docSnapshot = querySnapshot.docs[0];
Expand Down