Skip to content

Commit 298e59f

Browse files
Update from Hummingbird Project Template (#40)
* Update from hummingbird-project-template 572d468b2cabeca286314c5a35196bd42445c8ef * swift-format * Remove .swiftformat --------- Co-authored-by: adam-fowler <[email protected]> Co-authored-by: Adam Fowler <[email protected]>
1 parent 5626800 commit 298e59f

File tree

14 files changed

+193
-151
lines changed

14 files changed

+193
-151
lines changed

.github/workflows/validate.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ concurrency:
88

99
jobs:
1010
validate:
11-
runs-on: macOS-latest
11+
runs-on: ubuntu-latest
1212
timeout-minutes: 15
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 1
18-
- name: Install Dependencies
19-
run: |
20-
brew install mint
21-
mint install NickLockwood/[email protected] --no-link
2218
- name: run script
2319
run: ./scripts/validate.sh

.swift-format

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"version" : 1,
3+
"indentation" : {
4+
"spaces" : 4
5+
},
6+
"tabWidth" : 4,
7+
"fileScopedDeclarationPrivacy" : {
8+
"accessLevel" : "private"
9+
},
10+
"spacesAroundRangeFormationOperators" : false,
11+
"indentConditionalCompilationBlocks" : false,
12+
"indentSwitchCaseLabels" : false,
13+
"lineBreakAroundMultilineExpressionChainComponents" : false,
14+
"lineBreakBeforeControlFlowKeywords" : false,
15+
"lineBreakBeforeEachArgument" : true,
16+
"lineBreakBeforeEachGenericRequirement" : true,
17+
"lineLength" : 150,
18+
"maximumBlankLines" : 1,
19+
"respectsExistingLineBreaks" : true,
20+
"prioritizeKeepingFunctionOutputTogether" : true,
21+
"multiElementCollectionTrailingCommas" : true,
22+
"rules" : {
23+
"AllPublicDeclarationsHaveDocumentation" : false,
24+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
25+
"AlwaysUseLowerCamelCase" : false,
26+
"AmbiguousTrailingClosureOverload" : true,
27+
"BeginDocumentationCommentWithOneLineSummary" : false,
28+
"DoNotUseSemicolons" : true,
29+
"DontRepeatTypeInStaticProperties" : true,
30+
"FileScopedDeclarationPrivacy" : true,
31+
"FullyIndirectEnum" : true,
32+
"GroupNumericLiterals" : true,
33+
"IdentifiersMustBeASCII" : true,
34+
"NeverForceUnwrap" : false,
35+
"NeverUseForceTry" : false,
36+
"NeverUseImplicitlyUnwrappedOptionals" : false,
37+
"NoAccessLevelOnExtensionDeclaration" : true,
38+
"NoAssignmentInExpressions" : true,
39+
"NoBlockComments" : true,
40+
"NoCasesWithOnlyFallthrough" : true,
41+
"NoEmptyTrailingClosureParentheses" : true,
42+
"NoLabelsInCasePatterns" : true,
43+
"NoLeadingUnderscores" : false,
44+
"NoParensAroundConditions" : true,
45+
"NoVoidReturnOnFunctionSignature" : true,
46+
"OmitExplicitReturns" : true,
47+
"OneCasePerLine" : true,
48+
"OneVariableDeclarationPerLine" : true,
49+
"OnlyOneTrailingClosureArgument" : true,
50+
"OrderedImports" : true,
51+
"ReplaceForEachWithForLoop" : true,
52+
"ReturnVoidInsteadOfEmptyTuple" : true,
53+
"UseEarlyExits" : false,
54+
"UseExplicitNilCheckInConditions" : false,
55+
"UseLetInEveryBoundCaseVariable" : false,
56+
"UseShorthandTypeNames" : true,
57+
"UseSingleLinePropertyGetter" : false,
58+
"UseSynthesizedInitializer" : false,
59+
"UseTripleSlashForDocumentationComments" : true,
60+
"UseWhereClausesInForLoops" : false,
61+
"ValidateDocumentationComments" : false
62+
}
63+
}

.swiftformat

Lines changed: 0 additions & 26 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ The main development branch of the repository is `main`.
2828

2929
### Formatting
3030

