diff --git a/Examples/Foundation/Lambda.swift b/Examples/Foundation/Lambda.swift index 660574a1..959c8e94 100644 --- a/Examples/Foundation/Lambda.swift +++ b/Examples/Foundation/Lambda.swift @@ -122,8 +122,7 @@ struct ExchangeRatesCalculator { monthIndex: Array.Index, currencies: [String], state: [Date: ExchangeRates], - callback: @escaping ((Result<[Date: ExchangeRates], Swift.Error>) -> Void)) - { + callback: @escaping ((Result<[Date: ExchangeRates], Swift.Error>) -> Void)) { if monthIndex == months.count { return callback(.success(state)) } @@ -182,7 +181,7 @@ struct ExchangeRatesCalculator { interval = nil } - let ratesByCurrencyCode: [String: Decimal?] = Dictionary(uniqueKeysWithValues: try currencyCodes.map { + let ratesByCurrencyCode: [String: Decimal?] = try Dictionary(uniqueKeysWithValues: currencyCodes.map { let xpathCurrency = $0.replacingOccurrences(of: "'", with: "'") if let rateString = try document.nodes(forXPath: "/exchangeRateMonthList/exchangeRate/currencyCode[text()='\(xpathCurrency)']/../rateNew/text()").first?.stringValue, // We must parse the decimal data using the UK locale, not the system one. diff --git a/Examples/LocalDebugging/MyApp/MyApp/ContentView.swift b/Examples/LocalDebugging/MyApp/MyApp/ContentView.swift index 4c7d3158..46f9d5a7 100644 --- a/Examples/LocalDebugging/MyApp/MyApp/ContentView.swift +++ b/Examples/LocalDebugging/MyApp/MyApp/ContentView.swift @@ -23,18 +23,18 @@ struct ContentView: View { var body: some View { VStack(alignment: .leading, spacing: 20) { - TextField("Username", text: $name) - SecureField("Password", text: $password) - let inputIncomplete = name.isEmpty || password.isEmpty + TextField("Username", text: self.$name) + SecureField("Password", text: self.$password) + let inputIncomplete = self.name.isEmpty || self.password.isEmpty Button { Task { - isLoading = true + self.isLoading = true do { - response = try await self.register() + self.response = try await self.register() } catch { - response = error.localizedDescription + self.response = error.localizedDescription } - isLoading = false + self.isLoading = false } } label: { Text("Register") @@ -42,16 +42,16 @@ struct ContentView: View { .foregroundColor(.white) .background(.black) .border(.black, width: 2) - .opacity(isLoading ? 0 : 1) + .opacity(self.isLoading ? 0 : 1) .overlay { - if isLoading { + if self.isLoading { ProgressView() } } } - .disabled(inputIncomplete || isLoading) + .disabled(inputIncomplete || self.isLoading) .opacity(inputIncomplete ? 0.5 : 1) - Text(response) + Text(self.response) }.padding(100) } diff --git a/Package.swift b/Package.swift index b1bfd98e..4e625ba6 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.67.0")), .package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.5.4")), - .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), + .package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.3.0"), ], targets: [ .target(name: "AWSLambdaRuntime", dependencies: [ diff --git a/Package@swift-5.7.swift b/Package@swift-5.7.swift index a4559656..d217b198 100644 --- a/Package@swift-5.7.swift +++ b/Package@swift-5.7.swift @@ -24,7 +24,7 @@ let package = Package( .package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")), .package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")), .package(url: "https://github.com/swift-server/swift-backtrace.git", .upToNextMajor(from: "1.2.3")), - .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), + .package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.3.0"), ], targets: [ .target(name: "AWSLambdaRuntime", dependencies: [ diff --git a/Package@swift-5.8.swift b/Package@swift-5.8.swift index a4559656..d217b198 100644 --- a/Package@swift-5.8.swift +++ b/Package@swift-5.8.swift @@ -24,7 +24,7 @@ let package = Package( .package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")), .package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")), .package(url: "https://github.com/swift-server/swift-backtrace.git", .upToNextMajor(from: "1.2.3")), - .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), + .package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.3.0"), ], targets: [ .target(name: "AWSLambdaRuntime", dependencies: [ diff --git a/Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift b/Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift index 411dc5ad..5c089a5c 100644 --- a/Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift +++ b/Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift @@ -66,7 +66,7 @@ struct ErrorResponse: Hashable, Codable { } extension ErrorResponse { - internal func toJSONBytes() -> [UInt8] { + func toJSONBytes() -> [UInt8] { var bytes = [UInt8]() bytes.append(UInt8(ascii: "{")) bytes.append(contentsOf: #""errorType":"#.utf8) diff --git a/Sources/AWSLambdaRuntimeCore/DetachedTasks.swift b/Sources/AWSLambdaRuntimeCore/DetachedTasks.swift index f06750bf..d684ffe7 100644 --- a/Sources/AWSLambdaRuntimeCore/DetachedTasks.swift +++ b/Sources/AWSLambdaRuntimeCore/DetachedTasks.swift @@ -12,19 +12,18 @@ // //===----------------------------------------------------------------------===// import Foundation +import Logging import NIOConcurrencyHelpers import NIOCore -import Logging /// A container that allows tasks to finish after a synchronous invocation /// has produced its response. actor DetachedTasksContainer: Sendable { - struct Context: Sendable { let eventLoop: EventLoop let logger: Logger } - + private var context: Context private var storage: [RegistrationKey: EventLoopFuture] = [:] @@ -40,9 +39,9 @@ actor DetachedTasksContainer: Sendable { /// - Returns: A `RegistrationKey` for the registered task. func detached(task: @Sendable @escaping () async -> Void) { let key = RegistrationKey() - let promise = context.eventLoop.makePromise(of: Void.self) + let promise = self.context.eventLoop.makePromise(of: Void.self) promise.completeWithTask(task) - let task = promise.futureResult.always { [weak self] result in + let task = promise.futureResult.always { [weak self] _ in guard let self else { return } Task { await self.removeTask(forKey: key) @@ -50,7 +49,7 @@ actor DetachedTasksContainer: Sendable { } self.storage[key] = task } - + func removeTask(forKey key: RegistrationKey) { self.storage.removeValue(forKey: key) } @@ -59,9 +58,9 @@ actor DetachedTasksContainer: Sendable { /// /// - Returns: An `EventLoopFuture` that completes when all tasks have finished. func awaitAll() -> EventLoopFuture { - let tasks = storage.values + let tasks = self.storage.values if tasks.isEmpty { - return context.eventLoop.makeSucceededVoidFuture() + return self.context.eventLoop.makeSucceededVoidFuture() } else { let context = context return EventLoopFuture.andAllComplete(Array(tasks), on: context.eventLoop).flatMap { [weak self] in diff --git a/Sources/AWSLambdaRuntimeCore/HTTPClient.swift b/Sources/AWSLambdaRuntimeCore/HTTPClient.swift index 7e724485..c5cf91e0 100644 --- a/Sources/AWSLambdaRuntimeCore/HTTPClient.swift +++ b/Sources/AWSLambdaRuntimeCore/HTTPClient.swift @@ -20,7 +20,7 @@ import NIOPosix /// A barebone HTTP client to interact with AWS Runtime Engine which is an HTTP server. /// Note that Lambda Runtime API dictate that only one requests runs at a time. /// This means we can avoid locks and other concurrency concern we would otherwise need to build into the client -internal final class HTTPClient { +final class HTTPClient { private let eventLoop: EventLoop private let configuration: LambdaConfiguration.RuntimeEngine private let targetHost: String @@ -120,7 +120,7 @@ internal final class HTTPClient { } } - internal struct Request: Equatable { + struct Request: Equatable { let url: String let method: HTTPMethod let targetHost: String @@ -138,14 +138,14 @@ internal final class HTTPClient { } } - internal struct Response: Equatable { + struct Response: Equatable { var version: HTTPVersion var status: HTTPResponseStatus var headers: HTTPHeaders var body: ByteBuffer? } - internal enum Errors: Error { + enum Errors: Error { case connectionResetByPeer case timeout case cancelled @@ -277,6 +277,7 @@ private final class LambdaChannelHandler: ChannelDuplexHandler { switch self.state { case .idle: break + case .running(let promise, let timeout): self.state = .idle timeout?.cancel() diff --git a/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift index 1f8c9e0f..7c91870f 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift @@ -36,7 +36,7 @@ extension Lambda { /// - body: Code to run within the context of the mock server. Typically this would be a Lambda.run function call. /// /// - note: This API is designed strictly for local testing and is behind a DEBUG flag - internal static func withLocalServer(invocationEndpoint: String? = nil, _ body: @escaping () -> Value) throws -> Value { + static func withLocalServer(invocationEndpoint: String? = nil, _ body: @escaping () -> Value) throws -> Value { let server = LocalLambda.Server(invocationEndpoint: invocationEndpoint) try server.start().wait() defer { try! server.stop() } diff --git a/Sources/AWSLambdaRuntimeCore/Lambda.swift b/Sources/AWSLambdaRuntimeCore/Lambda.swift index f499d581..def18c35 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda.swift @@ -40,11 +40,11 @@ public enum Lambda { /// - handlerType: The Handler to create and invoke. /// /// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine. - internal static func run( + static func run( configuration: LambdaConfiguration = .init(), handlerType: Handler.Type ) -> Result { - Self.run(configuration: configuration, handlerProvider: CodableSimpleLambdaHandler.makeHandler(context:)) + self.run(configuration: configuration, handlerProvider: CodableSimpleLambdaHandler.makeHandler(context:)) } /// Run a Lambda defined by implementing the ``LambdaHandler`` protocol. @@ -56,11 +56,11 @@ public enum Lambda { /// - handlerType: The Handler to create and invoke. /// /// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine. - internal static func run( + static func run( configuration: LambdaConfiguration = .init(), handlerType: Handler.Type ) -> Result { - Self.run(configuration: configuration, handlerProvider: CodableLambdaHandler.makeHandler(context:)) + self.run(configuration: configuration, handlerProvider: CodableLambdaHandler.makeHandler(context:)) } /// Run a Lambda defined by implementing the ``EventLoopLambdaHandler`` protocol. @@ -72,11 +72,11 @@ public enum Lambda { /// - handlerType: The Handler to create and invoke. /// /// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine. - internal static func run( + static func run( configuration: LambdaConfiguration = .init(), handlerType: Handler.Type ) -> Result { - Self.run(configuration: configuration, handlerProvider: CodableEventLoopLambdaHandler.makeHandler(context:)) + self.run(configuration: configuration, handlerProvider: CodableEventLoopLambdaHandler.makeHandler(context:)) } /// Run a Lambda defined by implementing the ``ByteBufferLambdaHandler`` protocol. @@ -88,11 +88,11 @@ public enum Lambda { /// - handlerType: The Handler to create and invoke. /// /// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine. - internal static func run( + static func run( configuration: LambdaConfiguration = .init(), handlerType: (some ByteBufferLambdaHandler).Type ) -> Result { - Self.run(configuration: configuration, handlerProvider: handlerType.makeHandler(context:)) + self.run(configuration: configuration, handlerProvider: handlerType.makeHandler(context:)) } /// Run a Lambda defined by implementing the ``LambdaRuntimeHandler`` protocol. @@ -101,7 +101,7 @@ public enum Lambda { /// - handlerProvider: A provider of the ``LambdaRuntimeHandler`` to invoke. /// /// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine. - internal static func run( + static func run( configuration: LambdaConfiguration = .init(), handlerProvider: @escaping (LambdaInitializationContext) -> EventLoopFuture ) -> Result { diff --git a/Sources/AWSLambdaRuntimeCore/LambdaConfiguration.swift b/Sources/AWSLambdaRuntimeCore/LambdaConfiguration.swift index 33d056f8..a1b739dd 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaConfiguration.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaConfiguration.swift @@ -16,7 +16,7 @@ import Dispatch import Logging import NIOCore -internal struct LambdaConfiguration: CustomStringConvertible { +struct LambdaConfiguration: CustomStringConvertible { let general: General let lifecycle: Lifecycle let runtimeEngine: RuntimeEngine diff --git a/Sources/AWSLambdaRuntimeCore/LambdaContext.swift b/Sources/AWSLambdaRuntimeCore/LambdaContext.swift index 943c4e5f..83737d92 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaContext.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaContext.swift @@ -197,19 +197,18 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable { let remaining = deadline - now return .milliseconds(remaining) } - + var tasks: DetachedTasksContainer { self.storage.tasks } - - + /// Registers a background task that continues running after the synchronous invocation has completed. /// This is useful for tasks like flushing metrics or performing clean-up operations without delaying the response. /// /// - Parameter body: An asynchronous closure that performs the background task. /// - Warning: You will be billed for the milliseconds of Lambda execution time until the very last /// background task is finished. - public func detachedBackgroundTask(_ body: @escaping @Sendable () async -> ()) { + public func detachedBackgroundTask(_ body: @escaping @Sendable () async -> Void) { Task { await self.tasks.detached(task: body) } diff --git a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift index 3a7e3c27..a64f28e5 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift @@ -255,7 +255,7 @@ extension LambdaHandler { /// unchecked sendable wrapper for the handler /// this is safe since lambda runtime is designed to calls the handler serially @usableFromInline -internal struct UncheckedSendableHandler: @unchecked Sendable where Event == Underlying.Event, Output == Underlying.Output { +struct UncheckedSendableHandler: @unchecked Sendable where Event == Underlying.Event, Output == Underlying.Output { @usableFromInline let underlying: Underlying diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRequestID.swift b/Sources/AWSLambdaRuntimeCore/LambdaRequestID.swift index 86178ff4..13cb7e19 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRequestID.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRequestID.swift @@ -217,38 +217,38 @@ extension LambdaRequestID { // are safe and we don't need Swifts safety guards. characters.withUnsafeBufferPointer { lookup in - string.0 = lookup[Int(uuid.0 >> 4)] - string.1 = lookup[Int(uuid.0 & 0x0F)] - string.2 = lookup[Int(uuid.1 >> 4)] - string.3 = lookup[Int(uuid.1 & 0x0F)] - string.4 = lookup[Int(uuid.2 >> 4)] - string.5 = lookup[Int(uuid.2 & 0x0F)] - string.6 = lookup[Int(uuid.3 >> 4)] - string.7 = lookup[Int(uuid.3 & 0x0F)] - string.9 = lookup[Int(uuid.4 >> 4)] - string.10 = lookup[Int(uuid.4 & 0x0F)] - string.11 = lookup[Int(uuid.5 >> 4)] - string.12 = lookup[Int(uuid.5 & 0x0F)] - string.14 = lookup[Int(uuid.6 >> 4)] - string.15 = lookup[Int(uuid.6 & 0x0F)] - string.16 = lookup[Int(uuid.7 >> 4)] - string.17 = lookup[Int(uuid.7 & 0x0F)] - string.19 = lookup[Int(uuid.8 >> 4)] - string.20 = lookup[Int(uuid.8 & 0x0F)] - string.21 = lookup[Int(uuid.9 >> 4)] - string.22 = lookup[Int(uuid.9 & 0x0F)] - string.24 = lookup[Int(uuid.10 >> 4)] - string.25 = lookup[Int(uuid.10 & 0x0F)] - string.26 = lookup[Int(uuid.11 >> 4)] - string.27 = lookup[Int(uuid.11 & 0x0F)] - string.28 = lookup[Int(uuid.12 >> 4)] - string.29 = lookup[Int(uuid.12 & 0x0F)] - string.30 = lookup[Int(uuid.13 >> 4)] - string.31 = lookup[Int(uuid.13 & 0x0F)] - string.32 = lookup[Int(uuid.14 >> 4)] - string.33 = lookup[Int(uuid.14 & 0x0F)] - string.34 = lookup[Int(uuid.15 >> 4)] - string.35 = lookup[Int(uuid.15 & 0x0F)] + string.0 = lookup[Int(self.uuid.0 >> 4)] + string.1 = lookup[Int(self.uuid.0 & 0x0F)] + string.2 = lookup[Int(self.uuid.1 >> 4)] + string.3 = lookup[Int(self.uuid.1 & 0x0F)] + string.4 = lookup[Int(self.uuid.2 >> 4)] + string.5 = lookup[Int(self.uuid.2 & 0x0F)] + string.6 = lookup[Int(self.uuid.3 >> 4)] + string.7 = lookup[Int(self.uuid.3 & 0x0F)] + string.9 = lookup[Int(self.uuid.4 >> 4)] + string.10 = lookup[Int(self.uuid.4 & 0x0F)] + string.11 = lookup[Int(self.uuid.5 >> 4)] + string.12 = lookup[Int(self.uuid.5 & 0x0F)] + string.14 = lookup[Int(self.uuid.6 >> 4)] + string.15 = lookup[Int(self.uuid.6 & 0x0F)] + string.16 = lookup[Int(self.uuid.7 >> 4)] + string.17 = lookup[Int(self.uuid.7 & 0x0F)] + string.19 = lookup[Int(self.uuid.8 >> 4)] + string.20 = lookup[Int(self.uuid.8 & 0x0F)] + string.21 = lookup[Int(self.uuid.9 >> 4)] + string.22 = lookup[Int(self.uuid.9 & 0x0F)] + string.24 = lookup[Int(self.uuid.10 >> 4)] + string.25 = lookup[Int(self.uuid.10 & 0x0F)] + string.26 = lookup[Int(self.uuid.11 >> 4)] + string.27 = lookup[Int(self.uuid.11 & 0x0F)] + string.28 = lookup[Int(self.uuid.12 >> 4)] + string.29 = lookup[Int(self.uuid.12 & 0x0F)] + string.30 = lookup[Int(self.uuid.13 >> 4)] + string.31 = lookup[Int(self.uuid.13 & 0x0F)] + string.32 = lookup[Int(self.uuid.14 >> 4)] + string.33 = lookup[Int(self.uuid.14 & 0x0F)] + string.34 = lookup[Int(self.uuid.15 >> 4)] + string.35 = lookup[Int(self.uuid.15 & 0x0F)] } return string diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift b/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift index 87457f43..f2fcaa22 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift @@ -17,7 +17,7 @@ import Logging import NIOCore /// LambdaRunner manages the Lambda runtime workflow, or business logic. -internal final class LambdaRunner { +final class LambdaRunner { private let runtimeClient: LambdaRuntimeClient private let eventLoop: EventLoop private let allocator: ByteBufferAllocator @@ -105,7 +105,7 @@ internal final class LambdaRunner { // Do we want to await the tasks in this case? let promise = context.eventLoop.makePromise(of: Void.self) promise.completeWithTask { - return try await context.tasks.awaitAll().get() + try await context.tasks.awaitAll().get() } return promise.futureResult }.map { _ in context } diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index c570a0b3..5349c5f8 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -204,7 +204,7 @@ public final class LambdaRuntime { case shuttingdown case shutdown - internal var order: Int { + var order: Int { switch self { case .idle: return 0 diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift index bcc65736..6fd0ac50 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift @@ -21,7 +21,7 @@ import NIOHTTP1 /// * /runtime/invocation/response /// * /runtime/invocation/error /// * /runtime/init/error -internal struct LambdaRuntimeClient { +struct LambdaRuntimeClient { private let eventLoop: EventLoop private let allocator = ByteBufferAllocator() private let httpClient: HTTPClient @@ -124,7 +124,7 @@ internal struct LambdaRuntimeClient { } } -internal enum LambdaRuntimeError: Error { +enum LambdaRuntimeError: Error { case badStatusCode(HTTPResponseStatus) case upstreamError(String) case invocationMissingHeader(String) @@ -134,10 +134,10 @@ internal enum LambdaRuntimeError: Error { } extension LambdaRuntimeClient { - internal static let defaultHeaders = HTTPHeaders([("user-agent", "Swift-Lambda/Unknown")]) + static let defaultHeaders = HTTPHeaders([("user-agent", "Swift-Lambda/Unknown")]) /// These headers must be sent along an invocation or initialization error report - internal static let errorHeaders = HTTPHeaders([ + static let errorHeaders = HTTPHeaders([ ("user-agent", "Swift-Lambda/Unknown"), ("lambda-runtime-function-error-type", "Unhandled"), ]) diff --git a/Sources/AWSLambdaRuntimeCore/Terminator.swift b/Sources/AWSLambdaRuntimeCore/Terminator.swift index cba8fd99..650b2a1d 100644 --- a/Sources/AWSLambdaRuntimeCore/Terminator.swift +++ b/Sources/AWSLambdaRuntimeCore/Terminator.swift @@ -56,7 +56,7 @@ public final class LambdaTerminator { /// - eventLoop: The `EventLoop` to run the termination on. /// /// - Returns: An `EventLoopFuture` with the result of the termination cycle. - internal func terminate(eventLoop: EventLoop) -> EventLoopFuture { + func terminate(eventLoop: EventLoop) -> EventLoopFuture { func terminate(_ iterator: IndexingIterator<[(name: String, handler: Handler)]>, errors: [Error], promise: EventLoopPromise) { var iterator = iterator guard let handler = iterator.next()?.handler else { diff --git a/Sources/AWSLambdaRuntimeCore/Utils.swift b/Sources/AWSLambdaRuntimeCore/Utils.swift index 9924a05b..7d53c5eb 100644 --- a/Sources/AWSLambdaRuntimeCore/Utils.swift +++ b/Sources/AWSLambdaRuntimeCore/Utils.swift @@ -15,7 +15,7 @@ import Dispatch import NIOPosix -internal enum Consts { +enum Consts { static let apiPrefix = "/2018-06-01" static let invocationURLPrefix = "\(apiPrefix)/runtime/invocation" static let getNextInvocationURLSuffix = "/next" @@ -27,7 +27,7 @@ internal enum Consts { } /// AWS Lambda HTTP Headers, used to populate the `LambdaContext` object. -internal enum AmazonHeaders { +enum AmazonHeaders { static let requestID = "Lambda-Runtime-Aws-Request-Id" static let traceID = "Lambda-Runtime-Trace-Id" static let clientContext = "X-Amz-Client-Context" @@ -37,7 +37,7 @@ internal enum AmazonHeaders { } /// Helper function to trap signals -internal func trap(signal sig: Signal, handler: @escaping (Signal) -> Void) -> DispatchSourceSignal { +func trap(signal sig: Signal, handler: @escaping (Signal) -> Void) -> DispatchSourceSignal { let signalSource = DispatchSource.makeSignalSource(signal: sig.rawValue, queue: DispatchQueue.global()) signal(sig.rawValue, SIG_IGN) signalSource.setEventHandler(handler: { @@ -48,7 +48,7 @@ internal func trap(signal sig: Signal, handler: @escaping (Signal) -> Void) -> D return signalSource } -internal enum Signal: Int32 { +enum Signal: Int32 { case HUP = 1 case INT = 2 case QUIT = 3 @@ -59,14 +59,14 @@ internal enum Signal: Int32 { } extension DispatchWallTime { - internal init(millisSinceEpoch: Int64) { + init(millisSinceEpoch: Int64) { let nanoSinceEpoch = UInt64(millisSinceEpoch) * 1_000_000 let seconds = UInt64(nanoSinceEpoch / 1_000_000_000) let nanoseconds = nanoSinceEpoch - (seconds * 1_000_000_000) self.init(timespec: timespec(tv_sec: Int(seconds), tv_nsec: Int(nanoseconds))) } - internal var millisSinceEpoch: Int64 { + var millisSinceEpoch: Int64 { Int64(bitPattern: self.rawValue) / -1_000_000 } } @@ -117,7 +117,7 @@ extension AmazonHeaders { /// # References /// - [Generating trace IDs](https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids) /// - [Tracing header](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader) - internal static func generateXRayTraceID() -> String { + static func generateXRayTraceID() -> String { // The version number, that is, 1. let version: UInt = 1 // The time of the original request, in Unix epoch time, in 8 hexadecimal digits. diff --git a/Sources/MockServer/main.swift b/Sources/MockServer/main.swift index 9b995bd5..d0e73152 100644 --- a/Sources/MockServer/main.swift +++ b/Sources/MockServer/main.swift @@ -17,7 +17,7 @@ import NIOCore import NIOHTTP1 import NIOPosix -internal struct MockServer { +struct MockServer { private let group: EventLoopGroup private let host: String private let port: Int @@ -48,7 +48,7 @@ internal struct MockServer { } } -internal final class HTTPHandler: ChannelInboundHandler { +final class HTTPHandler: ChannelInboundHandler { public typealias InboundIn = HTTPServerRequestPart public typealias OutboundOut = HTTPServerResponsePart @@ -134,12 +134,12 @@ internal final class HTTPHandler: ChannelInboundHandler { } } -internal enum ServerError: Error { +enum ServerError: Error { case notReady case cantBind } -internal enum AmazonHeaders { +enum AmazonHeaders { static let requestID = "Lambda-Runtime-Aws-Request-Id" static let traceID = "Lambda-Runtime-Trace-Id" static let clientContext = "X-Amz-Client-Context" @@ -148,7 +148,7 @@ internal enum AmazonHeaders { static let invokedFunctionARN = "Lambda-Runtime-Invoked-Function-Arn" } -internal enum Mode: String { +enum Mode: String { case string case json } diff --git a/Tests/AWSLambdaRuntimeCoreTests/DetachedTasksTests.swift b/Tests/AWSLambdaRuntimeCoreTests/DetachedTasksTests.swift index b0ec42bc..41ccf758 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/DetachedTasksTests.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/DetachedTasksTests.swift @@ -13,51 +13,50 @@ //===----------------------------------------------------------------------===// @testable import AWSLambdaRuntimeCore +import Logging import NIO import XCTest -import Logging class DetachedTasksTest: XCTestCase { - actor Expectation { var isFulfilled = false func fulfill() { - isFulfilled = true + self.isFulfilled = true } } - + func testAwaitTasks() async throws { let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } - + let context = DetachedTasksContainer.Context( eventLoop: eventLoopGroup.next(), logger: Logger(label: "test") ) let expectation = Expectation() - + let container = DetachedTasksContainer(context: context) await container.detached { try! await Task.sleep(for: .milliseconds(200)) await expectation.fulfill() } - + try await container.awaitAll().get() let isFulfilled = await expectation.isFulfilled XCTAssert(isFulfilled) } - + func testAwaitChildrenTasks() async throws { let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } - + let context = DetachedTasksContainer.Context( eventLoop: eventLoopGroup.next(), logger: Logger(label: "test") ) let expectation1 = Expectation() let expectation2 = Expectation() - + let container = DetachedTasksContainer(context: context) await container.detached { await container.detached { @@ -70,7 +69,7 @@ class DetachedTasksTest: XCTestCase { await expectation2.fulfill() } } - + try await container.awaitAll().get() let isFulfilled1 = await expectation1.isFulfilled let isFulfilled2 = await expectation2.isFulfilled diff --git a/Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift b/Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift index c66162e6..47be5444 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift @@ -19,7 +19,7 @@ import NIOCore import NIOHTTP1 import NIOPosix -internal final class MockLambdaServer { +final class MockLambdaServer { private let logger = Logger(label: "MockLambdaServer") private let behavior: LambdaServerBehavior private let host: String @@ -72,7 +72,7 @@ internal final class MockLambdaServer { } } -internal final class HTTPHandler: ChannelInboundHandler { +final class HTTPHandler: ChannelInboundHandler { typealias InboundIn = HTTPServerRequestPart typealias OutboundOut = HTTPServerResponsePart @@ -213,35 +213,35 @@ internal final class HTTPHandler: ChannelInboundHandler { } } -internal protocol LambdaServerBehavior { +protocol LambdaServerBehavior { func getInvocation() -> GetInvocationResult func processResponse(requestId: String, response: String?) -> Result func processError(requestId: String, error: ErrorResponse) -> Result func processInitError(error: ErrorResponse) -> Result } -internal typealias GetInvocationResult = Result<(String, String), GetWorkError> +typealias GetInvocationResult = Result<(String, String), GetWorkError> -internal enum GetWorkError: Int, Error { +enum GetWorkError: Int, Error { case badRequest = 400 case tooManyRequests = 429 case internalServerError = 500 } -internal enum ProcessResponseError: Int, Error { +enum ProcessResponseError: Int, Error { case badRequest = 400 case payloadTooLarge = 413 case tooManyRequests = 429 case internalServerError = 500 } -internal enum ProcessErrorError: Int, Error { +enum ProcessErrorError: Int, Error { case invalidErrorShape = 299 case badRequest = 400 case internalServerError = 500 } -internal enum ServerError: Error { +enum ServerError: Error { case notReady case cantBind } diff --git a/Tests/AWSLambdaRuntimeCoreTests/Utils.swift b/Tests/AWSLambdaRuntimeCoreTests/Utils.swift index 8e2d3c38..97317326 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/Utils.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/Utils.swift @@ -109,7 +109,7 @@ struct TestError: Error, Equatable, CustomStringConvertible { } extension Date { - internal var millisSinceEpoch: Int64 { + var millisSinceEpoch: Int64 { Int64(self.timeIntervalSince1970 * 1000) } }