-
Notifications
You must be signed in to change notification settings - Fork 351
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: oneof=union breaks wrapper types #458 #462
Changes from 9 commits
607d5cd
b95e27d
0e17a41
6f52e2c
8fc7544
3d231f8
a518a05
f952b0f
2649b9a
e50fbd8
92f4a3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,9 @@ export const BatchQueryRequest = { | |
|
||
fromJSON(object: any): BatchQueryRequest { | ||
const message = createBaseBatchQueryRequest(); | ||
message.ids = (object.ids ?? []).map((e: any) => String(e)); | ||
if (Array.isArray(object?.ids)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the
Which in theory should (with some handwaving) help v8 optimiziations. Can we keep the previous There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, so the idea is to get rid of the It made me wonder already why the default values for each field were overwritten each time. Thanks for clarifying, now it makes more sense. I'll change back to the ternary style. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep! @aikoven has an in-flight PR that is either doing this soon, or at least moving us closer to that I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stephenh Ah I didn't know @aikoven was already working on this. So I actually just made a PR #463 to do what you described. It was kind of simple as I was already deep into this part of the code, and had a solution in mind for the trickier 'oneof' case. So, @aikoven, if you also had something in the works and want to finish that instead, please close my PR. Sorry if I got in the way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adapting. Yeah the overall direction is to move away from mutability where you never know for sure what is set when. So a lot of recent work sent into exactly one assignment per field. This PR nicely adds to that journey There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We can easily get rid of it in fromJSON and fromPartial. For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That changed in #457, see e.g. #457 (comment). Now all fields are set to default and decode can override them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah great! |
||
message.ids = object.ids.map((e: any) => String(e)); | ||
} | ||
return message; | ||
}, | ||
|
||
|
@@ -131,7 +133,9 @@ export const BatchQueryResponse = { | |
|
||
fromJSON(object: any): BatchQueryResponse { | ||
const message = createBaseBatchQueryResponse(); | ||
message.entities = (object.entities ?? []).map((e: any) => Entity.fromJSON(e)); | ||
if (Array.isArray(object?.entities)) { | ||
message.entities = object.entities.map((e: any) => Entity.fromJSON(e)); | ||
} | ||
return message; | ||
}, | ||
|
||
|
@@ -184,7 +188,9 @@ export const BatchMapQueryRequest = { | |
|
||
fromJSON(object: any): BatchMapQueryRequest { | ||
const message = createBaseBatchMapQueryRequest(); | ||
message.ids = (object.ids ?? []).map((e: any) => String(e)); | ||
if (Array.isArray(object?.ids)) { | ||
message.ids = object.ids.map((e: any) => String(e)); | ||
} | ||
return message; | ||
}, | ||
|
||
|
@@ -308,8 +314,8 @@ export const BatchMapQueryResponse_EntitiesEntry = { | |
|
||
fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { | ||
const message = createBaseBatchMapQueryResponse_EntitiesEntry(); | ||
message.key = object.key !== undefined && object.key !== null ? String(object.key) : ''; | ||
message.value = object.value !== undefined && object.value !== null ? Entity.fromJSON(object.value) : undefined; | ||
message.key = isSet(object.key) ? String(object.key) : ''; | ||
message.value = isSet(object.value) ? Entity.fromJSON(object.value) : undefined; | ||
return message; | ||
}, | ||
|
||
|
@@ -362,7 +368,7 @@ export const GetOnlyMethodRequest = { | |
|
||
fromJSON(object: any): GetOnlyMethodRequest { | ||
const message = createBaseGetOnlyMethodRequest(); | ||
message.id = object.id !== undefined && object.id !== null ? String(object.id) : ''; | ||
message.id = isSet(object.id) ? String(object.id) : ''; | ||
return message; | ||
}, | ||
|
||
|
@@ -411,7 +417,7 @@ export const GetOnlyMethodResponse = { | |
|
||
fromJSON(object: any): GetOnlyMethodResponse { | ||
const message = createBaseGetOnlyMethodResponse(); | ||
message.entity = object.entity !== undefined && object.entity !== null ? Entity.fromJSON(object.entity) : undefined; | ||
message.entity = isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined; | ||
return message; | ||
}, | ||
|
||
|
@@ -461,7 +467,7 @@ export const WriteMethodRequest = { | |
|
||
fromJSON(object: any): WriteMethodRequest { | ||
const message = createBaseWriteMethodRequest(); | ||
message.id = object.id !== undefined && object.id !== null ? String(object.id) : ''; | ||
message.id = isSet(object.id) ? String(object.id) : ''; | ||
return message; | ||
}, | ||
|
||
|
@@ -556,8 +562,8 @@ export const Entity = { | |
|
||
fromJSON(object: any): Entity { | ||
const message = createBaseEntity(); | ||
message.id = object.id !== undefined && object.id !== null ? String(object.id) : ''; | ||
message.name = object.name !== undefined && object.name !== null ? String(object.name) : ''; | ||
message.id = isSet(object.id) ? String(object.id) : ''; | ||
message.name = isSet(object.name) ? String(object.name) : ''; | ||
return message; | ||
}, | ||
|
||
|
@@ -696,3 +702,7 @@ if (util.Long !== Long) { | |
util.Long = Long as any; | ||
configure(); | ||
} | ||
|
||
function isSet(value: any): boolean { | ||
return value !== null && value !== undefined; | ||
} |
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.
Now that this is pulled out into a nicely named helper, you can even use
value != null
.Do we need type narrowing? You can do something like