Skip to content

Commit 30f19ad

Browse files
author
Sebastien Stormacq
committed
Merge branch 'main' into sebsto/fix_584
2 parents 503f2da + e3b74f3 commit 30f19ad

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,28 @@ extension LambdaCodableAdapter {
8383
handler: handler
8484
)
8585
}
86+
87+
/// Initializes an instance given a decoder, and a handler with a `Void` output.
88+
/// - Parameters:
89+
/// - decoder: The decoder object that will be used to decode the received `ByteBuffer` event into the generic `Event` type served to the `handler`. By default, a JSONDecoder is used.
90+
/// - handler: The handler object.
91+
public init(
92+
decoder: JSONDecoder = JSONDecoder(),
93+
handler: sending Handler
94+
)
95+
where
96+
Output == Void,
97+
Handler.Output == Void,
98+
Decoder == LambdaJSONEventDecoder,
99+
Encoder == VoidEncoder
100+
{
101+
self.init(
102+
decoder: LambdaJSONEventDecoder(decoder),
103+
handler: handler
104+
)
105+
}
86106
}
107+
87108
@available(LambdaSwift 2.0, *)
88109
extension LambdaResponseStreamWriter {
89110
/// Writes the HTTP status code and headers to the response stream.
@@ -161,12 +182,41 @@ extension LambdaRuntime {
161182
self.init(handler: handler, logger: logger)
162183
}
163184

164-
/// Initialize an instance directly with a `LambdaHandler`.
185+
/// Initialize an instance directly with a `LambdaHandler`, when `Event` is `Decodable` and `Output` is `Void`.
186+
/// - Parameters:
187+
/// - decoder: The decoder object that will be used to decode the incoming `ByteBuffer` event into the generic `Event` type. `JSONDecoder()` used as default.
188+
/// - logger: The logger to use for the runtime. Defaults to a logger with label "LambdaRuntime".
189+
/// - lambdaHandler: A type that conforms to the `LambdaHandler` protocol, whose `Event` is `Decodable` and `Output` is `Void`
190+
public convenience init<Event: Decodable, LHandler: LambdaHandler>(
191+
decoder: JSONDecoder = JSONDecoder(),
192+
logger: Logger = Logger(label: "LambdaRuntime"),
193+
lambdaHandler: sending LHandler
194+
)
195+
where
196+
Handler == LambdaCodableAdapter<
197+
LambdaHandlerAdapter<Event, Void, LHandler>,
198+
Event,
199+
Void,
200+
LambdaJSONEventDecoder,
201+
VoidEncoder
202+
>,
203+
LHandler.Event == Event,
204+
LHandler.Output == Void
205+
{
206+
let handler = LambdaCodableAdapter(
207+
decoder: LambdaJSONEventDecoder(decoder),
208+
handler: LambdaHandlerAdapter(handler: lambdaHandler)
209+
)
210+
211+
self.init(handler: handler, logger: logger)
212+
}
213+
214+
/// Initialize an instance directly with a `LambdaHandler`, when `Event` is `Decodable` and `Output` is `Encodable`.
165215
/// - Parameters:
166216
/// - decoder: The decoder object that will be used to decode the incoming `ByteBuffer` event into the generic `Event` type. `JSONDecoder()` used as default.
167217
/// - encoder: The encoder object that will be used to encode the generic `Output` into a `ByteBuffer`. `JSONEncoder()` used as default.
168218
/// - logger: The logger to use for the runtime. Defaults to a logger with label "LambdaRuntime".
169-
/// - lambdaHandler: A type that conforms to the `LambdaHandler` protocol, whose `Event` and `Output` types must be `Decodable`/`Encodable`
219+
/// - lambdaHandler: A type that conforms to the `LambdaHandler` protocol, whose `Event` is `Decodable` and `Output` is `Encodable`
170220
public convenience init<Event: Decodable, Output, LHandler: LambdaHandler>(
171221
decoder: JSONDecoder = JSONDecoder(),
172222
encoder: JSONEncoder = JSONEncoder(),

0 commit comments

Comments
 (0)