Skip to content
Merged
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 Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let package = Package(
.default(enabledTraits: ["SharingGRDBTagged"]),
],
dependencies: [
.package(url: "https://github.com/groue/GRDB.swift", from: "7.4.0"),
.package(url: "https://github.com/groue/GRDB.swift", from: "7.6.0"),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the escaping closure fix in 7.6 I think it's a good idea to bump this...

.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.9.0"),
.package(url: "https://github.com/pointfreeco/swift-sharing", from: "2.3.0"),
Expand Down
2 changes: 1 addition & 1 deletion Package@swift-6.0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/groue/GRDB.swift", from: "7.4.0"),
.package(url: "https://github.com/groue/GRDB.swift", from: "7.6.0"),
.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.9.0"),
.package(url: "https://github.com/pointfreeco/swift-sharing", from: "2.3.0"),
Expand Down
5 changes: 3 additions & 2 deletions Sources/SharingGRDBCore/CloudKit/SyncEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1873,8 +1873,9 @@
throw SyncEngine.SchemaError(
reason: .triggersWithoutSynchronizationCheck(invalidTriggers),
debugDescription: """
Triggers must include '\(DatabaseFunction.syncEngineIsSynchronizingChanges.name)()' \
check: \(triggers.map { "'\($0)'" }.joined(separator: ", ")).
Triggers must include 'SyncEngine.isSynchronizingChanges()' \
('\(DatabaseFunction.syncEngineIsSynchronizingChanges.name)()') \
check: \(invalidTriggers.map { "'\($0)'" }.joined(separator: ", ")).
"""
)
}
Expand Down
11 changes: 3 additions & 8 deletions Sources/SharingGRDBCore/Internal/DataManager.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Dependencies
import Foundation

@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
package protocol DataManager: Sendable {
func load(_ url: URL) throws -> Data
func save(_ data: Data, to url: URL) throws
var temporaryDirectory: URL { get }
}

