Skip to content

Commit

Permalink
rename Service and cleanup Exports
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuawright11 committed Jul 16, 2024
1 parent 807a65b commit a97be90
Show file tree
Hide file tree
Showing 81 changed files with 127 additions and 30 deletions.
1 change: 1 addition & 0 deletions Alchemy/AlchemyX/Application+AlchemyX.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AlchemyX
import Foundation

extension Application {
@discardableResult
Expand Down
1 change: 1 addition & 0 deletions Alchemy/AlchemyX/Database+Resource.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AlchemyX
import Collections
import Foundation

extension Database {
/// Adds or alters a database table to match the schema of the Resource.
Expand Down
4 changes: 2 additions & 2 deletions Alchemy/Application/Lifecycle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public final class Lifecycle {
let plugins: [Plugin]

private var group: ServiceGroup?
private var services: [ServiceLifecycle.Service] = []
private var services: [Service] = []
private let lock = NIOLock()

init(app: Application) {
Expand Down Expand Up @@ -65,7 +65,7 @@ public final class Lifecycle {
lock.withLock { shutdownTasks.append(action) }
}

public func addService(_ service: ServiceLifecycle.Service) {
public func addService(_ service: Service) {
lock.withLock { services.append(service) }
}

Expand Down
2 changes: 1 addition & 1 deletion Alchemy/Cache/Cache.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// A type for accessing a persistant cache. Supported providers are
/// `RedisCache`, `DatabaseCache`, and `MemoryCache`.
public final class Cache: Service {
public final class Cache: IdentifiedService {
public typealias Identifier = ServiceIdentifier<Cache>

private let provider: CacheProvider
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Cache/Providers/DatabaseCache.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// A SQL based provider for `Cache`.
final class DatabaseCache: CacheProvider {
private let db: Database
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Cache/Providers/MemoryCache.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// An in memory provider for `Cache` for testing.
public final class MemoryCache: CacheProvider {
var data: [String: MemoryCacheItem] = [:]
Expand Down
1 change: 1 addition & 0 deletions Alchemy/Command/Make/FileCreator.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import Rainbow

/// Used to generate files related to an alchemy project.
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Command/Terminal.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

struct Terminal {
static var columns: Int = {
guard let string = try? shell("tput cols").trimmingCharacters(in: .whitespacesAndNewlines), let columns = Int(string) else {
Expand Down
2 changes: 1 addition & 1 deletion Alchemy/Database/Database.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Used for interacting with an SQL database.
public final class Database: Service {
public final class Database: IdentifiedService {
public typealias Identifier = ServiceIdentifier<Database>

/// The provider of this database.
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Migrations/Database+Migration.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

extension Database {
/// Represents a table for storing migration data. Alchemy will use
/// this table for keeping track of the various batches of
Expand Down
1 change: 1 addition & 0 deletions Alchemy/Database/Providers/MySQL/MySQLConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AsyncKit
import Foundation
import NIOSSL
import MySQLNIO

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import PostgresNIO

extension PostgresBindings {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AsyncKit
import Atomics
import Foundation
import PostgresNIO

public struct PostgresConfiguration: ConnectionPoolSource {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AsyncKit
import Foundation
import PostgresNIO

/// A concrete `Database` for connecting to and querying a PostgreSQL
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Providers/SQLite/Database+SQLite.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

extension Database {
/// An in memory SQLite database configuration.
public static var memory: Database {
Expand Down
1 change: 1 addition & 0 deletions Alchemy/Database/Providers/SQLite/SQLite+SQLValue.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import SQLiteNIO

extension SQLiteData: SQLValueConvertible {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AsyncKit
import Foundation
import SQLiteNIO

public struct SQLiteConfiguration: ConnectionPoolSource {
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Query/Query.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// An SQL query.
open class Query<Result: QueryResult>: SQLConvertible {
let db: Database
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Rune/Model/Coding/SQLRowDecoder.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

struct SQLRowDecoder: Decoder {
/// A `KeyedDecodingContainerProtocol` used to decode keys from a
/// `SQLRow`.
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Rune/Model/Coding/SQLRowEncoder.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

final class SQLRowEncoder: Encoder {
/// Used to decode keyed values from a Model.
private struct _KeyedEncodingContainer<Key: CodingKey>: KeyedEncodingContainerProtocol {
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Rune/Model/Coding/SQLRowReader.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public struct SQLRowReader {
public let row: SQLRow
public let keyMapping: KeyMapping
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Rune/Model/Coding/SQLRowWriter.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public struct SQLRowWriter {
public internal(set) var fields: SQLFields
let keyMapping: KeyMapping
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Rune/Model/Model+CRUD.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// Useful extensions for various CRUD operations of a `Model`.
extension Model {

Expand Down
1 change: 1 addition & 0 deletions Alchemy/Database/Rune/Model/Model.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import Pluralize

/// An ActiveRecord-esque type used for modeling a table in a relational
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Rune/Model/ModelProperty.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

// For custom logic around loading and saving properties on a Model.
public protocol ModelProperty {
init(key: String, on row: SQLRowReader) throws
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Rune/Model/PrimaryKeyProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// Represents a type that may be the primary key of a database table. Out of
/// the box, `UUID`, `String` and `Int` are supported but you can easily
/// support your own by conforming to this protocol.
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Rune/Model/SoftDeletes.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public protocol SoftDeletes {
static var deletedAtKey: String { get }
}
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Rune/Model/Timestamped.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public protocol Timestamped {
static var createdAtKey: String { get }
static var updatedAtKey: String { get }
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/SQL/SQLConvertible.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// Something that's convertible to an SQL statement or expression.
public protocol SQLConvertible {
var sql: SQL { get }
Expand Down
1 change: 1 addition & 0 deletions Alchemy/Database/SQL/SQLRow.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Collections
import Foundation

/// A row of data returned by an SQL query.
public struct SQLRow: ExpressibleByDictionaryLiteral {
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/SQL/SQLValue.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// A value that can be stored and loaded from fields in an SQL table.
public enum SQLValue: Hashable, CustomStringConvertible {
/// An `Int` value.
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/SQL/SQLValueConvertible.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public protocol SQLValueConvertible: SQLConvertible {
var sqlValue: SQLValue { get }
}
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Schema/CreateColumnBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// A type erased `CreateColumnBuilder`.
protocol ColumnBuilderErased {
/// Generate the `CreateColumn` data associated with this builder.
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Database/Schema/CreateTableBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// A builder with useful functions for creating a table.
public class CreateTableBuilder {
/// The grammar with which this builder will compile SQL
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Encryption/Encrypted.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

@propertyWrapper
public struct Encrypted: ModelProperty, Codable {
public var wrappedValue: String
Expand Down
1 change: 1 addition & 0 deletions Alchemy/Encryption/Encrypter.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Crypto
import Foundation

extension SymmetricKey {
public static var app: SymmetricKey = {
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Environment/Environment.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// Handles any environment info of your application. Loads any environment
/// variables from the file a `.env` or `.env.{APP_ENV}` if `APP_ENV` is
/// set in the current environment.
Expand Down
2 changes: 1 addition & 1 deletion Alchemy/Events/EventBus.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NIOConcurrencyHelpers

public final class EventBus: Service {
public final class EventBus: IdentifiedService {
public typealias Identifier = ServiceIdentifier<EventBus>

public typealias Handler<E: Event> = (E) async throws -> Void
Expand Down
10 changes: 0 additions & 10 deletions Alchemy/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// Argument Parser
@_exported import ArgumentParser

// Foundation
@_exported import Foundation

// HTTPTypes
@_exported import struct HTTPTypes.HTTPField
@_exported import struct HTTPTypes.HTTPFields
Expand All @@ -20,13 +17,6 @@

// NIO
@_exported import struct NIO.ByteBuffer
@_exported import class NIO.EmbeddedEventLoop
@_exported import protocol NIO.EventLoop
@_exported import protocol NIO.EventLoopGroup
@_exported import struct NIO.NonBlockingFileIO
@_exported import class NIO.NIOThreadPool
@_exported import enum NIO.System
@_exported import struct NIO.TimeAmount

// NIOCore
@_exported import enum NIOCore.SocketAddress
1 change: 1 addition & 0 deletions Alchemy/Filesystem/File.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import MultipartKit

/// Represents a file from either a filesystem (on disk, in AWS S3, etc) or from
Expand Down
3 changes: 2 additions & 1 deletion Alchemy/Filesystem/Filesystem.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation
import NIOConcurrencyHelpers

/// An abstraction around local or remote file storage.
public final class Filesystem: Service {
public final class Filesystem: IdentifiedService {
public typealias Identifier = ServiceIdentifier<Filesystem>

private var provider: FilesystemProvider
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Filesystem/FilesystemProvider.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public protocol FilesystemProvider {
/// The root directory for storing and fetching files.
var root: String { get }
Expand Down
3 changes: 2 additions & 1 deletion Alchemy/Filesystem/Providers/LocalFilesystem.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import NIOCore
import Foundation
import NIO

extension Filesystem {
/// Create a filesystem backed by the local filesystem at the given root
Expand Down
1 change: 1 addition & 0 deletions Alchemy/HTTP/Bytes.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AsyncHTTPClient
import Foundation
import HummingbirdCore

/// A collection of bytes that is either a single buffer or a stream of buffers.
Expand Down
3 changes: 2 additions & 1 deletion Alchemy/HTTP/Client.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AsyncHTTPClient
import Foundation
import NIOCore
import NIOHTTP1

Expand All @@ -10,7 +11,7 @@ import NIOHTTP1
/// let response = try await Http.get("https://swift.org")
///
/// See `Client.Builder` for the request builder interface.
public final class Client: Service {
public final class Client: IdentifiedService {
public typealias Identifier = ServiceIdentifier<Client>

/// A type for making http requests with a `Client`. Supports static or
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/HTTP/Coding/HTTPCoding+JSON.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

extension HTTPEncoder where Self == JSONEncoder {
public static var json: JSONEncoder { JSONEncoder() }
}
Expand Down
1 change: 1 addition & 0 deletions Alchemy/HTTP/Protocols/HTTPBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import Hummingbird
import MultipartKit

Expand Down
1 change: 1 addition & 0 deletions Alchemy/HTTP/Protocols/HTTPInspector.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import MultipartKit

public protocol HTTPInspector {
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/HTTP/Protocols/RequestBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public protocol RequestBuilder: HTTPBuilder {
associatedtype Res

Expand Down
2 changes: 2 additions & 0 deletions Alchemy/HTTP/Protocols/RequestInspector.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public protocol RequestInspector: HTTPInspector {
var method: HTTPRequest.Method { get }
var urlComponents: URLComponents { get }
Expand Down
3 changes: 3 additions & 0 deletions Alchemy/HTTP/Request.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Foundation
import NIOCore

/// A type that represents inbound requests to your application.
public final class Request: RequestInspector {
/// Represents a dynamic parameter inside the path. Parameter placeholders
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/HTTP/Response.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// A type representing the response from an HTTP endpoint. This response can be
/// a failure or success case depending on the status code in the `head`.
public final class Response {
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/HTTP/Serving/Responder.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Foundation
import Hummingbird
import NIOCore

actor Responder: HTTPResponder {
struct Context: RequestContext {
Expand Down
2 changes: 1 addition & 1 deletion Alchemy/Hashing/Hasher.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public struct Hasher: Service {
public struct Hasher: IdentifiedService {
public typealias Identifier = ServiceIdentifier<Database>

private let algorithm: HashAlgorithm
Expand Down
1 change: 1 addition & 0 deletions Alchemy/Hashing/Providers/BCryptHasher.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CAlchemy
import Foundation

extension HashAlgorithm where Self == BCryptHasher {
public static var bcrypt: BCryptHasher {
Expand Down
1 change: 1 addition & 0 deletions Alchemy/Hashing/Providers/SHA256Hasher.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Crypto
import Foundation

extension HashAlgorithm where Self == SHA256Hasher {
public static var sha256: SHA256Hasher {
Expand Down
2 changes: 1 addition & 1 deletion Alchemy/Logging/Logger+Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// // In Application.boot...
/// Log.logger = Logger(label: "my_default_logger")
/// ```
extension Logger: Service {
extension Logger: IdentifiedService {
public typealias Identifier = ServiceIdentifier<Logger>

// MARK: Conveniences
Expand Down
2 changes: 2 additions & 0 deletions Alchemy/Logging/Loggers.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public struct Loggers: Plugin {
public let `default`: Logger.Identifier?
public let loggers: [Logger.Identifier: Logger]
Expand Down
Loading

0 comments on commit a97be90

Please sign in to comment.