Hide package API
This commit is contained in:
@@ -13,10 +13,7 @@ let package = Package(
|
||||
.library(name: "DataLiteCoder", targets: ["DataLiteCoder"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(
|
||||
url: "https://github.com/angd-dev/data-lite-core.git",
|
||||
revision: "2b3ba846b06f865616787edfdb47f503317a0dc0"
|
||||
),
|
||||
.package(url: "https://github.com/angd-dev/data-lite-core.git", from: "1.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
|
||||
],
|
||||
targets: [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
public extension SQLiteRow {
|
||||
package extension SQLiteRow {
|
||||
func contains(_ key: CodingKey) -> Bool {
|
||||
if let index = key.intValue {
|
||||
0..<count ~= index
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import Foundation
|
||||
|
||||
public struct RowCodingKey: CodingKey, Equatable {
|
||||
package struct RowCodingKey: CodingKey, Equatable {
|
||||
// MARK: - Properties
|
||||
|
||||
public let stringValue: String
|
||||
public let intValue: Int?
|
||||
package let stringValue: String
|
||||
package let intValue: Int?
|
||||
|
||||
// MARK: - Inits
|
||||
|
||||
public init(stringValue: String) {
|
||||
package init(stringValue: String) {
|
||||
self.stringValue = stringValue
|
||||
self.intValue = nil
|
||||
}
|
||||
|
||||
public init(intValue: Int) {
|
||||
package init(intValue: Int) {
|
||||
self.stringValue = "Index \(intValue)"
|
||||
self.intValue = intValue
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
public final class MultiRowDecoder: RowDecoder {
|
||||
package final class MultiRowDecoder: RowDecoder {
|
||||
// MARK: - Properties
|
||||
|
||||
public let dateDecoder: any DateDecoder
|
||||
public let sqliteData: [SQLiteRow]
|
||||
public let codingPath: [any CodingKey]
|
||||
public let userInfo: [CodingUserInfoKey: Any]
|
||||
package let dateDecoder: any DateDecoder
|
||||
package let sqliteData: [SQLiteRow]
|
||||
package let codingPath: [any CodingKey]
|
||||
package let userInfo: [CodingUserInfoKey: Any]
|
||||
|
||||
public var count: Int? { sqliteData.count }
|
||||
package var count: Int? { sqliteData.count }
|
||||
|
||||
// MARK: Inits
|
||||
|
||||
public init(
|
||||
package init(
|
||||
dateDecoder: any DateDecoder,
|
||||
sqliteData: [SQLiteRow],
|
||||
codingPath: [any CodingKey],
|
||||
@@ -27,7 +27,7 @@ public final class MultiRowDecoder: RowDecoder {
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
public func decodeNil(for key: any CodingKey) throws -> Bool {
|
||||
package func decodeNil(for key: any CodingKey) throws -> Bool {
|
||||
let info = "Attempted to decode nil, but it's not supported for an array of rows."
|
||||
let context = DecodingError.Context(
|
||||
codingPath: codingPath + [key],
|
||||
@@ -36,11 +36,11 @@ public final class MultiRowDecoder: RowDecoder {
|
||||
throw DecodingError.dataCorrupted(context)
|
||||
}
|
||||
|
||||
public func decodeDate(for key: any CodingKey) throws -> Date {
|
||||
package func decodeDate(for key: any CodingKey) throws -> Date {
|
||||
return try decode(Date.self, for: key)
|
||||
}
|
||||
|
||||
public func decode<T: SQLiteRepresentable>(
|
||||
package func decode<T: SQLiteRepresentable>(
|
||||
_ type: T.Type,
|
||||
for key: any CodingKey
|
||||
) throws -> T {
|
||||
@@ -52,7 +52,7 @@ public final class MultiRowDecoder: RowDecoder {
|
||||
throw DecodingError.typeMismatch(type, context)
|
||||
}
|
||||
|
||||
public func decoder(for key: any CodingKey) throws -> any Decoder {
|
||||
package func decoder(for key: any CodingKey) throws -> any Decoder {
|
||||
guard let index = key.intValue else {
|
||||
let info = "Expected an integer key, but found a non-integer key."
|
||||
let context = DecodingError.Context(
|
||||
@@ -69,7 +69,7 @@ public final class MultiRowDecoder: RowDecoder {
|
||||
)
|
||||
}
|
||||
|
||||
public func container<Key: CodingKey>(
|
||||
package func container<Key: CodingKey>(
|
||||
keyedBy type: Key.Type
|
||||
) throws -> KeyedDecodingContainer<Key> {
|
||||
let info = "Expected a keyed container, but found an array of rows."
|
||||
@@ -83,14 +83,14 @@ public final class MultiRowDecoder: RowDecoder {
|
||||
)
|
||||
}
|
||||
|
||||
public func unkeyedContainer() throws -> any UnkeyedDecodingContainer {
|
||||
package func unkeyedContainer() throws -> any UnkeyedDecodingContainer {
|
||||
UnkeyedContainer(
|
||||
decoder: self,
|
||||
codingPath: codingPath
|
||||
)
|
||||
}
|
||||
|
||||
public func singleValueContainer() throws -> any SingleValueDecodingContainer {
|
||||
package func singleValueContainer() throws -> any SingleValueDecodingContainer {
|
||||
let info = "Expected a single value container, but found an array of rows."
|
||||
let context = DecodingError.Context(
|
||||
codingPath: codingPath,
|
||||
|
||||
@@ -3,19 +3,19 @@ import DataLiteCore
|
||||
|
||||
private import DLCCommon
|
||||
|
||||
public final class SingleRowDecoder: RowDecoder, KeyCheckingDecoder {
|
||||
package final class SingleRowDecoder: RowDecoder, KeyCheckingDecoder {
|
||||
// MARK: - Properties
|
||||
|
||||
public let dateDecoder: any DateDecoder
|
||||
public let sqliteData: SQLiteRow
|
||||
public let codingPath: [any CodingKey]
|
||||
public let userInfo: [CodingUserInfoKey: Any]
|
||||
package let dateDecoder: any DateDecoder
|
||||
package let sqliteData: SQLiteRow
|
||||
package let codingPath: [any CodingKey]
|
||||
package let userInfo: [CodingUserInfoKey: Any]
|
||||
|
||||
public var count: Int? { sqliteData.count }
|
||||
package var count: Int? { sqliteData.count }
|
||||
|
||||
// MARK: Inits
|
||||
|
||||
public init(
|
||||
package init(
|
||||
dateDecoder: any DateDecoder,
|
||||
sqliteData: SQLiteRow,
|
||||
codingPath: [any CodingKey],
|
||||
@@ -29,11 +29,11 @@ public final class SingleRowDecoder: RowDecoder, KeyCheckingDecoder {
|
||||
|
||||
// MARK: - Methods
|
||||
|
||||
public func contains(_ key: any CodingKey) -> Bool {
|
||||
package func contains(_ key: any CodingKey) -> Bool {
|
||||
sqliteData.contains(key)
|
||||
}
|
||||
|
||||
public func decodeNil(for key: any CodingKey) throws -> Bool {
|
||||
package func decodeNil(for key: any CodingKey) throws -> Bool {
|
||||
guard sqliteData.contains(key) else {
|
||||
let info = "No value associated with key \(key)."
|
||||
let context = DecodingError.Context(
|
||||
@@ -45,11 +45,11 @@ public final class SingleRowDecoder: RowDecoder, KeyCheckingDecoder {
|
||||
return sqliteData[key] == .null
|
||||
}
|
||||
|
||||
public func decodeDate(for key: any CodingKey) throws -> Date {
|
||||
package func decodeDate(for key: any CodingKey) throws -> Date {
|
||||
try dateDecoder.decode(from: self, for: key)
|
||||
}
|
||||
|
||||
public func decode<T: SQLiteRepresentable>(
|
||||
package func decode<T: SQLiteRepresentable>(
|
||||
_ type: T.Type,
|
||||
for key: any CodingKey
|
||||
) throws -> T {
|
||||
@@ -83,7 +83,7 @@ public final class SingleRowDecoder: RowDecoder, KeyCheckingDecoder {
|
||||
return result
|
||||
}
|
||||
|
||||
public func decoder(for key: any CodingKey) throws -> any Decoder {
|
||||
package func decoder(for key: any CodingKey) throws -> any Decoder {
|
||||
guard let data = sqliteData[key] else {
|
||||
let info = "No value associated with key \(key)."
|
||||
let context = DecodingError.Context(
|
||||
@@ -100,7 +100,7 @@ public final class SingleRowDecoder: RowDecoder, KeyCheckingDecoder {
|
||||
)
|
||||
}
|
||||
|
||||
public func container<Key: CodingKey>(
|
||||
package func container<Key: CodingKey>(
|
||||
keyedBy type: Key.Type
|
||||
) throws -> KeyedDecodingContainer<Key> {
|
||||
let allKeys = sqliteData.compactMap { (column, _) in
|
||||
@@ -114,14 +114,14 @@ public final class SingleRowDecoder: RowDecoder, KeyCheckingDecoder {
|
||||
return KeyedDecodingContainer(container)
|
||||
}
|
||||
|
||||
public func unkeyedContainer() throws -> any UnkeyedDecodingContainer {
|
||||
package func unkeyedContainer() throws -> any UnkeyedDecodingContainer {
|
||||
UnkeyedContainer(
|
||||
decoder: self,
|
||||
codingPath: codingPath
|
||||
)
|
||||
}
|
||||
|
||||
public func singleValueContainer() throws -> any SingleValueDecodingContainer {
|
||||
package func singleValueContainer() throws -> any SingleValueDecodingContainer {
|
||||
let info = "Expected a single value container, but found a row value."
|
||||
let context = DecodingError.Context(
|
||||
codingPath: codingPath,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
public protocol DateDecoder {
|
||||
package protocol DateDecoder {
|
||||
func decode(from decoder: any ValueDecoder) throws -> Date
|
||||
func decode(from decoder: any RowDecoder, for key: any CodingKey) throws -> Date
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
public protocol Decoder: Swift.Decoder {
|
||||
package protocol Decoder: Swift.Decoder {
|
||||
associatedtype SQLiteData
|
||||
|
||||
var dateDecoder: any DateDecoder { get }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Foundation
|
||||
|
||||
public protocol KeyCheckingDecoder: Decoder {
|
||||
package protocol KeyCheckingDecoder: Decoder {
|
||||
func contains(_ key: CodingKey) -> Bool
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
public protocol RowDecoder: Decoder {
|
||||
package protocol RowDecoder: Decoder {
|
||||
var count: Int? { get }
|
||||
|
||||
func decodeNil(for key: CodingKey) throws -> Bool
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
public protocol ValueDecoder: Decoder {
|
||||
package protocol ValueDecoder: Decoder {
|
||||
func decodeNil() -> Bool
|
||||
func decodeDate() throws -> Date
|
||||
func decode<T: SQLiteRepresentable>(_ type: T.Type) throws -> T
|
||||
|
||||
@@ -3,20 +3,20 @@ import DataLiteCore
|
||||
|
||||
private import DLCCommon
|
||||
|
||||
public final class MultiRowEncoder: RowEncoder {
|
||||
package final class MultiRowEncoder: RowEncoder {
|
||||
// MARK: - Properties
|
||||
|
||||
public let dateEncoder: any DateEncoder
|
||||
public let codingPath: [any CodingKey]
|
||||
public let userInfo: [CodingUserInfoKey : Any]
|
||||
package let dateEncoder: any DateEncoder
|
||||
package let codingPath: [any CodingKey]
|
||||
package let userInfo: [CodingUserInfoKey : Any]
|
||||
|
||||
public private(set) var sqliteData = [SQLiteRow]()
|
||||
package private(set) var sqliteData = [SQLiteRow]()
|
||||
|
||||
public var count: Int { sqliteData.count }
|
||||
package var count: Int { sqliteData.count }
|
||||
|
||||
// MARK: - Inits
|
||||
|
||||
public init(
|
||||
package init(
|
||||
dateEncoder: any DateEncoder,
|
||||
codingPath: [any CodingKey],
|
||||
userInfo: [CodingUserInfoKey : Any]
|
||||
@@ -28,7 +28,7 @@ public final class MultiRowEncoder: RowEncoder {
|
||||
|
||||
// MARK: - Methods
|
||||
|
||||
public func set(_ value: Any, for key: any CodingKey) throws {
|
||||
package func set(_ value: Any, for key: any CodingKey) throws {
|
||||
guard let value = value as? SQLiteRow else {
|
||||
let info = "Expected value of type \(SQLiteRow.self)"
|
||||
let context = EncodingError.Context(
|
||||
@@ -40,7 +40,7 @@ public final class MultiRowEncoder: RowEncoder {
|
||||
sqliteData.append(value)
|
||||
}
|
||||
|
||||
public func encodeNil(for key: any CodingKey) throws {
|
||||
package func encodeNil(for key: any CodingKey) throws {
|
||||
let value = Optional<Any>.none as Any
|
||||
let info = "Attempted to encode nil, but it's not supported."
|
||||
let context = EncodingError.Context(
|
||||
@@ -50,7 +50,7 @@ public final class MultiRowEncoder: RowEncoder {
|
||||
throw EncodingError.invalidValue(value, context)
|
||||
}
|
||||
|
||||
public func encodeDate(_ date: Date, for key: any CodingKey) throws {
|
||||
package func encodeDate(_ date: Date, for key: any CodingKey) throws {
|
||||
let info = "Attempted to encode Date, but it's not supported."
|
||||
let context = EncodingError.Context(
|
||||
codingPath: codingPath + [key],
|
||||
@@ -59,7 +59,7 @@ public final class MultiRowEncoder: RowEncoder {
|
||||
throw EncodingError.invalidValue(date, context)
|
||||
}
|
||||
|
||||
public func encode<T: SQLiteBindable>(_ value: T, for key: any CodingKey) throws {
|
||||
package func encode<T: SQLiteBindable>(_ value: T, for key: any CodingKey) throws {
|
||||
let info = "Attempted to encode \(T.self), but it's not supported."
|
||||
let context = EncodingError.Context(
|
||||
codingPath: codingPath + [key],
|
||||
@@ -68,7 +68,7 @@ public final class MultiRowEncoder: RowEncoder {
|
||||
throw EncodingError.invalidValue(value, context)
|
||||
}
|
||||
|
||||
public func encoder(for key: any CodingKey) throws -> any Encoder {
|
||||
package func encoder(for key: any CodingKey) throws -> any Encoder {
|
||||
SingleRowEncoder(
|
||||
dateEncoder: dateEncoder,
|
||||
codingPath: codingPath + [key],
|
||||
@@ -76,7 +76,7 @@ public final class MultiRowEncoder: RowEncoder {
|
||||
)
|
||||
}
|
||||
|
||||
public func container<Key: CodingKey>(
|
||||
package func container<Key: CodingKey>(
|
||||
keyedBy type: Key.Type
|
||||
) -> KeyedEncodingContainer<Key> {
|
||||
let container = FailedEncodingContainer<Key>(
|
||||
@@ -85,11 +85,11 @@ public final class MultiRowEncoder: RowEncoder {
|
||||
return KeyedEncodingContainer(container)
|
||||
}
|
||||
|
||||
public func unkeyedContainer() -> any UnkeyedEncodingContainer {
|
||||
package func unkeyedContainer() -> any UnkeyedEncodingContainer {
|
||||
UnkeyedContainer(encoder: self, codingPath: codingPath)
|
||||
}
|
||||
|
||||
public func singleValueContainer() -> any SingleValueEncodingContainer {
|
||||
package func singleValueContainer() -> any SingleValueEncodingContainer {
|
||||
FailedEncodingContainer<RowCodingKey>(codingPath: codingPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,20 @@ import DataLiteCore
|
||||
|
||||
private import DLCCommon
|
||||
|
||||
public final class SingleRowEncoder: RowEncoder {
|
||||
package final class SingleRowEncoder: RowEncoder {
|
||||
// MARK: - Properties
|
||||
|
||||
public let dateEncoder: any DateEncoder
|
||||
public let codingPath: [any CodingKey]
|
||||
public let userInfo: [CodingUserInfoKey : Any]
|
||||
package let dateEncoder: any DateEncoder
|
||||
package let codingPath: [any CodingKey]
|
||||
package let userInfo: [CodingUserInfoKey : Any]
|
||||
|
||||
public private(set) var sqliteData = SQLiteRow()
|
||||
package private(set) var sqliteData = SQLiteRow()
|
||||
|
||||
public var count: Int { sqliteData.count }
|
||||
package var count: Int { sqliteData.count }
|
||||
|
||||
// MARK: - Inits
|
||||
|
||||
public init(
|
||||
package init(
|
||||
dateEncoder: any DateEncoder,
|
||||
codingPath: [any CodingKey],
|
||||
userInfo: [CodingUserInfoKey : Any],
|
||||
@@ -28,7 +28,7 @@ public final class SingleRowEncoder: RowEncoder {
|
||||
|
||||
// MARK: - Methods
|
||||
|
||||
public func set(_ value: Any, for key: any CodingKey) throws {
|
||||
package func set(_ value: Any, for key: any CodingKey) throws {
|
||||
guard let value = value as? SQLiteValue else {
|
||||
let info = "The value does not match \(SQLiteValue.self)"
|
||||
let context = EncodingError.Context(
|
||||
@@ -40,19 +40,19 @@ public final class SingleRowEncoder: RowEncoder {
|
||||
sqliteData[key] = value
|
||||
}
|
||||
|
||||
public func encodeNil(for key: any CodingKey) throws {
|
||||
package func encodeNil(for key: any CodingKey) throws {
|
||||
sqliteData[key] = .null
|
||||
}
|
||||
|
||||
public func encodeDate(_ date: Date, for key: any CodingKey) throws {
|
||||
package func encodeDate(_ date: Date, for key: any CodingKey) throws {
|
||||
try dateEncoder.encode(date, for: key, to: self)
|
||||
}
|
||||
|
||||
public func encode<T: SQLiteBindable>(_ value: T, for key: any CodingKey) throws {
|
||||
package func encode<T: SQLiteBindable>(_ value: T, for key: any CodingKey) throws {
|
||||
sqliteData[key] = value.sqliteValue
|
||||
}
|
||||
|
||||
public func encoder(for key: any CodingKey) throws -> any Encoder {
|
||||
package func encoder(for key: any CodingKey) throws -> any Encoder {
|
||||
SingleValueEncoder(
|
||||
dateEncoder: dateEncoder,
|
||||
codingPath: codingPath + [key],
|
||||
@@ -60,7 +60,7 @@ public final class SingleRowEncoder: RowEncoder {
|
||||
)
|
||||
}
|
||||
|
||||
public func container<Key: CodingKey>(
|
||||
package func container<Key: CodingKey>(
|
||||
keyedBy type: Key.Type
|
||||
) -> KeyedEncodingContainer<Key> {
|
||||
let container = KeyedContainer<SingleRowEncoder, Key>(
|
||||
@@ -69,11 +69,11 @@ public final class SingleRowEncoder: RowEncoder {
|
||||
return KeyedEncodingContainer(container)
|
||||
}
|
||||
|
||||
public func unkeyedContainer() -> any UnkeyedEncodingContainer {
|
||||
package func unkeyedContainer() -> any UnkeyedEncodingContainer {
|
||||
FailedEncodingContainer<RowCodingKey>(codingPath: codingPath)
|
||||
}
|
||||
|
||||
public func singleValueContainer() -> any SingleValueEncodingContainer {
|
||||
package func singleValueContainer() -> any SingleValueEncodingContainer {
|
||||
FailedEncodingContainer<RowCodingKey>(codingPath: codingPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
public protocol DateEncoder {
|
||||
package protocol DateEncoder {
|
||||
func encode(_ date: Date, to encoder: any ValueEncoder) throws
|
||||
func encode(_ date: Date, for key: any CodingKey, to encoder: any RowEncoder) throws
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
public protocol Encoder: Swift.Encoder {
|
||||
package protocol Encoder: Swift.Encoder {
|
||||
associatedtype SQLiteData
|
||||
|
||||
var dateEncoder: any DateEncoder { get }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
public protocol RowEncoder: Encoder {
|
||||
package protocol RowEncoder: Encoder {
|
||||
var count: Int { get }
|
||||
|
||||
func set(_ value: Any, for key: CodingKey) throws
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
public protocol ValueEncoder: Encoder {
|
||||
package protocol ValueEncoder: Encoder {
|
||||
func encodeNil() throws
|
||||
func encodeDate(_ date: Date) throws
|
||||
func encode<T: SQLiteBindable>(_ value: T) throws
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
|
||||
internal import DLCDecoder
|
||||
|
||||
extension RowDecoder {
|
||||
|
||||
Reference in New Issue
Block a user