From 6935764741a002f1359a9f262f52c2d808c97d82 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Thu, 14 Nov 2024 19:04:14 -0600 Subject: [PATCH] WitnessModule --- Sources/XyoClient/Panel/Panel.swift | 8 ++++---- Sources/XyoClient/Witness/Basic/BasicWitness.swift | 2 +- Sources/XyoClient/Witness/Event/EventWitness.swift | 2 +- .../XyoClient/Witness/Location/LocationWitness.swift | 2 +- .../Witness/SystemInfo/SystemInfoWitness.swift | 2 +- .../{AbstractWitness.swift => WitnessModule.swift} | 11 ++++------- Tests/XyoClientTests/Panel.swift | 2 +- 7 files changed, 13 insertions(+), 16 deletions(-) rename Sources/XyoClient/Witness/{AbstractWitness.swift => WitnessModule.swift} (77%) diff --git a/Sources/XyoClient/Panel/Panel.swift b/Sources/XyoClient/Panel/Panel.swift index ff8577c..319fecb 100644 --- a/Sources/XyoClient/Panel/Panel.swift +++ b/Sources/XyoClient/Panel/Panel.swift @@ -6,13 +6,13 @@ public enum XyoPanelError: Error { public class XyoPanel { - public init(archivists: [XyoArchivistApiClient], witnesses: [AbstractSyncWitness]) { + public init(archivists: [XyoArchivistApiClient], witnesses: [WitnessModuleSync]) { self._archivists = archivists self._witnesses = witnesses } public convenience init( - archive: String? = nil, apiDomain: String? = nil, witnesses: [AbstractSyncWitness]? = nil, + archive: String? = nil, apiDomain: String? = nil, witnesses: [WitnessModuleSync]? = nil, token: String? = nil ) { let apiConfig = XyoArchivistApiConfig( @@ -23,7 +23,7 @@ public class XyoPanel { public convenience init(observe: (() -> XyoEventPayload?)?) { if observe != nil { - var witnesses = [AbstractSyncWitness]() + var witnesses = [WitnessModuleSync]() if let observe = observe { witnesses.append(XyoEventWitness(observe)) @@ -38,7 +38,7 @@ public class XyoPanel { public typealias XyoPanelReportCallback = (([String]) -> Void) private var _archivists: [XyoArchivistApiClient] - private var _witnesses: [AbstractSyncWitness] + private var _witnesses: [WitnessModuleSync] private var _previous_hash: String? @available(iOS 15, *) diff --git a/Sources/XyoClient/Witness/Basic/BasicWitness.swift b/Sources/XyoClient/Witness/Basic/BasicWitness.swift index ec1acc9..1d733da 100644 --- a/Sources/XyoClient/Witness/Basic/BasicWitness.swift +++ b/Sources/XyoClient/Witness/Basic/BasicWitness.swift @@ -1,6 +1,6 @@ import Foundation -open class BasicWitness: AbstractSyncWitness { +open class BasicWitness: WitnessModuleSync { public typealias TPayloadOut = Payload diff --git a/Sources/XyoClient/Witness/Event/EventWitness.swift b/Sources/XyoClient/Witness/Event/EventWitness.swift index 5e5e12e..6cb8c54 100644 --- a/Sources/XyoClient/Witness/Event/EventWitness.swift +++ b/Sources/XyoClient/Witness/Event/EventWitness.swift @@ -1,6 +1,6 @@ import Foundation -open class XyoEventWitness: AbstractSyncWitness { +open class XyoEventWitness: WitnessModuleSync { public init(_ observer: @escaping ObserverClosure) { _observer = observer diff --git a/Sources/XyoClient/Witness/Location/LocationWitness.swift b/Sources/XyoClient/Witness/Location/LocationWitness.swift index 43c895e..ee32847 100644 --- a/Sources/XyoClient/Witness/Location/LocationWitness.swift +++ b/Sources/XyoClient/Witness/Location/LocationWitness.swift @@ -1,7 +1,7 @@ import CoreLocation import Foundation -open class LocationWitness: AbstractAsyncWitness { +open class LocationWitness: WitnessModuleAsync { private let locationService = LocationService() override open func observe(completion: @escaping ([Payload]?, Error?) -> Void) { diff --git a/Sources/XyoClient/Witness/SystemInfo/SystemInfoWitness.swift b/Sources/XyoClient/Witness/SystemInfo/SystemInfoWitness.swift index 9053cb7..381715e 100644 --- a/Sources/XyoClient/Witness/SystemInfo/SystemInfoWitness.swift +++ b/Sources/XyoClient/Witness/SystemInfo/SystemInfoWitness.swift @@ -1,6 +1,6 @@ import Foundation -open class SystemInfoWitness: AbstractSyncWitness { +open class SystemInfoWitness: WitnessModuleSync { var allowPathMonitor: Bool diff --git a/Sources/XyoClient/Witness/AbstractWitness.swift b/Sources/XyoClient/Witness/WitnessModule.swift similarity index 77% rename from Sources/XyoClient/Witness/AbstractWitness.swift rename to Sources/XyoClient/Witness/WitnessModule.swift index 6712b1e..81cca61 100644 --- a/Sources/XyoClient/Witness/AbstractWitness.swift +++ b/Sources/XyoClient/Witness/WitnessModule.swift @@ -1,12 +1,14 @@ import Foundation -open class AbstractSyncWitness: AbstractModule, WitnessSync { +public protocol WitnessModule: Module {} + +open class WitnessModuleSync: AbstractModule, WitnessSync, WitnessModule { open func observe() -> [Payload] { preconditionFailure("This method must be overridden") } } -open class AbstractAsyncWitness: AbstractModule, WitnessAsync { +open class WitnessModuleAsync: AbstractModule, WitnessAsync, WitnessModule { open func observe(completion: @escaping ([Payload]?, Error?) -> Void) { preconditionFailure("This method must be overridden") } @@ -26,8 +28,3 @@ open class AbstractAsyncWitness: AbstractModule, WitnessAsync { } } } - -public protocol Witness {} - -extension AbstractSyncWitness: Witness {} -extension AbstractAsyncWitness: Witness {} diff --git a/Tests/XyoClientTests/Panel.swift b/Tests/XyoClientTests/Panel.swift index b3bb9de..a1530f7 100644 --- a/Tests/XyoClientTests/Panel.swift +++ b/Tests/XyoClientTests/Panel.swift @@ -17,7 +17,7 @@ final class PanelTests: XCTestCase { let apiDomain = XyoPanel.Defaults.apiDomain let archive = XyoPanel.Defaults.apiModule let account = Account() - let witness = AbstractSyncWitness(account: account) + let witness = WitnessModuleSync(account: account) let panel = XyoPanel(archive: archive, apiDomain: apiDomain, witnesses: [witness]) XCTAssertNotNil(account) XCTAssertNotNil(panel)