diff --git a/Package.resolved b/Package.resolved index 2c0c1b3b..629c0bf1 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,15 +1,6 @@ { "object": { "pins": [ - { - "package": "AsyncObjects", - "repositoryURL": "https://github.com/SwiftyLab/AsyncObjects.git", - "state": { - "branch": null, - "revision": "93aacfba87d738ac94fb50c2a6768c43ec9d42eb", - "version": "2.1.0" - } - }, { "package": "BigInt", "repositoryURL": "https://github.com/attaswift/BigInt.git", @@ -33,8 +24,8 @@ "repositoryURL": "https://github.com/outfoxx/PotentCodables.git", "state": { "branch": null, - "revision": "583f1b04b89e36742255d05ef1d2e5961485811d", - "version": "3.2.0" + "revision": "660e33e84e00b9bf07bd41dd99ff800600e435e7", + "version": "3.5.0" } }, { @@ -46,6 +37,15 @@ "version": "2.1.1" } }, + { + "package": "Semaphore", + "repositoryURL": "https://github.com/groue/Semaphore.git", + "state": { + "branch": null, + "revision": "2543679282aa6f6c8ecf2138acd613ed20790bc2", + "version": "0.1.0" + } + }, { "package": "swift-collections", "repositoryURL": "https://github.com/apple/swift-collections.git", @@ -74,12 +74,12 @@ } }, { - "package": "URITemplate", + "package": "ScreamURITemplate", "repositoryURL": "https://github.com/SwiftScream/URITemplate.git", "state": { "branch": null, - "revision": "c36e52f4c10fe3cb86f4ba723bb2e69308ab5bbe", - "version": "2.1.0" + "revision": "3a6acca43ac7aa3f58474e6c8f686809b3660d6a", + "version": "4.0.0" } } ] diff --git a/Package.swift b/Package.swift index 5465850e..72b1d27c 100644 --- a/Package.swift +++ b/Package.swift @@ -21,10 +21,10 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/outfoxx/PotentCodables.git", .upToNextMinor(from: "3.2.0")), + .package(url: "https://github.com/outfoxx/PotentCodables.git", .upToNextMinor(from: "3.5.0")), .package(url: "https://github.com/sharplet/Regex.git", .upToNextMinor(from: "2.1.0")), - .package(url: "https://github.com/SwiftScream/URITemplate.git", .upToNextMinor(from: "2.1.0")), - .package(url: "https://github.com/SwiftyLab/AsyncObjects.git", .upToNextMinor(from: "2.1.0")) + .package(url: "https://github.com/SwiftScream/URITemplate.git", .upToNextMinor(from: "4.0.0")), + .package(url: "https://github.com/groue/Semaphore.git", .upToNextMinor(from: "0.1.0")) ], targets: [ .target( @@ -32,8 +32,8 @@ let package = Package( dependencies: [ "Regex", "PotentCodables", - "URITemplate", - "AsyncObjects" + .product(name: "ScreamURITemplate", package: "uritemplate"), + .product(name: "Semaphore", package: "semaphore") ] ), .target( diff --git a/Sources/Sunday/NetworkRequestAdapters.swift b/Sources/Sunday/NetworkRequestAdapters.swift index 4efc7573..854f3998 100644 --- a/Sources/Sunday/NetworkRequestAdapters.swift +++ b/Sources/Sunday/NetworkRequestAdapters.swift @@ -14,8 +14,8 @@ * limitations under the License. */ -import AsyncObjects import Foundation +import Semaphore /// Composing request adapter that applies another request adapter @@ -110,7 +110,7 @@ open class RefreshingHeaderTokenAuthorizingAdapter: NetworkRequestAdapter { } public func adapt(requestFactory: NetworkRequestFactory, urlRequest: URLRequest) async throws -> URLRequest { - try await lock.wait() + await lock.wait() defer { lock.signal() } if shouldRefresh { diff --git a/Sources/Sunday/URI.swift b/Sources/Sunday/URI.swift index c1fa42c7..bcb697a7 100644 --- a/Sources/Sunday/URI.swift +++ b/Sources/Sunday/URI.swift @@ -15,7 +15,7 @@ */ import Foundation -import URITemplate +import ScreamURITemplate public struct URI: Equatable, Hashable { diff --git a/Sources/Sunday/URITemplate.swift b/Sources/Sunday/URITemplate.swift index bf5b1662..1c5240e1 100644 --- a/Sources/Sunday/URITemplate.swift +++ b/Sources/Sunday/URITemplate.swift @@ -15,7 +15,7 @@ */ import Foundation -import URITemplate +import ScreamURITemplate public extension URI { @@ -89,32 +89,53 @@ public extension URI { for variableName in impl.variableNames { - switch parameters[variableName] { + let value = switch parameters[variableName] { case let value as VariableValue: - variables[variableName] = value + value case .some(.some(let value)): - guard let converted = encoders.firstSupported(value: value) else { - if let pathValue = value as? PathEncodable { - variables[variableName] = pathValue.pathDescription - continue - } - else if let losslessValue = value as? LosslessStringConvertible { - variables[variableName] = losslessValue.description - continue - } - else if let rawRepValue = value as? any RawRepresentable { - variables[variableName] = String(describing: rawRepValue.rawValue) - continue - } - throw Error.unsupportedParameterType(name: variableName, type: type(of: value)) - } - variables[variableName] = converted + value case nil: throw Error.missingParameterValue(name: variableName) default: throw Error.unsupportedParameterType(name: variableName, type: type(of: parameters[variableName])) } + guard let converted = encoders.firstSupported(value: value) else { + if let dictValue = value as? [String: StringVariableValue] { + variables[variableName] = dictValue + continue + } + else if let arrayValue = value as? [StringVariableValue] { + variables[variableName] = arrayValue + continue + } + else if let kvPairsValue = value as? KeyValuePairs { + variables[variableName] = kvPairsValue + continue + } + else if let stringValue = value as? StringVariableValue { + variables[variableName] = stringValue + continue + } + else if let varValue = value as? VariableValue { + variables[variableName] = varValue + continue + } + else if let pathValue = value as? PathEncodable { + variables[variableName] = pathValue.pathDescription + continue + } + else if let losslessValue = value as? LosslessStringConvertible { + variables[variableName] = losslessValue.description + continue + } + else if let rawRepValue = value as? any RawRepresentable { + variables[variableName] = String(describing: rawRepValue.rawValue) + continue + } + throw Error.unsupportedParameterType(name: variableName, type: type(of: value)) + } + variables[variableName] = converted } let processedUrl = try impl.process(variables: variables) diff --git a/Tests/SundayTests/URITemplatesTests.swift b/Tests/SundayTests/URITemplatesTests.swift index ecd15593..d3bc5806 100644 --- a/Tests/SundayTests/URITemplatesTests.swift +++ b/Tests/SundayTests/URITemplatesTests.swift @@ -15,7 +15,7 @@ */ @testable import Sunday -import URITemplate +import ScreamURITemplate import XCTest