Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/Reminders/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension Color {
return .int(hexValue)
}

public init(decoder: inout some QueryDecoder) throws {
public init(decoder: inout some QueryDecoder) throws(QueryDecodingError) {
try self.init(hexValue: Int64(decoder: &decoder))
}
}
Expand Down
10 changes: 5 additions & 5 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.4"),
.package(
url: "https://github.com/pointfreeco/swift-structured-queries",
from: "0.36.0",
// from: "0.36.0",
branch: "typed-decoding",
traits: [
.trait(
name: "LazyInitializableByDefault",
Expand Down
33 changes: 15 additions & 18 deletions Sources/SQLiteData/CloudKit/CloudKit+StructuredQueries.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,23 @@
try? self.init(data: Data(bytes))
}

public init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws {
public init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws(QueryDecodingError) {
try self.init(data: try Data(decoder: &decoder))
}

private init(data: Data) throws {
let coder = try NSKeyedUnarchiver(forReadingFrom: data)
private init(data: Data) throws(QueryDecodingError) {
guard let coder = try? NSKeyedUnarchiver(forReadingFrom: data)
else { throw .dataCorrupted }
coder.requiresSecureCoding = true
guard let queryOutput = Record(coder: coder) else {
throw DecodingError()
}
guard let queryOutput = Record(coder: coder)
else { throw .dataCorrupted }
if isTesting {
queryOutput._recordChangeTag =
coder
.decodeObject(of: NSNumber.self, forKey: "_recordChangeTag")?.intValue
}
self.init(queryOutput: queryOutput)
}

private struct DecodingError: Error {}
}

public struct _AllFieldsRepresentation<Record: CKRecord>: QueryBindable, QueryRepresentable {
Expand All @@ -83,15 +81,16 @@
try? self.init(data: Data(bytes))
}

public init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws {
public init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws(QueryDecodingError) {
try self.init(data: try Data(decoder: &decoder))
}

private init(data: Data) throws {
let coder = try NSKeyedUnarchiver(forReadingFrom: data)
private init(data: Data) throws(QueryDecodingError) {
guard let coder = try? NSKeyedUnarchiver(forReadingFrom: data)
else { throw .dataCorrupted }
coder.requiresSecureCoding = true
guard let queryOutput = Record(coder: coder) else {
throw DecodingError()
throw .dataCorrupted
}
if isTesting {
queryOutput._recordChangeTag =
Expand All @@ -117,16 +116,14 @@
guard case .int(let rawValue) = queryBinding else { return nil }
try? self.init(rawValue: Int(rawValue))
}
public init(decoder: inout some QueryDecoder) throws {
public init(decoder: inout some QueryDecoder) throws(QueryDecodingError) {
try self.init(rawValue: Int(decoder: &decoder))
}
private init(rawValue: Int) throws {
guard let queryOutput = CKDatabase.Scope(rawValue: rawValue) else {
throw DecodingError()
}
private init(rawValue: Int) throws(QueryDecodingError) {
guard let queryOutput = CKDatabase.Scope(rawValue: rawValue)
else { throw .dataCorrupted }
self.init(queryOutput: queryOutput)
}
private struct DecodingError: Error {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@
try? self.init(data: Data(bytes))
}

package init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws {
package init(
decoder: inout some StructuredQueriesCore.QueryDecoder
) throws(QueryDecodingError) {
try self.init(data: Data(decoder: &decoder))
}

private init(data: Data) throws {
let coder = try NSKeyedUnarchiver(forReadingFrom: data)
private init(data: Data) throws(QueryDecodingError) {
guard let coder = try? NSKeyedUnarchiver(forReadingFrom: data)
else { throw .dataCorrupted }
coder.requiresSecureCoding = true
guard let recordID = CKRecord.ID(coder: coder) else {
throw DecodingError()
throw .dataCorrupted
}
let changeType = coder.decodeObject(of: NSString.self, forKey: "changeType") as? String
switch changeType {
Expand All @@ -65,12 +68,11 @@
case "deleteRecord":
self.init(queryOutput: .deleteRecord(recordID))
default:
throw DecodingError()
throw .dataCorrupted
}
}
}

private struct DecodingError: Error {}
private struct BindingError: Error {}
}
#endif