@@ -21,6 +21,29 @@ import Foundation
2121
2222@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
2323struct PipelineListenOptions : Sendable , Equatable , Hashable {
24+ /// Defines how to handle server-generated timestamps that are not yet known locally
25+ /// during latency compensation.
26+ struct ServerTimestampBehavior : Sendable , Equatable , Hashable {
27+ /// The raw string value for the behavior, used for implementation and hashability.
28+ let rawValue : String
29+ /// Creates a new behavior with a private raw value.
30+ private init ( rawValue: String ) {
31+ self . rawValue = rawValue
32+ }
33+
34+ /// Fields dependent on server timestamps will be `nil` until the value is
35+ /// confirmed by the server.
36+ public static let none = ServerTimestampBehavior ( rawValue: " none " )
37+
38+ /// Fields dependent on server timestamps will receive a local, client-generated
39+ /// time estimate until the value is confirmed by the server.
40+ public static let estimate = ServerTimestampBehavior ( rawValue: " estimate " )
41+
42+ /// Fields dependent on server timestamps will hold the value from the last
43+ /// server-confirmed write until the new value is confirmed.
44+ public static let previous = ServerTimestampBehavior ( rawValue: " previous " )
45+ }
46+
2447 // MARK: - Stored Properties
2548
2649 /// The desired behavior for handling pending server timestamps.
@@ -46,31 +69,16 @@ struct PipelineListenOptions: Sendable, Equatable, Hashable {
4669 self . includeMetadataChanges = includeMetadataChanges
4770 self . source = source
4871 bridge = __PipelineListenOptionsBridge (
49- serverTimestampBehavior: PipelineListenOptions
50- . toRawValue ( servertimestamp: self . serverTimestamps ?? . none) ,
72+ serverTimestampBehavior: ( self . serverTimestamps ?? . none) . rawValue,
5173 includeMetadata: self . includeMetadataChanges ?? false ,
5274 source: self . source ?? ListenSource . default
5375 )
5476 }
55-
56- private static func toRawValue( servertimestamp: ServerTimestampBehavior ) -> String {
57- switch servertimestamp {
58- case . none:
59- return " none "
60- case . estimate:
61- return " estimate "
62- case . previous:
63- return " previous "
64- @unknown default :
65- fatalError ( " Unknown server timestamp behavior " )
66- }
67- }
6877}
6978
7079@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
7180struct RealtimePipeline : @unchecked Sendable {
7281 private var stages : [ Stage ]
73-
7482 let bridge : RealtimePipelineBridge
7583 let db : Firestore
7684
@@ -81,22 +89,18 @@ struct RealtimePipeline: @unchecked Sendable {
8189 }
8290
8391 struct Snapshot : Sendable {
84- /// An array of all the results in the `Pipeline.Snapshot `.
92+ /// An array of all the results in the `PipelineSnapshot `.
8593 let results_cache : [ PipelineResult ]
8694
8795 public let changes : [ PipelineResultChange ]
8896 public let metadata : SnapshotMetadata
8997
9098 let bridge : __RealtimePipelineSnapshotBridge
91- private var options : PipelineListenOptions
9299
93- init ( _ bridge: __RealtimePipelineSnapshotBridge ,
94- options: PipelineListenOptions ) {
100+ init ( _ bridge: __RealtimePipelineSnapshotBridge ) {
95101 self . bridge = bridge
96- self . options = options
97102 metadata = bridge. metadata
98- results_cache = self . bridge. results
99- . map { PipelineResult ( $0, options. serverTimestamps ?? . none) }
103+ results_cache = self . bridge. results. map { PipelineResult ( $0) }
100104 changes = self . bridge. changes. map { PipelineResultChange ( $0) }
101105 }
102106
@@ -109,17 +113,13 @@ struct RealtimePipeline: @unchecked Sendable {
109113 listener: @escaping ( RealtimePipeline . Snapshot ? , Error ? ) -> Void )
110114 -> ListenerRegistration {
111115 return bridge. addSnapshotListener ( options: options. bridge) { snapshotBridge, error in
112- if snapshotBridge != nil {
113- listener (
114- RealtimePipeline . Snapshot (
115- snapshotBridge!,
116- options: options
117- ) ,
118- error
119- )
120- } else {
121- listener ( nil , error)
122- }
116+ listener (
117+ RealtimePipeline . Snapshot (
118+ // TODO(pipeline): this needs to be fixed
119+ snapshotBridge!
120+ ) ,
121+ error
122+ )
123123 }
124124 }
125125
0 commit comments