Skip to content

Commit 266b187

Browse files
committed
Rename payload to event
1 parent 5e546a1 commit 266b187

File tree

12 files changed

+48
-48
lines changed

12 files changed

+48
-48
lines changed

Sources/AWSLambdaRuntime/Lambda+Codable.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ internal struct CodableClosureWrapper<In: Decodable, Out: Encodable>: LambdaHand
5757
self.closure = closure
5858
}
5959

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

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

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

Sources/AWSLambdaRuntimeCore/Lambda+String.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ internal struct StringClosureWrapper: LambdaHandler {
6464
self.closure = closure
6565
}
6666

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

@@ -79,8 +79,8 @@ internal struct StringVoidClosureWrapper: LambdaHandler {
7979
self.closure = closure
8080
}
8181

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

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public protocol LambdaHandler: EventLoopLambdaHandler {
3333
///
3434
/// - parameters:
3535
/// - context: Runtime `Context`.
36-
/// - payload: Payload of type `In` representing the event or request.
36+
/// - event: Event of type `In` representing the event or request.
3737
/// - callback: Completion handler to report the result of the Lambda back to the runtime engine.
3838
/// The completion handler expects a `Result` with either a response of type `Out` or an `Error`
39-
func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void)
39+
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void)
4040
}
4141

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

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

