Skip to content

Commit 1ed45af

Browse files
Merge pull request #2 from swift-serverless/feature/swift-6
Update SDK to Swift 6
2 parents 293eb1a + f64f310 commit 1ed45af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1953
-901
lines changed

.github/workflows/meterian.yml renamed to .github/workflows/meterian.yml.disabled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
steps:
1212
- uses: swift-actions/setup-swift@v2
1313
with:
14-
swift-version: "5.7.3"
14+
swift-version: '6.1.2'
1515
- name: Get swift version
1616
run: swift --version
1717
- name: Checkout

.github/workflows/swift-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
image:
21-
- swift:5.10.1
21+
- swift:6.1.2
2222
services:
2323
localstack:
2424
image: localstack/localstack

.spi.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: 1
2+
builder:
3+
configs:
4+
- documentation_targets: [BreezeLambdaAPI, BreezeDynamoDBService]

Images/Icon.png

119 KB
Loading

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,35 @@ composer_down:
2020
localstack:
2121
docker run -it --rm -p "4566:4566" localstack/localstack
2222

23+
local_setup_dynamo_db:
24+
aws --endpoint-url=http://localhost:4566 dynamodb create-table \
25+
--table-name Breeze \
26+
--attribute-definitions AttributeName=itemKey,AttributeType=S \
27+
--key-schema AttributeName=itemKey,KeyType=HASH \
28+
--billing-mode PAY_PER_REQUEST
29+
--region us-east-1
30+
31+
local_invoke_demo_app:
32+
curl -X POST 127.0.0.1:7000/invoke -H "Content-Type: application/json" -d @Tests/BreezeLambdaAPITests/Fixtures/post_products_api_gtw.json
33+
2334
test:
2435
swift test --sanitize=thread --enable-code-coverage
2536

37+
generate_docc:
38+
mkdir -p docs && \
39+
swift package --allow-writing-to-directory docs/BreezeLambdaAPI generate-documentation \
40+
--target BreezeLambdaAPI \
41+
--disable-indexing \
42+
--transform-for-static-hosting \
43+
--hosting-base-path "https://swift-serverless.github.io/BreezeLambdaDynamoDBAPI/BreezeLambdaAPI/" \
44+
--output-path docs/BreezeLambdaAPI && \
45+
swift package --allow-writing-to-directory docs/BreezeDynamoDBService generate-documentation \
46+
--target BreezeDynamoDBService \
47+
--disable-indexing \
48+
--transform-for-static-hosting \
49+
--hosting-base-path "https://swift-serverless.github.io/BreezeLambdaDynamoDBAPI/BreezeDynamoDBService/" \
50+
--output-path docs/BreezeDynamoDBService
51+
2652
coverage:
2753
llvm-cov export $(TEST_PACKAGE) \
2854
--instr-profile=$(SWIFT_BIN_PATH)/codecov/default.profdata \

Package.swift

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
// swift-tools-version: 5.7
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
1+
// swift-tools-version: 6.0
32

43
import PackageDescription
54

5+
#if os(macOS)
6+
let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)]
7+
#else
8+
let platforms: [PackageDescription.SupportedPlatform]? = nil
9+
#endif
10+
611
let package = Package(
712
name: "BreezeLambdaDynamoDBAPI",
8-
platforms: [
9-
.macOS(.v13),
10-
],
13+
platforms: platforms,
1114
products: [
1215
.library(
1316
name: "BreezeDynamoDBService",
@@ -16,43 +19,63 @@ let package = Package(
1619
.library(
1720
name: "BreezeLambdaAPI",
1821
targets: ["BreezeLambdaAPI"]
22+
),
23+
.executable(
24+
name: "BreezeLambdaItemAPI",
25+
targets: ["BreezeLambdaItemAPI"]
1926
)
2027
],
2128
dependencies: [
22-
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha.2"),
23-
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "0.1.0"),
24-
.package(url: "https://github.com/soto-project/soto.git", from: "6.7.0"),
25-
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
26-
.package(url: "https://github.com/swift-serverless/swift-sls-adapter", from: "0.2.1"),
27-
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.11.2"),
29+
// TODO: change to upstream once the upstream is tagged
30+
.package(url: "https://github.com/andrea-scuderi/swift-aws-lambda-runtime.git", branch: "main"),
31+
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "0.5.0"),
32+
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.0.0"),
33+
.package(url: "https://github.com/soto-project/soto.git", from: "7.0.0"),
34+
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.2"),
35+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
2836
],
2937
targets: [
38+
.executableTarget(
39+
name: "BreezeLambdaItemAPI",
40+
dependencies: [
41+
"BreezeLambdaAPI"
42+
]
43+
),
3044
.target(
3145
name: "BreezeDynamoDBService",
3246
dependencies: [
3347
.product(name: "SotoDynamoDB", package: "soto"),
34-
.product(name: "Logging", package: "swift-log")
48+
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
49+
.product(name: "Logging", package: "swift-log"),
3550
]
3651
),
3752
.target(
3853
name: "BreezeLambdaAPI",
3954
dependencies: [
4055
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
4156
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
57+
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
4258
"BreezeDynamoDBService"
4359
]
4460
),
4561
.testTarget(
4662
name: "BreezeLambdaAPITests",
4763
dependencies: [
48-
.product(name: "AWSLambdaTesting", package: "swift-aws-lambda-runtime"),
64+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
65+
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
66+
.product(name: "ServiceLifecycleTestKit", package: "swift-service-lifecycle"),
4967
"BreezeLambdaAPI"
5068
],
5169
resources: [.copy("Fixtures")]
5270
),
5371
.testTarget(
5472
name: "BreezeDynamoDBServiceTests",
55-
dependencies: ["BreezeDynamoDBService"]
73+
dependencies: [
74+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
75+
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
76+
.product(name: "ServiceLifecycleTestKit", package: "swift-service-lifecycle"),
77+
"BreezeDynamoDBService"
78+
]
5679
)
5780
]
5881
)

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ extension Item: BreezeCodable { }
6969
Add the implementation of the Lambda to the file `swift.main`
7070

