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: regression in being able to return a Date as a GRPC return value #534

Merged
merged 10 commits into from
Apr 8, 2022

Conversation

fizx
Copy link
Collaborator

@fizx fizx commented Mar 15, 2022

service Clock {
  rpc Now(google.protobuf.Empty) returns (google.protobuf.Timestamp);
}

The above will not respect ts_opt useDate=true. I know it's more idiomatic to wrap the response in a message type, but bear with me--it's legal, used to work fine, and is a pretty terse, relevant interface.

This PR fixes this, adds a regression test. I do feel like the fix is clunky, and likely doesn't address every instance of similar problems. Some advice there would be nice.

Also, I don't really know why my M1 laptop insists on making the following 1 chr diff to random *.bins, but it doesn't seem to be affecting anything. I'll investigate that separately:

diff --git a/integration/grpc-js/google/protobuf/wrappers.bin b/integration/grpc-js/google/protobuf/wrappers.bin
index 5b4b186..7f34d6c 100644
--- a/integration/grpc-js/google/protobuf/wrappers.bin
+++ b/integration/grpc-js/google/protobuf/wrappers.bin
@@ -1,5 +1,5 @@
 
-^^google/protobuf/wrappers.proto^Z^H^H^C^P^N^X^@"^@z<AF>!
+^^google/protobuf/wrappers.proto^Z^H^H^C^P^S^X^A"^@z<AF>!
 ^^google/protobuf/wrappers.proto^R^Ogoogle.protobuf"#
 ^KDoubleValue^R^T
 ^Evalue^X^A ^A(^AR^Evalue""

@fizx fizx changed the title bug: regression in being able to return a Date as a GRPC return value fix: regression in being able to return a Date as a GRPC return value Mar 15, 2022
Copy link
Owner

@stephenh stephenh left a comment

Choose a reason for hiding this comment

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

@fizx sorry for the delayed review, but I think this lgtm.

Yeah, figuring up the .bin files would be great; fwiw let me know if that's just a pita and I can also locally checkout/copy this branch, fix up those bins, and then merge on my side of things, if that's more pragmatic than figuring out root case on that for now.

Thanks!


const params = [...(options.context ? [code`ctx: Context`] : []), code`request: ${inputType}`];
const maybeCtx = options.context ? 'ctx,' : '';

let encode = code`${rawInputType}.encode(request).finish()`;
let decode = code`data => ${outputType}.decode(new ${Reader}(data))`;

console.error();
Copy link
Owner

Choose a reason for hiding this comment

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

This snuck in :-)


const params = [...(options.context ? [code`ctx: Context`] : []), code`request: ${inputType}`];
const maybeCtx = options.context ? 'ctx,' : '';

let encode = code`${rawInputType}.encode(request).finish()`;
let decode = code`data => ${outputType}.decode(new ${Reader}(data))`;

console.error();
if (options.useDate && rawOutputType.toString().includes('Timestamp')) {
Copy link
Owner

Choose a reason for hiding this comment

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

Let's check == .google.protobuf.Timestamp instead of just an includes, just in case there are other have-Timestamp-in-their-name messages in a user's schema.


console.error();
if (options.useDate && rawOutputType.toString().includes('Timestamp')) {
decode = code`data => ${utils.fromTimestamp}(${rawOutputType}.decode(new ${Reader}(data)))`;
Copy link
Owner

Choose a reason for hiding this comment

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

Ah yeah... this makes sense, and I see what you mean by this is a slippery slope to just re-coding ~all of our well known/use date/etc. special type handling that we currently have ~quite a few of here:

https://github.com/stephenh/ts-proto/blob/main/src/main.ts#L839

Yeah, it'd be great to re-use code, but dunno, I'm pretty comfortable with what you have as a point/incremental solution to a use case that's covered by a test case, and we will magically refactor things at some point in the future (...probably... :-)).

@fizx
Copy link
Collaborator Author

fizx commented Apr 8, 2022

Now that we're trued up in #546, this looks more reasonable. Going to land after the status checks pass.

@fizx fizx merged commit 22b76ec into stephenh:main Apr 8, 2022
stephenh pushed a commit that referenced this pull request Apr 8, 2022
## [1.110.3](v1.110.2...v1.110.3) (2022-04-08)

### Bug Fixes

* regression in being able to return a Date as a GRPC return value ([#534](#534)) ([22b76ec](22b76ec))
@stephenh
Copy link
Owner

stephenh commented Apr 8, 2022

🎉 This PR is included in version 1.110.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stephenh
Copy link
Owner

stephenh commented Apr 8, 2022

Great, thanks for pushing this through @fizx !

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.

2 participants