Skip to content

Commit b9b4f6e

Browse files
committed
docs(kitsu-core): add v10 migration guide
1 parent dbd625c commit b9b4f6e

1 file changed

Lines changed: 156 additions & 8 deletions

File tree

packages/kitsu-core/MIGRATING.md

Lines changed: 156 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,153 @@
11
# Migration Guides
22

3+
## Migrating to `10.0.0`
4+
5+
`serialise` has been refactored to match the v9 `deserialise` behaviour. This was intended for the v9 release, however it slipped though the net and resulted in broken relationship serialisation in v9.
6+
7+
Relationships given to the `serialise` function are now always an object containing either a `data` object or a `data` array. This allows for optional top-level relationship `links` and `meta` objects to be serialised into the JSON:API format.
8+
9+
Exemptions:
10+
- `links` that are not objects or do not contain `self` or `related` will become attributes as normal
11+
- `meta` that are not objects will become attributes as normal
12+
13+
#### Legacy Input
14+
15+
```js
16+
{
17+
id: '1',
18+
type: 'libraryEntries',
19+
links: { self: 'library-entries/1' }
20+
user: { // one-to-one relationship
21+
id: '2',
22+
type: 'users',
23+
links: { self: 'users/2' }
24+
name: 'Example'
25+
},
26+
unit: [ // one-to-many relationship
27+
{
28+
id: '3',
29+
type: 'episodes',
30+
links: { self: 'episodes/3' }
31+
number: 12
32+
}
33+
]
34+
}
35+
```
36+
37+
##### Legacy Output
38+
39+
```js
40+
data: {
41+
id: '1',
42+
type: 'libraryEntries',
43+
attributes: {
44+
links: { self: 'library-entries/1' }
45+
},
46+
relationships: {
47+
user: {
48+
data: {
49+
id: '2',
50+
type: 'users',
51+
attributes: {
52+
links: { self: 'users/2' }
53+
name: 'Example'
54+
}
55+
}
56+
},
57+
unit: {
58+
data: [
59+
{
60+
id: '3',
61+
type: 'episodes',
62+
attributes: {
63+
links: { self: 'episodes/3' }
64+
number: 12
65+
}
66+
}
67+
]
68+
}
69+
}
70+
}
71+
```
72+
73+
#### New Input
74+
75+
```js
76+
{
77+
id: '1',
78+
type: 'libraryEntries',
79+
links: { self: 'library-entries/1' }
80+
user: { // one-to-one relationship
81+
links: {
82+
self: 'library-entries/1/relationships/user'
83+
related: 'libary-entries/1/user'
84+
},
85+
data: {
86+
id: '2',
87+
type: 'users',
88+
links: { self: 'users/2' }
89+
name: 'Example'
90+
}
91+
},
92+
unit: { // one-to-many relationship
93+
links: {
94+
self: 'library-entries/1/relationships/unit',
95+
related: 'library-entries/1/unit'
96+
},
97+
data: [
98+
{
99+
id: '3',
100+
type: 'episodes',
101+
links: { self: 'episodes/3' },
102+
number: 12
103+
}
104+
]
105+
}
106+
}
107+
```
108+
109+
##### New Output
110+
111+
```
112+
data: {
113+
id: '1',
114+
type: 'libraryEntries',
115+
links: { self: 'library-entries/1' },
116+
relationships: {
117+
user: {
118+
links: {
119+
self: 'library-entries/1/relationships/user'
120+
related: 'libary-entries/1/user'
121+
},
122+
data: {
123+
id: '2',
124+
type: 'users',
125+
links: { self: 'users/2' },
126+
attributes: {
127+
name: 'Example'
128+
}
129+
}
130+
},
131+
unit: {
132+
links: {
133+
self: 'library-entries/1/relationships/unit',
134+
related: 'library-entries/1/unit'
135+
},
136+
data: [
137+
{
138+
id: '3',
139+
type: 'episodes',
140+
links: { self: 'episodes/3' },
141+
attributes: {
142+
number: 12
143+
}
144+
}
145+
]
146+
}
147+
}
148+
}
149+
```
150+
3151
## Migrating to `9.0.0`
4152

5153
### Deserialising
@@ -21,16 +169,16 @@ data: {
21169
id: '1',
22170
type: 'libraryEntries'
23171
links: {
24-
self: 'https://kitsu.io/api/edge/library-entries/1'
172+
self: 'library-entries/1'
25173
},
26174
attributes: {
27175
ratingTwenty: 10
28176
},
29177
relationships: {
30178
user: {
31179
links: {
32-
self: 'https://kitsu.io/api/edge/library-entries/1/relationships/user',
33-
related: 'https://kitsu.io/api/edge/library-entries/1/user'
180+
self: 'library-entries/1/relationships/user',
181+
related: 'library-entries/1/user'
34182
},
35183
data: {
36184
id: '2',
@@ -44,7 +192,7 @@ included: [
44192
id: '2',
45193
type: 'users',
46194
links: {
47-
self: 'https://kitsu.io/api/edge/users/2'
195+
self: 'users/2'
48196
},
49197
attributes: {
50198
name: 'Example'
@@ -77,19 +225,19 @@ data: {
77225
id: '1',
78226
type: 'libraryEntries',
79227
links: {
80-
self: 'https://kitsu.io/api/edge/library-entries/1'
228+
self: 'library-entries/1'
81229
},
82230
ratingTwenty: 10,
83231
user: {
84232
links: {
85-
self: 'https://kitsu.io/api/edge/library-entries/1/relationships/user',
86-
related: 'https://kitsu.io/api/edge/library-entries/1/user'
233+
self: 'library-entries/1/relationships/user',
234+
related: 'library-entries/1/user'
87235
},
88236
data: {
89237
id: '2',
90238
type: 'users',
91239
links: {
92-
self: 'https://kitsu.io/api/edge/users/2'
240+
self: 'users/2'
93241
},
94242
name: 'Example'
95243
}

0 commit comments

Comments
 (0)