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

fix(Transfomers): call .toJSON in toSnakeCase #8790

Merged
merged 5 commits into from Nov 19, 2022

Conversation

RedGuy12
Copy link
Contributor

@RedGuy12 RedGuy12 commented Oct 27, 2022

Please describe the changes this PR makes and why it should be merged:
Makes toSnakeCase call .toJSON functions if they exist.
Fixes #8742
Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes

I could make calling .toJSON togglable via a boolean parameter if that is preferred to avoid breaking changes.

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
@vercel
Copy link

vercel bot commented Oct 27, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Updated
discord-js ⬜️ Ignored (Inspect) Nov 19, 2022 at 8:55PM (UTC)
discord-js-guide ⬜️ Ignored (Inspect) Nov 19, 2022 at 8:55PM (UTC)

@codecov
Copy link

codecov bot commented Oct 27, 2022

Codecov Report

Merging #8790 (2ecca62) into main (6e348ff) will increase coverage by 0.38%.
The diff coverage is 87.62%.

❗ Current head 2ecca62 differs from pull request most recent head 70277da. Consider uploading reports for the commit 70277da to get more accurate results

@@            Coverage Diff             @@
##             main    #8790      +/-   ##
==========================================
+ Coverage   85.22%   85.61%   +0.38%     
==========================================
  Files          77       96      +19     
  Lines        6715     9459    +2744     
  Branches      877     1134     +257     
==========================================
+ Hits         5723     8098    +2375     
- Misses        953     1319     +366     
- Partials       39       42       +3     
Flag Coverage Δ
brokers 65.24% <ø> (?)
builders 98.65% <87.87%> (-1.35%) ⬇️
collection 100.00% <ø> (ø)
proxy 81.53% <ø> (ø)
rest 91.97% <82.35%> (?)
util 100.00% <ø> (ø)
utilities 100.00% <ø> (ø)
voice 63.70% <ø> (ø)
ws 59.83% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ackages/rest/src/lib/handlers/SequentialHandler.ts 86.07% <50.00%> (ø)
packages/builders/src/components/Components.ts 87.87% <60.00%> (-12.13%) ⬇️
...ers/src/components/selectMenu/ChannelSelectMenu.ts 63.49% <63.49%> (ø)
...src/components/selectMenu/MentionableSelectMenu.ts 90.32% <90.32%> (ø)
...ilders/src/components/selectMenu/RoleSelectMenu.ts 90.32% <90.32%> (ø)
...ilders/src/components/selectMenu/UserSelectMenu.ts 90.32% <90.32%> (ø)
...ilders/src/components/selectMenu/BaseSelectMenu.ts 92.18% <92.18%> (ø)
packages/rest/src/lib/utils/utils.ts 97.33% <92.30%> (ø)
packages/builders/src/components/ActionRow.ts 100.00% <100.00%> (ø)
packages/builders/src/components/Assertions.ts 100.00% <100.00%> (ø)
... and 17 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
Copy link
Member

@kyranet kyranet left a comment

Choose a reason for hiding this comment

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

This makes the bold assumption that any JSON encodable will always yield snake_case properties, but that's (hopefully) almost always the case here, and for the places we use toSnakeCase for, it would be wrong to use JSON encodable classes that don't yield snake_case properties.

Either way, this seems to be triggered when using builders inside plain objects, which makes sense.

@RedGuy12
Copy link
Contributor Author

Would it be better if I called toSnakeCase on toJSON's return value?

@suneettipirneni
Copy link
Member

Would it be better if I called toSnakeCase on toJSON's return value?

I would personally prefer this.

Splitting functions by specific behaviors yields more flexible predictable code. toSnakeCase should only be concerned with transforming the input (as-is) to snake_case json, it shouldn't do anything else in addition to that.

@kodiakhq kodiakhq bot merged commit 017f9b1 into discordjs:main Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Non-recursive InteractionResponses#showModal body transformation
6 participants