Skip to content

Commit d803861

Browse files
committed
apply swift-format
1 parent 6227444 commit d803861

8 files changed

+97
-87
lines changed

Plugins/AWSLambdaPackager/PluginUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import Dispatch
16+
import Foundation
1617
import PackagePlugin
1718
import Synchronization
18-
import Foundation
1919

2020
@available(macOS 15.0, *)
2121
struct Utils {
@@ -47,7 +47,7 @@ struct Utils {
4747
let outputSync = DispatchGroup()
4848
let outputQueue = DispatchQueue(label: "AWSLambdaPackager.output")
4949
let unsafeTransfer = UnsafeTransfer(value: stdout)
50-
let outputHandler = { @Sendable (data: Data?) in
50+
let outputHandler = { @Sendable(data:Data?) in
5151
dispatchPrecondition(condition: .onQueue(outputQueue))
5252

5353
outputSync.enter()

Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,39 @@ enum ControlPlaneResponse: Hashable {
2828
case error(ErrorResponse)
2929
}
3030

31-
package struct InvocationMetadata: Hashable {
32-
package let requestID: String
33-
package let deadlineInMillisSinceEpoch: Int64
34-
package let invokedFunctionARN: String
35-
package let traceID: String
36-
package let clientContext: String?
37-
package let cognitoIdentity: String?
31+
package
32+
struct InvocationMetadata: Hashable {
33+
package let requestID: String
34+
package let deadlineInMillisSinceEpoch: Int64
35+
package let invokedFunctionARN: String
36+
package let traceID: String
37+
package let clientContext: String?
38+
package let cognitoIdentity: String?
3839

39-
package init(headers: HTTPHeaders) throws(LambdaRuntimeError) {
40-
guard let requestID = headers.first(name: AmazonHeaders.requestID), !requestID.isEmpty else {
41-
throw LambdaRuntimeError(code: .nextInvocationMissingHeaderRequestID)
42-
}
43-
44-
guard let deadline = headers.first(name: AmazonHeaders.deadline),
45-
let unixTimeInMilliseconds = Int64(deadline)
46-
else {
47-
throw LambdaRuntimeError(code: .nextInvocationMissingHeaderDeadline)
48-
}
40+
package init(headers: HTTPHeaders) throws
41+
(LambdaRuntimeError) {
42+
guard let requestID = headers.first(name: AmazonHeaders.requestID), !requestID.isEmpty else {
43+
throw LambdaRuntimeError(code: .nextInvocationMissingHeaderRequestID)
44+
}
4945

50-
guard let invokedFunctionARN = headers.first(name: AmazonHeaders.invokedFunctionARN) else {
51-
throw LambdaRuntimeError(code: .nextInvocationMissingHeaderInvokeFuctionARN)
52-
}
46+
guard let deadline = headers.first(name: AmazonHeaders.deadline),
47+
let unixTimeInMilliseconds = Int64(deadline)
48+
else {
49+
throw LambdaRuntimeError(code: .nextInvocationMissingHeaderDeadline)
50+
}
5351

54-
self.requestID = requestID
55-
self.deadlineInMillisSinceEpoch = unixTimeInMilliseconds
56-
self.invokedFunctionARN = invokedFunctionARN
57-
self.traceID =
58-
headers.first(name: AmazonHeaders.traceID) ?? "Root=\(AmazonHeaders.generateXRayTraceID());Sampled=0"
59-
self.clientContext = headers["Lambda-Runtime-Client-Context"].first
60-
self.cognitoIdentity = headers["Lambda-Runtime-Cognito-Identity"].first
52+
guard let invokedFunctionARN = headers.first(name: AmazonHeaders.invokedFunctionARN) else {
53+
throw LambdaRuntimeError(code: .nextInvocationMissingHeaderInvokeFuctionARN)
6154
}
55+
56+
self.requestID = requestID
57+
self.deadlineInMillisSinceEpoch = unixTimeInMilliseconds
58+
self.invokedFunctionARN = invokedFunctionARN
59+
self.traceID =
60+
headers.first(name: AmazonHeaders.traceID) ?? "Root=\(AmazonHeaders.generateXRayTraceID());Sampled=0"
61+
self.clientContext = headers["Lambda-Runtime-Client-Context"].first
62+
self.cognitoIdentity = headers["Lambda-Runtime-Cognito-Identity"].first
63+
}
6264
}
6365

6466
struct ErrorResponse: Hashable, Codable {

Sources/AWSLambdaRuntimeCore/Lambda.swift

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,38 @@ import ucrt
3030
#endif
3131

3232
public enum Lambda {
33-
package static func runLoop<RuntimeClient: LambdaRuntimeClientProtocol, Handler>(
34-
runtimeClient: RuntimeClient,
35-
handler: Handler,
36-
logger: Logger
37-
) async throws where Handler: StreamingLambdaHandler {
38-
var handler = handler
33+
package
34+
static func runLoop<RuntimeClient: LambdaRuntimeClientProtocol, Handler>(
35+
runtimeClient: RuntimeClient,
36+
handler: Handler,
37+
logger: Logger
38+
) async throws where Handler: StreamingLambdaHandler {
39+
var handler = handler
3940

40-
while !Task.isCancelled {
41-
let (invocation, writer) = try await runtimeClient.nextInvocation()
41+
while !Task.isCancelled {
42+
let (invocation, writer) = try await runtimeClient.nextInvocation()
4243

43-
do {
44-
try await handler.handle(
45-
invocation.event,
46-
responseWriter: writer,
47-
context: LambdaContext(
48-
requestID: invocation.metadata.requestID,
49-
traceID: invocation.metadata.traceID,
50-
invokedFunctionARN: invocation.metadata.invokedFunctionARN,
51-
deadline: DispatchWallTime(millisSinceEpoch: invocation.metadata.deadlineInMillisSinceEpoch),
52-
logger: logger
53-
)
44+
do {
45+
try await handler.handle(
46+
invocation.event,
47+
responseWriter: writer,
48+
context: LambdaContext(
49+
requestID: invocation.metadata.requestID,
50+
traceID: invocation.metadata.traceID,
51+
invokedFunctionARN: invocation.metadata.invokedFunctionARN,
52+
deadline: DispatchWallTime(millisSinceEpoch: invocation.metadata.deadlineInMillisSinceEpoch),
53+
logger: logger
5454
)
55-
} catch {
56-
try await writer.reportError(error)
57-
continue
58-
}
55+
)
56+
} catch {
57+
try await writer.reportError(error)
58+
continue
5959
}
6060
}
61+
}
6162

62-
/// The default EventLoop the Lambda is scheduled on.
63-
public static var defaultEventLoop: any EventLoop = NIOSingletons.posixEventLoopGroup.next()
63+
/// The default EventLoop the Lambda is scheduled on.
64+
public static var defaultEventLoop: any EventLoop = NIOSingletons.posixEventLoopGroup.next()
6465
}
6566

6667
// MARK: - Public API

Sources/AWSLambdaRuntimeCore/LambdaContext.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,20 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
120120
"\(Self.self)(requestID: \(self.requestID), traceID: \(self.traceID), invokedFunctionARN: \(self.invokedFunctionARN), cognitoIdentity: \(self.cognitoIdentity ?? "nil"), clientContext: \(self.clientContext ?? "nil"), deadline: \(self.deadline))"
121121
}
122122

123-
/// This interface is not part of the public API and must not be used by adopters. This API is not part of semver versioning.
124-
package static func __forTestsOnly(
125-
requestID: String,
126-
traceID: String,
127-
invokedFunctionARN: String,
128-
timeout: DispatchTimeInterval,
129-
logger: Logger
130-
) -> LambdaContext {
131-
LambdaContext(
132-
requestID: requestID,
133-
traceID: traceID,
134-
invokedFunctionARN: invokedFunctionARN,
135-
deadline: .now() + timeout,
136-
logger: logger
137-
)
138-
}
139-
}
123+
/// This interface is not part of the public API and must not be used by adopters. This API is not part of semver versioning.
124+
package
125+
static func __forTestsOnly(
126+
requestID: String,
127+
traceID: String,
128+
invokedFunctionARN: String,
129+
timeout: DispatchTimeInterval,
130+
logger: Logger
131+
) -> LambdaContext {
132+
LambdaContext(
133+
requestID: requestID,
134+
traceID: traceID,
135+
invokedFunctionARN: invokedFunctionARN,
136+
deadline: .now() + timeout,
137+
logger: logger
138+
)
139+
}}

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@
1414

1515
import Foundation
1616
import Logging
17-
import NIOCore
1817
import NIOConcurrencyHelpers
18+
import NIOCore
1919

2020
// We need `@unchecked` Sendable here, as `NIOLockedValueBox` does not understand `sending` today.
2121
// We don't want to use `NIOLockedValueBox` here anyway. We would love to use Mutex here, but this
2222
// sadly crashes the compiler today.
2323
public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: StreamingLambdaHandler {
2424
// TODO: We want to change this to Mutex as soon as this doesn't crash the Swift compiler on Linux anymore
25-
let handlerMutex: NIOLockedValueBox<Optional<Handler>>
25+
let handlerMutex: NIOLockedValueBox<Handler?>
2626
let logger: Logger
2727
let eventLoop: EventLoop
2828

2929
public init(
30-
handler: sending Handler,
30+
handler: sending
31+
Handler
32+
,
3133
eventLoop: EventLoop = Lambda.defaultEventLoop,
3234
logger: Logger = Logger(label: "LambdaRuntime")
3335
) {

Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
462462
]
463463
}
464464

465-
func nextInvocation(isolation: isolated (any Actor)? = #isolation) async throws -> Invocation {
465+
func nextInvocation(isolation: isolated (any Actor)? = #isolation) async throws -> Invocation {
466466
switch self.state {
467467
case .connected(let context, .idle):
468468
return try await withCheckedThrowingContinuation {
@@ -484,7 +484,8 @@ private final class LambdaChannelHandler<Delegate: LambdaChannelHandlerDelegate>
484484
}
485485

486486
func reportError(
487-
isolation: isolated (any Actor)? = #isolation,
487+
isolation: isolated (any Actor)? =
488+
#isolation,
488489
_ error: any Error,
489490
requestID: String
490491
) async throws {

Sources/AWSLambdaRuntimeCore/LambdaRuntimeClientProtocol.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,27 @@
1414

1515
import NIOCore
1616

17-
package protocol LambdaRuntimeClientResponseStreamWriter: LambdaResponseStreamWriter {
17+
package
18+
protocol LambdaRuntimeClientResponseStreamWriter: LambdaResponseStreamWriter {
1819
func write(_ buffer: ByteBuffer) async throws
1920
func finish() async throws
2021
func writeAndFinish(_ buffer: ByteBuffer) async throws
2122
func reportError(_ error: any Error) async throws
2223
}
2324

24-
package protocol LambdaRuntimeClientProtocol {
25+
package
26+
protocol LambdaRuntimeClientProtocol {
2527
associatedtype Writer: LambdaRuntimeClientResponseStreamWriter
2628

2729
func nextInvocation() async throws -> (Invocation, Writer)
2830
}
2931

30-
package struct Invocation {
31-
package var metadata: InvocationMetadata
32-
package var event: ByteBuffer
32+
package
33+
struct Invocation {
34+
package var metadata: InvocationMetadata
35+
package var event: ByteBuffer
3336

34-
package init(metadata: InvocationMetadata, event: ByteBuffer) {
37+
package init(metadata: InvocationMetadata, event: ByteBuffer) {
3538
self.metadata = metadata
3639
self.event = event
3740
}

Sources/AWSLambdaRuntimeCore/LambdaRuntimeError.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
package struct LambdaRuntimeError: Error {
16-
package enum Code {
15+
package
16+
struct LambdaRuntimeError: Error {
17+
package enum Code {
1718
case closingRuntimeClient
1819

1920
case connectionToControlPlaneLost
@@ -34,12 +35,12 @@ package struct LambdaRuntimeError: Error {
3435
case invalidPort
3536
}
3637

37-
package init(code: Code, underlying: (any Error)? = nil) {
38+
package init(code: Code, underlying: (any Error)? = nil) {
3839
self.code = code
3940
self.underlying = underlying
4041
}
4142

42-
package var code: Code
43-
package var underlying: (any Error)?
43+
package var code: Code
44+
package var underlying: (any Error)?
4445

4546
}

0 commit comments

Comments
 (0)