Skip to content

addopt strict concurrency #50

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 11 commits into from
May 28, 2024
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")]),
]
)
2 changes: 1 addition & 1 deletion Sources/AWSLambdaEvents/AWSRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion Sources/AWSLambdaEvents/Cloudwatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ 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
/// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events-structure.html
public struct CloudwatchEvent<Detail: CloudwatchDetail>: Decodable {
public let id: String
public let source: String
Expand Down Expand Up @@ -131,7 +132,7 @@ public enum CloudwatchDetails {

struct TypeMismatch: Error {
let name: String
let type: Any
let type: any Sendable
}
}

Expand Down
17 changes: 6 additions & 11 deletions Sources/AWSLambdaEvents/Utils/DateWrappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ public struct ISO8601Coding: Decodable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let dateString = try container.decode(String.self)
guard let date = Self.dateFormatter.date(from: dateString) else {
guard let date = Self.dateFormatter().date(from: dateString) else {
throw DecodingError.dataCorruptedError(in: container, debugDescription:
"Expected date to be in ISO8601 date format, but `\(dateString)` is not in the correct format")
}
self.wrappedValue = date
}

private static let dateFormatter: DateFormatter = Self.createDateFormatter()

private static func createDateFormatter() -> DateFormatter {
private static func dateFormatter() -> DateFormatter {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.timeZone = TimeZone(secondsFromGMT: 0)
Expand All @@ -61,16 +59,14 @@ public struct ISO8601WithFractionalSecondsCoding: Decodable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let dateString = try container.decode(String.self)
guard let date = Self.dateFormatter.date(from: dateString) else {
guard let date = Self.dateFormatter().date(from: dateString) else {
throw DecodingError.dataCorruptedError(in: container, debugDescription:
"Expected date to be in ISO8601 date format with fractional seconds, but `\(dateString)` is not in the correct format")
}
self.wrappedValue = date
}

private static let dateFormatter: DateFormatter = Self.createDateFormatter()

private static func createDateFormatter() -> DateFormatter {
private static func dateFormatter() -> DateFormatter {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.timeZone = TimeZone(secondsFromGMT: 0)
Expand All @@ -95,7 +91,7 @@ public struct RFC5322DateTimeCoding: Decodable {
if let bracket = string.firstIndex(of: "(") {
string = String(string[string.startIndex ..< bracket].trimmingCharacters(in: .whitespaces))
}
for formatter in Self.dateFormatters {
for formatter in Self.dateFormatters() {
if let date = formatter.date(from: string) {
self.wrappedValue = date
return
Expand All @@ -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 func 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()
Expand Down