From 502f82ad14331b6a93ae8e7c258318dbaaa14d23 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Wed, 12 Jun 2019 19:11:43 -0700 Subject: [PATCH] Rename EntityProxy to ResourceObjectProxy and EntityType to ResourceObjectType. --- Sources/JSONAPI/Resource/Relationship.swift | 12 +++++----- Sources/JSONAPI/Resource/ResourceObject.swift | 22 +++++++++---------- Tests/JSONAPITests/Poly/PolyProxyTests.swift | 2 +- .../EncodedEntityPropertyTest.swift | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Sources/JSONAPI/Resource/Relationship.swift b/Sources/JSONAPI/Resource/Relationship.swift index 7b2ca68..2af4d04 100644 --- a/Sources/JSONAPI/Resource/Relationship.swift +++ b/Sources/JSONAPI/Resource/Relationship.swift @@ -38,25 +38,25 @@ extension ToOneRelationship where MetaType == NoMetadata, LinksType == NoLinks { } extension ToOneRelationship { - public init(entity: E, meta: MetaType, links: LinksType) where E.Id == Identifiable.Identifier { + public init(entity: E, meta: MetaType, links: LinksType) where E.Id == Identifiable.Identifier { self.init(id: entity.id, meta: meta, links: links) } } extension ToOneRelationship where MetaType == NoMetadata, LinksType == NoLinks { - public init(entity: E) where E.Id == Identifiable.Identifier { + public init(entity: E) where E.Id == Identifiable.Identifier { self.init(id: entity.id, meta: .none, links: .none) } } extension ToOneRelationship where Identifiable: OptionalRelatable { - public init(entity: E?, meta: MetaType, links: LinksType) where E.Id == Identifiable.Wrapped.Identifier { + public init(entity: E?, meta: MetaType, links: LinksType) where E.Id == Identifiable.Wrapped.Identifier { self.init(id: entity?.id, meta: meta, links: links) } } extension ToOneRelationship where Identifiable: OptionalRelatable, MetaType == NoMetadata, LinksType == NoLinks { - public init(entity: E?) where E.Id == Identifiable.Wrapped.Identifier { + public init(entity: E?) where E.Id == Identifiable.Wrapped.Identifier { self.init(id: entity?.id, meta: .none, links: .none) } } @@ -84,7 +84,7 @@ public struct ToManyRelationship(entities: [E], meta: MetaType, links: LinksType) where E.Id == Relatable.Identifier { + public init(entities: [E], meta: MetaType, links: LinksType) where E.Id == Relatable.Identifier { self.init(ids: entities.map { $0.id }, meta: meta, links: links) } @@ -111,7 +111,7 @@ extension ToManyRelationship where MetaType == NoMetadata, LinksType == NoLinks return .none(withMeta: .none, links: .none) } - public init(entities: [E]) where E.Id == Relatable.Identifier { + public init(entities: [E]) where E.Id == Relatable.Identifier { self.init(entities: entities, meta: .none, links: .none) } } diff --git a/Sources/JSONAPI/Resource/ResourceObject.swift b/Sources/JSONAPI/Resource/ResourceObject.swift index 4081145..89cdc52 100644 --- a/Sources/JSONAPI/Resource/ResourceObject.swift +++ b/Sources/JSONAPI/Resource/ResourceObject.swift @@ -54,10 +54,10 @@ public protocol ResourceObjectProxyDescription: JSONTyped { /// `ResourceObjectDescription`. public protocol ResourceObjectDescription: ResourceObjectProxyDescription where Attributes: JSONAPI.Attributes, Relationships: JSONAPI.Relationships {} -/// EntityProxy is a protocol that can be used to create +/// ResourceObjectProxy is a protocol that can be used to create /// types that _act_ like Entities but cannot be encoded /// or decoded as Entities. -public protocol EntityProxy: Equatable, JSONTyped { +public protocol ResourceObjectProxy: Equatable, JSONTyped { associatedtype Description: ResourceObjectProxyDescription associatedtype EntityRawIdType: JSONAPI.MaybeRawId @@ -79,26 +79,26 @@ public protocol EntityProxy: Equatable, JSONTyped { var relationships: Relationships { get } } -extension EntityProxy { +extension ResourceObjectProxy { /// The JSON API compliant "type" of this `Entity`. public static var jsonType: String { return Description.jsonType } } -/// EntityType is the protocol that Entity conforms to. This +/// ResourceObjectType is the protocol that Entity conforms to. This /// protocol lets other types accept any Entity as a generic /// specialization. -public protocol EntityType: EntityProxy, PrimaryResource where Description: ResourceObjectDescription { +public protocol ResourceObjectType: ResourceObjectProxy, PrimaryResource where Description: ResourceObjectDescription { associatedtype Meta: JSONAPI.Meta associatedtype Links: JSONAPI.Links } -public protocol IdentifiableEntityType: EntityType, Relatable where EntityRawIdType: JSONAPI.RawIdType {} +public protocol IdentifiableEntityType: ResourceObjectType, Relatable where EntityRawIdType: JSONAPI.RawIdType {} /// An `Entity` is a single model type that can be /// encoded to or decoded from a JSON API /// "Resource Object." /// See https://jsonapi.org/format/#document-resource-objects -public struct Entity: EntityType { +public struct Entity: ResourceObjectType { public typealias Meta = MetaType public typealias Links = LinksType @@ -437,7 +437,7 @@ public extension Entity where EntityRawIdType: CreatableRawIdType { } // MARK: Attribute Access -public extension EntityProxy { +public extension ResourceObjectProxy { /// Access the attribute at the given keypath. This just /// allows you to write `entity[\.propertyName]` instead /// of `entity.attributes.propertyName`. @@ -475,7 +475,7 @@ public extension EntityProxy { } // MARK: Meta-Attribute Access -public extension EntityProxy { +public extension ResourceObjectProxy { /// Access an attribute requiring a transformation on the RawValue _and_ /// a secondary transformation on this entity (self). subscript(_ path: KeyPath T>) -> T { @@ -484,7 +484,7 @@ public extension EntityProxy { } // MARK: Relationship Access -public extension EntityProxy { +public extension ResourceObjectProxy { /// Access to an Id of a `ToOneRelationship`. /// This allows you to write `entity ~> \.other` instead /// of `entity.relationships.other.id`. @@ -526,7 +526,7 @@ public extension EntityProxy { } // MARK: Meta-Relationship Access -public extension EntityProxy { +public extension ResourceObjectProxy { /// Access to an Id of a `ToOneRelationship`. /// This allows you to write `entity ~> \.other` instead /// of `entity.relationships.other.id`. diff --git a/Tests/JSONAPITests/Poly/PolyProxyTests.swift b/Tests/JSONAPITests/Poly/PolyProxyTests.swift index 29dca66..3d12259 100644 --- a/Tests/JSONAPITests/Poly/PolyProxyTests.swift +++ b/Tests/JSONAPITests/Poly/PolyProxyTests.swift @@ -92,7 +92,7 @@ public extension PolyProxyTests { typealias User = Poly2 } -extension Poly2: EntityProxy, JSONTyped where A == PolyProxyTests.UserA, B == PolyProxyTests.UserB { +extension Poly2: ResourceObjectProxy, JSONTyped where A == PolyProxyTests.UserA, B == PolyProxyTests.UserB { public var userA: PolyProxyTests.UserA? { return a diff --git a/Tests/JSONAPITests/Test Helpers/EncodedEntityPropertyTest.swift b/Tests/JSONAPITests/Test Helpers/EncodedEntityPropertyTest.swift index e7de8b7..16bfa52 100644 --- a/Tests/JSONAPITests/Test Helpers/EncodedEntityPropertyTest.swift +++ b/Tests/JSONAPITests/Test Helpers/EncodedEntityPropertyTest.swift @@ -10,7 +10,7 @@ import XCTest import JSONAPI import JSONAPITesting -func testEncoded(entity: E) { +func testEncoded(entity: E) { let encodedEntityData = encoded(value: entity) let jsonObject = try! JSONSerialization.jsonObject(with: encodedEntityData, options: []) let jsonDict = jsonObject as? [String: Any]