7171
```swift
72-
BreezeLambdaAPI<Item>.main()
72+
@main
73+
struct BreezeLambdaItemAPI {
74+
static func main() async throws {
75+
do {
76+
try await BreezeLambdaAPI<Item>().run()
77+
} catch {
78+
print(error.localizedDescription)
79+
}
80+
}
81+
}
7382
```
7483

7584
## Documentation

Sources/BreezeDynamoDBService/BreezeCodable.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 (c) Andrea Scuderi - https://github.com/swift-serverless
1+
// Copyright 2024 (c) Andrea Scuderi - https://github.com/swift-serverless
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,9 +12,24 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#if canImport(FoundationEssentials)
16+
import FoundationEssentials
17+
#else
1518
import Foundation
19+
#endif
1620

17-
public protocol BreezeCodable: Codable {
21+
/// CodableSendable is a protocol that combines Sendable and Codable.
22+
public protocol CodableSendable: Sendable, Codable { }
23+
24+
/// BreezeCodable is a protocol that extends CodableSendable to include properties
25+
/// for a key, creation date, and update date.
26+
/// It is designed to be used with Breeze services that require these common fields
27+
/// for items stored in a database, such as DynamoDB.
28+
/// - Parameters:
29+
/// - key: A unique identifier for the item.
30+
/// - createdAt: An optional string representing the creation date of the item.
31+
/// - updatedAt: An optional string representing the last update date of the item.
32+
public protocol BreezeCodable: CodableSendable {
1833
var key: String { get set }
1934
var createdAt: String? { get set }
2035
var updatedAt: String? { get set }
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2024 (c) Andrea Scuderi - https://github.com/swift-serverless
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import SotoCore
16+
17+
/// BreezeDynamoDBConfig is a configuration structure for Breeze DynamoDB service.
18+
/// It contains the necessary parameters to connect to a DynamoDB instance, including the region, table name, key name, and an optional endpoint.
19+
public struct BreezeDynamoDBConfig: Sendable {
20+
21+
/// Initializes a new instance of BreezeDynamoDBConfig.
22+
/// - Parameters:
23+
/// - region: The AWS region where the DynamoDB table is located.
24+
/// - tableName: The name of the DynamoDB table.
25+
/// - keyName: The name of the primary key in the DynamoDB table.
26+
/// - endpoint: An optional endpoint URL for the DynamoDB service. If not provided, the default AWS endpoint will be used.
27+
public init(
28+
region: Region,
29+
tableName: String,
30+
keyName: String,
31+
endpoint: String? = nil
32+
) {
33+
self.region = region
34+
self.tableName = tableName
35+
self.keyName = keyName
36+
self.endpoint = endpoint
37+
}
38+
39+
/// The AWS region where the DynamoDB table is located.
40+
public let region: Region
41+
42+
/// The name of the DynamoDB table.
43+
public let tableName: String
44+
45+
/// The name of the primary key in the DynamoDB table.
46+
public let keyName: String
47+
48+
/// An optional endpoint URL for the DynamoDB service.
49+
public let endpoint: String?
50+
}

0 commit comments

Comments
 (0)