Skip to content

Strict Concurrency Support #15

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 12 commits into from
Oct 22, 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
26 changes: 26 additions & 0 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run Danger
on:
workflow_dispatch:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
build:
if: github.event.pull_request.draft == false
name: Run Danger
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Git checkout
uses: actions/checkout@v4
- name: Danger
uses: 417-72KI/danger-swiftlint@v5.9
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 changes: 16 additions & 15 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@ excluded:
- .build

opt_in_rules:
- array_init
- attributes
- closure_end_indentation
- closure_spacing
- empty_count
- explicit_init
- closure_spacing
- overridden_super_call
- redundant_nil_coalescing
- private_outlet
- extension_access_modifier
- fatal_error_message
- first_where
- let_var_whitespace
- literal_expression_end_indentation
- nimble_operator
- attributes
- operator_usage_whitespace
- closure_end_indentation
- first_where
- overridden_super_call
- pattern_matching_keywords
- private_outlet
- prohibited_super_call
- fatal_error_message
- vertical_parameter_alignment_on_call
- let_var_whitespace
- redundant_nil_coalescing
- unneeded_parentheses_in_closure_argument
- extension_access_modifier
- pattern_matching_keywords
- array_init
- literal_expression_end_indentation
- vertical_parameter_alignment_on_call

disabled_rules:
- void_return
- multiple_closures_with_trailing_closure
- optional_data_string_conversion
- vertical_parameter_alignment_on_call
- void_return

identifier_name:
excluded:
Expand Down
15 changes: 15 additions & 0 deletions Dangerfile.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Danger

extension String: Error {}

let danger = Danger()

if danger.github.pullRequest.body == nil {
danger.fail("Please add a description to this Pull Request")
}

SwiftLint
.lint(
.all(directory: nil),
configFile: ".swiftlint.yml"
)
103 changes: 20 additions & 83 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -14,10 +14,10 @@ let package = Package(
.library(name: "LambdaMocks", targets: ["LambdaMocks"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")),
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")),
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", .upToNextMajor(from: "0.2.0")),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", "1.0.0-alpha.1"..<"1.0.0-beta.999")
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.2"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.43.1"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-events", from: "0.2.0"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime", from: "1.0.0-alpha.3")
]
)

Expand All @@ -33,7 +33,7 @@ let targets: [Target] = [
name: "LambdaExtras",
dependencies: [
"LambdaExtrasCore",
.product(name: "AWSLambdaRuntime",package: "swift-aws-lambda-runtime"),
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events")
]
),
Expand All @@ -54,11 +54,8 @@ let targets: [Target] = [
)
]

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

package.targets = targets
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Swifty helpers for working with AWS Lambda.

## 📱 Requirements

Swift 5.7 toolchain with Swift Package Manager.
Swift 5.9 toolchain with Swift Package Manager.

## 🖥 Installation

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

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

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

### Handler

Expand Down
11 changes: 6 additions & 5 deletions Sources/LambdaExtras/APIGatewayCoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import AWSLambdaEvents
import AWSLambdaRuntime
import Foundation
import HTTPTypes
import LambdaExtrasCore

/// A coder for APIGateway events.
public struct APIGatewayCoder<E, O>: LambdaCoding where E: Codable, E: Sendable, O: Sendable {
public struct APIGatewayCoder<E, O>: LambdaCoding, Sendable where E: Codable, E: Sendable, O: Sendable {
/// A JSON decoder.
let decoder: JSONDecoder

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

public func encode(error: Error) throws -> APIGatewayV2Response {
let statusCode: HTTPResponseStatus
let status: HTTPResponse.Status
switch error {
case HandlerError.emptyBody:
statusCode = .badRequest
status = .badRequest
default:
statusCode = .internalServerError
status = .internalServerError
}

return APIGatewayV2Response(
statusCode: statusCode,
statusCode: status,
body: try errorBodyProvider(error.localizedDescription))
}
}
2 changes: 1 addition & 1 deletion Sources/LambdaExtrasCore/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public extension Optional {
}
}

extension String: LocalizedError {
extension Swift.String: Foundation.LocalizedError {
public var errorDescription: String? { self }
public var failureReason: String? { self }
}
2 changes: 1 addition & 1 deletion Sources/LambdaExtrasCore/HandlerError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// An error that occurs during lambda handler execution.
public enum HandlerError: Error, Equatable, LocalizedError {
public enum HandlerError: Error, Equatable, LocalizedError, Sendable {
/// The request is missing a body.
case emptyBody
/// The lambda context is missing an expected environment variable.
Expand Down
7 changes: 4 additions & 3 deletions Sources/LambdaMocks/Extensions/APIGatewayV2+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import AWSLambdaEvents
import Foundation
import HTTPTypes

// MARK: - Helpers

Expand Down Expand Up @@ -53,7 +54,7 @@ public extension APIGatewayV2Request {
static func mock<T: Encodable>(
_ bodyValue: T,
encodedWith encoder: JSONEncoder = .init(),
method: HTTPMethod = .POST,
method: HTTPRequest.Method = .post,
rawPath: String = "/endpoint",
cookies: [String]? = nil,
headers: [String: String] = [:],
Expand Down Expand Up @@ -87,7 +88,7 @@ public extension APIGatewayV2Request {
/// - Returns: The mock request.
static func mock(
// swiftlint:disable:previous function_body_length
method: HTTPMethod = .POST,
method: HTTPRequest.Method = .post,
rawPath: String = "/endpoint",
cookies: [String]? = nil,
headers: [String: String] = [:],
Expand Down Expand Up @@ -206,7 +207,7 @@ public extension APIGatewayV2Response {
static func mock<T: Encodable>(
_ bodyValue: T,
encodedWith encoder: JSONEncoder = .init(),
statusCode: HTTPResponseStatus = .ok,
statusCode: HTTPResponse.Status = .ok,
headers: [String: String]? = nil,
isBase64Encoded: Bool = false,
cookies: [String]? = nil
Expand Down
Loading
Loading