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(javascript): expose requestOptions and cache options #283

Merged
merged 7 commits into from
Mar 24, 2022

Conversation

shortcuts
Copy link
Member

@shortcuts shortcuts commented Mar 23, 2022

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-176

Changes included:

Follow up of #274
Follow up of #281

  • Expose cache options at the client initialization level
  • Expose requestsOptions on the method, like we currently have on the clients.
    • This allow forcing a request to be cacheable, and more.
    • Due to options coming from 3 sources, doing it in the transporter was the less impactful solution (both for size and redudancy), but I'm still not a fan of it. Don't hesitate to suggest alternatives.

Next steps:

There is a looot of duplicate types, we could have a small cleaning PR to try to re-use them.

🧪 Test

CI :D

@shortcuts shortcuts self-assigned this Mar 23, 2022
@netlify
Copy link

netlify bot commented Mar 23, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit bf5a304
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/623c440987aeb100087e52b3

@shortcuts
Copy link
Member Author

shortcuts commented Mar 23, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the generated/main branch.

Base automatically changed from feat/APIC-176/use-javascript-cache to main March 24, 2022 09:43
@millotp
Copy link
Collaborator

millotp commented Mar 24, 2022

Can you make it ready for review please ? 😄

@shortcuts
Copy link
Member Author

Can you make it ready for review please ? 😄

Yep I'm resolving conflicts first, sorry for the ping D:

@shortcuts shortcuts marked this pull request as ready for review March 24, 2022 10:12
Comment on lines +229 to +251
const mergedData: Request['data'] = Array.isArray(baseRequest.data)
? baseRequest.data
: {
...baseRequest.data,
...baseRequestOptions?.data,
};
const request: Request = {
...baseRequest,
data: mergedData,
};
const requestOptions: RequestOptions = {
cacheable: baseRequestOptions?.cacheable,
timeout: baseRequestOptions?.timeout,
queryParameters: {
...baseRequestOptions?.queryParameters,
...methodOptions.queryParameters,
},
headers: {
Accept: 'application/json',
...baseRequestOptions?.headers,
...methodOptions.headers,
},
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of this part, but those changes at the method level added like 1kb to the bundle size of each clients

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Logic could definitely be extracted in a method)

Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean !

Comment on lines +240 to +241
cacheable: baseRequestOptions?.cacheable,
timeout: baseRequestOptions?.timeout,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cacheable: baseRequestOptions?.cacheable,
timeout: baseRequestOptions?.timeout,
...baseRequestOptions,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indeed better but small size impact, so I've went with that instead

): Promise<TResponse> {
const mergedData: Request['data'] = Array.isArray(baseRequest.data)
? baseRequest.data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really useful to have optional data ? Do you have a use case in mind ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I could see is when an option is not available in the client but exists on tHe REST api.

e.g. if they try dev things on the engine, they can test it without changing clients.

It was already there in v4 so I've kept it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay this is already handled by the customRequest endpoint but why not

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