Skip to content

Commit 3d5faf8

Browse files
authored
Strict Concurrency Support (#15)
* Remove SwiftLint, enable strict concurrency * Upgrade dependencies * Fix errors from change to HTTPTypes * Sendable conformances * Fix warnings * Add Danger workflow * Sort rules * Disable optional_data_string_conversion * SwiftLint fixes * Replace @retroactive with fully qualified names * generic -> regular * Update toolchain version
1 parent 17985a0 commit 3d5faf8

File tree

11 files changed

+105
-126
lines changed

11 files changed

+105
-126
lines changed

.github/workflows/danger.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Run Danger
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- ready_for_review
10+
11+
jobs:
12+
build:
13+
if: github.event.pull_request.draft == false
14+
name: Run Danger
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
issues: write
19+
pull-requests: write
20+
steps:
21+
- name: Git checkout
22+
uses: actions/checkout@v4
23+
- name: Danger
24+
uses: 417-72KI/[email protected]
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.swiftlint.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,32 @@ excluded:
22
- .build
33

44
opt_in_rules:
5+
- array_init
6+
- attributes
7+
- closure_end_indentation
8+
- closure_spacing
59
- empty_count
610
- explicit_init
7-
- closure_spacing
8-
- overridden_super_call
9-
- redundant_nil_coalescing
10-
- private_outlet
11+
- extension_access_modifier
12+
- fatal_error_message
13+
- first_where
14+
- let_var_whitespace
15+
- literal_expression_end_indentation
1116
- nimble_operator
12-
- attributes
1317
- operator_usage_whitespace
14-
- closure_end_indentation
15-
- first_where
18+
- overridden_super_call
19+
- pattern_matching_keywords
20+
- private_outlet
1621
- prohibited_super_call
17-
- fatal_error_message
18-
- vertical_parameter_alignment_on_call
19-
- let_var_whitespace
22+
- redundant_nil_coalescing
2023
- unneeded_parentheses_in_closure_argument
21-
- extension_access_modifier
22-
- pattern_matching_keywords
23-
- array_init
24-
- literal_expression_end_indentation
24+
- vertical_parameter_alignment_on_call
2525

2626
disabled_rules:
27-
- void_return
2827
- multiple_closures_with_trailing_closure
28+
- optional_data_string_conversion
2929
- vertical_parameter_alignment_on_call
30+
- void_return
3031

3132
identifier_name:
3233
excluded:

Dangerfile.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Danger
2+
3+
extension String: Error {}
4+
5+
let danger = Danger()
6+
7+
if danger.github.pullRequest.body == nil {
8+
danger.fail("Please add a description to this Pull Request")
9+
}
10+
11+
SwiftLint
12+
.lint(
13+
.all(directory: nil),
14+
configFile: ".swiftlint.yml"
15+
)

Package.resolved

Lines changed: 20 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.7
1+
// swift-tools-version: 5.9
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -14,10 +14,10 @@ let package = Package(
1414
.library(name: "LambdaMocks", targets: ["LambdaMocks"])
1515
],
1616
dependencies: [
17-
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")),
18-
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")),
19-
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", .upToNextMajor(from: "0.2.0")),
20-
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", "1.0.0-alpha.1"..<"1.0.0-beta.999")
17+
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.2"),
18+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.43.1"),
19+
.package(url: "https://github.com/swift-server/swift-aws-lambda-events", from: "0.2.0"),
20+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime", from: "1.0.0-alpha.3")
2121
]
2222
)
2323

@@ -33,7 +33,7 @@ let targets: [Target] = [
3333
name: "LambdaExtras",
3434
dependencies: [
3535
"LambdaExtrasCore",
36-
.product(name: "AWSLambdaRuntime",package: "swift-aws-lambda-runtime"),
36+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
3737
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events")
3838
]
3939
),
@@ -54,11 +54,8 @@ let targets: [Target] = [
5454
)
5555
]
5656

