diff --git a/Package.swift b/Package.swift index 17d592ad..03aebe37 100644 --- a/Package.swift +++ b/Package.swift @@ -41,7 +41,7 @@ let package = Package( .target(name: "TIFoundationUtils", dependencies: ["TISwiftUtils"], path: "TIFoundationUtils/Sources"), .target(name: "TIKeychainUtils", dependencies: ["TIFoundationUtils", "KeychainAccess"], path: "TIKeychainUtils/Sources"), .target(name: "TITableKitUtils", dependencies: ["TIUIElements", "TableKit"], path: "TITableKitUtils/Sources"), - .target(name: "TINetworking", dependencies: ["Alamofire"], path: "TINetworking/Sources"), + .target(name: "TINetworking", dependencies: ["TISwiftUtils", "Alamofire"], path: "TINetworking/Sources"), // MARK: - Elements diff --git a/TINetworking/Sources/Mapping/BodyContent/ApplicationJsonBodyContent.swift b/TINetworking/Sources/Mapping/BodyContent/ApplicationJsonBodyContent.swift index ab839bfa..5e4a1734 100644 --- a/TINetworking/Sources/Mapping/BodyContent/ApplicationJsonBodyContent.swift +++ b/TINetworking/Sources/Mapping/BodyContent/ApplicationJsonBodyContent.swift @@ -1,7 +1,8 @@ import Foundation +import TISwiftUtils open class ApplicationJsonBodyContent: BaseContent, BodyContent { - private let encodingClosure: () throws -> Data + private let encodingClosure: ThrowableResultClosure public init(body: Body, jsonEncoder: JSONEncoder = JSONEncoder()) where Body: Encodable { encodingClosure = { diff --git a/TINetworking/Sources/Mapping/OneOfMapping/AnyTypeMapping.swift b/TINetworking/Sources/Mapping/OneOfMapping/AnyTypeMapping.swift index 9a13b1fd..02a2181b 100644 --- a/TINetworking/Sources/Mapping/OneOfMapping/AnyTypeMapping.swift +++ b/TINetworking/Sources/Mapping/OneOfMapping/AnyTypeMapping.swift @@ -1,10 +1,12 @@ +import TISwiftUtils + public struct AnyTypeMapping { - private let mappingClosure: () -> Result + private let mappingClosure: ResultClosure> public let type: Any.Type public init(decoder: Decoder, - transform: @escaping (T) -> R) { + transform: @escaping Closure) { type = T.self diff --git a/TINetworking/Sources/Mapping/ResponseContent/MapResponseContent.swift b/TINetworking/Sources/Mapping/ResponseContent/MapResponseContent.swift index eda890e4..04e53ded 100644 --- a/TINetworking/Sources/Mapping/ResponseContent/MapResponseContent.swift +++ b/TINetworking/Sources/Mapping/ResponseContent/MapResponseContent.swift @@ -1,11 +1,12 @@ import Foundation +import TISwiftUtils public struct MapResponseContent: ResponseContent { - private let decodeClosure: (Data) throws -> Model + private let decodeClosure: ThrowableClosure public let mediaTypeName: String - public init(responseContent: C, transform: @escaping (C.Model) -> Model) { + public init(responseContent: C, transform: @escaping Closure) { mediaTypeName = responseContent.mediaTypeName decodeClosure = { transform(try responseContent.decodeResponse(data: $0)) @@ -18,7 +19,7 @@ public struct MapResponseContent: ResponseContent { } public extension ResponseContent { - typealias TransformClosure = (Model) -> T + typealias TransformClosure = Closure func map(_ transform: @escaping TransformClosure) -> MapResponseContent { .init(responseContent: self, transform: transform) @@ -26,11 +27,11 @@ public extension ResponseContent { } public extension JSONDecoder { - func responseContent(_ tranfsorm: @escaping (T) -> R) -> MapResponseContent { + func responseContent(_ tranfsorm: @escaping Closure) -> MapResponseContent { responseContent().map(tranfsorm) } - func decoding(to tranfsorm: @escaping (T) -> R) -> (Data) throws -> R { + func decoding(to tranfsorm: @escaping Closure) -> ThrowableClosure { responseContent(tranfsorm).decodeResponse } } diff --git a/TINetworking/Sources/Response/ResponseType+Decoding.swift b/TINetworking/Sources/Response/ResponseType+Decoding.swift index 558a76d6..b1ef2228 100644 --- a/TINetworking/Sources/Response/ResponseType+Decoding.swift +++ b/TINetworking/Sources/Response/ResponseType+Decoding.swift @@ -1,9 +1,10 @@ import Foundation +import TISwiftUtils public typealias StatusCodeMimeType = (statusCode: Int, mimeType: String?) public typealias StatusCodesMimeType = (statusCodes: Set, mimeType: String?) -public typealias DecodingClosure = (Data) throws -> R +public typealias DecodingClosure = ThrowableClosure public extension ResponseType { func decode(mapping: [KeyValueTuple>]) -> Result {