feat(ios): HapiProtocol wire models, catalogs, session patching (A-M1a)

This commit is contained in:
weishu
2026-08-17 12:31:34 +08:00
parent fada270424
commit 1e80327d76
21 changed files with 2992 additions and 19 deletions
@@ -0,0 +1,32 @@
import Foundation
/// A pass-through coding key used to enumerate whatever keys a JSON object
/// actually carries (the synthesized `CodingKeys` enums cannot represent
/// unknown keys).
struct AnyCodingKey: CodingKey {
let stringValue: String
let intValue: Int?
init?(stringValue: String) {
self.stringValue = stringValue
self.intValue = nil
}
init?(intValue: Int) {
self.stringValue = String(intValue)
self.intValue = intValue
}
}
/// Mirror of zod's `.strict()`: throw when the payload carries a key outside
/// `known`. Used by the patch types whose strictness discriminates the
/// `Session | SessionPatch` and `Machine | MachinePatch | null` unions.
func rejectUnknownKeys(in decoder: Decoder, known: Set<String>, payloadName: String) throws {
let container = try decoder.container(keyedBy: AnyCodingKey.self)
for key in container.allKeys where !known.contains(key.stringValue) {
throw DecodingError.dataCorrupted(DecodingError.Context(
codingPath: decoder.codingPath,
debugDescription: "Unknown key '\(key.stringValue)' in strict \(payloadName) payload"
))
}
}