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!: allow date types to be strings | re-runs the generator #93

Merged
merged 1 commit into from
Jun 15, 2021

Conversation

grant
Copy link
Contributor

@grant grant commented May 21, 2021

Fixes #91

  • Allows Google CloudEvent date types to be either a JS date object or a string. (APIs return strings)
  • Re-runs the generator (includes very minor breaking changes with TS field capitalization). The generator has not been run in a few months.

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
@grant grant requested a review from grayside May 21, 2021 01:08
@grant grant self-assigned this May 21, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label May 21, 2021
@product-auto-label product-auto-label bot added the api: eventarc Issues related to the googleapis/google-cloudevents-nodejs API. label May 21, 2021
Copy link

@grayside grayside left a comment

Choose a reason for hiding this comment

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

With this change, does using the library mean the unmarshalled data could be string or date? If so, should we have a conversion mechanism under the hood that converts the string to a Date for consistent behavior?

@grant
Copy link
Contributor Author

grant commented Jun 3, 2021

With this change, does using the library mean the unmarshalled data could be string or date? If so, should we have a conversion mechanism under the hood that converts the string to a Date for consistent behavior?

Thanks for the question. In JavaScript, a Date object is stringified when passed as JSON. The conversion of the Date object to string is automatic when calling JSON.stringify or passing the data around

This change allows for the TypeScript types of date types to be strings, as that is the serialized format they come in over HTTP / over JSON.

We could create a function that parses the date string into a Date object when converting to a type, although that has trade-offs (not everyone wants JS dates) and would be a tangential feature to this PR.

WDYT @grayside ?

@grant grant requested a review from grayside June 3, 2021 17:13
@grayside
Copy link

grayside commented Jun 3, 2021

Given that clarification, and that we're calling this a breaking change (is it?), when would we receive a Date object? Maybe this should only use string?

@grant
Copy link
Contributor Author

grant commented Jun 3, 2021

Given that clarification, and that we're calling this a breaking change (is it?), when would we receive a Date object? Maybe this should only use string?

A developer should be able to pass a native JS date object in the TypeScript interface without the TS compiler complaining. Right now we are only receiving these types from Eventarc, but they can also be created. A JS developer would expect to pass Date fields and not have to stringify it before using a type.

Only string would be one option, but Date or string would be better.

@grant grant merged commit 10e1889 into master Jun 15, 2021
@grant grant deleted the grant_dates branch June 15, 2021 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: eventarc Issues related to the googleapis/google-cloudevents-nodejs API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow TypeScript dates to also be strings
2 participants