Skip to content

Commit 8676c89

Browse files
authoredAug 26, 2024··
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

+2-3
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

+11-11
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

+1-1
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: [

‎Package@swift-5.7.swift

+1-1
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: [

‎Package@swift-5.8.swift

+1-1
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

+1-1
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

+7-8
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

+5-4
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

+1-1
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

+9-9
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> {

‎Sources/AWSLambdaRuntimeCore/LambdaConfiguration.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Dispatch
1616
import Logging
1717
import NIOCore
1818

19-
internal struct LambdaConfiguration: CustomStringConvertible {
19+
struct LambdaConfiguration: CustomStringConvertible {
2020
let general: General
2121
let lifecycle: Lifecycle
2222
let runtimeEngine: RuntimeEngine

‎Sources/AWSLambdaRuntimeCore/LambdaContext.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,18 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
197197
let remaining = deadline - now
198198
return .milliseconds(remaining)
199199
}
200-
200+
201201
var tasks: DetachedTasksContainer {
202202
self.storage.tasks
203203
}
204-
205-
204+
206205
/// Registers a background task that continues running after the synchronous invocation has completed.
207206
/// This is useful for tasks like flushing metrics or performing clean-up operations without delaying the response.
208207
///
209208
/// - Parameter body: An asynchronous closure that performs the background task.
210209
/// - Warning: You will be billed for the milliseconds of Lambda execution time until the very last
211210
/// background task is finished.
212-
public func detachedBackgroundTask(_ body: @escaping @Sendable () async -> ()) {
211+
public func detachedBackgroundTask(_ body: @escaping @Sendable () async -> Void) {
213212
Task {
214213
await self.tasks.detached(task: body)
215214
}

‎Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ extension LambdaHandler {
255255
/// unchecked sendable wrapper for the handler
256256
/// this is safe since lambda runtime is designed to calls the handler serially
257257
@usableFromInline
258-
internal struct UncheckedSendableHandler<Underlying: LambdaHandler, Event, Output>: @unchecked Sendable where Event == Underlying.Event, Output == Underlying.Output {
258+
struct UncheckedSendableHandler<Underlying: LambdaHandler, Event, Output>: @unchecked Sendable where Event == Underlying.Event, Output == Underlying.Output {
259259
@usableFromInline
260260
let underlying: Underlying
261261

‎Sources/AWSLambdaRuntimeCore/LambdaRequestID.swift

+32-32
Original file line numberDiff line numberDiff line change
@@ -217,38 +217,38 @@ extension LambdaRequestID {
217217
// are safe and we don't need Swifts safety guards.
218218

219219
characters.withUnsafeBufferPointer { lookup in
220-
string.0 = lookup[Int(uuid.0 >> 4)]
221-
string.1 = lookup[Int(uuid.0 & 0x0F)]
222-
string.2 = lookup[Int(uuid.1 >> 4)]
223-
string.3 = lookup[Int(uuid.1 & 0x0F)]
224-
string.4 = lookup[Int(uuid.2 >> 4)]
225-
string.5 = lookup[Int(uuid.2 & 0x0F)]
226-
string.6 = lookup[Int(uuid.3 >> 4)]
227-
string.7 = lookup[Int(uuid.3 & 0x0F)]
228-
string.9 = lookup[Int(uuid.4 >> 4)]
229-
string.10 = lookup[Int(uuid.4 & 0x0F)]
230-
string.11 = lookup[Int(uuid.5 >> 4)]
231-
string.12 = lookup[Int(uuid.5 & 0x0F)]
232-
string.14 = lookup[Int(uuid.6 >> 4)]
233-
string.15 = lookup[Int(uuid.6 & 0x0F)]
234-
string.16 = lookup[Int(uuid.7 >> 4)]
235-
string.17 = lookup[Int(uuid.7 & 0x0F)]
236-
string.19 = lookup[Int(uuid.8 >> 4)]
237-
string.20 = lookup[Int(uuid.8 & 0x0F)]
238-
string.21 = lookup[Int(uuid.9 >> 4)]
239-
string.22 = lookup[Int(uuid.9 & 0x0F)]
240-
string.24 = lookup[Int(uuid.10 >> 4)]
241-
string.25 = lookup[Int(uuid.10 & 0x0F)]
242-
string.26 = lookup[Int(uuid.11 >> 4)]
243-
string.27 = lookup[Int(uuid.11 & 0x0F)]
244-
string.28 = lookup[Int(uuid.12 >> 4)]
245-
string.29 = lookup[Int(uuid.12 & 0x0F)]
246-
string.30 = lookup[Int(uuid.13 >> 4)]
247-
string.31 = lookup[Int(uuid.13 & 0x0F)]
248-
string.32 = lookup[Int(uuid.14 >> 4)]
249-
string.33 = lookup[Int(uuid.14 & 0x0F)]
250-
string.34 = lookup[Int(uuid.15 >> 4)]
251-
string.35 = lookup[Int(uuid.15 & 0x0F)]
220+
string.0 = lookup[Int(self.uuid.0 >> 4)]
221+
string.1 = lookup[Int(self.uuid.0 & 0x0F)]
222+
string.2 = lookup[Int(self.uuid.1 >> 4)]
223+
string.3 = lookup[Int(self.uuid.1 & 0x0F)]
224+
string.4 = lookup[Int(self.uuid.2 >> 4)]
225+
string.5 = lookup[Int(self.uuid.2 & 0x0F)]
226+
string.6 = lookup[Int(self.uuid.3 >> 4)]
227+
string.7 = lookup[Int(self.uuid.3 & 0x0F)]
228+
string.9 = lookup[Int(self.uuid.4 >> 4)]
229+
string.10 = lookup[Int(self.uuid.4 & 0x0F)]
230+
string.11 = lookup[Int(self.uuid.5 >> 4)]
231+
string.12 = lookup[Int(self.uuid.5 & 0x0F)]
232+
string.14 = lookup[Int(self.uuid.6 >> 4)]
233+
string.15 = lookup[Int(self.uuid.6 & 0x0F)]
234+
string.16 = lookup[Int(self.uuid.7 >> 4)]
235+
string.17 = lookup[Int(self.uuid.7 & 0x0F)]
236+
string.19 = lookup[Int(self.uuid.8 >> 4)]
237+
string.20 = lookup[Int(self.uuid.8 & 0x0F)]
238+
string.21 = lookup[Int(self.uuid.9 >> 4)]
239+
string.22 = lookup[Int(self.uuid.9 & 0x0F)]
240+
string.24 = lookup[Int(self.uuid.10 >> 4)]
241+
string.25 = lookup[Int(self.uuid.10 & 0x0F)]
242+
string.26 = lookup[Int(self.uuid.11 >> 4)]
243+
string.27 = lookup[Int(self.uuid.11 & 0x0F)]
244+
string.28 = lookup[Int(self.uuid.12 >> 4)]
245+
string.29 = lookup[Int(self.uuid.12 & 0x0F)]
246+
string.30 = lookup[Int(self.uuid.13 >> 4)]
247+
string.31 = lookup[Int(self.uuid.13 & 0x0F)]
248+
string.32 = lookup[Int(self.uuid.14 >> 4)]
249+
string.33 = lookup[Int(self.uuid.14 & 0x0F)]
250+
string.34 = lookup[Int(self.uuid.15 >> 4)]
251+
string.35 = lookup[Int(self.uuid.15 & 0x0F)]
252252
}
253253

254254
return string

0 commit comments

Comments
 (0)
Please sign in to comment.