Skip to content

Commit

Permalink
swift format
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Feb 17, 2024
1 parent c229280 commit 90ca705
Show file tree
Hide file tree
Showing 32 changed files with 112 additions and 112 deletions.
2 changes: 1 addition & 1 deletion Benchmarks/Sources/HBPerformance/EmbeddedApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public struct HBEmbeddedApplication {
// write request
let requestHead = HTTPRequestHead(version: .init(major: 1, minor: 1), method: method, uri: uri, headers: headers)
try writeInbound(.head(requestHead))
if let body = body {
if let body {
try self.writeInbound(.body(body))
}
try self.writeInbound(.end(nil))
Expand Down
2 changes: 1 addition & 1 deletion Benchmarks/Sources/HBPerformance/RunBenchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//
import BenchmarkSupport

public func runBenchmark<B: BenchmarkWrapper>(benchmark: BenchmarkSupport.Benchmark, running: B) throws {
public func runBenchmark(benchmark: BenchmarkSupport.Benchmark, running: some BenchmarkWrapper) throws {
try running.setUp()
defer {
running.tearDown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension HBPersistDriver {
/// - value: Codable value to store
/// - expires: If non-nil defines time that value will expire
/// - request: Request making this call
public func create<Object: Codable>(key: String, value: Object, expires: TimeAmount? = nil, request: HBRequest) async throws {
public func create(key: String, value: some Codable, expires: TimeAmount? = nil, request: HBRequest) async throws {
try await self.create(key: key, value: value, expires: expires, request: request).get()
}

Expand All @@ -30,7 +30,7 @@ extension HBPersistDriver {
/// - value: Codable value to store
/// - expires: If non-nil defines time that value will expire
/// - request: Request making this call
public func set<Object: Codable>(key: String, value: Object, expires: TimeAmount? = nil, request: HBRequest) async throws {
public func set(key: String, value: some Codable, expires: TimeAmount? = nil, request: HBRequest) async throws {
try await self.set(key: key, value: value, expires: expires, request: request).get()
}

Expand Down Expand Up @@ -61,7 +61,7 @@ extension HBRequest.Persist {
/// - key: key string
/// - value: value
/// - expires: time key/value pair will expire
public func create<Object: Codable>(key: String, value: Object, expires: TimeAmount? = nil) async throws {
public func create(key: String, value: some Codable, expires: TimeAmount? = nil) async throws {
try await self.request.application.persist.driver.create(key: key, value: value, expires: expires, request: self.request)
}

Expand All @@ -70,7 +70,7 @@ extension HBRequest.Persist {
/// - key: key string
/// - value: value
/// - expires: time key/value pair will expire
public func set<Object: Codable>(key: String, value: Object, expires: TimeAmount? = nil) async throws {
public func set(key: String, value: some Codable, expires: TimeAmount? = nil) async throws {
try await self.request.application.persist.driver.set(key: key, value: value, expires: expires, request: self.request)
}

Expand Down
36 changes: 18 additions & 18 deletions Sources/Hummingbird/AsyncAwaitSupport/Router+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,62 @@ import NIOCore
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBRouterMethods {
/// GET path for async closure returning type conforming to ResponseEncodable
@discardableResult public func get<Output: HBResponseGenerator>(
@discardableResult public func get(
_ path: String = "",
options: HBRouterMethodOptions = [],
use handler: @escaping (HBRequest) async throws -> Output
use handler: @escaping (HBRequest) async throws -> some HBResponseGenerator
) -> Self {
return on(path, method: .GET, options: options, use: handler)
}

/// PUT path for async closure returning type conforming to ResponseEncodable
@discardableResult public func put<Output: HBResponseGenerator>(
@discardableResult public func put(
_ path: String = "",
options: HBRouterMethodOptions = [],
use handler: @escaping (HBRequest) async throws -> Output
use handler: @escaping (HBRequest) async throws -> some HBResponseGenerator
) -> Self {
return on(path, method: .PUT, options: options, use: handler)
}

/// DELETE path for async closure returning type conforming to ResponseEncodable
@discardableResult public func delete<Output: HBResponseGenerator>(
@discardableResult public func delete(
_ path: String = "",
options: HBRouterMethodOptions = [],
use handler: @escaping (HBRequest) async throws -> Output
use handler: @escaping (HBRequest) async throws -> some HBResponseGenerator
) -> Self {
return on(path, method: .DELETE, options: options, use: handler)
}

/// HEAD path for async closure returning type conforming to ResponseEncodable
@discardableResult public func head<Output: HBResponseGenerator>(
@discardableResult public func head(
_ path: String = "",
options: HBRouterMethodOptions = [],
use handler: @escaping (HBRequest) async throws -> Output
use handler: @escaping (HBRequest) async throws -> some HBResponseGenerator
) -> Self {
return on(path, method: .HEAD, options: options, use: handler)
}

/// POST path for async closure returning type conforming to ResponseEncodable
@discardableResult public func post<Output: HBResponseGenerator>(
@discardableResult public func post(
_ path: String = "",
options: HBRouterMethodOptions = [],
use handler: @escaping (HBRequest) async throws -> Output
use handler: @escaping (HBRequest) async throws -> some HBResponseGenerator
) -> Self {
return on(path, method: .POST, options: options, use: handler)
}

/// PATCH path for async closure returning type conforming to ResponseEncodable
@discardableResult public func patch<Output: HBResponseGenerator>(
@discardableResult public func patch(
_ path: String = "",
options: HBRouterMethodOptions = [],
use handler: @escaping (HBRequest) async throws -> Output
use handler: @escaping (HBRequest) async throws -> some HBResponseGenerator
) -> Self {
return on(path, method: .PATCH, options: options, use: handler)
}

public static func constructResponder<Output: HBResponseGenerator>(
public static func constructResponder(
options: HBRouterMethodOptions = [],
use closure: @escaping (HBRequest) async throws -> Output
use closure: @escaping (HBRequest) async throws -> some HBResponseGenerator
) -> HBResponder {
return HBAsyncCallbackResponder { request in
var request = request
Expand All @@ -95,11 +95,11 @@ extension HBRouterMethods {
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBRouterBuilder {
/// Add path for closure returning type conforming to ResponseFutureEncodable
@discardableResult public func on<Output: HBResponseGenerator>(
@discardableResult public func on(
_ path: String,
method: HTTPMethod,
options: HBRouterMethodOptions = [],
use closure: @escaping (HBRequest) async throws -> Output
use closure: @escaping (HBRequest) async throws -> some HBResponseGenerator
) -> Self {
let responder = Self.constructResponder(options: options, use: closure)
add(path, method: method, responder: responder)
Expand All @@ -110,11 +110,11 @@ extension HBRouterBuilder {
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBRouterGroup {
/// Add path for closure returning type conforming to ResponseFutureEncodable
@discardableResult public func on<Output: HBResponseGenerator>(
@discardableResult public func on(
_ path: String = "",
method: HTTPMethod,
options: HBRouterMethodOptions = [],
use closure: @escaping (HBRequest) async throws -> Output
use closure: @escaping (HBRequest) async throws -> some HBResponseGenerator
) -> Self {
let responder = Self.constructResponder(options: options, use: closure)
let path = self.combinePaths(self.path, path)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Hummingbird/Codable/CodableProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public protocol HBRequestDecoder {

/// Default encoder. Outputs request with the swift string description of object
struct NullEncoder: HBResponseEncoder {
func encode<T: Encodable>(_ value: T, from request: HBRequest) throws -> HBResponse {
func encode(_ value: some Encodable, from request: HBRequest) throws -> HBResponse {
return HBResponse(
status: .ok,
headers: ["content-type": "text/plain; charset=utf-8"],
Expand Down
8 changes: 4 additions & 4 deletions Sources/Hummingbird/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension HBApplication {
self.threadPoolSize = threadPoolSize
self.noHTTPServer = noHTTPServer

if let logLevel = logLevel {
if let logLevel {
self.logLevel = logLevel
} else if let logLevel = env.get("LOG_LEVEL") {
self.logLevel = Logger.Level(rawValue: logLevel) ?? .info
Expand Down Expand Up @@ -169,7 +169,7 @@ extension HBApplication {
self.threadPoolSize = threadPoolSize
self.noHTTPServer = noHTTPServer

if let logLevel = logLevel {
if let logLevel {

Check warning on line 172 in Sources/Hummingbird/Configuration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Hummingbird/Configuration.swift#L172

Added line #L172 was not covered by tests
self.logLevel = logLevel
} else if let logLevel = env.get("LOG_LEVEL") {
self.logLevel = Logger.Level(rawValue: logLevel) ?? .info
Expand Down Expand Up @@ -223,7 +223,7 @@ extension HBApplication {
self.threadPoolSize = threadPoolSize
self.noHTTPServer = noHTTPServer

if let logLevel = logLevel {
if let logLevel {

Check warning on line 226 in Sources/Hummingbird/Configuration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Hummingbird/Configuration.swift#L226

Added line #L226 was not covered by tests
self.logLevel = logLevel
} else if let logLevel = env.get("LOG_LEVEL") {
self.logLevel = Logger.Level(rawValue: logLevel) ?? .info
Expand Down Expand Up @@ -277,7 +277,7 @@ extension HBApplication {
self.threadPoolSize = threadPoolSize
self.noHTTPServer = noHTTPServer

if let logLevel = logLevel {
if let logLevel {

Check warning on line 280 in Sources/Hummingbird/Configuration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Hummingbird/Configuration.swift#L280

Added line #L280 was not covered by tests
self.logLevel = logLevel
} else if let logLevel = env.get("LOG_LEVEL") {
self.logLevel = Logger.Level(rawValue: logLevel) ?? .info
Expand Down
4 changes: 2 additions & 2 deletions Sources/Hummingbird/Extensions/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public struct HBExtensions<ParentObject> {

/// Return if extension has been set
@inlinable
public func exists<Type>(_ key: KeyPath<ParentObject, Type>) -> Bool {
public func exists(_ key: KeyPath<ParentObject, some Any>) -> Bool {
self.items[key.hashValue]?.value != nil
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public struct HBSendableExtensions<ParentObject>: Sendable {

/// Return if extension has been set
@inlinable
public func exists<Type: Sendable>(_ key: KeyPath<ParentObject, Type>) -> Bool {
public func exists(_ key: KeyPath<ParentObject, some Sendable>) -> Bool {

Check warning on line 149 in Sources/Hummingbird/Extensions/Extensions.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Hummingbird/Extensions/Extensions.swift#L149

Added line #L149 was not covered by tests
self.items[key.hashValue]?.value != nil
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Hummingbird/HTTP/MediaType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public struct HBMediaType: Sendable, CustomStringConvertible {
break
}
}
if let category = category,
let subCategory = subCategory
if let category,
let subCategory
{
self.type = category
self.subType = subCategory.lowercased()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Hummingbird/HTTP/URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ extension HBParameters {
/// Initialize parameters from parser struct
/// - Parameter query: parser holding query strings
init(fromQuery query: HBParser?) {
guard var query = query else {
guard var query else {
self.parameters = .init()
return
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Hummingbird/Middleware/TracingMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct HBTracingMiddleware: HBMiddleware {
///
/// - Parameter recordingHeaders: A list of HTTP header names to be recorded as span attributes. By default, no headers
/// are being recorded.
public init<C: Collection>(recordingHeaders headerNamesToRecord: C) where C.Element == String {
public init(recordingHeaders headerNamesToRecord: some Collection<String>) {
self.headerNamesToRecord = Set(headerNamesToRecord.map(RecordingHeader.init))
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Hummingbird/Router/RouterBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,23 @@ public final class HBRouterBuilder: HBRouterMethods {
}

/// Add path for closure returning type conforming to ResponseFutureEncodable
@discardableResult public func on<Output: HBResponseGenerator>(
@discardableResult public func on(
_ path: String,
method: HTTPMethod,
options: HBRouterMethodOptions = [],
use closure: @escaping (HBRequest) throws -> Output
use closure: @escaping (HBRequest) throws -> some HBResponseGenerator
) -> Self {
let responder = Self.constructResponder(options: options, use: closure)
self.add(path, method: method, responder: responder)
return self
}

/// Add path for closure returning type conforming to ResponseFutureEncodable
@discardableResult public func on<Output: HBResponseGenerator>(
@discardableResult public func on(
_ path: String,
method: HTTPMethod,
options: HBRouterMethodOptions = [],
use closure: @escaping (HBRequest) -> EventLoopFuture<Output>
use closure: @escaping (HBRequest) -> EventLoopFuture<some HBResponseGenerator>
) -> Self {
let responder = Self.constructResponder(options: options, use: closure)
self.add(path, method: method, responder: responder)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Hummingbird/Router/RouterGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public struct HBRouterGroup: HBRouterMethods {
}

/// Add path for closure returning type conforming to ResponseFutureEncodable
@discardableResult public func on<Output: HBResponseGenerator>(
@discardableResult public func on(
_ path: String = "",
method: HTTPMethod,
options: HBRouterMethodOptions = [],
use closure: @escaping (HBRequest) throws -> Output
use closure: @escaping (HBRequest) throws -> some HBResponseGenerator
) -> Self {
let responder = Self.constructResponder(options: options, use: closure)
let path = self.combinePaths(self.path, path)
Expand All @@ -71,11 +71,11 @@ public struct HBRouterGroup: HBRouterMethods {
}

/// Add path for closure returning type conforming to ResponseFutureEncodable
@discardableResult public func on<Output: HBResponseGenerator>(
@discardableResult public func on(
_ path: String = "",
method: HTTPMethod,
options: HBRouterMethodOptions = [],
use closure: @escaping (HBRequest) -> EventLoopFuture<Output>
use closure: @escaping (HBRequest) -> EventLoopFuture<some HBResponseGenerator>
) -> Self {
let responder = Self.constructResponder(options: options, use: closure)
let path = self.combinePaths(self.path, path)
Expand Down
Loading

0 comments on commit 90ca705

Please sign in to comment.