-
Notifications
You must be signed in to change notification settings - Fork 655
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
grpc-loader: add method options in MethodDefinition #2230
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.
Can you send a corresponding PR to update this file with the new MethodDefinition
fields?
Yeah sure, please check this out grpc/proposal#328 |
Both of those fields seem to contain the same information; what is the purpose of adding both of them? What does each one provide that is missing from the other one? I am also still concerned about the types of these fields. |
I updated both MRs with new changes:
Waiting for your further feedback, thanks. |
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 don't like what you're currently doing with the google.api.*
option extensions. The fields are always in the MethodOptions
type, but if I understand correctly, the user needs to explicitly depend on the package and explicitly put it in the includeDirs
list for it to actually be provided. My preference would be to not single out any specific option extension for inclusion in these types, and to let users handle whatever extensions they want to use.
However, if there is a compelling reason for us to provide this specific extension directly, we should provide it consistently. That means moving google-proto-files
to the dependencies
list and adding it to the includeDirs
option ourselves.
packages/proto-loader/src/index.ts
Outdated
name?: (NamePart[]|null); | ||
identifierValue?: (string|null); | ||
positiveIntValue?: (number|Long|string|null); | ||
negativeIntValue?: (number|Long|string|null); |
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 don't like the variance in these field types. I assume it comes from the options that were passed when loading the proto files. If possible, it would be better to have a specific type for this, if possible.
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.
Could we leave custom extension type as unknown
?
export interface MethodOptions {
deprecated?: boolean;
idempotency_level?: IdempotencyLevel|keyof typeof IdempotencyLevel;
uninterpreted_option?: UninterpretedOption[];
[k: string]: unknown
}
And clean up null
values in other field types too, do you still need to separated type for UninterpretedOption
values?
export enum IdempotencyLevel {
IDEMPOTENCY_UNKNOWN = 0,
NO_SIDE_EFFECTS = 1,
IDEMPOTENT = 2
}
export interface NamePart {
namePart: string;
isExtension: boolean;
}
export interface UninterpretedOption {
name?: NamePart[];
identifierValue?: string;
positiveIntValue?: number|Long|string;
negativeIntValue?: number|Long|string;
doubleValue?: number;
stringValue?: Uint8Array|string;
aggregateValue?: string;
}
export interface CustomHttpPattern {
kind?: string;
path?: string;
}
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.
Custom extension types as unknown
seems like a good solution for that part to me. Removing the null
values from the other fields is good too, but I'm more concerned about the number|Long|string
part and similar. It would be better if we could declare in advance which specific type each field will have, either by fixing the corresponding protobuf options in advance or by having type conversion code on top of that. This also applies to stringValue
and to idempotency_level
.
Also, I just realized, what is the deal with the inconsistent field name format between MethodOptions
and the other interfaces? In descriptor.proto
, they all use snake_case.
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.
Hi, sorry for this late response.
I updated & cleaned up MethodOptions
and other related interfaces. As protobufjs
won't handle 64-bit integers in method options, it will output just number
at the moment.
I also updated new test cases; please check and let me know if you find any other issues.
packages/proto-loader/src/index.ts
Outdated
export interface MethodOptions { | ||
deprecated?: (boolean|null); | ||
idempotency_level?: (IdempotencyLevel|keyof typeof IdempotencyLevel|null); | ||
uninterpreted_option?: (UninterpretedOption[]|null); |
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 don't like having these fields as optional and/or nullable. deprecated
can coalesce to false
, idempotency_level
can coalesce to the default value, and uninterpreted_option
can coalesce to []
. Similarly, idempotency_level
can be narrowed to either IdempotencyLevel
or keyof typeof IdempotencyLevel
. In all of these cases, if the value provided by protobuf.js has a wider type, it should be explicitly narrowed in code in this library.
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 cleaned up these nullable values, and add a new test to make sure that protobuf.js won't have any fallback.
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.
These fields should also not be optional, and idempotency_level
should be exactly one of IdempotencyLevel
and keyof typeof IdempotencyLevel
. My goal here is for values provided by this library to the user to have the narrowest types possible, and we can make these narrower because we control the code that returns them. We can explicitly set a value for each field that is not already set. We can convert idempotency_level
to the chosen type if it has the wrong type.
been waiting for this feature to come out :) |
If it's ok for @hiepthai, I can try to continue work on this PR. Two questions mainly to @murgatroid99:
|
|
@murgatroid99, I created PR #2711 as a follow-up to this PR which tries to address your comments. |
Superseded by #2711. |
Add
options
andparsedOptions
intoMethodDefinition