Skip to content

Commit

Permalink
Fix NIO imports (#171)
Browse files Browse the repository at this point in the history
### Motivation

- SwiftNIO 2.32.0 introduces explicit modules for its Core and Posix.
- To write great platform independent code in most parts we should only ever import `NIOCore`

### Changes

- This pr explicitly imports NIOCore, NIOPosix and NIOEmbedded where needed.
  • Loading branch information
fabianfett authored Aug 18, 2021
1 parent 6f6ec7b commit 08c0dc5
Show file tree
Hide file tree
Showing 145 changed files with 219 additions and 90 deletions.
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
.library(name: "PostgresNIO", targets: ["PostgresNIO"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.28.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.12.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.0.0"),
Expand All @@ -25,12 +25,15 @@ let package = Package(
.product(name: "Logging", package: "swift-log"),
.product(name: "Metrics", package: "swift-metrics"),
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "NIOTLS", package: "swift-nio"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
]),
.testTarget(name: "PostgresNIOTests", dependencies: [
.target(name: "PostgresNIO"),
.product(name: "NIOEmbedded", package: "swift-nio"),
.product(name: "NIOTestUtils", package: "swift-nio"),
]),
.testTarget(name: "IntegrationTests", dependencies: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import NIO
import NIOCore
import Logging

extension PostgresConnection {
public func authenticate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import NIO
import NIOCore
import NIOSSL
import Logging

extension PostgresConnection {
public static func connect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import NIOCore
import Logging
import struct Foundation.Data

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore
import Logging

/// Context for receiving NotificationResponse messages on a connection, used for PostgreSQL's `LISTEN`/`NOTIFY` support.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Connection/PostgresConnection.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore
import Logging
import struct Foundation.UUID

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import NIOCore
import struct Foundation.UUID

extension PostgresDatabase {
public func prepare(query: String) -> EventLoopFuture<PreparedQuery> {
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/Data/PostgresData+Array.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension PostgresData {
public init<T>(array: [T])
where T: PostgresDataConvertible
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/Data/PostgresData+Bool.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension PostgresData {
public init(bool: Bool) {
var buffer = ByteBufferAllocator().buffer(capacity: 1)
Expand Down
1 change: 1 addition & 0 deletions Sources/PostgresNIO/Data/PostgresData+Bytes.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import struct Foundation.Data
import NIOCore

extension PostgresData {
public init<Bytes>(bytes: Bytes)
Expand Down
3 changes: 2 additions & 1 deletion Sources/PostgresNIO/Data/PostgresData+Date.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import struct Foundation.Date
import NIOCore

extension PostgresData {
public init(date: Date) {
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/Data/PostgresData+Double.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension PostgresData {
public init(double: Double) {
var buffer = ByteBufferAllocator().buffer(capacity: 0)
Expand Down
3 changes: 2 additions & 1 deletion Sources/PostgresNIO/Data/PostgresData+JSON.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import struct Foundation.Data
import NIOCore

extension PostgresData {
public init(json jsonData: Data) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/PostgresNIO/Data/PostgresData+JSONB.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import NIOCore
import struct Foundation.Data

fileprivate let jsonBVersionBytes: [UInt8] = [0x01]

Expand Down
1 change: 1 addition & 0 deletions Sources/PostgresNIO/Data/PostgresData+Numeric.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import NIOCore
import struct Foundation.Decimal

public struct PostgresNumeric: CustomStringConvertible, CustomDebugStringConvertible, ExpressibleByStringLiteral {
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/Data/PostgresData+String.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension PostgresData {
public init(string: String) {
var buffer = ByteBufferAllocator().buffer(capacity: string.utf8.count)
Expand Down
1 change: 1 addition & 0 deletions Sources/PostgresNIO/Data/PostgresData+UUID.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import NIOCore

extension PostgresData {
public init(uuid: UUID) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Data/PostgresData.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore
import Foundation

public struct PostgresData: CustomStringConvertible, CustomDebugStringConvertible {
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/Message/PostgresMessage+0.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

/// A frontend or backend Postgres message.
public struct PostgresMessage: Equatable {
public var identifier: Identifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Authentication request returned by the server.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as cancellation key data.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+Bind.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a Bind command.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+Close.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a Close Command
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a Close command.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+DataRow.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a data row.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+Describe.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a Describe command.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+Error.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// First message sent from the frontend during startup.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+Execute.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as an Execute command.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies an incoming or outgoing postgres message. Sent as the first byte, before the message size.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a notification response.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a parameter description.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
public struct ParameterStatus: PostgresMessageType, CustomStringConvertible {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+Parse.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a Parse command.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+Password.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a password response. Note that this is also used for
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message type. ReadyForQuery is sent whenever the backend is ready for a new query cycle.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a row description.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// SASL ongoing challenge response message sent by the client.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// A message asking the PostgreSQL server if SSL is supported
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a simple query.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+Startup.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// First message sent from the frontend during startup.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Message/PostgresMessage+Sync.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PostgresMessage {
/// Identifies the message as a Bind command.
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/Message/PostgresMessage+Terminate.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension PostgresMessage {
public struct Terminate: PostgresMessageType {
public static var identifier: PostgresMessage.Identifier {
Expand Down
3 changes: 2 additions & 1 deletion Sources/PostgresNIO/Message/PostgresMessageDecoder.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import NIO
import NIOCore
import Logging

public final class PostgresMessageDecoder: ByteToMessageDecoder {
/// See `ByteToMessageDecoder`.
Expand Down
3 changes: 2 additions & 1 deletion Sources/PostgresNIO/Message/PostgresMessageEncoder.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import NIO
import NIOCore
import Logging

public final class PostgresMessageEncoder: MessageToByteEncoder {
/// See `MessageToByteEncoder`.
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/Message/PostgresMessageType.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

public protocol PostgresMessageType {
static var identifier: PostgresMessage.Identifier { get }
static func parse(from buffer: inout ByteBuffer) throws -> Self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

struct AuthenticationStateMachine {

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

struct ConnectionStateMachine {

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

struct ExtendedQueryStateMachine {

Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore
import struct Foundation.UUID

/// A type, of which arrays can be encoded into and decoded from a postgres binary format
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension Bool: PSQLCodable {
var psqlType: PSQLDataType {
.bool
Expand Down
1 change: 1 addition & 0 deletions Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import struct Foundation.Data
import NIOCore
import NIOFoundationCompat

extension PSQLEncodable where Self: Sequence, Self.Element == UInt8 {
Expand Down
1 change: 1 addition & 0 deletions Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import NIOCore
import struct Foundation.Date

extension Date: PSQLCodable {
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension Float: PSQLCodable {
var psqlType: PSQLDataType {
.float4
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension UInt8: PSQLCodable {
var psqlType: PSQLDataType {
.char
Expand Down
1 change: 1 addition & 0 deletions Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import NIOCore
import NIOFoundationCompat
import class Foundation.JSONEncoder
import class Foundation.JSONDecoder
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/New/Data/Optional+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension Optional: PSQLDecodable where Wrapped: PSQLDecodable {
static func decode(from byteBuffer: inout ByteBuffer, type: PSQLDataType, format: PSQLFormat, context: PSQLDecodingContext) throws -> Optional<Wrapped> {
preconditionFailure("This code path should never be hit.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension PSQLCodable where Self: RawRepresentable, RawValue: PSQLCodable {
var psqlType: PSQLDataType {
self.rawValue.psqlType
Expand Down
1 change: 1 addition & 0 deletions Sources/PostgresNIO/New/Data/String+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import NIOCore
import struct Foundation.UUID

extension String: PSQLCodable {
Expand Down
1 change: 1 addition & 0 deletions Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import NIOCore
import struct Foundation.UUID
import typealias Foundation.uuid_t

Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/New/Extensions/ByteBuffer+PSQL.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

internal extension ByteBuffer {
mutating func writeNullTerminatedString(_ string: String) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/New/Messages/Authentication.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NIO
import NIOCore

extension PSQLBackendMessage {

Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/New/Messages/BackendKeyData.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension PSQLBackendMessage {

struct BackendKeyData: PayloadDecodable, Equatable {
Expand Down
2 changes: 2 additions & 0 deletions Sources/PostgresNIO/New/Messages/Bind.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NIOCore

extension PSQLFrontendMessage {

struct Bind {
Expand Down
Loading

0 comments on commit 08c0dc5

Please sign in to comment.