diff --git a/Package.swift b/Package.swift index b4d0217..c212921 100644 --- a/Package.swift +++ b/Package.swift @@ -13,8 +13,10 @@ let package = Package( ], targets: [ .target(name: "AWSLambdaEvents", - dependencies: [.product(name: "HTTPTypes", package: "swift-http-types")]), + dependencies: [.product(name: "HTTPTypes", package: "swift-http-types")], + swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]), .testTarget(name: "AWSLambdaEventsTests", - dependencies: ["AWSLambdaEvents"]), + dependencies: ["AWSLambdaEvents"], + swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]), ] ) diff --git a/Sources/AWSLambdaEvents/AWSRegion.swift b/Sources/AWSLambdaEvents/AWSRegion.swift index dcbc05a..3b340fc 100644 --- a/Sources/AWSLambdaEvents/AWSRegion.swift +++ b/Sources/AWSLambdaEvents/AWSRegion.swift @@ -25,7 +25,7 @@ public struct AWSRegion: RawRepresentable, Equatable { self.rawValue = rawValue } - static var all: [AWSRegion] = [ + static let all: [AWSRegion] = [ Self.af_south_1, Self.ap_northeast_1, Self.ap_northeast_2, diff --git a/Sources/AWSLambdaEvents/Cloudwatch.swift b/Sources/AWSLambdaEvents/Cloudwatch.swift index e2160c2..d814266 100644 --- a/Sources/AWSLambdaEvents/Cloudwatch.swift +++ b/Sources/AWSLambdaEvents/Cloudwatch.swift @@ -21,7 +21,7 @@ import struct Foundation.Date /// EventBridge has the same events/notification types as CloudWatch public typealias EventBridgeEvent = CloudwatchEvent -public protocol CloudwatchDetail: Decodable { +public protocol CloudwatchDetail: Decodable, Sendable { static var name: String { get } } @@ -37,7 +37,8 @@ extension CloudwatchDetail { /// https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html /// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html /// https://docs.aws.amazon.com/eventbridge/latest/userguide/event-types.html -public struct CloudwatchEvent: Decodable { +/// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events-structure.html +public struct CloudwatchEvent: Decodable, Sendable { public let id: String public let source: String public let accountId: String @@ -89,11 +90,11 @@ public enum CloudwatchDetails { public static let name = "Scheduled Event" } - public enum EC2 { + public enum EC2: Sendable { public struct InstanceStateChangeNotification: CloudwatchDetail { public static let name = "EC2 Instance State-change Notification" - public enum State: String, Codable { + public enum State: String, Codable, Sendable { case running case shuttingDown = "shutting-down" case stopped @@ -113,7 +114,7 @@ public enum CloudwatchDetails { public struct SpotInstanceInterruptionNotice: CloudwatchDetail { public static let name = "EC2 Spot Instance Interruption Warning" - public enum Action: String, Codable { + public enum Action: String, Codable, Sendable { case hibernate case stop case terminate @@ -131,12 +132,6 @@ public enum CloudwatchDetails { struct TypeMismatch: Error { let name: String - let type: Any + let type: any CloudwatchDetail.Type } } - -#if swift(>=5.6) -extension CloudwatchEvent: Sendable where Detail: Sendable {} -extension CloudwatchDetails.EC2: Sendable {} -extension CloudwatchDetails.Scheduled: Sendable {} -#endif diff --git a/Sources/AWSLambdaEvents/Utils/DateWrappers.swift b/Sources/AWSLambdaEvents/Utils/DateWrappers.swift index 235e380..36c6640 100644 --- a/Sources/AWSLambdaEvents/Utils/DateWrappers.swift +++ b/Sources/AWSLambdaEvents/Utils/DateWrappers.swift @@ -39,9 +39,7 @@ public struct ISO8601Coding: Decodable { self.wrappedValue = date } - private static let dateFormatter: DateFormatter = Self.createDateFormatter() - - private static func createDateFormatter() -> DateFormatter { + private static var dateFormatter: DateFormatter { let formatter = DateFormatter() formatter.locale = Locale(identifier: "en_US_POSIX") formatter.timeZone = TimeZone(secondsFromGMT: 0) @@ -68,9 +66,7 @@ public struct ISO8601WithFractionalSecondsCoding: Decodable { self.wrappedValue = date } - private static let dateFormatter: DateFormatter = Self.createDateFormatter() - - private static func createDateFormatter() -> DateFormatter { + private static var dateFormatter: DateFormatter { let formatter = DateFormatter() formatter.locale = Locale(identifier: "en_US_POSIX") formatter.timeZone = TimeZone(secondsFromGMT: 0) @@ -105,8 +101,7 @@ public struct RFC5322DateTimeCoding: Decodable { "Expected date to be in RFC5322 date-time format, but `\(string)` is not in the correct format") } - private static let dateFormatters: [DateFormatter] = Self.createDateFormatters() - private static func createDateFormatters() -> [DateFormatter] { + private static var dateFormatters: [DateFormatter] { // rfc5322 dates received in SES mails sometimes do not include the day, so need two dateformatters // one with a day and one without let formatterWithDay = DateFormatter()