Skip to content

Commit

Permalink
Protocol conformance for witnesses
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Nov 15, 2024
1 parent 462348e commit dffcfd2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 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: [AbstractWitness]) {
public init(archivists: [XyoArchivistApiClient], witnesses: [AbstractSyncWitness]) {
self._archivists = archivists
self._witnesses = witnesses
}

public convenience init(
archive: String? = nil, apiDomain: String? = nil, witnesses: [AbstractWitness]? = nil,
archive: String? = nil, apiDomain: String? = nil, witnesses: [AbstractSyncWitness]? = 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 = [AbstractWitness]()
var witnesses = [AbstractSyncWitness]()

if let observe = observe {
witnesses.append(XyoEventWitness(observe))
Expand All @@ -38,9 +38,9 @@ public class XyoPanel {
public typealias XyoPanelReportCallback = (([String]) -> Void)

private var _archivists: [XyoArchivistApiClient]
private var _witnesses: [AbstractWitness]
private var _witnesses: [AbstractSyncWitness]
private var _previous_hash: String?

@available(iOS 15, *)
public func report() async throws
-> [Payload]
Expand Down
7 changes: 6 additions & 1 deletion Sources/XyoClient/Witness/AbstractWitness.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

open class AbstractWitness: AbstractModule, WitnessSync {
open class AbstractSyncWitness: AbstractModule, WitnessSync {
open func observe() -> [Payload] {
preconditionFailure("This method must be overridden")
}
Expand All @@ -26,3 +26,8 @@ open class AbstractAsyncWitness: AbstractModule, WitnessAsync {
}
}
}

public protocol Witness {}

extension AbstractSyncWitness: Witness {}
extension AbstractAsyncWitness: Witness {}
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: AbstractWitness {
open class BasicWitness: AbstractSyncWitness {

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: AbstractWitness {
open class XyoEventWitness: AbstractSyncWitness {

public init(_ observer: @escaping ObserverClosure) {
_observer = observer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

open class SystemInfoWitness: AbstractWitness {
open class SystemInfoWitness: AbstractSyncWitness {

var allowPathMonitor: Bool

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
public protocol WitnessProtocol {}


public protocol WitnessSync: WitnessProtocol {
public protocol WitnessSync {
func observe() -> [Payload]
}

public protocol WitnessAsync: WitnessProtocol {
public protocol WitnessAsync {
func observe(completion: @escaping ([Payload]?, Error?) -> Void)

@available(iOS 15, *)
func observe() async throws -> [Payload]
}


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 = AbstractWitness(account: account)
let witness = AbstractSyncWitness(account: account)
let panel = XyoPanel(archive: archive, apiDomain: apiDomain, witnesses: [witness])
XCTAssertNotNil(account)
XCTAssertNotNil(panel)
Expand Down

0 comments on commit dffcfd2

Please sign in to comment.