Skip to content

Commit 2c04633

Browse files
authored
cleanup pre Swift 5.6 code (#51)
remove "if swift(>=5.6)" statements and move Sendable up to the struct definition
1 parent 99a3bf1 commit 2c04633

16 files changed

+98
-218
lines changed

Sources/AWSLambdaEvents/ALB.swift

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

1919
// https://github.com/aws/aws-lambda-go/blob/master/events/alb.go
2020
/// `ALBTargetGroupRequest` contains data originating from the ALB Lambda target group integration.
21-
public struct ALBTargetGroupRequest: Codable {
21+
public struct ALBTargetGroupRequest: Codable, Sendable {
2222
/// `Context` contains information to identify the load balancer invoking the lambda.
23-
public struct Context: Codable {
23+
public struct Context: Codable, Sendable {
2424
public let elb: ELBContext
2525
}
2626

@@ -46,12 +46,12 @@ public struct ALBTargetGroupRequest: Codable {
4646
public let body: String?
4747

4848
/// `ELBContext` contains information to identify the ARN invoking the lambda.
49-
public struct ELBContext: Codable {
49+
public struct ELBContext: Codable, Sendable {
5050
public let targetGroupArn: String
5151
}
5252
}
5353

54-
public struct ALBTargetGroupResponse: Codable {
54+
public struct ALBTargetGroupResponse: Codable, Sendable {
5555
public var statusCode: HTTPResponse.Status
5656
public var statusDescription: String?
5757
public var headers: HTTPHeaders?
@@ -75,10 +75,3 @@ public struct ALBTargetGroupResponse: Codable {
7575
self.isBase64Encoded = isBase64Encoded
7676
}
7777
}
78-
79-
#if swift(>=5.6)
80-
extension ALBTargetGroupRequest: Sendable {}
81-
extension ALBTargetGroupRequest.Context: Sendable {}
82-
extension ALBTargetGroupRequest.ELBContext: Sendable {}
83-
extension ALBTargetGroupResponse: Sendable {}
84-
#endif

Sources/AWSLambdaEvents/APIGateway+V2.swift

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import HTTPTypes
1616

1717
/// `APIGatewayV2Request` contains data coming from the new HTTP API Gateway.
18-
public struct APIGatewayV2Request: Codable {
18+
public struct APIGatewayV2Request: Codable, Sendable {
1919
/// `Context` contains information to identify the AWS account and resources invoking the Lambda function.
20-
public struct Context: Codable {
21-
public struct HTTP: Codable {
20+
public struct Context: Codable, Sendable {
21+
public struct HTTP: Codable, Sendable {
2222
public let method: HTTPRequest.Method
2323
public let path: String
2424
public let `protocol`: String
@@ -27,18 +27,18 @@ public struct APIGatewayV2Request: Codable {
2727
}
2828

2929
/// `Authorizer` contains authorizer information for the request context.
30-
public struct Authorizer: Codable {
30+
public struct Authorizer: Codable, Sendable {
3131
/// `JWT` contains JWT authorizer information for the request context.
32-
public struct JWT: Codable {
32+
public struct JWT: Codable, Sendable {
3333
public let claims: [String: String]?
3434
public let scopes: [String]?
3535
}
3636

3737
public let jwt: JWT?
3838

3939
// `IAM` contains AWS IAM authorizer information for the request context.
40-
public struct IAM: Codable {
41-
public struct CognitoIdentity: Codable {
40+
public struct IAM: Codable, Sendable {
41+
public struct CognitoIdentity: Codable, Sendable {
4242
public let amr: [String]?
4343
public let identityId: String?
4444
public let identityPoolId: String?
@@ -58,9 +58,9 @@ public struct APIGatewayV2Request: Codable {
5858
public let lambda: LambdaAuthorizerContext?
5959
}
6060

61-
public struct Authentication: Codable {
62-
public struct ClientCert: Codable {
63-
public struct Validity: Codable {
61+
public struct Authentication: Codable, Sendable {
62+
public struct ClientCert: Codable, Sendable {
63+
public struct Validity: Codable, Sendable {
6464
public let notBefore: String
6565
public let notAfter: String
6666
}
@@ -126,7 +126,7 @@ public struct APIGatewayV2Request: Codable {
126126
}
127127
}
128128

129-
public struct APIGatewayV2Response: Codable {
129+
public struct APIGatewayV2Response: Codable, Sendable {
130130
public var statusCode: HTTPResponse.Status
131131
public var headers: HTTPHeaders?
132132
public var body: String?
@@ -147,17 +147,3 @@ public struct APIGatewayV2Response: Codable {
147147
self.cookies = cookies
148148
}
149149
}
150-
151-
#if swift(>=5.6)
152-
extension APIGatewayV2Request: Sendable {}
153-
extension APIGatewayV2Request.Context: Sendable {}
154-
extension APIGatewayV2Request.Context.HTTP: Sendable {}
155-
extension APIGatewayV2Request.Context.Authorizer: Sendable {}
156-
extension APIGatewayV2Request.Context.Authorizer.JWT: Sendable {}
157-
extension APIGatewayV2Request.Context.Authorizer.IAM: Sendable {}
158-
extension APIGatewayV2Request.Context.Authorizer.IAM.CognitoIdentity: Sendable {}
159-
extension APIGatewayV2Request.Context.Authentication: Sendable {}
160-
extension APIGatewayV2Request.Context.Authentication.ClientCert: Sendable {}
161-
extension APIGatewayV2Request.Context.Authentication.ClientCert.Validity: Sendable {}
162-
extension APIGatewayV2Response: Sendable {}
163-
#endif

Sources/AWSLambdaEvents/APIGateway.swift

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

2222
/// `APIGatewayRequest` contains data coming from the API Gateway.
23-
public struct APIGatewayRequest: Codable {
24-
public struct Context: Codable {
25-
public struct Identity: Codable {
23+
public struct APIGatewayRequest: Codable, Sendable {
24+
public struct Context: Codable, Sendable {
25+
public struct Identity: Codable, Sendable {
2626
public let cognitoIdentityPoolId: String?
2727

2828
public let apiKey: String?
@@ -37,7 +37,7 @@ public struct APIGatewayRequest: Codable {
3737
public let accountId: String?
3838
}
3939

40-
public struct Authorizer: Codable {
40+
public struct Authorizer: Codable, Sendable {
4141
public let claims: [String: String]?
4242
}
4343

@@ -74,7 +74,7 @@ public struct APIGatewayRequest: Codable {
7474

7575
// MARK: - Response -
7676

77-
public struct APIGatewayResponse: Codable {
77+
public struct APIGatewayResponse: Codable, Sendable {
7878
public var statusCode: HTTPResponse.Status
7979
public var headers: HTTPHeaders?
8080
public var multiValueHeaders: HTTPMultiValueHeaders?
@@ -95,11 +95,3 @@ public struct APIGatewayResponse: Codable {
9595
self.isBase64Encoded = isBase64Encoded
9696
}
9797
}
98-
99-
#if swift(>=5.6)
100-
extension APIGatewayRequest: Sendable {}
101-
extension APIGatewayRequest.Context: Sendable {}
102-
extension APIGatewayRequest.Context.Identity: Sendable {}
103-
extension APIGatewayRequest.Context.Authorizer: Sendable {}
104-
extension APIGatewayResponse: Sendable {}
105-
#endif

Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import HTTPTypes
1818
public typealias LambdaAuthorizerContext = [String: String]
1919

2020
/// `APIGatewayLambdaAuthorizerRequest` contains the payload sent to a Lambda Authorizer function
21-
public struct APIGatewayLambdaAuthorizerRequest: Codable {
21+
public struct APIGatewayLambdaAuthorizerRequest: Codable, Sendable {
2222
public let version: String
2323
public let type: String
2424
public let routeArn: String?
@@ -29,8 +29,8 @@ public struct APIGatewayLambdaAuthorizerRequest: Codable {
2929
public let headers: [String: String]
3030

3131
/// `Context` contains information to identify the AWS account and resources invoking the Lambda function.
32-
public struct Context: Codable {
33-
public struct HTTP: Codable {
32+
public struct Context: Codable, Sendable {
33+
public struct HTTP: Codable, Sendable {
3434
public let method: HTTPRequest.Method
3535
public let path: String
3636
public let `protocol`: String
@@ -56,7 +56,7 @@ public struct APIGatewayLambdaAuthorizerRequest: Codable {
5656
}
5757

5858
/// `APIGatewayLambdaAuthorizerSimpleResponse` contains a simple response (yes/no) returned by a Lambda authorizer function
59-
public struct APIGatewayLambdaAuthorizerSimpleResponse: Codable {
59+
public struct APIGatewayLambdaAuthorizerSimpleResponse: Codable, Sendable {
6060
public let isAuthorized: Bool
6161
public let context: LambdaAuthorizerContext?
6262

@@ -68,15 +68,15 @@ public struct APIGatewayLambdaAuthorizerSimpleResponse: Codable {
6868
}
6969

7070
/// `APIGatewayLambdaAuthorizerPolicyResponse` contains a Policy response (inc. an IAM policy document) returned by a Lambda authorizer function
71-
public struct APIGatewayLambdaAuthorizerPolicyResponse: Codable {
71+
public struct APIGatewayLambdaAuthorizerPolicyResponse: Codable, Sendable {
7272
public let principalId: String
7373

7474
/// `PolicyDocument` contains an IAM policy document
75-
public struct PolicyDocument: Codable {
75+
public struct PolicyDocument: Codable, Sendable {
7676
public let version: String
7777

78-
public struct Statement: Codable {
79-
public enum Effect: String, Codable {
78+
public struct Statement: Codable, Sendable {
79+
public enum Effect: String, Codable, Sendable {
8080
case allow = "Allow"
8181
case deny = "Deny"
8282
}
@@ -121,15 +121,3 @@ public struct APIGatewayLambdaAuthorizerPolicyResponse: Codable {
121121
self.context = context
122122
}
123123
}
124-
125-
#if swift(>=5.6)
126-
extension LambdaAuthorizerContext: Sendable {}
127-
extension APIGatewayLambdaAuthorizerRequest: Sendable {}
128-
extension APIGatewayLambdaAuthorizerRequest.Context: Sendable {}
129-
extension APIGatewayLambdaAuthorizerRequest.Context.HTTP: Sendable {}
130-
extension APIGatewayLambdaAuthorizerSimpleResponse: Sendable {}
131-
extension APIGatewayLambdaAuthorizerPolicyResponse: Sendable {}
132-
extension APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument: Sendable {}
133-
extension APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument.Statement: Sendable {}
134-
extension APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument.Statement.Effect: Sendable {}
135-
#endif

Sources/AWSLambdaEvents/AWSRegion.swift

Lines changed: 1 addition & 5 deletions
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, Sendable {
2020
public typealias RawValue = String
2121

2222
public let rawValue: String
@@ -107,7 +107,3 @@ extension AWSRegion: Codable {
107107
try container.encode(self.rawValue)
108108
}
109109
}
110-
111-
#if swift(>=5.6)
112-
extension AWSRegion: Sendable {}
113-
#endif

Sources/AWSLambdaEvents/AppSync.swift

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import HTTPTypes
1616

1717
// https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html
18-
public struct AppSyncEvent: Decodable {
18+
public struct AppSyncEvent: Decodable, Sendable {
1919
public let arguments: [String: ArgumentValue]
2020

21-
public enum ArgumentValue: Codable {
21+
public enum ArgumentValue: Codable, Sendable {
2222
case string(String)
2323
case dictionary([String: String])
2424

@@ -48,15 +48,15 @@ public struct AppSyncEvent: Decodable {
4848
}
4949

5050
public let request: Request
51-
public struct Request: Decodable {
51+
public struct Request: Decodable, Sendable {
5252
let headers: HTTPHeaders
5353
}
5454

5555
public let source: [String: String]?
5656
public let stash: [String: String]?
5757

5858
public let info: Info
59-
public struct Info: Codable {
59+
public struct Info: Codable, Sendable {
6060
public var selectionSetList: [String]
6161
public var selectionSetGraphQL: String
6262
public var parentTypeName: String
@@ -65,11 +65,11 @@ public struct AppSyncEvent: Decodable {
6565
}
6666

6767
public let identity: Identity?
68-
public enum Identity: Codable {
68+
public enum Identity: Codable, Sendable {
6969
case iam(IAMIdentity)
7070
case cognitoUserPools(CognitoUserPoolIdentity)
7171

72-
public struct IAMIdentity: Codable {
72+
public struct IAMIdentity: Codable, Sendable {
7373
public let accountId: String
7474
public let cognitoIdentityPoolId: String
7575
public let cognitoIdentityId: String
@@ -80,7 +80,7 @@ public struct AppSyncEvent: Decodable {
8080
public let cognitoIdentityAuthProvider: String
8181
}
8282

83-
public struct CognitoUserPoolIdentity: Codable {
83+
public struct CognitoUserPoolIdentity: Codable, Sendable {
8484
public let defaultAuthStrategy: String
8585
public let issuer: String
8686
public let sourceIp: [String]
@@ -165,14 +165,4 @@ public enum AppSyncResponse<ResultType: Encodable>: Encodable {
165165
}
166166

167167
public typealias AppSyncJSONResponse = AppSyncResponse<String>
168-
169-
#if swift(>=5.6)
170-
extension AppSyncEvent: Sendable {}
171-
extension AppSyncEvent.ArgumentValue: Sendable {}
172-
extension AppSyncEvent.Request: Sendable {}
173-
extension AppSyncEvent.Info: Sendable {}
174-
extension AppSyncEvent.Identity: Sendable {}
175-
extension AppSyncEvent.Identity.CognitoUserPoolIdentity: Sendable {}
176-
extension AppSyncEvent.Identity.IAMIdentity: Sendable {}
177168
extension AppSyncResponse: Sendable where ResultType: Sendable {}
178-
#endif

Sources/AWSLambdaEvents/CloudFormation.swift

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

1515
// CloudFormation custom resource.
16-
public enum CloudFormation {
16+
public enum CloudFormation: Sendable {
1717
// Request represents the request body of AWS::CloudFormation::CustomResource.
1818
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requests.html
1919
public struct Request<R: Decodable, O: Decodable>: Decodable {
20-
public enum RequestType: String, Decodable {
20+
public enum RequestType: String, Decodable, Sendable {
2121
case create = "Create"
2222
case update = "Update"
2323
case delete = "Delete"
@@ -60,7 +60,7 @@ public enum CloudFormation {
6060
// Response represents the response body of AWS::CloudFormation::CustomResource.
6161
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html
6262
public struct Response<D: Encodable>: Encodable {
63-
public enum StatusType: String, Encodable {
63+
public enum StatusType: String, Encodable, Sendable {
6464
case success = "SUCCESS"
6565
case failed = "FAILED"
6666
}
@@ -119,3 +119,6 @@ public enum CloudFormation {
119119
}
120120
}
121121
}
122+
123+
extension CloudFormation.Request: Sendable where R: Sendable, O: Sendable {}
124+
extension CloudFormation.Response: Sendable where D: Sendable {}

Sources/AWSLambdaEvents/Cognito.swift

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

15-
enum CognitoEventError: Error {
15+
enum CognitoEventError: Error, Sendable {
1616
case unimplementedEvent(String)
1717
}
1818

1919
/// https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html
20-
public enum CognitoEvent: Equatable {
21-
public struct CallerContext: Codable, Hashable {
20+
public enum CognitoEvent: Equatable, Sendable {
21+
public struct CallerContext: Codable, Hashable, Sendable {
2222
let awsSdkVersion: String
2323
let clientId: String
2424
}
2525

26-
public struct Parameters: Codable, Equatable {
26+
public struct Parameters: Codable, Equatable, Sendable {
2727
let version: String
2828
let triggerSource: String
2929
let region: AWSRegion
@@ -34,7 +34,7 @@ public enum CognitoEvent: Equatable {
3434

3535
case preSignUpSignUp(Parameters, PreSignUp)
3636

37-
public struct PreSignUp: Codable, Hashable {
37+
public struct PreSignUp: Codable, Hashable, Sendable {
3838
/// One or more name-value pairs representing user attributes. The attribute names are the keys.
3939
public let userAttributes: [String: String]
4040
/// One or more name-value pairs containing the validation data in the request to register a user.
@@ -108,10 +108,10 @@ extension CognitoEvent: Codable {
108108
}
109109
}
110110

111-
public enum CognitoEventResponse {
111+
public enum CognitoEventResponse: Sendable {
112112
case preSignUpSignUp(CognitoEvent.Parameters, CognitoEvent.PreSignUp, PreSignUp)
113113

114-
public struct PreSignUp: Codable, Hashable {
114+
public struct PreSignUp: Codable, Hashable, Sendable {
115115
public let autoConfirmUser: Bool
116116
public let autoVerifyPhone: Bool
117117
public let autoVerifyEmail: Bool

0 commit comments

Comments
 (0)