diff --git a/Sources/VergeNormalizationDerived/EntityType+Typealias.swift b/Sources/VergeNormalizationDerived/EntityType+Typealias.swift index 2cd76507b5..9f36dd7e9b 100644 --- a/Sources/VergeNormalizationDerived/EntityType+Typealias.swift +++ b/Sources/VergeNormalizationDerived/EntityType+Typealias.swift @@ -1,7 +1,21 @@ - extension EntityType { public typealias Derived = Verge.Derived> public typealias NonNullDerived = Verge.Derived> } + +extension Derived where Value: NonNullEntityWrapperType { + + public var entityID: Value.Entity.TypedID { + self.state.id + } +} + +extension Derived where Value: EntityWrapperType { + + public var entityID: Value.Entity.TypedID? { + self.state.id + } + +} diff --git a/Sources/VergeNormalizationDerived/EntityWrapper.swift b/Sources/VergeNormalizationDerived/EntityWrapper.swift index bbe1f376fa..fb484e0502 100644 --- a/Sources/VergeNormalizationDerived/EntityWrapper.swift +++ b/Sources/VergeNormalizationDerived/EntityWrapper.swift @@ -1,9 +1,16 @@ import Normalization +public protocol EntityWrapperType { + associatedtype Entity: EntityType + + var id: Entity.TypedID { get } +} + /// A value that wraps an entity and results of fetching. -public struct EntityWrapper: Sendable { +public struct EntityWrapper: Sendable, EntityWrapperType { - public private(set) var wrapped: Entity? + public let wrapped: Entity? + public let id: Entity.TypedID public init(id: Entity.TypedID, entity: Entity?) { diff --git a/Sources/VergeNormalizationDerived/NonNullEntityWrapper.swift b/Sources/VergeNormalizationDerived/NonNullEntityWrapper.swift index 6dd1186064..952485c6ab 100644 --- a/Sources/VergeNormalizationDerived/NonNullEntityWrapper.swift +++ b/Sources/VergeNormalizationDerived/NonNullEntityWrapper.swift @@ -1,11 +1,17 @@ import Normalization +public protocol NonNullEntityWrapperType { + associatedtype Entity: EntityType + + var id: Entity.TypedID { get } +} + /// A value that wraps an entity and results of fetching. @dynamicMemberLookup -public struct NonNullEntityWrapper { +public struct NonNullEntityWrapper: Sendable, NonNullEntityWrapperType { /// An entity value - public private(set) var wrapped: Entity + public let wrapped: Entity /// An identifier public let id: Entity.TypedID