Skip to content

Commit 4c4181c

Browse files
committed
adjustments to sendable
motivation: events may be used in an async context and as such musct conform to Sendable changes: * define common abstraction for Sendable & Codable * conform all events Sendable
1 parent 2101c95 commit 4c4181c

16 files changed

+113
-75
lines changed

Sources/AWSLambdaEvents/ALB.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import class Foundation.JSONEncoder
1616

1717
// https://github.com/aws/aws-lambda-go/blob/master/events/alb.go
1818
/// ALBTargetGroupRequest contains data originating from the ALB Lambda target group integration
19-
public struct ALBTargetGroupRequest: Codable {
19+
public struct ALBTargetGroupRequest: AWSLambdaEvent {
2020
/// ALBTargetGroupRequestContext contains the information to identify the load balancer invoking the lambda
21-
public struct Context: Codable {
21+
public struct Context: AWSLambdaEvent {
2222
public let elb: ELBContext
2323
}
2424

@@ -44,12 +44,12 @@ public struct ALBTargetGroupRequest: Codable {
4444
public let body: String?
4545

4646
/// ELBContext contains the information to identify the ARN invoking the lambda
47-
public struct ELBContext: Codable {
47+
public struct ELBContext: AWSLambdaEvent {
4848
public let targetGroupArn: String
4949
}
5050
}
5151

52-
public struct ALBTargetGroupResponse: Codable {
52+
public struct ALBTargetGroupResponse: AWSLambdaEvent {
5353
public var statusCode: HTTPResponseStatus
5454
public var statusDescription: String?
5555
public var headers: HTTPHeaders?

Sources/AWSLambdaEvents/APIGateway+V2.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
/// APIGatewayV2Request contains data coming from the new HTTP API Gateway
16-
public struct APIGatewayV2Request: Codable {
16+
public struct APIGatewayV2Request: AWSLambdaEvent {
1717
/// Context contains the information to identify the AWS account and resources invoking the Lambda function.
18-
public struct Context: Codable {
19-
public struct HTTP: Codable {
18+
public struct Context: AWSLambdaEvent {
19+
public struct HTTP: AWSLambdaEvent {
2020
public let method: HTTPMethod
2121
public let path: String
2222
public let `protocol`: String
@@ -25,9 +25,9 @@ public struct APIGatewayV2Request: Codable {
2525
}
2626

2727
/// Authorizer contains authorizer information for the request context.
28-
public struct Authorizer: Codable {
28+
public struct Authorizer: AWSLambdaEvent {
2929
/// JWT contains JWT authorizer information for the request context.
30-
public struct JWT: Codable {
30+
public struct JWT: AWSLambdaEvent {
3131
public let claims: [String: String]?
3232
public let scopes: [String]?
3333
}

Sources/AWSLambdaEvents/APIGateway.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import class Foundation.JSONEncoder
1818
// https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
1919

2020
/// APIGatewayRequest contains data coming from the API Gateway
21-
public struct APIGatewayRequest: Codable {
22-
public struct Context: Codable {
23-
public struct Identity: Codable {
21+
public struct APIGatewayRequest: AWSLambdaEvent {
22+
public struct Context: AWSLambdaEvent {
23+
public struct Identity: AWSLambdaEvent {
2424
public let cognitoIdentityPoolId: String?
2525

2626
public let apiKey: String?
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftAWSLambdaRuntime open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the SwiftAWSLambdaRuntime project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
public protocol AWSLambdaEvent: Decodable, _AWSLambdaEventsSendable {}

Sources/AWSLambdaEvents/AWSRegion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// $ aws ssm get-parameters-by-path --path /aws/service/global-infrastructure/services/lambda/regions --output json
1717

1818
/// Enumeration of the AWS Regions.
19-
public struct AWSRegion: RawRepresentable, Equatable {
19+
public struct AWSRegion: RawRepresentable, Equatable, _AWSLambdaEventsSendable {
2020
public typealias RawValue = String
2121

2222
public let rawValue: String

Sources/AWSLambdaEvents/AppSync.swift

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
// https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html
16-
public struct AppSyncEvent: Decodable {
16+
public struct AppSyncEvent: AWSLambdaEvent {
1717
public let arguments: [String: ArgumentValue]
1818

19-
public enum ArgumentValue: Codable {
19+
public enum ArgumentValue: AWSLambdaEvent {
2020
case string(String)
2121
case dictionary([String: String])
2222

@@ -46,15 +46,15 @@ public struct AppSyncEvent: Decodable {
4646
}
4747

4848
public let request: Request
49-
public struct Request: Decodable {
49+
public struct Request: AWSLambdaEvent {
5050
let headers: HTTPHeaders
5151
}
5252

5353
public let source: [String: String]?
5454
public let stash: [String: String]?
5555

5656
public let info: Info
57-
public struct Info: Codable {
57+
public struct Info: AWSLambdaEvent {
5858
public var selectionSetList: [String]
5959
public var selectionSetGraphQL: String
6060
public var parentTypeName: String
@@ -63,11 +63,11 @@ public struct AppSyncEvent: Decodable {
6363
}
6464

6565
public let identity: Identity?
66-
public enum Identity: Codable {
66+
public enum Identity: AWSLambdaEvent {
6767
case iam(IAMIdentity)
6868
case cognitoUserPools(CognitoUserPoolIdentity)
6969

70-
public struct IAMIdentity: Codable {
70+
public struct IAMIdentity: AWSLambdaEvent {
7171
public let accountId: String
7272
public let cognitoIdentityPoolId: String
7373
public let cognitoIdentityId: String
@@ -78,7 +78,7 @@ public struct AppSyncEvent: Decodable {
7878
public let cognitoIdentityAuthProvider: String
7979
}
8080

81-
public struct CognitoUserPoolIdentity: Codable {
81+
public struct CognitoUserPoolIdentity: AWSLambdaEvent {
8282
public let defaultAuthStrategy: String
8383
public let issuer: String
8484
public let sourceIp: [String]
@@ -131,16 +131,6 @@ public struct AppSyncEvent: Decodable {
131131
""")
132132
}
133133
}
134-
135-
public func encode(to encoder: Encoder) throws {
136-
var container = encoder.singleValueContainer()
137-
switch self {
138-
case .iam(let iamIdentity):
139-
try container.encode(iamIdentity)
140-
case .cognitoUserPools(let cognitoUserPool):
141-
try container.encode(cognitoUserPool)
142-
}
143-
}
144134
}
145135
}
146136

Sources/AWSLambdaEvents/Cloudwatch.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
#if compiler(>=5.6)
16+
@preconcurrency import struct Foundation.Date
17+
#else
1518
import struct Foundation.Date
19+
#endif
1620

1721
/// EventBridge has the same events/notification types as CloudWatch
1822
typealias EventBridgeEvent = CloudwatchEvent
1923

20-
public protocol CloudwatchDetail: Decodable {
24+
public protocol CloudwatchDetail: AWSLambdaEvent {
2125
static var name: String { get }
2226
}
2327

@@ -33,7 +37,7 @@ extension CloudwatchDetail {
3337
/// https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html
3438
/// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html
3539
/// https://docs.aws.amazon.com/eventbridge/latest/userguide/event-types.html
36-
public struct CloudwatchEvent<Detail: CloudwatchDetail>: Decodable {
40+
public struct CloudwatchEvent<Detail: CloudwatchDetail>: AWSLambdaEvent {
3741
public let id: String
3842
public let source: String
3943
public let accountId: String
@@ -89,7 +93,7 @@ public enum CloudwatchDetails {
8993
public struct InstanceStateChangeNotification: CloudwatchDetail {
9094
public static let name = "EC2 Instance State-change Notification"
9195

92-
public enum State: String, Codable {
96+
public enum State: String, AWSLambdaEvent {
9397
case running
9498
case shuttingDown = "shutting-down"
9599
case stopped
@@ -109,7 +113,7 @@ public enum CloudwatchDetails {
109113
public struct SpotInstanceInterruptionNotice: CloudwatchDetail {
110114
public static let name = "EC2 Spot Instance Interruption Warning"
111115

112-
public enum Action: String, Codable {
116+
public enum Action: String, AWSLambdaEvent {
113117
case hibernate
114118
case stop
115119
case terminate

Sources/AWSLambdaEvents/DynamoDB.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,32 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
#if compiler(>=5.6)
16+
@preconcurrency import struct Foundation.Date
17+
#else
1518
import struct Foundation.Date
19+
#endif
1620

1721
// https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html
18-
public struct DynamoDBEvent: Decodable {
22+
public struct DynamoDBEvent: AWSLambdaEvent {
1923
public let records: [EventRecord]
2024

2125
public enum CodingKeys: String, CodingKey {
2226
case records = "Records"
2327
}
2428

25-
public enum KeyType: String, Codable {
29+
public enum KeyType: String, AWSLambdaEvent {
2630
case hash = "HASH"
2731
case range = "RANGE"
2832
}
2933

30-
public enum OperationType: String, Codable {
34+
public enum OperationType: String, AWSLambdaEvent {
3135
case insert = "INSERT"
3236
case modify = "MODIFY"
3337
case remove = "REMOVE"
3438
}
3539

36-
public enum SharedIteratorType: String, Codable {
40+
public enum SharedIteratorType: String, AWSLambdaEvent {
3741
case trimHorizon = "TRIM_HORIZON"
3842
case latest = "LATEST"
3943
case atSequenceNumber = "AT_SEQUENCE_NUMBER"
@@ -47,7 +51,7 @@ public struct DynamoDBEvent: Decodable {
4751
case disabled = "DISABLED"
4852
}
4953

50-
public enum StreamViewType: String, Codable {
54+
public enum StreamViewType: String, AWSLambdaEvent {
5155
/// the entire item, as it appeared after it was modified.
5256
case newImage = "NEW_IMAGE"
5357
/// the entire item, as it appeared before it was modified.
@@ -58,7 +62,7 @@ public struct DynamoDBEvent: Decodable {
5862
case keysOnly = "KEYS_ONLY"
5963
}
6064

61-
public struct EventRecord: Decodable {
65+
public struct EventRecord: AWSLambdaEvent {
6266
/// The region in which the GetRecords request was received.
6367
public let awsRegion: AWSRegion
6468

@@ -113,7 +117,7 @@ public struct DynamoDBEvent: Decodable {
113117
}
114118
}
115119

116-
public struct StreamRecord {
120+
public struct StreamRecord: AWSLambdaEvent {
117121
/// The approximate date and time when the stream record was created, in UNIX
118122
/// epoch time (http://www.epochconverter.com/) format.
119123
public let approximateCreationDateTime: Date?
@@ -138,7 +142,7 @@ public struct DynamoDBEvent: Decodable {
138142
public let streamViewType: StreamViewType
139143
}
140144

141-
public struct UserIdentity: Codable {
145+
public struct UserIdentity: AWSLambdaEvent {
142146
public let type: String
143147
public let principalId: String
144148
}
@@ -187,7 +191,7 @@ extension DynamoDBEvent.StreamRecord: Decodable {
187191
// MARK: - AttributeValue -
188192

189193
extension DynamoDBEvent {
190-
public enum AttributeValue {
194+
public enum AttributeValue: AWSLambdaEvent {
191195
case boolean(Bool)
192196
case binary([UInt8])
193197
case binarySet([[UInt8]])

Sources/AWSLambdaEvents/S3.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import struct Foundation.Date
1616

1717
// https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html
1818

19-
public struct S3Event: Decodable {
20-
public struct Record: Decodable {
19+
public struct S3Event: AWSLambdaEvent {
20+
public struct Record: AWSLambdaEvent {
2121
public let eventVersion: String
2222
public let eventSource: String
2323
public let awsRegion: AWSRegion
@@ -37,15 +37,15 @@ public struct S3Event: Decodable {
3737
case records = "Records"
3838
}
3939

40-
public struct RequestParameters: Codable, Equatable {
40+
public struct RequestParameters: AWSLambdaEvent, Equatable {
4141
public let sourceIPAddress: String
4242
}
4343

44-
public struct UserIdentity: Codable, Equatable {
44+
public struct UserIdentity: AWSLambdaEvent, Equatable {
4545
public let principalId: String
4646
}
4747

48-
public struct Entity: Codable {
48+
public struct Entity: AWSLambdaEvent {
4949
public let configurationId: String
5050
public let schemaVersion: String
5151
public let bucket: Bucket
@@ -59,13 +59,13 @@ public struct S3Event: Decodable {
5959
}
6060
}
6161

62-
public struct Bucket: Codable {
62+
public struct Bucket: AWSLambdaEvent {
6363
public let name: String
6464
public let ownerIdentity: UserIdentity
6565
public let arn: String
6666
}
6767

68-
public struct Object: Codable {
68+
public struct Object: AWSLambdaEvent {
6969
public let key: String
7070
/// The object's size in bytes.
7171
///

0 commit comments

Comments
 (0)