From e4bed5d8244e557f2aa670fa04b9bf027e8284cd Mon Sep 17 00:00:00 2001 From: Leo Dion Date: Mon, 14 Oct 2024 15:59:42 -0400 Subject: [PATCH] reorganzing files [skip ci] --- .../{ => Databases}/BackgroundDatabase.swift | 0 .../{ => Databases}/Database+Extras.swift | 0 .../{ => Databases}/Database+ModelContext.swift | 0 Sources/DataThespian/{ => Databases}/Database.swift | 0 .../EnvironmentValues+Database.swift} | 9 +-------- .../{ => Databases}/ModelActor+Database.swift | 0 .../{ => Databases}/ModelActorDatabase.swift | 0 .../{ => Notification}/AgentRegister.swift | 0 .../Combine}/DatabaseChangePublicist.swift | 0 .../Combine}/DatabaseChangePublicistKey.swift | 11 +---------- .../{ => Notification/Combine}/PublishingAgent.swift | 0 .../Combine}/PublishingRegister.swift | 0 .../DataThespian/{ => Notification}/DataAgent.swift | 0 .../DataThespian/{ => Notification}/DataMonitor.swift | 0 .../{ => Notification}/DatabaseChangeSet.swift | 0 .../{ => Notification}/DatabaseChangeType.swift | 0 .../{ => Notification}/DatabaseMonitoring.swift | 0 .../{ => Notification}/ManagedObjectMetadata.swift | 0 .../{ => Notification}/Notification.swift | 0 .../{ => Notification}/NotificationDataUpdate.swift | 0 .../{ => Notification}/RegistrationCollection.swift | 0 .../{ => SwiftData}/FetchDescriptor.swift | 2 ++ .../{ => SwiftData}/ModelContext+Extension.swift | 8 +++++++- .../DataThespian/{ => SwiftData}/ModelContext.swift | 8 +++++--- .../{ => SwiftData}/NSManagedObjectID.swift | 0 25 files changed, 16 insertions(+), 22 deletions(-) rename Sources/DataThespian/{ => Databases}/BackgroundDatabase.swift (100%) rename Sources/DataThespian/{ => Databases}/Database+Extras.swift (100%) rename Sources/DataThespian/{ => Databases}/Database+ModelContext.swift (100%) rename Sources/DataThespian/{ => Databases}/Database.swift (100%) rename Sources/DataThespian/{DatabaseKey.swift => Databases/EnvironmentValues+Database.swift} (88%) rename Sources/DataThespian/{ => Databases}/ModelActor+Database.swift (100%) rename Sources/DataThespian/{ => Databases}/ModelActorDatabase.swift (100%) rename Sources/DataThespian/{ => Notification}/AgentRegister.swift (100%) rename Sources/DataThespian/{ => Notification/Combine}/DatabaseChangePublicist.swift (100%) rename Sources/DataThespian/{ => Notification/Combine}/DatabaseChangePublicistKey.swift (78%) rename Sources/DataThespian/{ => Notification/Combine}/PublishingAgent.swift (100%) rename Sources/DataThespian/{ => Notification/Combine}/PublishingRegister.swift (100%) rename Sources/DataThespian/{ => Notification}/DataAgent.swift (100%) rename Sources/DataThespian/{ => Notification}/DataMonitor.swift (100%) rename Sources/DataThespian/{ => Notification}/DatabaseChangeSet.swift (100%) rename Sources/DataThespian/{ => Notification}/DatabaseChangeType.swift (100%) rename Sources/DataThespian/{ => Notification}/DatabaseMonitoring.swift (100%) rename Sources/DataThespian/{ => Notification}/ManagedObjectMetadata.swift (100%) rename Sources/DataThespian/{ => Notification}/Notification.swift (100%) rename Sources/DataThespian/{ => Notification}/NotificationDataUpdate.swift (100%) rename Sources/DataThespian/{ => Notification}/RegistrationCollection.swift (100%) rename Sources/DataThespian/{ => SwiftData}/FetchDescriptor.swift (98%) rename Sources/DataThespian/{ => SwiftData}/ModelContext+Extension.swift (95%) rename Sources/DataThespian/{ => SwiftData}/ModelContext.swift (92%) rename Sources/DataThespian/{ => SwiftData}/NSManagedObjectID.swift (100%) diff --git a/Sources/DataThespian/BackgroundDatabase.swift b/Sources/DataThespian/Databases/BackgroundDatabase.swift similarity index 100% rename from Sources/DataThespian/BackgroundDatabase.swift rename to Sources/DataThespian/Databases/BackgroundDatabase.swift diff --git a/Sources/DataThespian/Database+Extras.swift b/Sources/DataThespian/Databases/Database+Extras.swift similarity index 100% rename from Sources/DataThespian/Database+Extras.swift rename to Sources/DataThespian/Databases/Database+Extras.swift diff --git a/Sources/DataThespian/Database+ModelContext.swift b/Sources/DataThespian/Databases/Database+ModelContext.swift similarity index 100% rename from Sources/DataThespian/Database+ModelContext.swift rename to Sources/DataThespian/Databases/Database+ModelContext.swift diff --git a/Sources/DataThespian/Database.swift b/Sources/DataThespian/Databases/Database.swift similarity index 100% rename from Sources/DataThespian/Database.swift rename to Sources/DataThespian/Databases/Database.swift diff --git a/Sources/DataThespian/DatabaseKey.swift b/Sources/DataThespian/Databases/EnvironmentValues+Database.swift similarity index 88% rename from Sources/DataThespian/DatabaseKey.swift rename to Sources/DataThespian/Databases/EnvironmentValues+Database.swift index 3c2d0fd..3509da2 100644 --- a/Sources/DataThespian/DatabaseKey.swift +++ b/Sources/DataThespian/Databases/EnvironmentValues+Database.swift @@ -42,15 +42,8 @@ } } - private struct DatabaseKey: EnvironmentKey { - static var defaultValue: any Database { DefaultDatabase.instance } - } - extension EnvironmentValues { - public var database: any Database { - get { self[DatabaseKey.self] } - set { self[DatabaseKey.self] = newValue } - } + @Entry public var database: any Database = DefaultDatabase.instance } extension Scene { diff --git a/Sources/DataThespian/ModelActor+Database.swift b/Sources/DataThespian/Databases/ModelActor+Database.swift similarity index 100% rename from Sources/DataThespian/ModelActor+Database.swift rename to Sources/DataThespian/Databases/ModelActor+Database.swift diff --git a/Sources/DataThespian/ModelActorDatabase.swift b/Sources/DataThespian/Databases/ModelActorDatabase.swift similarity index 100% rename from Sources/DataThespian/ModelActorDatabase.swift rename to Sources/DataThespian/Databases/ModelActorDatabase.swift diff --git a/Sources/DataThespian/AgentRegister.swift b/Sources/DataThespian/Notification/AgentRegister.swift similarity index 100% rename from Sources/DataThespian/AgentRegister.swift rename to Sources/DataThespian/Notification/AgentRegister.swift diff --git a/Sources/DataThespian/DatabaseChangePublicist.swift b/Sources/DataThespian/Notification/Combine/DatabaseChangePublicist.swift similarity index 100% rename from Sources/DataThespian/DatabaseChangePublicist.swift rename to Sources/DataThespian/Notification/Combine/DatabaseChangePublicist.swift diff --git a/Sources/DataThespian/DatabaseChangePublicistKey.swift b/Sources/DataThespian/Notification/Combine/DatabaseChangePublicistKey.swift similarity index 78% rename from Sources/DataThespian/DatabaseChangePublicistKey.swift rename to Sources/DataThespian/Notification/Combine/DatabaseChangePublicistKey.swift index 1f3b4e6..0035876 100644 --- a/Sources/DataThespian/DatabaseChangePublicistKey.swift +++ b/Sources/DataThespian/Notification/Combine/DatabaseChangePublicistKey.swift @@ -32,16 +32,7 @@ public import SwiftUI - private struct DatabaseChangePublicistKey: EnvironmentKey { - typealias Value = DatabaseChangePublicist - - nonisolated static let defaultValue: DatabaseChangePublicist = .never() - } - extension EnvironmentValues { - public var databaseChangePublicist: DatabaseChangePublicist { - get { self[DatabaseChangePublicistKey.self] } - set { self[DatabaseChangePublicistKey.self] = newValue } - } + @Entry public var databaseChangePublicist: DatabaseChangePublicist = .never() } #endif diff --git a/Sources/DataThespian/PublishingAgent.swift b/Sources/DataThespian/Notification/Combine/PublishingAgent.swift similarity index 100% rename from Sources/DataThespian/PublishingAgent.swift rename to Sources/DataThespian/Notification/Combine/PublishingAgent.swift diff --git a/Sources/DataThespian/PublishingRegister.swift b/Sources/DataThespian/Notification/Combine/PublishingRegister.swift similarity index 100% rename from Sources/DataThespian/PublishingRegister.swift rename to Sources/DataThespian/Notification/Combine/PublishingRegister.swift diff --git a/Sources/DataThespian/DataAgent.swift b/Sources/DataThespian/Notification/DataAgent.swift similarity index 100% rename from Sources/DataThespian/DataAgent.swift rename to Sources/DataThespian/Notification/DataAgent.swift diff --git a/Sources/DataThespian/DataMonitor.swift b/Sources/DataThespian/Notification/DataMonitor.swift similarity index 100% rename from Sources/DataThespian/DataMonitor.swift rename to Sources/DataThespian/Notification/DataMonitor.swift diff --git a/Sources/DataThespian/DatabaseChangeSet.swift b/Sources/DataThespian/Notification/DatabaseChangeSet.swift similarity index 100% rename from Sources/DataThespian/DatabaseChangeSet.swift rename to Sources/DataThespian/Notification/DatabaseChangeSet.swift diff --git a/Sources/DataThespian/DatabaseChangeType.swift b/Sources/DataThespian/Notification/DatabaseChangeType.swift similarity index 100% rename from Sources/DataThespian/DatabaseChangeType.swift rename to Sources/DataThespian/Notification/DatabaseChangeType.swift diff --git a/Sources/DataThespian/DatabaseMonitoring.swift b/Sources/DataThespian/Notification/DatabaseMonitoring.swift similarity index 100% rename from Sources/DataThespian/DatabaseMonitoring.swift rename to Sources/DataThespian/Notification/DatabaseMonitoring.swift diff --git a/Sources/DataThespian/ManagedObjectMetadata.swift b/Sources/DataThespian/Notification/ManagedObjectMetadata.swift similarity index 100% rename from Sources/DataThespian/ManagedObjectMetadata.swift rename to Sources/DataThespian/Notification/ManagedObjectMetadata.swift diff --git a/Sources/DataThespian/Notification.swift b/Sources/DataThespian/Notification/Notification.swift similarity index 100% rename from Sources/DataThespian/Notification.swift rename to Sources/DataThespian/Notification/Notification.swift diff --git a/Sources/DataThespian/NotificationDataUpdate.swift b/Sources/DataThespian/Notification/NotificationDataUpdate.swift similarity index 100% rename from Sources/DataThespian/NotificationDataUpdate.swift rename to Sources/DataThespian/Notification/NotificationDataUpdate.swift diff --git a/Sources/DataThespian/RegistrationCollection.swift b/Sources/DataThespian/Notification/RegistrationCollection.swift similarity index 100% rename from Sources/DataThespian/RegistrationCollection.swift rename to Sources/DataThespian/Notification/RegistrationCollection.swift diff --git a/Sources/DataThespian/FetchDescriptor.swift b/Sources/DataThespian/SwiftData/FetchDescriptor.swift similarity index 98% rename from Sources/DataThespian/FetchDescriptor.swift rename to Sources/DataThespian/SwiftData/FetchDescriptor.swift index 1ced50d..a421568 100644 --- a/Sources/DataThespian/FetchDescriptor.swift +++ b/Sources/DataThespian/SwiftData/FetchDescriptor.swift @@ -38,6 +38,8 @@ self.fetchLimit = fetchLimit } + + @available(*, deprecated) public init(model: Model) { let persistentIdentifier = model.persistentIdentifier self.init( diff --git a/Sources/DataThespian/ModelContext+Extension.swift b/Sources/DataThespian/SwiftData/ModelContext+Extension.swift similarity index 95% rename from Sources/DataThespian/ModelContext+Extension.swift rename to Sources/DataThespian/SwiftData/ModelContext+Extension.swift index 3013d03..037f18c 100644 --- a/Sources/DataThespian/ModelContext+Extension.swift +++ b/Sources/DataThespian/SwiftData/ModelContext+Extension.swift @@ -32,6 +32,7 @@ public import SwiftData extension ModelContext { + @available(*, deprecated) public func delete(_: T.Type, withID id: PersistentIdentifier) -> Bool { guard let model: T = self.registeredModel(for: id) else { return false @@ -51,6 +52,7 @@ self.insert(model) return model.persistentModelID } + public func fetch( _ selectDescriptor: @escaping @Sendable () -> FetchDescriptor, with closure: @escaping @Sendable ([T]) throws -> U @@ -58,6 +60,8 @@ let models = try self.fetch(selectDescriptor()) return try closure(models) } + + @available(*, deprecated) public func fetch( _ selectDescriptorA: @escaping @Sendable () -> FetchDescriptor, _ selectDescriptorB: @escaping @Sendable () -> FetchDescriptor, @@ -68,13 +72,15 @@ return try closure(firstModels, secondModels) } + @available(*, deprecated) public func get( for objectID: PersistentIdentifier, with closure: @escaping @Sendable (T?) throws -> U ) throws -> U where T: PersistentModel, U: Sendable { let model: T? = try self.existingModel(for: objectID) return try closure(model) } - + + @available(*, deprecated) public func transaction(block: @escaping @Sendable (ModelContext) throws -> Void) throws { try self.transaction { try block(self) } } diff --git a/Sources/DataThespian/ModelContext.swift b/Sources/DataThespian/SwiftData/ModelContext.swift similarity index 92% rename from Sources/DataThespian/ModelContext.swift rename to Sources/DataThespian/SwiftData/ModelContext.swift index 422fae3..f5c515f 100644 --- a/Sources/DataThespian/ModelContext.swift +++ b/Sources/DataThespian/SwiftData/ModelContext.swift @@ -29,10 +29,11 @@ #if canImport(SwiftData) import Foundation - public import SwiftData + import SwiftData extension ModelContext { - public func existingModel(for objectID: PersistentIdentifier) throws -> T? + + internal func existingModel(for objectID: PersistentIdentifier) throws -> T? where T: PersistentModel { if let registered: T = registeredModel(for: objectID) { return registered @@ -42,7 +43,8 @@ } let fetchDescriptor = FetchDescriptor( - predicate: #Predicate { $0.persistentModelID == objectID } + predicate: #Predicate { $0.persistentModelID == objectID }, + fetchLimit: 1 ) return try fetch(fetchDescriptor).first diff --git a/Sources/DataThespian/NSManagedObjectID.swift b/Sources/DataThespian/SwiftData/NSManagedObjectID.swift similarity index 100% rename from Sources/DataThespian/NSManagedObjectID.swift rename to Sources/DataThespian/SwiftData/NSManagedObjectID.swift