Skip to content

Commit 495dec9

Browse files
authored
Make PostgresEncodingContext & PostgresDecodingContext public (#243)
1 parent ef425af commit 495dec9

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

Sources/PostgresNIO/New/PostgresCodable.swift

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,47 @@ extension PostgresEncodable {
8989
}
9090
}
9191

92-
struct PostgresEncodingContext<JSONEncoder: PostgresJSONEncoder> {
93-
let jsonEncoder: JSONEncoder
92+
/// A context that is passed to Swift objects that are encoded into the Postgres wire format. Used
93+
/// to pass further information to the encoding method.
94+
public struct PostgresEncodingContext<JSONEncoder: PostgresJSONEncoder> {
95+
/// A ``PostgresJSONEncoder`` used to encode the object to json.
96+
public var jsonEncoder: JSONEncoder
9497

95-
init(jsonEncoder: JSONEncoder) {
98+
99+
/// Creates a ``PostgresEncodingContext`` with the given ``PostgresJSONEncoder``. In case you want
100+
/// to use the a ``PostgresEncodingContext`` with an unconfigured Foundation `JSONEncoder`
101+
/// you can use the ``default`` context instead.
102+
///
103+
/// - Parameter jsonEncoder: A ``PostgresJSONEncoder`` to use when encoding objects to json
104+
public init(jsonEncoder: JSONEncoder) {
96105
self.jsonEncoder = jsonEncoder
97106
}
98107
}
99108

100109
extension PostgresEncodingContext where JSONEncoder == Foundation.JSONEncoder {
101-
static let `default` = PostgresEncodingContext(jsonEncoder: JSONEncoder())
110+
/// A default ``PostgresEncodingContext`` that uses a Foundation `JSONEncoder`.
111+
public static let `default` = PostgresEncodingContext(jsonEncoder: JSONEncoder())
102112
}
103113

104-
struct PostgresDecodingContext<JSONDecoder: PostgresJSONDecoder> {
105-
let jsonDecoder: JSONDecoder
106-
107-
init(jsonDecoder: JSONDecoder) {
114+
/// A context that is passed to Swift objects that are decoded from the Postgres wire format. Used
115+
/// to pass further information to the decoding method.
116+
public struct PostgresDecodingContext<JSONDecoder: PostgresJSONDecoder> {
117+
/// A ``PostgresJSONDecoder`` used to decode the object from json.
118+
public var jsonDecoder: JSONDecoder
119+
120+
/// Creates a ``PostgresDecodingContext`` with the given ``PostgresJSONDecoder``. In case you want
121+
/// to use the a ``PostgresDecodingContext`` with an unconfigured Foundation `JSONDecoder`
122+
/// you can use the ``default`` context instead.
123+
///
124+
/// - Parameter jsonDecoder: A ``PostgresJSONDecoder`` to use when decoding objects from json
125+
public init(jsonDecoder: JSONDecoder) {
108126
self.jsonDecoder = jsonDecoder
109127
}
110128
}
111129

112130
extension PostgresDecodingContext where JSONDecoder == Foundation.JSONDecoder {
113-
static let `default` = PostgresDecodingContext(jsonDecoder: Foundation.JSONDecoder())
131+
/// A default ``PostgresDecodingContext`` that uses a Foundation `JSONDecoder`.
132+
public static let `default` = PostgresDecodingContext(jsonDecoder: Foundation.JSONDecoder())
114133
}
115134

116135
extension Optional: PostgresDecodable where Wrapped: PostgresDecodable, Wrapped._DecodableType == Wrapped {

0 commit comments

Comments
 (0)