Skip to content

Commit 517fdcd

Browse files
Nick feedback
1 parent b1569e8 commit 517fdcd

File tree

12 files changed

+38
-86
lines changed

12 files changed

+38
-86
lines changed

Sources/Cache/ResultTree.swift

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414

1515
import Foundation
1616

17-
import FirebaseCore
18-
1917
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
20-
struct ResultTree {
21-
let data: String // tree data - could be hydrated or dehydrated.
22-
let ttl: TimeInterval // interval during which query results are considered fresh
23-
let cachedAt: Date // Local time when the entry was cached / updated
24-
var lastAccessed: Date // Local time when the entry was read or updated
18+
struct ResultTree: Codable {
19+
// tree data - could be hydrated or dehydrated.
20+
let data: String
21+
22+
// interval during which query results are considered fresh
23+
let ttl: TimeInterval
24+
25+
// Local time when the entry was cached / updated
26+
let cachedAt: Date
27+
28+
// Local time when the entry was read or updated
29+
var lastAccessed: Date
2530

2631
var rootObject: EntityNode?
2732

@@ -37,21 +42,3 @@ struct ResultTree {
3742
case data = "d" // data cached
3843
}
3944
}
40-
41-
extension ResultTree: Codable {
42-
init(from decoder: any Decoder) throws {
43-
let container = try decoder.container(keyedBy: CodingKeys.self)
44-
cachedAt = try container.decode(Date.self, forKey: .cachedAt)
45-
lastAccessed = try container.decode(Date.self, forKey: .lastAccessed)
46-
ttl = try container.decode(TimeInterval.self, forKey: .ttl)
47-
data = try container.decode(String.self, forKey: .data)
48-
}
49-
50-
func encode(to encoder: any Encoder) throws {
51-
var container = encoder.container(keyedBy: CodingKeys.self)
52-
try container.encode(cachedAt, forKey: .cachedAt)
53-
try container.encode(lastAccessed, forKey: .lastAccessed)
54-
try container.encode(ttl, forKey: .ttl)
55-
try container.encode(data, forKey: .data)
56-
}
57-
}

Sources/Cache/ResultTreeProcessor.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,9 @@ class ImpactedQueryRefsAccumulator {
6666
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
6767
struct ResultTreeProcessor {
6868
/*
69-
Go down the tree and convert them to entity nodes
70-
For each Node
71-
- extract globalID
72-
- Get the EDO for the globalID
73-
- extract scalars and update EDO with scalars
74-
- for each array
75-
- recursively process each object (could be scalar or composite)
76-
- for composite objects (dictionaries), create references to their node
77-
- create a Node and init it with dictionary.
69+
Takes a JSON tree with data and normalizes the entities contained in it,
70+
creating a resultant JSON tree with references to entities.
7871
*/
79-
8072
func dehydrateResults(_ hydratedTree: String, cacheProvider: CacheProvider,
8173
requestor: (any QueryRefInternal)? = nil) throws -> (
8274
dehydratedResults: String,
@@ -116,6 +108,9 @@ struct ResultTreeProcessor {
116108
return (dehydratedResultsString, enode, impactedRefs)
117109
}
118110

111+
/*
112+
Takes a dehydrated tree and fills it up with Entity data from referenced entities.
113+
*/
119114
func hydrateResults(_ dehydratedTree: String, cacheProvider: CacheProvider) throws ->
120115
(hydratedResults: String, rootObject: EntityNode) {
121116
guard let dehydratedData = dehydratedTree.data(using: .utf8) else {

Sources/Cache/SQLiteCacheProvider.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import FirebaseCore
1615
import Foundation
1716
import SQLite3
1817

Sources/Internal/OperationsManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class OperationsManager {
5252
}
5353

5454
if publisher == .auto || publisher == .observableMacro {
55-
if #available(iOS 17, macOS 15, tvOS 17, watchOS 10, *) {
55+
if #available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) {
5656
let obsRef = QueryRefObservation<ResultDataType, VariableType>(
5757
request: request,
5858
dataType: resultType,

Sources/MutationRef.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ public class MutationRef<
3131
ResultData: Decodable & Sendable,
3232
Variable: OperationVariable
3333
>: OperationRef {
34-
private var request: any OperationRequest
34+
private var request: MutationRequest<Variable>
3535

3636
private var grpcClient: GrpcClient
3737

38-
init(request: any OperationRequest, grpcClient: GrpcClient) {
38+
init(request: MutationRequest<Variable>, grpcClient: GrpcClient) {
3939
self.request = request
4040
self.grpcClient = grpcClient
4141
}
4242

4343
public func execute() async throws -> OperationResult<ResultData> {
4444
let results = try await grpcClient.executeMutation(
45-
request: request as! MutationRequest<Variable>,
45+
request: request,
4646
resultType: ResultData.self
4747
)
4848
return results
@@ -54,6 +54,6 @@ public class MutationRef<
5454

5555
public static func == (lhs: MutationRef<ResultData, Variable>,
5656
rhs: MutationRef<ResultData, Variable>) -> Bool {
57-
return lhs.request as? MutationRequest<Variable> == rhs.request as? MutationRequest<Variable>
57+
return lhs.request == rhs.request
5858
}
5959
}

Sources/OperationResult.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import Foundation
1616

17-
/// Struct returned by operation calls - query or mutation
17+
/// Structure representing the value returned by operation calls - query or mutation
1818
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
1919
public struct OperationResult<ResultData: Decodable & Sendable>: Sendable {
2020
public let data: ResultData?

Sources/Queries/GenericQueryRef.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import CryptoKit
1615
import Foundation
1716

18-
import Firebase
19-
2017
@preconcurrency import Combine
2118
import Observation
2219

Sources/Queries/ObservableQueryRef.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import CryptoKit
1615
import Foundation
1716

18-
import Firebase
19-
2017
@preconcurrency import Combine
2118
import Observation
2219

@@ -154,7 +151,7 @@ extension QueryRefObservableObject: QueryRefInternal {
154151
/// - ``data``: Published variable that contains bindable results of the query.
155152
/// - ``lastError``: Published variable that contains ``DataConnectError`` if last fetch had error.
156153
/// If last fetch was successful, this variable is cleared
157-
@available(macOS 15, iOS 17, tvOS 17, watchOS 10, *)
154+
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
158155
@Observable
159156
public class QueryRefObservation<
160157
ResultData: Decodable & Sendable,
@@ -232,7 +229,7 @@ public class QueryRefObservation<
232229
}
233230
}
234231

235-
@available(macOS 15, iOS 17, tvOS 17, watchOS 10, *)
232+
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
236233
public extension QueryRefObservation {
237234
nonisolated func hash(into hasher: inout Hasher) {
238235
hasher.combine(baseRef)
@@ -243,14 +240,14 @@ public extension QueryRefObservation {
243240
}
244241
}
245242

246-
@available(macOS 15, iOS 17, tvOS 17, watchOS 10, *)
243+
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
247244
extension QueryRefObservation: CustomStringConvertible {
248245
public nonisolated var description: String {
249246
"QueryRefObservation(\(String(describing: baseRef)))"
250247
}
251248
}
252249

253-
@available(macOS 15, iOS 17, tvOS 17, watchOS 10, *)
250+
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
254251
extension QueryRefObservation: QueryRefInternal {
255252
func publishServerResultsToSubscribers() async throws {
256253
try await baseRef.publishServerResultsToSubscribers()

Sources/Queries/QueryRef.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import CryptoKit
1615
import Foundation
1716

18-
import Firebase
19-
2017
@preconcurrency import Combine
2118
import Observation
2219

Sources/Queries/QueryRequest.swift

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import CryptoKit
1615
import Foundation
1716

18-
import Firebase
19-
2017
/// A QueryRequest is used to get a QueryRef to a Data Connect query using the specified query name
2118
/// and input variables to the query
2219
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@@ -51,7 +48,8 @@ struct QueryRequest<Variable: OperationVariable>: OperationRequest, Hashable, Eq
5148
self.variables = variables
5249
}
5350

54-
// Hashable and Equatable implementation
51+
// MARK: - Hashable and Equatable implementation
52+
5553
func hash(into hasher: inout Hasher) {
5654
hasher.combine(operationName)
5755
if let variables {
@@ -64,16 +62,6 @@ struct QueryRequest<Variable: OperationVariable>: OperationRequest, Hashable, Eq
6462
return false
6563
}
6664

67-
if lhs.variables == nil && rhs.variables == nil {
68-
return true
69-
}
70-
71-
guard let lhsVar = lhs.variables,
72-
let rhsVar = rhs.variables,
73-
lhsVar == rhsVar else {
74-
return false
75-
}
76-
77-
return true
65+
return lhs.variables == rhs.variables
7866
}
7967
}

0 commit comments

Comments
 (0)