Update Models + docs

Summary:
- Sources: Models
- Docs: README

Stats:
- 3 files changed, 16 insertions(+), 10 deletions(-)
This commit is contained in:
Matt Bruce 2026-01-14 10:25:10 -06:00
parent bd96135d3b
commit 91aa0df7f4
3 changed files with 16 additions and 10 deletions

View File

@ -161,8 +161,8 @@ LocalData can generate a catalog of all configured storage keys, even if no data
struct AppStorageCatalog: StorageKeyCatalog { struct AppStorageCatalog: StorageKeyCatalog {
static var allKeys: [StorageKeyDescriptor] { static var allKeys: [StorageKeyDescriptor] {
[ [
.from(StorageKeys.AppVersionKey(), serializer: "json"), .from(StorageKeys.AppVersionKey(), serializer: .json),
.from(StorageKeys.UserPreferencesKey(), serializer: "json") .from(StorageKeys.UserPreferencesKey(), serializer: .json)
] ]
} }
} }

View File

@ -3,39 +3,45 @@ import Foundation
public struct Serializer<Value: Codable & Sendable>: Sendable { public struct Serializer<Value: Codable & Sendable>: Sendable {
public let encode: @Sendable (Value) throws -> Data public let encode: @Sendable (Value) throws -> Data
public let decode: @Sendable (Data) throws -> Value public let decode: @Sendable (Data) throws -> Value
public let name: String
public init( public init(
encode: @escaping @Sendable (Value) throws -> Data, encode: @escaping @Sendable (Value) throws -> Data,
decode: @escaping @Sendable (Data) throws -> Value decode: @escaping @Sendable (Data) throws -> Value,
name: String = "custom"
) { ) {
self.encode = encode self.encode = encode
self.decode = decode self.decode = decode
self.name = name
} }
public static var json: Serializer<Value> { public static var json: Serializer<Value> {
Serializer<Value>( Serializer<Value>(
encode: { try JSONEncoder().encode($0) }, encode: { try JSONEncoder().encode($0) },
decode: { try JSONDecoder().decode(Value.self, from: $0) } decode: { try JSONDecoder().decode(Value.self, from: $0) },
name: "json"
) )
} }
public static var plist: Serializer<Value> { public static var plist: Serializer<Value> {
Serializer<Value>( Serializer<Value>(
encode: { try PropertyListEncoder().encode($0) }, encode: { try PropertyListEncoder().encode($0) },
decode: { try PropertyListDecoder().decode(Value.self, from: $0) } decode: { try PropertyListDecoder().decode(Value.self, from: $0) },
name: "plist"
) )
} }
public static func custom( public static func custom(
encode: @escaping @Sendable (Value) throws -> Data, encode: @escaping @Sendable (Value) throws -> Data,
decode: @escaping @Sendable (Data) throws -> Value decode: @escaping @Sendable (Data) throws -> Value,
name: String = "custom"
) -> Serializer<Value> { ) -> Serializer<Value> {
Serializer<Value>(encode: encode, decode: decode) Serializer<Value>(encode: encode, decode: decode, name: name)
} }
} }
public extension Serializer where Value == Data { public extension Serializer where Value == Data {
static var data: Serializer<Value> { static var data: Serializer<Value> {
Serializer<Value>(encode: { $0 }, decode: { $0 }) Serializer<Value>(encode: { $0 }, decode: { $0 }, name: "data")
} }
} }

View File

@ -35,14 +35,14 @@ public struct StorageKeyDescriptor: Sendable {
public static func from<Key: StorageKey>( public static func from<Key: StorageKey>(
_ key: Key, _ key: Key,
serializer: String, serializer: Serializer<Key.Value>,
notes: String? = nil notes: String? = nil
) -> StorageKeyDescriptor { ) -> StorageKeyDescriptor {
StorageKeyDescriptor( StorageKeyDescriptor(
name: key.name, name: key.name,
domain: key.domain, domain: key.domain,
security: key.security, security: key.security,
serializer: serializer, serializer: serializer.name,
valueType: String(describing: Key.Value.self), valueType: String(describing: Key.Value.self),
owner: key.owner, owner: key.owner,
availability: key.availability, availability: key.availability,