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.
Changes are broken down by package (
kitsuandkitsu-core)kitsu
What
Change the first parameter behaviour of
api.get,api.patch,api.postandapi.deleteto be a plain URL path. E.g.api.get(anime/1/relationships/episodes)api.patch(users/1/password, body)where thetypemay not bepasswordsRemove the second parameter of
api.deleteapi.delete('posts', 1)is redundant when you can doapi.delete('posts/1')Second parameter (deserialised JSON:API) of
api.patchandapi.postwould now require thetypeto 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
pluralizeWhy
(1/2) Allows custom URLs for JSON:API resources without creating custom requests (how to send raw request? #414)
(4) Significantly reduces
kitsubundle size by 30% -pluralizeis 2.3 kB of kitsu's 8.2 kB.(1/3/4) Pluralisation leads to ambiguity of what the real value of
typein 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
typein some API endpoints, but not all endpoints.typePain points
This would break SOME
GET,PATCH,POSTandDELETErequests that relied on pluralisation to request the API resourceThis would break ALL
PATCH,POSTrequests as the data sent to the API will now be lacking thetypewithout changes to consumer codeThis would break ALL
DELETErequests 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 thetypeto be defined. E.g:serialise('posts', { id: '1', content: 'some content' }serialise({ id: '1', type: 'posts', content: 'some content' }Remove
pluralTypesandcamelCaseTypesoptions added in9.xas with (1.) thetypewill already be in the resource object and should be correctly formatted already8.xand older it would beserialise.apply({ camel, resCase: kebab, plural }, [ model, obj ])toserialise(obj)(withmodelnowobj.type)modelstring 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
typeof a new object (along with pluralisation and camelCase conversion)(1) With the logic removed from the
get,patchandpostmethods from the Kitsu class this doesn't really make much sense to keeptypeseparate here still(1) With the proposed behaviour it would match the existing behaviour of adding the
idto the new data object - extracting it from the second parameter (obj)serialisewill need to throw an error iftypeis missingobjis NOTnullor[](syntax to delete relationships)typesetPain points
serialiseas the first argument is dropped, making the input object (deserialised JSON:API) the first argument.