Skip to content

Commit

Permalink
WitnessModule
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Nov 15, 2024
1 parent dffcfd2 commit 6935764
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Sources/XyoClient/Panel/Panel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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))
Expand All @@ -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, *)
Expand Down
2 changes: 1 addition & 1 deletion Sources/XyoClient/Witness/Basic/BasicWitness.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

open class BasicWitness: AbstractSyncWitness {
open class BasicWitness: WitnessModuleSync {

public typealias TPayloadOut = Payload

Expand Down
2 changes: 1 addition & 1 deletion Sources/XyoClient/Witness/Event/EventWitness.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

open class XyoEventWitness: AbstractSyncWitness {
open class XyoEventWitness: WitnessModuleSync {

public init(_ observer: @escaping ObserverClosure) {
_observer = observer
Expand Down
2 changes: 1 addition & 1 deletion Sources/XyoClient/Witness/Location/LocationWitness.swift
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

open class SystemInfoWitness: AbstractSyncWitness {
open class SystemInfoWitness: WitnessModuleSync {

var allowPathMonitor: Bool

Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
Expand All @@ -26,8 +28,3 @@ open class AbstractAsyncWitness: AbstractModule, WitnessAsync {
}
}
}

public protocol Witness {}

extension AbstractSyncWitness: Witness {}
extension AbstractAsyncWitness: Witness {}
2 changes: 1 addition & 1 deletion Tests/XyoClientTests/Panel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6935764

Please sign in to comment.