Update Migrations, Models

Summary:
- Sources: update 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 8e3e754e43
commit c021333e9e
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 let destinationKey: StorageKey<Value>
public let sourceKeys: [AnyStorageKey]
public let aggregateAction: ([AnyCodable]) async throws -> Value
public let aggregateAction: @Sendable ([AnyCodable]) async throws -> Value
public init(
destinationKey: StorageKey<Value>,
sourceKeys: [AnyStorageKey],
aggregate: @escaping ([AnyCodable]) async throws -> Value
aggregate: @escaping @Sendable ([AnyCodable]) async throws -> Value
) {
self.destinationKey = destinationKey
self.sourceKeys = sourceKeys

View File

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

View File

@ -9,8 +9,12 @@ public struct AnyStorageMigration: Sendable {
public init<M: StorageMigration>(_ migration: M) {
self.destinationDescriptor = .from(migration.destinationKey)
self.shouldMigrateAction = migration.shouldMigrate
self.migrateAction = migration.migrate
self.shouldMigrateAction = { @Sendable router, context in
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 {