Skip to content

Commit 8676c89

Browse files
authored
apply swiftformat (#342)
* apply swiftformat * update dep on Swift Docc to v1.3.0 * force usage of swift docc plugin 1.3.0
1 parent 79fa2c2 commit 8676c89

23 files changed

+115
-118
lines changed

Examples/Foundation/Lambda.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ struct ExchangeRatesCalculator {
122122
monthIndex: Array<Date>.Index,
123123
currencies: [String],
124124
state: [Date: ExchangeRates],
125-
callback: @escaping ((Result<[Date: ExchangeRates], Swift.Error>) -> Void))
126-
{
125+
callback: @escaping ((Result<[Date: ExchangeRates], Swift.Error>) -> Void)) {
127126
if monthIndex == months.count {
128127
return callback(.success(state))
129128
}
@@ -182,7 +181,7 @@ struct ExchangeRatesCalculator {
182181
interval = nil
183182
}
184183

185-
let ratesByCurrencyCode: [String: Decimal?] = Dictionary(uniqueKeysWithValues: try currencyCodes.map {
184+
let ratesByCurrencyCode: [String: Decimal?] = try Dictionary(uniqueKeysWithValues: currencyCodes.map {
186185
let xpathCurrency = $0.replacingOccurrences(of: "'", with: "&apos;")
187186
if let rateString = try document.nodes(forXPath: "/exchangeRateMonthList/exchangeRate/currencyCode[text()='\(xpathCurrency)']/../rateNew/text()").first?.stringValue,
188187
// We must parse the decimal data using the UK locale, not the system one.

Examples/LocalDebugging/MyApp/MyApp/ContentView.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,35 @@ struct ContentView: View {
2323

2424
var body: some View {
2525
VStack(alignment: .leading, spacing: 20) {
26-
TextField("Username", text: $name)
27-
SecureField("Password", text: $password)
28-
let inputIncomplete = name.isEmpty || password.isEmpty
26+
TextField("Username", text: self.$name)
27+
SecureField("Password", text: self.$password)
28+
let inputIncomplete = self.name.isEmpty || self.password.isEmpty
2929
Button {
3030
Task {
31-
isLoading = true
31+
self.isLoading = true
3232
do {
33-
response = try await self.register()
33+
self.response = try await self.register()
3434
} catch {
35-
response = error.localizedDescription
35+
self.response = error.localizedDescription
3636
}
37-
isLoading = false
37+
self.isLoading = false
3838
}
3939
} label: {
4040
Text("Register")
4141
.padding()
4242
.foregroundColor(.white)
4343
.background(.black)
4444
.border(.black, width: 2)
45-
.opacity(isLoading ? 0 : 1)
45+
.opacity(self.isLoading ? 0 : 1)
4646
.overlay {
47-
if isLoading {
47+
if self.isLoading {
4848
ProgressView()
4949
}
5050
}
5151
}
52-
.disabled(inputIncomplete || isLoading)
52+
.disabled(inputIncomplete || self.isLoading)
5353
.opacity(inputIncomplete ? 0.5 : 1)
54-
Text(response)
54+
Text(self.response)
5555
}.padding(100)
5656
}
5757

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let package = Package(
2323
dependencies: [
2424
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.67.0")),
2525
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.5.4")),
26-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
26+
.package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.3.0"),
2727
],
2828
targets: [
2929
.target(name: "AWSLambdaRuntime", dependencies: [

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let package = Package(
2424
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")),
2525
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")),
2626
.package(url: "https://github.com/swift-server/swift-backtrace.git", .upToNextMajor(from: "1.2.3")),
27-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
27+
.package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.3.0"),
2828
],
2929
targets: [
3030
.target(name: "AWSLambdaRuntime", dependencies: [

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let package = Package(
2424
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")),
2525
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")),
2626
.package(url: "https://github.com/swift-server/swift-backtrace.git", .upToNextMajor(from: "1.2.3")),
27-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
27+
.package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.3.0"),
2828
],
2929
targets: [
3030
.target(name: "AWSLambdaRuntime", dependencies: [

Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct ErrorResponse: Hashable, Codable {
6666
}
6767

6868
extension ErrorResponse {
69-
internal func toJSONBytes() -> [UInt8] {
69+
func toJSONBytes() -> [UInt8] {
7070
var bytes = [UInt8]()
7171
bytes.append(UInt8(ascii: "{"))
7272
bytes.append(contentsOf: #""errorType":"#.utf8)

Sources/AWSLambdaRuntimeCore/DetachedTasks.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
import Foundation
15+
import Logging
1516
import NIOConcurrencyHelpers
1617
import NIOCore
17-
import Logging
1818

1919
/// A container that allows tasks to finish after a synchronous invocation
2020
/// has produced its response.
2121
actor DetachedTasksContainer: Sendable {
22-
2322
struct Context: Sendable {
2423
let eventLoop: EventLoop
2524
let logger: Logger
2625
}
27-
26+
2827
private var context: Context
2928
private var storage: [RegistrationKey: EventLoopFuture<Void>] = [:]
3029

@@ -40,17 +39,17 @@ actor DetachedTasksContainer: Sendable {
4039
/// - Returns: A `RegistrationKey` for the registered task.
4140
func detached(task: @Sendable @escaping () async -> Void) {
4241
let key = RegistrationKey()
43-
let promise = context.eventLoop.makePromise(of: Void.self)
42+
let promise = self.context.eventLoop.makePromise(of: Void.self)
4443
promise.completeWithTask(task)
45-
let task = promise.futureResult.always { [weak self] result in
44+
let task = promise.futureResult.always { [weak self] _ in
4645
guard let self else { return }
4746
Task {
4847
await self.removeTask(forKey: key)
4948
}
5049
}
5150
self.storage[key] = task
5251
}
53-
52+
5453
func removeTask(forKey key: RegistrationKey) {
5554
self.storage.removeValue(forKey: key)
5655
}
@@ -59,9 +58,9 @@ actor DetachedTasksContainer: Sendable {
5958
///
6059
/// - Returns: An `EventLoopFuture<Void>` that completes when all tasks have finished.
6160
func awaitAll() -> EventLoopFuture<Void> {
62-
let tasks = storage.values
61+
let tasks = self.storage.values
6362
if tasks.isEmpty {
64-
return context.eventLoop.makeSucceededVoidFuture()
63+
return self.context.eventLoop.makeSucceededVoidFuture()
6564
} else {
6665
let context = context
6766
return EventLoopFuture.andAllComplete(Array(tasks), on: context.eventLoop).flatMap { [weak self] in

Sources/AWSLambdaRuntimeCore/HTTPClient.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import NIOPosix
2020
/// A barebone HTTP client to interact with AWS Runtime Engine which is an HTTP server.
2121
/// Note that Lambda Runtime API dictate that only one requests runs at a time.
2222
/// This means we can avoid locks and other concurrency concern we would otherwise need to build into the client
23-
internal final class HTTPClient {
23+
final class HTTPClient {
2424
private let eventLoop: EventLoop
2525
private let configuration: LambdaConfiguration.RuntimeEngine
2626
private let targetHost: String
@@ -120,7 +120,7 @@ internal final class HTTPClient {
120120
}
121121
}
122122

123-
internal struct Request: Equatable {
123+
struct Request: Equatable {
124124
let url: String
125125
let method: HTTPMethod
126126
let targetHost: String
@@ -138,14 +138,14 @@ internal final class HTTPClient {
138138
}
139139
}
140140

141-
internal struct Response: Equatable {
141+
struct Response: Equatable {
142142
var version: HTTPVersion
143143
var status: HTTPResponseStatus
144144
var headers: HTTPHeaders
145145
var body: ByteBuffer?
146146
}
147147

148-
internal enum Errors: Error {
148+
enum Errors: Error {
149149
case connectionResetByPeer
150150
case timeout
151151
case cancelled
@@ -277,6 +277,7 @@ private final class LambdaChannelHandler: ChannelDuplexHandler {
277277
switch self.state {
278278
case .idle:
279279
break
280+
280281
case .running(let promise, let timeout):
281282
self.state = .idle
282283
timeout?.cancel()

Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension Lambda {
3636
/// - body: Code to run within the context of the mock server. Typically this would be a Lambda.run function call.
3737
///
3838
/// - note: This API is designed strictly for local testing and is behind a DEBUG flag
39-
internal static func withLocalServer<Value>(invocationEndpoint: String? = nil, _ body: @escaping () -> Value) throws -> Value {
39+
static func withLocalServer<Value>(invocationEndpoint: String? = nil, _ body: @escaping () -> Value) throws -> Value {
4040
let server = LocalLambda.Server(invocationEndpoint: invocationEndpoint)
4141
try server.start().wait()
4242
defer { try! server.stop() }

Sources/AWSLambdaRuntimeCore/Lambda.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public enum Lambda {
4040
/// - handlerType: The Handler to create and invoke.
4141
///
4242
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
43-
internal static func run<Handler: SimpleLambdaHandler>(
43+
static func run<Handler: SimpleLambdaHandler>(
4444
configuration: LambdaConfiguration = .init(),
4545
handlerType: Handler.Type
4646
) -> Result<Int, Error> {
47-
Self.run(configuration: configuration, handlerProvider: CodableSimpleLambdaHandler<Handler>.makeHandler(context:))
47+
self.run(configuration: configuration, handlerProvider: CodableSimpleLambdaHandler<Handler>.makeHandler(context:))
4848
}
4949

5050
/// Run a Lambda defined by implementing the ``LambdaHandler`` protocol.
@@ -56,11 +56,11 @@ public enum Lambda {
5656
/// - handlerType: The Handler to create and invoke.
5757
///
5858
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
59-
internal static func run<Handler: LambdaHandler>(
59+
static func run<Handler: LambdaHandler>(
6060
configuration: LambdaConfiguration = .init(),
6161
handlerType: Handler.Type
6262
) -> Result<Int, Error> {
63-
Self.run(configuration: configuration, handlerProvider: CodableLambdaHandler<Handler>.makeHandler(context:))
63+
self.run(configuration: configuration, handlerProvider: CodableLambdaHandler<Handler>.makeHandler(context:))
6464
}
6565

6666
/// Run a Lambda defined by implementing the ``EventLoopLambdaHandler`` protocol.
@@ -72,11 +72,11 @@ public enum Lambda {
7272
/// - handlerType: The Handler to create and invoke.
7373
///
7474
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
75-
internal static func run<Handler: EventLoopLambdaHandler>(
75+
static func run<Handler: EventLoopLambdaHandler>(
7676
configuration: LambdaConfiguration = .init(),
7777
handlerType: Handler.Type
7878
) -> Result<Int, Error> {
79-
Self.run(configuration: configuration, handlerProvider: CodableEventLoopLambdaHandler<Handler>.makeHandler(context:))
79+
self.run(configuration: configuration, handlerProvider: CodableEventLoopLambdaHandler<Handler>.makeHandler(context:))
8080
}
8181

8282
/// Run a Lambda defined by implementing the ``ByteBufferLambdaHandler`` protocol.
@@ -88,11 +88,11 @@ public enum Lambda {
8888
/// - handlerType: The Handler to create and invoke.
8989
///
9090
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
91-
internal static func run(
91+
static func run(
9292
configuration: LambdaConfiguration = .init(),
9393
handlerType: (some ByteBufferLambdaHandler).Type
9494
) -> Result<Int, Error> {
95-
Self.run(configuration: configuration, handlerProvider: handlerType.makeHandler(context:))
95+
self.run(configuration: configuration, handlerProvider: handlerType.makeHandler(context:))
9696
}
9797

9898
/// Run a Lambda defined by implementing the ``LambdaRuntimeHandler`` protocol.
@@ -101,7 +101,7 @@ public enum Lambda {
101101
/// - handlerProvider: A provider of the ``LambdaRuntimeHandler`` to invoke.
102102
///
103103
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
104-
internal static func run(
104+
static func run(
105105
configuration: LambdaConfiguration = .init(),
106106
handlerProvider: @escaping (LambdaInitializationContext) -> EventLoopFuture<some LambdaRuntimeHandler>
107107
) -> Result<Int, Error> {

0 commit comments

Comments
 (0)