Skip to content

Add ProtoJS types to generated proto types #2749

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

Merged
merged 4 commits into from
Mar 18, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Mar 17, 2020

See #2715 for the bigger picture.

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/protochanges branch 2 times, most recently from 5c742e7 to 69e5386 Compare March 17, 2020 01:43
nanos?: number;
}
// Denotes the possible representations for timestamps in the Value type.
export type TimestampValue =
Copy link
Contributor

Choose a reason for hiding this comment

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

The Value proto can contain a timestamp and the name TimestampValue suggests that this is one of those, when it's really just the timestamp itself. Also, this is somewhat confusing because historically FooValue has been one of our model types and not a proto. In this regard the old TimestampProto name was better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed it to Timestamp, which aligns with LatLng and GeoPoint. I also moved it to the proto d.ts file.

@@ -148,46 +146,33 @@ export class JsonProtoSerializer {
* our generated proto interfaces say Int32Value must be. But GRPC actually
* expects a { value: <number> } struct.
*/
private toInt32Value(val: number | null): number | null {
if (this.options.useProto3Json || typeUtils.isNullOrUndefined(val)) {
private toInt32Value(val: number | null): number | { value: number } | null {
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: toInt32Value doesn't really do much to indicate that it's converting to a proto message. What do you think of renaming these (and related items) to names like toInt32Proto?

The Android/iOS convention of naming these encode/decode helps somewhat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed this instance to toInt32Proto but did not convert the methods to the encode/decode pattern. I am personally also confused by the naming in the file and constantly try to use the wrong methods (toValue instead of fromValue etc)

@@ -180,7 +180,7 @@ export declare namespace firestoreV1ApiClientInterfaces {
name?: string;
fields?: ApiClientObjectMap<Value>;
createTime?: string;
updateTime?: string;
updateTime?: string | { seconds?: string | number; nanos?: number };
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this generated or hand edited?

If hand edited, would it be worthwhile to define the timestamp type in here and reuse it for all these declarations?

Then we could just call it Timestamp and refer to it as api.Timestamp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This used to be generated, but has been hand edited many times since then. As such, I added api.Timestamp.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Mar 18, 2020
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Mar 18, 2020
@schmidt-sebastian schmidt-sebastian merged commit 70be6ac into mrschmidt/rewritefieldvalue Mar 18, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/protochanges branch March 26, 2020 03:05
@firebase firebase locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants