LocalData/Sources/LocalData/Models/StorageKeyDescriptor.swift
Matt Bruce f3f42c7844 Update Audit, Helpers, Migrations (+4 more)
Summary:
- Sources: Audit, Helpers, Migrations, Models, Protocols (+2 more)

Stats:
- 27 files changed, 303 insertions(+), 12 deletions(-)
2026-01-18 14:53:31 -06:00

93 lines
3.0 KiB
Swift

import Foundation
/// Snapshot of a ``StorageKey`` used for audit and registration.
public struct StorageKeyDescriptor: Sendable, CustomStringConvertible {
/// Key name within its domain.
public let name: String
/// Storage domain for the key.
public let domain: StorageDomain
/// Security policy applied to the key.
public let security: SecurityPolicy
/// Serializer name used for encoding/decoding.
public let serializer: String
/// String representation of the value type.
public let valueType: String
/// Owning module or feature name.
public let owner: String
/// Platform availability for the key.
public let availability: PlatformAvailability
/// Sync policy for WatchConnectivity.
public let syncPolicy: SyncPolicy
/// Human-readable description for audit reports.
public let description: String
/// Optional catalog name the key belongs to.
public let catalog: String?
init(
name: String,
domain: StorageDomain,
security: SecurityPolicy,
serializer: String,
valueType: String,
owner: String,
availability: PlatformAvailability,
syncPolicy: SyncPolicy,
description: String,
catalog: String? = nil
) {
self.name = name
self.domain = domain
self.security = security
self.serializer = serializer
self.valueType = valueType
self.owner = owner
self.availability = availability
self.syncPolicy = syncPolicy
self.description = description
self.catalog = catalog
}
/// Builds a descriptor from a ``StorageKey``.
///
/// - Parameters:
/// - key: The key to describe.
/// - catalog: Optional catalog name for audit context.
/// - Returns: A populated ``StorageKeyDescriptor``.
public static func from<Value>(
_ key: StorageKey<Value>,
catalog: String? = nil
) -> StorageKeyDescriptor {
StorageKeyDescriptor(
name: key.name,
domain: key.domain,
security: key.security,
serializer: key.serializer.name,
valueType: String(describing: Value.self),
owner: key.owner,
availability: key.availability,
syncPolicy: key.syncPolicy,
description: key.description,
catalog: catalog
)
}
/// Returns a new descriptor with the catalog name set.
///
/// - Parameter catalogName: Catalog name to assign.
/// - Returns: A new descriptor with the catalog field set.
public func withCatalog(_ catalogName: String) -> StorageKeyDescriptor {
StorageKeyDescriptor(
name: self.name,
domain: domain,
security: security,
serializer: serializer,
valueType: valueType,
owner: owner,
availability: availability,
syncPolicy: syncPolicy,
description: description,
catalog: catalogName
)
}
}