Skip to content

Commit

Permalink
change method name rather than coping ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfedr committed May 31, 2022
1 parent 6bcb65d commit c1cb293
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions example/generated/service.twirp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function matchHaberdasherRoute<T extends TwirpContext = TwirpContext>(
data: Buffer,
interceptors?: Interceptor<T, Size, Hat>[]
) => {
ctx = { ...ctx, methodName: "MakeHat" };
ctx.methodName = "MakeHat";
await events.onMatch(ctx);
return handleHaberdasherMakeHatRequest(
ctx,
Expand All @@ -190,7 +190,7 @@ function matchHaberdasherRoute<T extends TwirpContext = TwirpContext>(
data: Buffer,
interceptors?: Interceptor<T, FindHatRPC, FindHatRPC>[]
) => {
ctx = { ...ctx, methodName: "FindHat" };
ctx.methodName = "FindHat";
await events.onMatch(ctx);
return handleHaberdasherFindHatRequest(
ctx,
Expand All @@ -206,7 +206,7 @@ function matchHaberdasherRoute<T extends TwirpContext = TwirpContext>(
data: Buffer,
interceptors?: Interceptor<T, ListHatRPC, ListHatRPC>[]
) => {
ctx = { ...ctx, methodName: "ListHat" };
ctx.methodName = "ListHat";
await events.onMatch(ctx);
return handleHaberdasherListHatRequest(
ctx,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/protoc-gen-twirp-ts/gen/twirp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function genRouteHandler(ctx: any, file: FileDescriptorProto, service: ServiceDe
const cases = service.method.map(method => code`
case "${formatMethodName(ctx, method.name!)}":
return async (ctx: T, service: ${service.name}Twirp ,data: Buffer, interceptors?: ${Interceptor}<T, ${relativeMessageName(ctx, file, method.inputType)}, ${relativeMessageName(ctx, file, method.outputType)}>[]) => {
ctx = {...ctx, methodName: "${formatMethodName(ctx, method.name!)}" }
ctx.methodName = "${formatMethodName(ctx, method.name!)}"
await events.onMatch(ctx);
return handle${formatMethodName(ctx, method.name!, service.name)}Request(ctx, service, data, interceptors)
}
Expand Down Expand Up @@ -472,4 +472,4 @@ function formatMethodName(ctx: any, methodName: string, serviceName?: string) {

serviceName = serviceName || ""
return ctx.camelCase ? camelCase(serviceName) + camelCase(methodName) : serviceName + methodName;
}
}
6 changes: 3 additions & 3 deletions src/twirp/__mocks__/service.twirp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function matchHaberdasherRoute<T extends TwirpContext = TwirpContext>(
data: Buffer,
interceptors?: Interceptor<T, Size, Hat>[]
) => {
ctx = { ...ctx, methodName: "MakeHat" };
ctx.methodName = "MakeHat";
await events.onMatch(ctx);
return handleHaberdasherMakeHatRequest(
ctx,
Expand All @@ -190,7 +190,7 @@ function matchHaberdasherRoute<T extends TwirpContext = TwirpContext>(
data: Buffer,
interceptors?: Interceptor<T, FindHatRPC, FindHatRPC>[]
) => {
ctx = { ...ctx, methodName: "FindHat" };
ctx.methodName = "FindHat";
await events.onMatch(ctx);
return handleHaberdasherFindHatRequest(
ctx,
Expand All @@ -206,7 +206,7 @@ function matchHaberdasherRoute<T extends TwirpContext = TwirpContext>(
data: Buffer,
interceptors?: Interceptor<T, ListHatRPC, ListHatRPC>[]
) => {
ctx = { ...ctx, methodName: "ListHat" };
ctx.methodName = "ListHat";
await events.onMatch(ctx);
return handleHaberdasherListHatRequest(
ctx,
Expand Down
2 changes: 1 addition & 1 deletion src/twirp/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface TwirpContext<
> {
readonly packageName: string;
readonly serviceName: string;
readonly methodName: string;
methodName: string;

readonly contentType: TwirpContentType;
readonly req: Request;
Expand Down

0 comments on commit c1cb293

Please sign in to comment.