-
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
Timestamp to String conversion #152
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this as a config option but would ask for:
- add a new
integration/<pick-some-name>
directory with aparameter.txt
with the new option and include the generated output in the PR. This will ensure the output compiles and will serve as a regression test - Right now you're only changing the type, and not handling any of the protobuf (
encode
&decode
) or JSON (toJSON
/fromJSON
) serialization/deserialization.
Can you add tests (within the new integration/<pick-some-name>
directory) that show serialization/deserialization with the string-based timestamps works correctly?
src/main.ts
Outdated
@@ -87,6 +87,7 @@ export type Options = { | |||
lowerCaseServiceMethods: boolean; | |||
nestJs: boolean; | |||
env: EnvOption; | |||
timestampAsString: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Given we already have forceLong
which can be long
or string
, wonder if we should have (the newly added) useDate
be something like builtin
(to use Date
) / string
(as you propose) / protobuf
(the google.protobuf.Timestamp
type as-is).
I don't really love those names (builtin
/ string
/ protobuf
)...ideally could think of better names.
But the main idea would be to reuse the existing useDate
flag, by turning it into a tri-state.
Maybe just:
useDate=true
-- default behavior, usesDate
useDate=false
-- as-is today, uses `google.protobuf.TimestampuseDate=string
-- as you want to add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Let's stick with the tri-state option. I'll change the code accordingly.
I'm tempted to remove these dependencies all together because at this point ts-proto has many different flags that can change whether the generated code actually does/does not use certain dependencies. I.e. users using the "only types" output probably don't want ts-proto to bring in any dependencies. I guess in that case, they could be using ts-proto as a devDependency. Fixes stephenh#147.
This reverts commit da5f10a.
What's going on with this change? I'd love to see this functionality added as it allows me to align my interfaces directly with the json I get over the wire without any decoding/encoding. Seems like there has been a lot of drift since this request was opened. I'm happy to help finish this off. Would it be easier to start with a fresh branch and just try cherry pick the relevant changes? |
Yep, due to the ts-poet upgrade there was a significant amount of churn/conflicts.
That's an interesting goal. I think I wanted to do that as one point too...i.e. I think the wrinkle would be primitives that are default values, i.e. if So you might end up with code doing And filling in these defaults is essentially what Granted, if you control the server, you could tell it to always include these primitive values... I think as happenstance ts-proto itself currently does include |
Cool. I'll open a new branch and try to get this working. Thanks for being so responsive.
We have a rule against using unwrapped primitives, so not a problem for our use case. The only default we have to make sure to send from the server is default enums. |
This functionality was just merged as part of #221. |
There is should be an option to convert Timestamp as a string.