protobuf-ts icon indicating copy to clipboard operation
protobuf-ts copied to clipboard

Accessing "built-in" `MethodOptions` shouldn't be less convenient than accessing custom options

Open jcready opened this issue 1 year ago • 0 comments

Trying to access the IdempotencyLevel MethodOption is arguably more challenging than accessing other custom method options. One can use the convenient readMethodOption() from @protobuf-ts/runtime-rpc to get custom options which handles finding the correct MethodInfo from the list of methods on the service.

But when trying to discover a method's IdempotencyLevel one must instead manually iterate over the ServiceType.method array. At the very least it'd be convenient to have some exported function similar to readMethodOption() which would return the MethodInfo given a method name and service. Something like:

// Proposed function
function readMethodOption<I extends object = any, O extends object = any>(service: ServiceInfo, methodName: string | number): MethodInfo<I, O>;

// Usage
const idempotency = readMethodInfo(AnnotatedService, "get").idempotency;

jcready avatar May 09 '23 12:05 jcready