Skip to content
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 typed DescMethod variants #985

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion packages/protobuf/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
// limitations under the License.

import type { GenEnum, GenExtension, GenMessage } from "./codegenv1/types.js";
import type { DescEnum, DescExtension, DescMessage } from "./descriptors.js";
import type {
DescEnum,
DescExtension,
DescMessage,
DescMethod,
} from "./descriptors.js";
import type { OneofADT } from "./reflect/guard.js";
import type { WireType } from "./wire/index.js";
import type { JsonValue } from "./json-value.js";
Expand Down Expand Up @@ -89,6 +94,65 @@ export type UnknownField = {
readonly data: Uint8Array;
};

/**
* Describes a streaming RPC declaration.
*/
export type DescMethodStreaming<
I extends DescMessage = DescMessage,
O extends DescMessage = DescMessage,
> =
| DescMethodClientStreaming<I, O>
| DescMethodServerStreaming<I, O>
| DescMethodBiDiStreaming<I, O>;

/**
* Describes a unary RPC declaration.
*/
export type DescMethodUnary<
I extends DescMessage = DescMessage,
O extends DescMessage = DescMessage,
> = DescMethodCommon & {
methodKind: "unary";
input: I;
output: O;
};

/**
* Describes a server streaming RPC declaration.
*/
export type DescMethodServerStreaming<
I extends DescMessage = DescMessage,
O extends DescMessage = DescMessage,
> = DescMethodCommon & {
methodKind: "server_streaming";
input: I;
output: O;
};

/**
* Describes a client streaming RPC declaration.
*/
export type DescMethodClientStreaming<
I extends DescMessage = DescMessage,
O extends DescMessage = DescMessage,
> = DescMethodCommon & {
methodKind: "client_streaming";
input: I;
output: O;
};

/**
* Describes a bidi streaming RPC declaration.
*/
export type DescMethodBiDiStreaming<
I extends DescMessage = DescMessage,
O extends DescMessage = DescMessage,
> = DescMethodCommon & {
methodKind: "bidi_streaming";
input: I;
output: O;
};

/**
* The init type for a message, which makes all fields optional.
* The init type is accepted by the function create().
Expand Down Expand Up @@ -119,3 +183,5 @@ type OneofSelectedMessage<K extends string, M extends Message> = {
case: K;
value: M;
};

type DescMethodCommon = Omit<DescMethod, "methodKind" | "input" | "output">;