Skip to content

Commit

Permalink
Improve types
Browse files Browse the repository at this point in the history
Signed-off-by: Sri Krishna Paritala <skrishna@buf.build>
  • Loading branch information
srikrsna-buf committed Oct 3, 2024
1 parent 177193b commit 034ee2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions packages/connect/src/protocol/invoke-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import type { DescMessage, MessageShape } from "@bufbuild/protobuf";
import type { DescMessage, DescMethod, MessageShape } from "@bufbuild/protobuf";
import { ConnectError } from "../connect-error.js";
import { Code } from "../code.js";
import type { HandlerContext, MethodImplSpec } from "../implementation.js";
Expand All @@ -29,7 +29,6 @@ import type {
UnaryResponse,
} from "../interceptor.js";
import { applyInterceptors } from "../interceptor.js";
import type { DescMethodStreaming } from "../types.js";

/**
* Invoke a user-provided implementation of a unary RPC. Returns a normalized
Expand Down Expand Up @@ -114,7 +113,7 @@ export function transformInvokeImplementation<
return {
stream: true,
message: output,
method: spec.method as DescMethodStreaming<I, O>,
method: spec.method,
...responseCommon(context, spec),
};
},
Expand All @@ -137,7 +136,7 @@ export function transformInvokeImplementation<
),
]),
stream: true,
method: spec.method as DescMethodStreaming<I, O>,
method: spec.method,
...responseCommon(context, spec),
};
},
Expand All @@ -158,7 +157,7 @@ export function transformInvokeImplementation<
spec.impl(req.message, mergeRequest(context, req)),
),
stream: true,
method: spec.method as DescMethodStreaming<I, O>,
method: spec.method,
...responseCommon(context, spec),
});
},
Expand All @@ -171,7 +170,9 @@ async function* invokeStreamImplementation<
I extends DescMessage,
O extends DescMessage,
>(
spec: MethodImplSpec<I, O>,
spec: MethodImplSpec<I, O> & {
kind: Exclude<DescMethod["methodKind"], "unary">;
},
context: HandlerContext,
input: AsyncIterable<MessageShape<I>>,
interceptors: Interceptor[],
Expand All @@ -181,7 +182,7 @@ async function* invokeStreamImplementation<
const { message, header, trailer } = await next({
stream: true,
message: input,
method: spec.method as DescMethodStreaming<I, O>,
method: spec.method,
...requestCommon(context, spec),
});
copyHeaders(header, context.responseHeader);
Expand Down
8 changes: 4 additions & 4 deletions packages/connect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type DescMethodStreaming<
export type DescMethodUnary<
I extends DescMessage = DescMessage,
O extends DescMessage = DescMessage,
> = DescMethod & {
> = Omit<DescMethod, "methodKind" | "input" | "output"> & {
methodKind: "unary";
input: I;
output: O;
Expand All @@ -35,7 +35,7 @@ export type DescMethodUnary<
export type DescMethodServerStreaming<
I extends DescMessage = DescMessage,
O extends DescMessage = DescMessage,
> = DescMethod & {
> = Omit<DescMethod, "methodKind" | "input" | "output"> & {
methodKind: "server_streaming";
input: I;
output: O;
Expand All @@ -44,7 +44,7 @@ export type DescMethodServerStreaming<
export type DescMethodClientStreaming<
I extends DescMessage = DescMessage,
O extends DescMessage = DescMessage,
> = DescMethod & {
> = Omit<DescMethod, "methodKind" | "input" | "output"> & {
methodKind: "client_streaming";
input: I;
output: O;
Expand All @@ -53,7 +53,7 @@ export type DescMethodClientStreaming<
export type DescMethodBiDiStreaming<
I extends DescMessage = DescMessage,
O extends DescMessage = DescMessage,
> = DescMethod & {
> = Omit<DescMethod, "methodKind" | "input" | "output"> & {
methodKind: "bidi_streaming";
input: I;
output: O;
Expand Down

0 comments on commit 034ee2b

Please sign in to comment.