You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(4) Significantly reduces kitsu bundle size by 30% - pluralize is 2.3 kB of kitsu's 8.2 kB.
(1/3/4) Pluralisation leads to ambiguity of what the real value of type in the API actually is (especially when it is not simple rules like post -> posts)
Proposed behaviour would be WYSIWYG (What You See Is What You Get)
(1/3/4) Pluralisation can get in the way of the correct value of type in some API endpoints, but not all endpoints.
Which results in consumers either disabling pluralisation entirely or setting pluralisation rules to mitigate the one wrong type
Pain points
This would break SOMEGET, PATCH, POST and DELETE requests that relied on pluralisation to request the API resource
This would break ALLPATCH, POST requests as the data sent to the API will now be lacking the type without changes to consumer code
This would break ALLDELETE requests as the 2nd argument is removed, making the 3rd argument for additional headers the 2nd argument
kitsu-core
What
Remove the first parameter of serialise (model / the root resources' type)
The second parameter (obj / the deserialised JSON:API input) now requires the type to be defined. E.g:
Remove pluralTypes and camelCaseTypes options added in 9.x as with (1.) the type will already be in the resource object and should be correctly formatted already
For upgrades from 8.x and older it would be serialise.apply({ camel, resCase: kebab, plural }, [ model, obj ]) to serialise(obj) (with model now obj.type)
Instead of being extracted from the model string in the Kitsu class and passed down, where pluralisation mismatch and kebab/snakecase could be present, which necessitated these options`
Why
(1/2) It is only used once to set the type of a new object (along with pluralisation and camelCase conversion)
(1) With the logic removed from the get, patch and post methods from the Kitsu class this doesn't really make much sense to keep type separate here still
(1) With the proposed behaviour it would match the existing behaviour of adding the id to the new data object - extracting it from the second parameter (obj)
serialise will need to throw an error if type is missing
Only when obj is NOTnull or [] (syntax to delete relationships)
In current behaviour it is guaranteed to have a type set
Pain points
This would break ALL uses of serialise as the first argument is dropped, making the input object (deserialised JSON:API) the first argument.
The text was updated successfully, but these errors were encountered:
Changes are broken down by package (
kitsu
andkitsu-core
)kitsu
What
Change the first parameter behaviour of
api.get
,api.patch
,api.post
andapi.delete
to be a plain URL path. E.g.api.get(anime/1/relationships/episodes)
api.patch(users/1/password, body)
where thetype
may not bepasswords
Remove the second parameter of
api.delete
api.delete('posts', 1)
is redundant when you can doapi.delete('posts/1')
Second parameter (deserialised JSON:API) of
api.patch
andapi.post
would now require thetype
to be definedapi.post('post', { content: 'some content' }
api.patch('post', { id: '1', content: 'some content' }
api.post('posts', { type: 'posts', content: 'some content' }
api.patch('posts', { id: '1', type: 'posts', content: 'some content' }
Drop dependency on
pluralize
Why
(1/2) Allows custom URLs for JSON:API resources without creating custom requests (how to send raw request? #414)
(4) Significantly reduces
kitsu
bundle size by 30% -pluralize
is 2.3 kB of kitsu's 8.2 kB.(1/3/4) Pluralisation leads to ambiguity of what the real value of
type
in the API actually is (especially when it is not simple rules likepost -> posts
)(1/3/4) Pluralisation can get in the way of the correct value of
type
in some API endpoints, but not all endpoints.type
Pain points
This would break SOME
GET
,PATCH
,POST
andDELETE
requests that relied on pluralisation to request the API resourceThis would break ALL
PATCH
,POST
requests as the data sent to the API will now be lacking thetype
without changes to consumer codeThis would break ALL
DELETE
requests as the 2nd argument is removed, making the 3rd argument for additional headers the 2nd argumentkitsu-core
What
Remove the first parameter of
serialise
(model
/ the root resources'type
)obj
/ the deserialised JSON:API input) now requires thetype
to be defined. E.g:serialise('posts', { id: '1', content: 'some content' }
serialise({ id: '1', type: 'posts', content: 'some content' }
Remove
pluralTypes
andcamelCaseTypes
options added in9.x
as with (1.) thetype
will already be in the resource object and should be correctly formatted already8.x
and older it would beserialise.apply({ camel, resCase: kebab, plural }, [ model, obj ])
toserialise(obj)
(withmodel
nowobj.type
)model
string in the Kitsu class and passed down, where pluralisation mismatch and kebab/snakecase could be present, which necessitated these options`Why
(1/2) It is only used once to set the
type
of a new object (along with pluralisation and camelCase conversion)(1) With the logic removed from the
get
,patch
andpost
methods from the Kitsu class this doesn't really make much sense to keeptype
separate here still(1) With the proposed behaviour it would match the existing behaviour of adding the
id
to the new data object - extracting it from the second parameter (obj
)serialise
will need to throw an error iftype
is missingobj
is NOTnull
or[]
(syntax to delete relationships)type
setPain points
serialise
as the first argument is dropped, making the input object (deserialised JSON:API) the first argument.The text was updated successfully, but these errors were encountered: