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

+26
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

+16-15
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

+15
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

+20-83
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
11
{
22
"pins" : [
3-
{
4-
"identity" : "collectionconcurrencykit",
5-
"kind" : "remoteSourceControl",
6-
"location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git",
7-
"state" : {
8-
"revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95",
9-
"version" : "0.2.0"
10-
}
11-
},
12-
{
13-
"identity" : "cryptoswift",
14-
"kind" : "remoteSourceControl",
15-
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
16-
"state" : {
17-
"revision" : "db51c407d3be4a051484a141bf0bff36c43d3b1e",
18-
"version" : "1.8.0"
19-
}
20-
},
21-
{
22-
"identity" : "sourcekitten",
23-
"kind" : "remoteSourceControl",
24-
"location" : "https://github.com/jpsim/SourceKitten.git",
25-
"state" : {
26-
"revision" : "b6dc09ee51dfb0c66e042d2328c017483a1a5d56",
27-
"version" : "0.34.1"
28-
}
29-
},
30-
{
31-
"identity" : "swift-argument-parser",
32-
"kind" : "remoteSourceControl",
33-
"location" : "https://github.com/apple/swift-argument-parser.git",
34-
"state" : {
35-
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
36-
"version" : "1.2.3"
37-
}
38-
},
393
{
404
"identity" : "swift-atomics",
415
"kind" : "remoteSourceControl",
@@ -50,17 +14,17 @@
5014
"kind" : "remoteSourceControl",
5115
"location" : "https://github.com/swift-server/swift-aws-lambda-events",
5216
"state" : {
53-
"revision" : "997094fe7c55762c07179419a1686230dfa13bef",
54-
"version" : "0.2.0"
17+
"revision" : "a0b64e9d0d5de872169ef645fda2e33575ee42d0",
18+
"version" : "0.4.0"
5519
}
5620
},
5721
{
5822
"identity" : "swift-aws-lambda-runtime",
5923
"kind" : "remoteSourceControl",
6024
"location" : "https://github.com/swift-server/swift-aws-lambda-runtime.git",
6125
"state" : {
62-
"revision" : "8d9f44b7838750b103ad2ad49055e8333d719e8a",
63-
"version" : "1.0.0-alpha.2"
26+
"revision" : "5ecc24fa54e61756fe7a7a01f2451da1cffa916e",
27+
"version" : "1.0.0-alpha.3"
6428
}
6529
},
6630
{
@@ -73,66 +37,39 @@
7337
}
7438
},
7539
{
76-
"identity" : "swift-log",
40+
"identity" : "swift-http-types",
7741
"kind" : "remoteSourceControl",
78-
"location" : "https://github.com/apple/swift-log.git",
42+
"location" : "https://github.com/apple/swift-http-types.git",
7943
"state" : {
80-
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
81-
"version" : "1.5.3"
44+
"revision" : "ae67c8178eb46944fd85e4dc6dd970e1f3ed6ccd",
45+
"version" : "1.3.0"
8246
}
8347
},
8448
{
85-
"identity" : "swift-nio",
86-
"kind" : "remoteSourceControl",
87-
"location" : "https://github.com/apple/swift-nio.git",
88-
"state" : {
89-
"revision" : "702cd7c56d5d44eeba73fdf83918339b26dc855c",
90-
"version" : "2.62.0"
91-
}
92-
},
93-
{
94-
"identity" : "swift-syntax",
95-
"kind" : "remoteSourceControl",
96-
"location" : "https://github.com/apple/swift-syntax.git",
97-
"state" : {
98-
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
99-
"version" : "509.0.2"
100-
}
101-
},
102-
{
103-
"identity" : "swiftlint",
104-
"kind" : "remoteSourceControl",
105-
"location" : "https://github.com/realm/SwiftLint.git",
106-
"state" : {
107-
"revision" : "f17a4f9dfb6a6afb0408426354e4180daaf49cee",
108-
"version" : "0.54.0"
109-
}
110-
},
111-
{
112-
"identity" : "swiftytexttable",
49+
"identity" : "swift-log",
11350
"kind" : "remoteSourceControl",
114-
"location" : "https://github.com/scottrhoyt/SwiftyTextTable.git",
51+
"location" : "https://github.com/apple/swift-log.git",
11552
"state" : {
116-
"revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
117-
"version" : "0.9.0"
53+
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
54+
"version" : "1.6.1"
11855
}
11956
},
12057
{
121-
"identity" : "swxmlhash",
58+
"identity" : "swift-nio",
12259
"kind" : "remoteSourceControl",
123-
"location" : "https://github.com/drmohundro/SWXMLHash.git",
60+
"location" : "https://github.com/apple/swift-nio.git",
12461
"state" : {
125-
"revision" : "a853604c9e9a83ad9954c7e3d2a565273982471f",
126-
"version" : "7.0.2"
62+
"revision" : "f7dc3f527576c398709b017584392fb58592e7f5",
63+
"version" : "2.75.0"
12764
}
12865
},
12966
{
130-
"identity" : "yams",
67+
"identity" : "swift-system",
13168
"kind" : "remoteSourceControl",
132-
"location" : "https://github.com/jpsim/Yams.git",
69+
"location" : "https://github.com/apple/swift-system.git",
13370
"state" : {
134-
"revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3",
135-
"version" : "5.0.6"
71+
"revision" : "c8a44d836fe7913603e246acab7c528c2e780168",
72+
"version" : "1.4.0"
13673
}
13774
}
13875
],

Package.swift

+7-10
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

+3-3
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

+6-5
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

+1-1
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

+1-1
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

+4-3
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)