-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add message branding with types #147
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.
Thank you for this, @odashevskii-plaid. I've run into cases like your logger example several times already. I've added a comment about the type property and my thoughts on it.
As far as I see, this could be a first step into this direction. I'm okay with it not being part of the generated interfaces for a start. I'm also okay with not caring about IMessageType.is
, isAssignable
and equals
for now. But some points should be addressed before we can sneak this in.
@timostamm thanks for the quick turnaround and detailed suggestions! I think I have addressed all your comments except adding |
Thanks so far, @odashevskii-plaid. For context: protobuf-ts/packages/plugin/src/message-type-extensions/create.ts Lines 73 to 87 in 0534891
I don't think it's possible to simply add |
@timostamm thanks for the suggestions, I was able to figure out the Compiler API, see 483882e. The final // packages/test-generated/ts-out/google/type/color.ts
create(value?: PartialMessage<Color>): Color {
const message = { red: 0, green: 0, blue: 0 };
(message as unknown as MessageTypeContainer<Color>)[MESSAGE_TYPE] = this;
if (value !== undefined)
reflectionMergePartial<Color>(this, message, value);
return message;
} |
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.
Apologies for suggesting incomplete typing for containsMessageType
earlier, @odashevskii-plaid. Have added a suggestion to address. If you could implement it, this is ready to merge.
@timostamm the new typing is cool; I've removed |
Thanks for putting up with my review 😅 @odashevskii-plaid Released in v2.0.3! |
@timostamm I understand the use-case here, but IMO this really clutters up the objects returned from I realize this wasn't a breaking change, but trying to update our codebase from 2.0.2 to 2.0.3 has been made difficult because we have some unit tests that are doing things like |
If tests break, this is a breaking change in my mind. But why do they break? Symbol properties are unlike regular properties (not listed in protobuf-ts/packages/runtime/spec/message-type.spec.ts Lines 86 to 100 in 1f6771f
It is using Jasmine 3.5. Could you share details about your setup? |
We're using Jest v26. Docs for I tracked down Jest's implementation of |
Does this symbol need to be enumerable? It seems like @odashevskii-plaid's use-case would still be met if it was non-enumerable, but perhaps his example was simplified and he would still need this to work after stuff like object spread. |
I disagree with Jest's choice and believe that symbols should only be compared with @odashevskii-plaid, you can still access the @jcready, it would be great if you could confirm the fix with Jest. |
I can confirm that making the property non-enumerable fixes the issue. Thank you for the incredibly quick turnaround. I hope no one else is broken by making it non-enumerable. |
Thanks! Released in v2.0.4. |
I've originally commented here on why this is important; in a nutshell, the existing layout when messages are fully decoupled from their types doesn't work in situations when you need to reflect on a message which came from elsewhere and its exact type is unknown.
Here's a stripped-down example:
The second argument of
enterpriseGradeLogger
is an arbitrary object; recursive redaction is applied, and for any protobuf messages, redaction is based on field annotations.With this PR, redaction logic could check if
reflectionIsProtoMessage
returns true and proceed with extracting annotations if so.