Skip to content

Commit

Permalink
Ensure a snapshot exists before returning it (#11)
Browse files Browse the repository at this point in the history
* We need to ensure a snapshot exists

* Remove errant change in function signature

* Addressing PR feedback
  • Loading branch information
brianmichel authored Nov 27, 2023
1 parent 5cef2f9 commit a960f53
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/FirebaseFirestore/DocumentReference+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extension DocumentReference {
future.Wait(firebase.FutureBase.kWaitTimeoutInfinite)
}

guard snapshot.pointee.exists else { return nil }
return snapshot.pointee.is_valid() ? snapshot.pointee : nil
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/FirebaseFirestore/DocumentSnapshot+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ extension DocumentSnapshot {
swift_firebase.swift_cxx_shims.firebase.firestore.snapshot_reference(self)
}

public var exists: Bool {
swift_firebase.swift_cxx_shims.firebase.firestore.snapshot_exists(self)
}

public func data(with behavior: ServerTimestampBehavior) -> [String: Any]? {
let data = swift_firebase.swift_cxx_shims.firebase.firestore.snapshot_get_data_workaround(self, behavior)
return FirestoreDataConverter.value(workaround: data)
Expand Down
5 changes: 5 additions & 0 deletions Sources/firebase/include/FirebaseFirestore.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ snapshot_reference(const ::firebase::firestore::DocumentSnapshot snapshot) {
return snapshot.reference();
}

inline bool
snapshot_exists(const ::firebase::firestore::DocumentSnapshot &snapshot) {
return snapshot.exists();
}

#if SR69711
struct MapFieldValue_Workaround {
std::vector<std::string> keys;
Expand Down

0 comments on commit a960f53

Please sign in to comment.