Skip to content

Commit d667e91

Browse files
committed
Add some missing initializers for Entity and fix Playground sources.
1 parent 75c8ce7 commit d667e91

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

JSONAPI.playground/Sources/Entities.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension String: CreatableRawIdType {
2424
}
2525

2626
// MARK: - Entity typealias for convenience
27-
public typealias ExampleEntity<Description: EntityDescription> = Entity<Description, String>
27+
public typealias ExampleEntity<Description: EntityDescription> = Entity<Description, NoMetadata, NoLinks, String>
2828

2929
// MARK: - A few resource objects (entities)
3030
public enum PersonDescription: EntityDescription {
@@ -60,7 +60,7 @@ public enum PersonDescription: EntityDescription {
6060

6161
public typealias Person = ExampleEntity<PersonDescription>
6262

63-
public extension Entity where Description == PersonDescription, EntityRawIdType == String {
63+
public extension Entity where Description == PersonDescription, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == String {
6464
public init(id: Person.Id? = nil,name: [String], favoriteColor: String, friends: [Person], dogs: [Dog], home: House) throws {
6565
self = try Person(id: id ?? Person.Id(), attributes: .init(name: .init(rawValue: name), favoriteColor: .init(rawValue: favoriteColor)), relationships: .init(friends: .init(entities: friends), dogs: .init(entities: dogs), home: .init(entity: home)))
6666
}
@@ -89,7 +89,7 @@ public enum DogDescription: EntityDescription {
8989

9090
public typealias Dog = ExampleEntity<DogDescription>
9191

92-
public extension Entity where Description == DogDescription, EntityRawIdType == String {
92+
public extension Entity where Description == DogDescription, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == String {
9393
public init(name: String, owner: Person?) throws {
9494
self = try Dog(attributes: .init(name: .init(rawValue: name)), relationships: DogDescription.Relationships(owner: .init(entity: owner)))
9595
}

Sources/JSONAPI/Resource/Entity.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,36 @@ extension Entity where MetaType == NoMetadata {
320320
}
321321
}
322322

323+
extension Entity where MetaType == NoMetadata, EntityRawIdType: CreatableRawIdType {
324+
public init(attributes: Description.Attributes, relationships: Description.Relationships, links: LinksType) {
325+
self.init(attributes: attributes, relationships: relationships, meta: .none, links: links)
326+
}
327+
}
328+
323329
extension Entity where LinksType == NoLinks {
324330
public init(id: Entity.Id, attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType) {
325331
self.init(id: id, attributes: attributes, relationships: relationships, meta: meta, links: .none)
326332
}
327333
}
328334

335+
extension Entity where LinksType == NoLinks, EntityRawIdType: CreatableRawIdType {
336+
public init(attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType) {
337+
self.init(attributes: attributes, relationships: relationships, meta: meta, links: .none)
338+
}
339+
}
340+
329341
extension Entity where MetaType == NoMetadata, LinksType == NoLinks {
330342
public init(id: Entity.Id, attributes: Description.Attributes, relationships: Description.Relationships) {
331343
self.init(id: id, attributes: attributes, relationships: relationships, meta: .none, links: .none)
332344
}
333345
}
334346

347+
extension Entity where MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType: CreatableRawIdType {
348+
public init(attributes: Description.Attributes, relationships: Description.Relationships) {
349+
self.init(attributes: attributes, relationships: relationships, meta: .none, links: .none)
350+
}
351+
}
352+
335353
// MARK: Pointer for Relationships use.
336354
public extension Entity where EntityRawIdType: JSONAPI.RawIdType {
337355
/// Get a pointer to this entity that can be used as a

0 commit comments

Comments
 (0)