kitsu
kitsu copied to clipboard
JSDoc comment for `deserialise()` is inconsistent with implementation
This example states that the linked relationship user
will look like this:
user: { type: 'users', id: '2', slug: 'wopian' }
However, according to the linkRelationships documentation and a brief test, the function output looks like this:
user: { data: { type: 'users', id: '2', slug: 'wopian' } }
Thank you, it seems some of the JSDoc examples didn't get updated in the 9.x release.
I'm fairly certain this is not an actual problem. If you run the example exactly as-is, you get the expected output. I have removed the variable names from my example below to avoid confusing data:
with data =
.
My REPL output results in the exact same data as the example.
> linkRelationships = require("./linkRelationships").linkRelationships
[Function: linkRelationships]
> linkRelationships(
... {
..... attributes: { author: 'Joe' },
..... relationships: {
....... author: {
......... data: { id: '1', type: 'people' }
......... }
....... }
..... },
... [
... {
..... id: '1',
..... type: 'people',
..... attributes: { name: 'Joe' }
..... }
... ]
... )
{
attributes: { author: 'Joe' },
author: { data: { id: '1', type: 'people', name: 'Joe' } }
}
I think its worth noting that linkRelationships
is called internally by deserialise
, but as can be seen here https://github.com/wopian/kitsu/blob/b3e2624a1e5969e606fc50daa68fdd44ff90abb2/packages/kitsu-core/src/deserialise/index.js#L63 it assigns the result to response.data
, which explains the difference between the between the output of deserialise
and linkRelationships
If I run the linked example exactly as is:
const { deserialise } = require("kitsu-core");
deserialise({
data: {
id: '1',
relationships: {
user: {
data: {
type: 'users',
id: '2' }
}
}
},
included: [
{
type: 'users',
id: '2',
attributes: { slug: 'wopian' }
}
]
})
the output is:
{ data: { id: '1', user: { data: { type: 'users', id: '2', slug: 'wopian' }}}}
while the JSDoc comment says it should be:
{ data: { id: '1', user: { type: 'users', id: '2', slug: 'wopian' } } }
Yes, 9.x added data
to relationships to support relationship meta/links objects when the relationship is an array.
This didn't get updated in the documentation and appears I forgot to make this change after this issue was opened :(
Thank you for the fix! :)
Released in 10.0.0-alpha.26 and 9.1.26