diff --git a/.swift-format b/.swift-format new file mode 100644 index 0000000..7fa06fb --- /dev/null +++ b/.swift-format @@ -0,0 +1,62 @@ +{ + "version" : 1, + "indentation" : { + "spaces" : 4 + }, + "tabWidth" : 4, + "fileScopedDeclarationPrivacy" : { + "accessLevel" : "private" + }, + "spacesAroundRangeFormationOperators" : false, + "indentConditionalCompilationBlocks" : false, + "indentSwitchCaseLabels" : false, + "lineBreakAroundMultilineExpressionChainComponents" : false, + "lineBreakBeforeControlFlowKeywords" : false, + "lineBreakBeforeEachArgument" : true, + "lineBreakBeforeEachGenericRequirement" : true, + "lineLength" : 120, + "maximumBlankLines" : 1, + "respectsExistingLineBreaks" : true, + "prioritizeKeepingFunctionOutputTogether" : true, + "rules" : { + "AllPublicDeclarationsHaveDocumentation" : false, + "AlwaysUseLiteralForEmptyCollectionInit" : false, + "AlwaysUseLowerCamelCase" : false, + "AmbiguousTrailingClosureOverload" : true, + "BeginDocumentationCommentWithOneLineSummary" : false, + "DoNotUseSemicolons" : true, + "DontRepeatTypeInStaticProperties" : true, + "FileScopedDeclarationPrivacy" : true, + "FullyIndirectEnum" : true, + "GroupNumericLiterals" : true, + "IdentifiersMustBeASCII" : true, + "NeverForceUnwrap" : false, + "NeverUseForceTry" : false, + "NeverUseImplicitlyUnwrappedOptionals" : false, + "NoAccessLevelOnExtensionDeclaration" : true, + "NoAssignmentInExpressions" : true, + "NoBlockComments" : true, + "NoCasesWithOnlyFallthrough" : true, + "NoEmptyTrailingClosureParentheses" : true, + "NoLabelsInCasePatterns" : true, + "NoLeadingUnderscores" : false, + "NoParensAroundConditions" : true, + "NoVoidReturnOnFunctionSignature" : true, + "OmitExplicitReturns" : true, + "OneCasePerLine" : true, + "OneVariableDeclarationPerLine" : true, + "OnlyOneTrailingClosureArgument" : true, + "OrderedImports" : true, + "ReplaceForEachWithForLoop" : true, + "ReturnVoidInsteadOfEmptyTuple" : true, + "UseEarlyExits" : false, + "UseExplicitNilCheckInConditions" : false, + "UseLetInEveryBoundCaseVariable" : false, + "UseShorthandTypeNames" : true, + "UseSingleLinePropertyGetter" : false, + "UseSynthesizedInitializer" : false, + "UseTripleSlashForDocumentationComments" : true, + "UseWhereClausesInForLoops" : false, + "ValidateDocumentationComments" : false + } +} diff --git a/.swiftformat b/.swiftformat deleted file mode 100644 index 2458d1b..0000000 --- a/.swiftformat +++ /dev/null @@ -1,19 +0,0 @@ -# file options - ---swiftversion 5.4 ---exclude .build - -# format options - ---self insert ---patternlet inline ---stripunusedargs unnamed-only ---ifdef no-indent ---extensionacl on-declarations ---disable typeSugar ---disable andOperator ---disable wrapMultilineStatementBraces ---disable enumNamespaces ---disable redundantExtensionACL - -# rules diff --git a/Examples/Simple/.dockerignore b/Examples/Simple/.dockerignore deleted file mode 100644 index 24e5b0a..0000000 --- a/Examples/Simple/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -.build diff --git a/Examples/Simple/Package.swift b/Examples/Simple/Package.swift deleted file mode 100644 index 8eaf80f..0000000 --- a/Examples/Simple/Package.swift +++ /dev/null @@ -1,32 +0,0 @@ -// swift-tools-version:5.8 - -import PackageDescription - -let package = Package( - name: "swift-aws-lambda-events-samples", - platforms: [ - .macOS(.v12) - ], - products: [ - // demonstrate how to integrate with AWS API Gateway - .executable(name: "APIGateway", targets: ["APIGateway"]) - ], - dependencies: [ - // this is the dependency on the swift-aws-lambda-runtime library - .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha.2"), - // this is the dependency on the swift-aws-lambda-events library - // in real-world projects this would say - // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime-events.git", from: "1.0.0") - // but here, we're using the local version - .package(name: "swift-aws-lambda-events", path: "../.."), - ], - targets: [ - .executableTarget( - name: "APIGateway", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), - .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), - ] - ) - ] -) diff --git a/Examples/Simple/Sources/APIGateway/APIGatewayProxyLambda.swift b/Examples/Simple/Sources/APIGateway/APIGatewayProxyLambda.swift deleted file mode 100644 index ab5a476..0000000 --- a/Examples/Simple/Sources/APIGateway/APIGatewayProxyLambda.swift +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the SwiftAWSLambdaRuntime open source project -// -// Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// - -import AWSLambdaEvents -import AWSLambdaRuntime -import NIO - -// MARK: - Run Lambda - -// FIXME: Use proper Event abstractions once added to AWSLambdaRuntime -@main -struct APIGatewayProxyLambda: LambdaHandler { - typealias Event = APIGatewayV2Request - typealias Output = APIGatewayV2Response - - init(context: LambdaInitializationContext) async throws {} - - func handle(_ request: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response { - context.logger.debug("hello, api gateway!") - return APIGatewayV2Response(statusCode: .ok, body: "hello, world!") - } -} diff --git a/Examples/Simple/Tests/LinuxMain.swift b/Examples/Simple/Tests/LinuxMain.swift deleted file mode 100644 index c46de76..0000000 --- a/Examples/Simple/Tests/LinuxMain.swift +++ /dev/null @@ -1,15 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the SwiftAWSLambdaRuntime open source project -// -// Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// - -preconditionFailure("use `swift test --enable-test-discovery`") diff --git a/Sources/AWSLambdaEvents/Utils/Base64.swift b/Sources/AWSLambdaEvents/Utils/Base64.swift index df6d535..38b4cec 100644 --- a/Sources/AWSLambdaEvents/Utils/Base64.swift +++ b/Sources/AWSLambdaEvents/Utils/Base64.swift @@ -42,8 +42,8 @@ extension Base64 { ) throws -> [UInt8] where Buffer.Element == UInt8 { let alphabet = options.contains(.base64UrlAlphabet) - ? Base64.decodeBase64Url - : Base64.decodeBase64 + ? Base64.decodeDataUrl + : Base64.decodeData // In Base64 4 encoded bytes, become 3 decoded bytes. We pad to the // nearest multiple of three. @@ -112,7 +112,7 @@ extension Base64 { // MARK: Internal @usableFromInline - static let decodeBase64: [UInt8] = [ + static let decodeData: [UInt8] = [ // 0 1 2 3 4 5 6 7 8 9 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // 0 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // 1 @@ -143,7 +143,7 @@ extension Base64 { ] @usableFromInline - static let decodeBase64Url: [UInt8] = [ + static let decodeDataUrl: [UInt8] = [ // 0 1 2 3 4 5 6 7 8 9 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // 0 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // 1 diff --git a/Tests/AWSLambdaEventsTests/DynamoDBTests.swift b/Tests/AWSLambdaEventsTests/DynamoDBTests.swift index 5d2db43..28905d1 100644 --- a/Tests/AWSLambdaEventsTests/DynamoDBTests.swift +++ b/Tests/AWSLambdaEventsTests/DynamoDBTests.swift @@ -222,7 +222,7 @@ class DynamoDBTests: XCTestCase { func testAttributeValueEmptyDecoding() { let json = "{\"haha\": 1}" XCTAssertThrowsError( - _ = try JSONDecoder().decode(DynamoDBEvent.AttributeValue.self, from: json.data(using: .utf8)!) + try JSONDecoder().decode(DynamoDBEvent.AttributeValue.self, from: json.data(using: .utf8)!) ) { error in guard case DecodingError.dataCorrupted = error else { XCTFail("Unexpected error: \(String(describing: error))") diff --git a/Tests/AWSLambdaEventsTests/Utils/Base64Tests.swift b/Tests/AWSLambdaEventsTests/Utils/Base64Tests.swift index ed62ef1..531975f 100644 --- a/Tests/AWSLambdaEventsTests/Utils/Base64Tests.swift +++ b/Tests/AWSLambdaEventsTests/Utils/Base64Tests.swift @@ -55,13 +55,13 @@ class Base64Tests: XCTestCase { } func testBase64DecodingWithPoop() { - XCTAssertThrowsError(_ = try "💩".base64decoded()) { error in + XCTAssertThrowsError(try "💩".base64decoded()) { error in XCTAssertEqual(error as? Base64.DecodingError, .invalidCharacter(240)) } } func testBase64DecodingWithInvalidLength() { - XCTAssertThrowsError(_ = try "AAAAA".base64decoded()) { error in + XCTAssertThrowsError(try "AAAAA".base64decoded()) { error in XCTAssertEqual(error as? Base64.DecodingError, .invalidLength) } } diff --git a/Tests/AWSLambdaEventsTests/Utils/DateWrapperTests.swift b/Tests/AWSLambdaEventsTests/Utils/DateWrapperTests.swift index cacc2e8..b9f1993 100644 --- a/Tests/AWSLambdaEventsTests/Utils/DateWrapperTests.swift +++ b/Tests/AWSLambdaEventsTests/Utils/DateWrapperTests.swift @@ -38,7 +38,7 @@ class DateWrapperTests: XCTestCase { let date = "2020-03-26T16:53:05" // missing Z at end let json = #"{"date":"\#(date)"}"# - XCTAssertThrowsError(_ = try JSONDecoder().decode(TestEvent.self, from: json.data(using: .utf8)!)) { error in + XCTAssertThrowsError(try JSONDecoder().decode(TestEvent.self, from: json.data(using: .utf8)!)) { error in guard case DecodingError.dataCorrupted(let context) = error else { XCTFail("Unexpected error: \(error)") return @@ -74,7 +74,7 @@ class DateWrapperTests: XCTestCase { let date = "2020-03-26T16:53:05Z" // missing fractional seconds let json = #"{"date":"\#(date)"}"# - XCTAssertThrowsError(_ = try JSONDecoder().decode(TestEvent.self, from: json.data(using: .utf8)!)) { error in + XCTAssertThrowsError(try JSONDecoder().decode(TestEvent.self, from: json.data(using: .utf8)!)) { error in guard case DecodingError.dataCorrupted(let context) = error else { XCTFail("Unexpected error: \(error)") return @@ -149,7 +149,7 @@ class DateWrapperTests: XCTestCase { let date = "Thu, 5 Apr 2012 23:47 +0200" // missing seconds let json = #"{"date":"\#(date)"}"# - XCTAssertThrowsError(_ = try JSONDecoder().decode(TestEvent.self, from: json.data(using: .utf8)!)) { error in + XCTAssertThrowsError(try JSONDecoder().decode(TestEvent.self, from: json.data(using: .utf8)!)) { error in guard case DecodingError.dataCorrupted(let context) = error else { XCTFail("Unexpected error: \(error)") return diff --git a/readme.md b/readme.md index 5e2c515..28db437 100644 --- a/readme.md +++ b/readme.md @@ -22,7 +22,7 @@ AWS Lambda functions can be invoked directly from the AWS Lambda console UI, AWS ## Getting started -If you have never used AWS Lambda or Docker before, check out this [getting started guide](https://fabianfett.dev/getting-started-with-swift-aws-lambda-runtime) which helps you with every step from zero to a running Lambda. +If you have never used AWS Lambda or Docker before, check out this [getting started guide](https://swiftpackageindex.com/swift-server/swift-aws-lambda-runtime/1.0.0-alpha.3/tutorials/table-of-content) which helps you with every step from zero to a running Lambda. Swift AWS Lambda Events is a supporting library for the [Swift AWS Lambda Runtime](http://github.com/swift-server/swift-aws-lambda-runtime) library, where you can find further documentation and examples.