Skip to content

Rename payload to event #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/AWSLambdaRuntime/Lambda+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ internal struct CodableClosureWrapper<In: Decodable, Out: Encodable>: LambdaHand
self.closure = closure
}

func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
self.closure(context, payload, callback)
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
self.closure(context, event, callback)
}
}

Expand All @@ -72,8 +72,8 @@ internal struct CodableVoidClosureWrapper<In: Decodable>: LambdaHandler {
self.closure = closure
}

func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
self.closure(context, payload, callback)
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
self.closure(context, event, callback)
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/AWSLambdaRuntimeCore/Lambda+String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ internal struct StringClosureWrapper: LambdaHandler {
self.closure = closure
}

func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
self.closure(context, payload, callback)
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
self.closure(context, event, callback)
}
}

Expand All @@ -79,8 +79,8 @@ internal struct StringVoidClosureWrapper: LambdaHandler {
self.closure = closure
}

func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
self.closure(context, payload, callback)
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
self.closure(context, event, callback)
}
}

Expand Down
22 changes: 11 additions & 11 deletions Sources/AWSLambdaRuntimeCore/LambdaHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public protocol LambdaHandler: EventLoopLambdaHandler {
///
/// - parameters:
/// - context: Runtime `Context`.
/// - payload: Payload of type `In` representing the event or request.
/// - event: Event of type `In` representing the event or request.
/// - callback: Completion handler to report the result of the Lambda back to the runtime engine.
/// The completion handler expects a `Result` with either a response of type `Out` or an `Error`
func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void)
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void)
}

