|
1 | 1 | # Migration Guides |
2 | 2 |
|
| 3 | +## Migrating to `9.0.0` |
| 4 | + |
| 5 | +### Deserialising |
| 6 | + |
| 7 | +`deserialise` and `linkRelationships` have been refactored. They now preserve `link` objects from relationships and match the structure of the root `data` object/array. |
| 8 | +- Root `data` self links are avaiable as `data.links` or `data[].links` |
| 9 | +- Relationship objects are now `relationshipName.data.id` from `relationshipName.id` |
| 10 | +- Relationship arrays are now `relationshipName.data[].id` from `relationshipName[].id` |
| 11 | +- Relationship links are avaiable as `relationshipName.links` |
| 12 | + |
| 13 | +For the full change in behaviour, see the legacy and new outputs below. |
| 14 | + |
| 15 | +#### Legacy Behaviour |
| 16 | + |
| 17 | +Input: |
| 18 | + |
| 19 | +```js |
| 20 | +data: { |
| 21 | + id: '1', |
| 22 | + type: 'libraryEntries' |
| 23 | + links: { |
| 24 | + self: 'https://kitsu.io/api/edge/library-entries/1' |
| 25 | + }, |
| 26 | + attributes: { |
| 27 | + ratingTwenty: 10 |
| 28 | + }, |
| 29 | + relationships: { |
| 30 | + user: { |
| 31 | + links: { |
| 32 | + self: 'https://kitsu.io/api/edge/library-entries/1/relationships/user', |
| 33 | + related: 'https://kitsu.io/api/edge/library-entries/1/user' |
| 34 | + }, |
| 35 | + data: { |
| 36 | + id: '2', |
| 37 | + type: 'users' |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | +}, |
| 42 | +included: [ |
| 43 | + { |
| 44 | + id: '2', |
| 45 | + type: 'users', |
| 46 | + links: { |
| 47 | + self: 'https://kitsu.io/api/edge/users/2' |
| 48 | + }, |
| 49 | + attributes: { |
| 50 | + name: 'Example' |
| 51 | + } |
| 52 | + } |
| 53 | +``` |
| 54 | + |
| 55 | +Output: |
| 56 | + |
| 57 | +```js |
| 58 | +data: { |
| 59 | + id: '1', |
| 60 | + type: 'libraryEntries', |
| 61 | + ratingTwenty: 10, |
| 62 | + user: { |
| 63 | + id: '2', |
| 64 | + type: 'users', |
| 65 | + name: 'Example' |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +#### New Behaviour |
| 71 | + |
| 72 | + |
| 73 | +Output with same input data as legacy behaviour: |
| 74 | + |
| 75 | +```js |
| 76 | +data: { |
| 77 | + id: '1', |
| 78 | + type: 'libraryEntries', |
| 79 | + links: { |
| 80 | + self: 'https://kitsu.io/api/edge/library-entries/1' |
| 81 | + }, |
| 82 | + ratingTwenty: 10, |
| 83 | + user: { |
| 84 | + links: { |
| 85 | + self: 'https://kitsu.io/api/edge/library-entries/1/relationships/user', |
| 86 | + related: 'https://kitsu.io/api/edge/library-entries/1/user' |
| 87 | + } |
| 88 | + data: { |
| 89 | + id: '2', |
| 90 | + type: 'users', |
| 91 | + links: { |
| 92 | + self: 'https://kitsu.io/api/edge/users/2' |
| 93 | + }, |
| 94 | + name: 'Example' |
| 95 | + } |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +### Serialising |
| 101 | + |
| 102 | +`serialise` has been refactored. It now passes camel case and pluralisation options as argument options. Options are 100% optional and will default to no conversion or pluralisation (e.g libraryEntry -> libraryEntry). |
| 103 | + |
| 104 | +#### Legacy Syntax |
| 105 | + |
| 106 | +```js |
| 107 | +import { serialise, camel, kebab } from 'kitsu-core' |
| 108 | +import plural from 'pluralize' |
| 109 | + |
| 110 | +serialise.apply({ camel, resCase: kebab, plural }, [ model, obj, 'PATCH' ]) |
| 111 | +``` |
| 112 | + |
| 113 | +#### New Syntax |
| 114 | + |
| 115 | +```js |
| 116 | +import { serialise, camel } from 'kitsu-core' |
| 117 | +import plural from 'pluralize' |
| 118 | + |
| 119 | +serialise(model, obj, 'PATCH', { |
| 120 | + camelCaseTypes: camel, |
| 121 | + pluralTypes: plural |
| 122 | +}) |
| 123 | +``` |
| 124 | + |
3 | 125 | ## Migrating to `8.0.0` |
4 | 126 |
|
| 127 | +Dropped Node 8 support. Lowest supported version is now Node 10. |
| 128 | + |
5 | 129 | `kitsu-core/node` has been removed as it is now identical to`kitsu-core`. |
6 | 130 |
|
7 | 131 | - Replace `kitsu-core/node` imports with `kitsu-core` |
|
0 commit comments