From 3fc20fbaf5bd1540e9a32b58de6545f8e509b0a0 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Wed, 13 Jan 2021 22:20:56 -0800 Subject: [PATCH] Code sync from internal code base --- javascript/net/grpc/web/abstractclientbase.js | 6 +++--- javascript/net/grpc/web/grpc_generator.cc | 11 ++++++++--- javascript/net/grpc/web/grpcwebclientbase.js | 2 +- javascript/net/grpc/web/grpcwebstreamparser.js | 8 ++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/javascript/net/grpc/web/abstractclientbase.js b/javascript/net/grpc/web/abstractclientbase.js index 5eca66f..5785681 100644 --- a/javascript/net/grpc/web/abstractclientbase.js +++ b/javascript/net/grpc/web/abstractclientbase.js @@ -28,7 +28,7 @@ goog.module.declareLegacyNamespace(); const ClientReadableStream = goog.require('grpc.web.ClientReadableStream'); -const Error = goog.require('grpc.web.Error'); +const GrpcWebError = goog.require('grpc.web.Error'); const MethodDescriptor = goog.require('grpc.web.MethodDescriptor'); const MethodType = goog.require('grpc.web.MethodType'); @@ -49,7 +49,7 @@ const AbstractClientBase = class { * @param {!MethodDescriptor| * !AbstractClientBase.MethodInfo} * methodDescriptor Information of this RPC method - * @param {function(?Error, ?)} + * @param {function(?GrpcWebError, ?)} * callback A callback function which takes (error, RESPONSE or null) * @return {!ClientReadableStream} */ @@ -65,7 +65,7 @@ const AbstractClientBase = class { * @param {!MethodDescriptor| * !AbstractClientBase.MethodInfo} * methodDescriptor Information of this RPC method - * @return {!IThenable } + * @return {!IThenable} * A promise that resolves to the response message */ thenableCall(method, requestMessage, metadata, methodDescriptor) {} diff --git a/javascript/net/grpc/web/grpc_generator.cc b/javascript/net/grpc/web/grpc_generator.cc index 29e253a..2a36655 100644 --- a/javascript/net/grpc/web/grpc_generator.cc +++ b/javascript/net/grpc/web/grpc_generator.cc @@ -582,7 +582,7 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) { printer->Print(vars, "proto.$current_package_ns$ = {};\n"); offset = dotIndex + 1; - dotIndex = package.find(".", offset); + dotIndex = package.find('.', offset); } } @@ -1338,6 +1338,7 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, GeneratorContext* context, std::map vars) { std::map method_descriptors; + bool has_server_streaming = false; // Print MethodDescriptor files. for (int i = 0; i < file->service_count(); ++i) { @@ -1351,6 +1352,9 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, string method_file_name = Lowercase(service->name()) + "_" + Lowercase(method->name()) + "_methoddescriptor.js"; + if (method->server_streaming()) { + has_server_streaming = true; + } std::unique_ptr output( context->Open(method_file_name)); Printer printer(output.get(), '$'); @@ -1406,8 +1410,9 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, printer1.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); printer1.Print(vars, "goog.require('grpc.web.Error');\n"); printer2.Print(vars, "goog.require('grpc.web.$mode$ClientBase');\n"); - printer2.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); - printer2.Print(vars, "goog.require('grpc.web.Error');\n"); + if (has_server_streaming) { + printer2.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); + } PrintClosureDependencies(&printer1, file); PrintClosureDependencies(&printer2, file); diff --git a/javascript/net/grpc/web/grpcwebclientbase.js b/javascript/net/grpc/web/grpcwebclientbase.js index 6aebfc3..3bde320 100644 --- a/javascript/net/grpc/web/grpcwebclientbase.js +++ b/javascript/net/grpc/web/grpcwebclientbase.js @@ -222,7 +222,7 @@ class GrpcWebClientBase { * @static * @template RESPONSE * @param {!ClientReadableStream} stream - * @param {function(?Error, ?RESPONSE, ?Status=, ?Metadata=)| + * @param {function(?Error, ?RESPONSE, ?Status=, ?Object=)| * function(?Error,?RESPONSE)} callback * @param {boolean} useUnaryResponse */ diff --git a/javascript/net/grpc/web/grpcwebstreamparser.js b/javascript/net/grpc/web/grpcwebstreamparser.js index 76c4c5c..6933d20 100644 --- a/javascript/net/grpc/web/grpcwebstreamparser.js +++ b/javascript/net/grpc/web/grpcwebstreamparser.js @@ -124,6 +124,14 @@ class GrpcWebStreamParser { return this.errorMessage_; } + /** + * @override + * @return {boolean} + */ + acceptsBinaryInput() { + return true; + } + /** * Parse the new input. *