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: Consistently apply lowerCaseServiceMethods=true #332

Merged
merged 13 commits into from
Jul 11, 2021

Conversation

protango
Copy link
Contributor

@protango protango commented Jun 29, 2021

Fixes #310.

The lowerCaseServiceMethods option was inconsistently applied, for example, it was being applied for nestjs but not for grpc-web. It was also not applied to auto-generated batching methods, leading to inconsistent output and typescript compilation errors.

This PR aims to address these issues by replacing all MethodDescriptorProto objects with a new class FormattedMethodDescriptor. This class implements MethodDescriptorProto and copies all properties verbatim, so existing usage is not impacted in any way. However, an additional field, formattedName, is added which applies any formatting rules in the Options to the original method name. I expect that this pattern could be used in other areas where we want to conditionally format strings and other values.

In order to not refactor the whole application to expect a FormattedMethodDescriptor in place of a MethodDescriptorProto, areas which require access to the formattedName property simply assert that the methodDescriptor is an instance of FormattedMethodDescriptor, which should always succeed because they are all converted in main. Code that doesn't use this new property does not need to know about the new class at all, and works as normal.

Testing

Integration tests are setup to validate that the option produces a lower case implementation, but preserves the original name internally. It also validates the behavior works as expected for batch functions.

@protango protango marked this pull request as ready for review June 29, 2021 06:49
* @param obj The object to check
* @param constructor The constructor of the class to check
*/
export function assertInstanceOf<T>(obj: unknown, constructor: { new (...args: any[]): T }): asserts obj is T {
Copy link
Owner

Choose a reason for hiding this comment

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

This is a pretty neat approach!

@stephenh stephenh merged commit 57f2473 into stephenh:main Jul 11, 2021
stephenh pushed a commit that referenced this pull request Jul 11, 2021
## [1.82.1](v1.82.0...v1.82.1) (2021-07-11)

### Bug Fixes

* Consistently apply lowerCaseServiceMethods=true ([#332](#332)) ([57f2473](57f2473))
@stephenh
Copy link
Owner

🎉 This PR is included in version 1.82.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lowerCaseServiceMethods option does not change client implementation
2 participants