Skip to content

Commit c996d62

Browse files
authored
Deprecating PostgresDataConvertible, PostgresMessageType (vapor#313)
1 parent 606c68a commit c996d62

31 files changed

+201
-123
lines changed

Sources/PostgresNIO/Data/PostgresData+Array.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import NIOCore
22

33
extension PostgresData {
4-
public init<T>(array: [T])
5-
where T: PostgresDataConvertible
6-
{
4+
@available(*, deprecated, message: "Use ``PostgresQuery`` and ``PostgresBindings`` instead.")
5+
public init<T>(array: [T]) where T: PostgresDataConvertible {
76
self.init(
87
array: array.map { $0.postgresData },
98
elementType: T.postgresDataType
109
)
1110
}
11+
1212
public init(array: [PostgresData?], elementType: PostgresDataType) {
1313
var buffer = ByteBufferAllocator().buffer(capacity: 0)
1414
// 0 if empty, 1 if not
@@ -46,9 +46,8 @@ extension PostgresData {
4646
)
4747
}
4848

49-
public func array<T>(of type: T.Type = T.self) -> [T]?
50-
where T: PostgresDataConvertible
51-
{
49+
@available(*, deprecated, message: "Use ``PostgresRow`` and ``PostgresDecodable`` instead.")
50+
public func array<T>(of type: T.Type = T.self) -> [T]? where T: PostgresDataConvertible {
5251
guard let array = self.array else {
5352
return nil
5453
}
@@ -114,6 +113,7 @@ extension PostgresData {
114113
}
115114
}
116115

116+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
117117
extension Array: PostgresDataConvertible where Element: PostgresDataConvertible {
118118
public static var postgresDataType: PostgresDataType {
119119
guard let arrayType = Element.postgresDataType.arrayType else {

Sources/PostgresNIO/Data/PostgresData+Bool.swift

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extension PostgresData: ExpressibleByBooleanLiteral {
4747
}
4848
}
4949

50+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
5051
extension Bool: PostgresDataConvertible {
5152
public static var postgresDataType: PostgresDataType {
5253
return .bool

Sources/PostgresNIO/Data/PostgresData+Bytes.swift

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extension PostgresData {
2121
}
2222
}
2323

24+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
2425
extension Data: PostgresDataConvertible {
2526
public static var postgresDataType: PostgresDataType {
2627
return .bytea

Sources/PostgresNIO/Data/PostgresData+Date.swift

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extension PostgresData {
3636
}
3737
}
3838

39+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
3940
extension Date: PostgresDataConvertible {
4041
public static var postgresDataType: PostgresDataType {
4142
return .timestamptz

Sources/PostgresNIO/Data/PostgresData+Decimal.swift

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extension PostgresData {
1616
}
1717
}
1818

19+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
1920
extension Decimal: PostgresDataConvertible {
2021
public static var postgresDataType: PostgresDataType {
2122
return .numeric

Sources/PostgresNIO/Data/PostgresData+Double.swift

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extension PostgresData {
3434
}
3535
}
3636

37+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
3738
extension Double: PostgresDataConvertible {
3839
public static var postgresDataType: PostgresDataType {
3940
return .float8

Sources/PostgresNIO/Data/PostgresData+Float.swift

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extension PostgresData {
2828
}
2929
}
3030

31+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
3132
extension Float: PostgresDataConvertible {
3233
public static var postgresDataType: PostgresDataType {
3334
return .float4

Sources/PostgresNIO/Data/PostgresData+Int.swift

+5
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ extension PostgresData {
183183
}
184184
}
185185

186+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
186187
extension Int: PostgresDataConvertible {
187188
public static var postgresDataType: PostgresDataType { .int8 }
188189

@@ -198,6 +199,7 @@ extension Int: PostgresDataConvertible {
198199
}
199200
}
200201

202+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
201203
extension UInt8: PostgresDataConvertible {
202204
public static var postgresDataType: PostgresDataType { .char }
203205

@@ -213,6 +215,7 @@ extension UInt8: PostgresDataConvertible {
213215
}
214216
}
215217

218+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
216219
extension Int16: PostgresDataConvertible {
217220
public static var postgresDataType: PostgresDataType { .int2 }
218221

@@ -228,6 +231,7 @@ extension Int16: PostgresDataConvertible {
228231
}
229232
}
230233

234+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
231235
extension Int32: PostgresDataConvertible {
232236
public static var postgresDataType: PostgresDataType { .int4 }
233237

@@ -243,6 +247,7 @@ extension Int32: PostgresDataConvertible {
243247
}
244248
}
245249

250+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
246251
extension Int64: PostgresDataConvertible {
247252
public static var postgresDataType: PostgresDataType { .int8 }
248253

Sources/PostgresNIO/Data/PostgresData+JSON.swift

+2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ extension PostgresData {
3737
}
3838
}
3939

40+
@available(*, deprecated, message: "This protocol is going to be replaced with ``PostgresEncodable`` and ``PostgresDecodable`` and conforming to ``Codable`` at the same time")
4041
public protocol PostgresJSONCodable: Codable, PostgresDataConvertible { }
4142

43+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
4244
extension PostgresJSONCodable {
4345
public static var postgresDataType: PostgresDataType {
4446
return .json

Sources/PostgresNIO/Data/PostgresData+JSONB.swift

+2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ extension PostgresData {
4848
}
4949
}
5050

51+
@available(*, deprecated, message: "This protocol is going to be replaced with ``PostgresEncodable`` and ``PostgresDecodable`` and conforming to ``Codable`` at the same time")
5152
public protocol PostgresJSONBCodable: Codable, PostgresDataConvertible { }
5253

54+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
5355
extension PostgresJSONBCodable {
5456
public static var postgresDataType: PostgresDataType {
5557
return .jsonb

Sources/PostgresNIO/Data/PostgresData+Optional.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
12
extension Optional: PostgresDataConvertible where Wrapped: PostgresDataConvertible {
23
public static var postgresDataType: PostgresDataType {
34
return Wrapped.postgresDataType

Sources/PostgresNIO/Data/PostgresData+RawRepresentable.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
12
extension RawRepresentable where Self.RawValue: PostgresDataConvertible {
23
public static var postgresDataType: PostgresDataType {
34
RawValue.postgresDataType

Sources/PostgresNIO/Data/PostgresData+Set.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
12
extension Set: PostgresDataConvertible where Element: PostgresDataConvertible {
23
public static var postgresDataType: PostgresDataType {
34
[Element].postgresDataType

Sources/PostgresNIO/Data/PostgresData+String.swift

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ extension PostgresData: ExpressibleByStringLiteral {
9494
}
9595
}
9696

97+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
9798
extension String: PostgresDataConvertible {
9899
public static var postgresDataType: PostgresDataType {
99100
return .text

Sources/PostgresNIO/Data/PostgresData+UUID.swift

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extension PostgresData {
2929
}
3030
}
3131

32+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
3233
extension UUID: PostgresDataConvertible {
3334
public static var postgresDataType: PostgresDataType {
3435
return .uuid

Sources/PostgresNIO/Data/PostgresData.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import NIOCore
22
import struct Foundation.UUID
33

4-
public struct PostgresData: Sendable, CustomStringConvertible, CustomDebugStringConvertible {
4+
public struct PostgresData: Sendable {
55
public static var null: PostgresData {
66
return .init(type: .null)
77
}
@@ -26,7 +26,10 @@ public struct PostgresData: Sendable, CustomStringConvertible, CustomDebugString
2626
self.formatCode = formatCode
2727
self.value = value
2828
}
29-
29+
}
30+
31+
@available(*, deprecated, message: "Deprecating conformance to `CustomStringConvertible` as a first step of deprecating `PostgresData`. Please use `PostgresBindings` or `PostgresCell` instead.")
32+
extension PostgresData: CustomStringConvertible {
3033
public var description: String {
3134
guard var value = self.value else {
3235
return "<null>"
@@ -93,12 +96,16 @@ public struct PostgresData: Sendable, CustomStringConvertible, CustomDebugString
9396
return "\(raw) (\(self.type))"
9497
}
9598
}
99+
}
96100

101+
@available(*, deprecated, message: "Deprecating conformance to `CustomDebugStringConvertible` as a first step of deprecating `PostgresData`. Please use `PostgresBindings` or `PostgresCell` instead.")
102+
extension PostgresData: CustomDebugStringConvertible {
97103
public var debugDescription: String {
98104
return self.description
99105
}
100106
}
101107

108+
@available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.")
102109
extension PostgresData: PostgresDataConvertible {
103110
public static var postgresDataType: PostgresDataType {
104111
fatalError("PostgresData cannot be statically represented as a single data type")

Sources/PostgresNIO/Data/PostgresDataConvertible.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
@available(*, deprecated, message: "This protocol is going to be replaced with ``PostgresEncodable`` and ``PostgresDecodable``")
34
public protocol PostgresDataConvertible {
45
static var postgresDataType: PostgresDataType { get }
56
init?(postgresData: PostgresData)

Sources/PostgresNIO/Data/PostgresRow.swift

+2
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ extension PostgresRandomAccessRow {
265265
// MARK: Deprecated API
266266

267267
extension PostgresRow {
268+
@available(*, deprecated, message: "Will be removed from public API.")
268269
public var rowDescription: PostgresMessage.RowDescription {
269270
let fields = self.columns.map { column in
270271
PostgresMessage.RowDescription.Field(
@@ -280,6 +281,7 @@ extension PostgresRow {
280281
return PostgresMessage.RowDescription(fields: fields)
281282
}
282283

284+
@available(*, deprecated, message: "Iterate the cells on `PostgresRow` instead.")
283285
public var dataRow: PostgresMessage.DataRow {
284286
let columns = self.data.map {
285287
PostgresMessage.DataRow.Column(value: $0)

Sources/PostgresNIO/Deprecated/PostgresMessage+SASLResponse.swift

+29-25
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,13 @@ extension PostgresMessage {
3030

3131
extension PostgresMessage {
3232
/// SASL initial challenge response message sent by the client.
33-
public struct SASLInitialResponse: PostgresMessageType {
34-
public static var identifier: PostgresMessage.Identifier {
35-
return .saslInitialResponse
36-
}
37-
33+
@available(*, deprecated, message: "Will be removed from public API")
34+
public struct SASLInitialResponse {
3835
public let mechanism: String
3936
public let initialData: [UInt8]
4037

41-
public static func parse(from buffer: inout ByteBuffer) throws -> PostgresMessage.SASLInitialResponse {
42-
guard let mechanism = buffer.readNullTerminatedString() else {
43-
throw PostgresError.protocol("Could not parse SASL mechanism from initial response message")
44-
}
45-
guard let dataLength = buffer.readInteger(as: Int32.self) else {
46-
throw PostgresError.protocol("Could not parse SASL initial data length from initial response message")
47-
}
48-
49-
var actualData: [UInt8] = []
50-
51-
if dataLength != -1 {
52-
guard let data = buffer.readBytes(length: Int(dataLength)) else {
53-
throw PostgresError.protocol("Could not parse SASL initial data from initial response message")
54-
}
55-
actualData = data
56-
}
57-
return SASLInitialResponse(mechanism: mechanism, initialData: actualData)
58-
}
59-
6038
public func serialize(into buffer: inout ByteBuffer) throws {
61-
buffer.writeNullTerminatedString(mechanism)
39+
buffer.writeNullTerminatedString(self.mechanism)
6240
if initialData.count > 0 {
6341
buffer.writeInteger(Int32(initialData.count), as: Int32.self) // write(array:) writes Int16, which is incorrect here
6442
buffer.writeBytes(initialData)
@@ -72,3 +50,29 @@ extension PostgresMessage {
7250
}
7351
}
7452
}
53+
54+
@available(*, deprecated, message: "Deprecating conformance to `PostgresMessageType` since it is deprecated.")
55+
extension PostgresMessage.SASLInitialResponse: PostgresMessageType {
56+
public static var identifier: PostgresMessage.Identifier {
57+
return .saslInitialResponse
58+
}
59+
60+
public static func parse(from buffer: inout ByteBuffer) throws -> Self {
61+
guard let mechanism = buffer.readNullTerminatedString() else {
62+
throw PostgresError.protocol("Could not parse SASL mechanism from initial response message")
63+
}
64+
guard let dataLength = buffer.readInteger(as: Int32.self) else {
65+
throw PostgresError.protocol("Could not parse SASL initial data length from initial response message")
66+
}
67+
68+
var actualData: [UInt8] = []
69+
70+
if dataLength != -1 {
71+
guard let data = buffer.readBytes(length: Int(dataLength)) else {
72+
throw PostgresError.protocol("Could not parse SASL initial data from initial response message")
73+
}
74+
actualData = data
75+
}
76+
return .init(mechanism: mechanism, initialData: actualData)
77+
}
78+
}

Sources/PostgresNIO/Docs.docc/index.md

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Features:
4545
- ``PostgresJSONEncoder``
4646
- ``PostgresJSONDecoder``
4747
- ``PostgresDataType``
48+
- ``PostgresFormat``
4849
- ``PostgresNumeric``
4950

5051
### Notifications
@@ -72,8 +73,11 @@ removed from the public API with the next major release.
7273
- ``PostgresRequest``
7374
- ``PostgresMessage``
7475
- ``PostgresMessageType``
76+
- ``PostgresFormatCode``
7577
- ``SASLAuthenticationManager``
7678
- ``SASLAuthenticationMechanism``
79+
- ``SASLAuthenticationError``
80+
- ``SASLAuthenticationStepResult``
7781

7882
[SwiftNIO]: https://github.com/apple/swift-nio
7983
[SwiftLog]: https://github.com/apple/swift-log

Sources/PostgresNIO/Message/PostgresMessage+0.swift

+3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import NIOCore
22

33
/// A frontend or backend Postgres message.
44
public struct PostgresMessage: Equatable {
5+
@available(*, deprecated, message: "Will be removed from public API.")
56
public var identifier: Identifier
67
public var data: ByteBuffer
78

9+
@available(*, deprecated, message: "Will be removed from public API.")
810
public init<Data>(identifier: Identifier, bytes: Data)
911
where Data: Sequence, Data.Element == UInt8
1012
{
@@ -13,6 +15,7 @@ public struct PostgresMessage: Equatable {
1315
self.init(identifier: identifier, data: buffer)
1416
}
1517

18+
@available(*, deprecated, message: "Will be removed from public API.")
1619
public init(identifier: Identifier, data: ByteBuffer) {
1720
self.identifier = identifier
1821
self.data = data

Sources/PostgresNIO/Message/PostgresMessage+BackendKeyData.swift

+19-16
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@ import NIOCore
33
extension PostgresMessage {
44
/// Identifies the message as cancellation key data.
55
/// The frontend must save these values if it wishes to be able to issue CancelRequest messages later.
6-
public struct BackendKeyData: PostgresMessageType {
7-
public static var identifier: PostgresMessage.Identifier {
8-
.backendKeyData
9-
}
10-
11-
/// Parses an instance of this message type from a byte buffer.
12-
public static func parse(from buffer: inout ByteBuffer) throws -> BackendKeyData {
13-
guard let processID = buffer.readInteger(as: Int32.self) else {
14-
throw PostgresError.protocol("Could not parse process id from backend key data")
15-
}
16-
guard let secretKey = buffer.readInteger(as: Int32.self) else {
17-
throw PostgresError.protocol("Could not parse secret key from backend key data")
18-
}
19-
return .init(processID: processID, secretKey: secretKey)
20-
}
21-
6+
public struct BackendKeyData {
227
/// The process ID of this backend.
238
public var processID: Int32
249

2510
/// The secret key of this backend.
2611
public var secretKey: Int32
2712
}
2813
}
14+
15+
@available(*, deprecated, message: "Deprecating conformance to `PostgresMessageType` since it is deprecated.")
16+
extension PostgresMessage.BackendKeyData: PostgresMessageType {
17+
public static var identifier: PostgresMessage.Identifier {
18+
.backendKeyData
19+
}
20+
21+
/// Parses an instance of this message type from a byte buffer.
22+
public static func parse(from buffer: inout ByteBuffer) throws -> Self {
23+
guard let processID = buffer.readInteger(as: Int32.self) else {
24+
throw PostgresError.protocol("Could not parse process id from backend key data")
25+
}
26+
guard let secretKey = buffer.readInteger(as: Int32.self) else {
27+
throw PostgresError.protocol("Could not parse secret key from backend key data")
28+
}
29+
return .init(processID: processID, secretKey: secretKey)
30+
}
31+
}

0 commit comments

Comments
 (0)