Skip to content

Commit 79bf354

Browse files
authored
Update For Swift 6 (#61)
* Update to 5.9 * Make it compile * Remove the warnings * Adopt new APIs * update CI * Fix test compilation
1 parent 266a489 commit 79bf354

19 files changed

+104
-67
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
dbimage:
2222
- mongo:6
2323
runs-on: ubuntu-latest
24-
container: swift:5.7-jammy
24+
container: swift:6.0-jammy
2525
services:
2626
mongo-a:
2727
image: ${{ matrix.dbimage }}
@@ -48,7 +48,7 @@ jobs:
4848
api-breakage:
4949
if: github.event_name == 'pull_request'
5050
runs-on: ubuntu-latest
51-
container: swift:5.8-jammy
51+
container: swift:6.0-jammy
5252
steps:
5353
- name: Check out package
5454
uses: actions/checkout@v3
@@ -68,11 +68,9 @@ jobs:
6868
dbimage:
6969
- mongo:6
7070
runner:
71-
- swift:5.6-focal
72-
- swift:5.7-jammy
73-
- swift:5.8-jammy
74-
- swiftlang/swift:nightly-5.9-jammy
75-
- swiftlang/swift:nightly-main-jammy
71+
- swift:5.9-focal
72+
- swift:5.10-jammy
73+
- swift:6.0-jammy
7674
container: ${{ matrix.runner }}
7775
runs-on: ubuntu-latest
7876
services:
@@ -92,7 +90,7 @@ jobs:
9290
fail-fast: false
9391
matrix:
9492
dbimage: ['mongodb-community']
95-
macos: ['macos-12']
93+
macos: ['macos-14']
9694
xcode: ['latest-stable']
9795
runs-on: ${{ matrix.macos }}
9896
env:

Package.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.6
1+
// swift-tools-version:5.9
22
import PackageDescription
33

44
let package = Package(
@@ -13,7 +13,7 @@ let package = Package(
1313
.library(name: "FluentMongoDriver", targets: ["FluentMongoDriver"]),
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.37.0"),
16+
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.49.0"),
1717
.package(url: "https://github.com/orlandos-nl/MongoKitten.git", from: "6.7.13"),
1818
.package(url: "https://github.com/orlandos-nl/DNSClient.git", exact: "2.3.0"),
1919
],
@@ -24,14 +24,24 @@ let package = Package(
2424
.product(name: "FluentKit", package: "fluent-kit"),
2525
.product(name: "MongoKitten", package: "MongoKitten"),
2626
.product(name: "DNSClient", package: "DNSClient"),
27-
]
27+
],
28+
swiftSettings: swiftSettings
2829
),
2930
.testTarget(
3031
name: "FluentMongoDriverTests",
3132
dependencies: [
3233
.target(name: "FluentMongoDriver"),
3334
.product(name: "FluentBenchmark", package: "fluent-kit"),
34-
]
35+
],
36+
swiftSettings: swiftSettings
3537
),
3638
]
3739
)
40+
41+
var swiftSettings: [SwiftSetting] { [
42+
.enableUpcomingFeature("ExistentialAny"),
43+
.enableUpcomingFeature("ConciseMagicFile"),
44+
.enableUpcomingFeature("ForwardTrailingClosures"),
45+
.enableUpcomingFeature("DisableOutwardActorInference"),
46+
.enableExperimentalFeature("StrictConcurrency=complete"),
47+
] }

Sources/FluentMongoDriver/ChangeStream.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import MongoKitten
22
import FluentKit
33

