Enable upcoming feature ExistentialAny in Swift 5.9

This commit is contained in:
Gwendal Roué committed 2023-11-02 16:28:49 +01:00
1 parent 7eaf67fb6a
commit fc10db84fe
47 files changed
+264 -188

No files matched your search

@@ -27,7 +27,7 @@ struct PlayerRequest: Queryable {
static var defaultValue: [Player] { [] }
func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], Error> {
func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], any Error> {
// Build the publisher from the general-purpose read-only access
// granted by `appDatabase.reader`.
// Some apps will prefer to call a dedicated method of `appDatabase`.
@@ -27,7 +27,7 @@ struct PlayerRequest: Queryable {
static var defaultValue: [Player] { [] }
func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], Error> {
func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], any Error> {
// Build the publisher from the general-purpose read-only access
// granted by `appDatabase.reader`.
// Some apps will prefer to call a dedicated method of `appDatabase`.
+3 -3
View File
@@ -308,7 +308,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
///
/// Invariant: `transactionDateResult` is nil iff connection is not
/// inside a transaction.
var transactionDateResult: Result<Date, Error>?
var transactionDateResult: Result<Date, any Error>?
/// The date of the current transaction.
///
@@ -1209,7 +1209,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
// Now that transaction has begun, we'll rollback in case of error.
// But we'll throw the first caught error, so that user knows
// what happened.
var firstError: Error? = nil
var firstError: (any Error)? = nil
let needsRollback: Bool
do {
let completion = try operations()
@@ -1353,7 +1353,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
// Now that savepoint has begun, we'll rollback in case of error.
// But we'll throw the first caught error, so that user knows
// what happened.
var firstError: Error? = nil
var firstError: (any Error)? = nil
let needsRollback: Bool
do {
let completion = try operations()
+1 -1
View File
@@ -186,7 +186,7 @@ extension ResultCode {
/// // any other database error
/// }
/// ```
public static func ~= (lhs: Self, rhs: Error) -> Bool {
public static func ~= (lhs: Self, rhs: any Error) -> Bool {
guard let error = rhs as? DatabaseError else { return false }
return lhs ~= error.extendedResultCode
}
+1 -1
View File
@@ -403,7 +403,7 @@ public final class DatabaseFunction: Hashable {
}
}
private static func report(error: Error, in sqliteContext: OpaquePointer?) {
private static func report(error: some Error, in sqliteContext: OpaquePointer?) {
if let error = error as? DatabaseError {
if let message = error.message {
sqlite3_result_error(sqliteContext, message, -1)
+8 -8
View File
@@ -14,7 +14,7 @@ public final class DatabasePool {
@LockedBox var databaseSnapshotCount = 0
/// If Database Suspension is enabled, this array contains the necessary `NotificationCenter` observers.
private var suspensionObservers: [NSObjectProtocol] = []
private var suspensionObservers: [any NSObjectProtocol] = []
// MARK: - Database Information
@@ -357,7 +357,7 @@ extension DatabasePool: DatabaseReader {
}
}
public func asyncRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
guard let readerPool else {
value(.failure(DatabaseError.connectionIsClosed()))
return
@@ -401,7 +401,7 @@ extension DatabasePool: DatabaseReader {
}
}
public func asyncUnsafeRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncUnsafeRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
guard let readerPool else {
value(.failure(DatabaseError.connectionIsClosed()))
return
@@ -449,7 +449,7 @@ extension DatabasePool: DatabaseReader {
public func concurrentRead<T>(_ value: @escaping (Database) throws -> T) -> DatabaseFuture<T> {
// The semaphore that blocks until futureResult is defined:
let futureSemaphore = DispatchSemaphore(value: 0)
var futureResult: Result<T, Error>? = nil
var futureResult: Result<T, any Error>? = nil
asyncConcurrentRead { dbResult in
// Fetch and release the future
@@ -464,7 +464,7 @@ extension DatabasePool: DatabaseReader {
}
}
public func spawnConcurrentRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func spawnConcurrentRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
asyncConcurrentRead(value)
}
@@ -505,7 +505,7 @@ extension DatabasePool: DatabaseReader {
/// ```
///
/// - parameter value: A function that accesses the database.
public func asyncConcurrentRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncConcurrentRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
// Check that we're on the writer queue...
writer.execute { db in
// ... and that no transaction is opened.
@@ -665,7 +665,7 @@ extension DatabasePool: DatabaseReader {
///
/// - important: The `completion` argument is executed in a serial
/// dispatch queue, so make sure you use the transaction asynchronously.
func asyncWALSnapshotTransaction(_ completion: @escaping (Result<WALSnapshotTransaction, Error>) -> Void) {
func asyncWALSnapshotTransaction(_ completion: @escaping (Result<WALSnapshotTransaction, any Error>) -> Void) {
guard let readerPool else {
completion(.failure(DatabaseError.connectionIsClosed()))
return
@@ -756,7 +756,7 @@ extension DatabasePool: DatabaseWriter {
}
}
public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result<Database, Error>) -> Void) {
public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result<Database, any Error>) -> Void) {
guard let readerPool else {
updates(.failure(DatabaseError.connectionIsClosed()))
return
+5 -5
View File
@@ -8,7 +8,7 @@ public final class DatabaseQueue {
private let writer: SerializedDatabase
/// If Database Suspension is enabled, this array contains the necessary `NotificationCenter` observers.
private var suspensionObservers: [NSObjectProtocol] = []
private var suspensionObservers: [any NSObjectProtocol] = []
// MARK: - Configuration
@@ -233,7 +233,7 @@ extension DatabaseQueue: DatabaseReader {
}
}
public func asyncRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
writer.async { db in
defer {
// Ignore error because we can not notify it.
@@ -258,7 +258,7 @@ extension DatabaseQueue: DatabaseReader {
try writer.sync(value)
}
public func asyncUnsafeRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncUnsafeRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
writer.async { value(.success($0)) }
}
@@ -279,7 +279,7 @@ extension DatabaseQueue: DatabaseReader {
})
}
public func spawnConcurrentRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func spawnConcurrentRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
// Check that we're on the writer queue...
writer.execute { db in
// ... and that no transaction is opened.
@@ -379,7 +379,7 @@ extension DatabaseQueue: DatabaseWriter {
try writer.sync(updates)
}
public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result<Database, Error>) -> Void) {
public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result<Database, any Error>) -> Void) {
writer.async { updates(.success($0)) }
}
+8 -8
View File
@@ -213,7 +213,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
/// - parameter value: A closure which accesses the database. Its argument
/// is a `Result` that provides the database connection, or the failure
/// that would prevent establishing the read access to the database.
func asyncRead(_ value: @escaping (Result<Database, Error>) -> Void)
func asyncRead(_ value: @escaping (Result<Database, any Error>) -> Void)
/// Executes database operations, and returns their result after they have
/// finished executing.
@@ -284,7 +284,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
/// - parameter value: A closure which accesses the database. Its argument
/// is a `Result` that provides the database connection, or the failure
/// that would prevent establishing the read access to the database.
func asyncUnsafeRead(_ value: @escaping (Result<Database, Error>) -> Void)
func asyncUnsafeRead(_ value: @escaping (Result<Database, any Error>) -> Void)
/// Executes database operations, and returns their result after they have
/// finished executing.
@@ -575,9 +575,9 @@ extension DatabasePublishers {
/// You build such a publisher from ``DatabaseReader``.
public struct Read<Output>: Publisher {
public typealias Output = Output
public typealias Failure = Error
public typealias Failure = any Error
fileprivate let upstream: AnyPublisher<Output, Error>
fileprivate let upstream: AnyPublisher<Output, any Error>
public func receive<S>(subscriber: S) where S: Subscriber, Self.Failure == S.Failure, Self.Output == S.Input {
upstream.receive(subscriber: subscriber)
@@ -586,7 +586,7 @@ extension DatabasePublishers {
}
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
extension Publisher where Failure == Error {
extension Publisher where Failure == any Error {
fileprivate func eraseToReadPublisher() -> DatabasePublishers.Read<Output> {
.init(upstream: eraseToAnyPublisher())
}
@@ -677,7 +677,7 @@ extension AnyDatabaseReader: DatabaseReader {
try base.read(value)
}
public func asyncRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
base.asyncRead(value)
}
@@ -686,7 +686,7 @@ extension AnyDatabaseReader: DatabaseReader {
try base.unsafeRead(value)
}
public func asyncUnsafeRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncUnsafeRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
base.asyncUnsafeRead(value)
}
@@ -757,7 +757,7 @@ extension DatabaseSnapshotReader {
}
// There is no such thing as an unsafe access to a snapshot.
public func asyncUnsafeRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncUnsafeRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
asyncRead(value)
}
}
+4 -4
View File
@@ -85,7 +85,7 @@ extension DatabaseRegionObservation {
/// - returns: A DatabaseCancellable that can stop the observation.
public func start(
in writer: some DatabaseWriter,
onError: @escaping (Error) -> Void,
onError: @escaping (any Error) -> Void,
onChange: @escaping (Database) -> Void)
-> AnyDatabaseCancellable
{
@@ -188,7 +188,7 @@ extension DatabasePublishers {
/// You build such a publisher from ``DatabaseRegionObservation``.
public struct DatabaseRegion: Publisher {
public typealias Output = Database
public typealias Failure = Error
public typealias Failure = any Error
let writer: any DatabaseWriter
let observation: DatabaseRegionObservation
@@ -208,7 +208,7 @@ extension DatabasePublishers {
}
private class DatabaseRegionSubscription<Downstream: Subscriber>: Subscription
where Downstream.Failure == Error, Downstream.Input == Database
where Downstream.Failure == any Error, Downstream.Input == Database
{
private struct WaitingForDemand {
let downstream: Downstream
@@ -298,7 +298,7 @@ extension DatabasePublishers {
}
}
private func receive(failure error: Error) {
private func receive(failure error: any Error) {
lock.synchronized {
if case let .observing(info) = state {
state = .finished
+2 -2
View File
@@ -154,7 +154,7 @@ extension DatabaseSnapshot: DatabaseSnapshotReader {
try reader.sync(block)
}
public func asyncRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
reader.async { value(.success($0)) }
}
@@ -162,7 +162,7 @@ extension DatabaseSnapshot: DatabaseSnapshotReader {
try reader.sync(value)
}
public func asyncUnsafeRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncUnsafeRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
reader.async { value(.success($0)) }
}
+1 -1
View File
@@ -292,7 +292,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
}
}
public func asyncRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
guard let readerPool else {
value(.failure(DatabaseError.connectionIsClosed()))
return
+11 -11
View File
@@ -181,7 +181,7 @@ public protocol DatabaseWriter: DatabaseReader {
/// - parameter updates: A closure which accesses the database. Its argument
/// is a `Result` that provides the database connection, or the failure
/// that would prevent establishing the barrier access to the database.
func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result<Database, Error>) -> Void)
func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result<Database, any Error>) -> Void)
/// Schedules database operations for execution, and returns immediately.
///
@@ -340,7 +340,7 @@ public protocol DatabaseWriter: DatabaseReader {
/// - parameter value: A closure which accesses the database. Its argument
/// is a `Result` that provides the database connection, or the failure
/// that would prevent establishing the read access to the database.
func spawnConcurrentRead(_ value: @escaping (Result<Database, Error>) -> Void)
func spawnConcurrentRead(_ value: @escaping (Result<Database, any Error>) -> Void)
}
extension DatabaseWriter {
@@ -427,7 +427,7 @@ extension DatabaseWriter {
/// - parameter completion: A closure called with the transaction result.
public func asyncWrite<T>(
_ updates: @escaping (Database) throws -> T,
completion: @escaping (Database, Result<T, Error>) -> Void)
completion: @escaping (Database, Result<T, any Error>) -> Void)
{
asyncWriteWithoutTransaction { db in
do {
@@ -906,9 +906,9 @@ extension DatabasePublishers {
/// You build such a publisher from ``DatabaseWriter``.
public struct Write<Output>: Publisher {
public typealias Output = Output
public typealias Failure = Error
public typealias Failure = any Error
fileprivate let upstream: AnyPublisher<Output, Error>
fileprivate let upstream: AnyPublisher<Output, any Error>
public func receive<S>(subscriber: S) where S: Subscriber, Self.Failure == S.Failure, Self.Output == S.Input {
upstream.receive(subscriber: subscriber)
@@ -917,7 +917,7 @@ extension DatabasePublishers {
}
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
extension Publisher where Failure == Error {
extension Publisher where Failure == any Error {
fileprivate func eraseToWritePublisher() -> DatabasePublishers.Write<Output> {
.init(upstream: self.eraseToAnyPublisher())
}
@@ -949,7 +949,7 @@ public class DatabaseFuture<Value> {
_wait = wait
}
init(_ result: Result<Value, Error>) {
init(_ result: Result<Value, any Error>) {
_wait = result.get
}
@@ -1003,7 +1003,7 @@ extension AnyDatabaseWriter: DatabaseReader {
try base.read(value)
}
public func asyncRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
base.asyncRead(value)
}
@@ -1012,7 +1012,7 @@ extension AnyDatabaseWriter: DatabaseReader {
try base.unsafeRead(value)
}
public func asyncUnsafeRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func asyncUnsafeRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
base.asyncUnsafeRead(value)
}
@@ -1044,7 +1044,7 @@ extension AnyDatabaseWriter: DatabaseWriter {
try base.barrierWriteWithoutTransaction(updates)
}
public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result<Database, Error>) -> Void) {
public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result<Database, any Error>) -> Void) {
base.asyncBarrierWriteWithoutTransaction(updates)
}
@@ -1060,7 +1060,7 @@ extension AnyDatabaseWriter: DatabaseWriter {
base.concurrentRead(value)
}
public func spawnConcurrentRead(_ value: @escaping (Result<Database, Error>) -> Void) {
public func spawnConcurrentRead(_ value: @escaping (Result<Database, any Error>) -> Void) {
base.spawnConcurrentRead(value)
}
}
@@ -152,7 +152,7 @@ extension DatabaseDateComponents: DatabaseValueConvertible {
}
extension DatabaseDateComponents: Decodable {
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let stringValue = try container.decode(String.self)
guard let decodedValue = DatabaseDateComponents.fromDatabaseValue(stringValue.databaseValue) else {
@@ -164,7 +164,7 @@ extension DatabaseDateComponents: Decodable {
}
extension DatabaseDateComponents: Encodable {
public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(String.fromDatabaseValue(databaseValue)!)
}
@@ -161,12 +161,12 @@ private struct DatabaseValueDecoder: Decoder {
throw JSONRequiredError()
}
func unkeyedContainer() throws -> UnkeyedDecodingContainer {
func unkeyedContainer() throws -> any UnkeyedDecodingContainer {
// We need to switch to JSON decoding
throw JSONRequiredError()
}
func singleValueContainer() throws -> SingleValueDecodingContainer {
func singleValueContainer() throws -> any SingleValueDecodingContainer {
DatabaseValueDecodingContainer(dbValue: dbValue, codingPath: codingPath)
}
}
@@ -92,7 +92,7 @@ private class DatabaseValueEncoder: Encoder {
/// - precondition: May not be called after a prior `self.container(keyedBy:)` call.
/// - precondition: May not be called after a value has been encoded through
/// a previous `self.singleValueContainer()` call.
func unkeyedContainer() -> UnkeyedEncodingContainer {
func unkeyedContainer() -> any UnkeyedEncodingContainer {
// We need to perform JSON encoding. Unfortunately we can't access the
// inner container of Foundation's JSONEncoder. At this point we must
// throw an error so that the caller can retry encoding from scratch.
@@ -109,7 +109,7 @@ private class DatabaseValueEncoder: Encoder {
/// - precondition: May not be called after a prior `self.unkeyedContainer()` call.
/// - precondition: May not be called after a value has been encoded through
/// a previous `self.singleValueContainer()` call.
func singleValueContainer() -> SingleValueEncodingContainer {
func singleValueContainer() -> any SingleValueEncodingContainer {
DatabaseValueEncodingContainer(encode: encode, jsonEncoder: jsonEncoder)
}
@@ -10,9 +10,9 @@ struct JSONRequiredEncoder: Encoder {
return KeyedEncodingContainer(container)
}
func unkeyedContainer() -> UnkeyedEncodingContainer { self }
func unkeyedContainer() -> any UnkeyedEncodingContainer { self }
func singleValueContainer() -> SingleValueEncodingContainer { self }
func singleValueContainer() -> any SingleValueEncodingContainer { self }
struct KeyedContainer<KeyType: CodingKey>: KeyedEncodingContainerProtocol {
var codingPath: [any CodingKey]
@@ -47,15 +47,15 @@ struct JSONRequiredEncoder: Encoder {
return KeyedEncodingContainer(container)
}
func nestedUnkeyedContainer(forKey key: KeyType) -> UnkeyedEncodingContainer {
func nestedUnkeyedContainer(forKey key: KeyType) -> any UnkeyedEncodingContainer {
JSONRequiredEncoder(codingPath: codingPath)
}
func superEncoder() -> Encoder {
func superEncoder() -> any Encoder {
JSONRequiredEncoder(codingPath: codingPath)
}
func superEncoder(forKey key: KeyType) -> Encoder {
func superEncoder(forKey key: KeyType) -> any Encoder {
JSONRequiredEncoder(codingPath: codingPath)
}
}
@@ -91,7 +91,7 @@ extension JSONRequiredEncoder: UnkeyedEncodingContainer {
return KeyedEncodingContainer(container)
}
mutating func nestedUnkeyedContainer() -> UnkeyedEncodingContainer { self }
mutating func nestedUnkeyedContainer() -> any UnkeyedEncodingContainer { self }
mutating func superEncoder() -> Encoder { self }
mutating func superEncoder() -> any Encoder { self }
}
+1 -1
View File
@@ -751,7 +751,7 @@ class DatabaseObservationBroker {
/// Transaction turns rollbacked because a transaction observer has
/// cancelled a commit by throwing an error.
case cancelledCommit(Error)
case cancelledCommit(any Error)
}
}
+1 -1
View File
@@ -58,7 +58,7 @@ extension DatabaseMigrator {
@available(*, unavailable, message: "The completion function now accepts one Result<Database, Error> argument")
public func asyncMigrate(
_ writer: any DatabaseWriter,
completion: @escaping (Database, Error?) -> Void)
completion: @escaping (Database, (any Error)?) -> Void)
{ preconditionFailure() }
}
+3 -3
View File
@@ -264,7 +264,7 @@ public struct DatabaseMigrator {
/// from succeeding.
public func asyncMigrate(
_ writer: some DatabaseWriter,
completion: @escaping (Result<Database, Error>) -> Void)
completion: @escaping (Result<Database, any Error>) -> Void)
{
writer.asyncBarrierWriteWithoutTransaction { dbResult in
do {
@@ -523,9 +523,9 @@ extension DatabasePublishers {
/// You build such a publisher from ``DatabaseMigrator``.
public struct Migrate: Publisher {
public typealias Output = Void
public typealias Failure = Error
public typealias Failure = any Error
fileprivate let upstream: AnyPublisher<Void, Error>
fileprivate let upstream: AnyPublisher<Void, any Error>
public func receive<S>(subscriber: S) where S: Subscriber, Self.Failure == S.Failure, Self.Output == S.Input {
upstream.receive(subscriber: subscriber)
@@ -365,7 +365,7 @@ extension Database {
view name: String,
options: ViewOptions = [],
columns: [String]? = nil,
as request: SQLSubqueryable)
as request: some SQLSubqueryable)
throws {
var literal: SQL = "CREATE "
+7 -7
View File
@@ -29,11 +29,11 @@ private class RecordEncoder<Record: EncodableRecord>: Encoder {
return KeyedEncodingContainer(container)
}
func unkeyedContainer() -> UnkeyedEncodingContainer {
func unkeyedContainer() -> any UnkeyedEncodingContainer {
fatalError("unkeyed encoding is not supported")
}
func singleValueContainer() -> SingleValueEncodingContainer {
func singleValueContainer() -> any SingleValueEncodingContainer {
// @itaiferber on https://forums.swift.org/t/how-to-encode-objects-of-unknown-type/12253/11
//
// > Encoding a value into a single-value container is equivalent to
@@ -109,15 +109,15 @@ private class RecordEncoder<Record: EncodableRecord>: Encoder {
fatalError("Not implemented")
}
func nestedUnkeyedContainer(forKey key: Key) -> UnkeyedEncodingContainer {
func nestedUnkeyedContainer(forKey key: Key) -> any UnkeyedEncodingContainer {
fatalError("Not implemented")
}
func superEncoder() -> Encoder {
func superEncoder() -> any Encoder {
recordEncoder
}
func superEncoder(forKey key: Key) -> Encoder {
func superEncoder(forKey key: Key) -> any Encoder {
recordEncoder
}
}
@@ -195,7 +195,7 @@ private class ColumnEncoder<Record: EncodableRecord>: Encoder {
return KeyedEncodingContainer(container)
}
func unkeyedContainer() -> UnkeyedEncodingContainer {
func unkeyedContainer() -> any UnkeyedEncodingContainer {
// We need to perform JSON encoding. Unfortunately we can't access the
// inner container of Foundation's JSONEncoder. At this point we must
// throw an error so that the caller can retry encoding from scratch.
@@ -205,7 +205,7 @@ private class ColumnEncoder<Record: EncodableRecord>: Encoder {
return JSONRequiredEncoder(codingPath: codingPath)
}
func singleValueContainer() -> SingleValueEncodingContainer { self }
func singleValueContainer() -> any SingleValueEncodingContainer { self }
}
extension ColumnEncoder: SingleValueEncodingContainer {
+19 -19
View File
@@ -79,7 +79,7 @@ public class FetchableRecordDecoder {
/// The decoder that decodes a record from a database row
private struct _RowDecoder<R: FetchableRecord>: Decoder {
var row: Row
var codingPath: [CodingKey]
var codingPath: [any CodingKey]
var columnDecodingStrategy: DatabaseColumnDecodingStrategy
var userInfo: [CodingUserInfoKey: Any] { R.databaseDecodingUserInfo }
@@ -87,7 +87,7 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
KeyedDecodingContainer(KeyedContainer<Key>(decoder: self))
}
func unkeyedContainer() throws -> UnkeyedDecodingContainer {
func unkeyedContainer() throws -> any UnkeyedDecodingContainer {
guard let codingKey = codingPath.last else {
fatalError("unkeyed decoding from database row is not supported")
}
@@ -105,7 +105,7 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
debugDescription: debugDescription))
}
func singleValueContainer() throws -> SingleValueDecodingContainer {
func singleValueContainer() throws -> any SingleValueDecodingContainer {
guard let key = codingPath.last else {
// Decoding an array of scalars from rows: pick the first column
return ColumnDecoder<R>(row: row, columnIndex: 0, codingPath: codingPath)
@@ -123,8 +123,8 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
class KeyedContainer<Key: CodingKey>: KeyedDecodingContainerProtocol {
private let decoder: _RowDecoder
var codingPath: [CodingKey] { decoder.codingPath }
private var decodedRootKey: CodingKey?
var codingPath: [any CodingKey] { decoder.codingPath }
private var decodedRootKey: (any CodingKey)?
// Not nil iff decoder has a columnDecodingStrategy
private let _columnForKey: [String: String]?
@@ -378,17 +378,17 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
fatalError("not implemented")
}
func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer {
func nestedUnkeyedContainer(forKey key: Key) throws -> any UnkeyedDecodingContainer {
throw DecodingError.typeMismatch(
UnkeyedDecodingContainer.self,
(any UnkeyedDecodingContainer).self,
DecodingError.Context(codingPath: codingPath, debugDescription: "unkeyed decoding is not supported"))
}
func superDecoder() throws -> Decoder {
func superDecoder() throws -> any Decoder {
decoder
}
func superDecoder(forKey key: Key) throws -> Decoder {
func superDecoder(forKey key: Key) throws -> any Decoder {
decoder
}
@@ -397,7 +397,7 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
private func decode<T>(
_ type: T.Type,
fromRow row: Row,
codingPath: [CodingKey])
codingPath: [any CodingKey])
throws -> T
where T: Decodable
{
@@ -449,11 +449,11 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
private struct PrefetchedRowsDecoder<R: FetchableRecord>: Decoder {
var rows: [Row]
var codingPath: [CodingKey]
var codingPath: [any CodingKey]
var currentIndex: Int
var userInfo: [CodingUserInfoKey: Any] { R.databaseDecodingUserInfo }
init(rows: [Row], codingPath: [CodingKey]) {
init(rows: [Row], codingPath: [any CodingKey]) {
self.rows = rows
self.codingPath = codingPath
self.currentIndex = 0
@@ -463,9 +463,9 @@ private struct PrefetchedRowsDecoder<R: FetchableRecord>: Decoder {
fatalError("keyed decoding from prefetched rows is not supported")
}
func unkeyedContainer() throws -> UnkeyedDecodingContainer { self }
func unkeyedContainer() throws -> any UnkeyedDecodingContainer { self }
func singleValueContainer() throws -> SingleValueDecodingContainer {
func singleValueContainer() throws -> any SingleValueDecodingContainer {
fatalError("single value decoding from prefetched rows is not supported")
}
}
@@ -501,11 +501,11 @@ extension PrefetchedRowsDecoder: UnkeyedDecodingContainer {
fatalError("not implemented")
}
mutating func nestedUnkeyedContainer() throws -> UnkeyedDecodingContainer {
mutating func nestedUnkeyedContainer() throws -> any UnkeyedDecodingContainer {
fatalError("not implemented")
}
mutating func superDecoder() throws -> Decoder {
mutating func superDecoder() throws -> any Decoder {
fatalError("not implemented")
}
}
@@ -516,7 +516,7 @@ extension PrefetchedRowsDecoder: UnkeyedDecodingContainer {
private struct ColumnDecoder<R: FetchableRecord>: Decoder {
var row: Row
var columnIndex: Int
var codingPath: [CodingKey]
var codingPath: [any CodingKey]
var userInfo: [CodingUserInfoKey: Any] { R.databaseDecodingUserInfo }
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
@@ -524,12 +524,12 @@ private struct ColumnDecoder<R: FetchableRecord>: Decoder {
throw JSONRequiredError()
}
func unkeyedContainer() throws -> UnkeyedDecodingContainer {
func unkeyedContainer() throws -> any UnkeyedDecodingContainer {
// We need to switch to JSON decoding
throw JSONRequiredError()
}
func singleValueContainer() throws -> SingleValueDecodingContainer { self }
func singleValueContainer() throws -> any SingleValueDecodingContainer { self }
}
extension ColumnDecoder: SingleValueDecodingContainer {
+1 -1
View File
@@ -967,7 +967,7 @@ public enum DatabaseColumnDecodingStrategy {
case convertFromSnakeCase
/// A key decoding strategy defined by the closure you supply.
case custom((String) -> CodingKey)
case custom((String) -> any CodingKey)
func key<K: CodingKey>(forColumn column: String) -> K? {
switch self {
+1 -1
View File
@@ -107,7 +107,7 @@ final class Pool<T> {
///
/// - important: The `execute` argument is executed in a serial dispatch
/// queue, so make sure you use the element asynchronously.
func asyncGet(_ execute: @escaping (Result<(element: T, release: (PoolCompletion) -> Void), Error>) -> Void) {
func asyncGet(_ execute: @escaping (Result<(element: T, release: (PoolCompletion) -> Void), any Error>) -> Void) {
// Inspired by https://khanlou.com/2016/04/the-GCD-handbook/
// > We wait on the semaphore in the serial queue, which means that
// > we’ll have at most one blocked thread when we reach maximum
+2 -2
View File
@@ -48,7 +48,7 @@ where
private enum State {
case waitingForRequest(Upstream, Target)
case waitingForSubscription(Target, Subscribers.Demand)
case subscribed(Target, Subscription)
case subscribed(Target, any Subscription)
case finished
}
@@ -110,7 +110,7 @@ where
// MARK: Subscriber
func receive(subscription: Subscription) {
func receive(subscription: any Subscription) {
lock.synchronized { sideEffect in
switch state {
case let .waitingForSubscription(target, currentDemand):
+1 -1
View File
@@ -99,7 +99,7 @@ extension Sequence {
/// finally: cleanup)
func throwingFirstError<T>(execute: () throws -> T, finally: () throws -> Void) throws -> T {
var result: T?
var firstError: Error?
var firstError: (any Error)?
do {
result = try execute()
} catch {
@@ -817,7 +817,7 @@ extension ValueConcurrentObserver: TransactionObserver {
}
}
private func reduce(_ fetchResult: Result<Reducer.Fetched, Error>) {
private func reduce(_ fetchResult: Result<Reducer.Fetched, any Error>) {
reduceQueue.async {
do {
let fetchedValue = try fetchResult.get()
@@ -874,7 +874,7 @@ extension ValueConcurrentObserver: DatabaseCancellable {
}
}
func notifyError(_ error: Error) {
func notifyError(_ error: any Error) {
scheduler.schedule {
let events = self.lock.synchronized {
let events = self.notificationCallbacks?.events
@@ -457,7 +457,7 @@ extension ValueWriteOnlyObserver: DatabaseCancellable {
}
}
func notifyError(_ error: Error) {
func notifyError(_ error: any Error) {
scheduler.schedule {
let events = self.lock.synchronized {
let events = self.notificationCallbacks?.events
@@ -177,13 +177,13 @@ public final class SharedValueObservation<Element> {
private var clients: [Client]
private var isObserving = false
private var cancellable: AnyDatabaseCancellable?
private var lastResult: Result<Element, Error>?
private var lastResult: Result<Element, any Error>?
private final class Client {
var onError: (Error) -> Void
var onError: (any Error) -> Void
var onChange: (Element) -> Void
init(onError: @escaping (Error) -> Void, onChange: @escaping (Element) -> Void) {
init(onError: @escaping (any Error) -> Void, onChange: @escaping (Element) -> Void) {
self.onError = onError
self.onChange = onChange
}
@@ -224,7 +224,7 @@ public final class SharedValueObservation<Element> {
/// fresh value.
/// - returns: A DatabaseCancellable that can stop the observation.
public func start(
onError: @escaping (Error) -> Void,
onError: @escaping (any Error) -> Void,
onChange: @escaping (Element) -> Void)
-> AnyDatabaseCancellable
{
@@ -299,7 +299,7 @@ public final class SharedValueObservation<Element> {
}
#endif
private func handleError(_ error: Error) {
private func handleError(_ error: any Error) {
synchronized {
let notifiedClients = clients
+9 -9
View File
@@ -77,12 +77,12 @@ struct ValueObservationEvents: Refinable {
var willStart: (() -> Void)?
var willTrackRegion: ((DatabaseRegion) -> Void)?
var databaseDidChange: (() -> Void)?
var didFail: ((Error) -> Void)?
var didFail: ((any Error) -> Void)?
var didCancel: (() -> Void)?
}
typealias ValueObservationStart<T> = (
_ onError: @escaping (Error) -> Void,
_ onError: @escaping (any Error) -> Void,
_ onChange: @escaping (T) -> Void)
-> AnyDatabaseCancellable
@@ -138,7 +138,7 @@ extension ValueObservation: Refinable {
public func start(
in reader: some DatabaseReader,
scheduling scheduler: some ValueObservationScheduler = .async(onQueue: .main),
onError: @escaping (Error) -> Void,
onError: @escaping (any Error) -> Void,
onChange: @escaping (Reducer.Value) -> Void)
-> AnyDatabaseCancellable
where Reducer: ValueReducer
@@ -180,7 +180,7 @@ extension ValueObservation: Refinable {
willTrackRegion: ((DatabaseRegion) -> Void)? = nil,
databaseDidChange: (() -> Void)? = nil,
didReceiveValue: ((Reducer.Value) -> Void)? = nil,
didFail: ((Error) -> Void)? = nil,
didFail: ((any Error) -> Void)? = nil,
didCancel: (() -> Void)? = nil)
-> ValueObservation<ValueReducers.Trace<Reducer>>
{
@@ -231,7 +231,7 @@ extension ValueObservation: Refinable {
/// used to log messages to other destinations.
public func print(
_ prefix: String = "",
to stream: TextOutputStream? = nil)
to stream: (any TextOutputStream)? = nil)
-> ValueObservation<ValueReducers.Trace<Reducer>>
{
let lock = NSLock()
@@ -333,7 +333,7 @@ extension ValueObservation {
/// ``SharedValueObservation``.
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
public struct AsyncValueObservation<Element>: AsyncSequence {
public typealias BufferingPolicy = AsyncThrowingStream<Element, Error>.Continuation.BufferingPolicy
public typealias BufferingPolicy = AsyncThrowingStream<Element, any Error>.Continuation.BufferingPolicy
public typealias AsyncIterator = Iterator
var bufferingPolicy: BufferingPolicy
@@ -377,7 +377,7 @@ public struct AsyncValueObservation<Element>: AsyncSequence {
}
public struct Iterator: AsyncIteratorProtocol {
var iterator: AsyncThrowingStream<Element, Error>.AsyncIterator
var iterator: AsyncThrowingStream<Element, any Error>.AsyncIterator
let cancellable: AnyDatabaseCancellable
public mutating func next() async throws -> Element? {
@@ -457,7 +457,7 @@ extension DatabasePublishers {
/// You build such a publisher from ``ValueObservation``
/// or ``SharedValueObservation``.
public struct Value<Output>: Publisher {
public typealias Failure = Error
public typealias Failure = any Error
private let start: ValueObservationStart<Output>
init(start: @escaping ValueObservationStart<Output>) {
@@ -473,7 +473,7 @@ extension DatabasePublishers {
}
private class ValueSubscription<Downstream: Subscriber>: Subscription
where Downstream.Failure == Error
where Downstream.Failure == any Error
{
private struct WaitingForDemand {
let downstream: Downstream
+1 -5
View File
@@ -10,9 +10,6 @@ var swiftSettings: [SwiftSetting] = [
var cSettings: [CSetting] = []
var dependencies: [PackageDescription.Package.Dependency] = []
// For Swift 5.8+
//swiftSettings.append(.enableUpcomingFeature("ExistentialAny"))
// Don't rely on those environment variables. They are ONLY testing conveniences:
// $ SQLITE_ENABLE_PREUPDATE_HOOK=1 make test_SPM
if ProcessInfo.processInfo.environment["SQLITE_ENABLE_PREUPDATE_HOOK"] == "1" {
@@ -77,6 +74,5 @@ let package = Package(
],
cSettings: cSettings,
swiftSettings: swiftSettings)
],
swiftLanguageVersions: [.v5]
]
)
+80
View File
@@ -0,0 +1,80 @@
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import Foundation
import PackageDescription
var swiftSettings: [SwiftSetting] = [
.define("SQLITE_ENABLE_FTS5"),
// <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
.enableUpcomingFeature("ExistentialAny"),
]
var cSettings: [CSetting] = []
var dependencies: [PackageDescription.Package.Dependency] = []
// Don't rely on those environment variables. They are ONLY testing conveniences:
// $ SQLITE_ENABLE_PREUPDATE_HOOK=1 make test_SPM
if ProcessInfo.processInfo.environment["SQLITE_ENABLE_PREUPDATE_HOOK"] == "1" {
swiftSettings.append(.define("SQLITE_ENABLE_PREUPDATE_HOOK"))
cSettings.append(.define("GRDB_SQLITE_ENABLE_PREUPDATE_HOOK"))
}
// The SPI_BUILDER environment variable enables documentation building
// on <https://swiftpackageindex.com/groue/GRDB.swift>. See
// <https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2122>
// for more information.
//
// SPI_BUILDER also enables the `make docs-localhost` command.
if ProcessInfo.processInfo.environment["SPI_BUILDER"] == "1" {
dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"))
}
let package = Package(
name: "GRDB",
defaultLocalization: "en", // for tests
platforms: [
.iOS(.v11),
.macOS(.v10_13),
.tvOS(.v11),
.watchOS(.v4),
],
products: [
.library(name: "CSQLite", targets: ["CSQLite"]),
.library(name: "GRDB", targets: ["GRDB"]),
.library(name: "GRDB-dynamic", type: .dynamic, targets: ["GRDB"]),
],
dependencies: dependencies,
targets: [
.systemLibrary(
name: "CSQLite",
providers: [.apt(["libsqlite3-dev"])]),
.target(
name: "GRDB",
dependencies: ["CSQLite"],
path: "GRDB",
cSettings: cSettings,
swiftSettings: swiftSettings),
.testTarget(
name: "GRDBTests",
dependencies: ["GRDB"],
path: "Tests",
exclude: [
"CocoaPods",
"Crash",
"CustomSQLite",
"GRDBTests/getThreadsCount.c",
"Info.plist",
"Performance",
"SPM",
"generatePerformanceReport.rb",
"parsePerformanceTests.rb",
],
resources: [
.copy("GRDBTests/Betty.jpeg"),
.copy("GRDBTests/InflectionsTests.json"),
.copy("GRDBTests/Issue1383.sqlite"),
],
cSettings: cSettings,
swiftSettings: swiftSettings)
]
)
+2 -2
View File
@@ -40,7 +40,7 @@ public class Recorder<Input, Failure: Error>: Subscriber {
/// Publisher is subscribed. The recorder may have an expectation to
/// fulfill. It keeps track of all published elements.
case subscribed(Subscription, RecorderExpectation?, [Input])
case subscribed(any Subscription, RecorderExpectation?, [Input])
/// Publisher is completed. The recorder keeps track of all published
/// elements and completion.
@@ -204,7 +204,7 @@ public class Recorder<Input, Failure: Error>: Subscriber {
// MARK: - Subscriber
public func receive(subscription: Subscription) {
public func receive(subscription: any Subscription) {
synchronized {
switch state {
case let .waitingForSubscription(exp):
@@ -72,7 +72,7 @@ class DatabaseRegionObservationPublisherTests : XCTestCase {
func test(writer: some DatabaseWriter) throws {
let expectation = self.expectation(description: "")
let testSubject = PassthroughSubject<Database, Error>()
let testSubject = PassthroughSubject<Database, any Error>()
let testCancellable = testSubject
.tryMap(Player.fetchCount)
.collect(3)
@@ -397,7 +397,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase {
func test(writer: some DatabaseWriter, iteration: Int) throws {
// print(iteration)
let scoreSubject = PassthroughSubject<Int, Error>()
let scoreSubject = PassthroughSubject<Int, any Error>()
let publisher = scoreSubject
.map { score in
writer.writePublisher { db -> Int in
@@ -176,7 +176,7 @@ class ValueObservationPublisherTests : XCTestCase {
func test(writer: some DatabaseWriter) throws {
let semaphore = DispatchSemaphore(value: 0)
let testSubject = PassthroughSubject<Int, Error>()
let testSubject = PassthroughSubject<Int, any Error>()
let testCancellable = testSubject
.sink(
receiveCompletion: { _ in },
@@ -228,7 +228,7 @@ class ValueObservationPublisherTests : XCTestCase {
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
private class DemandSubscriber<Input, Failure: Error>: Subscriber {
private var subscription: Subscription?
private var subscription: (any Subscription)?
let subject = PassthroughSubject<Input, Failure>()
deinit {
subscription?.cancel()
@@ -242,7 +242,7 @@ class ValueObservationPublisherTests : XCTestCase {
subscription!.request(demand)
}
func receive(subscription: Subscription) {
func receive(subscription: any Subscription) {
self.subscription = subscription
}
@@ -267,7 +267,7 @@ class ValueObservationPublisherTests : XCTestCase {
}
func test(writer: some DatabaseWriter) throws {
let subscriber = DemandSubscriber<Int, Error>()
let subscriber = DemandSubscriber<Int, any Error>()
let expectation = self.expectation(description: "")
expectation.isInverted = true
@@ -302,7 +302,7 @@ class ValueObservationPublisherTests : XCTestCase {
}
func test(writer: some DatabaseWriter) throws {
let subscriber = DemandSubscriber<Int, Error>()
let subscriber = DemandSubscriber<Int, any Error>()
let expectation = self.expectation(description: "")
let testCancellable = subscriber.subject.sink(
@@ -340,7 +340,7 @@ class ValueObservationPublisherTests : XCTestCase {
}
func test(writer: some DatabaseWriter) throws {
let subscriber = DemandSubscriber<Int, Error>()
let subscriber = DemandSubscriber<Int, any Error>()
let expectation = self.expectation(description: "")
expectation.isInverted = true
@@ -382,7 +382,7 @@ class ValueObservationPublisherTests : XCTestCase {
}
func test(writer: some DatabaseWriter) throws {
let subscriber = DemandSubscriber<Int, Error>()
let subscriber = DemandSubscriber<Int, any Error>()
let expectation = self.expectation(description: "")
let testCancellable = subscriber.subject
@@ -127,7 +127,7 @@ class AssociationPrefetchingCodableRecordTests: GRDBTestCase {
}
enum CodingKeys: CodingKey { case a, bs }
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
a = try container.decode(A.self, forKey: .a)
if try container.decodeNil(forKey: .bs) {
@@ -307,7 +307,7 @@ class AssociationPrefetchingCodableRecordTests: GRDBTestCase {
}
enum CodingKeys: CodingKey { case a, bs }
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
a = try container.decode(A.self, forKey: .a)
if try container.decodeNil(forKey: .bs) {
@@ -1334,7 +1334,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
// of NSFileCoordinator. What a weird API.
let coordinator = NSFileCoordinator(filePresenter: nil)
var coordinatorError: NSError?
var poolError: Error?
var poolError: (any Error)?
coordinator.coordinate(writingItemAt: dbURL, options: .forMerging, error: &coordinatorError) { url in
do {
_ = try DatabasePool(path: url.path)
@@ -1355,7 +1355,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
let coordinator = NSFileCoordinator(filePresenter: nil)
var coordinatorError: NSError?
var dbPool: DatabasePool?
var dbError: Error?
var dbError: (any Error)?
coordinator.coordinate(writingItemAt: databaseURL, options: .forMerging, error: &coordinatorError) { url in
do {
dbPool = try openDatabase(at: url)
@@ -1384,7 +1384,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
let coordinator = NSFileCoordinator(filePresenter: nil)
var coordinatorError: NSError?
var dbPool: DatabasePool?
var dbError: Error?
var dbError: (any Error)?
coordinator.coordinate(readingItemAt: databaseURL, options: .withoutChanges, error: &coordinatorError) { url in
do {
dbPool = try openReadOnlyDatabase(at: url)
@@ -6,7 +6,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
struct Value : Decodable, DatabaseValueConvertible {
let string: String
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
string = try decoder.singleValueContainer().decode(String.self)
}
@@ -42,7 +42,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
struct Value : Decodable, DatabaseValueConvertible {
let string: String
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
string = try decoder.singleValueContainer().decode(String.self)
}
@@ -54,7 +54,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
struct ValueWrapper : Decodable, DatabaseValueConvertible {
let value: Value
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
value = try decoder.singleValueContainer().decode(Value.self)
}
@@ -91,13 +91,13 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
struct Nested : Decodable {
let string: String
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
string = try decoder.singleValueContainer().decode(String.self)
}
}
let nested: Nested
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
nested = try decoder.singleValueContainer().decode(Nested.self)
}
@@ -162,7 +162,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
struct Value: Decodable, DatabaseValueConvertible {
let dictionary: [String: Int]
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
dictionary = try .init(from: decoder)
}
@@ -195,7 +195,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
struct Value: Decodable, DatabaseValueConvertible {
let strings: [String]
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
strings = try .init(from: decoder)
}
@@ -228,7 +228,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
struct Value: Decodable, DatabaseValueConvertible {
let dictionary: [String: Int]
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
dictionary = try container.decode([String: Int].self)
}
@@ -262,7 +262,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
struct Value: Decodable, DatabaseValueConvertible {
let strings: [String]
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
strings = try container.decode([String].self)
}
@@ -7,7 +7,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase {
struct Value : Encodable, DatabaseValueConvertible {
let string: String
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(string)
}
@@ -28,7 +28,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase {
struct Value : Encodable, DatabaseValueConvertible {
let string: String
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(string)
}
@@ -41,7 +41,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase {
struct Wrapper : Encodable, DatabaseValueConvertible {
let value: Value
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(value)
}
@@ -63,14 +63,14 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase {
struct Nested : Encodable {
let string: String
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(string)
}
}
let nested: Nested
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(nested)
}
@@ -111,7 +111,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase {
struct Value: Encodable, DatabaseValueConvertible {
let dictionary: [String: Int]
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
try dictionary.encode(to: encoder)
}
@@ -135,7 +135,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase {
struct Value: Encodable, DatabaseValueConvertible {
let strings: [String]
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
try strings.encode(to: encoder)
}
@@ -159,7 +159,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase {
struct Value: Encodable, DatabaseValueConvertible {
let dictionary: [String: Int]
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(dictionary)
}
@@ -184,7 +184,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase {
struct Value: Encodable, DatabaseValueConvertible {
let strings: [String]
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(strings)
}
@@ -232,7 +232,7 @@ extension DatabaseValueConvertibleEncodableTests {
struct Value : Encodable, DatabaseValueConvertible {
let date: Date
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(date)
}
@@ -261,7 +261,7 @@ extension DatabaseValueConvertibleEncodableTests {
struct Value : Encodable, DatabaseValueConvertible {
let url: URL
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(url)
}
@@ -285,7 +285,7 @@ extension DatabaseValueConvertibleEncodableTests {
struct Value : Encodable, DatabaseValueConvertible {
let uuid: UUID
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(uuid)
}
@@ -27,7 +27,7 @@ extension FetchableRecordDecodableTests {
case value = "someColumn"
}
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
value = try container.decode(String.self, forKey: .value)
}
@@ -89,7 +89,7 @@ extension FetchableRecordDecodableTests {
struct Value : Decodable {
let string: String
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
string = try decoder.singleValueContainer().decode(String.self)
}
}
@@ -125,7 +125,7 @@ extension FetchableRecordDecodableTests {
struct NestedValue : Decodable {
let string: String
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
string = try decoder.singleValueContainer().decode(String.self)
}
}
@@ -133,7 +133,7 @@ extension FetchableRecordDecodableTests {
struct Value : Decodable {
let nestedValue: NestedValue
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
nestedValue = try decoder.singleValueContainer().decode(NestedValue.self)
}
}
@@ -214,7 +214,7 @@ extension FetchableRecordDecodableTests {
self.string = string
}
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
string = try decoder.singleValueContainer().decode(String.self) + " (Decodable)"
}
@@ -1084,7 +1084,7 @@ extension FetchableRecordDecodableTests {
enum CodingKeys: String, CodingKey { case name }
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
name = try container.decode(String.self, forKey: .name)
key = decoder.codingPath.last?.stringValue
@@ -1097,7 +1097,7 @@ extension FetchableRecordDecodableTests {
var key: String?
var context: String?
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
name = try container.decode(String.self)
key = decoder.codingPath.last?.stringValue
@@ -1110,7 +1110,7 @@ extension FetchableRecordDecodableTests {
var key: String?
var context: String?
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
var container = try decoder.unkeyedContainer()
name = try container.decode(String.self)
key = decoder.codingPath.last?.stringValue
@@ -1129,7 +1129,7 @@ extension FetchableRecordDecodableTests {
case nestedKeyed, nestedSingle, nestedUnkeyed
}
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
nestedKeyed = try container.decode(NestedKeyed.self, forKey: .nestedKeyed)
nestedSingle = try container.decode(NestedSingle.self, forKey: .nestedSingle)
@@ -1150,7 +1150,7 @@ extension FetchableRecordDecodableTests {
case nestedKeyed, nestedSingle, nestedUnkeyed
}
required init(from decoder: Decoder) throws {
required init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
nestedKeyed = try container.decode(NestedKeyed.self, forKey: .nestedKeyed)
nestedSingle = try container.decode(NestedSingle.self, forKey: .nestedSingle)
@@ -1448,7 +1448,7 @@ extension FetchableRecordDecodableTests {
self.lastName = lastName
}
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
let userInfoValue = decoder.userInfo[.testKey] as? String
let container = try decoder.container(keyedBy: CodingKeys.self)
+1 -1
View File
@@ -252,7 +252,7 @@ struct InflectionTestCases: Decodable {
}
}
init(from decoder: Decoder) throws {
init(from decoder: any Decoder) throws {
var testCases: [String: [(String, String)]] = [:]
let container = try decoder.container(keyedBy: AnyCodingKey.self)
for key in container.allKeys {
@@ -38,7 +38,7 @@ extension MutablePersistableRecordEncodableTests {
case value = "someColumn"
}
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(value + " (Encodable)", forKey: .value)
}
@@ -129,7 +129,7 @@ extension MutablePersistableRecordEncodableTests {
struct Value : Encodable {
let string: String
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(string)
}
@@ -174,7 +174,7 @@ extension MutablePersistableRecordEncodableTests {
struct NestedValue : Encodable {
let string: String
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(string)
}
@@ -183,7 +183,7 @@ extension MutablePersistableRecordEncodableTests {
struct Value : Encodable {
let nestedValue: NestedValue
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(nestedValue)
}
@@ -281,7 +281,7 @@ extension MutablePersistableRecordEncodableTests {
self.string = string
}
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(string + " (Encodable)")
}
@@ -576,7 +576,7 @@ extension MutablePersistableRecordEncodableTests {
enum CodingKeys: String, CodingKey { case name, key, context }
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(name, forKey: .name)
try container.encodeIfPresent(encoder.codingPath.last?.stringValue, forKey: .key)
@@ -587,7 +587,7 @@ extension MutablePersistableRecordEncodableTests {
struct NestedSingle: Encodable {
var name: String
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
var value = name
value += ",key:\(encoder.codingPath.last?.stringValue ?? "nil")"
@@ -599,7 +599,7 @@ extension MutablePersistableRecordEncodableTests {
struct NestedUnkeyed: Encodable {
var name: String
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(name)
if let key = encoder.codingPath.last?.stringValue {
@@ -630,7 +630,7 @@ extension MutablePersistableRecordEncodableTests {
case nestedKeyed, nestedSingle, nestedUnkeyed, key, context
}
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(nestedKeyed, forKey: .nestedKeyed)
try container.encode(nestedSingle, forKey: .nestedSingle)
@@ -668,7 +668,7 @@ extension MutablePersistableRecordEncodableTests {
return encoder
}
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(nestedKeyed, forKey: .nestedKeyed)
try container.encode(nestedSingle, forKey: .nestedSingle)
@@ -798,7 +798,7 @@ extension MutablePersistableRecordEncodableTests {
self.lastName = lastName
}
func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
let userInfoValue = encoder.userInfo[.testKey] as? String
var container = encoder.container(keyedBy: CodingKeys.self)
@@ -523,7 +523,7 @@ class SharedValueObservationTests: GRDBTestCase {
}
let log = Log()
var fetchError: Error? = nil
var fetchError: (any Error)? = nil
let publisher = ValueObservation
.tracking { db -> Int in
if let error = fetchError { throw error }
@@ -579,7 +579,7 @@ class SharedValueObservationTests: GRDBTestCase {
}
let log = Log()
var fetchError: Error? = nil
var fetchError: (any Error)? = nil
let publisher = ValueObservation
.tracking { db -> Int in
if let error = fetchError { throw error }
@@ -4,7 +4,7 @@ import XCTest
private class Observer : TransactionObserver {
var lastCommittedEvents: [DatabaseEvent] = []
var events: [DatabaseEvent] = []
var commitError: Error?
var commitError: (any Error)?
var deinitBlock: (() -> ())?
var didCommitBlock: ((Database) -> ())?
var observesBlock: (DatabaseEventKind) -> Bool
@@ -14,7 +14,7 @@ public class ValueObservationRecorder<Value> {
/// The recorder state
private struct State {
var values: [Value]
var error: Error?
var error: (any Error)?
var recorderExpectation: RecorderExpectation?
var cancellable: AnyDatabaseCancellable?
}
@@ -65,7 +65,7 @@ public class ValueObservationRecorder<Value> {
}
// Internal for testability.
func onError(_ error: Error) {
func onError(_ error: any Error) {
return synchronized {
if state.error != nil {
// This is possible with ValueObservation, but not supported by ValueObservationRecorder
@@ -140,7 +140,7 @@ public class ValueObservationRecorder<Value> {
/// - returns: The value
func value<T>(_ value: (
_ values: [Value],
_ error: Error?,
_ error: (any Error)?,
_ remainingValues: ArraySlice<Value>,
_ consume: (_ count: Int) -> ()) throws -> T)
rethrows -> T
@@ -220,7 +220,7 @@ extension ValueObservation {
public func record(
in reader: some DatabaseReader,
scheduling scheduler: some ValueObservationScheduler = .async(onQueue: .main),
onError: ((Error) -> Void)? = nil,
onError: ((any Error) -> Void)? = nil,
onChange: ((Reducer.Value) -> Void)? = nil)
-> ValueObservationRecorder<Reducer.Value>
where Reducer: ValueReducer
@@ -805,7 +805,7 @@ extension ValueObservationExpectations {
recorder.fulfillOnError(expectation)
}
public func get() throws -> (values: [Value], error: Error) {
public func get() throws -> (values: [Value], error: any Error) {
try recorder.value { (values, error, remainingValues, consume) in
if let error {
consume(remainingValues.count)
+2 -2
View File
@@ -37,7 +37,7 @@ class ValueObservationTests: GRDBTestCase {
notificationExpectation.expectedFulfillmentCount = 4
notificationExpectation.isInverted = true
var nextError: Error? = nil // If not null, observation throws an error
var nextError: (any Error)? = nil // If not null, observation throws an error
let observation = ValueObservation.trackingConstantRegion {
_ = try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")
if let error = nextError {
@@ -922,7 +922,7 @@ class ValueObservationTests: GRDBTestCase {
let cancellationExpectation = expectation(description: "cancelled")
// Launch a task that we'll cancel
let cancelledTask = Task<String, Error> {
let cancelledTask = Task<String, any Error> {
// Loops until cancelled
let observation = ValueObservation.trackingConstantRegion(Table("t").fetchCount)
let cancelledObservation = observation.handleEvents(didCancel: {