88public protocol AttributeType : Codable {
99}
1010
11+ // MARK: TransformedAttribute
12+ /// A TransformedAttribute takes a Codable type and attempts to turn it into another type.
1113public struct TransformedAttribute < RawValue: Codable , Transformer: JSONAPI . Transformer > : AttributeType where Transformer. From == RawValue {
1214 private let rawValue : RawValue
1315
@@ -19,6 +21,15 @@ public struct TransformedAttribute<RawValue: Codable, Transformer: JSONAPI.Trans
1921 }
2022}
2123
24+ // MARK: ValidatedAttribute
25+ /// A ValidatedAttribute does not transform its raw value, but it throws
26+ /// an error if the raw value does not match expectations.
27+ public typealias ValidatedAttribute < RawValue: Codable , Validator: JSONAPI . Validator > = TransformedAttribute < RawValue , Validator > where RawValue == Validator. From
28+
29+ // MARK: Attribute
30+ /// An Attribute simply represents a type that can be encoded and decoded.
31+ public typealias Attribute < T: Codable > = TransformedAttribute < T , IdentityTransformer < T > >
32+
2233extension TransformedAttribute where Transformer: ReversibleTransformer {
2334 public init ( transformedValue: Transformer . To ) throws {
2435 self . value = transformedValue
@@ -43,10 +54,6 @@ extension TransformedAttribute where Transformer == IdentityTransformer<RawValue
4354 }
4455}
4556
46- public typealias ValidatedAttribute < RawValue: Codable , Validator: JSONAPI . Validator > = TransformedAttribute < RawValue , Validator > where RawValue == Validator. From
47-
48- public typealias Attribute < T: Codable > = TransformedAttribute < T , IdentityTransformer < T > >
49-
5057// MARK: - Codable
5158extension TransformedAttribute {
5259 public init ( from decoder: Decoder ) throws {
0 commit comments