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

feat(kitsu): Configurable modern query serializer #828

Merged
merged 2 commits into from
Feb 28, 2023

Conversation

pedep
Copy link
Contributor

@pedep pedep commented Feb 28, 2023

Resolves discussion from #781

This PR aims to introduce the following:

  1. Parse key names like id_in[] and id_in][ and ensure they appear intuitively in the query (filter[id_in][])
    Previous behaviour would generate keys like filter[id_in[]], requiring unintuitive keys id_in][ in order to achieve the expected behaviour.
  2. Make the query method configurable, by allowing an option to be passed to the Kitsu class constructor
    2.1 Allow the user to switch between traditional (current behaviour) and modern mode. Modern mode allows to automatic generation of array style keys when passing an array to params, instead of having to explicitly declare them:
    traditional api.get('anime', {filter: {id_in[]: [1,2]}}) -> filter[id_in][]=1&filter[id_in][]=2
    modern api.get('anime', {filter: {id_in: [1,2]}}) -> filter[id_in][]=1&filter[id_in][]=2
    2.2 Allow arbitrary serialization functions to be passed, for customized handling ((obj: any) => string)
    const api = new Kitsu({ query: (obj) => /* handle serialization */ })

packages/kitsu/src/index.js Outdated Show resolved Hide resolved
@codeclimate
Copy link

codeclimate bot commented Feb 28, 2023

Code Climate has analyzed commit 4974425 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (100% is the threshold).

This pull request will bring the total coverage in the repository to 100.0% (0.0% change).

View more on Code Climate.

@wopian wopian merged commit feedef8 into wopian:master Feb 28, 2023
@wopian
Copy link
Owner

wopian commented Feb 28, 2023

Released as 10.1.0

@pedep pedep deleted the feat(kitsu)/configurable-query-serializer branch March 1, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants