Skip to content
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

Asyncification of Fluent provider #772

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 24 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 2
enable-beta-ecosystems: true
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-type: all
groups:
dependencies:
patterns:
- "*"
- package-ecosystem: "swift"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 6
allow:
- dependency-type: all
groups:
all-dependencies:
patterns:
- "*"
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7
import PackageDescription

let package = Package(
Expand All @@ -13,8 +13,8 @@ let package = Package(
.library(name: "Fluent", targets: ["Fluent"]),
],
dependencies: [
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.38.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.50.0"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.45.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.91.1"),
],
targets: [
.target(name: "Fluent", dependencies: [
Expand Down
44 changes: 44 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// swift-tools-version:5.9
import PackageDescription

let package = Package(
name: "fluent",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.watchOS(.v6),
.tvOS(.v13),
],
products: [
.library(name: "Fluent", targets: ["Fluent"]),
],
dependencies: [
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.45.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.91.1"),
],
targets: [
.target(
name: "Fluent",
dependencies: [
.product(name: "FluentKit", package: "fluent-kit"),
.product(name: "Vapor", package: "vapor"),
],
swiftSettings: [
.enableUpcomingFeature("ExistentialAny"),
.enableExperimentalFeature("StrictConcurrency=complete"),
]
),
.testTarget(
name: "FluentTests",
dependencies: [
.target(name: "Fluent"),
.product(name: "XCTFluent", package: "fluent-kit"),
.product(name: "XCTVapor", package: "vapor"),
],
swiftSettings: [
.enableUpcomingFeature("ExistentialAny"),
.enableExperimentalFeature("StrictConcurrency=complete"),
]
),
]
)
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/1130717/259915558-d72ded24-bc79-4b1b-8f8b-398bf0640f9a.png">
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/1130717/259915594-3fb46670-44a7-4677-a7b2-30f9bcf873af.png">
<img src="https://user-images.githubusercontent.com/1130717/259915594-3fb46670-44a7-4677-a7b2-30f9bcf873af.png" height="96" alt="Fluent">
</picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/fluent/assets/1130717/f4708c0b-3c9e-4e8b-9508-aa1ca6481c70">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/fluent/assets/1130717/bc4e1040-1e8a-4c0c-a24d-e87221a01af3">
<img src="https://github.com/vapor/fluent/assets/1130717/bc4e1040-1e8a-4c0c-a24d-e87221a01af3" height="96" alt="Fluent">
</picture>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/fluent/overview/"><img src="https://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/fluent/actions/workflows/test.yml"><img src="https://github.com/vapor/fluent/actions/workflows/test.yml/badge.svg" alt="Continuous Integration"></a>
<a href="https://swift.org"><img src="https://img.shields.io/badge/swift-5.6-brightgreen.svg" alt="Swift 5.6"></a>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/fluent/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/fluent/test.yml?event=push&style=plastic&logo=github&label=test&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/fluent"><img src="https://img.shields.io/codecov/c/github/vapor/fluent?style=plastic&logo=codecov&label=Codecov&token=yDzzHja8lt"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift57up.svg" alt="Swift 5.7+"></a>
</p>

<br>

The Fluent package makes it easy to use FluentKit in Vapor applications by tying the FluentKit database abstraction layer into the Vapor application lifecycle. It also provides helpers for mapping FluentKit's models to Vapor's authentication APIs.

For more information, see the [Fluent documentation](https://docs.vapor.codes/fluent/overview/).
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import NIOCore
import Vapor
import FluentKit
@preconcurrency import FluentKit

extension ModelCredentialsAuthenticatable {
public static func asyncCredentialsAuthenticator(
_ database: DatabaseID? = nil
) -> AsyncAuthenticator {
) -> any AsyncAuthenticator {
AsyncModelCredentialsAuthenticator<Self>(database: database)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Fluent/Concurrency/Sessions+Concurrency.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import NIOCore
import Vapor
import FluentKit
@preconcurrency import FluentKit

extension Model where Self: SessionAuthenticatable, Self.SessionID == Self.IDValue {
public static func asyncSessionAuthenticator(
_ databaseID: DatabaseID? = nil
) -> AsyncAuthenticator {
) -> any AsyncAuthenticator {
AsyncDatabaseSessionAuthenticator<Self>(databaseID: databaseID)
}
}
Expand Down
22 changes: 22 additions & 0 deletions Sources/Fluent/Docs.docc/images/vapor-fluent-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Sources/Fluent/Docs.docc/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ``Fluent``

Fluent makes it easy for you to use FluentKit in your Vapor application. It ties together the FluentKit database abstraction layer with the Vapor application lifecycle. It also provides helpers for mapping FluentKit's models to Vapor's authentication APIs.
The Fluent package makes it easy to use FluentKit in Vapor applications by tying the FluentKit database abstraction layer into the Vapor application lifecycle. It also provides helpers for mapping FluentKit's models to Vapor's authentication APIs.

For more information, see the [Vapor documentation](https://docs.vapor.codes/fluent/overview/).
For more information, see the [Fluent documentation](https://docs.vapor.codes/fluent/overview/).
21 changes: 21 additions & 0 deletions Sources/Fluent/Docs.docc/theme-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"theme": {
"aside": { "border-radius": "6px", "border-style": "double", "border-width": "3px" },
"border-radius": "0",
"button": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
"code": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
"color": {
"fluent": "#392048",
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-fluent) 30%, #000 100%)",
"documentation-intro-accent": "var(--color-fluent)",
"logo-base": { "dark": "#fff", "light": "#000" },
"logo-shape": { "dark": "#000", "light": "#fff" },
"fill": { "dark": "#000", "light": "#fff" }
},
"icons": { "technology": "/fluent/images/vapor-fluent-logo.svg" }
},
"features": {
"quickNavigation": { "enable": true },
"i18n": { "enable": true }
}
}
16 changes: 8 additions & 8 deletions Sources/Fluent/Fluent+Cache.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import NIOCore
import Foundation
import Vapor
import FluentKit
@preconcurrency import FluentKit

extension Application.Caches {
public var fluent: Cache {
public var fluent: any Cache {
self.fluent(nil)
}

public func fluent(_ db: DatabaseID?) -> Cache {
public func fluent(_ db: DatabaseID?) -> any Cache {
FluentCache(id: db, database: self.application.db(db))
}
}
Expand All @@ -27,9 +27,9 @@ extension Application.Caches.Provider {

private struct FluentCache: Cache {
let id: DatabaseID?
let database: Database
let database: any Database

init(id: DatabaseID?, database: Database) {
init(id: DatabaseID?, database: any Database) {
self.id = id
self.database = database
}
Expand Down Expand Up @@ -78,7 +78,7 @@ public final class CacheEntry: Model {
public static let schema: String = "_fluent_cache"

struct Create: Migration {
func prepare(on database: Database) -> EventLoopFuture<Void> {
func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema("_fluent_cache")
.id()
.field("key", .string, .required)
Expand All @@ -87,12 +87,12 @@ public final class CacheEntry: Model {
.create()
}

func revert(on database: Database) -> EventLoopFuture<Void> {
func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema("_fluent_cache").delete()
}
}

public static var migration: Migration {
public static var migration: any Migration {
Create()
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Fluent/Fluent+History.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vapor
import FluentKit
@preconcurrency import FluentKit

struct RequestQueryHistory: StorageKey {
typealias Value = QueryHistory
Expand Down
2 changes: 1 addition & 1 deletion Sources/Fluent/Fluent+Pagination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct RequestPaginationKey: StorageKey {
typealias Value = RequestPagination
}

struct RequestPagination {
struct RequestPagination: Sendable {
let pageSizeLimit: PageLimit?
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/Fluent/Fluent+Sessions.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import NIOCore
import Vapor
import FluentKit
@preconcurrency import FluentKit

extension Application.Fluent {
public var sessions: Sessions {
Expand Down Expand Up @@ -29,13 +29,13 @@ extension ModelSessionAuthenticatable {
extension Model where Self: SessionAuthenticatable, Self.SessionID == Self.IDValue {
public static func sessionAuthenticator(
_ databaseID: DatabaseID? = nil
) -> Authenticator {
) -> any Authenticator {
DatabaseSessionAuthenticator<Self>(databaseID: databaseID)
}
}

extension Application.Fluent.Sessions {
public func driver(_ databaseID: DatabaseID? = nil) -> SessionDriver {
public func driver(_ databaseID: DatabaseID? = nil) -> any SessionDriver {
DatabaseSessions(databaseID: databaseID)
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public final class SessionRecord: Model {
public static let schema = "_fluent_sessions"

struct Create: Migration {
func prepare(on database: Database) -> EventLoopFuture<Void> {
func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema("_fluent_sessions")
.id()
.field("key", .string, .required)
Expand All @@ -123,12 +123,12 @@ public final class SessionRecord: Model {
.create()
}

func revert(on database: Database) -> EventLoopFuture<Void> {
func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema("_fluent_sessions").delete()
}
}

public static var migration: Migration {
public static var migration: any Migration {
Create()
}

Expand Down
18 changes: 9 additions & 9 deletions Sources/Fluent/FluentProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import Vapor
import FluentKit

extension Request {
public var db: Database {
public var db: any Database {
self.db(nil)
}

public func db(_ id: DatabaseID?) -> Database {
public func db(_ id: DatabaseID?) -> any Database {
self.application
.databases
.database(
Expand All @@ -28,16 +28,16 @@ extension Request {
}

extension Application {
public var db: Database {
public var db: any Database {
self.db(nil)
}

public func db(_ id: DatabaseID?) -> Database {
public func db(_ id: DatabaseID?) -> any Database {
self.databases
.database(
id,
logger: self.logger,
on: self.eventLoopGroup.next(),
on: self.eventLoopGroup.any(),
history: self.fluent.history.historyEnabled ? self.fluent.history.history : nil,
pageSizeLimit: self.fluent.pagination.pageSizeLimit
)!
Expand Down Expand Up @@ -78,12 +78,12 @@ extension Application {
}

public struct Fluent {
final class Storage {
final class Storage: @unchecked Sendable {
gwynne marked this conversation as resolved.
Show resolved Hide resolved
let databases: Databases
let migrations: Migrations
var migrationLogLevel: Logger.Level

init(threadPool: NIOThreadPool, on eventLoopGroup: EventLoopGroup, migrationLogLevel: Logger.Level) {
init(threadPool: NIOThreadPool, on eventLoopGroup: any EventLoopGroup, migrationLogLevel: Logger.Level) {
self.databases = Databases(
threadPool: threadPool,
on: eventLoopGroup
Expand All @@ -106,7 +106,7 @@ extension Application {
@Flag(name: "auto-revert", help: "If true, Fluent will automatically revert your database on boot")
var autoRevert: Bool

init() { }
init() {}
}

let signature = try Signature(from: &application.environment.commandInput)
Expand Down Expand Up @@ -139,7 +139,7 @@ extension Application {
migrationLogLevel: .info
)
self.application.lifecycle.use(Lifecycle())
self.application.commands.use(MigrateCommand(), as: "migrate")
self.application.asyncCommands.use(MigrateCommand(), as: "migrate")
}

public var migrationLogLevel: Logger.Level {
Expand Down
Loading