From 4e5e219f1669f3dfe2eddc7e8e57aeac5423df6f Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Fri, 22 Jul 2022 12:49:12 +0100
Subject: [PATCH] Add ConnectionClose functor

---
 Sources/ElixxirDAppsSDK/Connection.swift      | 10 ++++--
 Sources/ElixxirDAppsSDK/ConnectionClose.swift | 26 ++++++++++++++++
 .../Legacy/ConnectionCloser.swift             | 31 -------------------
 3 files changed, 33 insertions(+), 34 deletions(-)
 create mode 100644 Sources/ElixxirDAppsSDK/ConnectionClose.swift
 delete mode 100644 Sources/ElixxirDAppsSDK/Legacy/ConnectionCloser.swift

diff --git a/Sources/ElixxirDAppsSDK/Connection.swift b/Sources/ElixxirDAppsSDK/Connection.swift
index 1d857798..4daaacdc 100644
--- a/Sources/ElixxirDAppsSDK/Connection.swift
+++ b/Sources/ElixxirDAppsSDK/Connection.swift
@@ -3,20 +3,23 @@ import Bindings
 public struct Connection {
   public var getId: ConnectionGetId
   public var getPartner: ConnectionGetPartner
+  public var close: ConnectionClose
 }
 
 extension Connection {
   public static func live(_ bindingsConnection: BindingsConnection) -> Connection {
     Connection(
       getId: .live(bindingsConnection),
-      getPartner: .live(bindingsConnection)
+      getPartner: .live(bindingsConnection),
+      close: .live(bindingsConnection)
     )
   }
 
   public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> Connection {
     Connection(
       getId: .live(bindingsConnection),
-      getPartner: .live(bindingsConnection)
+      getPartner: .live(bindingsConnection),
+      close: .live(bindingsConnection)
     )
   }
 }
@@ -24,6 +27,7 @@ extension Connection {
 extension Connection {
   public static let unimplemented = Connection(
     getId: .unimplemented,
-    getPartner: .unimplemented
+    getPartner: .unimplemented,
+    close: .unimplemented
   )
 }
diff --git a/Sources/ElixxirDAppsSDK/ConnectionClose.swift b/Sources/ElixxirDAppsSDK/ConnectionClose.swift
new file mode 100644
index 00000000..62115a0a
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/ConnectionClose.swift
@@ -0,0 +1,26 @@
+import Bindings
+import XCTestDynamicOverlay
+
+public struct ConnectionClose {
+  public var run: () throws -> Void
+
+  public func callAsFunction() throws {
+    try run()
+  }
+}
+
+extension ConnectionClose {
+  public static func live(_ bindingsConnection: BindingsConnection) -> ConnectionClose {
+    ConnectionClose(run: bindingsConnection.close)
+  }
+
+  public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> ConnectionClose {
+    ConnectionClose(run: bindingsConnection.close)
+  }
+}
+
+extension ConnectionClose {
+  public static let unimplemented = ConnectionClose(
+    run: XCTUnimplemented("\(Self.self)")
+  )
+}
diff --git a/Sources/ElixxirDAppsSDK/Legacy/ConnectionCloser.swift b/Sources/ElixxirDAppsSDK/Legacy/ConnectionCloser.swift
deleted file mode 100644
index eb31677d..00000000
--- a/Sources/ElixxirDAppsSDK/Legacy/ConnectionCloser.swift
+++ /dev/null
@@ -1,31 +0,0 @@
-import Bindings
-
-public struct ConnectionCloser {
-  public var close: () throws -> Void
-
-  public func callAsFunction() throws {
-    try close()
-  }
-}
-
-extension ConnectionCloser {
-  public static func live(
-    bindingsConnection: BindingsConnection
-  ) -> ConnectionCloser {
-    ConnectionCloser(close: bindingsConnection.close)
-  }
-
-  public static func live(
-    bindingsAuthenticatedConnection: BindingsAuthenticatedConnection
-  ) -> ConnectionCloser {
-    ConnectionCloser(close: bindingsAuthenticatedConnection.close)
-  }
-}
-
-#if DEBUG
-extension ConnectionCloser {
-  public static let failing = ConnectionCloser {
-    fatalError("Not implemented")
-  }
-}
-#endif
-- 
GitLab