|
1 | 1 | # Migration Guides |
2 | 2 |
|
| 3 | +## Migrating to `10.0.0` |
| 4 | + |
| 5 | +### Parameter Changes |
| 6 | + |
| 7 | +1. JSON:API query parameters can be set for `PATCH`, `POST` and `DELETE` requests. |
| 8 | + |
| 9 | +2. All requests have had `params` and `headers` merged under one `config` parameter. |
| 10 | + |
| 11 | +#### get |
| 12 | + |
| 13 | +`Kitsu.get(model, params?, headers?)` is now `Kitsu.get(model, config? { params?, headers? })` |
| 14 | + |
| 15 | +#### patch / post |
| 16 | + |
| 17 | +`Kitsu.patch(model, body, headers?)` is now `Kitsu.patch(model, body, config? { params?, headers? })` |
| 18 | + |
| 19 | +#### delete |
| 20 | + |
| 21 | +`Kitsu.delete(model, id, headers?)` is now `Kitsu.delete(model, id, config? { params?, headers? })` |
| 22 | + |
| 23 | +#### self |
| 24 | + |
| 25 | +`Kitsu.self(params?, headers?)` is now `Kitsu.self(config? { params?, headers? })` |
| 26 | + |
| 27 | +#### request |
| 28 | + |
| 29 | +The `headers` parameter has been merged with the existing `config` parameter |
| 30 | + |
| 31 | +`Kitsu.request(config?, headers?)` is now `Kitsu.self(config? { headers? })` |
| 32 | + |
| 33 | +### Serialisation Changes |
| 34 | + |
| 35 | +This change does not affect `Kitsu.get`. |
| 36 | + |
| 37 | +`kitsu-core` serialisation internals have been refactored to match the deserialisation behaviour introduced in v9. This was intended for the v9 release, however it slipped though the net and resulted in broken relationship serialisation in v9. |
| 38 | + |
| 39 | +Relationships in the `body` of `PATCH` and `POST` requests 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. |
| 40 | + |
| 41 | +Exemptions: |
| 42 | +- `links` that are not objects or do not contain `self` or `related` will become attributes as normal |
| 43 | +- `meta` that are not objects will become attributes as normal |
| 44 | + |
| 45 | +#### Legacy PATCH/POST Input |
| 46 | + |
| 47 | +`body` parameter of PATCH/POST requests |
| 48 | + |
| 49 | +```js |
| 50 | +{ |
| 51 | + id: '1', |
| 52 | + type: 'libraryEntries', |
| 53 | + links: { self: 'library-entries/1' } |
| 54 | + user: { // one-to-one relationship |
| 55 | + id: '2', |
| 56 | + type: 'users', |
| 57 | + links: { self: 'users/2' } |
| 58 | + name: 'Example' |
| 59 | + }, |
| 60 | + unit: [ // one-to-many relationship |
| 61 | + { |
| 62 | + id: '3', |
| 63 | + type: 'episodes', |
| 64 | + links: { self: 'episodes/3' } |
| 65 | + number: 12 |
| 66 | + } |
| 67 | + ] |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +##### Legacy Output |
| 72 | + |
| 73 | +JSON data sent to the API server |
| 74 | + |
| 75 | +```js |
| 76 | +data: { |
| 77 | + id: '1', |
| 78 | + type: 'libraryEntries', |
| 79 | + attributes: { |
| 80 | + links: { self: 'library-entries/1' } |
| 81 | + }, |
| 82 | + relationships: { |
| 83 | + user: { |
| 84 | + data: { |
| 85 | + id: '2', |
| 86 | + type: 'users', |
| 87 | + attributes: { |
| 88 | + links: { self: 'users/2' } |
| 89 | + name: 'Example' |
| 90 | + } |
| 91 | + } |
| 92 | + }, |
| 93 | + unit: { |
| 94 | + data: [ |
| 95 | + { |
| 96 | + id: '3', |
| 97 | + type: 'episodes', |
| 98 | + attributes: { |
| 99 | + links: { self: 'episodes/3' } |
| 100 | + number: 12 |
| 101 | + } |
| 102 | + } |
| 103 | + ] |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +#### New Input |
| 110 | + |
| 111 | +`body` parameter of PATCH/POST requests |
| 112 | + |
| 113 | +```js |
| 114 | +{ |
| 115 | + id: '1', |
| 116 | + type: 'libraryEntries', |
| 117 | + links: { self: 'library-entries/1' } |
| 118 | + user: { // one-to-one relationship |
| 119 | + links: { |
| 120 | + self: 'library-entries/1/relationships/user' |
| 121 | + related: 'libary-entries/1/user' |
| 122 | + }, |
| 123 | + data: { |
| 124 | + id: '2', |
| 125 | + type: 'users', |
| 126 | + links: { self: 'users/2' } |
| 127 | + name: 'Example' |
| 128 | + } |
| 129 | + }, |
| 130 | + unit: { // one-to-many relationship |
| 131 | + links: { |
| 132 | + self: 'library-entries/1/relationships/unit', |
| 133 | + related: 'library-entries/1/unit' |
| 134 | + }, |
| 135 | + data: [ |
| 136 | + { |
| 137 | + id: '3', |
| 138 | + type: 'episodes', |
| 139 | + links: { self: 'episodes/3' }, |
| 140 | + number: 12 |
| 141 | + } |
| 142 | + ] |
| 143 | + } |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +##### New Output |
| 148 | + |
| 149 | +JSON data sent to the API server |
| 150 | + |
| 151 | +``` |
| 152 | +data: { |
| 153 | + id: '1', |
| 154 | + type: 'libraryEntries', |
| 155 | + links: { self: 'library-entries/1' }, |
| 156 | + relationships: { |
| 157 | + user: { |
| 158 | + links: { |
| 159 | + self: 'library-entries/1/relationships/user' |
| 160 | + related: 'libary-entries/1/user' |
| 161 | + }, |
| 162 | + data: { |
| 163 | + id: '2', |
| 164 | + type: 'users', |
| 165 | + links: { self: 'users/2' }, |
| 166 | + attributes: { |
| 167 | + name: 'Example' |
| 168 | + } |
| 169 | + } |
| 170 | + }, |
| 171 | + unit: { |
| 172 | + links: { |
| 173 | + self: 'library-entries/1/relationships/unit', |
| 174 | + related: 'library-entries/1/unit' |
| 175 | + }, |
| 176 | + data: [ |
| 177 | + { |
| 178 | + id: '3', |
| 179 | + type: 'episodes', |
| 180 | + links: { self: 'episodes/3' }, |
| 181 | + attributes: { |
| 182 | + number: 12 |
| 183 | + } |
| 184 | + } |
| 185 | + ] |
| 186 | + } |
| 187 | + } |
| 188 | +} |
| 189 | +``` |
| 190 | + |
| 191 | + |
3 | 192 | ## Migrating to `9.0.0` |
4 | 193 |
|
5 | 194 | ### Link objects |
|
0 commit comments