@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
struct LiveDataManager: DataManager {
func load(_ url: URL) throws -> Data {
try Data(contentsOf: url)
Expand All @@ -17,11 +15,10 @@ struct LiveDataManager: DataManager {
try data.write(to: url)
}
var temporaryDirectory: URL {
.temporaryDirectory
URL(fileURLWithPath: NSTemporaryDirectory())
}
}

@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
package struct InMemoryDataManager: DataManager {
package let storage = LockIsolated<[URL: Data]>([:])

Expand All @@ -43,11 +40,10 @@ package struct InMemoryDataManager: DataManager {
}

package var temporaryDirectory: URL {
URL(filePath: "/")
URL(fileURLWithPath: "/")
}
}

@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
private enum DataManagerKey: DependencyKey {
static var liveValue: any DataManager {
LiveDataManager()
Expand All @@ -58,8 +54,7 @@ private enum DataManagerKey: DependencyKey {
}

extension DependencyValues {
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
package var dataManager: DataManager {
package var dataManager: DataManager {
get { self[DataManagerKey.self] }
set { self[DataManagerKey.self] = newValue }
}
Expand Down
49 changes: 18 additions & 31 deletions Sources/SharingGRDBCore/Internal/UserDatabase.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Dependencies
import GRDB

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
package struct UserDatabase {
private let database: any DatabaseWriter
package init(database: any DatabaseWriter) {
Expand All @@ -16,60 +15,48 @@ package struct UserDatabase {
database.configuration
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
package func write<T: Sendable>(
_ updates: @escaping @Sendable (Database) throws -> T
_ updates: @Sendable (Database) throws -> T
) async throws -> T {
try await withEscapedDependencies { dependencies in
try await database.write { db in
try SyncEngine.$_isSynchronizingChanges.withValue(true) {
try dependencies.yield {
try updates(db)
}
}
try await database.write { db in
try SyncEngine.$_isSynchronizingChanges.withValue(true) {
try updates(db)
}
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
package func read<T: Sendable>(
_ updates: @escaping @Sendable (Database) throws -> T
_ updates: @Sendable (Database) throws -> T
) async throws -> T {
try await withEscapedDependencies { dependencies in
try await database.read { db in
try SyncEngine.$_isSynchronizingChanges.withValue(true) {
try dependencies.yield {
try updates(db)
}
}
try await database.read { db in
try SyncEngine.$_isSynchronizingChanges.withValue(true) {
try updates(db)
}
}
}

@_disfavoredOverload
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
package func write<T>(
_ updates: (Database) throws -> T
) throws -> T {
try withEscapedDependencies { dependencies in
try database.write { db in
try SyncEngine.$_isSynchronizingChanges.withValue(true) {
try dependencies.yield {
try updates(db)
}
}
try database.write { db in
try SyncEngine.$_isSynchronizingChanges.withValue(true) {
try updates(db)
}
}
}

@_disfavoredOverload
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
package func read<T>(
_ updates: (Database) throws -> T
) throws -> T {
try withEscapedDependencies { dependencies in
try database.read { db in
try SyncEngine.$_isSynchronizingChanges.withValue(true) {
try dependencies.yield {
try updates(db)
}
}
try database.read { db in
try SyncEngine.$_isSynchronizingChanges.withValue(true) {
try updates(db)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Testing
extension BaseCloudKitTests {
@MainActor
final class AccountLifecycleTests: BaseCloudKitTests, @unchecked Sendable {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func signOutClearsUserDatabaseAndMetadatabase() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand All @@ -34,8 +35,8 @@ extension BaseCloudKitTests {
}()
}

@Test(.accountStatus(.noAccount))
func signInUploadsLocalRecordsToCloudKit() async throws {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(.accountStatus(.noAccount)) func signInUploadsLocalRecordsToCloudKit() async throws {
try await userDatabase.userWrite { db in
try db.seed {
RemindersList(id: 1, title: "Personal")
Expand Down Expand Up @@ -107,6 +108,7 @@ extension BaseCloudKitTests {
@MainActor
@Suite(.accountStatus(.noAccount))
final class SignedOutTests: BaseCloudKitTests, @unchecked Sendable {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
init() async throws {
try await super.init { userDatabase in
try await userDatabase.write { db in
Expand All @@ -120,6 +122,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func doNotUploadExistingDataToCloudKitWhenSignedOut() {
}
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/SharingGRDBTests/CloudKitTests/CloudKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func cascadingDeletionOrder() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down Expand Up @@ -1012,6 +1013,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func generatedColumns() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extension BaseCloudKitTests {
@MainActor
@Suite
final class FetchRecordZoneChangeTests: BaseCloudKitTests, @unchecked Sendable {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func saveExtraFieldsToSyncMetadata() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down Expand Up @@ -105,6 +106,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func remoteChangeParentRelationship() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down Expand Up @@ -201,6 +203,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func receiveNewRecordFromCloudKit() async throws {
let remindersListRecord = CKRecord(
recordType: RemindersList.tableName,
Expand Down Expand Up @@ -284,6 +287,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func receiveNewRecordFromCloudKit_ChildBeforeParent() async throws {
let remindersListRecord = CKRecord(
recordType: RemindersList.tableName,
Expand Down Expand Up @@ -415,6 +419,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func deleteMultipleRecords() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down Expand Up @@ -443,6 +448,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func receiveRecord_SingleFieldPrimaryKey() async throws {
let tagRecord = CKRecord(recordType: "tags", recordID: Tag.recordID(for: "weekend"))
tagRecord.encryptedValues["title"] = "weekend"
Expand All @@ -453,6 +459,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func renamePrimaryKey() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extension BaseCloudKitTests {
@MainActor
@Suite
final class FetchedDatabaseChangesTests: BaseCloudKitTests, @unchecked Sendable {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func deleteSyncEngineZone() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down Expand Up @@ -42,6 +43,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func deleteSyncEngineZone_EncryptedDataReset() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Testing
extension BaseCloudKitTests {
@MainActor
final class ForeignKeyConstraintTests: BaseCloudKitTests, @unchecked Sendable {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func receiveChildBeforeParent() async throws {
let remindersListRecord = CKRecord(
recordType: RemindersList.tableName,
Expand Down Expand Up @@ -153,6 +154,7 @@ extension BaseCloudKitTests {
* Remote deletes record B and C.
* C should be deleted from local client.
*/
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func remoteCreatesRecordABC_localReceivesAC_remoteDeletesBC() async throws {
let modelARecord = CKRecord(recordType: ModelA.tableName, recordID: ModelA.recordID(for: 1))
let modelBRecord = CKRecord(recordType: ModelB.tableName, recordID: ModelB.recordID(for: 1))
Expand Down Expand Up @@ -207,6 +209,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(
"""
1) Receive child record without parent.
Expand Down Expand Up @@ -293,6 +296,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func receiveChild_Relaunch_ReceiveParent() async throws {
let remindersListRecord = CKRecord(
recordType: RemindersList.tableName,
Expand Down Expand Up @@ -437,6 +441,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(
"""
Remote changes parent relationship to an unknown record which is synchronized later.
Expand Down Expand Up @@ -579,6 +584,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func changeParentRelationship_RemotelyThenLocally() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down Expand Up @@ -659,6 +665,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test
func changeParentRelationship_RemoteFirstEdited_LocalSecondEdited_SendBatch_ReceiveCloudKit()
async throws
Expand Down Expand Up @@ -759,6 +766,7 @@ extension BaseCloudKitTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func cascadingDeletes() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down
Loading
Loading