31-
We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.53.10.
31+
We use Apple's swift-format for formatting code. PRs will not be accepted if they haven't be formatted.

Package.swift

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PackageDescription
55
let package = Package(
66
name: "hummingbird-lambda",
77
platforms: [
8-
.macOS(.v14),
8+
.macOS(.v14)
99
],
1010
products: [
1111
.library(name: "HummingbirdLambda", targets: ["HummingbirdLambda"]),
@@ -20,22 +20,34 @@ let package = Package(
2020
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
2121
],
2222
targets: [
23-
.target(name: "HummingbirdLambda", dependencies: [
24-
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
25-
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
26-
.product(name: "ExtrasBase64", package: "swift-extras-base64"),
27-
.product(name: "Hummingbird", package: "hummingbird"),
28-
]),
29-
.target(name: "HummingbirdLambdaTesting", dependencies: [
30-
.byName(name: "HummingbirdLambda"),
31-
]),
32-
.executableTarget(name: "HBLambdaTest", dependencies: [
33-
.byName(name: "HummingbirdLambda"),
34-
]),
35-
.testTarget(name: "HummingbirdLambdaTests", dependencies: [
36-
.byName(name: "HummingbirdLambda"),
37-
.byName(name: "HummingbirdLambdaTesting"),
38-
.product(name: "NIOPosix", package: "swift-nio"),
39-
]),
23+
.target(
24+
name: "HummingbirdLambda",
25+
dependencies: [
26+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
27+
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
28+
.product(name: "ExtrasBase64", package: "swift-extras-base64"),
29+
.product(name: "Hummingbird", package: "hummingbird"),
30+
]
31+
),
32+
.target(
33+
name: "HummingbirdLambdaTesting",
34+
dependencies: [
35+
.byName(name: "HummingbirdLambda")
36+
]
37+
),
38+
.executableTarget(
39+
name: "HBLambdaTest",
40+
dependencies: [
41+
.byName(name: "HummingbirdLambda")
42+
]
43+
),
44+
.testTarget(
45+
name: "HummingbirdLambdaTests",
46+
dependencies: [
47+
.byName(name: "HummingbirdLambda"),
48+
.byName(name: "HummingbirdLambdaTesting"),
49+
.product(name: "NIOPosix", package: "swift-nio"),
50+
]
51+
),
4052
]
4153
)

Sources/HummingbirdLambda/APIGatewayLambda.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public protocol APIGatewayLambdaFunction: LambdaFunction where Event == APIGatew
4545
extension LambdaFunction where Event == APIGatewayRequest {
4646
/// Specialization of Lambda.request where `Event` is `APIGatewayRequest`
4747
public func request(context: LambdaContext, from: Event) throws -> Request {
48-
return try Request(context: context, from: from)
48+
try Request(context: context, from: from)
4949
}
5050
}
5151

5252
extension LambdaFunction where Output == APIGatewayResponse {
5353
/// Specialization of Lambda.request where `Output` is `APIGatewayResponse`
5454
public func output(from response: Response) async throws -> Output {
55-
return try await response.apiResponse()
55+
try await response.apiResponse()
5656
}
5757
}
5858

Sources/HummingbirdLambda/APIGatewayV2Lambda.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ public protocol APIGatewayV2LambdaFunction: LambdaFunction where Event == APIGat
4545
extension LambdaFunction where Event == APIGatewayV2Request {
4646
/// Specialization of Lambda.request where `Event` is `APIGatewayV2Request`
4747
public func request(context: LambdaContext, from: Event) throws -> Request {
48-
return try Request(context: context, from: from)
48+
try Request(context: context, from: from)
4949
}
5050
}
5151

5252
extension LambdaFunction where Output == APIGatewayV2Response {
5353
/// Specialization of Lambda.request where `Output` is `APIGatewayV2Response`
5454
public func output(from response: Response) async throws -> Output {
55-
return try await response.apiResponse()
55+
try await response.apiResponse()
5656
}
5757
}
5858

5959
// conform `APIGatewayV2Request` to `APIRequest` so we can use Request.init(context:application:from)
6060
extension APIGatewayV2Request: APIRequest {
6161
var path: String {
62-
return context.http.path
62+
context.http.path
6363
}
6464

6565
var httpMethod: HTTPRequest.Method { context.http.method }

Sources/HummingbirdLambda/LambdaHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct LambdaFunctionHandler<L: LambdaFunction>: LambdaHandler {
3434
let lambda = try await L(context: context)
3535

3636
context.terminator.register(name: "Application") { eventLoop in
37-
return eventLoop.makeFutureWithTask {
37+
eventLoop.makeFutureWithTask {
3838
try await lambda.shutdown()
3939
}
4040
}

Sources/HummingbirdLambda/Request+APIGateway.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension Request {
3333
/// Specialization of Lambda.request where `In` is `APIGateway.Request`
3434
init(context: LambdaContext, from: some APIRequest) throws {
3535
func urlPercentEncoded(_ string: String) -> String {
36-
return string.addingPercentEncoding(withAllowedCharacters: .urlQueryComponentAllowed) ?? string
36+
string.addingPercentEncoding(withAllowedCharacters: .urlQueryComponentAllowed) ?? string
3737
}
3838

3939
// construct URI with query parameters

Sources/HummingbirdLambdaTesting/APIGatewayLambda.swift

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,43 +46,43 @@ extension APIGatewayRequest: LambdaTestableEvent {
4646
let headerValuesString = try String(decoding: JSONEncoder().encode(singleHeaderValues), as: UTF8.self)
4747
let multiHeaderValuesString = try String(decoding: JSONEncoder().encode(headerValues), as: UTF8.self)
4848
let eventJson = """
49-
{
50-
"httpMethod": "\(method)",
51-
"body": \(base64Body),
52-
"resource": "\(url.path)",
53-
"requestContext": {
54-
"resourceId": "123456",
55-
"apiId": "1234567890",
56-
"resourcePath": "\(url.path)",
49+
{
5750
"httpMethod": "\(method)",
58-
"requestId": "\(UUID().uuidString)",
59-
"accountId": "123456789012",
60-
"stage": "Prod",
61-
"identity": {
62-
"apiKey": null,
63-
"userArn": null,
64-
"cognitoAuthenticationType": null,
65-
"caller": null,
66-
"userAgent": "Custom User Agent String",
67-
"user": null,
68-
"cognitoIdentityPoolId": null,
69-
"cognitoAuthenticationProvider": null,
70-
"sourceIp": "127.0.0.1",
71-
"accountId": null
51+
"body": \(base64Body),
52+
"resource": "\(url.path)",
53+
"requestContext": {
54+
"resourceId": "123456",
55+
"apiId": "1234567890",
56+
"resourcePath": "\(url.path)",
57+
"httpMethod": "\(method)",
58+
"requestId": "\(UUID().uuidString)",
59+
"accountId": "123456789012",
60+
"stage": "Prod",
61+
"identity": {
62+
"apiKey": null,
63+
"userArn": null,
64+
"cognitoAuthenticationType": null,
65+
"caller": null,
66+
"userAgent": "Custom User Agent String",
67+
"user": null,
68+
"cognitoIdentityPoolId": null,
69+
"cognitoAuthenticationProvider": null,
70+
"sourceIp": "127.0.0.1",
71+
"accountId": null
72+
},
73+
"extendedRequestId": null,
74+
"path": "\(uri)"
7275
},
73-
"extendedRequestId": null,
74-
"path": "\(uri)"
75-
},
76-
"queryStringParameters": \(queryValuesString),
77-
"multiValueQueryStringParameters": \(multiQueryValuesString),
78-
"headers": \(headerValuesString),
79-
"multiValueHeaders": \(multiHeaderValuesString),
80-
"pathParameters": null,
81-
"stageVariables": null,
82-
"path": "\(url.path)",
83-
"isBase64Encoded": \(body != nil)
84-
}
85-
"""
76+
"queryStringParameters": \(queryValuesString),
77+
"multiValueQueryStringParameters": \(multiQueryValuesString),
78+
"headers": \(headerValuesString),
79+
"multiValueHeaders": \(multiHeaderValuesString),
80+
"pathParameters": null,
81+
"stageVariables": null,
82+
"path": "\(url.path)",
83+
"isBase64Encoded": \(body != nil)
84+
}
85+
"""
8686
self = try JSONDecoder().decode(Self.self, from: Data(eventJson.utf8))
8787
}
8888
}

0 commit comments

Comments
 (0)