108108
public extension EventLoopLambdaHandler {
109109
/// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding
110-
func handle(context: Lambda.Context, payload: ByteBuffer) -> EventLoopFuture<ByteBuffer?> {
111-
switch self.decodeIn(buffer: payload) {
110+
func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture<ByteBuffer?> {
111+
switch self.decodeIn(buffer: event) {
112112
case .failure(let error):
113113
return context.eventLoop.makeFailedFuture(CodecError.requestDecoding(error))
114114
case .success(let `in`):
115-
return self.handle(context: context, payload: `in`).flatMapThrowing { out in
115+
return self.handle(context: context, event: `in`).flatMapThrowing { out in
116116
switch self.encodeOut(allocator: context.allocator, value: out) {
117117
case .failure(let error):
118118
throw CodecError.responseEncoding(error)
@@ -159,11 +159,11 @@ public protocol ByteBufferLambdaHandler {
159159
///
160160
/// - parameters:
161161
/// - context: Runtime `Context`.
162-
/// - payload: The event or request payload encoded as `ByteBuffer`.
162+
/// - event: The event or input payload encoded as `ByteBuffer`.
163163
///
164164
/// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine.
165165
/// The `EventLoopFuture` should be completed with either a response encoded as `ByteBuffer` or an `Error`
166-
func handle(context: Lambda.Context, payload: ByteBuffer) -> EventLoopFuture<ByteBuffer?>
166+
func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture<ByteBuffer?>
167167
}
168168

169169
private enum CodecError: Error {

Sources/AWSLambdaRuntimeCore/LambdaRunner.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension Lambda {
5656
self.isGettingNextInvocation = false
5757
let context = Context(logger: logger, eventLoop: self.eventLoop, invocation: invocation)
5858
logger.debug("sending invocation to lambda handler \(handler)")
59-
return handler.handle(context: context, payload: payload)
59+
return handler.handle(context: context, event: payload)
6060
.mapResult { result in
6161
if case .failure(let error) = result {
6262
logger.warning("lambda handler returned an error: \(error)")

Sources/AWSLambdaTesting/Lambda+Testing.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extension Lambda {
8888

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

107107
return try eventLoop.flatSubmit {
108-
handler.handle(context: context, payload: payload)
108+
handler.handle(context: context, event: event)
109109
}.wait()
110110
}
111111
}

Sources/CodableSample/main.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ struct Handler: EventLoopLambdaHandler {
2929
typealias In = Request
3030
typealias Out = Response
3131

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

Sources/StringSample/main.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ struct Handler: EventLoopLambdaHandler {
2020
typealias In = String
2121
typealias Out = String
2222

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

Tests/AWSLambdaRuntimeCoreTests/Lambda+StringTest.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class StringLambdaTest: XCTestCase {
2626
typealias In = String
2727
typealias Out = String
2828

29-
func handle(context: Lambda.Context, payload: String, callback: (Result<String, Error>) -> Void) {
30-
callback(.success(payload))
29+
func handle(context: Lambda.Context, event: String, callback: (Result<String, Error>) -> Void) {
30+
callback(.success(event))
3131
}
3232
}
3333

@@ -46,7 +46,7 @@ class StringLambdaTest: XCTestCase {
4646
typealias In = String
4747
typealias Out = Void
4848

49-
func handle(context: Lambda.Context, payload: String, callback: (Result<Void, Error>) -> Void) {
49+
func handle(context: Lambda.Context, event: String, callback: (Result<Void, Error>) -> Void) {
5050
callback(.success(()))
5151
}
5252
}
@@ -66,7 +66,7 @@ class StringLambdaTest: XCTestCase {
6666
typealias In = String
6767
typealias Out = String
6868

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

89-
func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<String> {
90-
context.eventLoop.makeSucceededFuture(payload)
89+
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
90+
context.eventLoop.makeSucceededFuture(event)
9191
}
9292
}
9393

@@ -106,7 +106,7 @@ class StringLambdaTest: XCTestCase {
106106
typealias In = String
107107
typealias Out = Void
108108

109-
func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<Void> {
109+
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<Void> {
110110
context.eventLoop.makeSucceededFuture(())
111111
}
112112
}
@@ -126,7 +126,7 @@ class StringLambdaTest: XCTestCase {
126126
typealias In = String
127127
typealias Out = String
128128

129-
func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<String> {
129+
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
130130
context.eventLoop.makeFailedFuture(TestError("boom"))
131131
}
132132
}
@@ -189,7 +189,7 @@ class StringLambdaTest: XCTestCase {
189189
throw TestError("kaboom")
190190
}
191191

192-
func handle(context: Lambda.Context, payload: String, callback: (Result<String, Error>) -> Void) {
192+
func handle(context: Lambda.Context, event: String, callback: (Result<String, Error>) -> Void) {
193193
callback(.failure(TestError("should not be called")))
194194
}
195195
}

Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class LambdaTest: XCTestCase {
5656
self.initialized = true
5757
}
5858

59-
func handle(context: Lambda.Context, payload: String, callback: (Result<String, Error>) -> Void) {
60-
callback(.success(payload))
59+
func handle(context: Lambda.Context, event: String, callback: (Result<String, Error>) -> Void) {
60+
callback(.success(event))
6161
}
6262
}
6363

@@ -89,7 +89,7 @@ class LambdaTest: XCTestCase {
8989
throw TestError("kaboom")
9090
}
9191

92-
func handle(context: Lambda.Context, payload: String, callback: (Result<Void, Error>) -> Void) {
92+
func handle(context: Lambda.Context, event: String, callback: (Result<Void, Error>) -> Void) {
9393
callback(.failure(TestError("should not be called")))
9494
}
9595
}

Tests/AWSLambdaRuntimeCoreTests/Utils.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ struct EchoHandler: LambdaHandler {
3838
typealias In = String
3939
typealias Out = String
4040

41-
func handle(context: Lambda.Context, payload: String, callback: (Result<String, Error>) -> Void) {
42-
callback(.success(payload))
41+
func handle(context: Lambda.Context, event: String, callback: (Result<String, Error>) -> Void) {
42+
callback(.success(event))
4343
}
4444
}
4545

@@ -53,7 +53,7 @@ struct FailedHandler: LambdaHandler {
5353
self.reason = reason
5454
}
5555

56-
func handle(context: Lambda.Context, payload: String, callback: (Result<Void, Error>) -> Void) {
56+
func handle(context: Lambda.Context, event: String, callback: (Result<Void, Error>) -> Void) {
5757
callback(.failure(TestError(self.reason)))
5858
}
5959
}

Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CodableLambdaTest: XCTestCase {
4242
}
4343

4444
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
45-
XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), payload: XCTUnwrap(inputBuffer)).wait())
45+
XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
4646
XCTAssertNil(outputBuffer)
4747
}
4848

@@ -58,7 +58,7 @@ class CodableLambdaTest: XCTestCase {
5858
}
5959

6060
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
61-
XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), payload: XCTUnwrap(inputBuffer)).wait())
61+
XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
6262
XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer)))
6363
XCTAssertEqual(response?.requestId, request.requestId)
6464
}

Tests/AWSLambdaTestingTests/Tests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class LambdaTestingTests: XCTestCase {
6363
typealias In = Request
6464
typealias Out = Response
6565

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

@@ -80,9 +80,9 @@ class LambdaTestingTests: XCTestCase {
8080
typealias In = String
8181
typealias Out = String
8282

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

@@ -99,7 +99,7 @@ class LambdaTestingTests: XCTestCase {
9999
typealias In = String
100100
typealias Out = Void
101101

102-
func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
102+
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
103103
callback(.failure(MyError()))
104104
}
105105
}

0 commit comments

Comments
 (0)