Skip to content

Commit 68bca21

Browse files
committed
Move closure initializers not using Foundation to NewLambdaHandlers.swift in AWSLambdaRuntimeCore
1 parent ea0f0d3 commit 68bca21

File tree

3 files changed

+67
-67
lines changed

3 files changed

+67
-67
lines changed

Sources/AWSLambdaRuntime/Lambda+Codable.swift

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -67,63 +67,6 @@ extension LambdaCodableAdapter {
6767
}
6868

6969
extension NewLambdaRuntime {
70-
/// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a non-`Void` return type**, an encoder, and a decoder.
71-
/// - Parameter body: The handler in the form of a closure.
72-
/// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
73-
/// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type.
74-
package convenience init<
75-
Event: Decodable,
76-
Output: Encodable,
77-
Encoder: LambdaOutputEncoder,
78-
Decoder: LambdaEventDecoder
79-
>(
80-
encoder: Encoder,
81-
decoder: Decoder,
82-
body: @escaping (Event, NewLambdaContext) async throws -> Output
83-
)
84-
where
85-
Handler == LambdaCodableAdapter<
86-
LambdaHandlerAdapter<Event, Output, ClosureHandler<Event, Output>>,
87-
Event,
88-
Output,
89-
Decoder,
90-
Encoder
91-
>
92-
{
93-
let handler = LambdaCodableAdapter(
94-
encoder: encoder,
95-
decoder: decoder,
96-
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
97-
)
98-
99-
self.init(handler: handler)
100-
}
101-
102-
/// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a `Void` return type**, an encoder, and a decoder.
103-
/// - Parameter body: The handler in the form of a closure.
104-
/// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
105-
/// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type.
106-
package convenience init<Event: Decodable, Decoder: LambdaEventDecoder>(
107-
decoder: Decoder,
108-
body: @escaping (Event, NewLambdaContext) async throws -> Void
109-
)
110-
where
111-
Handler == LambdaCodableAdapter<
112-
LambdaHandlerAdapter<Event, Void, ClosureHandler<Event, Void>>,
113-
Event,
114-
Void,
115-
Decoder,
116-
VoidEncoder
117-
>
118-
{
119-
let handler = LambdaCodableAdapter(
120-
decoder: decoder,
121-
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
122-
)
123-
124-
self.init(handler: handler)
125-
}
126-
12770
/// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a non-`Void` return type**.
12871
/// - Parameter body: The handler in the form of a closure.
12972
/// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``. ``JSONEncoder()`` used as default.

Sources/AWSLambdaRuntimeCore/NewLambda+JSON.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,3 @@ 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-
}

Sources/AWSLambdaRuntimeCore/NewLambdaHandlers.swift

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,70 @@ package struct ClosureHandler<Event: Decodable, Output>: NewLambdaHandler {
171171
try await self.body(event, context)
172172
}
173173
}
174+
175+
extension NewLambdaRuntime {
176+
/// Initialize an instance with a ``StreamingLambdaHandler`` in the form of a closure.
177+
/// - Parameter body: The handler in the form of a closure.
178+
package convenience init(
179+
body: @Sendable @escaping (ByteBuffer, LambdaResponseStreamWriter, NewLambdaContext) async throws -> Void
180+
) where Handler == StreamingClosureHandler {
181+
self.init(handler: StreamingClosureHandler(body: body))
182+
}
183+
184+
/// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a non-`Void` return type**, an encoder, and a decoder.
185+
/// - Parameter body: The handler in the form of a closure.
186+
/// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
187+
/// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type.
188+
package convenience init<
189+
Event: Decodable,
190+
Output: Encodable,
191+
Encoder: LambdaOutputEncoder,
192+
Decoder: LambdaEventDecoder
193+
>(
194+
encoder: Encoder,
195+
decoder: Decoder,
196+
body: @escaping (Event, NewLambdaContext) async throws -> Output
197+
)
198+
where
199+
Handler == LambdaCodableAdapter<
200+
LambdaHandlerAdapter<Event, Output, ClosureHandler<Event, Output>>,
201+
Event,
202+
Output,
203+
Decoder,
204+
Encoder
205+
>
206+
{
207+
let handler = LambdaCodableAdapter(
208+
encoder: encoder,
209+
decoder: decoder,
210+
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
211+
)
212+
213+
self.init(handler: handler)
214+
}
215+
216+
/// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a `Void` return type**, an encoder, and a decoder.
217+
/// - Parameter body: The handler in the form of a closure.
218+
/// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
219+
/// - 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>(
221+
decoder: Decoder,
222+
body: @escaping (Event, NewLambdaContext) async throws -> Void
223+
)
224+
where
225+
Handler == LambdaCodableAdapter<
226+
LambdaHandlerAdapter<Event, Void, ClosureHandler<Event, Void>>,
227+
Event,
228+
Void,
229+
Decoder,
230+
VoidEncoder
231+
>
232+
{
233+
let handler = LambdaCodableAdapter(
234+
decoder: decoder,
235+
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
236+
)
237+
238+
self.init(handler: handler)
239+
}
240+
}

0 commit comments

Comments
 (0)