Skip to content

Commit c870b43

Browse files
committed
Make v2 API functions and types public
1 parent 2abd9b5 commit c870b43

File tree

5 files changed

+43
-42
lines changed

5 files changed

+43
-42
lines changed

Sources/AWSLambdaRuntimeCore/NewLambda+JSON.swift renamed to Sources/AWSLambdaRuntimeCore/Lambda+JSON.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import NIOCore
1616

1717
/// The protocol a decoder must conform to so that it can be used with ``LambdaCodableAdapter`` to decode incoming
1818
/// ``ByteBuffer`` events.
19-
package protocol LambdaEventDecoder {
19+
public protocol LambdaEventDecoder {
2020
/// Decode the ``ByteBuffer`` representing the received event into the generic ``Event`` type
2121
/// the handler will receive.
2222
/// - Parameters:
@@ -28,7 +28,7 @@ package protocol LambdaEventDecoder {
2828

2929
/// The protocol an encoder must conform to so that it can be used with ``LambdaCodableAdapter`` to encode the generic
3030
/// ``Output`` object into a ``ByteBuffer``.
31-
package protocol LambdaOutputEncoder {
31+
public protocol LambdaOutputEncoder {
3232
associatedtype Output
3333

3434
/// Encode the generic type `Output` the handler has returned into a ``ByteBuffer``.
@@ -38,15 +38,17 @@ package protocol LambdaOutputEncoder {
3838
func encode(_ value: Output, into buffer: inout ByteBuffer) throws
3939
}
4040

41-
package struct VoidEncoder: LambdaOutputEncoder {
42-
package typealias Output = Void
41+
public struct VoidEncoder: LambdaOutputEncoder {
42+
public typealias Output = Void
43+
44+
public init() {}
4345

4446
@inlinable
45-
package func encode(_ value: Void, into buffer: inout NIOCore.ByteBuffer) throws {}
47+
public func encode(_ value: Void, into buffer: inout NIOCore.ByteBuffer) throws {}
4648
}
4749

4850
/// Adapts a ``LambdaHandler`` conforming handler to conform to ``LambdaWithBackgroundProcessingHandler``.
49-
package struct LambdaHandlerAdapter<
51+
public struct LambdaHandlerAdapter<
5052
Event: Decodable,
5153
Output,
5254
Handler: LambdaHandler
@@ -67,7 +69,7 @@ package struct LambdaHandlerAdapter<
6769
/// - outputWriter: The writer to write the computed response to.
6870
/// - context: The ``LambdaContext`` containing the invocation's metadata.
6971
@inlinable
70-
package func handle(
72+
public func handle(
7173
_ event: Event,
7274
outputWriter: some LambdaResponseWriter<Output>,
7375
context: LambdaContext
@@ -78,7 +80,7 @@ package struct LambdaHandlerAdapter<
7880
}
7981

8082
/// Adapts a ``LambdaWithBackgroundProcessingHandler`` conforming handler to conform to ``StreamingLambdaHandler``.
81-
package struct LambdaCodableAdapter<
83+
public struct LambdaCodableAdapter<
8284
Handler: LambdaWithBackgroundProcessingHandler,
8385
Event: Decodable,
8486
Output,
@@ -88,7 +90,6 @@ package struct LambdaCodableAdapter<
8890
@usableFromInline let handler: Handler
8991
@usableFromInline let encoder: Encoder
9092
@usableFromInline let decoder: Decoder
91-
//
9293
@usableFromInline var byteBuffer: ByteBuffer = .init()
9394

9495
/// Initializes an instance given an encoder, decoder, and a handler with a non-`Void` output.
@@ -120,7 +121,7 @@ package struct LambdaCodableAdapter<
120121
/// - outputWriter: The writer to write the computed response to.
121122
/// - context: The ``LambdaContext`` containing the invocation's metadata.
122123
@inlinable
123-
package mutating func handle<Writer: LambdaResponseStreamWriter>(
124+
public mutating func handle<Writer: LambdaResponseStreamWriter>(
124125
_ request: ByteBuffer,
125126
responseWriter: Writer,
126127
context: LambdaContext
@@ -136,7 +137,7 @@ package struct LambdaCodableAdapter<
136137
}
137138

138139
/// A ``LambdaResponseStreamWriter`` wrapper that conforms to ``LambdaResponseWriter``.
139-
package struct LambdaCodableResponseWriter<Output, Encoder: LambdaOutputEncoder, Base: LambdaResponseStreamWriter>:
140+
public struct LambdaCodableResponseWriter<Output, Encoder: LambdaOutputEncoder, Base: LambdaResponseStreamWriter>:
140141
LambdaResponseWriter
141142
where Output == Encoder.Output {
142143
@usableFromInline let underlyingStreamWriter: Base
@@ -153,7 +154,7 @@ where Output == Encoder.Output {
153154
}
154155

155156
@inlinable
156-
package func write(_ output: Output) async throws {
157+
public func write(_ output: Output) async throws {
157158
var outputBuffer = ByteBuffer()
158159
try self.encoder.encode(output, into: &outputBuffer)
159160
try await self.underlyingStreamWriter.writeAndFinish(outputBuffer)

Sources/AWSLambdaRuntimeCore/Lambda.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import ucrt
2929
#error("Unsupported platform")
3030
#endif
3131

32-
enum Lambda {
32+
public enum Lambda {
3333
package static func runLoop<RuntimeClient: LambdaRuntimeClientProtocol, Handler>(
3434
runtimeClient: RuntimeClient,
3535
handler: Handler,
@@ -60,7 +60,7 @@ enum Lambda {
6060
}
6161

6262
/// The default EventLoop the Lambda is scheduled on.
63-
package static var defaultEventLoop: any EventLoop = NIOSingletons.posixEventLoopGroup.next()
63+
public static var defaultEventLoop: any EventLoop = NIOSingletons.posixEventLoopGroup.next()
6464
}
6565

6666
// MARK: - Public API

Sources/AWSLambdaRuntimeCore/LambdaContext.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import NIOCore
2020

2121
/// Lambda runtime context.
2222
/// The Lambda runtime generates and passes the `LambdaContext` to the Lambda handler as an argument.
23-
package struct LambdaContext: CustomDebugStringConvertible, Sendable {
23+
public struct LambdaContext: CustomDebugStringConvertible, Sendable {
2424
final class _Storage: Sendable {
2525
let requestID: String
2626
let traceID: String
@@ -52,39 +52,39 @@ package struct LambdaContext: CustomDebugStringConvertible, Sendable {
5252
private var storage: _Storage
5353

5454
/// The request ID, which identifies the request that triggered the function invocation.
55-
package var requestID: String {
55+
public var requestID: String {
5656
self.storage.requestID
5757
}
5858

5959
/// The AWS X-Ray tracing header.
60-
package var traceID: String {
60+
public var traceID: String {
6161
self.storage.traceID
6262
}
6363

6464
/// The ARN of the Lambda function, version, or alias that's specified in the invocation.
65-
package var invokedFunctionARN: String {
65+
public var invokedFunctionARN: String {
6666
self.storage.invokedFunctionARN
6767
}
6868

6969
/// The timestamp that the function times out.
70-
package var deadline: DispatchWallTime {
70+
public var deadline: DispatchWallTime {
7171
self.storage.deadline
7272
}
7373

7474
/// For invocations from the AWS Mobile SDK, data about the Amazon Cognito identity provider.
75-
package var cognitoIdentity: String? {
75+
public var cognitoIdentity: String? {
7676
self.storage.cognitoIdentity
7777
}
7878

7979
/// For invocations from the AWS Mobile SDK, data about the client application and device.
80-
package var clientContext: String? {
80+
public var clientContext: String? {
8181
self.storage.clientContext
8282
}
8383

8484
/// `Logger` to log with.
8585
///
8686
/// - note: The `LogLevel` can be configured using the `LOG_LEVEL` environment variable.
87-
package var logger: Logger {
87+
public var logger: Logger {
8888
self.storage.logger
8989
}
9090

@@ -108,15 +108,15 @@ package struct LambdaContext: CustomDebugStringConvertible, Sendable {
108108
)
109109
}
110110

111-
package func getRemainingTime() -> TimeAmount {
111+
public func getRemainingTime() -> TimeAmount {
112112
let deadline = self.deadline.millisSinceEpoch
113113
let now = DispatchWallTime.now().millisSinceEpoch
114114

115115
let remaining = deadline - now
116116
return .milliseconds(remaining)
117117
}
118118

119-
package var debugDescription: String {
119+
public var debugDescription: String {
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

Sources/AWSLambdaRuntimeCore/LambdaHandlers.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import NIOCore
2020
/// Background work can also be executed after returning the response. After closing the response stream by calling
2121
/// ``LambdaResponseStreamWriter/finish()`` or ``LambdaResponseStreamWriter/writeAndFinish(_:)``,
2222
/// the ``handle(_:responseWriter:context:)`` function is free to execute any background work.
23-
package protocol StreamingLambdaHandler {
23+
public protocol StreamingLambdaHandler {
2424
/// The handler function -- implement the business logic of the Lambda function here.
2525
/// - Parameters:
2626
/// - event: The invocation's input data.
@@ -45,7 +45,7 @@ package protocol StreamingLambdaHandler {
4545

4646
/// A writer object to write the Lambda response stream into. The HTTP response is started lazily.
4747
/// before the first call to ``write(_:)`` or ``writeAndFinish(_:)``.
48-
package protocol LambdaResponseStreamWriter {
48+
public protocol LambdaResponseStreamWriter {
4949
/// Write a response part into the stream. Bytes written are streamed continually.
5050
/// - Parameter buffer: The buffer to write.
5151
func write(_ buffer: ByteBuffer) async throws
@@ -64,7 +64,7 @@ package protocol LambdaResponseStreamWriter {
6464
///
6565
/// - note: This handler protocol does not support response streaming because the output has to be encoded prior to it being sent, e.g. it is not possible to encode a partial/incomplete JSON string.
6666
/// This protocol also does not support the execution of background work after the response has been returned -- the ``LambdaWithBackgroundProcessingHandler`` protocol caters for such use-cases.
67-
package protocol LambdaHandler {
67+
public protocol LambdaHandler {
6868
/// Generic input type.
6969
/// The body of the request sent to Lambda will be decoded into this type for the handler to consume.
7070
associatedtype Event: Decodable
@@ -85,7 +85,7 @@ package protocol LambdaHandler {
8585
/// This is achieved by not having a return type in the `handle` function. The output is instead written into a
8686
/// ``LambdaResponseWriter``that is passed in as an argument, meaning that the ``handle(_:)`` function is then free to implement
8787
/// any background work after the result has been sent to the AWS Lambda control plane.
88-
package protocol LambdaWithBackgroundProcessingHandler {
88+
public protocol LambdaWithBackgroundProcessingHandler {
8989
/// Generic input type.
9090
/// The body of the request sent to Lambda will be decoded into this type for the handler to consume.
9191
associatedtype Event: Decodable
@@ -109,7 +109,7 @@ package protocol LambdaWithBackgroundProcessingHandler {
109109
/// Used with ``LambdaWithBackgroundProcessingHandler``.
110110
/// A mechanism to "return" an output from ``LambdaWithBackgroundProcessingHandler/handle(_:outputWriter:context:)`` without the function needing to
111111
/// have a return type and exit at that point. This allows for background work to be executed _after_ a response has been sent to the AWS Lambda response endpoint.
112-
package protocol LambdaResponseWriter<Output> {
112+
public protocol LambdaResponseWriter<Output> {
113113
associatedtype Output
114114
/// Sends the generic ``Output`` object (representing the computed result of the handler)
115115
/// to the AWS Lambda response endpoint.
@@ -120,12 +120,12 @@ package protocol LambdaResponseWriter<Output> {
120120

121121
/// A ``StreamingLambdaHandler`` conforming handler object that can be constructed with a closure.
122122
/// Allows for a handler to be defined in a clean manner, leveraging Swift's trailing closure syntax.
123-
package struct StreamingClosureHandler: StreamingLambdaHandler {
123+
public struct StreamingClosureHandler: StreamingLambdaHandler {
124124
let body: @Sendable (ByteBuffer, LambdaResponseStreamWriter, LambdaContext) async throws -> Void
125125

126126
/// Initialize an instance from a handler function in the form of a closure.
127127
/// - Parameter body: The handler function written as a closure.
128-
package init(
128+
public init(
129129
body: @Sendable @escaping (ByteBuffer, LambdaResponseStreamWriter, LambdaContext) async throws -> Void
130130
) {
131131
self.body = body
@@ -137,7 +137,7 @@ package struct StreamingClosureHandler: StreamingLambdaHandler {
137137
/// - responseWriter: A ``LambdaResponseStreamWriter`` to write the invocation's response to.
138138
/// If no response or error is written to `responseWriter` an error will be reported to the invoker.
139139
/// - context: The ``LambdaContext`` containing the invocation's metadata.
140-
package func handle(
140+
public func handle(
141141
_ request: ByteBuffer,
142142
responseWriter: some LambdaResponseStreamWriter,
143143
context: LambdaContext
@@ -148,34 +148,34 @@ package struct StreamingClosureHandler: StreamingLambdaHandler {
148148

149149
/// A ``LambdaHandler`` conforming handler object that can be constructed with a closure.
150150
/// Allows for a handler to be defined in a clean manner, leveraging Swift's trailing closure syntax.
151-
package struct ClosureHandler<Event: Decodable, Output>: LambdaHandler {
151+
public struct ClosureHandler<Event: Decodable, Output>: LambdaHandler {
152152
let body: (Event, LambdaContext) async throws -> Output
153153

154154
/// Initialize with a closure handler over generic `Input` and `Output` types.
155155
/// - Parameter body: The handler function written as a closure.
156-
package init(body: @escaping (Event, LambdaContext) async throws -> Output) where Output: Encodable {
156+
public init(body: @escaping (Event, LambdaContext) async throws -> Output) where Output: Encodable {
157157
self.body = body
158158
}
159159

160160
/// Initialize with a closure handler over a generic `Input` type, and a `Void` `Output`.
161161
/// - Parameter body: The handler function written as a closure.
162-
package init(body: @escaping (Event, LambdaContext) async throws -> Void) where Output == Void {
162+
public init(body: @escaping (Event, LambdaContext) async throws -> Void) where Output == Void {
163163
self.body = body
164164
}
165165

166166
/// Calls the provided `self.body` closure with the generic ``Event`` object representing the incoming event, and the ``LambdaContext``
167167
/// - Parameters:
168168
/// - event: The generic ``Event`` object representing the invocation's input data.
169169
/// - context: The ``LambdaContext`` containing the invocation's metadata.
170-
package func handle(_ event: Event, context: LambdaContext) async throws -> Output {
170+
public func handle(_ event: Event, context: LambdaContext) async throws -> Output {
171171
try await self.body(event, context)
172172
}
173173
}
174174

175175
extension LambdaRuntime {
176176
/// Initialize an instance with a ``StreamingLambdaHandler`` in the form of a closure.
177177
/// - Parameter body: The handler in the form of a closure.
178-
package convenience init(
178+
public convenience init(
179179
body: @Sendable @escaping (ByteBuffer, LambdaResponseStreamWriter, LambdaContext) async throws -> Void
180180
) where Handler == StreamingClosureHandler {
181181
self.init(handler: StreamingClosureHandler(body: body))
@@ -185,7 +185,7 @@ extension LambdaRuntime {
185185
/// - Parameter body: The handler in the form of a closure.
186186
/// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
187187
/// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type.
188-
package convenience init<
188+
public convenience init<
189189
Event: Decodable,
190190
Output: Encodable,
191191
Encoder: LambdaOutputEncoder,
@@ -217,7 +217,7 @@ extension LambdaRuntime {
217217
/// - Parameter body: The handler in the form of a closure.
218218
/// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
219219
/// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type.
220-
package convenience init<Event: Decodable, Decoder: LambdaEventDecoder>(
220+
public convenience init<Event: Decodable, Decoder: LambdaEventDecoder>(
221221
decoder: Decoder,
222222
body: @escaping (Event, LambdaContext) async throws -> Void
223223
)

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import NIOConcurrencyHelpers
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.
23-
package final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: StreamingLambdaHandler {
23+
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
2525
let handlerMutex: NIOLockedValueBox<Optional<Handler>>
2626
let logger: Logger
2727
let eventLoop: EventLoop
2828

29-
package init(
29+
public init(
3030
handler: sending Handler,
3131
eventLoop: EventLoop = Lambda.defaultEventLoop,
3232
logger: Logger = Logger(label: "LambdaRuntime")
@@ -36,7 +36,7 @@ package final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: S
3636
self.logger = logger
3737
}
3838

39-
package func run() async throws {
39+
public func run() async throws {
4040
guard let runtimeEndpoint = Lambda.env("AWS_LAMBDA_RUNTIME_API") else {
4141
throw LambdaRuntimeError(code: .missingLambdaRuntimeAPIEnvironmentVariable)
4242
}

0 commit comments

Comments
 (0)