Skip to content

Commit d264312

Browse files
authored
Add FirebaseSource to ReadDecodable extensions of DocumentReference (#12401)
1 parent 134e7f2 commit d264312

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Firestore/Swift/Source/Codable/DocumentReference+ReadDecodable.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ public extension DocumentReference {
4848
/// not yet been set to their final value are returned from the snapshot.
4949
/// - decoder: The decoder to use to convert the document. Defaults to use
5050
/// the default decoder.
51+
/// - source: Indicates whether the results should be fetched from the cache only
52+
/// (`Source.cache`), the server only (`Source.server`), or to attempt the
53+
/// server and fall back to the cache (`Source.default`).
5154
/// - completion: The closure to call when the document snapshot has been
5255
/// fetched and decoded.
5356
func getDocument<T: Decodable>(as type: T.Type,
5457
with serverTimestampBehavior: ServerTimestampBehavior =
5558
.none,
5659
decoder: Firestore.Decoder = .init(),
60+
source: FirestoreSource = .default,
5761
completion: @escaping (Result<T, Error>) -> Void) {
58-
getDocument { snapshot, error in
62+
getDocument(source: source) { snapshot, error in
5963
guard let snapshot = snapshot else {
6064
/**
6165
* Force unwrapping here is fine since this logic corresponds to the auto-synthesized
@@ -101,13 +105,17 @@ public extension DocumentReference {
101105
/// snapshot.
102106
/// - decoder: The decoder to use to convert the document. Defaults to use
103107
/// the default decoder.
108+
/// - source: Indicates whether the results should be fetched from the cache only
109+
/// (`Source.cache`), the server only (`Source.server`), or to attempt the
110+
/// server and fall back to the cache (`Source.default`).
104111
/// - Returns: This instance of the supplied `Decodable` type `T`.
105112
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
106113
func getDocument<T: Decodable>(as type: T.Type,
107114
with serverTimestampBehavior: ServerTimestampBehavior =
108115
.none,
109-
decoder: Firestore.Decoder = .init()) async throws -> T {
110-
let snapshot = try await getDocument()
116+
decoder: Firestore.Decoder = .init(),
117+
source: FirestoreSource = .default) async throws -> T {
118+
let snapshot = try await getDocument(source: source)
111119
return try snapshot.data(as: T.self,
112120
with: serverTimestampBehavior,
113121
decoder: decoder)

0 commit comments

Comments
 (0)