diff --git a/Sources/ParseCareKit/Models/PCKRevisionRecord.swift b/Sources/ParseCareKit/Models/PCKRevisionRecord.swift index c6ba26ffa..60565e51a 100644 --- a/Sources/ParseCareKit/Models/PCKRevisionRecord.swift +++ b/Sources/ParseCareKit/Models/PCKRevisionRecord.swift @@ -55,7 +55,11 @@ struct PCKRevisionRecord: ParseObject, Equatable, Codable { } } - public var vector: String? + var vector: String? + + var storeClassesToSynchronize: [PCKStoreClass: any PCKVersionable.Type]? = try? PCKStoreClass.getConcrete() + + var customClassesToSynchronize: [String: any PCKVersionable.Type]? var objects: [any PCKVersionable] { guard let entities = entities else { @@ -112,6 +116,13 @@ struct PCKRevisionRecord: ParseObject, Equatable, Codable { logicalClock, clock, clockUUID } + static func == (lhs: PCKRevisionRecord, rhs: PCKRevisionRecord) -> Bool { + lhs.vector == rhs.vector && + lhs.logicalClock == rhs.logicalClock && + lhs.objectId == rhs.objectId && + lhs.entities == rhs.entities + } + func convertToCareKit() throws -> OCKRevisionRecord { guard let entities = entities, let knowledgeVector = knowledgeVector else { @@ -246,13 +257,17 @@ extension PCKRevisionRecord { init(record: OCKRevisionRecord, remoteClockUUID: UUID, remoteClock: PCKClock, - remoteClockValue: Int) throws { + remoteClockValue: Int, + storeClassesToSynchronize: [PCKStoreClass: any PCKVersionable.Type]? = nil, + customClassesToSynchronize: [String: any PCKVersionable.Type]? = nil) throws { self.objectId = UUID().uuidString self.ACL = PCKUtility.getDefaultACL() self.clockUUID = remoteClockUUID self.logicalClock = remoteClockValue self.clock = remoteClock self.knowledgeVector = record.knowledgeVector + self.storeClassesToSynchronize = storeClassesToSynchronize + self.customClassesToSynchronize = customClassesToSynchronize self.entities = try record.entities.compactMap { entity in var parseEntity = try entity.parseEntity().value parseEntity.logicalClock = remoteClockValue // Stamp Entity diff --git a/Sources/ParseCareKit/Models/PCKStoreClass.swift b/Sources/ParseCareKit/Models/PCKStoreClass.swift index ff9efcce0..80c4c50e5 100644 --- a/Sources/ParseCareKit/Models/PCKStoreClass.swift +++ b/Sources/ParseCareKit/Models/PCKStoreClass.swift @@ -13,7 +13,7 @@ import os.log // swiftlint:disable line_length /// Types of ParseCareKit classes. -public enum PCKStoreClass: String, CaseIterable { +public enum PCKStoreClass: String, Equatable, CaseIterable { /// The ParseCareKit equivalent of `OCKPatient`. case patient /// The ParseCareKit equivalent of `OCKCarePlan`. diff --git a/Sources/ParseCareKit/ParseRemote.swift b/Sources/ParseCareKit/ParseRemote.swift index 1c2c0d1ff..fe9534d27 100644 --- a/Sources/ParseCareKit/ParseRemote.swift +++ b/Sources/ParseCareKit/ParseRemote.swift @@ -36,7 +36,7 @@ public class ParseRemote: OCKRemoteSynchronizable { public var uuid: UUID! /// A dictionary of any custom classes to synchronize between the `CareKitStore` and the Parse Server. - public var customClassesToSynchronize: [String: any PCKVersionable]? + public var customClassesToSynchronize: [String: any PCKVersionable.Type]? /// A dictionary of any default classes to synchronize between the `CareKitStore` and the Parse Server. These /// are `PCKPatient`, `PCKCarePlan`, `PCKContact`, `PCKTask`, `PCKHealthKitTask`, @@ -128,7 +128,7 @@ public class ParseRemote: OCKRemoteSynchronizable { convenience public init(uuid: UUID, auto: Bool, replacePCKStoreClasses: [PCKStoreClass: any PCKVersionable.Type]? = nil, - customClasses: [String: any PCKVersionable], + customClasses: [String: any PCKVersionable.Type], subscribeToServerUpdates: Bool, defaultACL: ParseACL? = nil) async throws { try await self.init(uuid: uuid,