Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSDoc comment for deserialise() is inconsistent with implementation #578

Closed
fspoettel opened this issue Aug 25, 2021 · 6 comments · Fixed by #703 or #702
Closed

JSDoc comment for deserialise() is inconsistent with implementation #578

fspoettel opened this issue Aug 25, 2021 · 6 comments · Fixed by #703 or #702

Comments

@fspoettel
Copy link

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' } }
@wopian
Copy link
Owner

wopian commented Aug 25, 2021

Thank you, it seems some of the JSDoc examples didn't get updated in the 9.x release.

@pedep
Copy link
Contributor

pedep commented Aug 11, 2022

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

else if (response.included) response.data = linkRelationships(response.data, response.included)
it assigns the result to response.data, which explains the difference between the between the output of deserialise and linkRelationships

@fspoettel
Copy link
Author

fspoettel commented Aug 11, 2022

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' } } }

@wopian
Copy link
Owner

wopian commented Aug 11, 2022

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 :(

@fspoettel
Copy link
Author

Thank you for the fix! :)

@wopian
Copy link
Owner

wopian commented Aug 11, 2022

Released in 10.0.0-alpha.26 and 9.1.26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants