-
Notifications
You must be signed in to change notification settings - Fork 349
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: Add functionality for grpc camel case to respect splitting by word #721
Conversation
@stephenh Could you take a look for me, please? Thanks. |
There is a failing check :-( Not sure what that is. |
I noticed that lodash I was using was included in the packages/lock but not as a direct dependency, added it. |
Oh, I see the checks are all passing now, but before the 16.x was failing, but all seems good now. |
This is where the grpc library does its conversion. and |
@iangregsondev I just added a https://github.com/stephenh/ts-proto/blob/main/.yarnrc.yml Can you try running/rebasing on |
* chore: Bump to yarn v3. * Bump angular example.
This did not work I am afraid. |
@stephenh Sorry had some issues :-( Couldn't update the lodash to use the one suggested because it gives an issue with esModuleInterop, so I had to add it to the tsconfig but then I get issues in the tests. I also updated the protoc and passing the required parameter but it kept failing :-( I have returned it back to the way it was. I added a comment though as suggested. let me know your thoughts. |
Oh Wait, I think I updated the wrong tsconfig. Let me have another play :-) |
@stephenh Sorry mate, no go, it causes me issues if import lodash.camel as I have to enable esModuleInterop but all tests start to fail. I am probably missing something :-( Help ? Would this be a major concern as this is a build tool anyway and keep the size down for front end use is probably not a concern here. Let me know your feedback, maybe you see the issue ? Failing that I could extract the lodash internal implementation :-) Speak soon. |
Ah damn, yeah it's been awhile since I've fought with esModuleInterop but
yeah it can be finicky...
I dunno, I don't actually hate the idea of just copy/pasting in their camel
case; assuming that it's a short/self-contained method, yeah let's try that?
Otherwise yeah I'm fine with the full lodash dependency; thanks!
…On Fri, Dec 9, 2022, 10:20 AM Ian Gregson ***@***.***> wrote:
@stephenh <https://github.com/stephenh> Sorry mate, no go, it causes me
issues if import lodash.camel as I have to enable esModuleInterop but all
tests start to fail.
I am probably missing something :-(
Help ?
Would this be a major concern as this is a build tool anyway and keep the
size down for front end use is probably not a concern here.
Let me know your feedback, maybe you see the issue ?
Failing that I could extract the lodash internal implementation :-)
Speak soon.
—
Reply to this email directly, view it on GitHub
<#721 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAABSALFEYWMTSYWT2NY6FLWMNL4JANCNFSM6AAAAAASZHWZYE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
The internal implementation for camelCase inside of lodash was a mess :-) A new library found that is a native typescript library and only 1.4K in size compared to lodash which was 71k :-) It also supports precisely what we need to do. Also updated the comment to remove the reference to lodash as we are no longer using it. |
@stephenh Sometimes the build seems to fail, for example, before it failed all of them :-( Maybe an issue of Github Actions, I don't think its anything I have done. I had this before.
Could you force a new build please, I don't think I have rights. |
@stephenh I updated a comment and it forced a build :-) It has now passed. Over to you :-) Cheers. |
This looks great! Thanks @iangregsondev ! |
🎉 This PR is included in version 1.135.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I believe this change breaks service names that use snake_case. With version 1.135.0 the following proto
generates export interface GeneralServer extends UntypedServiceImplementation {
general_analysis_calculation: handleUnaryCall<GeneralInputs, GeneralOutputsList>;
}
export interface GeneralClient extends Client {
general_analysis_calculation(
request: GeneralInputs,
callback: (error: ServiceError | null, response: GeneralOutputsList) => void,
): ClientUnaryCall;
general_analysis_calculation(
request: GeneralInputs,
metadata: Metadata,
callback: (error: ServiceError | null, response: GeneralOutputsList) => void,
): ClientUnaryCall;
general_analysis_calculation(
request: GeneralInputs,
metadata: Metadata,
options: Partial<CallOptions>,
callback: (error: ServiceError | null, response: GeneralOutputsList) => void,
): ClientUnaryCall;
} maintaining the snake_case (general_analysis_calculation). Then with version 1.135.1 the same proto generates export interface GeneralServer extends UntypedServiceImplementation {
generalAnalysisCalculation: handleUnaryCall<GeneralInputs, GeneralOutputsList>;
}
export interface GeneralClient extends Client {
generalAnalysisCalculation(
request: GeneralInputs,
callback: (error: ServiceError | null, response: GeneralOutputsList) => void,
): ClientUnaryCall;
generalAnalysisCalculation(
request: GeneralInputs,
metadata: Metadata,
callback: (error: ServiceError | null, response: GeneralOutputsList) => void,
): ClientUnaryCall;
generalAnalysisCalculation(
request: GeneralInputs,
metadata: Metadata,
options: Partial<CallOptions>,
callback: (error: ServiceError | null, response: GeneralOutputsList) => void,
): ClientUnaryCall;
} which has converted the name to camelCase (generalAnalysisCalculation). I'm using the following options when generating the TypeScript. const PROTO_DIR = path.join(__dirname, '../proto_files')
const MODEL_DIR = path.join(__dirname, '../src/models/protos')
const PROTOC_PATH = path.join(__dirname, '../node_modules/grpc-tools/bin/protoc')
const PLUGIN_PATH = path.join(__dirname, '../node_modules/.bin/protoc-gen-ts_proto')
const protoConfig = [
`--plugin=${PLUGIN_PATH}`,
// https://github.com/stephenh/ts-proto/blob/main/README.markdown
'--ts_proto_opt=outputServices=grpc-js,env=node,useOptionals=messages,exportCommonSymbols=false,esModuleInterop=true,snakeToCamel=false',
`--ts_proto_out=${MODEL_DIR}`,
`--proto_path ${PROTO_DIR} ${PROTO_DIR}/*.proto`
]
execSync(`${PROTOC_PATH} ${protoConfig.join(' ')}`) It's not a huge issue as a quick find/replace across the workspace fixes it, and when building the JS my compiler suggested the "new" function name as I guess snake/camel difference was easy enough to detect. |
@Hoppingmad9 FWIW from @iangregsondev 's fix in this PR, I had assumed the method names of But your assertion is that grpc-js works fine with |
We don't do any config for grpc-js. So
all use Everything worked when ts-proto generated it as snake_case. I'm happy to change our code/proto to use camelCase everywhere so don't worry about this for us. |
I am using the exact same functionality found in the grpc nodejs library.
I also added a small test.
It now converts GetAPIKey -> getApiKey
Before the change it would be -> getAPIKey
This obviously fails inside the grpc nodejs library.
I have run the tests and of course that works but I was unable to run
I am on a M1 and get
I know that this issue was raised and fixed previously but it doesn't work for me :-(