Skip to content

Commit 3804510

Browse files
committed
Move StreamingClosureHandler initializer to AWSLambdaRuntimeCore, fix codable initializers.
1 parent ddc538d commit 3804510

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Sources/AWSLambdaRuntime/Lambda+Codable.swift

+11-15
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ extension LambdaCodableAdapter {
6767
}
6868

6969
extension NewLambdaRuntime {
70-
/// Initialize an instance with a ``StreamingLambdaHandler`` in the form of a closure.
71-
/// - Parameter body: The handler in the form of a closure.
72-
package convenience init(
73-
body: @Sendable @escaping (ByteBuffer, LambdaResponseStreamWriter, NewLambdaContext) async throws -> Void
74-
) where Handler == StreamingClosureHandler {
75-
self.init(handler: StreamingClosureHandler(body: body))
76-
}
77-
7870
/// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a non-`Void` return type**, an encoder, and a decoder.
7971
/// - Parameter body: The handler in the form of a closure.
8072
/// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
@@ -133,10 +125,13 @@ extension NewLambdaRuntime {
133125
}
134126

135127
/// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a non-`Void` return type**.
136-
/// - note: ``JSONEncoder`` and ``JSONDecoder`` are used as the encoder and decoder objects. Use ``init(encoder:decoder:body:)`` to specify custom encoder and decoder objects.
137128
/// - Parameter body: The handler in the form of a closure.
129+
/// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``. ``JSONEncoder()`` used as default.
130+
/// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type. ``JSONDecoder()`` used as default.
138131
package convenience init<Event: Decodable, Output>(
139-
body: @escaping (Event, NewLambdaContext) async throws -> Output
132+
body: @escaping (Event, NewLambdaContext) async throws -> Output,
133+
encoder: JSONEncoder = JSONEncoder(),
134+
decoder: JSONDecoder = JSONDecoder()
140135
)
141136
where
142137
Handler == LambdaCodableAdapter<
@@ -148,19 +143,20 @@ extension NewLambdaRuntime {
148143
>
149144
{
150145
let handler = LambdaCodableAdapter(
151-
encoder: JSONEncoder(),
152-
decoder: JSONDecoder(),
146+
encoder: encoder,
147+
decoder: decoder,
153148
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
154149
)
155150

156151
self.init(handler: handler)
157152
}
158153

159154
/// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a `Void` return type**.
160-
/// - note: ``JSONDecoder`` is used as the decoder object. Use ``init(decoder:body:)`` to specify a custom decoder object.
161155
/// - Parameter body: The handler in the form of a closure.
156+
/// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type. ``JSONDecoder()`` used as default.
162157
package convenience init<Event: Decodable>(
163-
body: @escaping (Event, NewLambdaContext) async throws -> Void
158+
body: @escaping (Event, NewLambdaContext) async throws -> Void,
159+
decoder: JSONDecoder = JSONDecoder()
164160
)
165161
where
166162
Handler == LambdaCodableAdapter<
@@ -172,7 +168,7 @@ extension NewLambdaRuntime {
172168
>
173169
{
174170
let handler = LambdaCodableAdapter(
175-
decoder: JSONDecoder(),
171+
decoder: decoder,
176172
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
177173
)
178174

Sources/AWSLambdaRuntimeCore/NewLambda+JSON.swift

+10
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,13 @@ where Output == Encoder.Output {
159159
try await self.underlyingStreamWriter.writeAndFinish(outputBuffer)
160160
}
161161
}
162+
163+
extension NewLambdaRuntime {
164+
/// Initialize an instance with a ``StreamingLambdaHandler`` in the form of a closure.
165+
/// - Parameter body: The handler in the form of a closure.
166+
package convenience init(
167+
body: @Sendable @escaping (ByteBuffer, LambdaResponseStreamWriter, NewLambdaContext) async throws -> Void
168+
) where Handler == StreamingClosureHandler {
169+
self.init(handler: StreamingClosureHandler(body: body))
170+
}
171+
}

0 commit comments

Comments
 (0)