Skip to content

cleanup pre Swift 5.6 code #51

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

Merged
merged 4 commits into from
May 29, 2024
Merged
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
15 changes: 4 additions & 11 deletions Sources/AWSLambdaEvents/ALB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import class Foundation.JSONEncoder

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

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

/// `ELBContext` contains information to identify the ARN invoking the lambda.
public struct ELBContext: Codable {
public struct ELBContext: Codable, Sendable {
public let targetGroupArn: String
}
}

public struct ALBTargetGroupResponse: Codable {
public struct ALBTargetGroupResponse: Codable, Sendable {
public var statusCode: HTTPResponse.Status
public var statusDescription: String?
public var headers: HTTPHeaders?
Expand All @@ -75,10 +75,3 @@ public struct ALBTargetGroupResponse: Codable {
self.isBase64Encoded = isBase64Encoded
}
}

#if swift(>=5.6)
extension ALBTargetGroupRequest: Sendable {}
extension ALBTargetGroupRequest.Context: Sendable {}
extension ALBTargetGroupRequest.ELBContext: Sendable {}
extension ALBTargetGroupResponse: Sendable {}
#endif
36 changes: 11 additions & 25 deletions Sources/AWSLambdaEvents/APIGateway+V2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import HTTPTypes

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

/// `Authorizer` contains authorizer information for the request context.
public struct Authorizer: Codable {
public struct Authorizer: Codable, Sendable {
/// `JWT` contains JWT authorizer information for the request context.
public struct JWT: Codable {
public struct JWT: Codable, Sendable {
public let claims: [String: String]?
public let scopes: [String]?
}

public let jwt: JWT?

// `IAM` contains AWS IAM authorizer information for the request context.
public struct IAM: Codable {
public struct CognitoIdentity: Codable {
public struct IAM: Codable, Sendable {
public struct CognitoIdentity: Codable, Sendable {
public let amr: [String]?
public let identityId: String?
public let identityPoolId: String?
Expand All @@ -58,9 +58,9 @@ public struct APIGatewayV2Request: Codable {
public let lambda: LambdaAuthorizerContext?
}

public struct Authentication: Codable {
public struct ClientCert: Codable {
public struct Validity: Codable {
public struct Authentication: Codable, Sendable {
public struct ClientCert: Codable, Sendable {
public struct Validity: Codable, Sendable {
public let notBefore: String
public let notAfter: String
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public struct APIGatewayV2Request: Codable {
}
}

public struct APIGatewayV2Response: Codable {
public struct APIGatewayV2Response: Codable, Sendable {
public var statusCode: HTTPResponse.Status
public var headers: HTTPHeaders?
public var body: String?
Expand All @@ -147,17 +147,3 @@ public struct APIGatewayV2Response: Codable {
self.cookies = cookies
}
}

#if swift(>=5.6)
extension APIGatewayV2Request: Sendable {}
extension APIGatewayV2Request.Context: Sendable {}
extension APIGatewayV2Request.Context.HTTP: Sendable {}
extension APIGatewayV2Request.Context.Authorizer: Sendable {}
extension APIGatewayV2Request.Context.Authorizer.JWT: Sendable {}
extension APIGatewayV2Request.Context.Authorizer.IAM: Sendable {}
extension APIGatewayV2Request.Context.Authorizer.IAM.CognitoIdentity: Sendable {}
extension APIGatewayV2Request.Context.Authentication: Sendable {}
extension APIGatewayV2Request.Context.Authentication.ClientCert: Sendable {}
extension APIGatewayV2Request.Context.Authentication.ClientCert.Validity: Sendable {}
extension APIGatewayV2Response: Sendable {}
#endif
18 changes: 5 additions & 13 deletions Sources/AWSLambdaEvents/APIGateway.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import class Foundation.JSONEncoder
// https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html

/// `APIGatewayRequest` contains data coming from the API Gateway.
public struct APIGatewayRequest: Codable {
public struct Context: Codable {
public struct Identity: Codable {
public struct APIGatewayRequest: Codable, Sendable {
public struct Context: Codable, Sendable {
public struct Identity: Codable, Sendable {
public let cognitoIdentityPoolId: String?

public let apiKey: String?
Expand All @@ -37,7 +37,7 @@ public struct APIGatewayRequest: Codable {
public let accountId: String?
}

public struct Authorizer: Codable {
public struct Authorizer: Codable, Sendable {
public let claims: [String: String]?
}

Expand Down Expand Up @@ -74,7 +74,7 @@ public struct APIGatewayRequest: Codable {

// MARK: - Response -

public struct APIGatewayResponse: Codable {
public struct APIGatewayResponse: Codable, Sendable {
public var statusCode: HTTPResponse.Status
public var headers: HTTPHeaders?
public var multiValueHeaders: HTTPMultiValueHeaders?
Expand All @@ -95,11 +95,3 @@ public struct APIGatewayResponse: Codable {
self.isBase64Encoded = isBase64Encoded
}
}

#if swift(>=5.6)
extension APIGatewayRequest: Sendable {}
extension APIGatewayRequest.Context: Sendable {}
extension APIGatewayRequest.Context.Identity: Sendable {}
extension APIGatewayRequest.Context.Authorizer: Sendable {}
extension APIGatewayResponse: Sendable {}
#endif
28 changes: 8 additions & 20 deletions Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import HTTPTypes
public typealias LambdaAuthorizerContext = [String: String]

/// `APIGatewayLambdaAuthorizerRequest` contains the payload sent to a Lambda Authorizer function
public struct APIGatewayLambdaAuthorizerRequest: Codable {
public struct APIGatewayLambdaAuthorizerRequest: Codable, Sendable {
public let version: String
public let type: String
public let routeArn: String?
Expand All @@ -29,8 +29,8 @@ public struct APIGatewayLambdaAuthorizerRequest: Codable {
public let headers: [String: String]

/// `Context` contains information to identify the AWS account and resources invoking the Lambda function.
public struct Context: Codable {
public struct HTTP: Codable {
public struct Context: Codable, Sendable {
public struct HTTP: Codable, Sendable {
public let method: HTTPRequest.Method
public let path: String
public let `protocol`: String
Expand All @@ -56,7 +56,7 @@ public struct APIGatewayLambdaAuthorizerRequest: Codable {
}

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

Expand All @@ -68,15 +68,15 @@ public struct APIGatewayLambdaAuthorizerSimpleResponse: Codable {
}

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

/// `PolicyDocument` contains an IAM policy document
public struct PolicyDocument: Codable {
public struct PolicyDocument: Codable, Sendable {
public let version: String

public struct Statement: Codable {
public enum Effect: String, Codable {
public struct Statement: Codable, Sendable {
public enum Effect: String, Codable, Sendable {
case allow = "Allow"
case deny = "Deny"
}
Expand Down Expand Up @@ -121,15 +121,3 @@ public struct APIGatewayLambdaAuthorizerPolicyResponse: Codable {
self.context = context
}
}

#if swift(>=5.6)
extension LambdaAuthorizerContext: Sendable {}
extension APIGatewayLambdaAuthorizerRequest: Sendable {}
extension APIGatewayLambdaAuthorizerRequest.Context: Sendable {}
extension APIGatewayLambdaAuthorizerRequest.Context.HTTP: Sendable {}
extension APIGatewayLambdaAuthorizerSimpleResponse: Sendable {}
extension APIGatewayLambdaAuthorizerPolicyResponse: Sendable {}
extension APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument: Sendable {}
extension APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument.Statement: Sendable {}
extension APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument.Statement.Effect: Sendable {}
#endif
6 changes: 1 addition & 5 deletions Sources/AWSLambdaEvents/AWSRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// $ aws ssm get-parameters-by-path --path /aws/service/global-infrastructure/services/lambda/regions --output json

/// Enumeration of the AWS Regions.
public struct AWSRegion: RawRepresentable, Equatable {
public struct AWSRegion: RawRepresentable, Equatable, Sendable {
public typealias RawValue = String

public let rawValue: String
Expand Down Expand Up @@ -107,7 +107,3 @@ extension AWSRegion: Codable {
try container.encode(self.rawValue)
}
}

#if swift(>=5.6)
extension AWSRegion: Sendable {}
#endif
24 changes: 7 additions & 17 deletions Sources/AWSLambdaEvents/AppSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import HTTPTypes

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

public enum ArgumentValue: Codable {
public enum ArgumentValue: Codable, Sendable {
case string(String)
case dictionary([String: String])

Expand Down Expand Up @@ -48,15 +48,15 @@ public struct AppSyncEvent: Decodable {
}

public let request: Request
public struct Request: Decodable {
public struct Request: Decodable, Sendable {
let headers: HTTPHeaders
}

public let source: [String: String]?
public let stash: [String: String]?

public let info: Info
public struct Info: Codable {
public struct Info: Codable, Sendable {
public var selectionSetList: [String]
public var selectionSetGraphQL: String
public var parentTypeName: String
Expand All @@ -65,11 +65,11 @@ public struct AppSyncEvent: Decodable {
}

public let identity: Identity?
public enum Identity: Codable {
public enum Identity: Codable, Sendable {
case iam(IAMIdentity)
case cognitoUserPools(CognitoUserPoolIdentity)

public struct IAMIdentity: Codable {
public struct IAMIdentity: Codable, Sendable {
public let accountId: String
public let cognitoIdentityPoolId: String
public let cognitoIdentityId: String
Expand All @@ -80,7 +80,7 @@ public struct AppSyncEvent: Decodable {
public let cognitoIdentityAuthProvider: String
}

public struct CognitoUserPoolIdentity: Codable {
public struct CognitoUserPoolIdentity: Codable, Sendable {
public let defaultAuthStrategy: String
public let issuer: String
public let sourceIp: [String]
Expand Down Expand Up @@ -165,14 +165,4 @@ public enum AppSyncResponse<ResultType: Encodable>: Encodable {
}

public typealias AppSyncJSONResponse = AppSyncResponse<String>

#if swift(>=5.6)
extension AppSyncEvent: Sendable {}
extension AppSyncEvent.ArgumentValue: Sendable {}
extension AppSyncEvent.Request: Sendable {}
extension AppSyncEvent.Info: Sendable {}
extension AppSyncEvent.Identity: Sendable {}
extension AppSyncEvent.Identity.CognitoUserPoolIdentity: Sendable {}
extension AppSyncEvent.Identity.IAMIdentity: Sendable {}
extension AppSyncResponse: Sendable where ResultType: Sendable {}
#endif
9 changes: 6 additions & 3 deletions Sources/AWSLambdaEvents/CloudFormation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
//===----------------------------------------------------------------------===//

// CloudFormation custom resource.
public enum CloudFormation {
public enum CloudFormation: Sendable {
// Request represents the request body of AWS::CloudFormation::CustomResource.
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requests.html
public struct Request<R: Decodable, O: Decodable>: Decodable {
public enum RequestType: String, Decodable {
public enum RequestType: String, Decodable, Sendable {
case create = "Create"
case update = "Update"
case delete = "Delete"
Expand Down Expand Up @@ -60,7 +60,7 @@ public enum CloudFormation {
// Response represents the response body of AWS::CloudFormation::CustomResource.
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html
public struct Response<D: Encodable>: Encodable {
public enum StatusType: String, Encodable {
public enum StatusType: String, Encodable, Sendable {
case success = "SUCCESS"
case failed = "FAILED"
}
Expand Down Expand Up @@ -119,3 +119,6 @@ public enum CloudFormation {
}
}
}

extension CloudFormation.Request: Sendable where R: Sendable, O: Sendable {}
extension CloudFormation.Response: Sendable where D: Sendable {}
14 changes: 7 additions & 7 deletions Sources/AWSLambdaEvents/Cognito.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
//
//===----------------------------------------------------------------------===//

enum CognitoEventError: Error {
enum CognitoEventError: Error, Sendable {
case unimplementedEvent(String)
}

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

public struct Parameters: Codable, Equatable {
public struct Parameters: Codable, Equatable, Sendable {
let version: String
let triggerSource: String
let region: AWSRegion
Expand All @@ -34,7 +34,7 @@ public enum CognitoEvent: Equatable {

case preSignUpSignUp(Parameters, PreSignUp)

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

public enum CognitoEventResponse {
public enum CognitoEventResponse: Sendable {
case preSignUpSignUp(CognitoEvent.Parameters, CognitoEvent.PreSignUp, PreSignUp)

public struct PreSignUp: Codable, Hashable {
public struct PreSignUp: Codable, Hashable, Sendable {
public let autoConfirmUser: Bool
public let autoVerifyPhone: Bool
public let autoVerifyEmail: Bool
Expand Down
Loading