44
extension Model {
5-
public static func watch(on database: Database, options: ChangeStreamOptions = .init()) -> EventLoopFuture<ChangeStream<Self>> {
6-
guard let mongodb = database as? MongoDatabaseRepresentable else {
5+
public static func watch(on database: any Database, options: ChangeStreamOptions = .init()) -> EventLoopFuture<ChangeStream<Self>> {
6+
guard let mongodb = database as? (any MongoDatabaseRepresentable) else {
77
return database.eventLoop.makeFailedFuture(FluentMongoError.notMongoDB)
88
}
99

Sources/FluentMongoDriver/DatabaseValue+Mongo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import FluentKit
22
import MongoKitten
33

44
extension DatabaseQuery.Value {
5-
func makePrimitive() throws -> Primitive {
5+
func makePrimitive() throws -> any Primitive {
66
switch self {
77
case .array(let values):
88
var array = Document(isArray: true)
@@ -24,7 +24,7 @@ extension DatabaseQuery.Value {
2424
return Null()
2525
case .default:
2626
throw FluentMongoError.unsupportedDefaultValue
27-
case .custom(let primitive as Primitive):
27+
case .custom(let primitive as any Primitive):
2828
return primitive
2929
case .enumCase(let string):
3030
return string

Sources/FluentMongoDriver/Document+DatabaseOutput.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import FluentKit
2-
import MongoKitten
2+
@preconcurrency import MongoKitten
33

44
extension Document {
5-
internal func databaseOutput(using decoder: BSONDecoder) -> DatabaseOutput {
5+
internal func databaseOutput(using decoder: BSONDecoder) -> any DatabaseOutput {
66
_FluentMongoOutput(document: self, decoder: decoder, schema: nil)
77
}
88
}
@@ -16,7 +16,7 @@ private struct _FluentMongoOutput: DatabaseOutput {
1616
self.document.debugDescription
1717
}
1818

19-
func schema(_ schema: String) -> DatabaseOutput {
19+
func schema(_ schema: String) -> any DatabaseOutput {
2020
_FluentMongoOutput(document: self.document, decoder: self.decoder, schema: schema)
2121
}
2222

@@ -41,7 +41,7 @@ private struct _FluentMongoOutput: DatabaseOutput {
4141
)
4242
}
4343

44-
private func primitive(_ key: FieldKey) -> Primitive? {
44+
private func primitive(_ key: FieldKey) -> (any Primitive)? {
4545
if let schema = self.schema {
4646
let nested = self.document[schema] as! Document
4747
return nested[key.makeMongoKey()]

Sources/FluentMongoDriver/Errors.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@ import MongoCore
33
import FluentKit
44
import Foundation
55

6-
extension MongoWriteError: DatabaseError {
6+
extension MongoWriteError {
77
public var isSyntaxError: Bool { false }
88
public var isConstraintFailure: Bool { false }
99
public var isConnectionClosed: Bool { false }
1010
}
1111

12-
extension MongoError: DatabaseError {
12+
// Used for DatabaseError
13+
extension MongoError {
1314
public var isSyntaxError: Bool { false }
1415
public var isConstraintFailure: Bool { false }
1516
public var isConnectionClosed: Bool { false }
1617
}
1718

19+
#if compiler(<6)
20+
extension MongoWriteError: DatabaseError {}
21+
extension MongoError: DatabaseError {}
22+
#else
23+
extension MongoWriteError: @retroactive DatabaseError {}
24+
extension MongoError: @retroactive DatabaseError {}
25+
#endif
26+
1827
public enum FluentMongoError: Error, DatabaseError {
1928
public var isSyntaxError: Bool { false }
2029
public var isConstraintFailure: Bool { false }

Sources/FluentMongoDriver/GridFS.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Foundation
2-
import MongoKitten
2+
@preconcurrency import MongoKitten
33
import FluentKit
44

55
extension MongoDatabaseRepresentable {
@@ -9,15 +9,15 @@ extension MongoDatabaseRepresentable {
99
}
1010

1111
extension GridFSFile {
12-
public static func find(_ id: Primitive, on database: Database) -> EventLoopFuture<GridFSFile?> {
13-
guard let mongodb = database as? MongoDatabaseRepresentable else {
12+
public static func find(_ id: any Primitive, on database: any Database) -> EventLoopFuture<GridFSFile?> {
13+
guard let mongodb = database as? (any MongoDatabaseRepresentable) else {
1414
return database.eventLoop.makeFailedFuture(FluentMongoError.notMongoDB)
1515
}
1616

1717
return mongodb._gridFS.findFile(byId: id)
1818
}
1919

20-
public static func read(_ id: Primitive, on database: Database) -> EventLoopFuture<ByteBuffer?> {
20+
public static func read(_ id: any Primitive, on database: any Database) -> EventLoopFuture<ByteBuffer?> {
2121
return find(id, on: database).flatMap { file in
2222
guard let file = file else {
2323
return database.eventLoop.makeSucceededFuture(nil)
@@ -32,9 +32,9 @@ extension GridFSFile {
3232
_ buffer: ByteBuffer,
3333
named filename: String? = nil,
3434
metadata: Document? = nil,
35-
on database: Database
35+
on database: any Database
3636
) -> EventLoopFuture<GridFSFile> {
37-
guard let mongodb = database as? MongoDatabaseRepresentable else {
37+
guard let mongodb = database as? (any MongoDatabaseRepresentable) else {
3838
return database.eventLoop.makeFailedFuture(FluentMongoError.notMongoDB)
3939
}
4040

Sources/FluentMongoDriver/MongoDB+Aggregate.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import FluentKit
2-
import MongoKitten
2+
@preconcurrency import MongoKitten
33
import MongoCore
44

55
extension FluentMongoDatabase {
6+
@preconcurrency
67
func aggregate(
78
query: DatabaseQuery,
89
aggregate: DatabaseQuery.Aggregate,
9-
onOutput: @escaping (DatabaseOutput) -> ()
10+
onOutput: @Sendable @escaping (any DatabaseOutput) -> ()
1011
) -> EventLoopFuture<Void> {
1112
guard case .field(let field, let method) = aggregate else {
1213
return eventLoop.makeFailedFuture(FluentMongoError.unsupportedCustomAggregate)
@@ -52,7 +53,7 @@ extension FluentMongoDatabase {
5253

5354
private func count(
5455
query: DatabaseQuery,
55-
onOutput: @escaping (DatabaseOutput) -> ()
56+
onOutput: @escaping @Sendable (any DatabaseOutput) -> ()
5657
) -> EventLoopFuture<Void> {
5758
do {
5859
let condition = try query.makeMongoDBFilter(aggregate: false)
@@ -78,7 +79,7 @@ extension FluentMongoDatabase {
7879
query: DatabaseQuery,
7980
mongoOperator: String,
8081
field: DatabaseQuery.Field,
81-
onOutput: @escaping (DatabaseOutput) -> ()
82+
onOutput: @escaping @Sendable (any DatabaseOutput) -> ()
8283
) -> EventLoopFuture<Void> {
8384
do {
8485
let field = try field.makeMongoPath()

Sources/FluentMongoDriver/MongoDB+Create.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import FluentKit
2-
import MongoKitten
2+
@preconcurrency import MongoKitten
33
import MongoCore
44

55
extension FluentMongoDatabase {
6+
@preconcurrency
67
func create(
78
query: DatabaseQuery,
8-
onOutput: @escaping (DatabaseOutput) -> ()
9+
onOutput: @Sendable @escaping (any DatabaseOutput) -> ()
910
) -> EventLoopFuture<Void> {
1011
do {
1112
let documents = try query.makeValueDocuments()

Sources/FluentMongoDriver/MongoDB+DatabaseRow.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import MongoKitten
1+
@preconcurrency import MongoKitten
22
import FluentKit
33

44
struct _MongoDBAggregateResponse: DatabaseOutput {
5-
let value: Primitive
5+
let value: any Primitive
66
let decoder: BSONDecoder
77

88
var description: String {
99
"\(self.value)"
1010
}
1111

12-
func schema(_ schema: String) -> DatabaseOutput {
12+
func schema(_ schema: String) -> any DatabaseOutput {
1313
self
1414
}
1515

0 commit comments

Comments
 (0)