internal extension Lambda {
Expand All @@ -52,11 +52,11 @@ public extension LambdaHandler {
/// `LambdaHandler` is offloading the processing to a `DispatchQueue`
/// This is slower but safer, in case the implementation blocks the `EventLoop`
/// Performance sensitive Lambdas should be based on `EventLoopLambdaHandler` which does not offload.
func handle(context: Lambda.Context, payload: In) -> EventLoopFuture<Out> {
func handle(context: Lambda.Context, event: In) -> EventLoopFuture<Out> {
let promise = context.eventLoop.makePromise(of: Out.self)
// FIXME: reusable DispatchQueue
self.offloadQueue.async {
self.handle(context: context, payload: payload, callback: promise.completeWith)
self.handle(context: context, event: event, callback: promise.completeWith)
}
return promise.futureResult
}
Expand All @@ -80,11 +80,11 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
///
/// - parameters:
/// - context: Runtime `Context`.
/// - payload: Payload of type `In` representing the event or request.
/// - event: Event of type `In` representing the event or request.
///
/// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine.
/// The `EventLoopFuture` should be completed with either a response of type `Out` or an `Error`
func handle(context: Lambda.Context, payload: In) -> EventLoopFuture<Out>
func handle(context: Lambda.Context, event: In) -> EventLoopFuture<Out>

/// Encode a response of type `Out` to `ByteBuffer`
/// Concrete Lambda handlers implement this method to provide coding functionality.
Expand All @@ -107,12 +107,12 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {

public extension EventLoopLambdaHandler {
/// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding
func handle(context: Lambda.Context, payload: ByteBuffer) -> EventLoopFuture<ByteBuffer?> {
switch self.decodeIn(buffer: payload) {
func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture<ByteBuffer?> {
switch self.decodeIn(buffer: event) {
case .failure(let error):
return context.eventLoop.makeFailedFuture(CodecError.requestDecoding(error))
case .success(let `in`):
return self.handle(context: context, payload: `in`).flatMapThrowing { out in
return self.handle(context: context, event: `in`).flatMapThrowing { out in
switch self.encodeOut(allocator: context.allocator, value: out) {
case .failure(let error):
throw CodecError.responseEncoding(error)
Expand Down Expand Up @@ -159,11 +159,11 @@ public protocol ByteBufferLambdaHandler {
///
/// - parameters:
/// - context: Runtime `Context`.
/// - payload: The event or request payload encoded as `ByteBuffer`.
/// - event: The event or input payload encoded as `ByteBuffer`.
///
/// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine.
/// The `EventLoopFuture` should be completed with either a response encoded as `ByteBuffer` or an `Error`
func handle(context: Lambda.Context, payload: ByteBuffer) -> EventLoopFuture<ByteBuffer?>
func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture<ByteBuffer?>
}

private enum CodecError: Error {
Expand Down
2 changes: 1 addition & 1 deletion Sources/AWSLambdaRuntimeCore/LambdaRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension Lambda {
self.isGettingNextInvocation = false
let context = Context(logger: logger, eventLoop: self.eventLoop, invocation: invocation)
logger.debug("sending invocation to lambda handler \(handler)")
return handler.handle(context: context, payload: payload)
return handler.handle(context: context, event: payload)
.mapResult { result in
if case .failure(let error) = result {
logger.warning("lambda handler returned an error: \(error)")
Expand Down
4 changes: 2 additions & 2 deletions Sources/AWSLambdaTesting/Lambda+Testing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension Lambda {

public static func test<In, Out, Handler: EventLoopLambdaHandler>(
_ handler: Handler,
with payload: In,
with event: In,
using config: TestConfig = .init()
) throws -> Out where Handler.In == In, Handler.Out == Out {
let logger = Logger(label: "test")
Expand All @@ -105,7 +105,7 @@ extension Lambda {
eventLoop: eventLoop)

return try eventLoop.flatSubmit {
handler.handle(context: context, payload: payload)
handler.handle(context: context, event: event)
}.wait()
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/CodableSample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ struct Handler: EventLoopLambdaHandler {
typealias In = Request
typealias Out = Response

func handle(context: Lambda.Context, payload: Request) -> EventLoopFuture<Response> {
func handle(context: Lambda.Context, event: Request) -> EventLoopFuture<Response> {
// as an example, respond with the reverse the input payload
context.eventLoop.makeSucceededFuture(Response(body: String(payload.body.reversed())))
context.eventLoop.makeSucceededFuture(Response(body: String(event.body.reversed())))
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/StringSample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ struct Handler: EventLoopLambdaHandler {
typealias In = String
typealias Out = String

func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<String> {
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
// as an example, respond with the reverse the input payload
context.eventLoop.makeSucceededFuture(String(payload.reversed()))
context.eventLoop.makeSucceededFuture(String(event.reversed()))
}
}

Expand Down
18 changes: 9 additions & 9 deletions Tests/AWSLambdaRuntimeCoreTests/Lambda+StringTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class StringLambdaTest: XCTestCase {
typealias In = String
typealias Out = String

func handle(context: Lambda.Context, payload: String, callback: (Result<String, Error>) -> Void) {
callback(.success(payload))
func handle(context: Lambda.Context, event: String, callback: (Result<String, Error>) -> Void) {
callback(.success(event))
}
}

Expand All @@ -46,7 +46,7 @@ class StringLambdaTest: XCTestCase {
typealias In = String
typealias Out = Void

func handle(context: Lambda.Context, payload: String, callback: (Result<Void, Error>) -> Void) {
func handle(context: Lambda.Context, event: String, callback: (Result<Void, Error>) -> Void) {
callback(.success(()))
}
}
Expand All @@ -66,7 +66,7 @@ class StringLambdaTest: XCTestCase {
typealias In = String
typealias Out = String

func handle(context: Lambda.Context, payload: String, callback: (Result<String, Error>) -> Void) {
func handle(context: Lambda.Context, event: String, callback: (Result<String, Error>) -> Void) {
callback(.failure(TestError("boom")))
}
}
Expand All @@ -86,8 +86,8 @@ class StringLambdaTest: XCTestCase {
typealias In = String
typealias Out = String

func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<String> {
context.eventLoop.makeSucceededFuture(payload)
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
context.eventLoop.makeSucceededFuture(event)
}
}

Expand All @@ -106,7 +106,7 @@ class StringLambdaTest: XCTestCase {
typealias In = String
typealias Out = Void

func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<Void> {
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<Void> {
context.eventLoop.makeSucceededFuture(())
}
}
Expand All @@ -126,7 +126,7 @@ class StringLambdaTest: XCTestCase {
typealias In = String
typealias Out = String

func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<String> {
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
context.eventLoop.makeFailedFuture(TestError("boom"))
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ class StringLambdaTest: XCTestCase {
throw TestError("kaboom")
}

func handle(context: Lambda.Context, payload: String, callback: (Result<String, Error>) -> Void) {
func handle(context: Lambda.Context, event: String, callback: (Result<String, Error>) -> Void) {
callback(.failure(TestError("should not be called")))
}
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class LambdaTest: XCTestCase {
self.initialized = true
}

func handle(context: Lambda.Context, payload: String, callback: (Result<String, Error>) -> Void) {
callback(.success(payload))
func handle(context: Lambda.Context, event: String, callback: (Result<String, Error>) -> Void) {
callback(.success(event))
}
}

Expand Down Expand Up @@ -89,7 +89,7 @@ class LambdaTest: XCTestCase {
throw TestError("kaboom")
}

func handle(context: Lambda.Context, payload: String, callback: (Result<Void, Error>) -> Void) {
func handle(context: Lambda.Context, event: String, callback: (Result<Void, Error>) -> Void) {
callback(.failure(TestError("should not be called")))
}
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/AWSLambdaRuntimeCoreTests/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ struct EchoHandler: LambdaHandler {
typealias In = String
typealias Out = String

func handle(context: Lambda.Context, payload: String, callback: (Result<String, Error>) -> Void) {
callback(.success(payload))
func handle(context: Lambda.Context, event: String, callback: (Result<String, Error>) -> Void) {
callback(.success(event))
}
}

Expand All @@ -53,7 +53,7 @@ struct FailedHandler: LambdaHandler {
self.reason = reason
}

func handle(context: Lambda.Context, payload: String, callback: (Result<Void, Error>) -> Void) {
func handle(context: Lambda.Context, event: String, callback: (Result<Void, Error>) -> Void) {
callback(.failure(TestError(self.reason)))
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CodableLambdaTest: XCTestCase {
}

XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), payload: XCTUnwrap(inputBuffer)).wait())
XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
XCTAssertNil(outputBuffer)
}

Expand All @@ -58,7 +58,7 @@ class CodableLambdaTest: XCTestCase {
}

XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), payload: XCTUnwrap(inputBuffer)).wait())
XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer)))
XCTAssertEqual(response?.requestId, request.requestId)
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/AWSLambdaTestingTests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class LambdaTestingTests: XCTestCase {
typealias In = Request
typealias Out = Response

func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
XCTAssertFalse(context.eventLoop.inEventLoop)
callback(.success(Response(message: "echo" + payload.name)))
callback(.success(Response(message: "echo" + event.name)))
}
}

Expand All @@ -80,9 +80,9 @@ class LambdaTestingTests: XCTestCase {
typealias In = String
typealias Out = String

func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<String> {
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
XCTAssertTrue(context.eventLoop.inEventLoop)
return context.eventLoop.makeSucceededFuture("echo" + payload)
return context.eventLoop.makeSucceededFuture("echo" + event)
}
}

Expand All @@ -99,7 +99,7 @@ class LambdaTestingTests: XCTestCase {
typealias In = String
typealias Out = Void

func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
callback(.failure(MyError()))
}
}
Expand Down