@@ -184,3 +184,117 @@ extension LambdaCodableAdapter {
184184 )
185185 }
186186}
187+
188+ extension NewLambdaRuntime {
189+ /// Initialize an instance with a ``StreamingLambdaHandler`` in the form of a closure.
190+ /// - Parameter body: The handler in the form of a closure.
191+ package convenience init (
192+ body: @Sendable @escaping ( ByteBuffer, LambdaResponseStreamWriter, NewLambdaContext) async throws -> Void
193+ ) where Handler == StreamingClosureHandler {
194+ self . init ( handler: StreamingClosureHandler ( body: body) )
195+ }
196+
197+ /// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a non-`Void` return type**, an encoder, and a decoder.
198+ /// - Parameter body: The handler in the form of a closure.
199+ /// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
200+ /// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type.
201+ package convenience init <
202+ Event: Decodable ,
203+ Output: Encodable ,
204+ Encoder: LambdaOutputEncoder ,
205+ Decoder: LambdaEventDecoder
206+ > (
207+ encoder: Encoder ,
208+ decoder: Decoder ,
209+ body: @escaping ( Event , NewLambdaContext ) async throws -> Output
210+ )
211+ where
212+ Handler == LambdaCodableAdapter <
213+ LambdaHandlerAdapter < Event , Output , ClosureHandler < Event , Output > > ,
214+ Event ,
215+ Output ,
216+ Decoder ,
217+ Encoder
218+ >
219+ {
220+ let handler = LambdaCodableAdapter (
221+ encoder: encoder,
222+ decoder: decoder,
223+ handler: LambdaHandlerAdapter ( handler: ClosureHandler ( body: body) )
224+ )
225+
226+ self . init ( handler: handler)
227+ }
228+
229+ /// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a `Void` return type**, an encoder, and a decoder.
230+ /// - Parameter body: The handler in the form of a closure.
231+ /// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
232+ /// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type.
233+ package convenience init < Event: Decodable , Decoder: LambdaEventDecoder > (
234+ decoder: Decoder ,
235+ body: @escaping ( Event , NewLambdaContext ) async throws -> Void
236+ )
237+ where
238+ Handler == LambdaCodableAdapter <
239+ LambdaHandlerAdapter < Event , Void , ClosureHandler < Event , Void > > ,
240+ Event ,
241+ Void ,
242+ Decoder ,
243+ VoidEncoder
244+ >
245+ {
246+ let handler = LambdaCodableAdapter (
247+ decoder: decoder,
248+ handler: LambdaHandlerAdapter ( handler: ClosureHandler ( body: body) )
249+ )
250+
251+ self . init ( handler: handler)
252+ }
253+
254+ /// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a non-`Void` return type**.
255+ /// - note: ``JSONEncoder`` and ``JSONDecoder`` are used as the encoder and decoder objects. Use ``init(encoder:decoder:body:)`` to specify custom encoder and decoder objects.
256+ /// - Parameter body: The handler in the form of a closure.
257+ package convenience init < Event: Decodable , Output> (
258+ body: @escaping ( Event , NewLambdaContext ) async throws -> Output
259+ )
260+ where
261+ Handler == LambdaCodableAdapter <
262+ LambdaHandlerAdapter < Event , Output , ClosureHandler < Event , Output > > ,
263+ Event ,
264+ Output ,
265+ JSONDecoder ,
266+ LambdaJSONOutputEncoder < Output >
267+ >
268+ {
269+ let handler = LambdaCodableAdapter (
270+ encoder: JSONEncoder ( ) ,
271+ decoder: JSONDecoder ( ) ,
272+ handler: LambdaHandlerAdapter ( handler: ClosureHandler ( body: body) )
273+ )
274+
275+ self . init ( handler: handler)
276+ }
277+
278+ /// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a `Void` return type**.
279+ /// - note: ``JSONDecoder`` is used as the decoder object. Use ``init(decoder:body:)`` to specify a custom decoder object.
280+ /// - Parameter body: The handler in the form of a closure.
281+ package convenience init < Event: Decodable > (
282+ body: @escaping ( Event , NewLambdaContext ) async throws -> Void
283+ )
284+ where
285+ Handler == LambdaCodableAdapter <
286+ LambdaHandlerAdapter < Event , Void , ClosureHandler < Event , Void > > ,
287+ Event ,
288+ Void ,
289+ JSONDecoder ,
290+ VoidEncoder
291+ >
292+ {
293+ let handler = LambdaCodableAdapter (
294+ decoder: JSONDecoder ( ) ,
295+ handler: LambdaHandlerAdapter ( handler: ClosureHandler ( body: body) )
296+ )
297+
298+ self . init ( handler: handler)
299+ }
300+ }
0 commit comments