diff --git a/Sources/Helpers/AsyncSequence+.swift b/Sources/Helpers/AsyncSequence+.swift index 01c53064..c7a6d7c5 100644 --- a/Sources/Helpers/AsyncSequence+.swift +++ b/Sources/Helpers/AsyncSequence+.swift @@ -34,7 +34,8 @@ extension AsyncSequence { @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) extension AsyncSequence { public func first(beforeTimeout duration: Duration, using clock: any Clock) async throws - -> Element { + -> Element + { try await first(beforeTimeout: duration, using: clock, where: { _ in true }) } diff --git a/Sources/Networking/Components/Authentication/Authentication.swift b/Sources/Networking/Components/Authentication/Authentication.swift index c4d04939..53f8ca8a 100644 --- a/Sources/Networking/Components/Authentication/Authentication.swift +++ b/Sources/Networking/Components/Authentication/Authentication.swift @@ -2,7 +2,8 @@ import Helpers extension NetworkingComponent { public func authenticated(with delegate: Delegate) - -> some NetworkingComponent { + -> some NetworkingComponent + { checkedStatusCode().modified(Authentication(delegate: delegate)) } } diff --git a/Sources/Networking/Components/Authentication/BearerAuthentication.swift b/Sources/Networking/Components/Authentication/BearerAuthentication.swift index a76aefe5..aa1a48f6 100644 --- a/Sources/Networking/Components/Authentication/BearerAuthentication.swift +++ b/Sources/Networking/Components/Authentication/BearerAuthentication.swift @@ -5,7 +5,8 @@ extension AuthenticationMethod { } public struct BearerCredentials: Hashable, Sendable, Codable, HTTPRequestDataOption, - AuthenticatingCredentials { + AuthenticatingCredentials +{ public static let method: AuthenticationMethod = .bearer public static let defaultOption: Self? = nil diff --git a/Sources/Networking/Components/Authentication/HeaderBasedAuthentication.swift b/Sources/Networking/Components/Authentication/HeaderBasedAuthentication.swift index fd23f6d3..f9bd93b4 100644 --- a/Sources/Networking/Components/Authentication/HeaderBasedAuthentication.swift +++ b/Sources/Networking/Components/Authentication/HeaderBasedAuthentication.swift @@ -35,9 +35,10 @@ public struct HeaderBasedAuthentication { } private func performCredentialFetch(for request: HTTPRequestData) async throws -> Credentials { - logger?.info( - "🔐 Fetching credentials for \(Credentials.method.rawValue, privacy: .public) authorization method" - ) + logger? + .info( + "🔐 Fetching credentials for \(Credentials.method.rawValue, privacy: .public) authorization method" + ) do { let credentials = try await delegate.fetch(for: request) set(state: .authorized(credentials)) @@ -49,7 +50,8 @@ public struct HeaderBasedAuthentication { } func refresh(unauthorized credentials: Credentials, from response: HTTPResponseData) - async throws -> Credentials { + async throws -> Credentials + { if case let .fetching(task) = state { return try await task.value } @@ -65,9 +67,10 @@ public struct HeaderBasedAuthentication { unauthorized credentials: Credentials, from response: HTTPResponseData ) async throws -> Credentials { - logger?.info( - "🔑 Refreshing credentials for \(Credentials.method.rawValue, privacy: .public) authorization method" - ) + logger? + .info( + "🔑 Refreshing credentials for \(Credentials.method.rawValue, privacy: .public) authorization method" + ) do { let refreshed = try await delegate.refresh(unauthorized: credentials, from: response) set(state: .authorized(refreshed)) diff --git a/Sources/Networking/Components/Metrics.swift b/Sources/Networking/Components/Metrics.swift index f261e616..6d3b4abe 100644 --- a/Sources/Networking/Components/Metrics.swift +++ b/Sources/Networking/Components/Metrics.swift @@ -60,7 +60,7 @@ public struct NetworkingInstrumentClient { extension [ElapsedTimeMeasurement] { var total: Duration { - return map(\.duration).reduce(.zero, +) + map(\.duration).reduce(.zero, +) } } diff --git a/Sources/Networking/Components/Retry.swift b/Sources/Networking/Components/Retry.swift index 3acbeadb..7c5e1399 100644 --- a/Sources/Networking/Components/Retry.swift +++ b/Sources/Networking/Components/Retry.swift @@ -55,7 +55,7 @@ actor RetryData { func send(upstream: NetworkingComponent, request: HTTPRequestData) -> ResponseStream< HTTPResponseData > { - return ResponseStream { continuation in + ResponseStream { continuation in Task { var progress = BytesReceived() do { @@ -216,8 +216,7 @@ public protocol RetryingStrategy { } public struct BackoffRetryStrategy: RetryingStrategy { - private var block: - (HTTPRequestData, [Result], Date, Calendar) -> Duration? + private var block: (HTTPRequestData, [Result], Date, Calendar) -> Duration? public init( block: @escaping (HTTPRequestData, [Result], Date, Calendar) -> Duration? @@ -241,7 +240,7 @@ public struct BackoffRetryStrategy: RetryingStrategy { let rate: Double = 2.0 return .init { _, attempts, _, _ in guard attempts.count < maxAttemptCount else { return nil } - let delay: Double = (interval * pow(rate, Double(attempts.count))) + .random(in: 0...0.001) + let delay: Double = (interval * pow(rate, Double(attempts.count))) + .random(in: 0 ... 0.001) return min(.seconds(delay), maxDelay) } } diff --git a/Sources/Networking/Core/ActiveRequests.swift b/Sources/Networking/Core/ActiveRequests.swift index 529b78a7..180f11ee 100644 --- a/Sources/Networking/Core/ActiveRequests.swift +++ b/Sources/Networking/Core/ActiveRequests.swift @@ -29,7 +29,8 @@ public actor ActiveRequests { await self.removeStream(for: request) }) } - }.shared() + } + .shared() active[Key(id: request.id)] = Value(request: request, stream: shared) return shared diff --git a/Sources/Networking/Core/HTTPRequestData.swift b/Sources/Networking/Core/HTTPRequestData.swift index d89d3cb6..21082022 100644 --- a/Sources/Networking/Core/HTTPRequestData.swift +++ b/Sources/Networking/Core/HTTPRequestData.swift @@ -134,10 +134,10 @@ extension HTTPRequestData: Equatable { && lhs.body == rhs.body && lhs.request == rhs.request && lhs.options.allSatisfy { key, lhs in - return lhs.isEqualTo(rhs.options[key]?.value) + lhs.isEqualTo(rhs.options[key]?.value) } && rhs.options.allSatisfy { key, rhs in - return rhs.isEqualTo(lhs.options[key]?.value) + rhs.isEqualTo(lhs.options[key]?.value) } } } @@ -161,10 +161,10 @@ public func ~= (lhs: HTTPRequestData, rhs: HTTPRequestData) -> Bool { lhs.body == rhs.body && (lhs.request == rhs.request) && lhs.options.allSatisfy { key, lhs in - return lhs.isEqualTo(rhs.options[key]?.value) + lhs.isEqualTo(rhs.options[key]?.value) } && rhs.options.allSatisfy { key, rhs in - return rhs.isEqualTo(lhs.options[key]?.value) + rhs.isEqualTo(lhs.options[key]?.value) } } diff --git a/Sources/Networking/Core/HTTPResponseData.swift b/Sources/Networking/Core/HTTPResponseData.swift index 639a191f..91d6a223 100644 --- a/Sources/Networking/Core/HTTPResponseData.swift +++ b/Sources/Networking/Core/HTTPResponseData.swift @@ -50,7 +50,8 @@ public struct HTTPResponseData: Sendable { extension HTTPResponseData { public subscript(metadata metadataType: Metadata.Type) - -> Metadata.Value { + -> Metadata.Value + { get { let id = ObjectIdentifier(metadataType) guard let container = metadata[id], let value = container.value as? Metadata.Value else { @@ -86,10 +87,10 @@ extension HTTPResponseData: Equatable { && lhs.data == rhs.data && lhs._response == rhs._response && lhs.metadata.allSatisfy { key, lhs in - return lhs.isEqualTo(rhs.metadata[key]?.value) + lhs.isEqualTo(rhs.metadata[key]?.value) } && rhs.metadata.allSatisfy { key, rhs in - return rhs.isEqualTo(lhs.metadata[key]?.value) + rhs.isEqualTo(lhs.metadata[key]?.value) } } } @@ -111,9 +112,9 @@ extension HTTPResponseData: CustomDebugStringConvertible { if let contentType = self.headerFields[.contentType] { debugDescription += "\(contentType.description)" #if hasFeature(BareSlashRegexLiterals) - let regex = /(json)/ + let regex = /(json)/ #else - let regex = #/(json)/# + let regex = #/(json)/# #endif if contentType.contains(regex) { let dataDescription = String(decoding: data, as: UTF8.self) diff --git a/Sources/Networking/Core/NetworkingModifier.swift b/Sources/Networking/Core/NetworkingModifier.swift index 47fda726..62f2f0a1 100644 --- a/Sources/Networking/Core/NetworkingModifier.swift +++ b/Sources/Networking/Core/NetworkingModifier.swift @@ -15,7 +15,8 @@ extension NetworkingComponent { } private struct Modified: - NetworkingComponent { + NetworkingComponent +{ let upstream: Upstream let modifier: Modifier init(upstream: Upstream, modifier: Modifier) { diff --git a/Sources/TestSupport/StubbedResponse.swift b/Sources/TestSupport/StubbedResponse.swift index 4e849886..b603fcef 100644 --- a/Sources/TestSupport/StubbedResponse.swift +++ b/Sources/TestSupport/StubbedResponse.swift @@ -46,7 +46,7 @@ public struct StubbedResponseStream: Equatable, Sendable { continuation.finish() case .throwing: let bytesReceived = bytes.expected / 4 - for _ in 0..<2 { + for _ in 0 ..< 2 { await clock.advance(by: .seconds(2)) bytes.receiveBytes(count: bytesReceived) continuation.yield(.progress(bytes)) @@ -55,7 +55,7 @@ public struct StubbedResponseStream: Equatable, Sendable { case let .uniform(steps: steps, interval: interval): let bytesReceived = bytes.expected / Int64(steps) - for _ in 0..: @unchecked - Sendable { + Sendable +{ public typealias Fetch = @Sendable (HTTPRequestData) async throws -> Credentials public typealias Refresh = @Sendable (Credentials, HTTPResponseData) async throws -> Credentials diff --git a/Tests/NetworkingTests/Components/Authentication/AuthenticationTests.swift b/Tests/NetworkingTests/Components/Authentication/AuthenticationTests.swift index 4c4cd5a0..4fa7a05b 100644 --- a/Tests/NetworkingTests/Components/Authentication/AuthenticationTests.swift +++ b/Tests/NetworkingTests/Components/Authentication/AuthenticationTests.swift @@ -40,9 +40,9 @@ final class AuthenticationTests: XCTestCase { try await withMainSerialExecutor { try await withThrowingTaskGroup(of: HTTPResponseData.self) { group in - for _ in 0..<4 { + for _ in 0 ..< 4 { group.addTask { - return try await network.data(copy) + try await network.data(copy) } } diff --git a/Tests/NetworkingTests/Components/DuplicatesRemovedTests.swift b/Tests/NetworkingTests/Components/DuplicatesRemovedTests.swift index ee553342..ec7b37fb 100644 --- a/Tests/NetworkingTests/Components/DuplicatesRemovedTests.swift +++ b/Tests/NetworkingTests/Components/DuplicatesRemovedTests.swift @@ -33,7 +33,7 @@ final class DuplicatesRemovedTests: XCTestCase { .duplicatesRemoved() try await withThrowingTaskGroup(of: HTTPResponseData.self) { group in - for _ in 0..<4 { + for _ in 0 ..< 4 { group.addTask { try await network.data(request1) } diff --git a/Tests/NetworkingTests/Components/RetryTests.swift b/Tests/NetworkingTests/Components/RetryTests.swift index 45c2f099..560e4455 100644 --- a/Tests/NetworkingTests/Components/RetryTests.swift +++ b/Tests/NetworkingTests/Components/RetryTests.swift @@ -77,26 +77,29 @@ final class RetryTests: XCTestCase { let request = HTTPRequestData(id: .init("1"), authority: "example.com") XCTAssertTrue(request.supportsRetryingRequests) let strategy = request.retryingStrategy - var delay = await strategy?.retryDelay( - request: request, - after: [.failure("Some Error")], - date: Date(), - calendar: .current - ) + var delay = await strategy? + .retryDelay( + request: request, + after: [.failure("Some Error")], + date: Date(), + calendar: .current + ) XCTAssertEqual(delay, .seconds(3)) - delay = await strategy?.retryDelay( - request: request, - after: [.failure("Some Error"), .failure("Some Error")], - date: Date(), - calendar: .current - ) + delay = await strategy? + .retryDelay( + request: request, + after: [.failure("Some Error"), .failure("Some Error")], + date: Date(), + calendar: .current + ) XCTAssertEqual(delay, .seconds(3)) - delay = await strategy?.retryDelay( - request: request, - after: [.failure("Some Error"), .failure("Some Error"), .failure("Some Error")], - date: Date(), - calendar: .current - ) + delay = await strategy? + .retryDelay( + request: request, + after: [.failure("Some Error"), .failure("Some Error"), .failure("Some Error")], + date: Date(), + calendar: .current + ) XCTAssertNil(delay) } } diff --git a/Tests/NetworkingTests/Components/ThrottledTests.swift b/Tests/NetworkingTests/Components/ThrottledTests.swift index 4ed34775..211e65eb 100644 --- a/Tests/NetworkingTests/Components/ThrottledTests.swift +++ b/Tests/NetworkingTests/Components/ThrottledTests.swift @@ -23,7 +23,7 @@ final class ThrottledTests: XCTestCase { .throttled(max: 5) try await withThrowingTaskGroup(of: HTTPResponseData.self) { group in - for _ in 0..<100 { + for _ in 0 ..< 100 { group.addTask { try await network.data(HTTPRequestData(authority: "example.com")) }