Update Migrations, Models

Summary:
- Sources: Migrations, Models

Stats:
- 3 files changed, 10 insertions(+), 6 deletions(-)
This commit is contained in:
Matt Bruce 2026-01-17 09:35:42 -06:00
parent 0afaf34c78
commit 7520d195a2
3 changed files with 10 additions and 6 deletions

View File

@ -3,12 +3,12 @@ import Foundation
public struct DefaultAggregatingMigration<Value: Codable & Sendable>: AggregatingMigration { public struct DefaultAggregatingMigration<Value: Codable & Sendable>: AggregatingMigration {
public let destinationKey: StorageKey<Value> public let destinationKey: StorageKey<Value>
public let sourceKeys: [AnyStorageKey] public let sourceKeys: [AnyStorageKey]
public let aggregateAction: ([AnyCodable]) async throws -> Value public let aggregateAction: @Sendable ([AnyCodable]) async throws -> Value
public init( public init(
destinationKey: StorageKey<Value>, destinationKey: StorageKey<Value>,
sourceKeys: [AnyStorageKey], sourceKeys: [AnyStorageKey],
aggregate: @escaping ([AnyCodable]) async throws -> Value aggregate: @escaping @Sendable ([AnyCodable]) async throws -> Value
) { ) {
self.destinationKey = destinationKey self.destinationKey = destinationKey
self.sourceKeys = sourceKeys self.sourceKeys = sourceKeys

View File

@ -3,12 +3,12 @@ import Foundation
public struct DefaultTransformingMigration<SourceValue: Codable & Sendable, DestinationValue: Codable & Sendable>: TransformingMigration { public struct DefaultTransformingMigration<SourceValue: Codable & Sendable, DestinationValue: Codable & Sendable>: TransformingMigration {
public let destinationKey: StorageKey<DestinationValue> public let destinationKey: StorageKey<DestinationValue>
public let sourceKey: StorageKey<SourceValue> public let sourceKey: StorageKey<SourceValue>
public let transformAction: (SourceValue) async throws -> DestinationValue public let transformAction: @Sendable (SourceValue) async throws -> DestinationValue
public init( public init(
destinationKey: StorageKey<DestinationValue>, destinationKey: StorageKey<DestinationValue>,
sourceKey: StorageKey<SourceValue>, sourceKey: StorageKey<SourceValue>,
transform: @escaping (SourceValue) async throws -> DestinationValue transform: @escaping @Sendable (SourceValue) async throws -> DestinationValue
) { ) {
self.destinationKey = destinationKey self.destinationKey = destinationKey
self.sourceKey = sourceKey self.sourceKey = sourceKey

View File

@ -9,8 +9,12 @@ public struct AnyStorageMigration: Sendable {
public init<M: StorageMigration>(_ migration: M) { public init<M: StorageMigration>(_ migration: M) {
self.destinationDescriptor = .from(migration.destinationKey) self.destinationDescriptor = .from(migration.destinationKey)
self.shouldMigrateAction = migration.shouldMigrate self.shouldMigrateAction = { @Sendable router, context in
self.migrateAction = migration.migrate try await migration.shouldMigrate(using: router, context: context)
}
self.migrateAction = { @Sendable router, context in
try await migration.migrate(using: router, context: context)
}
} }
public func shouldMigrate(using router: StorageRouter, context: MigrationContext) async throws -> Bool { public func shouldMigrate(using router: StorageRouter, context: MigrationContext) async throws -> Bool {