Skip to content

Commit 3bbc569

Browse files
at-ishikawastanley-cheung
authored andcommitted
[dts] Add PromiseClient type
1 parent c3c5dad commit 3bbc569

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

javascript/net/grpc/web/grpc_generator.cc

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,15 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file,
454454
}
455455
}
456456

457-
void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
458-
PrintES6Imports(printer, file);
457+
void PrintGrpcWebDtsClientClass(Printer* printer, const FileDescriptor* file, const string &client_type) {
459458
std::map<string, string> vars;
459+
vars["client_type"] = client_type;
460460
for (int service_index = 0; service_index < file->service_count();
461461
++service_index) {
462462
printer->Print("export class ");
463463
const ServiceDescriptor* service = file->service(service_index);
464464
vars["service_name"] = service->name();
465-
printer->Print(vars, "$service_name$Client {\n");
465+
printer->Print(vars, "$service_name$$client_type$ {\n");
466466
printer->Indent();
467467
printer->Print(
468468
"constructor (hostname: string,\n"
@@ -485,16 +485,27 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
485485
printer->Print(vars,
486486
"): grpcWeb.ClientReadableStream<$output_type$>;\n\n");
487487
} else {
488-
printer->Print(vars, "$js_method_name$(\n");
489-
printer->Indent();
490-
printer->Print(vars,
491-
"request: $input_type$,\n"
492-
"metadata: grpcWeb.Metadata,\n"
493-
"callback: (err: grpcWeb.Error,\n"
494-
" response: $output_type$) => void\n");
495-
printer->Outdent();
496-
printer->Print(vars,
497-
"): grpcWeb.ClientReadableStream<$output_type$>;\n\n");
488+
if (vars["client_type"] == "PromiseClient") {
489+
printer->Print(vars, "$js_method_name$(\n");
490+
printer->Indent();
491+
printer->Print(vars,
492+
"request: $input_type$,\n"
493+
"metadata: grpcWeb.Metadata\n");
494+
printer->Outdent();
495+
printer->Print(vars,
496+
"): Promise<$output_type$>;\n\n");
497+
} else {
498+
printer->Print(vars, "$js_method_name$(\n");
499+
printer->Indent();
500+
printer->Print(vars,
501+
"request: $input_type$,\n"
502+
"metadata: grpcWeb.Metadata,\n"
503+
"callback: (err: grpcWeb.Error,\n"
504+
" response: $output_type$) => void\n");
505+
printer->Outdent();
506+
printer->Print(vars,
507+
"): grpcWeb.ClientReadableStream<$output_type$>;\n\n");
508+
}
498509
}
499510
}
500511
}
@@ -503,6 +514,12 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
503514
}
504515
}
505516

517+
void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
518+
PrintES6Imports(printer, file);
519+
PrintGrpcWebDtsClientClass(printer, file, "Client");
520+
PrintGrpcWebDtsClientClass(printer, file, "PromiseClient");
521+
}
522+
506523
void PrintProtoDtsFile(Printer* printer, const FileDescriptor* file) {
507524
std::map<string, string> vars;
508525
std::map<string, const Descriptor*> messages = GetAllMessages(file);

0 commit comments

Comments
 (0)