@@ -298,6 +298,30 @@ extension Delta: Encodable where Element: Encodable {
298
298
}
299
299
}
300
300
301
+ #if canImport(Foundation)
302
+ import Foundation
303
+
304
+ @available ( macOS 12 , * )
305
+ extension Delta : EncodableWithConfiguration where Element: EncodableWithConfiguration {
306
+ public typealias EncodingConfiguration = Element . EncodingConfiguration
307
+
308
+ public func encode( to encoder: any Encoder , configuration: Element . EncodingConfiguration ) throws {
309
+ switch self {
310
+ case . source( let source) :
311
+ var container = encoder. container ( keyedBy: CodingKeys . self)
312
+ try container. encode ( source, forKey: . source, configuration: configuration)
313
+ case . target( let target) :
314
+ var container = encoder. container ( keyedBy: CodingKeys . self)
315
+ try container. encode ( target, forKey: . target, configuration: configuration)
316
+ case . transition( let source, let target) :
317
+ var container = encoder. container ( keyedBy: CodingKeys . self)
318
+ try container. encode ( source, forKey: . source, configuration: configuration)
319
+ try container. encode ( target, forKey: . target, configuration: configuration)
320
+ }
321
+ }
322
+ }
323
+ #endif
324
+
301
325
extension Delta : Decodable where Element: Decodable {
302
326
public init ( from decoder: any Decoder ) throws {
303
327
let container = try decoder. container ( keyedBy: CodingKeys . self)
@@ -319,6 +343,34 @@ extension Delta: Decodable where Element: Decodable {
319
343
}
320
344
}
321
345
346
+ #if canImport(Foundation)
347
+ import Foundation
348
+
349
+ @available ( macOS 12 , * )
350
+ extension Delta : DecodableWithConfiguration where Element: DecodableWithConfiguration {
351
+ public typealias DecodingConfiguration = Element . DecodingConfiguration
352
+
353
+ public init ( from decoder: any Decoder , configuration: Element . DecodingConfiguration ) throws {
354
+ let container = try decoder. container ( keyedBy: CodingKeys . self)
355
+ let source = try container. decodeIfPresent ( Element . self, forKey: . source, configuration: configuration)
356
+ let target = try container. decodeIfPresent ( Element . self, forKey: . target, configuration: configuration)
357
+
358
+ if let source, let target {
359
+ self = . transition( source: source, target: target)
360
+ }
361
+ else if let source {
362
+ self = . source( source)
363
+ }
364
+ else if let target {
365
+ self = . target( target)
366
+ }
367
+ else {
368
+ throw DecodingError . dataCorrupted ( DecodingError . Context ( codingPath: decoder. codingPath, debugDescription: " No source or target value. " ) )
369
+ }
370
+ }
371
+ }
372
+ #endif
373
+
322
374
extension Delta : Sendable where Element: Sendable { }
323
375
324
376
extension Delta : BitwiseCopyable where Element: BitwiseCopyable { }
0 commit comments