diff --git a/javascript/net/grpc/web/grpc_generator.cc b/javascript/net/grpc/web/grpc_generator.cc index 69772459..148ded18 100644 --- a/javascript/net/grpc/web/grpc_generator.cc +++ b/javascript/net/grpc/web/grpc_generator.cc @@ -734,13 +734,31 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, printer->Outdent(); printer->Print("}\n\n"); } else { + printer->Print(vars, "$js_method_name$(\n"); + printer->Indent(); + printer->Print(vars, + "request: $input_type$,\n" + "metadata: grpcWeb.Metadata | null): Promise<$output_type$>;\n\n"); + printer->Outdent(); + printer->Print(vars, "$js_method_name$(\n"); printer->Indent(); printer->Print(vars, "request: $input_type$,\n" "metadata: grpcWeb.Metadata | null,\n" "callback: (err: grpcWeb.Error,\n" + " response: $output_type$) => void): grpcWeb.ClientReadableStream<$output_type$>;\n\n"); + printer->Outdent(); + + printer->Print(vars, "$js_method_name$(\n"); + printer->Indent(); + printer->Print(vars, + "request: $input_type$,\n" + "metadata: grpcWeb.Metadata | null,\n" + "callback?: (err: grpcWeb.Error,\n" " response: $output_type$) => void) {\n"); + printer->Print(vars, "if (callback !== undefined) {\n"); + printer->Indent(); printer->Print(vars, "return this.client_.rpcCall(\n"); printer->Indent(); printer->Print(vars, @@ -752,6 +770,16 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, "callback);\n"); printer->Outdent(); printer->Outdent(); + printer->Print(vars, + "}\n" + "return this.client_.unaryCall(\n"); + printer->Print(vars, + "this.hostname_ +\n" + " '/$package_dot$$service_name$/$method_name$',\n" + "request,\n" + "metadata || {},\n" + "this.methodInfo$method_name$);\n"); + printer->Outdent(); printer->Print("}\n\n"); } } diff --git a/packages/grpc-web/index.d.ts b/packages/grpc-web/index.d.ts index 19126ef3..ca737ebc 100644 --- a/packages/grpc-web/index.d.ts +++ b/packages/grpc-web/index.d.ts @@ -11,6 +11,12 @@ declare module "grpc-web" { } export class AbstractClientBase { + unaryCall (method: string, + request: Request, + metadata: Metadata, + methodInfo: AbstractClientBase.MethodInfo + ): Promise; + rpcCall (method: string, request: Request, metadata: Metadata,