57-
#if os(macOS)
58-
package.dependencies.append(.package(url: "https://github.com/realm/SwiftLint.git", from: "0.54.0"))
5957
for target in targets {
60-
target.plugins = [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
58+
target.swiftSettings = [.enableExperimentalFeature("StrictConcurrency")]
6159
}
62-
#endif
6360

6461
package.targets = targets

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Swifty helpers for working with AWS Lambda.
44

55
## 📱 Requirements
66

7-
Swift 5.7 toolchain with Swift Package Manager.
7+
Swift 5.9 toolchain with Swift Package Manager.
88

99
## 🖥 Installation
1010

@@ -32,8 +32,8 @@ Where `<product>` is one of the following:
3232

3333
This package is intended to support the creation of lambdas composed of 2 parts:
3434

35-
- a generic target with a handler implementing the core logic without AWS dependencies
36-
- an executable target using that generic one
35+
- a regular target with a handler implementing the core logic without AWS dependencies
36+
- an executable target using that regular one
3737

3838
### Handler
3939

Sources/LambdaExtras/APIGatewayCoder.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import AWSLambdaEvents
99
import AWSLambdaRuntime
1010
import Foundation
11+
import HTTPTypes
1112
import LambdaExtrasCore
1213

1314
/// A coder for APIGateway events.
14-
public struct APIGatewayCoder<E, O>: LambdaCoding where E: Codable, E: Sendable, O: Sendable {
15+
public struct APIGatewayCoder<E, O>: LambdaCoding, Sendable where E: Codable, E: Sendable, O: Sendable {
1516
/// A JSON decoder.
1617
let decoder: JSONDecoder
1718

@@ -52,16 +53,16 @@ public struct APIGatewayCoder<E, O>: LambdaCoding where E: Codable, E: Sendable,
5253
}
5354

5455
public func encode(error: Error) throws -> APIGatewayV2Response {
55-
let statusCode: HTTPResponseStatus
56+
let status: HTTPResponse.Status
5657
switch error {
5758
case HandlerError.emptyBody:
58-
statusCode = .badRequest
59+
status = .badRequest
5960
default:
60-
statusCode = .internalServerError
61+
status = .internalServerError
6162
}
6263

6364
return APIGatewayV2Response(
64-
statusCode: statusCode,
65+
statusCode: status,
6566
body: try errorBodyProvider(error.localizedDescription))
6667
}
6768
}

Sources/LambdaExtrasCore/Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public extension Optional {
7979
}
8080
}
8181

82-
extension String: LocalizedError {
82+
extension Swift.String: Foundation.LocalizedError {
8383
public var errorDescription: String? { self }
8484
public var failureReason: String? { self }
8585
}

Sources/LambdaExtrasCore/HandlerError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
/// An error that occurs during lambda handler execution.
11-
public enum HandlerError: Error, Equatable, LocalizedError {
11+
public enum HandlerError: Error, Equatable, LocalizedError, Sendable {
1212
/// The request is missing a body.
1313
case emptyBody
1414
/// The lambda context is missing an expected environment variable.

Sources/LambdaMocks/Extensions/APIGatewayV2+Utils.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import AWSLambdaEvents
99
import Foundation
10+
import HTTPTypes
1011

1112
// MARK: - Helpers
1213

@@ -53,7 +54,7 @@ public extension APIGatewayV2Request {
5354
static func mock<T: Encodable>(
5455
_ bodyValue: T,
5556
encodedWith encoder: JSONEncoder = .init(),
56-
method: HTTPMethod = .POST,
57+
method: HTTPRequest.Method = .post,
5758
rawPath: String = "/endpoint",
5859
cookies: [String]? = nil,
5960
headers: [String: String] = [:],
@@ -87,7 +88,7 @@ public extension APIGatewayV2Request {
8788
/// - Returns: The mock request.
8889
static func mock(
8990
// swiftlint:disable:previous function_body_length
90-
method: HTTPMethod = .POST,
91+
method: HTTPRequest.Method = .post,
9192
rawPath: String = "/endpoint",
9293
cookies: [String]? = nil,
9394
headers: [String: String] = [:],
@@ -206,7 +207,7 @@ public extension APIGatewayV2Response {
206207
static func mock<T: Encodable>(
207208
_ bodyValue: T,
208209
encodedWith encoder: JSONEncoder = .init(),
209-
statusCode: HTTPResponseStatus = .ok,
210+
statusCode: HTTPResponse.Status = .ok,
210211
headers: [String: String]? = nil,
211212
isBase64Encoded: Bool = false,
212213
cookies: [String]? = nil

0 commit comments

Comments
 (0)