@@ -21,6 +21,29 @@ import Foundation
21
21
22
22
@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
23
23
struct 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
+
24
47
// MARK: - Stored Properties
25
48
26
49
/// The desired behavior for handling pending server timestamps.
@@ -46,31 +69,16 @@ struct PipelineListenOptions: Sendable, Equatable, Hashable {
46
69
self . includeMetadataChanges = includeMetadataChanges
47
70
self . source = source
48
71
bridge = __PipelineListenOptionsBridge (
49
- serverTimestampBehavior: PipelineListenOptions
50
- . toRawValue ( servertimestamp: self . serverTimestamps ?? . none) ,
72
+ serverTimestampBehavior: ( self . serverTimestamps ?? . none) . rawValue,
51
73
includeMetadata: self . includeMetadataChanges ?? false ,
52
74
source: self . source ?? ListenSource . default
53
75
)
54
76
}
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
- }
68
77
}
69
78
70
79
@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
71
80
struct RealtimePipeline : @unchecked Sendable {
72
81
private var stages : [ Stage ]
73
-
74
82
let bridge : RealtimePipelineBridge
75
83
let db : Firestore
76
84
@@ -81,22 +89,18 @@ struct RealtimePipeline: @unchecked Sendable {
81
89
}
82
90
83
91
struct Snapshot : Sendable {
84
- /// An array of all the results in the `Pipeline.Snapshot `.
92
+ /// An array of all the results in the `PipelineSnapshot `.
85
93
let results_cache : [ PipelineResult ]
86
94
87
95
public let changes : [ PipelineResultChange ]
88
96
public let metadata : SnapshotMetadata
89
97
90
98
let bridge : __RealtimePipelineSnapshotBridge
91
- private var options : PipelineListenOptions
92
99
93
- init ( _ bridge: __RealtimePipelineSnapshotBridge ,
94
- options: PipelineListenOptions ) {
100
+ init ( _ bridge: __RealtimePipelineSnapshotBridge ) {
95
101
self . bridge = bridge
96
- self . options = options
97
102
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) }
100
104
changes = self . bridge. changes. map { PipelineResultChange ( $0) }
101
105
}
102
106
@@ -109,17 +113,13 @@ struct RealtimePipeline: @unchecked Sendable {
109
113
listener: @escaping ( RealtimePipeline . Snapshot ? , Error ? ) -> Void )
110
114
-> ListenerRegistration {
111
115
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
+ )
123
123
}
124
124
}
125
125
0 commit comments