diff --git a/packages/protobuf/src/service-type.ts b/packages/protobuf/src/service-type.ts index d2bfe3042..a6b267375 100644 --- a/packages/protobuf/src/service-type.ts +++ b/packages/protobuf/src/service-type.ts @@ -143,3 +143,64 @@ export enum MethodIdempotency { */ Idempotent = 2, } + +interface mtShared { + readonly localName: string; + readonly service: Omit; +} + +/** + * A unary method: rpc (Input) returns (Output) + */ +export interface MethodTypeUnary, O extends Message> + extends mtShared, + MethodInfoUnary {} + +/** + * A server streaming method: rpc (Input) returns (stream Output) + */ +export interface MethodTypeServerStreaming< + I extends Message, + O extends Message, +> extends mtShared, + MethodInfoServerStreaming {} + +/** + * A client streaming method: rpc (stream Input) returns (Output) + */ +export interface MethodTypeClientStreaming< + I extends Message, + O extends Message, +> extends mtShared, + MethodInfoClientStreaming {} + +/** + * A method that streams bi-directionally: rpc (stream Input) returns (stream Output) + */ +export interface MethodTypeBiDiStreaming< + I extends Message, + O extends Message, +> extends mtShared, + MethodInfoBiDiStreaming {} + +/** + * MethodType represents a self-contained method type. It must contain + * references to the service that implements it. + * + * - "name": The original name of the protobuf rpc. + * - "I": The input message type. + * - "O": The output message type. + * - "kind": The method type. + * - "idempotency": User-provided indication whether the method will cause + * the same effect every time it is called. + * - "localName": The local name of the method, safe to use in ECMAScript. + * - "service": The service that implements the method, without methods. + */ +export type MethodType< + I extends Message = AnyMessage, + O extends Message = AnyMessage, +> = + | MethodTypeUnary + | MethodTypeServerStreaming + | MethodTypeClientStreaming + | MethodTypeBiDiStreaming;