Skip to content

Commit 5401991

Browse files
committed
re-update documentation
1 parent 9027a7f commit 5401991

5 files changed

Lines changed: 17 additions & 17 deletions

File tree

JSONAPI.playground/Pages/Full Client & Server Example.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ typealias SingleArticleDocument = Document<SingleResourceBody<Article>, NoInclud
8686
func articleDocument(includeAuthor: Bool) -> Either<SingleArticleDocument, SingleArticleDocumentWithIncludes> {
8787
// Let's pretend all of this is coming from a database:
8888

89-
let authorId = Author.Identifier(rawValue: "1234")
89+
let authorId = Author.Id(rawValue: "1234")
9090

9191
let article = Article(id: .init(rawValue: "5678"),
9292
attributes: .init(title: .init(value: "JSON:API in Swift"),

JSONAPI.playground/Pages/Full Document Verbose Generation.xcplaygroundpage/Contents.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ enum ArticleDocumentError: String, JSONAPIError, Codable {
129129
typealias SingleArticleDocument = JSONAPI.Document<SingleResourceBody<Article>, DocumentMetadata, SingleArticleDocumentLinks, Include1<Author>, APIDescription<APIDescriptionMetadata>, ArticleDocumentError>
130130

131131
// MARK: - Instantiations
132-
let authorId1 = Author.Identifier()
133-
let authorId2 = Author.Identifier()
134-
let authorId3 = Author.Identifier()
132+
let authorId1 = Author.Id()
133+
let authorId2 = Author.Id()
134+
let authorId3 = Author.Id()
135135

136136
let now = Date()
137137
let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: now)!
@@ -155,7 +155,7 @@ let author1Links = EntityLinks(selfLink: .init(url: URL(string: "https://article
155155
meta: .init(expiry: tomorrow)))
156156
let author1 = Author(id: authorId1,
157157
attributes: .init(name: .init(value: "James Kinney")),
158-
relationships: .init(articles: .init(ids: [article.id, Article.Identifier(), Article.Identifier()],
158+
relationships: .init(articles: .init(ids: [article.id, Article.Id(), Article.Id()],
159159
meta: .init(pagination: .init(total: 3,
160160
limit: 50,
161161
offset: 0)),
@@ -167,7 +167,7 @@ let author2Links = EntityLinks(selfLink: .init(url: URL(string: "https://article
167167
meta: .init(expiry: tomorrow)))
168168
let author2 = Author(id: authorId2,
169169
attributes: .init(name: .init(value: "James Kinney")),
170-
relationships: .init(articles: .init(ids: [article.id, Article.Identifier()],
170+
relationships: .init(articles: .init(ids: [article.id, Article.Id()],
171171
meta: .init(pagination: .init(total: 2,
172172
limit: 50,
173173
offset: 0)),

JSONAPI.playground/Pages/Usage.xcplaygroundpage/Contents.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ let singleDogData = try! JSONEncoder().encode(singleDogDocument)
2020
// MARK: - Parse a request or response body with one Dog in it
2121
let dogResponse = try! JSONDecoder().decode(SingleDogDocument.self, from: singleDogData)
2222
let dogFromData = dogResponse.body.primaryResource?.value
23-
let dogOwner: Person.Identifier? = dogFromData.flatMap { $0 ~> \.owner }
23+
let dogOwner: Person.Id? = dogFromData.flatMap { $0 ~> \.owner }
2424

2525

2626
// MARK: - Parse a request or response body with one Dog in it using an alternative model
2727
typealias AltSingleDogDocument = JSONAPI.Document<SingleResourceBody<AlternativeDog>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, BasicJSONAPIError<String>>
2828
let altDogResponse = try! JSONDecoder().decode(AltSingleDogDocument.self, from: singleDogData)
2929
let altDogFromData = altDogResponse.body.primaryResource?.value
30-
let altDogHuman: Person.Identifier? = altDogFromData.flatMap { $0 ~> \.human }
30+
let altDogHuman: Person.Id? = altDogFromData.flatMap { $0 ~> \.human }
3131

3232

3333
// MARK: - Create a request or response with multiple people and dogs and houses included
34-
let personIds = [Person.Identifier(), Person.Identifier()]
34+
let personIds = [Person.Id(), Person.Id()]
3535
let dogs = try! [Dog(name: "Buddy", owner: personIds[0]), Dog(name: "Joy", owner: personIds[0]), Dog(name: "Travis", owner: personIds[1])]
3636
let houses = [House(attributes: .none, relationships: .none, meta: .none, links: .none), House(attributes: .none, relationships: .none, meta: .none, links: .none)]
3737
let people = try! [Person(id: personIds[0], name: ["Gary", "Doe"], favoriteColor: "Orange-Red", friends: [], dogs: [dogs[0], dogs[1]], home: houses[0]), Person(id: personIds[1], name: ["Elise", "Joy"], favoriteColor: "Red", friends: [], dogs: [dogs[2]], home: houses[1])]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ extension String: CreatableRawIdType {
151151

152152
// Create a typealias because we do not expect JSON:API Resource
153153
// Objects for this particular API to have Metadata or Links associated
154-
// with them. We also expect them to have String Identifiers.
154+
// with them. We also expect them to have String Ids.
155155
typealias JSONEntity<Description: ResourceObjectDescription> = JSONAPI.ResourceObject<Description, NoMetadata, NoLinks, String>
156156

157157
// Similarly, create a typealias for unidentified entities. JSON:API
@@ -220,7 +220,7 @@ typealias SingleArticleDocument = Document<SingleResourceBody<Article>, NoInclud
220220
func articleDocument(includeAuthor: Bool) -> Either<SingleArticleDocument, SingleArticleDocumentWithIncludes> {
221221
// Let's pretend all of this is coming from a database:
222222

223-
let authorId = Author.Identifier(rawValue: "1234")
223+
let authorId = Author.Id(rawValue: "1234")
224224

225225
let article = Article(id: .init(rawValue: "5678"),
226226
attributes: .init(title: .init(value: "JSON:API in Swift"),

documentation/usage.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ typealias Relationships = NoRelationships
167167

168168
`Relationship` values boil down to `Ids` of other resource objects. To access the `Id` of a related `ResourceObject`, you can use the custom `~>` operator with the `KeyPath` of the `Relationship` from which you want the `Id`. The friends of the above `Person` `ResourceObject` can be accessed as follows (type annotations for clarity):
169169
```swift
170-
let friendIds: [Person.Identifier] = person ~> \.friends
170+
let friendIds: [Person.Id] = person ~> \.friends
171171
```
172172

173173
### `JSONAPI.Attributes`
@@ -244,8 +244,8 @@ If your computed property is wrapped in a `AttributeType` then you can still use
244244

245245
### Copying/Mutating `ResourceObjects`
246246
`ResourceObject` is a value type, so copying is its default behavior. There are three common mutations you might want to make when copying a `ResourceObject`:
247-
1. Assigning a new `Identifier` to the copy of an identified `ResourceObject`.
248-
2. Assigning a new `Identifier` to the copy of an unidentified `ResourceObject`.
247+
1. Assigning a new `Id` to the copy of an identified `ResourceObject`.
248+
2. Assigning a new `Id` to the copy of an unidentified `ResourceObject`.
249249
3. Change attribute or relationship values.
250250

251251
The first two can be accomplished with code like the following:
@@ -595,9 +595,9 @@ enum UserDescription: ResourceObjectDescription {
595595
}
596596

597597
struct Relationships: JSONAPI.Relationships {
598-
public var friend: (User) -> User.Identifier {
598+
public var friend: (User) -> User.Id {
599599
return { user in
600-
return User.Identifier(rawValue: user.friend_id)
600+
return User.Id(rawValue: user.friend_id)
601601
}
602602
}
603603
}
@@ -612,4 +612,4 @@ Given a value `user` of the above resource object type, you can access the `frie
612612
let friendId = user ~> \.friend
613613
```
614614

615-
This works because `friend` is defined in the form: `var {name}: ({ResourceObject}) -> {Identifier}` where `{ResourceObject}` is the `JSONAPI.ResourceObject` described by the `ResourceObjectDescription` containing the meta-relationship.
615+
This works because `friend` is defined in the form: `var {name}: ({ResourceObject}) -> {Id}` where `{ResourceObject}` is the `JSONAPI.ResourceObject` described by the `ResourceObjectDescription` containing the meta-relationship.

0 commit comments

Comments
 (0)