From ca8058d9f0bf11c5e1485e8270b38da407493196 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 17:01:56 +0000 Subject: [PATCH 01/17] Upgrade and pin rules_cc and rules_java Signed-off-by: Dom Del Nano --- bazel/repositories.bzl | 3 +++ bazel/repository_locations.bzl | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 55d23e61323..5b7ab01a421 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -120,6 +120,7 @@ def _com_llvm_lib(): def _cc_deps(): # Dependencies with native bazel build files. + _bazel_repo("rules_cc") _bazel_repo("upb") _bazel_repo("com_google_protobuf", patches = ["//bazel/external:protobuf_text_format.patch", "//bazel/external:protobuf_warning.patch"], patch_args = ["-p1"]) _bazel_repo("com_github_grpc_grpc", patches = ["//bazel/external:grpc.patch", "//bazel/external:grpc_go_toolchain.patch", "//bazel/external:grpc_test_visibility.patch"], patch_args = ["-p1"]) @@ -127,6 +128,7 @@ def _cc_deps(): _bazel_repo("boringssl", patches = ["//bazel/external:boringssl.patch"], patch_args = ["-p0"]) _bazel_repo("com_google_benchmark") _bazel_repo("com_google_googletest") + # _bazel_repo("com_google_googletest", repo_mapping = {"@abseil-cpp": "@com_google_absl"}) _bazel_repo("com_github_gflags_gflags") _bazel_repo("com_github_google_glog") _bazel_repo("com_google_absl") @@ -241,6 +243,7 @@ def _pl_cc_toolchain_deps(): def _pl_deps(): _bazel_repo("bazel_gazelle") _bazel_repo("io_bazel_rules_go", patches = ["//bazel/external:rules_go.patch"], patch_args = ["-p1"]) + _bazel_repo("rules_java") _bazel_repo("io_bazel_rules_scala") _bazel_repo("rules_jvm_external") _bazel_repo("rules_foreign_cc") diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 0a2df3dcb80..d4b0ea0370a 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -451,6 +451,11 @@ REPOSITORY_LOCATIONS = dict( urls = ["http://musl.libc.org/releases/musl-1.2.3.tar.gz"], manual_license_name = "libc/musl", ), + rules_cc = dict( + sha256 = "abc605dd850f813bb37004b77db20106a19311a96b2da1c92b789da529d28fe1", + strip_prefix = "rules_cc-0.0.17", + urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz"], + ), rules_foreign_cc = dict( sha256 = "6041f1374ff32ba711564374ad8e007aef77f71561a7ce784123b9b4b88614fc", strip_prefix = "rules_foreign_cc-0.8.0", @@ -461,6 +466,12 @@ REPOSITORY_LOCATIONS = dict( strip_prefix = "rules_python-0.26.0", urls = ["https://github.com/bazelbuild/rules_python/archive/refs/tags/0.26.0.tar.gz"], ), + rules_java = dict( + sha256 = "a64ab04616e76a448c2c2d8165d836f0d2fb0906200d0b7c7376f46dd62e59cc", + urls = [ + "https://github.com/bazelbuild/rules_java/releases/download/8.6.2/rules_java-8.6.2.tar.gz", + ], + ), rules_jvm_external = dict( urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/refs/tags/5.2.tar.gz"], sha256 = "c9ae901381ae7f7eca08aed96caeb542f96c5449052db9c9d27274a8dc154cdf", From e94237774aa0563366ac156acde5caeb4531496d Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 17:28:15 +0000 Subject: [PATCH 02/17] Upgrade bazel to 6.5.0 Signed-off-by: Dom Del Nano --- .bazelversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelversion b/.bazelversion index 6abaeb2f907..f22d756da39 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.2.0 +6.5.0 From 7589df7ab7cd679e799ffd8a98b3e468dc605652 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 17:28:59 +0000 Subject: [PATCH 03/17] Upgrade absl, protobuf and grpc Signed-off-by: Dom Del Nano --- bazel/external/grpc_go_toolchain.patch | 8 +-- bazel/external/grpc_test_visibility.patch | 13 ----- bazel/external/protobuf_text_format.patch | 68 +++++++---------------- bazel/external/protobuf_warning.patch | 16 +++--- bazel/grpc_web.bzl | 2 +- bazel/proto_compile.bzl | 2 +- bazel/repositories.bzl | 7 +-- bazel/repository_locations.bzl | 19 +++---- src/carnot/exec/BUILD.bazel | 2 +- 9 files changed, 48 insertions(+), 89 deletions(-) delete mode 100644 bazel/external/grpc_test_visibility.patch diff --git a/bazel/external/grpc_go_toolchain.patch b/bazel/external/grpc_go_toolchain.patch index ec53b23de78..4d0c29c85c8 100644 --- a/bazel/external/grpc_go_toolchain.patch +++ b/bazel/external/grpc_go_toolchain.patch @@ -2,12 +2,12 @@ diff --git a/bazel/grpc_extra_deps.bzl b/bazel/grpc_extra_deps.bzl index 4d8afa3131..514189f9a5 100644 --- a/bazel/grpc_extra_deps.bzl +++ b/bazel/grpc_extra_deps.bzl -@@ -53,7 +53,7 @@ def grpc_extra_deps(ignore_version_differences = False): +@@ -63,7 +63,7 @@ def grpc_extra_deps(ignore_version_differences = False): api_dependencies() - + go_rules_dependencies() -- go_register_toolchains(version = "1.18") +- go_register_toolchains(version = "1.22.5") + go_register_toolchains() gazelle_dependencies() - + # Pull-in the go 3rd party dependencies for protoc_gen_validate, which is diff --git a/bazel/external/grpc_test_visibility.patch b/bazel/external/grpc_test_visibility.patch deleted file mode 100644 index 05f7ba64831..00000000000 --- a/bazel/external/grpc_test_visibility.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/BUILD b/BUILD -index cb6cdc2891..c4d7f2ab8c 100644 ---- a/BUILD -+++ b/BUILD -@@ -2073,7 +2073,7 @@ grpc_cc_library( - "include/grpcpp/test/mock_stream.h", - "include/grpcpp/test/server_context_test_spouse.h", - ], -- visibility = ["@grpc:grpc++_test"], -+ visibility = ["//visibility:public"], - deps = [ - "grpc++", - "grpc_base", diff --git a/bazel/external/protobuf_text_format.patch b/bazel/external/protobuf_text_format.patch index 0da75da7de7..59f88c6d44c 100644 --- a/bazel/external/protobuf_text_format.patch +++ b/bazel/external/protobuf_text_format.patch @@ -1,39 +1,13 @@ -diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc -index 594c8eac6..c7ef9437b 100644 ---- a/src/google/protobuf/stubs/strutil.cc -+++ b/src/google/protobuf/stubs/strutil.cc -@@ -592,7 +592,7 @@ void CEscapeAndAppend(StringPiece src, std::string *dest) { - } - } - --std::string CEscape(const std::string &src) { -+std::string CEscape(StringPiece src) { - std::string dest; - CEscapeAndAppend(src, &dest); - return dest; -diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h -index 9658abf90..9cf9cae83 100644 ---- a/src/google/protobuf/stubs/strutil.h -+++ b/src/google/protobuf/stubs/strutil.h -@@ -328,7 +328,7 @@ PROTOBUF_EXPORT std::string UnescapeCEscapeString(const std::string& src); - // - // Escaped chars: \n, \r, \t, ", ', \, and !isprint(). - // ---------------------------------------------------------------------- --PROTOBUF_EXPORT std::string CEscape(const std::string& src); -+PROTOBUF_EXPORT std::string CEscape(StringPiece src); - - // ---------------------------------------------------------------------- - // CEscapeAndAppend() diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc -index 19110499d..0d116ee7e 100644 +index 2c0a95d..1234567 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc -@@ -81,6 +81,18 @@ inline bool IsOctNumber(const std::string& str) { +@@ -82,6 +82,18 @@ inline bool IsOctNumber(const std::string& str) { (str[1] >= '0' && str[1] < '8')); } - -+// Returns true if truncatation occurred. -+bool TruncateString(int64_t max_length, StringPiece* s) { + ++// Returns true if truncation occurred. ++bool TruncateString(int64_t max_length, absl::string_view* s) { + if (max_length > 0) { + int64_t excess = static_cast(s->size()) - max_length; + if (excess > 0) { @@ -44,10 +18,10 @@ index 19110499d..0d116ee7e 100644 + return false; +} + - } // namespace - - namespace internal { -@@ -2555,20 +2567,22 @@ void TextFormat::Printer::PrintFieldValue(const Message& message, + // The number of fields that are redacted in AbslStringify. + std::atomic num_redacted_field{0}; + +@@ -2738,20 +2750,22 @@ void TextFormat::Printer::PrintFieldValue(const Message& message, ? reflection->GetRepeatedStringReference(message, field, index, &scratch) : reflection->GetStringReference(message, field, &scratch); @@ -60,39 +34,39 @@ index 19110499d..0d116ee7e 100644 - "......"; - value_to_print = &truncated_value; - } -+ StringPiece value_to_print(value); ++ absl::string_view value_to_print(value); + bool truncated = TruncateString(truncate_string_field_longer_than_, &value_to_print); + if (field->type() == FieldDescriptor::TYPE_STRING) { - printer->PrintString(*value_to_print, generator); + if (truncated) { -+ printer->PrintString(StrCat(value_to_print, "......"), generator); ++ printer->PrintString(absl::StrCat(value_to_print, "......"), generator); + } else { + printer->PrintString(value, generator); + } } else { - GOOGLE_DCHECK_EQ(field->type(), FieldDescriptor::TYPE_BYTES); + ABSL_DCHECK_EQ(field->type(), FieldDescriptor::TYPE_BYTES); - printer->PrintBytes(*value_to_print, generator); + if (truncated) { -+ printer->PrintBytes(StrCat(value_to_print, "......"), generator); ++ printer->PrintBytes(absl::StrCat(value_to_print, "......"), generator); + } else { + printer->PrintBytes(value, generator); + } } break; } -@@ -2708,7 +2722,14 @@ void TextFormat::Printer::PrintUnknownFields( - // This field is not parseable as a Message (or we ran out of - // recursion budget). So it is probably just a plain string. - generator->PrintMaybeWithMarker(": ", "\""); -- generator->PrintString(CEscape(value)); -+ StringPiece value_to_print(value); +@@ -2937,7 +2951,14 @@ void TextFormat::Printer::PrintUnknownFields( + break; + } + generator->PrintMaybeWithMarker(MarkerToken(), ": ", "\""); +- generator->PrintString(absl::CEscape(value)); ++ absl::string_view value_to_print(value); + bool truncated = TruncateString(truncate_string_field_longer_than_, &value_to_print); + + if (truncated) { -+ generator->PrintString(CEscape(value_to_print) + "......"); ++ generator->PrintString(absl::StrCat(absl::CEscape(value_to_print), "......")); + } else { -+ generator->PrintString(CEscape(value)); ++ generator->PrintString(absl::CEscape(value)); + } if (single_line_mode_) { generator->PrintLiteral("\" "); diff --git a/bazel/external/protobuf_warning.patch b/bazel/external/protobuf_warning.patch index 281ec297e1c..82203a2b6a0 100644 --- a/bazel/external/protobuf_warning.patch +++ b/bazel/external/protobuf_warning.patch @@ -14,20 +14,20 @@ index 5e9a2c418..f95684bd1 100644 virtual_path = ""; disk_path = parts[i]; diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc -index 5f3427dc7..ab049c7c6 100644 +index 7456d3c3d..ddcd08c17 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc -@@ -8161,10 +8161,11 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto, +@@ -10410,10 +10410,11 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto, if (is_error) { - AddError((*it)->name(), proto, DescriptorPool::ErrorCollector::IMPORT, - error_message); + AddError(unused->name(), proto, DescriptorPool::ErrorCollector::IMPORT, + make_error); - } else { -- AddWarning((*it)->name(), proto, DescriptorPool::ErrorCollector::IMPORT, -- error_message); +- AddWarning(unused->name(), proto, +- DescriptorPool::ErrorCollector::IMPORT, make_error); } + // else { -+ // AddWarning((*it)->name(), proto, DescriptorPool::ErrorCollector::IMPORT, -+ // error_message); ++ // AddWarning(unused->name(), proto, ++ // DescriptorPool::ErrorCollector::IMPORT, make_error); + // } } } diff --git a/bazel/grpc_web.bzl b/bazel/grpc_web.bzl index 097a9bb5995..322e494a5fb 100644 --- a/bazel/grpc_web.bzl +++ b/bazel/grpc_web.bzl @@ -184,7 +184,7 @@ pl_grpc_web_library = rule( default = Label("@com_google_protobuf//:well_known_protos"), ), "_protoc": attr.label( - default = Label("//external:protocol_compiler"), + default = Label("@com_google_protobuf//:protoc"), executable = True, cfg = "host", ), diff --git a/bazel/proto_compile.bzl b/bazel/proto_compile.bzl index 6969a23e681..74a26a2a50a 100644 --- a/bazel/proto_compile.bzl +++ b/bazel/proto_compile.bzl @@ -85,7 +85,7 @@ def pl_cc_proto_library(name, proto, deps = [], **kwargs): ) grpc_deps = [ "@com_github_grpc_grpc//:grpc++_codegen_proto", - "//external:protobuf", + "@com_google_protobuf//:protoc", ] pl_cc_library_internal( name = name, diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 5b7ab01a421..9d3b68e4100 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -122,13 +122,12 @@ def _cc_deps(): _bazel_repo("rules_cc") _bazel_repo("upb") - _bazel_repo("com_google_protobuf", patches = ["//bazel/external:protobuf_text_format.patch", "//bazel/external:protobuf_warning.patch"], patch_args = ["-p1"]) - _bazel_repo("com_github_grpc_grpc", patches = ["//bazel/external:grpc.patch", "//bazel/external:grpc_go_toolchain.patch", "//bazel/external:grpc_test_visibility.patch"], patch_args = ["-p1"]) + _bazel_repo("com_google_protobuf", patches = ["//bazel/external:protobuf_text_format.patch", "//bazel/external:protobuf_warning.patch"], patch_args = ["-p1"], repo_mapping = {"@abseil-cpp": "@com_google_absl"}) + _bazel_repo("com_github_grpc_grpc", patches = ["//bazel/external:grpc.patch", "//bazel/external:grpc_go_toolchain.patch"], patch_args = ["-p1"]) _bazel_repo("boringssl", patches = ["//bazel/external:boringssl.patch"], patch_args = ["-p0"]) _bazel_repo("com_google_benchmark") - _bazel_repo("com_google_googletest") - # _bazel_repo("com_google_googletest", repo_mapping = {"@abseil-cpp": "@com_google_absl"}) + _bazel_repo("com_google_googletest", repo_mapping = {"@abseil-cpp": "@com_google_absl"}) _bazel_repo("com_github_gflags_gflags") _bazel_repo("com_github_google_glog") _bazel_repo("com_google_absl") diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index d4b0ea0370a..3b79961499d 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -106,9 +106,9 @@ REPOSITORY_LOCATIONS = dict( urls = ["https://github.com/gperftools/gperftools/releases/download/gperftools-2.9.1/gperftools-2.9.1.tar.gz"], ), com_github_grpc_grpc = dict( - sha256 = "b55696fb249669744de3e71acc54a9382bea0dce7cd5ba379b356b12b82d4229", - strip_prefix = "grpc-1.51.1", - urls = ["https://github.com/grpc/grpc/archive/refs/tags/v1.51.1.tar.gz"], + sha256 = "7bf97c11cf3808d650a3a025bbf9c5f922c844a590826285067765dfd055d228", + strip_prefix = "grpc-1.74.1", + urls = ["https://github.com/grpc/grpc/archive/refs/tags/v1.74.1.tar.gz"], ), # August 19, 2020. com_github_google_sentencepiece = dict( @@ -232,9 +232,9 @@ REPOSITORY_LOCATIONS = dict( urls = ["https://github.com/pixie-io/libpypa/archive/eba8ec485a6c5e566d0d7a0716a06c91837c9d2f.tar.gz"], ), com_google_absl = dict( - sha256 = "91ac87d30cc6d79f9ab974c51874a704de9c2647c40f6932597329a282217ba8", - strip_prefix = "abseil-cpp-20220623.1", - urls = ["https://github.com/abseil/abseil-cpp/archive/refs/tags/20220623.1.tar.gz"], + sha256 = "9b7a064305e9fd94d124ffa6cc358592eb42b5da588fb4e07d09254aa40086db", + strip_prefix = "abseil-cpp-20250512.1", + urls = ["https://github.com/abseil/abseil-cpp/archive/refs/tags/20250512.1.tar.gz"], ), com_google_benchmark = dict( sha256 = "d26789a2b46d8808a48a4556ee58ccc7c497fcd4c0af9b90197674a81e04798a", @@ -262,11 +262,10 @@ REPOSITORY_LOCATIONS = dict( urls = ["https://github.com/google/googletest/archive/refs/tags/v1.17.0.tar.gz"], ), com_google_protobuf = dict( - sha256 = "63c5539a8506dc6bccd352a857cea106e0a389ce047a3ff0a78fe3f8fede410d", - strip_prefix = "protobuf-24487dd1045c7f3d64a21f38a3f0c06cc4cf2edb", + sha256 = "07a43d88fe5a38e434c7f94129cad56a4c43a51f99336074d0799c2f7d4e44c5", + strip_prefix = "protobuf-30.2", urls = [ - "https://storage.googleapis.com/grpc-bazel-mirror/github.com/protocolbuffers/protobuf/archive/24487dd1045c7f3d64a21f38a3f0c06cc4cf2edb.tar.gz", - "https://github.com/protocolbuffers/protobuf/archive/24487dd1045c7f3d64a21f38a3f0c06cc4cf2edb.tar.gz", + "https://github.com/protocolbuffers/protobuf/archive/v30.2.tar.gz", ], ), com_google_protobuf_javascript = dict( diff --git a/src/carnot/exec/BUILD.bazel b/src/carnot/exec/BUILD.bazel index 228b352501c..3f8732f705a 100644 --- a/src/carnot/exec/BUILD.bazel +++ b/src/carnot/exec/BUILD.bazel @@ -259,7 +259,7 @@ pl_cc_test( ":cc_library", ":test_utils", "//src/carnot/planpb:plan_testutils", - "@com_github_grpc_grpc//test/core/util:grpc_test_util_base", + "@com_github_grpc_grpc//test/core/test_util:grpc_test_util_base", ], ) From c8a16205f26d05071b672f4499269fca51cd9983 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 18:26:31 +0000 Subject: [PATCH 04/17] Upgrade tensorflow to v2.20.0 and flatbuffers Signed-off-by: Dom Del Nano --- .../flatbuffers_remove_rules_js_use.patch | 35 ++ .../tensorflow_disable_gpu_bazel_6.x.patch | 65 +++ bazel/external/tensorflow_disable_llvm.patch | 74 +++- bazel/external/tensorflow_disable_py.patch | 379 ++++++++++++++++-- bazel/repositories.bzl | 9 +- bazel/repository_locations.bzl | 12 +- src/carnot/exec/ml/BUILD.bazel | 4 +- src/carnot/exec/ml/coreset.h | 2 +- src/carnot/exec/ml/eigen_test_utils.h | 2 +- src/carnot/exec/ml/sampling.cc | 2 +- src/carnot/exec/ml/sampling.h | 2 +- 11 files changed, 528 insertions(+), 58 deletions(-) create mode 100644 bazel/external/flatbuffers_remove_rules_js_use.patch create mode 100644 bazel/external/tensorflow_disable_gpu_bazel_6.x.patch diff --git a/bazel/external/flatbuffers_remove_rules_js_use.patch b/bazel/external/flatbuffers_remove_rules_js_use.patch new file mode 100644 index 00000000000..bc44bd57b6a --- /dev/null +++ b/bazel/external/flatbuffers_remove_rules_js_use.patch @@ -0,0 +1,35 @@ +diff --git a/BUILD.bazel b/BUILD.bazel +index b4f015a0..70848962 100644 +--- a/BUILD.bazel ++++ b/BUILD.bazel +@@ -1,5 +1,3 @@ +-load("@aspect_rules_js//npm:defs.bzl", "npm_link_package") +-load("@npm//:defs.bzl", "npm_link_all_packages") + load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + + licenses(["notice"]) +@@ -8,12 +6,7 @@ package( + default_visibility = ["//visibility:public"], + ) + +-npm_link_all_packages(name = "node_modules") + +-npm_link_package( +- name = "node_modules/flatbuffers", +- src = "//ts:flatbuffers", +-) + + exports_files([ + "LICENSE", +@@ -40,11 +33,9 @@ filegroup( + "BUILD.bazel", + "WORKSPACE", + "build_defs.bzl", +- "typescript.bzl", + "//grpc/src/compiler:distribution", + "//reflection:distribution", + "//src:distribution", +- "//ts:distribution", + ] + glob([ + "include/flatbuffers/*.h", + ]), diff --git a/bazel/external/tensorflow_disable_gpu_bazel_6.x.patch b/bazel/external/tensorflow_disable_gpu_bazel_6.x.patch new file mode 100644 index 00000000000..31568d7b0b9 --- /dev/null +++ b/bazel/external/tensorflow_disable_gpu_bazel_6.x.patch @@ -0,0 +1,65 @@ +diff --git a/third_party/xla/third_party/gpus/cuda_configure.bzl b/third_party/xla/third_party/gpus/cuda_configure.bzl +index d110fa81460..80fccbfa234 100644 +--- a/third_party/xla/third_party/gpus/cuda_configure.bzl ++++ b/third_party/xla/third_party/gpus/cuda_configure.bzl +@@ -278,7 +278,7 @@ def _cuda_include_path(repository_ctx, cuda_config): + + def enable_cuda(repository_ctx): + """Returns whether to build with CUDA support.""" +- return int(get_host_environ(repository_ctx, "TF_NEED_CUDA", False)) ++ return int(False) + + def matches_version(environ_version, detected_version): + """Checks whether the user-specified version matches the detected version. +diff --git a/third_party/xla/third_party/gpus/rocm_configure.bzl b/third_party/xla/third_party/gpus/rocm_configure.bzl +index 80c151cde4d..b044e061473 100644 +--- a/third_party/xla/third_party/gpus/rocm_configure.bzl ++++ b/third_party/xla/third_party/gpus/rocm_configure.bzl +@@ -158,12 +158,6 @@ def _rocm_include_path(repository_ctx, rocm_config, bash_bin): + return inc_dirs + + def _enable_rocm(repository_ctx): +- enable_rocm = get_host_environ(repository_ctx, "TF_NEED_ROCM") +- if enable_rocm == "1": +- if get_cpu_value(repository_ctx) != "Linux": +- auto_configure_warning("ROCm configure is only supported on Linux") +- return False +- return True + return False + + def _amdgpu_targets(repository_ctx, rocm_toolkit_path, bash_bin): +diff --git a/third_party/xla/third_party/gpus/sycl_configure.bzl b/third_party/xla/third_party/gpus/sycl_configure.bzl +index ee63624f8e4..d60a10b10d6 100644 +--- a/third_party/xla/third_party/gpus/sycl_configure.bzl ++++ b/third_party/xla/third_party/gpus/sycl_configure.bzl +@@ -63,7 +63,7 @@ def _sycl_include_path(repository_ctx, sycl_config, bash_bin): + + def enable_sycl(repository_ctx): + """Returns whether to build with SYCL support.""" +- return int(get_host_environ(repository_ctx, "TF_NEED_SYCL", False)) ++ return int(False) + + def auto_configure_fail(msg): + """Output failure message when auto configuration fails.""" +diff --git a/third_party/xla/third_party/tensorrt/tensorrt_configure.bzl b/third_party/xla/third_party/tensorrt/tensorrt_configure.bzl +index 32c6d96f161..169df9b2a8b 100644 +--- a/third_party/xla/third_party/tensorrt/tensorrt_configure.bzl ++++ b/third_party/xla/third_party/tensorrt/tensorrt_configure.bzl +@@ -154,7 +154,7 @@ def _create_dummy_repository(repository_ctx): + + def enable_tensorrt(repository_ctx): + """Returns whether to build with TensorRT support.""" +- return int(get_host_environ(repository_ctx, _TF_NEED_TENSORRT, False)) ++ return int(False) + + def _get_tensorrt_static_path(repository_ctx): + """Returns the path for TensorRT static libraries.""" +@@ -284,7 +284,7 @@ def _py_tmpl_dict(d): + def _tensorrt_configure_impl(repository_ctx): + """Implementation of the tensorrt_configure repository rule.""" + +- if get_host_environ(repository_ctx, _TF_TENSORRT_CONFIG_REPO) != None: ++ if False: + # Forward to the pre-configured remote repository. + remote_config_repo = repository_ctx.os.environ[_TF_TENSORRT_CONFIG_REPO] + repository_ctx.template("BUILD", config_repo_label(remote_config_repo, ":BUILD"), {}) diff --git a/bazel/external/tensorflow_disable_llvm.patch b/bazel/external/tensorflow_disable_llvm.patch index 21008f649d6..55144e732e3 100644 --- a/bazel/external/tensorflow_disable_llvm.patch +++ b/bazel/external/tensorflow_disable_llvm.patch @@ -1,35 +1,67 @@ +diff --git a/tensorflow/workspace1.bzl b/tensorflow/workspace1.bzl +index b6755a6e68b..9d6562457b5 100644 +--- a/tensorflow/workspace1.bzl ++++ b/tensorflow/workspace1.bzl +@@ -4,7 +4,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") + load("@com_google_benchmark//:bazel/benchmark_deps.bzl", "benchmark_deps") + load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories") +-load("@local_xla//third_party/llvm:setup.bzl", "llvm_setup") ++# load("@local_xla//third_party/llvm:setup.bzl", "llvm_setup") + load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + load("//third_party/android:android_configure.bzl", "android_configure") + +@@ -15,7 +15,7 @@ def workspace(with_rules_cc = True): + Args: + with_rules_cc: Unused, to be removed soon. + """ +- llvm_setup(name = "llvm-project") ++ # llvm_setup(name = "llvm-project") + # native.register_toolchains("@local_config_python//:py_toolchain") + rules_pkg_dependencies() + diff --git a/tensorflow/workspace2.bzl b/tensorflow/workspace2.bzl -index 18b63ab47fb..92993d7c341 100644 +index e91df06041d..ce281ccf21c 100644 --- a/tensorflow/workspace2.bzl +++ b/tensorflow/workspace2.bzl -@@ -14,7 +14,7 @@ load("//tensorflow/tools/toolchains/embedded/arm-linux:arm_linux_toolchain_confi - load("//third_party:repo.bzl", "tf_http_archive", "tf_mirror_urls") - load("//third_party/clang_toolchain:cc_configure_clang.bzl", "cc_download_clang_toolchain") - load("//tensorflow/tools/def_file_filter:def_file_filter_configure.bzl", "def_file_filter_configure") --load("//third_party/llvm:setup.bzl", "llvm_setup") -+#load("//third_party/llvm:setup.bzl", "llvm_setup") +@@ -475,7 +475,7 @@ def _tf_repositories(): - # Import third party repository rules. See go/tfbr-thirdparty. - load("//third_party/FP16:workspace.bzl", FP16 = "repo") -@@ -530,7 +530,7 @@ def _tf_repositories(): - urls = tf_mirror_urls("https://github.com/antirez/linenoise/archive/4ce393a66b10903a0ef52edf9775ed526a17395f.tar.gz"), - ) + # Load the raw llvm-project. llvm does not have build rules set up by default, + # but provides a script for setting up build rules via overlays. +- llvm("llvm-raw") ++ # llvm("llvm-raw") + # Intel openMP that is part of LLVM sources. + tf_http_archive( +diff --git a/third_party/xla/workspace1.bzl b/third_party/xla/workspace1.bzl +index 05121708fc5..dfc5f2cedf3 100644 +--- a/third_party/xla/workspace1.bzl ++++ b/third_party/xla/workspace1.bzl +@@ -4,12 +4,12 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") + load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories") + load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") +-load("//third_party/llvm:setup.bzl", "llvm_setup") ++# load("//third_party/llvm:setup.bzl", "llvm_setup") + + # buildifier: disable=unnamed-macro + def workspace(): + """Loads a set of TensorFlow dependencies in a WORKSPACE file.""" - llvm_setup(name = "llvm-project") + # llvm_setup(name = "llvm-project") + native.register_toolchains("@local_config_python//:py_toolchain") + rules_pkg_dependencies() - # Intel openMP that is part of LLVM sources. - tf_http_archive( -diff --git a/tensorflow/workspace3.bzl b/tensorflow/workspace3.bzl -index a6c2c5c5835..3866493fcc9 100644 ---- a/tensorflow/workspace3.bzl -+++ b/tensorflow/workspace3.bzl -@@ -38,7 +38,7 @@ def workspace(): +diff --git a/third_party/xla/workspace2.bzl b/third_party/xla/workspace2.bzl +index 9e4166034d0..d34f643bd3f 100644 +--- a/third_party/xla/workspace2.bzl ++++ b/third_party/xla/workspace2.bzl +@@ -376,7 +376,7 @@ def _tf_repositories(): # Load the raw llvm-project. llvm does not have build rules set up by default, # but provides a script for setting up build rules via overlays. - llvm("llvm-raw") + # llvm("llvm-raw") - # Alias so it can be loaded without assigning to a different symbol to prevent - # shadowing previous loads and trigger a buildifier warning. + # Intel openMP that is part of LLVM sources. + tf_http_archive( diff --git a/bazel/external/tensorflow_disable_py.patch b/bazel/external/tensorflow_disable_py.patch index 8477ed66471..8021df267e4 100644 --- a/bazel/external/tensorflow_disable_py.patch +++ b/bazel/external/tensorflow_disable_py.patch @@ -1,44 +1,377 @@ -diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl -index 72bd0bcb94a..72c8987fc49 100644 ---- a/tensorflow/tensorflow.bzl -+++ b/tensorflow/tensorflow.bzl -@@ -2797,7 +2797,6 @@ _local_genrule_internal = rule( - def _local_genrule(**kwargs): - _local_genrule_internal( - exec_compatible_with = [ -- "@local_execution_config_platform//:platform_constraint", - ], - **kwargs - ) +diff --git a/tensorflow/tf_version.bzl b/tensorflow/tf_version.bzl +index e92c2d2ce2a..bc2ea14e48b 100644 +--- a/tensorflow/tf_version.bzl ++++ b/tensorflow/tf_version.bzl +@@ -1,14 +1,8 @@ + """Provides project and wheel version data for TensorFlow.""" + +-load( +- "//tensorflow:tf_version.default.bzl", +- "SEMANTIC_VERSION_SUFFIX", +- "VERSION_SUFFIX", +-) +- + # These constants are used by the targets //third_party/tensorflow/core/public:release_version, + # //third_party/tensorflow:tensorflow_bzl and //third_party/tensorflow/tools/pip_package:setup_py. + TF_VERSION = "2.20.0" + MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION = TF_VERSION.split(".") +-TF_WHEEL_VERSION_SUFFIX = VERSION_SUFFIX +-TF_SEMANTIC_VERSION_SUFFIX = SEMANTIC_VERSION_SUFFIX ++TF_WHEEL_VERSION_SUFFIX = "" ++TF_SEMANTIC_VERSION_SUFFIX = "" diff --git a/tensorflow/workspace1.bzl b/tensorflow/workspace1.bzl -index fb72d54e4d6..2f74e928d5a 100644 +index 399ff8f7579..b6755a6e68b 100644 --- a/tensorflow/workspace1.bzl +++ b/tensorflow/workspace1.bzl -@@ -14,7 +14,7 @@ def workspace(with_rules_cc = True): - Args: - with_rules_cc: whether to load and patch rules_cc repository. +@@ -16,7 +16,7 @@ def workspace(with_rules_cc = True): + with_rules_cc: Unused, to be removed soon. """ + llvm_setup(name = "llvm-project") - native.register_toolchains("@local_config_python//:py_toolchain") + # native.register_toolchains("@local_config_python//:py_toolchain") - rules_cuda_dependencies(with_rules_cc) rules_pkg_dependencies() - + + closure_repositories() diff --git a/tensorflow/workspace2.bzl b/tensorflow/workspace2.bzl -index 18b63ab47fb..0874cdd9150 100644 +index 9e49ab40b25..e91df06041d 100644 --- a/tensorflow/workspace2.bzl +++ b/tensorflow/workspace2.bzl -@@ -81,11 +81,11 @@ def _initialize_third_party(): - +@@ -20,6 +20,7 @@ load("@local_xla//third_party/FP16:workspace.bzl", FP16 = "repo") + load("@local_xla//third_party/gemmlowp:workspace.bzl", gemmlowp = "repo") + load("@local_xla//third_party/git:git_configure.bzl", "git_configure") + load("@local_xla//third_party/gpus:rocm_configure.bzl", "rocm_configure") ++load("@local_xla//third_party/gpus:cuda_configure.bzl", "cuda_configure") + load("@local_xla//third_party/gpus:sycl_configure.bzl", "sycl_configure") + load("@local_xla//third_party/highwayhash:workspace.bzl", highwayhash = "repo") + load("@local_xla//third_party/hwloc:workspace.bzl", hwloc = "repo") +@@ -105,11 +106,11 @@ def _initialize_third_party(): + # Toolchains & platforms required by Tensorflow to build. def _tf_toolchains(): - native.register_execution_platforms("@local_execution_config_platform//:platform") - native.register_toolchains("@local_execution_config_python//:py_toolchain") + # native.register_execution_platforms("@local_execution_config_platform//:platform") + # native.register_toolchains("@local_execution_config_python//:py_toolchain") - + # Loads all external repos to configure RBE builds. - initialize_rbe_configs() + # initialize_rbe_configs() - + # Note that we check the minimum bazel version in WORKSPACE. clang6_configure(name = "local_config_clang6") +@@ -117,9 +118,10 @@ def _tf_toolchains(): + tensorrt_configure(name = "local_config_tensorrt") + git_configure(name = "local_config_git") + syslibs_configure(name = "local_config_syslibs") +- python_configure(name = "local_config_python") ++ # python_configure(name = "local_config_python") ++ cuda_configure(name = "local_config_cuda") + rocm_configure(name = "local_config_rocm") + sycl_configure(name = "local_config_sycl") + remote_execution_configure(name = "local_config_remote_execution") + + # For windows bazel build +diff --git a/third_party/xla/third_party/py/rules_pywrap/pywrap.default.bzl b/third_party/xla/third_party/py/rules_pywrap/pywrap.default.bzl +index 9bbee965b57..39897ba2ef0 100644 +--- a/third_party/xla/third_party/py/rules_pywrap/pywrap.default.bzl ++++ b/third_party/xla/third_party/py/rules_pywrap/pywrap.default.bzl +@@ -1,5 +1,4 @@ + # TODO(b/356020232): remove entire file and all usages after migration is done +-load("@python_version_repo//:py_version.bzl", "USE_PYWRAP_RULES") + load( + "//third_party/py/rules_pywrap:pywrap.impl.bzl", + _pybind_extension = "pybind_extension", +@@ -91,7 +90,7 @@ def pybind_extension( + ) + + def use_pywrap_rules(): +- return USE_PYWRAP_RULES ++ return False + + def pywrap_library(name, **kwargs): + if use_pywrap_rules(): +diff --git a/third_party/xla/third_party/py/rules_pywrap/pywrap.impl.bzl b/third_party/xla/third_party/py/rules_pywrap/pywrap.impl.bzl +index 2f2f1906932..3ba3cdbf10a 100644 +--- a/third_party/xla/third_party/py/rules_pywrap/pywrap.impl.bzl ++++ b/third_party/xla/third_party/py/rules_pywrap/pywrap.impl.bzl +@@ -131,222 +131,7 @@ def pywrap_library( + testonly: The testonly argument of the resultant py_library target. + compatible_with: The compatible_with of the py_library target. + """ +- +- # 0) If pywrap_count is not specified, assume we pass pybind_extension, +- # targets directly, so actual pywrap_count should just be equal to number +- # of deps. +- actual_pywrap_count = len(deps) if pywrap_count == None else pywrap_count +- if starlark_only_deps: +- starlark_only_pywrap_count = len(starlark_only_deps) +- actual_deps = deps + starlark_only_deps +- +- # 1) Create common libraries cc-only (C API) and py-specific (parts reused +- # by different pywrap libraries but dependin on Python symbols). +- # The common library should link in everything except the object file with +- # Python Extension's init function PyInit_. +- info_collector_name = "_%s_info_collector" % name +- collected_pywrap_infos( +- name = info_collector_name, +- deps = actual_deps, +- pywrap_count = actual_pywrap_count, +- starlark_only_pywrap_count = starlark_only_pywrap_count, +- ) +- +- linker_input_filters_name = "_%s_linker_input_filters" % name +- +- cur_pkg = native.package_name() +- cur_pkg = cur_pkg + "/" if native.package_name() else cur_pkg +- starlark_only_filter_full_name = None +- if starlark_only_pywrap_count > 0: +- starlark_only_filter_full_name = "%s%s__starlark_only_common" % (cur_pkg, name) +- +- inverse_common_lib_filters = _construct_inverse_common_lib_filters( +- common_lib_filters, +- ) +- +- _linker_input_filters( +- name = linker_input_filters_name, +- dep = ":%s" % info_collector_name, +- pywrap_lib_filter = pywrap_lib_filter, +- pywrap_lib_exclusion_filter = pywrap_lib_exclusion_filter, +- common_lib_filters = inverse_common_lib_filters, +- starlark_only_filter_name = starlark_only_filter_full_name, +- enable_common_lib_starlark_only_filter = enable_common_lib_starlark_only_filter, +- ) +- +- common_deps = [] + extra_deps +- starlark_only_common_deps = [] +- binaries_data = {} +- starlark_only_binaries_data = {} +- win_binaries_data = {} +- win_starlark_only_binaries_data = {} +- internal_binaries = [] +- win_internal_binaries = [] +- +- common_lib_full_names = [] +- common_lib_full_names.extend(common_lib_filters.keys()) +- common_lib_full_names.append("%s%s_common" % (cur_pkg, name)) +- if starlark_only_filter_full_name: +- common_lib_full_names.append(starlark_only_filter_full_name) +- +- for common_lib_full_name in common_lib_full_names: +- common_lib_pkg, common_lib_name = _get_common_lib_package_and_name( +- common_lib_full_name, +- ) +- common_split_name = "_%s_split" % common_lib_name +- _pywrap_common_split_library( +- name = common_split_name, +- dep = ":%s" % info_collector_name, +- common_lib_full_name = common_lib_full_name, +- linker_input_filters = "%s" % linker_input_filters_name, +- testonly = testonly, +- compatible_with = compatible_with, +- collect_objects = select({ +- "@bazel_tools//src/conditions:windows": True, +- "//conditions:default": False, +- }), +- ) +- +- win_def_name = "_%s_def" % common_lib_name +- def_file_or_filter = common_lib_def_files_or_filters.get( +- common_lib_full_name, +- None, +- ) +- generated_common_win_def_file( +- name = win_def_name, +- dep = ":%s" % common_split_name, +- filter = def_file_or_filter, +- ) +- +- linkopts = common_lib_linkopts.get(common_lib_full_name, []) +- ver_script = common_lib_version_scripts.get(common_lib_full_name, None) +- common_cc_binary_name = "%s" % common_lib_name +- +- common_import_name, win_import_library_name = _construct_common_binary( +- common_cc_binary_name, +- common_deps + [":%s" % common_split_name], +- linkopts, +- testonly, +- compatible_with, +- ":%s" % win_def_name, +- None, +- binaries_data.values(), +- common_lib_pkg, +- ver_script, +- [":%s" % common_split_name], +- common_lib_versions.get(common_lib_full_name, ""), +- ) +- actual_binaries_data = binaries_data +- actual_common_deps = common_deps +- actual_win_binaries_data = win_binaries_data +- if common_lib_full_name == starlark_only_filter_full_name: +- actual_binaries_data = starlark_only_binaries_data +- actual_common_deps = starlark_only_common_deps +- actual_win_binaries_data = win_starlark_only_binaries_data +- internal_binaries.append(":%s" % common_cc_binary_name) +- win_internal_binaries.append(":%s" % win_import_library_name) +- actual_binaries_data[":%s" % common_cc_binary_name] = common_lib_pkg +- actual_win_binaries_data[":%s" % win_import_library_name] = common_lib_pkg +- actual_common_deps.append(":%s" % common_import_name) +- +- # 2) Create individual super-thin pywrap libraries, which depend on the +- # common one. The individual libraries must link in statically only the +- # object file with Python Extension's init function PyInit_ +- # +- shared_objects = [] +- for pywrap_index in range(0, actual_pywrap_count + starlark_only_pywrap_count): +- dep_name = "_%s_%s" % (name, pywrap_index) +- shared_object_name = "%s_shared_object" % dep_name +- win_def_name = "%s_win_def" % dep_name +- pywrap_name = "%s_pywrap" % dep_name +- +- _pywrap_split_library( +- name = pywrap_name, +- dep = ":%s" % info_collector_name, +- linker_input_filters = "%s" % linker_input_filters_name, +- pywrap_index = pywrap_index, +- testonly = testonly, +- compatible_with = compatible_with, +- ) +- +- _generated_win_def_file( +- name = win_def_name, +- dep = ":%s" % info_collector_name, +- pywrap_index = pywrap_index, +- testonly = testonly, +- compatible_with = compatible_with, +- ) +- +- actual_common_deps = common_deps +- if pywrap_index >= actual_pywrap_count: +- actual_common_deps = common_deps + starlark_only_common_deps +- +- native.cc_binary( +- name = shared_object_name, +- srcs = [], +- deps = [":%s" % pywrap_name] + actual_common_deps, +- linkshared = True, +- linkstatic = True, +- win_def_file = ":%s" % win_def_name, +- testonly = testonly, +- compatible_with = compatible_with, +- ) +- shared_objects.append(":%s" % shared_object_name) +- +- # 3) Construct final binaries with proper names and put them as data +- # attribute in a py_library, which is the final and only public artifact of +- # this macro +- # +- pywrap_binaries_name = "%s_common_binaries" % name +- wheel_locations_json_name = ":%s_wheel_locations.json" % pywrap_binaries_name +- +- win_binaries_data.update(binaries_data) +- win_starlark_only_binaries_data.update(starlark_only_binaries_data) +- +- _pywrap_binaries( +- name = pywrap_binaries_name, +- collected_pywraps = ":%s" % info_collector_name, +- deps = shared_objects, +- common_binaries = select({ +- "@bazel_tools//src/conditions:windows": win_binaries_data, +- "//conditions:default": binaries_data, +- }), +- starlark_only_common_binaries = select({ +- "@bazel_tools//src/conditions:windows": win_starlark_only_binaries_data, +- "//conditions:default": starlark_only_binaries_data, +- }), +- extension = select({ +- "@bazel_tools//src/conditions:windows": ".pyd", +- "//conditions:default": ".so", +- }), +- wheel_locations_json = wheel_locations_json_name, +- testonly = testonly, +- compatible_with = compatible_with, +- ) +- internal_binaries.append(":%s" % pywrap_binaries_name) +- internal_binaries.append(wheel_locations_json_name) +- +- all_binaries_data = list(binaries_data.keys()) +- all_binaries_data.extend(starlark_only_binaries_data.keys()) +- all_binaries_data.append(":%s" % pywrap_binaries_name) +- all_binaries_data.extend([shared_objects[-1]]) +- +- py_library( +- name = name, +- srcs = [":%s" % info_collector_name], +- data = all_binaries_data, +- testonly = testonly, +- compatible_with = compatible_with, +- visibility = visibility, +- ) +- +- native.filegroup( +- name = name + "_all_binaries", +- srcs = select({ +- "@bazel_tools//src/conditions:windows": internal_binaries + win_internal_binaries, +- "//conditions:default": internal_binaries, +- }), +- ) ++ pass + + def _construct_common_binary( + name, +@@ -1005,54 +790,11 @@ def pybind_extension(name, default_deps = None, **kwargs): + dependency on pybind11 will be added. + **kwargs: Additional arguments to pass to the python_extension. + """ ++ pass + +- actual_default_deps = ["@pybind11//:pybind11"] +- if default_deps != None: +- actual_default_deps = default_deps +- python_extension( +- name = name, +- default_deps = actual_default_deps, +- **kwargs +- ) + + def _pywrap_info_wrapper_impl(ctx): +- #the attribute is called deps not dep to match aspect's attr_aspects +- if len(ctx.attr.deps) != 1: +- fail("deps attribute must contain exactly one dependency") +- +- py_stub = ctx.actions.declare_file("%s.py" % ctx.attr.name) +- substitutions = {} +- py_pkgs = [] +- for pkg in ctx.attr.common_lib_packages: +- if pkg: +- py_pkgs.append(pkg.replace("/", ".") + "." + ctx.attr.name) +- +- if py_pkgs: +- val = "imports_paths = %s # template_val" % py_pkgs +- substitutions["imports_paths = [] # template_val"] = val +- +- ctx.actions.expand_template( +- template = ctx.file.py_stub_src, +- output = py_stub, +- substitutions = substitutions, +- ) +- +- default_runfiles = ctx.runfiles().merge( +- ctx.attr.deps[0][DefaultInfo].default_runfiles, +- ) +- +- return [ +- PyInfo(transitive_sources = depset()), +- PywrapInfo( +- cc_info = ctx.attr.deps[0][CcInfo], +- default_runfiles = default_runfiles, +- owner = ctx.label, +- common_lib_packages = ctx.attr.common_lib_packages, +- py_stub = py_stub, +- cc_only = False, +- starlark_only = ctx.attr.starlark_only, +- ), +- ] ++ pass + + _pywrap_info_wrapper = rule( + attrs = { diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 9d3b68e4100..c2dd5c996d8 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -131,9 +131,14 @@ def _cc_deps(): _bazel_repo("com_github_gflags_gflags") _bazel_repo("com_github_google_glog") _bazel_repo("com_google_absl") - _bazel_repo("com_google_flatbuffers") + _bazel_repo("com_google_flatbuffers", patches = ["//bazel/external:flatbuffers_remove_rules_js_use.patch"], patch_args = ["-p1"]) _bazel_repo("cpuinfo", patches = ["//bazel/external:cpuinfo.patch"], patch_args = ["-p1"]) - _bazel_repo("org_tensorflow", patches = ["//bazel/external:tensorflow_disable_llvm.patch", "//bazel/external:tensorflow_disable_mirrors.patch", "//bazel/external:tensorflow_disable_py.patch"], patch_args = ["-p1"]) + _bazel_repo("org_tensorflow", patches = [ + "//bazel/external:tensorflow_disable_py.patch", + "//bazel/external:tensorflow_disable_mirrors.patch", + # TODO(ddelnano): Remove once bazel 7.x is used. + "//bazel/external:tensorflow_disable_gpu_bazel_6.x.patch", + ], patch_args = ["-p1"]) _bazel_repo("com_github_neargye_magic_enum") _bazel_repo("com_github_thoughtspot_threadstacks") _bazel_repo("com_googlesource_code_re2", patches = ["//bazel/external:re2_warning.patch"], patch_args = ["-p1"]) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 3b79961499d..0db529490a9 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -252,9 +252,9 @@ REPOSITORY_LOCATIONS = dict( urls = ["https://github.com/google/farmhash/archive/2f0e005b81e296fa6963e395626137cf729b710c.tar.gz"], ), com_google_flatbuffers = dict( - sha256 = "e2dc24985a85b278dd06313481a9ca051d048f9474e0f199e372fea3ea4248c9", - strip_prefix = "flatbuffers-2.0.6", - urls = ["https://github.com/google/flatbuffers/archive/refs/tags/v2.0.6.tar.gz"], + sha256 = "4157c5cacdb59737c5d627e47ac26b140e9ee28b1102f812b36068aab728c1ed", + strip_prefix = "flatbuffers-24.3.25", + urls = ["https://github.com/google/flatbuffers/archive/refs/tags/v24.3.25.tar.gz"], ), com_google_googletest = dict( sha256 = "65fab701d9829d38cb77c14acdc431d2108bfdbf8979e40eb8ae567edf10b27c", @@ -440,9 +440,9 @@ REPOSITORY_LOCATIONS = dict( strip_prefix = "rules_scala-4ba3780fcba8d26980daff4639abc6f18517308b", ), org_tensorflow = dict( - sha256 = "99c732b92b1b37fc243a559e02f9aef5671771e272758aa4aec7f34dc92dac48", - strip_prefix = "tensorflow-2.11.0", - urls = ["https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.11.0.tar.gz"], + sha256 = "a640d1f97be316a09301dfc9347e3d929ad4d9a2336e3ca23c32c93b0ff7e5d0", + strip_prefix = "tensorflow-2.20.0", + urls = ["https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.20.0.tar.gz"], ), org_libc_musl = dict( sha256 = "7d5b0b6062521e4627e099e4c9dc8248d32a30285e959b7eecaa780cf8cfd4a4", diff --git a/src/carnot/exec/ml/BUILD.bazel b/src/carnot/exec/ml/BUILD.bazel index b2fce524782..860520eae6d 100644 --- a/src/carnot/exec/ml/BUILD.bazel +++ b/src/carnot/exec/ml/BUILD.bazel @@ -40,7 +40,7 @@ pl_cc_library( "@com_github_tencent_rapidjson//:rapidjson", "@org_tensorflow//tensorflow/lite:framework", "@org_tensorflow//tensorflow/lite/kernels:builtin_ops", - "@org_tensorflow//third_party/eigen3", + "@eigen_archive//:eigen3" ], ) @@ -51,7 +51,7 @@ pl_cc_test_library( "eigen_test_utils.h", ], deps = [ - "@org_tensorflow//third_party/eigen3", + "@eigen_archive//:eigen3" ], ) diff --git a/src/carnot/exec/ml/coreset.h b/src/carnot/exec/ml/coreset.h index 552c233f0b8..08329f4f3f4 100644 --- a/src/carnot/exec/ml/coreset.h +++ b/src/carnot/exec/ml/coreset.h @@ -28,7 +28,7 @@ #include #include -#include "third_party/eigen3/Eigen/Core" +#include "Eigen/Core" #include "src/common/base/base.h" diff --git a/src/carnot/exec/ml/eigen_test_utils.h b/src/carnot/exec/ml/eigen_test_utils.h index 13fb5c3f4c6..eabec471bd2 100644 --- a/src/carnot/exec/ml/eigen_test_utils.h +++ b/src/carnot/exec/ml/eigen_test_utils.h @@ -23,7 +23,7 @@ #include -#include "third_party/eigen3/Eigen/Core" +#include "Eigen/Core" MATCHER_P2(IsApproxMatrix, matrix, tol, "") { return matrix.isApprox(arg, static_cast(tol)); diff --git a/src/carnot/exec/ml/sampling.cc b/src/carnot/exec/ml/sampling.cc index 196ae6c56f0..987a540f611 100644 --- a/src/carnot/exec/ml/sampling.cc +++ b/src/carnot/exec/ml/sampling.cc @@ -22,7 +22,7 @@ #include #include "src/common/base/base.h" -#include "third_party/eigen3/Eigen/Core" +#include "Eigen/Core" #include "src/carnot/exec/ml/sampling.h" diff --git a/src/carnot/exec/ml/sampling.h b/src/carnot/exec/ml/sampling.h index 6d58dcc8c90..76990f6bd9d 100644 --- a/src/carnot/exec/ml/sampling.h +++ b/src/carnot/exec/ml/sampling.h @@ -19,7 +19,7 @@ #pragma once #include "src/common/base/base.h" -#include "third_party/eigen3/Eigen/Core" +#include "Eigen/Core" namespace px { namespace carnot { From d34f48931183a76ba732f7db9323af09deb65315 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 21:02:47 +0000 Subject: [PATCH 05/17] Fix absl build after upgrade Signed-off-by: Dom Del Nano --- bazel/repositories.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index c2dd5c996d8..9a5a7b21e77 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -130,7 +130,7 @@ def _cc_deps(): _bazel_repo("com_google_googletest", repo_mapping = {"@abseil-cpp": "@com_google_absl"}) _bazel_repo("com_github_gflags_gflags") _bazel_repo("com_github_google_glog") - _bazel_repo("com_google_absl") + _bazel_repo("com_google_absl", repo_mapping = {"@googletest": "@com_google_googletest"}) _bazel_repo("com_google_flatbuffers", patches = ["//bazel/external:flatbuffers_remove_rules_js_use.patch"], patch_args = ["-p1"]) _bazel_repo("cpuinfo", patches = ["//bazel/external:cpuinfo.patch"], patch_args = ["-p1"]) _bazel_repo("org_tensorflow", patches = [ From d154a2df4eac491d8e3aa3f085866f2df8378165 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 21:22:47 +0000 Subject: [PATCH 06/17] Fix linting Signed-off-by: Dom Del Nano --- src/carnot/exec/ml/BUILD.bazel | 4 ++-- src/carnot/exec/ml/sampling.cc | 2 +- src/carnot/exec/ml/sampling.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/carnot/exec/ml/BUILD.bazel b/src/carnot/exec/ml/BUILD.bazel index 860520eae6d..e87e61c52c3 100644 --- a/src/carnot/exec/ml/BUILD.bazel +++ b/src/carnot/exec/ml/BUILD.bazel @@ -38,9 +38,9 @@ pl_cc_library( "//src/shared/types:cc_library", "@com_github_google_sentencepiece//:libsentencepiece", "@com_github_tencent_rapidjson//:rapidjson", + "@eigen_archive//:eigen3", "@org_tensorflow//tensorflow/lite:framework", "@org_tensorflow//tensorflow/lite/kernels:builtin_ops", - "@eigen_archive//:eigen3" ], ) @@ -51,7 +51,7 @@ pl_cc_test_library( "eigen_test_utils.h", ], deps = [ - "@eigen_archive//:eigen3" + "@eigen_archive//:eigen3", ], ) diff --git a/src/carnot/exec/ml/sampling.cc b/src/carnot/exec/ml/sampling.cc index 987a540f611..2c71f00d677 100644 --- a/src/carnot/exec/ml/sampling.cc +++ b/src/carnot/exec/ml/sampling.cc @@ -21,8 +21,8 @@ #include #include -#include "src/common/base/base.h" #include "Eigen/Core" +#include "src/common/base/base.h" #include "src/carnot/exec/ml/sampling.h" diff --git a/src/carnot/exec/ml/sampling.h b/src/carnot/exec/ml/sampling.h index 76990f6bd9d..dc2ae06957d 100644 --- a/src/carnot/exec/ml/sampling.h +++ b/src/carnot/exec/ml/sampling.h @@ -18,8 +18,8 @@ #pragma once -#include "src/common/base/base.h" #include "Eigen/Core" +#include "src/common/base/base.h" namespace px { namespace carnot { From 1040064cd34d8ebd6ea9ed787e4c555789b2f09e Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 21:23:08 +0000 Subject: [PATCH 07/17] Upgrade protobuf to more recent supported version Signed-off-by: Dom Del Nano --- bazel/repository_locations.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 0db529490a9..1f097eb7ce6 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -262,10 +262,10 @@ REPOSITORY_LOCATIONS = dict( urls = ["https://github.com/google/googletest/archive/refs/tags/v1.17.0.tar.gz"], ), com_google_protobuf = dict( - sha256 = "07a43d88fe5a38e434c7f94129cad56a4c43a51f99336074d0799c2f7d4e44c5", - strip_prefix = "protobuf-30.2", + sha256 = "c3a0a9ece8932e31c3b736e2db18b1c42e7070cd9b881388b26d01aa71e24ca2", + strip_prefix = "protobuf-31.1", urls = [ - "https://github.com/protocolbuffers/protobuf/archive/v30.2.tar.gz", + "https://github.com/protocolbuffers/protobuf/archive/v31.1.tar.gz", ], ), com_google_protobuf_javascript = dict( From b1682d6ca776bc9392adba2a4bbaff465ba2de7f Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 21:44:18 +0000 Subject: [PATCH 08/17] Upgrade bazel skylib to fix protobuf v31.x build Signed-off-by: Dom Del Nano (cherry picked from commit f69b9d17010abe2cd8cabea7c42a4d4cc5f46f91) --- bazel/repository_locations.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 1f097eb7ce6..82a87eec7f9 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -23,10 +23,10 @@ REPOSITORY_LOCATIONS = dict( ], ), bazel_skylib = dict( - sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728", + sha256 = "51b5105a760b353773f904d2bbc5e664d0987fbaf22265164de65d43e910d8ac", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.8.1/bazel-skylib-1.8.1.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.1/bazel-skylib-1.8.1.tar.gz", ], ), # Must be called boringssl to make sure the deps pick it up correctly. From 6567b7d0e09cd92d96f0caf6a07de38f4edbf539 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 22:01:27 +0000 Subject: [PATCH 09/17] Increase dbg size threshold in stirling_wrapper_size_test Signed-off-by: Dom Del Nano --- src/stirling/e2e_tests/stirling_wrapper_size_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stirling/e2e_tests/stirling_wrapper_size_test.cc b/src/stirling/e2e_tests/stirling_wrapper_size_test.cc index 0718b01c3b3..dbc390b1816 100644 --- a/src/stirling/e2e_tests/stirling_wrapper_size_test.cc +++ b/src/stirling/e2e_tests/stirling_wrapper_size_test.cc @@ -30,7 +30,7 @@ namespace stirling { #ifdef __OPTIMIZE__ constexpr uint64_t kFileSizeLimitMB = 118; #else -constexpr uint64_t kFileSizeLimitMB = 310; +constexpr uint64_t kFileSizeLimitMB = 325; #endif TEST(StirlingWrapperSizeTest, ExecutableSizeLimit) { From 6e25c92d9e6582d797394903d33f058747daaa6c Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 22:01:40 +0000 Subject: [PATCH 10/17] Fix issue with gcc build Signed-off-by: Dom Del Nano --- src/stirling/source_connectors/socket_tracer/uprobe_manager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stirling/source_connectors/socket_tracer/uprobe_manager.h b/src/stirling/source_connectors/socket_tracer/uprobe_manager.h index 41d6e3c8157..858b5d838f1 100644 --- a/src/stirling/source_connectors/socket_tracer/uprobe_manager.h +++ b/src/stirling/source_connectors/socket_tracer/uprobe_manager.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include From 991713550a1430b3f9e0eb606bb3f208e763c305 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 22:06:12 +0000 Subject: [PATCH 11/17] Update grpc-web generator and protobuf-javascript Signed-off-by: Dom Del Nano --- bazel/external/protobuf_javascript.patch | 19 +- bazel/repository_locations.bzl | 6 +- .../protoc-gen-grpc-web/grpc_generator.cc | 788 +++++++++--------- 3 files changed, 399 insertions(+), 414 deletions(-) diff --git a/bazel/external/protobuf_javascript.patch b/bazel/external/protobuf_javascript.patch index 7241159e2c6..c150ccc6797 100644 --- a/bazel/external/protobuf_javascript.patch +++ b/bazel/external/protobuf_javascript.patch @@ -1,11 +1,24 @@ +diff --git a/generator/BUILD.bazel b/generator/BUILD.bazel +index ac7756d..a3480c8 100644 +--- a/generator/BUILD.bazel ++++ b/generator/BUILD.bazel +@@ -2,7 +2,7 @@ genrule( + name = "generate_version_header", + srcs = ["//:package.json"], + outs = ["version.h"], +- cmd = "node $(location //:generate-version-header.js) $(OUTS)", ++ cmd = "/opt/px_dev/tools/node/bin/node $(location //:generate-version-header.js) $(OUTS)", + tools = ["//:generate-version-header.js"], + ) + diff --git a/generator/js_generator.cc b/generator/js_generator.cc -index 97b5844..1351a54 100644 +index 7ba8bf0..09b1391 100644 --- a/generator/js_generator.cc +++ b/generator/js_generator.cc -@@ -3650,6 +3650,9 @@ void Generator::GenerateFile(const GeneratorOptions& options, +@@ -3647,6 +3647,9 @@ void Generator::GenerateFile(const GeneratorOptions& options, for (int i = 0; i < file->dependency_count(); i++) { - const std::string& name = file->dependency(i)->name(); + const std::string name = std::string(file->dependency(i)->name()); + if (ModuleAlias(name) == "gogoproto_gogo_pb") { + continue; + } diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 82a87eec7f9..1cee298801f 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -269,10 +269,10 @@ REPOSITORY_LOCATIONS = dict( ], ), com_google_protobuf_javascript = dict( - sha256 = "35bca1729532b0a77280bf28ab5937438e3dcccd6b31a282d9ae84c896b6f6e3", - strip_prefix = "protobuf-javascript-3.21.2", + sha256 = "123fac2e86109b24e80ccd356aa914e268bf5863ad1354d224d6ceaed6f5c45b", + strip_prefix = "protobuf-javascript-4.0.1", urls = [ - "https://github.com/protocolbuffers/protobuf-javascript/archive/refs/tags/v3.21.2.tar.gz", + "https://github.com/protocolbuffers/protobuf-javascript/archive/refs/tags/v4.0.1.tar.gz", ], ), com_googlesource_code_re2 = dict( diff --git a/third_party/protoc-gen-grpc-web/grpc_generator.cc b/third_party/protoc-gen-grpc-web/grpc_generator.cc index 276a00e73a8..8136afeca1f 100644 --- a/third_party/protoc-gen-grpc-web/grpc_generator.cc +++ b/third_party/protoc-gen-grpc-web/grpc_generator.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -27,8 +28,10 @@ #include #include #include +#include using google::protobuf::Descriptor; +using google::protobuf::Edition; using google::protobuf::EnumDescriptor; using google::protobuf::FieldDescriptor; using google::protobuf::FileDescriptor; @@ -40,6 +43,7 @@ using google::protobuf::compiler::CodeGenerator; using google::protobuf::compiler::GeneratorContext; using google::protobuf::compiler::ParseGeneratorParameter; using google::protobuf::compiler::PluginMain; +using google::protobuf::compiler::Version; using google::protobuf::io::Printer; using google::protobuf::io::ZeroCopyOutputStream; @@ -50,9 +54,8 @@ namespace { using std::string; enum Mode { - OP = 0, // first party google3 one platform services - OPJSPB = 1, // first party google3 one platform services with JSPB - GRPCWEB = 2, // client using the application/grpc-web wire format + OP = 0, // first party google3 one platform services + GRPCWEB = 1, // client using the application/grpc-web wire format }; enum ImportStyle { @@ -64,66 +67,32 @@ enum ImportStyle { const char GRPC_PROMISE[] = "grpc.web.promise.GrpcWebPromise"; const char* kKeyword[] = { - "abstract", - "boolean", - "break", - "byte", - "case", - "catch", - "char", - "class", - "const", - "continue", - "debugger", - "default", - "delete", - "do", - "double", - "else", - "enum", - "export", - "extends", - "false", - "final", - "finally", - "float", - "for", - "function", - "goto", - "if", - "implements", - "import", - "in", - "instanceof", - "int", - "interface", - "long", - "native", - "new", - "null", - "package", - "private", - "protected", - "public", - "return", - "short", - "static", - "super", - "switch", - "synchronized", - "this", - "throw", - "throws", - "transient", - "try", - "typeof", - "var", - "void", - "volatile", - "while", - "with", + "abstract", "boolean", "break", "byte", "case", + "catch", "char", "class", "const", "continue", + "debugger", "default", "delete", "do", "double", + "else", "enum", "export", "extends", "false", + "final", "finally", "float", "for", "function", + "goto", "if", "implements", "import", "in", + "instanceof", "int", "interface", "long", "native", + "new", "null", "package", "private", "protected", + "public", "return", "short", "static", "super", + "switch", "synchronized", "this", "throw", "throws", + "transient", "try", "typeof", "var", "void", + "volatile", "while", "with", }; +// Edit the version here prior to release +static const std::string GRPC_WEB_VERSION = "2.0.2"; + +string GetProtocVersion(GeneratorContext* context) { + Version compiler_version; + context->GetCompilerVersion(&compiler_version); + return std::to_string(compiler_version.major()) + "." + + std::to_string(compiler_version.minor()) + "." + + std::to_string(compiler_version.patch()) + + compiler_version.suffix(); +} + bool IsReserved(const string& ident) { for (size_t i = 0; i < sizeof(kKeyword) / sizeof(kKeyword[0]); i++) { if (ident == kKeyword[i]) { @@ -137,36 +106,35 @@ string GetModeVar(const Mode mode) { switch (mode) { case OP: return "OP"; - case OPJSPB: - return "OPJspb"; case GRPCWEB: return "GrpcWeb"; } return ""; } -string GetDeserializeMethodName(const string& mode_var) { - if (mode_var == GetModeVar(Mode::OPJSPB)) { +string GetDeserializeMethodName(std::map vars) { + if (vars["mode"] == GetModeVar(Mode::OP) && vars["binary"] == "false") { return "deserialize"; } return "deserializeBinary"; } -string GetSerializeMethodName(const string& mode_var) { - if (mode_var == GetModeVar(Mode::OPJSPB)) { +string GetSerializeMethodName(std::map vars) { + if (vars["mode"] == GetModeVar(Mode::OP) && vars["binary"] == "false") { return "serialize"; } return "serializeBinary"; } -std::string GetSerializeMethodReturnType(const string& mode_var) { - if (mode_var == GetModeVar(Mode::OPJSPB)) { +std::string GetSerializeMethodReturnType(std::map vars) { + if (vars["mode"] == GetModeVar(Mode::OP) && vars["binary"] == "false") { return "string"; } return "!Uint8Array"; } -string LowercaseFirstLetter(string s) { +string LowercaseFirstLetter(std::string_view sv) { + string s(sv); if (s.empty()) { return s; } @@ -174,7 +142,8 @@ string LowercaseFirstLetter(string s) { return s; } -string Lowercase(string s) { +string Lowercase(std::string_view sv) { + string s(sv); if (s.empty()) { return s; } @@ -185,7 +154,8 @@ string Lowercase(string s) { return s; } -string UppercaseFirstLetter(string s) { +string UppercaseFirstLetter(std::string_view sv) { + string s(sv); if (s.empty()) { return s; } @@ -193,7 +163,8 @@ string UppercaseFirstLetter(string s) { return s; } -string Uppercase(string s) { +string Uppercase(std::string_view sv) { + string s(sv); if (s.empty()) { return s; } @@ -207,49 +178,51 @@ string Uppercase(string s) { // The following 5 functions were copied from // google/protobuf/src/google/protobuf/stubs/strutil.h -inline bool HasPrefixString(const string& str, - const string& prefix) { +inline bool HasPrefixString(std::string_view str, std::string_view prefix) { return str.size() >= prefix.size() && - str.compare(0, prefix.size(), prefix) == 0; + str.compare(0, prefix.size(), prefix) == 0; } -inline string StripPrefixString(const string& str, const string& prefix) { - if (HasPrefixString(str, prefix)) { - return str.substr(prefix.size()); - } else { - return str; +// Strips the given prefix from the string, as well as the remaining leading dot +// if it exists. +inline string StripPrefixString(std::string_view str, std::string_view prefix) { + if (!HasPrefixString(str, prefix)) { + return string(str); } + + string remaining_str(str.substr(prefix.size())); + if (!remaining_str.empty() && remaining_str[0] == '.') { + remaining_str = remaining_str.substr(1); + } + return remaining_str; } -inline bool HasSuffixString(const string& str, - const string& suffix) { +inline bool HasSuffixString(std::string_view str, std::string_view suffix) { return str.size() >= suffix.size() && - str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } -inline string StripSuffixString(const string& str, const string& suffix) { +inline string StripSuffixString(std::string_view str, std::string_view suffix) { if (HasSuffixString(str, suffix)) { - return str.substr(0, str.size() - suffix.size()); + return string(str.substr(0, str.size() - suffix.size())); } else { - return str; + return string(str); } } -void ReplaceCharacters(string *s, const char *remove, char replacewith) { - const char *str_start = s->c_str(); - const char *str = str_start; - for (str = strpbrk(str, remove); - str != nullptr; +void ReplaceCharacters(string* s, const char* remove, char replacewith) { + const char* str_start = s->c_str(); + const char* str = str_start; + for (str = strpbrk(str, remove); str != nullptr; str = strpbrk(str + 1, remove)) { (*s)[str - str_start] = replacewith; } } - // The following function was copied from // google/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc -string StripProto(const string& filename) { +string StripProto(std::string_view filename) { if (HasSuffixString(filename, ".protodevel")) { return StripSuffixString(filename, ".protodevel"); } else { @@ -268,7 +241,7 @@ char ToLowerASCII(char c) { } } -std::vector ParseLowerUnderscore(const string& input) { +std::vector ParseLowerUnderscore(std::string_view input) { std::vector words; string running = ""; for (size_t i = 0; i < input.size(); i++) { @@ -301,7 +274,7 @@ string ToUpperCamel(const std::vector& words) { // Returns the alias we assign to the module of the given .proto filename // when importing. -string ModuleAlias(const string& filename) { +string ModuleAlias(std::string_view filename) { // This scheme could technically cause problems if a file includes any 2 of: // foo/bar_baz.proto // foo_bar_baz.proto @@ -316,12 +289,8 @@ string ModuleAlias(const string& filename) { return basename + "_pb"; } -string JSMessageType(const Descriptor *desc, const FileDescriptor *file) { - string class_name; - class_name = StripPrefixString(desc->full_name(), desc->file()->package()); - if (!class_name.empty() && class_name[0] == '.') { - class_name = class_name.substr(1); - } +string JSMessageType(const Descriptor* desc, const FileDescriptor* file) { + string class_name = StripPrefixString(desc->full_name(), desc->file()->package()); if (desc->file() == file) { // [for protobuf .d.ts files only] Do not add the module prefix for local // messages. @@ -330,11 +299,11 @@ string JSMessageType(const Descriptor *desc, const FileDescriptor *file) { return ModuleAlias(desc->file()->name()) + "." + class_name; } -string JSMessageType(const Descriptor *desc) { +string JSMessageType(const Descriptor* desc) { return JSMessageType(desc, nullptr); } -string JSElementType(const FieldDescriptor *desc, const FileDescriptor *file) { +string JSElementType(const FieldDescriptor* desc, const FileDescriptor* file) { switch (desc->type()) { case FieldDescriptor::TYPE_DOUBLE: case FieldDescriptor::TYPE_FLOAT: @@ -369,16 +338,12 @@ string JSElementType(const FieldDescriptor *desc, const FileDescriptor *file) { if (desc->enum_type()->file() == file) { // [for protobuf .d.ts files only] Do not add the module prefix for // local messages. - string enum_name = - StripPrefixString( - desc->enum_type()->full_name(), - desc->enum_type()->file()->package()); - return StripPrefixString(enum_name, "."); + return StripPrefixString(desc->enum_type()->full_name(), + desc->enum_type()->file()->package()); } - return ModuleAlias(desc->enum_type()->file()->name()) - + StripPrefixString( - desc->enum_type()->full_name(), - desc->enum_type()->file()->package()); + return ModuleAlias(desc->enum_type()->file()->name()) + "." + + StripPrefixString(desc->enum_type()->full_name(), + desc->enum_type()->file()->package()); case FieldDescriptor::TYPE_MESSAGE: return JSMessageType(desc->message_type(), file); @@ -388,22 +353,21 @@ string JSElementType(const FieldDescriptor *desc, const FileDescriptor *file) { } } -string JSFieldType(const FieldDescriptor *desc, const FileDescriptor *file) { +string JSFieldType(const FieldDescriptor* desc, const FileDescriptor* file) { string js_field_type = JSElementType(desc, file); if (desc->is_map()) { string key_type = JSFieldType(desc->message_type()->field(0), file); string value_type = JSFieldType(desc->message_type()->field(1), file); return "jspb.Map<" + key_type + ", " + value_type + ">"; } - if (desc->is_repeated()) - { + if (desc->is_repeated()) { return "Array<" + js_field_type + ">"; } return js_field_type; } -string AsObjectFieldType( - const FieldDescriptor *desc, const FileDescriptor *file) { +string AsObjectFieldType(const FieldDescriptor* desc, + const FileDescriptor* file) { if (desc->type() != FieldDescriptor::TYPE_MESSAGE) { return JSFieldType(desc, file); } @@ -420,11 +384,11 @@ string AsObjectFieldType( return field_type; } -string JSElementName(const FieldDescriptor *desc) { +string JSElementName(const FieldDescriptor* desc) { return ToUpperCamel(ParseLowerUnderscore(desc->name())); } -string JSFieldName(const FieldDescriptor *desc) { +string JSFieldName(const FieldDescriptor* desc) { string js_field_name = JSElementName(desc); if (desc->is_map()) { js_field_name += "Map"; @@ -435,20 +399,17 @@ string JSFieldName(const FieldDescriptor *desc) { } // Like ToUpperCamel except the first letter is not converted. -string ToCamelCase(const std::vector& words) -{ +string ToCamelCase(const std::vector& words) { if (words.empty()) { - return ""; + return ""; } string result = words[0]; return result + ToUpperCamel(std::vector( - words.begin()+1, - words.begin()+words.size())); + words.begin() + 1, words.begin() + words.size())); } // Like JSFieldName, but with first letter not uppercased -string CamelCaseJSFieldName(const FieldDescriptor *desc) -{ +string CamelCaseJSFieldName(const FieldDescriptor* desc) { string js_field_name = ToCamelCase(ParseLowerUnderscore(desc->name())); if (desc->is_map()) { js_field_name += "Map"; @@ -466,8 +427,8 @@ string GetNestedMessageName(const Descriptor* descriptor) { if (descriptor == nullptr) { return ""; } - string result = StripPrefixString(descriptor->full_name(), - descriptor->file()->package()); + string result = + StripPrefixString(descriptor->full_name(), descriptor->file()->package()); // Add a leading dot if one is not already present. if (!result.empty() && result[0] != '.') { result = "." + result; @@ -477,7 +438,7 @@ string GetNestedMessageName(const Descriptor* descriptor) { // Given a filename like foo/bar/baz.proto, returns the root directory // path ../../ -string GetRootPath(const string& from_filename, const string& to_filename) { +string GetRootPath(std::string_view from_filename, std::string_view to_filename) { if (HasPrefixString(to_filename, "google/protobuf")) { // Well-known types (.proto files in the google/protobuf directory) are // assumed to come from the 'google-protobuf' npm package. We may want to @@ -529,15 +490,37 @@ string GetBasename(string filename) { return basename; } -// Finds all message types used in all services in the file. -std::set GetAllMessages(const FileDescriptor* file) { - std::set messages; +//Adds $ suffix to reserved method names to avoid conflicts. +static bool IsReservedMethodName(const std::string& name) { + static const std::unordered_set reserved = { + "extension", + "jspbmessageid" + }; + + std::string lower_name = Lowercase(name); + + return reserved.count(lower_name) > 0; +} + +static std::string SafeAccessorName(const std::string& name) { + std::string result = name; + if (IsReservedMethodName(name)) { + result += "$"; + } + return result; +} + +// Finds all message types used in all services in the file. Return results as a +// map of full names to descriptors to get sorted results and deterministic +// build outputs. +std::map GetAllMessages(const FileDescriptor* file) { + std::map messages; for (int s = 0; s < file->service_count(); ++s) { const ServiceDescriptor* service = file->service(s); for (int m = 0; m < service->method_count(); ++m) { - const MethodDescriptor *method = service->method(m); - messages.insert(method->input_type()); - messages.insert(method->output_type()); + const MethodDescriptor* method = service->method(m); + messages[string(method->input_type()->full_name())] = method->input_type(); + messages[string(method->output_type()->full_name())] = method->output_type(); } } @@ -545,28 +528,24 @@ std::set GetAllMessages(const FileDescriptor* file) { } void PrintClosureDependencies(Printer* printer, const FileDescriptor* file) { - for (const Descriptor* message : GetAllMessages(file)) { - printer->Print( - "goog.require('proto.$full_name$');\n", - "full_name", message->full_name()); + for (const auto& entry : GetAllMessages(file)) { + printer->Print("goog.require('proto.$full_name$');\n", "full_name", + entry.second->full_name()); } - printer->Print("\n\n\n"); } void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) { std::map vars; for (int i = 0; i < file->dependency_count(); i++) { - const string& name = file->dependency(i)->name(); + const string name(file->dependency(i)->name()); vars["alias"] = ModuleAlias(name); vars["dep_filename"] = GetRootPath(file->name(), name) + StripProto(name); // we need to give each cross-file import an alias - printer->Print( - vars, - "\nvar $alias$ = require('$dep_filename$_pb.js')\n"); + printer->Print(vars, "\nvar $alias$ = require('$dep_filename$_pb.js')\n"); } - string package = file->package(); + const string package(file->package()); vars["package_name"] = package; if (!package.empty()) { @@ -580,7 +559,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); } } @@ -588,13 +567,10 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) { vars["filename"] = GetBasename(StripProto(file->name())); if (!package.empty()) { - printer->Print( - vars, - "proto.$package_name$ = require('./$filename$_pb.js');\n\n"); + printer->Print(vars, + "proto.$package_name$ = require('./$filename$_pb.js');\n\n"); } else { - printer->Print( - vars, - "const proto = require('./$filename$_pb.js');\n\n"); + printer->Print(vars, "const proto = require('./$filename$_pb.js');\n\n"); } } @@ -604,18 +580,18 @@ void PrintES6Imports(Printer* printer, const FileDescriptor* file) { printer->Print("import * as grpcWeb from 'grpc-web';\n\n"); std::set imports; - for (const Descriptor* message : GetAllMessages(file)) { - const string& name = message->file()->name(); - string dep_filename = GetRootPath(file->name(), name) + StripProto(name); + for (const auto& entry : GetAllMessages(file)) { + const string proto_filename(entry.second->file()->name()); + string dep_filename = GetRootPath(file->name(), proto_filename) + StripProto(proto_filename); if (imports.find(dep_filename) != imports.end()) { continue; } imports.insert(dep_filename); // We need to give each cross-file import an alias. - printer->Print( - "import * as $alias$ from '$dep_filename$_pb';\n", - "alias", ModuleAlias(name), - "dep_filename", dep_filename); + printer->Print("import * as $alias$ from '$dep_filename$_pb'; // proto import: \"$proto_filename$\"\n", + "alias", ModuleAlias(proto_filename), + "dep_filename", dep_filename, + "proto_filename", proto_filename); } printer->Print("\n\n"); } @@ -627,7 +603,7 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, ++service_index) { printer->Print("export class "); const ServiceDescriptor* service = file->service(service_index); - vars["service_name"] = service->name(); + vars["service_name"] = string(service->name()); printer->Print(vars, "$service_name$Client {\n"); printer->Indent(); printer->Print( @@ -646,7 +622,7 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, } printer->Print(vars, "this.client_ = new grpcWeb.$mode$ClientBase(options);\n" - "this.hostname_ = hostname;\n" + "this.hostname_ = hostname.replace(/\\/+$$/, '');\n" "this.credentials_ = credentials;\n" "this.options_ = options;\n"); printer->Outdent(); @@ -656,18 +632,23 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, ++method_index) { const MethodDescriptor* method = service->method(method_index); vars["js_method_name"] = LowercaseFirstLetter(method->name()); - vars["method_name"] = method->name(); + vars["method_name"] = string(method->name()); vars["input_type"] = JSMessageType(method->input_type()); vars["output_type"] = JSMessageType(method->output_type()); - vars["serialize_func_name"] = GetSerializeMethodName(vars["mode"]); - vars["deserialize_func_name"] = GetDeserializeMethodName(vars["mode"]); + vars["serialize_func_name"] = GetSerializeMethodName(vars); + vars["deserialize_func_name"] = GetDeserializeMethodName(vars); + vars["method_type"] = method->server_streaming() + ? "grpcWeb.MethodType.SERVER_STREAMING" + : "grpcWeb.MethodType.UNARY"; if (!method->client_streaming()) { - // TODO(jennyjiang): use methodDescriptor? printer->Print(vars, - "methodInfo$method_name$ = " - "new grpcWeb.AbstractClientBase.MethodInfo(\n"); + "methodDescriptor$method_name$ = " + "new grpcWeb.MethodDescriptor(\n"); printer->Indent(); printer->Print(vars, + "'/$package_dot$$service_name$/$method_name$',\n" + "$method_type$,\n" + "$input_type$,\n" "$output_type$,\n" "(request: $input_type$) => {\n" " return request.$serialize_func_name$();\n" @@ -680,16 +661,16 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, printer->Indent(); printer->Print(vars, "request: $input_type$,\n" - "metadata?: grpcWeb.Metadata) {\n"); + "metadata?: grpcWeb.Metadata): " + "grpcWeb.ClientReadableStream<$output_type$> {\n"); printer->Print(vars, "return this.client_.serverStreaming(\n"); printer->Indent(); - printer->Print( - vars, - "this.hostname_ +\n" - " '/$package_dot$$service_name$/$method_name$',\n" - "request,\n" - "metadata || {},\n" - "this.methodInfo$method_name$);\n"); + printer->Print(vars, + "this.hostname_ +\n" + " '/$package_dot$$service_name$/$method_name$',\n" + "request,\n" + "metadata || {},\n" + "this.methodDescriptor$method_name$);\n"); printer->Outdent(); printer->Outdent(); printer->Print("}\n\n"); @@ -698,7 +679,7 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, printer->Indent(); printer->Print(vars, "request: $input_type$,\n" - "metadata: grpcWeb.Metadata | null): " + "metadata?: grpcWeb.Metadata | null): " "$promise$<$output_type$>;\n\n"); printer->Outdent(); @@ -707,7 +688,7 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, printer->Print(vars, "request: $input_type$,\n" "metadata: grpcWeb.Metadata | null,\n" - "callback: (err: grpcWeb.Error,\n" + "callback: (err: grpcWeb.RpcError,\n" " response: $output_type$) => void): " "grpcWeb.ClientReadableStream<$output_type$>;\n\n"); printer->Outdent(); @@ -716,21 +697,20 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, printer->Indent(); printer->Print(vars, "request: $input_type$,\n" - "metadata: grpcWeb.Metadata | null,\n" - "callback?: (err: grpcWeb.Error,\n" + "metadata?: grpcWeb.Metadata | null,\n" + "callback?: (err: grpcWeb.RpcError,\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, - "this.hostname_ +\n" - " '/$package_dot$$service_name$/$method_name$',\n" - "request,\n" - "metadata || {},\n" - "this.methodInfo$method_name$,\n" - "callback);\n"); + printer->Print(vars, + "this.hostname_ +\n" + " '/$package_dot$$service_name$/$method_name$',\n" + "request,\n" + "metadata || {},\n" + "this.methodDescriptor$method_name$,\n" + "callback);\n"); printer->Outdent(); printer->Outdent(); printer->Print(vars, @@ -741,7 +721,7 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, " '/$package_dot$$service_name$/$method_name$',\n" "request,\n" "metadata || {},\n" - "this.methodInfo$method_name$);\n"); + "this.methodDescriptor$method_name$);\n"); printer->Outdent(); printer->Print("}\n\n"); } @@ -753,7 +733,7 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, } void PrintGrpcWebDtsClientClass(Printer* printer, const FileDescriptor* file, - const string &client_type) { + const string& client_type) { std::map vars; vars["client_type"] = client_type; vars["promise"] = "Promise"; @@ -761,7 +741,7 @@ void PrintGrpcWebDtsClientClass(Printer* printer, const FileDescriptor* file, ++service_index) { printer->Print("export class "); const ServiceDescriptor* service = file->service(service_index); - vars["service_name"] = service->name(); + vars["service_name"] = string(service->name()); printer->Print(vars, "$service_name$$client_type$ {\n"); printer->Indent(); printer->Print( @@ -799,7 +779,7 @@ void PrintGrpcWebDtsClientClass(Printer* printer, const FileDescriptor* file, printer->Print(vars, "request: $input_type$,\n" "metadata: grpcWeb.Metadata | undefined,\n" - "callback: (err: grpcWeb.Error,\n" + "callback: (err: grpcWeb.RpcError,\n" " response: $output_type$) => void\n"); printer->Outdent(); printer->Print(vars, @@ -820,15 +800,16 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) { PrintGrpcWebDtsClientClass(printer, file, "PromiseClient"); } -void PrintProtoDtsEnum(Printer *printer, const EnumDescriptor *desc) -{ +void PrintProtoDtsEnum(Printer* printer, const EnumDescriptor* desc) { std::map vars; - vars["enum_name"] = desc->name(); + vars["enum_name"] = string(desc->name()); - printer->Print(vars, "export enum $enum_name$ { \n"); + // Use regular enums for broad TypeScript compatibility. `const enum` + // triggers TS2748 when `verbatimModuleSyntax` is enabled (default in + // TypeScript 5.9+), so prefer `enum` here. + printer->Print(vars, "export enum $enum_name$ {\n"); printer->Indent(); - for (int i = 0; i < desc->value_count(); i++) - { + for (int i = 0; i < desc->value_count(); i++) { vars["value_name"] = Uppercase(desc->value(i)->name()); vars["value_number"] = std::to_string(desc->value(i)->number()); printer->Print(vars, "$value_name$ = $value_number$,\n"); @@ -837,17 +818,18 @@ void PrintProtoDtsEnum(Printer *printer, const EnumDescriptor *desc) printer->Print("}\n"); } -void PrintProtoDtsOneofCase(Printer *printer, const OneofDescriptor *desc) -{ +void PrintProtoDtsOneofCase(Printer* printer, const OneofDescriptor* desc) { std::map vars; vars["oneof_name"] = ToUpperCamel(ParseLowerUnderscore(desc->name())); vars["oneof_name_upper"] = Uppercase(desc->name()); - printer->Print(vars, "export enum $oneof_name$Case { \n"); + // Oneof case enums also use regular enums to avoid ambient `const enum` + // issues under `verbatimModuleSyntax`. + printer->Print(vars, "export enum $oneof_name$Case {\n"); printer->Indent(); printer->Print(vars, "$oneof_name_upper$_NOT_SET = 0,\n"); for (int i = 0; i < desc->field_count(); i++) { - const FieldDescriptor *field = desc->field(i); + const FieldDescriptor* field = desc->field(i); vars["field_name"] = Uppercase(field->name()); vars["field_number"] = std::to_string(field->number()); printer->Print(vars, "$field_name$ = $field_number$,\n"); @@ -856,9 +838,9 @@ void PrintProtoDtsOneofCase(Printer *printer, const OneofDescriptor *desc) printer->Print("}\n"); } -void PrintProtoDtsMessage(Printer *printer, const Descriptor *desc, - const FileDescriptor *file) { - string class_name = desc->name(); +void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc, + const FileDescriptor* file) { + const string class_name(desc->name()); std::map vars; vars["class_name"] = class_name; @@ -866,12 +848,12 @@ void PrintProtoDtsMessage(Printer *printer, const Descriptor *desc, printer->Indent(); for (int i = 0; i < desc->field_count(); i++) { const FieldDescriptor* field = desc->field(i); - vars["js_field_name"] = JSFieldName(field); + + vars["js_field_name"] = SafeAccessorName(JSFieldName(field)); vars["js_field_type"] = JSFieldType(field, file); if (field->type() != FieldDescriptor::TYPE_MESSAGE || field->is_repeated()) { - printer->Print(vars, - "get$js_field_name$(): $js_field_type$;\n"); + printer->Print(vars, "get$js_field_name$(): $js_field_type$;\n"); } else { printer->Print(vars, "get$js_field_name$(): $js_field_type$ | undefined;\n"); @@ -891,16 +873,16 @@ void PrintProtoDtsMessage(Printer *printer, const Descriptor *desc, "set$js_field_name$(value?: $js_field_type$): " "$class_name$;\n"); } - if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_repeated() - && !field->is_map()) { + if (field->has_presence()) { printer->Print(vars, "has$js_field_name$(): boolean;\n"); } if (field->type() == FieldDescriptor::TYPE_MESSAGE || - field->is_repeated() || field->is_map()) { + field->has_presence() || field->is_repeated() || field->is_map()) { printer->Print(vars, "clear$js_field_name$(): $class_name$;\n"); } if (field->is_repeated() && !field->is_map()) { - vars["js_field_name"] = JSElementName(field); + + vars["js_field_name"] = SafeAccessorName(JSElementName(field)); vars["js_field_type"] = JSElementType(field, file); if (field->type() != FieldDescriptor::TYPE_MESSAGE) { printer->Print(vars, @@ -916,12 +898,11 @@ void PrintProtoDtsMessage(Printer *printer, const Descriptor *desc, printer->Print("\n"); } - for (int i = 0; i < desc->oneof_decl_count(); i++) { - const OneofDescriptor* oneof = desc->oneof_decl(i); + for (int i = 0; i < desc->real_oneof_decl_count(); i++) { + const OneofDescriptor *oneof = desc->real_oneof_decl(i); vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name())); printer->Print( - vars, - "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n"); + vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n"); printer->Print("\n"); } @@ -946,21 +927,22 @@ void PrintProtoDtsMessage(Printer *printer, const Descriptor *desc, printer->Indent(); for (int i = 0; i < desc->field_count(); i++) { const FieldDescriptor* field = desc->field(i); + string js_field_name = CamelCaseJSFieldName(field); if (IsReserved(js_field_name)) { js_field_name = "pb_" + js_field_name; } + vars["js_field_name"] = js_field_name; vars["js_field_type"] = AsObjectFieldType(field, file); - if (field->type() != FieldDescriptor::TYPE_MESSAGE || - field->is_repeated()) { - printer->Print(vars, "$js_field_name$: $js_field_type$,\n"); + if (!field->has_presence()) { + printer->Print(vars, "$js_field_name$: $js_field_type$;\n"); } else { - printer->Print(vars, "$js_field_name$?: $js_field_type$,\n"); + printer->Print(vars, "$js_field_name$?: $js_field_type$;\n"); } } printer->Outdent(); - printer->Print("}\n"); + printer->Print("};\n"); for (int i = 0; i < desc->nested_type_count(); i++) { if (desc->nested_type(i)->options().map_entry()) { @@ -984,17 +966,16 @@ void PrintProtoDtsMessage(Printer *printer, const Descriptor *desc, printer->Print("}\n\n"); } -void PrintProtoDtsFile(Printer *printer, const FileDescriptor *file) -{ +void PrintProtoDtsFile(Printer* printer, const FileDescriptor* file) { printer->Print("import * as jspb from 'google-protobuf'\n\n"); for (int i = 0; i < file->dependency_count(); i++) { - const string& name = file->dependency(i)->name(); + const string proto_filename(file->dependency(i)->name()); // We need to give each cross-file import an alias. - printer->Print( - "import * as $alias$ from '$dep_filename$_pb';\n", - "alias", ModuleAlias(name), - "dep_filename", GetRootPath(file->name(), name) + StripProto(name)); + printer->Print("import * as $alias$ from '$dep_filename$_pb'; // proto import: \"$proto_filename$\"\n", + "alias", ModuleAlias(proto_filename), + "dep_filename", GetRootPath(file->name(), proto_filename) + StripProto(proto_filename), + "proto_filename", proto_filename); } printer->Print("\n\n"); @@ -1015,7 +996,11 @@ void PrintFileHeader(Printer* printer, const std::map& vars) { " * @enhanceable\n" " * @public\n" " */\n\n" - "// GENERATED CODE -- DO NOT EDIT!\n\n\n" + "// Code generated by protoc-gen-grpc-web. DO NOT EDIT.\n" + "// versions:\n" + "// \tprotoc-gen-grpc-web v$version$\n" + "// \tprotoc v$protoc_version$\n" + "// source: $source_file$\n\n\n" "/* eslint-disable */\n" "// @ts-nocheck\n\n\n"); } @@ -1025,17 +1010,29 @@ void PrintMethodDescriptorFile(Printer* printer, printer->Print( vars, "/**\n" - " * @fileoverview gRPC-Web generated MethodDescriptors for $package$\n" - " * @enhanceable\n" + " * @fileoverview gRPC-Web generated MethodDescriptors for $package$\n"); + if (vars["plugins"].empty()) { + printer->Print(" * @enhanceable\n"); + } + printer->Print( " * @public\n" " */\n\n" - "// GENERATED CODE -- DO NOT EDIT!\n\n\n" + "// Code generated by protoc-gen-grpc-web. DO NOT EDIT.\n" + "// versions:\n" + "// \tprotoc-gen-grpc-web v$version$\n" + "// \tprotoc v$protoc_version$\n" + "// source: $source_file$\n\n\n" "/* eslint-disable */\n" "// @ts-nocheck\n\n\n"); printer->Print(vars, "goog.provide('proto.$package_dot$$class_name$.$" "method_name$MethodDescriptor');\n\n"); + if (!vars["plugins"].empty()) { + printer->Print(vars, + "goog.require('$plugins$.$package_dot$$class_name$.$" + "method_name$MethodDescriptor');\n"); + } printer->Print(vars, "goog.require('grpc.web.MethodDescriptor');\n"); printer->Print(vars, "goog.require('grpc.web.MethodType');\n"); printer->Print(vars, "goog.require('$in_type$');\n"); @@ -1067,16 +1064,15 @@ void PrintMethodDescriptorFile(Printer* printer, "/**\n" " * @param {!proto.$in$} request\n"); printer->Print( - (" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n") - .c_str()); - printer->Print(" */\n" - "function(request) {\n"); + (" * @return {" + GetSerializeMethodReturnType(vars) + "}\n").c_str()); printer->Print( - (" return request." + GetSerializeMethodName(vars["mode"]) + "();\n") - .c_str()); - printer->Print("},\n"); + " */\n" + "function(request) {\n"); printer->Print( - vars, ("$out_type$." + GetDeserializeMethodName(vars["mode"])).c_str()); + (" return request." + GetSerializeMethodName(vars) + "();\n").c_str()); + printer->Print("},\n"); + printer->Print(vars, + ("$out_type$." + GetDeserializeMethodName(vars)).c_str()); printer->Print(vars, ");\n\n\n"); printer->Outdent(); printer->Outdent(); @@ -1085,132 +1081,77 @@ void PrintMethodDescriptorFile(Printer* printer, printer->Print("}); // goog.scope\n\n"); } -void PrintServiceConstructor(Printer* printer, - std::map vars) { - printer->Print( - vars, - "/**\n" - " * @param {string} hostname\n" - " * @param {?Object} credentials\n" - " * @param {?Object} options\n" - " * @constructor\n" - " * @struct\n" - " * @final\n" - " */\n" - "proto.$package_dot$$service_name$Client =\n" - " function(hostname, credentials, options) {\n" - " if (!options) options = {};\n"); - if (vars["mode"] == GetModeVar(Mode::GRPCWEB)) { - printer->Print( - vars, - " options['format'] = '$format$';\n\n"); - } - printer->Print( - vars, - " /**\n" - " * @private @const {!grpc.web.$mode$ClientBase} The client\n" - " */\n" - " this.client_ = new grpc.web.$mode$ClientBase(options);\n\n" - " /**\n" - " * @private @const {string} The hostname\n" - " */\n" - " this.hostname_ = hostname;\n\n" - "};\n\n\n"); -} - -void PrintPromiseServiceConstructor(Printer* printer, - std::map vars) { +void PrintServiceConstructor(Printer* printer, std::map vars, + bool is_promise) { + vars["is_promise"] = is_promise ? "Promise" : ""; printer->Print(vars, "/**\n" " * @param {string} hostname\n" " * @param {?Object} credentials\n" - " * @param {?Object} options\n" + " * @param {?grpc.web.ClientOptions} options\n" " * @constructor\n" " * @struct\n" " * @final\n" " */\n" - "proto.$package_dot$$service_name$PromiseClient =\n" + "proto.$package_dot$$service_name$$is_promise$Client =\n" " function(hostname, credentials, options) {\n" " if (!options) options = {};\n"); if (vars["mode"] == GetModeVar(Mode::GRPCWEB)) { - printer->Print(vars, " options['format'] = '$format$';\n\n"); + printer->Print(vars, " options.format = '$format$';\n\n"); } - printer->Print( - vars, - " /**\n" - " * @private @const {!grpc.web.$mode$ClientBase} The client\n" - " */\n" - " this.client_ = new grpc.web.$mode$ClientBase(options);\n\n" - " /**\n" - " * @private @const {string} The hostname\n" - " */\n" - " this.hostname_ = hostname;\n\n" - "};\n\n\n"); -} - -void PrintMethodInfo(Printer* printer, std::map vars) { - // Print MethodDescriptor. - printer->Print(vars, - "/**\n" - " * @const\n" - " * @type {!grpc.web.MethodDescriptor<\n" - " * !proto.$in$,\n" - " * !proto.$out$>}\n" - " */\n" - "const methodDescriptor_$service_name$_$method_name$ = " - "new grpc.web.MethodDescriptor(\n"); - printer->Indent(); - printer->Print(vars, - "'/$package_dot$$service_name$/$method_name$',\n" - "$method_type$,\n" - "$in_type$,\n"); - printer->Print(vars, - "$out_type$,\n" - "/**\n" - " * @param {!proto.$in$} request\n"); - printer->Print( - (" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n") - .c_str()); - printer->Print(" */\n" - "function(request) {\n"); + if (vars["mode"] == GetModeVar(Mode::OP)) { printer->Print( - (" return request." + GetSerializeMethodName(vars["mode"]) + "();\n") - .c_str()); - printer->Print("},\n"); + vars, + " /**\n" + " * @private @const {!grpc.web.$mode$ClientBase} The client\n" + " */\n" + " this.client_ = new grpc.web.$mode$ClientBase(options, " + "$binary$);\n\n"); + } else { printer->Print( - vars, ("$out_type$." + GetDeserializeMethodName(vars["mode"]) + "\n") - .c_str()); - printer->Outdent(); - printer->Print(vars, ");\n\n\n"); + vars, + " /**\n" + " * @private @const {!grpc.web.$mode$ClientBase} The client\n" + " */\n" + " this.client_ = new grpc.web.$mode$ClientBase(options);\n\n"); + } + printer->PrintRaw( + " /**\n" + " * @private @const {string} The hostname\n" + " */\n" + " this.hostname_ = hostname.replace(/\\/+$/, '');\n\n" + "};\n\n\n"); +} - // Print AbstractClientBase.MethodInfo, which will be deprecated. +void PrintMethodDescriptor(Printer* printer, std::map vars) { printer->Print(vars, "/**\n" " * @const\n" - " * @type {!grpc.web.AbstractClientBase.MethodInfo<\n" + " * @type {!grpc.web.MethodDescriptor<\n" " * !proto.$in$,\n" " * !proto.$out$>}\n" " */\n" - "const methodInfo_$service_name$_$method_name$ = " - "new grpc.web.AbstractClientBase.MethodInfo(\n"); + "const methodDescriptor_$service_name$_$method_name$ = " + "new grpc.web.MethodDescriptor(\n"); printer->Indent(); - + printer->Print(vars, + "'/$package_dot$$service_name$/$method_name$',\n" + "$method_type$,\n" + "$in_type$,\n"); printer->Print(vars, "$out_type$,\n" "/**\n" " * @param {!proto.$in$} request\n"); printer->Print( - (" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n") - .c_str()); - printer->Print(" */\n" - "function(request) {\n"); + (" * @return {" + GetSerializeMethodReturnType(vars) + "}\n").c_str()); + printer->Print( + " */\n" + "function(request) {\n"); printer->Print( - (" return request." + GetSerializeMethodName(vars["mode"]) + "();\n") - .c_str()); + (" return request." + GetSerializeMethodName(vars) + "();\n").c_str()); printer->Print("},\n"); printer->Print( - vars, - ("$out_type$." + GetDeserializeMethodName(vars["mode"]) + "\n").c_str()); + vars, ("$out_type$." + GetDeserializeMethodName(vars) + "\n").c_str()); printer->Outdent(); printer->Print(vars, ");\n\n\n"); } @@ -1223,7 +1164,7 @@ void PrintUnaryCall(Printer* printer, std::map vars) { " * request proto\n" " * @param {?Object} metadata User defined\n" " * call metadata\n" - " * @param {function(?grpc.web.Error," + " * @param {function(?grpc.web.RpcError," " ?proto.$out$)}\n" " * callback The callback function(error, response)\n" " * @return {!grpc.web.ClientReadableStream|undefined}\n" @@ -1236,8 +1177,7 @@ void PrintUnaryCall(Printer* printer, std::map vars) { "return this.client_.rpcCall(this.hostname_ +\n"); printer->Indent(); printer->Indent(); - if (vars["mode"] == GetModeVar(Mode::OP) || - vars["mode"] == GetModeVar(Mode::OPJSPB)) { + if (vars["mode"] == GetModeVar(Mode::OP)) { printer->Print(vars, "'/$$rpc/$package_dot$$service_name$/$method_name$',\n"); } else { @@ -1259,7 +1199,7 @@ void PrintPromiseUnaryCall(Printer* printer, std::map vars) { "/**\n" " * @param {!proto.$in$} request The\n" " * request proto\n" - " * @param {?Object} metadata User defined\n" + " * @param {?Object=} metadata User defined\n" " * call metadata\n" " * @return {!$promise$}\n" " * Promise that resolves to the response\n" @@ -1272,8 +1212,7 @@ void PrintPromiseUnaryCall(Printer* printer, std::map vars) { "return this.client_.unaryCall(this.hostname_ +\n"); printer->Indent(); printer->Indent(); - if (vars["mode"] == GetModeVar(Mode::OP) || - vars["mode"] == GetModeVar(Mode::OPJSPB)) { + if (vars["mode"] == GetModeVar(Mode::OP)) { printer->Print(vars, "'/$$rpc/$package_dot$$service_name$/$method_name$',\n"); } else { @@ -1290,25 +1229,23 @@ void PrintPromiseUnaryCall(Printer* printer, std::map vars) { } void PrintServerStreamingCall(Printer* printer, std::map vars) { - printer->Print( - vars, - "/**\n" - " * @param {!proto.$in$} request The request proto\n" - " * @param {?Object} metadata User defined\n" - " * call metadata\n" - " * @return {!grpc.web.ClientReadableStream}\n" - " * The XHR Node Readable Stream\n" - " */\n" - "proto.$package_dot$$service_name$$client_type$.prototype." - "$js_method_name$ =\n"); + printer->Print(vars, + "/**\n" + " * @param {!proto.$in$} request The request proto\n" + " * @param {?Object=} metadata User defined\n" + " * call metadata\n" + " * @return {!grpc.web.ClientReadableStream}\n" + " * The XHR Node Readable Stream\n" + " */\n" + "proto.$package_dot$$service_name$$client_type$.prototype." + "$js_method_name$ =\n"); printer->Indent(); printer->Print( " function(request, metadata) {\n" "return this.client_.serverStreaming(this.hostname_ +\n"); printer->Indent(); printer->Indent(); - if (vars["mode"] == GetModeVar(Mode::OP) || - vars["mode"] == GetModeVar(Mode::OPJSPB)) { + if (vars["mode"] == GetModeVar(Mode::OP)) { printer->Print(vars, "'/$$rpc/$package_dot$$service_name$/$method_name$',\n"); } else { @@ -1328,11 +1265,12 @@ 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) { const ServiceDescriptor* service = file->service(i); - vars["service_name"] = service->name(); + vars["service_name"] = string(service->name()); vars["class_name"] = LowercaseFirstLetter(service->name()); for (int method_index = 0; method_index < service->method_count(); @@ -1341,21 +1279,24 @@ 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(), '$'); - vars["method_name"] = method->name(); - vars["in"] = method->input_type()->full_name(); - vars["in_type"] = "proto." + method->input_type()->full_name(); - vars["out"] = method->output_type()->full_name(); - vars["out_type"] = "proto." + method->output_type()->full_name(); + vars["method_name"] = string(method->name()); + vars["in"] = string(method->input_type()->full_name()); + vars["in_type"] = "proto." + string(method->input_type()->full_name()); + vars["out"] = string(method->output_type()->full_name()); + vars["out_type"] = "proto." + string(method->output_type()->full_name()); vars["method_type"] = method->server_streaming() ? "grpc.web.MethodType.SERVER_STREAMING" : "grpc.web.MethodType.UNARY"; PrintMethodDescriptorFile(&printer, vars); - method_descriptors[service->name() + "." + method->name()] = + method_descriptors[string(service->name()) + "." + string(method->name())] = "proto." + vars["package_dot"] + vars["class_name"] + "." + vars["method_name"] + "MethodDescriptor"; } @@ -1374,7 +1315,7 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, // Print the Promise and callback client. for (int i = 0; i < file->service_count(); ++i) { const ServiceDescriptor* service = file->service(i); - vars["service_name"] = service->name(); + vars["service_name"] = string(service->name()); printer1.Print(vars, "goog.provide('proto.$package_dot$$service_name$" "Client');\n\n"); @@ -1394,23 +1335,29 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, } printer1.Print(vars, "goog.require('grpc.web.$mode$ClientBase');\n"); printer1.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); - printer1.Print(vars, "goog.require('grpc.web.Error');\n"); + printer1.Print(vars, "goog.require('grpc.web.RpcError');\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); + printer1.Print(vars, "\ngoog.requireType('grpc.web.ClientOptions');\n"); + printer2.Print(vars, "\ngoog.requireType('grpc.web.ClientOptions');\n"); + + printer1.Print("\n\n\n"); + printer2.Print("\n\n\n"); printer1.Print("goog.scope(function() {\n\n"); printer2.Print("goog.scope(function() {\n\n"); for (int service_index = 0; service_index < file->service_count(); ++service_index) { const ServiceDescriptor* service = file->service(service_index); - vars["service_name"] = service->name(); - PrintServiceConstructor(&printer1, vars); - PrintPromiseServiceConstructor(&printer2, vars); + vars["service_name"] = string(service->name()); + PrintServiceConstructor(&printer1, vars, false); + PrintServiceConstructor(&printer2, vars, true); for (int method_index = 0; method_index < service->method_count(); ++method_index) { @@ -1418,13 +1365,13 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, const Descriptor* input_type = method->input_type(); const Descriptor* output_type = method->output_type(); vars["js_method_name"] = LowercaseFirstLetter(method->name()); - vars["method_name"] = method->name(); - vars["in"] = input_type->full_name(); - vars["out"] = output_type->full_name(); + vars["method_name"] = string(method->name()); + vars["in"] = string(input_type->full_name()); + vars["out"] = string(output_type->full_name()); vars["method_descriptor"] = - method_descriptors[service->name() + "." + method->name()]; - vars["in_type"] = "proto." + input_type->full_name(); - vars["out_type"] = "proto." + output_type->full_name(); + method_descriptors[string(service->name()) + "." + string(method->name())]; + vars["in_type"] = "proto." + string(input_type->full_name()); + vars["out_type"] = "proto." + string(output_type->full_name()); // Client streaming is not supported yet if (!method->client_streaming()) { @@ -1446,35 +1393,39 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, printer2.Print("}); // goog.scope\n\n"); } -void PrintClosureES6Imports( - Printer* printer, const FileDescriptor* file, string package_dot) { +void PrintClosureES6Imports(Printer* printer, const FileDescriptor* file, + string package_dot) { for (int i = 0; i < file->service_count(); ++i) { const ServiceDescriptor* service = file->service(i); - string service_namespace = "proto." + package_dot + service->name(); + string service_namespace = "proto." + package_dot + string(service->name()); printer->Print( "import $service_name$Client_import from 'goog:$namespace$';\n", - "service_name", service->name(), - "namespace", service_namespace + "Client"); + "service_name", string(service->name()), "namespace", + service_namespace + "Client"); printer->Print( "import $service_name$PromiseClient_import from 'goog:$namespace$';\n", - "service_name", service->name(), - "namespace", service_namespace + "PromiseClient"); + "service_name", string(service->name()), "namespace", + service_namespace + "PromiseClient"); } printer->Print("\n\n\n"); } void PrintGrpcWebClosureES6File(Printer* printer, const FileDescriptor* file) { - string package_dot = file->package().empty() ? "" : file->package() + "."; + string package_dot = file->package().empty() ? "" : string(file->package()) + "."; printer->Print( - "// GENERATED CODE -- DO NOT EDIT!\n" - "\n" "/**\n" " * @fileoverview gRPC-Web generated client stub for '$file$'\n" " */\n" "\n" + "// Code generated by protoc-gen-grpc-web. DO NOT EDIT.\n" + "// versions:\n" + "// \tprotoc-gen-grpc-web v$version$\n" + "// \tprotoc v$protoc_version$\n" + "// source: $source_file$\n" + "\n" "\n", "file", file->name()); @@ -1483,13 +1434,12 @@ void PrintGrpcWebClosureES6File(Printer* printer, const FileDescriptor* file) { for (int i = 0; i < file->service_count(); ++i) { const ServiceDescriptor* service = file->service(i); - string service_namespace = "proto." + package_dot + service->name(); - printer->Print( - "export const $name$Client = $name$Client_import;\n", - "name", service->name()); + string service_namespace = "proto." + package_dot + string(service->name()); + printer->Print("export const $name$Client = $name$Client_import;\n", "name", + string(service->name())); printer->Print( "export const $name$PromiseClient = $name$PromiseClient_import;\n", - "name", service->name()); + "name", string(service->name())); } } @@ -1505,6 +1455,7 @@ class GeneratorOptions { string OutputFile(const string& proto_file) const; string mode() const { return mode_; } + string plugins() const { return plugins_; } ImportStyle import_style() const { return import_style_; } bool generate_dts() const { return generate_dts_; } bool generate_closure_es6() const { return generate_closure_es6_; } @@ -1514,6 +1465,7 @@ class GeneratorOptions { private: string file_name_; string mode_; + string plugins_; ImportStyle import_style_; bool generate_dts_; bool generate_closure_es6_; @@ -1524,6 +1476,7 @@ class GeneratorOptions { GeneratorOptions::GeneratorOptions() : file_name_(""), mode_(""), + plugins_(""), import_style_(ImportStyle::CLOSURE), generate_dts_(false), generate_closure_es6_(false), @@ -1564,6 +1517,8 @@ bool GeneratorOptions::ParseFromOptions( } } else if ("multiple_files" == option.first) { multiple_files_ = "True" == option.second; + } else if ("plugins" == option.first) { + plugins_ = option.second; } else if ("goog_promise" == option.first) { goog_promise_ = "True" == option.second; } else { @@ -1602,9 +1557,13 @@ class GrpcCodeGenerator : public CodeGenerator { uint64_t GetSupportedFeatures() const override { // Code generators must explicitly support proto3 optional. - return CodeGenerator::FEATURE_PROTO3_OPTIONAL; + return CodeGenerator::FEATURE_PROTO3_OPTIONAL | CodeGenerator::FEATURE_SUPPORTS_EDITIONS; } + // Keep synced with protoc-gen-js: https://github.com/protocolbuffers/protobuf-javascript/blob/861c8020a5c0cba9b7cdf915dffde96a4421a1f4/generator/js_generator.h#L157-L158 + Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; } + Edition GetMaximumEdition() const override { return Edition::EDITION_2023; } + bool Generate(const FileDescriptor* file, const string& parameter, GeneratorContext* context, string* error) const override { GeneratorOptions generator_options; @@ -1614,13 +1573,15 @@ class GrpcCodeGenerator : public CodeGenerator { std::map vars; std::map method_descriptors; - string package = file->package(); + string package(file->package()); vars["package"] = package; vars["package_dot"] = package.empty() ? "" : package + '.'; vars["promise"] = "Promise"; + vars["plugins"] = generator_options.plugins(); if ("binary" == generator_options.mode()) { vars["mode"] = GetModeVar(Mode::OP); + vars["binary"] = "true"; } else if ("grpcweb" == generator_options.mode()) { vars["mode"] = GetModeVar(Mode::GRPCWEB); vars["format"] = "binary"; @@ -1628,7 +1589,8 @@ class GrpcCodeGenerator : public CodeGenerator { vars["mode"] = GetModeVar(Mode::GRPCWEB); vars["format"] = "text"; } else if ("jspb" == generator_options.mode()) { - vars["mode"] = GetModeVar(Mode::OPJSPB); + vars["mode"] = GetModeVar(Mode::OP); + vars["binary"] = "false"; if (generator_options.goog_promise()) { vars["promise"] = GRPC_PROMISE; } @@ -1650,7 +1612,11 @@ class GrpcCodeGenerator : public CodeGenerator { return true; } - string file_name = generator_options.OutputFile(file->name()); + vars["version"] = GRPC_WEB_VERSION; + vars["protoc_version"] = GetProtocVersion(context); + vars["source_file"] = string(file->name()); + + string file_name = generator_options.OutputFile(string(file->name())); if (generator_options.multiple_files() && ImportStyle::CLOSURE == generator_options.import_style()) { PrintMultipleFilesMode(file, file_name, context, vars); @@ -1668,7 +1634,7 @@ class GrpcCodeGenerator : public CodeGenerator { for (int i = 0; i < file->service_count(); ++i) { const ServiceDescriptor* service = file->service(i); - vars["service_name"] = service->name(); + vars["service_name"] = string(service->name()); switch (generator_options.import_style()) { case ImportStyle::CLOSURE: printer.Print( @@ -1696,10 +1662,11 @@ class GrpcCodeGenerator : public CodeGenerator { printer.Print(vars, "goog.require('grpc.web.$mode$ClientBase');\n"); printer.Print(vars, "goog.require('grpc.web.AbstractClientBase');\n"); printer.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); - printer.Print(vars, "goog.require('grpc.web.Error');\n"); + printer.Print(vars, "goog.require('grpc.web.RpcError');\n"); PrintClosureDependencies(&printer, file); - + printer.Print(vars, "\ngoog.requireType('grpc.web.ClientOptions');\n"); + printer.Print("\n\n\n"); printer.Print("goog.scope(function() {\n\n"); break; case ImportStyle::COMMONJS: @@ -1714,9 +1681,9 @@ class GrpcCodeGenerator : public CodeGenerator { for (int service_index = 0; service_index < file->service_count(); ++service_index) { const ServiceDescriptor* service = file->service(service_index); - vars["service_name"] = service->name(); - PrintServiceConstructor(&printer, vars); - PrintPromiseServiceConstructor(&printer, vars); + vars["service_name"] = string(service->name()); + PrintServiceConstructor(&printer, vars, false); + PrintServiceConstructor(&printer, vars, true); for (int method_index = 0; method_index < service->method_count(); ++method_index) { @@ -1724,11 +1691,11 @@ class GrpcCodeGenerator : public CodeGenerator { const Descriptor* input_type = method->input_type(); const Descriptor* output_type = method->output_type(); vars["js_method_name"] = LowercaseFirstLetter(method->name()); - vars["method_name"] = method->name(); - vars["in"] = input_type->full_name(); - vars["out"] = output_type->full_name(); + vars["method_name"] = string(method->name()); + vars["in"] = string(input_type->full_name()); + vars["out"] = string(output_type->full_name()); vars["method_descriptor"] = - "methodDescriptor_" + service->name() + "_" + method->name(); + "methodDescriptor_" + string(service->name()) + "_" + string(method->name()); // Cross-file ref in CommonJS needs to use the module alias instead // of the global name. @@ -1737,28 +1704,28 @@ class GrpcCodeGenerator : public CodeGenerator { vars["in_type"] = ModuleAlias(input_type->file()->name()) + GetNestedMessageName(input_type); } else { - vars["in_type"] = "proto." + input_type->full_name(); + vars["in_type"] = "proto." + string(input_type->full_name()); } if (ImportStyle::COMMONJS == generator_options.import_style() && output_type->file() != file) { vars["out_type"] = ModuleAlias(output_type->file()->name()) + GetNestedMessageName(output_type); } else { - vars["out_type"] = "proto." + output_type->full_name(); + vars["out_type"] = "proto." + string(output_type->full_name()); } // Client streaming is not supported yet if (!method->client_streaming()) { if (method->server_streaming()) { vars["method_type"] = "grpc.web.MethodType.SERVER_STREAMING"; - PrintMethodInfo(&printer, vars); + PrintMethodDescriptor(&printer, vars); vars["client_type"] = "Client"; PrintServerStreamingCall(&printer, vars); vars["client_type"] = "PromiseClient"; PrintServerStreamingCall(&printer, vars); } else { vars["method_type"] = "grpc.web.MethodType.UNARY"; - PrintMethodInfo(&printer, vars); + PrintMethodDescriptor(&printer, vars); PrintUnaryCall(&printer, vars); PrintPromiseUnaryCall(&printer, vars); } @@ -1812,6 +1779,11 @@ class GrpcCodeGenerator : public CodeGenerator { } // namespace grpc int main(int argc, char* argv[]) { + if (argc == 2 && std::string(argv[1]) == "--version") { + std::cout << argv[0] << " " << grpc::web::GRPC_WEB_VERSION << std::endl; + return 0; + } + grpc::web::GrpcCodeGenerator generator; PluginMain(argc, argv, &generator); return 0; From 3c616a4ede3fc0dfbfb2973aba3a676064470b73 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 22:06:26 +0000 Subject: [PATCH 12/17] Regenerate ts protobuf files Signed-off-by: Dom Del Nano --- .../generated/VizierapiServiceClientPb.ts | 65 ++- src/ui/src/types/generated/vizierapi_pb.d.ts | 334 +++++++------- src/ui/src/types/generated/vizierapi_pb.js | 415 +++++++++--------- 3 files changed, 415 insertions(+), 399 deletions(-) diff --git a/src/ui/src/types/generated/VizierapiServiceClientPb.ts b/src/ui/src/types/generated/VizierapiServiceClientPb.ts index 7cb9af7a592..9d62889cf08 100755 --- a/src/ui/src/types/generated/VizierapiServiceClientPb.ts +++ b/src/ui/src/types/generated/VizierapiServiceClientPb.ts @@ -4,7 +4,11 @@ * @public */ -// GENERATED CODE -- DO NOT EDIT! +// Code generated by protoc-gen-grpc-web. DO NOT EDIT. +// versions: +// protoc-gen-grpc-web v2.0.2 +// protoc v6.31.1 +// source: src/api/proto/vizierpb/vizierapi.proto /* eslint-disable */ @@ -13,7 +17,7 @@ import * as grpcWeb from 'grpc-web'; -import * as src_api_proto_vizierpb_vizierapi_pb from './vizierapi_pb'; +import * as src_api_proto_vizierpb_vizierapi_pb from './vizierapi_pb'; // proto import: "src/api/proto/vizierpb/vizierapi.proto" export class VizierServiceClient { @@ -30,12 +34,15 @@ export class VizierServiceClient { options['format'] = 'text'; this.client_ = new grpcWeb.GrpcWebClientBase(options); - this.hostname_ = hostname; + this.hostname_ = hostname.replace(/\/+$/, ''); this.credentials_ = credentials; this.options_ = options; } - methodInfoExecuteScript = new grpcWeb.AbstractClientBase.MethodInfo( + methodDescriptorExecuteScript = new grpcWeb.MethodDescriptor( + '/px.api.vizierpb.VizierService/ExecuteScript', + grpcWeb.MethodType.SERVER_STREAMING, + src_api_proto_vizierpb_vizierapi_pb.ExecuteScriptRequest, src_api_proto_vizierpb_vizierapi_pb.ExecuteScriptResponse, (request: src_api_proto_vizierpb_vizierapi_pb.ExecuteScriptRequest) => { return request.serializeBinary(); @@ -45,16 +52,19 @@ export class VizierServiceClient { executeScript( request: src_api_proto_vizierpb_vizierapi_pb.ExecuteScriptRequest, - metadata?: grpcWeb.Metadata) { + metadata?: grpcWeb.Metadata): grpcWeb.ClientReadableStream { return this.client_.serverStreaming( this.hostname_ + '/px.api.vizierpb.VizierService/ExecuteScript', request, metadata || {}, - this.methodInfoExecuteScript); + this.methodDescriptorExecuteScript); } - methodInfoHealthCheck = new grpcWeb.AbstractClientBase.MethodInfo( + methodDescriptorHealthCheck = new grpcWeb.MethodDescriptor( + '/px.api.vizierpb.VizierService/HealthCheck', + grpcWeb.MethodType.SERVER_STREAMING, + src_api_proto_vizierpb_vizierapi_pb.HealthCheckRequest, src_api_proto_vizierpb_vizierapi_pb.HealthCheckResponse, (request: src_api_proto_vizierpb_vizierapi_pb.HealthCheckRequest) => { return request.serializeBinary(); @@ -64,16 +74,19 @@ export class VizierServiceClient { healthCheck( request: src_api_proto_vizierpb_vizierapi_pb.HealthCheckRequest, - metadata?: grpcWeb.Metadata) { + metadata?: grpcWeb.Metadata): grpcWeb.ClientReadableStream { return this.client_.serverStreaming( this.hostname_ + '/px.api.vizierpb.VizierService/HealthCheck', request, metadata || {}, - this.methodInfoHealthCheck); + this.methodDescriptorHealthCheck); } - methodInfoGenerateOTelScript = new grpcWeb.AbstractClientBase.MethodInfo( + methodDescriptorGenerateOTelScript = new grpcWeb.MethodDescriptor( + '/px.api.vizierpb.VizierService/GenerateOTelScript', + grpcWeb.MethodType.UNARY, + src_api_proto_vizierpb_vizierapi_pb.GenerateOTelScriptRequest, src_api_proto_vizierpb_vizierapi_pb.GenerateOTelScriptResponse, (request: src_api_proto_vizierpb_vizierapi_pb.GenerateOTelScriptRequest) => { return request.serializeBinary(); @@ -83,18 +96,18 @@ export class VizierServiceClient { generateOTelScript( request: src_api_proto_vizierpb_vizierapi_pb.GenerateOTelScriptRequest, - metadata: grpcWeb.Metadata | null): Promise; + metadata?: grpcWeb.Metadata | null): Promise; generateOTelScript( request: src_api_proto_vizierpb_vizierapi_pb.GenerateOTelScriptRequest, metadata: grpcWeb.Metadata | null, - callback: (err: grpcWeb.Error, + callback: (err: grpcWeb.RpcError, response: src_api_proto_vizierpb_vizierapi_pb.GenerateOTelScriptResponse) => void): grpcWeb.ClientReadableStream; generateOTelScript( request: src_api_proto_vizierpb_vizierapi_pb.GenerateOTelScriptRequest, - metadata: grpcWeb.Metadata | null, - callback?: (err: grpcWeb.Error, + metadata?: grpcWeb.Metadata | null, + callback?: (err: grpcWeb.RpcError, response: src_api_proto_vizierpb_vizierapi_pb.GenerateOTelScriptResponse) => void) { if (callback !== undefined) { return this.client_.rpcCall( @@ -102,7 +115,7 @@ export class VizierServiceClient { '/px.api.vizierpb.VizierService/GenerateOTelScript', request, metadata || {}, - this.methodInfoGenerateOTelScript, + this.methodDescriptorGenerateOTelScript, callback); } return this.client_.unaryCall( @@ -110,7 +123,7 @@ export class VizierServiceClient { '/px.api.vizierpb.VizierService/GenerateOTelScript', request, metadata || {}, - this.methodInfoGenerateOTelScript); + this.methodDescriptorGenerateOTelScript); } } @@ -129,12 +142,15 @@ export class VizierDebugServiceClient { options['format'] = 'text'; this.client_ = new grpcWeb.GrpcWebClientBase(options); - this.hostname_ = hostname; + this.hostname_ = hostname.replace(/\/+$/, ''); this.credentials_ = credentials; this.options_ = options; } - methodInfoDebugLog = new grpcWeb.AbstractClientBase.MethodInfo( + methodDescriptorDebugLog = new grpcWeb.MethodDescriptor( + '/px.api.vizierpb.VizierDebugService/DebugLog', + grpcWeb.MethodType.SERVER_STREAMING, + src_api_proto_vizierpb_vizierapi_pb.DebugLogRequest, src_api_proto_vizierpb_vizierapi_pb.DebugLogResponse, (request: src_api_proto_vizierpb_vizierapi_pb.DebugLogRequest) => { return request.serializeBinary(); @@ -144,16 +160,19 @@ export class VizierDebugServiceClient { debugLog( request: src_api_proto_vizierpb_vizierapi_pb.DebugLogRequest, - metadata?: grpcWeb.Metadata) { + metadata?: grpcWeb.Metadata): grpcWeb.ClientReadableStream { return this.client_.serverStreaming( this.hostname_ + '/px.api.vizierpb.VizierDebugService/DebugLog', request, metadata || {}, - this.methodInfoDebugLog); + this.methodDescriptorDebugLog); } - methodInfoDebugPods = new grpcWeb.AbstractClientBase.MethodInfo( + methodDescriptorDebugPods = new grpcWeb.MethodDescriptor( + '/px.api.vizierpb.VizierDebugService/DebugPods', + grpcWeb.MethodType.SERVER_STREAMING, + src_api_proto_vizierpb_vizierapi_pb.DebugPodsRequest, src_api_proto_vizierpb_vizierapi_pb.DebugPodsResponse, (request: src_api_proto_vizierpb_vizierapi_pb.DebugPodsRequest) => { return request.serializeBinary(); @@ -163,13 +182,13 @@ export class VizierDebugServiceClient { debugPods( request: src_api_proto_vizierpb_vizierapi_pb.DebugPodsRequest, - metadata?: grpcWeb.Metadata) { + metadata?: grpcWeb.Metadata): grpcWeb.ClientReadableStream { return this.client_.serverStreaming( this.hostname_ + '/px.api.vizierpb.VizierDebugService/DebugPods', request, metadata || {}, - this.methodInfoDebugPods); + this.methodDescriptorDebugPods); } } diff --git a/src/ui/src/types/generated/vizierapi_pb.d.ts b/src/ui/src/types/generated/vizierapi_pb.d.ts index fe38e0c37a0..7c9fe4b02c7 100755 --- a/src/ui/src/types/generated/vizierapi_pb.d.ts +++ b/src/ui/src/types/generated/vizierapi_pb.d.ts @@ -20,9 +20,9 @@ export class UInt128 extends jspb.Message { export namespace UInt128 { export type AsObject = { - low: number, - high: number, - } + low: number; + high: number; + }; } export class BooleanColumn extends jspb.Message { @@ -41,8 +41,8 @@ export class BooleanColumn extends jspb.Message { export namespace BooleanColumn { export type AsObject = { - dataList: Array, - } + dataList: Array; + }; } export class Int64Column extends jspb.Message { @@ -61,8 +61,8 @@ export class Int64Column extends jspb.Message { export namespace Int64Column { export type AsObject = { - dataList: Array, - } + dataList: Array; + }; } export class UInt128Column extends jspb.Message { @@ -81,8 +81,8 @@ export class UInt128Column extends jspb.Message { export namespace UInt128Column { export type AsObject = { - dataList: Array, - } + dataList: Array; + }; } export class Float64Column extends jspb.Message { @@ -101,8 +101,8 @@ export class Float64Column extends jspb.Message { export namespace Float64Column { export type AsObject = { - dataList: Array, - } + dataList: Array; + }; } export class Time64NSColumn extends jspb.Message { @@ -121,8 +121,8 @@ export class Time64NSColumn extends jspb.Message { export namespace Time64NSColumn { export type AsObject = { - dataList: Array, - } + dataList: Array; + }; } export class StringColumn extends jspb.Message { @@ -141,8 +141,8 @@ export class StringColumn extends jspb.Message { export namespace StringColumn { export type AsObject = { - dataList: Array, - } + dataList: Array; + }; } export class Column extends jspb.Message { @@ -188,15 +188,15 @@ export class Column extends jspb.Message { export namespace Column { export type AsObject = { - booleanData?: BooleanColumn.AsObject, - int64Data?: Int64Column.AsObject, - uint128Data?: UInt128Column.AsObject, - time64nsData?: Time64NSColumn.AsObject, - float64Data?: Float64Column.AsObject, - stringData?: StringColumn.AsObject, - } - - export enum ColDataCase { + booleanData?: BooleanColumn.AsObject; + int64Data?: Int64Column.AsObject; + uint128Data?: UInt128Column.AsObject; + time64nsData?: Time64NSColumn.AsObject; + float64Data?: Float64Column.AsObject; + stringData?: StringColumn.AsObject; + }; + + export enum ColDataCase { COL_DATA_NOT_SET = 0, BOOLEAN_DATA = 1, INT64_DATA = 2, @@ -235,12 +235,12 @@ export class RowBatchData extends jspb.Message { export namespace RowBatchData { export type AsObject = { - tableId: string, - colsList: Array, - numRows: number, - eow: boolean, - eos: boolean, - } + tableId: string; + colsList: Array; + numRows: number; + eow: boolean; + eos: boolean; + }; } export class Relation extends jspb.Message { @@ -259,8 +259,8 @@ export class Relation extends jspb.Message { export namespace Relation { export type AsObject = { - columnsList: Array, - } + columnsList: Array; + }; export class ColumnInfo extends jspb.Message { getColumnName(): string; @@ -285,11 +285,11 @@ export namespace Relation { export namespace ColumnInfo { export type AsObject = { - columnName: string, - columnType: DataType, - columnDesc: string, - columnSemanticType: SemanticType, - } + columnName: string; + columnType: DataType; + columnDesc: string; + columnSemanticType: SemanticType; + }; } } @@ -314,10 +314,10 @@ export class CompilerError extends jspb.Message { export namespace CompilerError { export type AsObject = { - line: number, - column: number, - message: string, - } + line: number; + column: number; + message: string; + }; } export class ErrorDetails extends jspb.Message { @@ -338,10 +338,10 @@ export class ErrorDetails extends jspb.Message { export namespace ErrorDetails { export type AsObject = { - compilerError?: CompilerError.AsObject, - } + compilerError?: CompilerError.AsObject; + }; - export enum ErrorCase { + export enum ErrorCase { ERROR_NOT_SET = 0, COMPILER_ERROR = 1, } @@ -369,10 +369,10 @@ export class Status extends jspb.Message { export namespace Status { export type AsObject = { - code: number, - message: string, - errorDetailsList: Array, - } + code: number; + message: string; + errorDetailsList: Array; + }; } export class ScalarValue extends jspb.Message { @@ -381,18 +381,28 @@ export class ScalarValue extends jspb.Message { getBoolValue(): boolean; setBoolValue(value: boolean): ScalarValue; + hasBoolValue(): boolean; + clearBoolValue(): ScalarValue; getInt64Value(): number; setInt64Value(value: number): ScalarValue; + hasInt64Value(): boolean; + clearInt64Value(): ScalarValue; getFloat64Value(): number; setFloat64Value(value: number): ScalarValue; + hasFloat64Value(): boolean; + clearFloat64Value(): ScalarValue; getStringValue(): string; setStringValue(value: string): ScalarValue; + hasStringValue(): boolean; + clearStringValue(): ScalarValue; getTime64NsValue(): number; setTime64NsValue(value: number): ScalarValue; + hasTime64NsValue(): boolean; + clearTime64NsValue(): ScalarValue; getUint128Value(): UInt128 | undefined; setUint128Value(value?: UInt128): ScalarValue; @@ -411,16 +421,16 @@ export class ScalarValue extends jspb.Message { export namespace ScalarValue { export type AsObject = { - dataType: DataType, - boolValue: boolean, - int64Value: number, - float64Value: number, - stringValue: string, - time64NsValue: number, - uint128Value?: UInt128.AsObject, - } - - export enum ValueCase { + dataType: DataType; + boolValue?: boolean; + int64Value?: number; + float64Value?: number; + stringValue?: string; + time64NsValue?: number; + uint128Value?: UInt128.AsObject; + }; + + export enum ValueCase { VALUE_NOT_SET = 0, BOOL_VALUE = 2, INT64_VALUE = 3, @@ -472,15 +482,15 @@ export class ExecuteScriptRequest extends jspb.Message { export namespace ExecuteScriptRequest { export type AsObject = { - queryStr: string, - clusterId: string, - execFuncsList: Array, - mutation: boolean, - encryptionOptions?: ExecuteScriptRequest.EncryptionOptions.AsObject, - queryId: string, - configs?: Configs.AsObject, - queryName: string, - } + queryStr: string; + clusterId: string; + execFuncsList: Array; + mutation: boolean; + encryptionOptions?: ExecuteScriptRequest.EncryptionOptions.AsObject; + queryId: string; + configs?: Configs.AsObject; + queryName: string; + }; export class FuncToExecute extends jspb.Message { getFuncName(): string; @@ -504,10 +514,10 @@ export namespace ExecuteScriptRequest { export namespace FuncToExecute { export type AsObject = { - funcName: string, - argValuesList: Array, - outputTablePrefix: string, - } + funcName: string; + argValuesList: Array; + outputTablePrefix: string; + }; export class ArgValue extends jspb.Message { getName(): string; @@ -526,9 +536,9 @@ export namespace ExecuteScriptRequest { export namespace ArgValue { export type AsObject = { - name: string, - value: string, - } + name: string; + value: string; + }; } } @@ -557,11 +567,11 @@ export namespace ExecuteScriptRequest { export namespace EncryptionOptions { export type AsObject = { - jwkKey: string, - keyAlg: string, - contentAlg: string, - compressionAlg: string, - } + jwkKey: string; + keyAlg: string; + contentAlg: string; + compressionAlg: string; + }; } } @@ -587,9 +597,9 @@ export class Configs extends jspb.Message { export namespace Configs { export type AsObject = { - otelEndpointConfig?: Configs.OTelEndpointConfig.AsObject, - pluginConfig?: Configs.PluginConfig.AsObject, - } + otelEndpointConfig?: Configs.OTelEndpointConfig.AsObject; + pluginConfig?: Configs.PluginConfig.AsObject; + }; export class OTelEndpointConfig extends jspb.Message { getUrl(): string; @@ -614,11 +624,11 @@ export namespace Configs { export namespace OTelEndpointConfig { export type AsObject = { - url: string, - headersMap: Array<[string, string]>, - insecure: boolean, - timeout: number, - } + url: string; + headersMap: Array<[string, string]>; + insecure: boolean; + timeout: number; + }; } @@ -639,9 +649,9 @@ export namespace Configs { export namespace PluginConfig { export type AsObject = { - startTimeNs: number, - endTimeNs: number, - } + startTimeNs: number; + endTimeNs: number; + }; } } @@ -663,9 +673,9 @@ export class QueryTimingInfo extends jspb.Message { export namespace QueryTimingInfo { export type AsObject = { - executionTimeNs: number, - compilationTimeNs: number, - } + executionTimeNs: number; + compilationTimeNs: number; + }; } export class QueryExecutionStats extends jspb.Message { @@ -690,10 +700,10 @@ export class QueryExecutionStats extends jspb.Message { export namespace QueryExecutionStats { export type AsObject = { - timing?: QueryTimingInfo.AsObject, - bytesProcessed: number, - recordsProcessed: number, - } + timing?: QueryTimingInfo.AsObject; + bytesProcessed: number; + recordsProcessed: number; + }; } export class QueryMetadata extends jspb.Message { @@ -718,10 +728,10 @@ export class QueryMetadata extends jspb.Message { export namespace QueryMetadata { export type AsObject = { - relation?: Relation.AsObject, - name: string, - id: string, - } + relation?: Relation.AsObject; + name: string; + id: string; + }; } export class QueryData extends jspb.Message { @@ -750,10 +760,10 @@ export class QueryData extends jspb.Message { export namespace QueryData { export type AsObject = { - batch?: RowBatchData.AsObject, - encryptedBatch: Uint8Array | string, - executionStats?: QueryExecutionStats.AsObject, - } + batch?: RowBatchData.AsObject; + encryptedBatch: Uint8Array | string; + executionStats?: QueryExecutionStats.AsObject; + }; } export class ExecuteScriptResponse extends jspb.Message { @@ -792,14 +802,14 @@ export class ExecuteScriptResponse extends jspb.Message { export namespace ExecuteScriptResponse { export type AsObject = { - status?: Status.AsObject, - queryId: string, - data?: QueryData.AsObject, - metaData?: QueryMetadata.AsObject, - mutationInfo?: MutationInfo.AsObject, - } - - export enum ResultCase { + status?: Status.AsObject; + queryId: string; + data?: QueryData.AsObject; + metaData?: QueryMetadata.AsObject; + mutationInfo?: MutationInfo.AsObject; + }; + + export enum ResultCase { RESULT_NOT_SET = 0, DATA = 3, META_DATA = 4, @@ -827,9 +837,9 @@ export class MutationInfo extends jspb.Message { export namespace MutationInfo { export type AsObject = { - status?: Status.AsObject, - statesList: Array, - } + status?: Status.AsObject; + statesList: Array; + }; export class MutationState extends jspb.Message { getId(): string; @@ -851,10 +861,10 @@ export namespace MutationInfo { export namespace MutationState { export type AsObject = { - id: string, - state: LifeCycleState, - name: string, - } + id: string; + state: LifeCycleState; + name: string; + }; } } @@ -873,8 +883,8 @@ export class HealthCheckRequest extends jspb.Message { export namespace HealthCheckRequest { export type AsObject = { - clusterId: string, - } + clusterId: string; + }; } export class HealthCheckResponse extends jspb.Message { @@ -893,8 +903,8 @@ export class HealthCheckResponse extends jspb.Message { export namespace HealthCheckResponse { export type AsObject = { - status?: Status.AsObject, - } + status?: Status.AsObject; + }; } export class GenerateOTelScriptRequest extends jspb.Message { @@ -914,9 +924,9 @@ export class GenerateOTelScriptRequest extends jspb.Message { export namespace GenerateOTelScriptRequest { export type AsObject = { - clusterId: string, - pxlScript: string, - } + clusterId: string; + pxlScript: string; + }; } export class GenerateOTelScriptResponse extends jspb.Message { @@ -938,9 +948,9 @@ export class GenerateOTelScriptResponse extends jspb.Message { export namespace GenerateOTelScriptResponse { export type AsObject = { - status?: Status.AsObject, - otelScript: string, - } + status?: Status.AsObject; + otelScript: string; + }; } export class DebugLogRequest extends jspb.Message { @@ -966,11 +976,11 @@ export class DebugLogRequest extends jspb.Message { export namespace DebugLogRequest { export type AsObject = { - clusterId: string, - podName: string, - previous: boolean, - container: string, - } + clusterId: string; + podName: string; + previous: boolean; + container: string; + }; } export class DebugLogResponse extends jspb.Message { @@ -987,8 +997,8 @@ export class DebugLogResponse extends jspb.Message { export namespace DebugLogResponse { export type AsObject = { - data: string, - } + data: string; + }; } export class ContainerStatus extends jspb.Message { @@ -1020,13 +1030,13 @@ export class ContainerStatus extends jspb.Message { export namespace ContainerStatus { export type AsObject = { - name: string, - containerState: ContainerState, - message: string, - reason: string, - startTimestampNs: number, - restartCount: number, - } + name: string; + containerState: ContainerState; + message: string; + reason: string; + startTimestampNs: number; + restartCount: number; + }; } export class VizierPodStatus extends jspb.Message { @@ -1063,14 +1073,14 @@ export class VizierPodStatus extends jspb.Message { export namespace VizierPodStatus { export type AsObject = { - name: string, - phase: PodPhase, - message: string, - reason: string, - createdAt: number, - containerStatusesList: Array, - restartCount: number, - } + name: string; + phase: PodPhase; + message: string; + reason: string; + createdAt: number; + containerStatusesList: Array; + restartCount: number; + }; } export class DebugPodsRequest extends jspb.Message { @@ -1087,8 +1097,8 @@ export class DebugPodsRequest extends jspb.Message { export namespace DebugPodsRequest { export type AsObject = { - clusterId: string, - } + clusterId: string; + }; } export class DebugPodsResponse extends jspb.Message { @@ -1112,12 +1122,12 @@ export class DebugPodsResponse extends jspb.Message { export namespace DebugPodsResponse { export type AsObject = { - dataPlanePodsList: Array, - controlPlanePodsList: Array, - } + dataPlanePodsList: Array; + controlPlanePodsList: Array; + }; } -export enum DataType { +export enum DataType { DATA_TYPE_UNKNOWN = 0, BOOLEAN = 1, INT64 = 2, @@ -1126,7 +1136,7 @@ export enum DataType { STRING = 5, TIME64NS = 6, } -export enum SemanticType { +export enum SemanticType { ST_UNSPECIFIED = 0, ST_NONE = 1, ST_TIME_NS = 2, @@ -1156,20 +1166,20 @@ export enum SemanticType { ST_HTTP_RESP_MESSAGE = 1500, ST_SCRIPT_REFERENCE = 3000, } -export enum LifeCycleState { +export enum LifeCycleState { UNKNOWN_STATE = 0, PENDING_STATE = 1, RUNNING_STATE = 2, FAILED_STATE = 3, TERMINATED_STATE = 4, } -export enum ContainerState { +export enum ContainerState { CONTAINER_STATE_UNKNOWN = 0, CONTAINER_STATE_RUNNING = 1, CONTAINER_STATE_TERMINATED = 2, CONTAINER_STATE_WAITING = 3, } -export enum PodPhase { +export enum PodPhase { PHASE_UNKNOWN = 0, PENDING = 1, RUNNING = 2, diff --git a/src/ui/src/types/generated/vizierapi_pb.js b/src/ui/src/types/generated/vizierapi_pb.js index dde6bc20610..cdf3eaf1de6 100755 --- a/src/ui/src/types/generated/vizierapi_pb.js +++ b/src/ui/src/types/generated/vizierapi_pb.js @@ -13,13 +13,7 @@ var jspb = require('google-protobuf'); var goog = jspb; -var global = - (typeof globalThis !== 'undefined' && globalThis) || - (typeof window !== 'undefined' && window) || - (typeof global !== 'undefined' && global) || - (typeof self !== 'undefined' && self) || - (function () { return this; }).call(null) || - Function('return this')(); +var global = globalThis; goog.exportSymbol('proto.px.api.vizierpb.BooleanColumn', null, global); goog.exportSymbol('proto.px.api.vizierpb.Column', null, global); @@ -920,8 +914,8 @@ proto.px.api.vizierpb.UInt128.prototype.toObject = function(opt_includeInstance) */ proto.px.api.vizierpb.UInt128.toObject = function(includeInstance, msg) { var f, obj = { - low: jspb.Message.getFieldWithDefault(msg, 1, 0), - high: jspb.Message.getFieldWithDefault(msg, 2, 0) +low: jspb.Message.getFieldWithDefault(msg, 1, 0), +high: jspb.Message.getFieldWithDefault(msg, 2, 0) }; if (includeInstance) { @@ -934,7 +928,7 @@ proto.px.api.vizierpb.UInt128.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.UInt128} */ proto.px.api.vizierpb.UInt128.deserializeBinary = function(bytes) { @@ -1087,7 +1081,7 @@ proto.px.api.vizierpb.BooleanColumn.prototype.toObject = function(opt_includeIns */ proto.px.api.vizierpb.BooleanColumn.toObject = function(includeInstance, msg) { var f, obj = { - dataList: (f = jspb.Message.getRepeatedBooleanField(msg, 1)) == null ? undefined : f +dataList: (f = jspb.Message.getRepeatedBooleanField(msg, 1)) == null ? undefined : f }; if (includeInstance) { @@ -1100,7 +1094,7 @@ proto.px.api.vizierpb.BooleanColumn.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.BooleanColumn} */ proto.px.api.vizierpb.BooleanColumn.deserializeBinary = function(bytes) { @@ -1125,10 +1119,7 @@ proto.px.api.vizierpb.BooleanColumn.deserializeBinaryFromReader = function(msg, var field = reader.getFieldNumber(); switch (field) { case 1: - var values = /** @type {!Array} */ (reader.isDelimited() ? reader.readPackedBool() : [reader.readBool()]); - for (var i = 0; i < values.length; i++) { - msg.addData(values[i]); - } + reader.readPackableBoolInto(msg.getDataList()); break; default: reader.skipField(); @@ -1245,7 +1236,7 @@ proto.px.api.vizierpb.Int64Column.prototype.toObject = function(opt_includeInsta */ proto.px.api.vizierpb.Int64Column.toObject = function(includeInstance, msg) { var f, obj = { - dataList: (f = jspb.Message.getRepeatedField(msg, 1)) == null ? undefined : f +dataList: (f = jspb.Message.getRepeatedField(msg, 1)) == null ? undefined : f }; if (includeInstance) { @@ -1258,7 +1249,7 @@ proto.px.api.vizierpb.Int64Column.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Int64Column} */ proto.px.api.vizierpb.Int64Column.deserializeBinary = function(bytes) { @@ -1283,10 +1274,7 @@ proto.px.api.vizierpb.Int64Column.deserializeBinaryFromReader = function(msg, re var field = reader.getFieldNumber(); switch (field) { case 1: - var values = /** @type {!Array} */ (reader.isDelimited() ? reader.readPackedInt64() : [reader.readInt64()]); - for (var i = 0; i < values.length; i++) { - msg.addData(values[i]); - } + reader.readPackableInt64Into(msg.getDataList()); break; default: reader.skipField(); @@ -1403,7 +1391,7 @@ proto.px.api.vizierpb.UInt128Column.prototype.toObject = function(opt_includeIns */ proto.px.api.vizierpb.UInt128Column.toObject = function(includeInstance, msg) { var f, obj = { - dataList: jspb.Message.toObjectList(msg.getDataList(), +dataList: jspb.Message.toObjectList(msg.getDataList(), proto.px.api.vizierpb.UInt128.toObject, includeInstance) }; @@ -1417,7 +1405,7 @@ proto.px.api.vizierpb.UInt128Column.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.UInt128Column} */ proto.px.api.vizierpb.UInt128Column.deserializeBinary = function(bytes) { @@ -1563,7 +1551,7 @@ proto.px.api.vizierpb.Float64Column.prototype.toObject = function(opt_includeIns */ proto.px.api.vizierpb.Float64Column.toObject = function(includeInstance, msg) { var f, obj = { - dataList: (f = jspb.Message.getRepeatedFloatingPointField(msg, 1)) == null ? undefined : f +dataList: (f = jspb.Message.getRepeatedFloatingPointField(msg, 1)) == null ? undefined : f }; if (includeInstance) { @@ -1576,7 +1564,7 @@ proto.px.api.vizierpb.Float64Column.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Float64Column} */ proto.px.api.vizierpb.Float64Column.deserializeBinary = function(bytes) { @@ -1601,10 +1589,7 @@ proto.px.api.vizierpb.Float64Column.deserializeBinaryFromReader = function(msg, var field = reader.getFieldNumber(); switch (field) { case 1: - var values = /** @type {!Array} */ (reader.isDelimited() ? reader.readPackedDouble() : [reader.readDouble()]); - for (var i = 0; i < values.length; i++) { - msg.addData(values[i]); - } + reader.readPackableDoubleInto(msg.getDataList()); break; default: reader.skipField(); @@ -1721,7 +1706,7 @@ proto.px.api.vizierpb.Time64NSColumn.prototype.toObject = function(opt_includeIn */ proto.px.api.vizierpb.Time64NSColumn.toObject = function(includeInstance, msg) { var f, obj = { - dataList: (f = jspb.Message.getRepeatedField(msg, 1)) == null ? undefined : f +dataList: (f = jspb.Message.getRepeatedField(msg, 1)) == null ? undefined : f }; if (includeInstance) { @@ -1734,7 +1719,7 @@ proto.px.api.vizierpb.Time64NSColumn.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Time64NSColumn} */ proto.px.api.vizierpb.Time64NSColumn.deserializeBinary = function(bytes) { @@ -1759,10 +1744,7 @@ proto.px.api.vizierpb.Time64NSColumn.deserializeBinaryFromReader = function(msg, var field = reader.getFieldNumber(); switch (field) { case 1: - var values = /** @type {!Array} */ (reader.isDelimited() ? reader.readPackedInt64() : [reader.readInt64()]); - for (var i = 0; i < values.length; i++) { - msg.addData(values[i]); - } + reader.readPackableInt64Into(msg.getDataList()); break; default: reader.skipField(); @@ -1879,7 +1861,7 @@ proto.px.api.vizierpb.StringColumn.prototype.toObject = function(opt_includeInst */ proto.px.api.vizierpb.StringColumn.toObject = function(includeInstance, msg) { var f, obj = { - dataList: msg.getDataList_asB64() +dataList: msg.getDataList_asB64() }; if (includeInstance) { @@ -1892,7 +1874,7 @@ proto.px.api.vizierpb.StringColumn.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.StringColumn} */ proto.px.api.vizierpb.StringColumn.deserializeBinary = function(bytes) { @@ -2082,12 +2064,12 @@ proto.px.api.vizierpb.Column.prototype.toObject = function(opt_includeInstance) */ proto.px.api.vizierpb.Column.toObject = function(includeInstance, msg) { var f, obj = { - booleanData: (f = msg.getBooleanData()) && proto.px.api.vizierpb.BooleanColumn.toObject(includeInstance, f), - int64Data: (f = msg.getInt64Data()) && proto.px.api.vizierpb.Int64Column.toObject(includeInstance, f), - uint128Data: (f = msg.getUint128Data()) && proto.px.api.vizierpb.UInt128Column.toObject(includeInstance, f), - time64nsData: (f = msg.getTime64nsData()) && proto.px.api.vizierpb.Time64NSColumn.toObject(includeInstance, f), - float64Data: (f = msg.getFloat64Data()) && proto.px.api.vizierpb.Float64Column.toObject(includeInstance, f), - stringData: (f = msg.getStringData()) && proto.px.api.vizierpb.StringColumn.toObject(includeInstance, f) +booleanData: (f = msg.getBooleanData()) && proto.px.api.vizierpb.BooleanColumn.toObject(includeInstance, f), +int64Data: (f = msg.getInt64Data()) && proto.px.api.vizierpb.Int64Column.toObject(includeInstance, f), +uint128Data: (f = msg.getUint128Data()) && proto.px.api.vizierpb.UInt128Column.toObject(includeInstance, f), +time64nsData: (f = msg.getTime64nsData()) && proto.px.api.vizierpb.Time64NSColumn.toObject(includeInstance, f), +float64Data: (f = msg.getFloat64Data()) && proto.px.api.vizierpb.Float64Column.toObject(includeInstance, f), +stringData: (f = msg.getStringData()) && proto.px.api.vizierpb.StringColumn.toObject(includeInstance, f) }; if (includeInstance) { @@ -2100,7 +2082,7 @@ proto.px.api.vizierpb.Column.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Column} */ proto.px.api.vizierpb.Column.deserializeBinary = function(bytes) { @@ -2495,12 +2477,12 @@ proto.px.api.vizierpb.RowBatchData.prototype.toObject = function(opt_includeInst */ proto.px.api.vizierpb.RowBatchData.toObject = function(includeInstance, msg) { var f, obj = { - tableId: jspb.Message.getFieldWithDefault(msg, 5, ""), - colsList: jspb.Message.toObjectList(msg.getColsList(), +tableId: jspb.Message.getFieldWithDefault(msg, 5, ""), +colsList: jspb.Message.toObjectList(msg.getColsList(), proto.px.api.vizierpb.Column.toObject, includeInstance), - numRows: jspb.Message.getFieldWithDefault(msg, 2, 0), - eow: jspb.Message.getBooleanFieldWithDefault(msg, 3, false), - eos: jspb.Message.getBooleanFieldWithDefault(msg, 4, false) +numRows: jspb.Message.getFieldWithDefault(msg, 2, 0), +eow: jspb.Message.getBooleanFieldWithDefault(msg, 3, false), +eos: jspb.Message.getBooleanFieldWithDefault(msg, 4, false) }; if (includeInstance) { @@ -2513,7 +2495,7 @@ proto.px.api.vizierpb.RowBatchData.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.RowBatchData} */ proto.px.api.vizierpb.RowBatchData.deserializeBinary = function(bytes) { @@ -2538,7 +2520,7 @@ proto.px.api.vizierpb.RowBatchData.deserializeBinaryFromReader = function(msg, r var field = reader.getFieldNumber(); switch (field) { case 5: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setTableId(value); break; case 1: @@ -2775,7 +2757,7 @@ proto.px.api.vizierpb.Relation.prototype.toObject = function(opt_includeInstance */ proto.px.api.vizierpb.Relation.toObject = function(includeInstance, msg) { var f, obj = { - columnsList: jspb.Message.toObjectList(msg.getColumnsList(), +columnsList: jspb.Message.toObjectList(msg.getColumnsList(), proto.px.api.vizierpb.Relation.ColumnInfo.toObject, includeInstance) }; @@ -2789,7 +2771,7 @@ proto.px.api.vizierpb.Relation.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Relation} */ proto.px.api.vizierpb.Relation.deserializeBinary = function(bytes) { @@ -2890,10 +2872,10 @@ proto.px.api.vizierpb.Relation.ColumnInfo.prototype.toObject = function(opt_incl */ proto.px.api.vizierpb.Relation.ColumnInfo.toObject = function(includeInstance, msg) { var f, obj = { - columnName: jspb.Message.getFieldWithDefault(msg, 1, ""), - columnType: jspb.Message.getFieldWithDefault(msg, 2, 0), - columnDesc: jspb.Message.getFieldWithDefault(msg, 3, ""), - columnSemanticType: jspb.Message.getFieldWithDefault(msg, 4, 0) +columnName: jspb.Message.getFieldWithDefault(msg, 1, ""), +columnType: jspb.Message.getFieldWithDefault(msg, 2, 0), +columnDesc: jspb.Message.getFieldWithDefault(msg, 3, ""), +columnSemanticType: jspb.Message.getFieldWithDefault(msg, 4, 0) }; if (includeInstance) { @@ -2906,7 +2888,7 @@ proto.px.api.vizierpb.Relation.ColumnInfo.toObject = function(includeInstance, m /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Relation.ColumnInfo} */ proto.px.api.vizierpb.Relation.ColumnInfo.deserializeBinary = function(bytes) { @@ -2931,7 +2913,7 @@ proto.px.api.vizierpb.Relation.ColumnInfo.deserializeBinaryFromReader = function var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setColumnName(value); break; case 2: @@ -2939,7 +2921,7 @@ proto.px.api.vizierpb.Relation.ColumnInfo.deserializeBinaryFromReader = function msg.setColumnType(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setColumnDesc(value); break; case 4: @@ -3148,9 +3130,9 @@ proto.px.api.vizierpb.CompilerError.prototype.toObject = function(opt_includeIns */ proto.px.api.vizierpb.CompilerError.toObject = function(includeInstance, msg) { var f, obj = { - line: jspb.Message.getFieldWithDefault(msg, 1, 0), - column: jspb.Message.getFieldWithDefault(msg, 2, 0), - message: jspb.Message.getFieldWithDefault(msg, 3, "") +line: jspb.Message.getFieldWithDefault(msg, 1, 0), +column: jspb.Message.getFieldWithDefault(msg, 2, 0), +message: jspb.Message.getFieldWithDefault(msg, 3, "") }; if (includeInstance) { @@ -3163,7 +3145,7 @@ proto.px.api.vizierpb.CompilerError.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.CompilerError} */ proto.px.api.vizierpb.CompilerError.deserializeBinary = function(bytes) { @@ -3196,7 +3178,7 @@ proto.px.api.vizierpb.CompilerError.deserializeBinaryFromReader = function(msg, msg.setColumn(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setMessage(value); break; default: @@ -3363,7 +3345,7 @@ proto.px.api.vizierpb.ErrorDetails.prototype.toObject = function(opt_includeInst */ proto.px.api.vizierpb.ErrorDetails.toObject = function(includeInstance, msg) { var f, obj = { - compilerError: (f = msg.getCompilerError()) && proto.px.api.vizierpb.CompilerError.toObject(includeInstance, f) +compilerError: (f = msg.getCompilerError()) && proto.px.api.vizierpb.CompilerError.toObject(includeInstance, f) }; if (includeInstance) { @@ -3376,7 +3358,7 @@ proto.px.api.vizierpb.ErrorDetails.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.ErrorDetails} */ proto.px.api.vizierpb.ErrorDetails.deserializeBinary = function(bytes) { @@ -3521,9 +3503,9 @@ proto.px.api.vizierpb.Status.prototype.toObject = function(opt_includeInstance) */ proto.px.api.vizierpb.Status.toObject = function(includeInstance, msg) { var f, obj = { - code: jspb.Message.getFieldWithDefault(msg, 1, 0), - message: jspb.Message.getFieldWithDefault(msg, 2, ""), - errorDetailsList: jspb.Message.toObjectList(msg.getErrorDetailsList(), +code: jspb.Message.getFieldWithDefault(msg, 1, 0), +message: jspb.Message.getFieldWithDefault(msg, 2, ""), +errorDetailsList: jspb.Message.toObjectList(msg.getErrorDetailsList(), proto.px.api.vizierpb.ErrorDetails.toObject, includeInstance) }; @@ -3537,7 +3519,7 @@ proto.px.api.vizierpb.Status.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Status} */ proto.px.api.vizierpb.Status.deserializeBinary = function(bytes) { @@ -3566,7 +3548,7 @@ proto.px.api.vizierpb.Status.deserializeBinaryFromReader = function(msg, reader) msg.setCode(value); break; case 2: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setMessage(value); break; case 4: @@ -3764,13 +3746,13 @@ proto.px.api.vizierpb.ScalarValue.prototype.toObject = function(opt_includeInsta */ proto.px.api.vizierpb.ScalarValue.toObject = function(includeInstance, msg) { var f, obj = { - dataType: jspb.Message.getFieldWithDefault(msg, 1, 0), - boolValue: jspb.Message.getBooleanFieldWithDefault(msg, 2, false), - int64Value: jspb.Message.getFieldWithDefault(msg, 3, 0), - float64Value: jspb.Message.getFloatingPointFieldWithDefault(msg, 4, 0.0), - stringValue: jspb.Message.getFieldWithDefault(msg, 5, ""), - time64NsValue: jspb.Message.getFieldWithDefault(msg, 6, 0), - uint128Value: (f = msg.getUint128Value()) && proto.px.api.vizierpb.UInt128.toObject(includeInstance, f) +dataType: jspb.Message.getFieldWithDefault(msg, 1, 0), +boolValue: (f = jspb.Message.getBooleanField(msg, 2)) == null ? undefined : f, +int64Value: (f = jspb.Message.getField(msg, 3)) == null ? undefined : f, +float64Value: (f = jspb.Message.getOptionalFloatingPointField(msg, 4)) == null ? undefined : f, +stringValue: (f = jspb.Message.getField(msg, 5)) == null ? undefined : f, +time64NsValue: (f = jspb.Message.getField(msg, 6)) == null ? undefined : f, +uint128Value: (f = msg.getUint128Value()) && proto.px.api.vizierpb.UInt128.toObject(includeInstance, f) }; if (includeInstance) { @@ -3783,7 +3765,7 @@ proto.px.api.vizierpb.ScalarValue.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.ScalarValue} */ proto.px.api.vizierpb.ScalarValue.deserializeBinary = function(bytes) { @@ -3824,7 +3806,7 @@ proto.px.api.vizierpb.ScalarValue.deserializeBinaryFromReader = function(msg, re msg.setFloat64Value(value); break; case 5: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setStringValue(value); break; case 6: @@ -4192,15 +4174,15 @@ proto.px.api.vizierpb.ExecuteScriptRequest.prototype.toObject = function(opt_inc */ proto.px.api.vizierpb.ExecuteScriptRequest.toObject = function(includeInstance, msg) { var f, obj = { - queryStr: jspb.Message.getFieldWithDefault(msg, 1, ""), - clusterId: jspb.Message.getFieldWithDefault(msg, 3, ""), - execFuncsList: jspb.Message.toObjectList(msg.getExecFuncsList(), +queryStr: jspb.Message.getFieldWithDefault(msg, 1, ""), +clusterId: jspb.Message.getFieldWithDefault(msg, 3, ""), +execFuncsList: jspb.Message.toObjectList(msg.getExecFuncsList(), proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.toObject, includeInstance), - mutation: jspb.Message.getBooleanFieldWithDefault(msg, 5, false), - encryptionOptions: (f = msg.getEncryptionOptions()) && proto.px.api.vizierpb.ExecuteScriptRequest.EncryptionOptions.toObject(includeInstance, f), - queryId: jspb.Message.getFieldWithDefault(msg, 7, ""), - configs: (f = msg.getConfigs()) && proto.px.api.vizierpb.Configs.toObject(includeInstance, f), - queryName: jspb.Message.getFieldWithDefault(msg, 10, "") +mutation: jspb.Message.getBooleanFieldWithDefault(msg, 5, false), +encryptionOptions: (f = msg.getEncryptionOptions()) && proto.px.api.vizierpb.ExecuteScriptRequest.EncryptionOptions.toObject(includeInstance, f), +queryId: jspb.Message.getFieldWithDefault(msg, 7, ""), +configs: (f = msg.getConfigs()) && proto.px.api.vizierpb.Configs.toObject(includeInstance, f), +queryName: jspb.Message.getFieldWithDefault(msg, 10, "") }; if (includeInstance) { @@ -4213,7 +4195,7 @@ proto.px.api.vizierpb.ExecuteScriptRequest.toObject = function(includeInstance, /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.ExecuteScriptRequest} */ proto.px.api.vizierpb.ExecuteScriptRequest.deserializeBinary = function(bytes) { @@ -4238,11 +4220,11 @@ proto.px.api.vizierpb.ExecuteScriptRequest.deserializeBinaryFromReader = functio var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setQueryStr(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setClusterId(value); break; case 4: @@ -4260,7 +4242,7 @@ proto.px.api.vizierpb.ExecuteScriptRequest.deserializeBinaryFromReader = functio msg.setEncryptionOptions(value); break; case 7: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setQueryId(value); break; case 9: @@ -4269,7 +4251,7 @@ proto.px.api.vizierpb.ExecuteScriptRequest.deserializeBinaryFromReader = functio msg.setConfigs(value); break; case 10: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setQueryName(value); break; default: @@ -4402,10 +4384,10 @@ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.prototype.toObject = fu */ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.toObject = function(includeInstance, msg) { var f, obj = { - funcName: jspb.Message.getFieldWithDefault(msg, 1, ""), - argValuesList: jspb.Message.toObjectList(msg.getArgValuesList(), +funcName: jspb.Message.getFieldWithDefault(msg, 1, ""), +argValuesList: jspb.Message.toObjectList(msg.getArgValuesList(), proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.ArgValue.toObject, includeInstance), - outputTablePrefix: jspb.Message.getFieldWithDefault(msg, 3, "") +outputTablePrefix: jspb.Message.getFieldWithDefault(msg, 3, "") }; if (includeInstance) { @@ -4418,7 +4400,7 @@ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.toObject = function(inc /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute} */ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.deserializeBinary = function(bytes) { @@ -4443,7 +4425,7 @@ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.deserializeBinaryFromRe var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setFuncName(value); break; case 2: @@ -4452,7 +4434,7 @@ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.deserializeBinaryFromRe msg.addArgValues(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setOutputTablePrefix(value); break; default: @@ -4541,8 +4523,8 @@ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.ArgValue.prototype.toOb */ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.ArgValue.toObject = function(includeInstance, msg) { var f, obj = { - name: jspb.Message.getFieldWithDefault(msg, 1, ""), - value: jspb.Message.getFieldWithDefault(msg, 2, "") +name: jspb.Message.getFieldWithDefault(msg, 1, ""), +value: jspb.Message.getFieldWithDefault(msg, 2, "") }; if (includeInstance) { @@ -4555,7 +4537,7 @@ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.ArgValue.toObject = fun /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.ArgValue} */ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.ArgValue.deserializeBinary = function(bytes) { @@ -4580,11 +4562,11 @@ proto.px.api.vizierpb.ExecuteScriptRequest.FuncToExecute.ArgValue.deserializeBin var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setName(value); break; case 2: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setValue(value); break; default: @@ -4775,10 +4757,10 @@ proto.px.api.vizierpb.ExecuteScriptRequest.EncryptionOptions.prototype.toObject */ proto.px.api.vizierpb.ExecuteScriptRequest.EncryptionOptions.toObject = function(includeInstance, msg) { var f, obj = { - jwkKey: jspb.Message.getFieldWithDefault(msg, 1, ""), - keyAlg: jspb.Message.getFieldWithDefault(msg, 2, ""), - contentAlg: jspb.Message.getFieldWithDefault(msg, 3, ""), - compressionAlg: jspb.Message.getFieldWithDefault(msg, 4, "") +jwkKey: jspb.Message.getFieldWithDefault(msg, 1, ""), +keyAlg: jspb.Message.getFieldWithDefault(msg, 2, ""), +contentAlg: jspb.Message.getFieldWithDefault(msg, 3, ""), +compressionAlg: jspb.Message.getFieldWithDefault(msg, 4, "") }; if (includeInstance) { @@ -4791,7 +4773,7 @@ proto.px.api.vizierpb.ExecuteScriptRequest.EncryptionOptions.toObject = function /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.ExecuteScriptRequest.EncryptionOptions} */ proto.px.api.vizierpb.ExecuteScriptRequest.EncryptionOptions.deserializeBinary = function(bytes) { @@ -4816,19 +4798,19 @@ proto.px.api.vizierpb.ExecuteScriptRequest.EncryptionOptions.deserializeBinaryFr var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setJwkKey(value); break; case 2: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setKeyAlg(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setContentAlg(value); break; case 4: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setCompressionAlg(value); break; default: @@ -5197,8 +5179,8 @@ proto.px.api.vizierpb.Configs.prototype.toObject = function(opt_includeInstance) */ proto.px.api.vizierpb.Configs.toObject = function(includeInstance, msg) { var f, obj = { - otelEndpointConfig: (f = msg.getOtelEndpointConfig()) && proto.px.api.vizierpb.Configs.OTelEndpointConfig.toObject(includeInstance, f), - pluginConfig: (f = msg.getPluginConfig()) && proto.px.api.vizierpb.Configs.PluginConfig.toObject(includeInstance, f) +otelEndpointConfig: (f = msg.getOtelEndpointConfig()) && proto.px.api.vizierpb.Configs.OTelEndpointConfig.toObject(includeInstance, f), +pluginConfig: (f = msg.getPluginConfig()) && proto.px.api.vizierpb.Configs.PluginConfig.toObject(includeInstance, f) }; if (includeInstance) { @@ -5211,7 +5193,7 @@ proto.px.api.vizierpb.Configs.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Configs} */ proto.px.api.vizierpb.Configs.deserializeBinary = function(bytes) { @@ -5325,10 +5307,10 @@ proto.px.api.vizierpb.Configs.OTelEndpointConfig.prototype.toObject = function(o */ proto.px.api.vizierpb.Configs.OTelEndpointConfig.toObject = function(includeInstance, msg) { var f, obj = { - url: jspb.Message.getFieldWithDefault(msg, 1, ""), - headersMap: (f = msg.getHeadersMap()) ? f.toObject(includeInstance, undefined) : [], - insecure: jspb.Message.getBooleanFieldWithDefault(msg, 3, false), - timeout: jspb.Message.getFieldWithDefault(msg, 4, 0) +url: jspb.Message.getFieldWithDefault(msg, 1, ""), +headersMap: (f = msg.getHeadersMap()) ? f.toObject(includeInstance, undefined) : [], +insecure: jspb.Message.getBooleanFieldWithDefault(msg, 3, false), +timeout: jspb.Message.getFieldWithDefault(msg, 4, 0) }; if (includeInstance) { @@ -5341,7 +5323,7 @@ proto.px.api.vizierpb.Configs.OTelEndpointConfig.toObject = function(includeInst /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Configs.OTelEndpointConfig} */ proto.px.api.vizierpb.Configs.OTelEndpointConfig.deserializeBinary = function(bytes) { @@ -5366,13 +5348,13 @@ proto.px.api.vizierpb.Configs.OTelEndpointConfig.deserializeBinaryFromReader = f var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setUrl(value); break; case 2: var value = msg.getHeadersMap(); reader.readMessage(value, function(message, reader) { - jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readString, null, "", ""); + jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readStringRequireUtf8, jspb.BinaryReader.prototype.readStringRequireUtf8, null, "", ""); }); break; case 3: @@ -5421,7 +5403,12 @@ proto.px.api.vizierpb.Configs.OTelEndpointConfig.serializeBinaryToWriter = funct } f = message.getHeadersMap(true); if (f && f.getLength() > 0) { - f.serializeBinary(2, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeString); +jspb.internal.public_for_gencode.serializeMapToBinary( + message.getHeadersMap(true), + 2, + writer, + jspb.BinaryWriter.prototype.writeString, + jspb.BinaryWriter.prototype.writeString); } f = message.getInsecure(); if (f) { @@ -5549,8 +5536,8 @@ proto.px.api.vizierpb.Configs.PluginConfig.prototype.toObject = function(opt_inc */ proto.px.api.vizierpb.Configs.PluginConfig.toObject = function(includeInstance, msg) { var f, obj = { - startTimeNs: jspb.Message.getFieldWithDefault(msg, 1, 0), - endTimeNs: jspb.Message.getFieldWithDefault(msg, 2, 0) +startTimeNs: jspb.Message.getFieldWithDefault(msg, 1, 0), +endTimeNs: jspb.Message.getFieldWithDefault(msg, 2, 0) }; if (includeInstance) { @@ -5563,7 +5550,7 @@ proto.px.api.vizierpb.Configs.PluginConfig.toObject = function(includeInstance, /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.Configs.PluginConfig} */ proto.px.api.vizierpb.Configs.PluginConfig.deserializeBinary = function(bytes) { @@ -5783,8 +5770,8 @@ proto.px.api.vizierpb.QueryTimingInfo.prototype.toObject = function(opt_includeI */ proto.px.api.vizierpb.QueryTimingInfo.toObject = function(includeInstance, msg) { var f, obj = { - executionTimeNs: jspb.Message.getFieldWithDefault(msg, 1, 0), - compilationTimeNs: jspb.Message.getFieldWithDefault(msg, 2, 0) +executionTimeNs: jspb.Message.getFieldWithDefault(msg, 1, 0), +compilationTimeNs: jspb.Message.getFieldWithDefault(msg, 2, 0) }; if (includeInstance) { @@ -5797,7 +5784,7 @@ proto.px.api.vizierpb.QueryTimingInfo.toObject = function(includeInstance, msg) /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.QueryTimingInfo} */ proto.px.api.vizierpb.QueryTimingInfo.deserializeBinary = function(bytes) { @@ -5943,9 +5930,9 @@ proto.px.api.vizierpb.QueryExecutionStats.prototype.toObject = function(opt_incl */ proto.px.api.vizierpb.QueryExecutionStats.toObject = function(includeInstance, msg) { var f, obj = { - timing: (f = msg.getTiming()) && proto.px.api.vizierpb.QueryTimingInfo.toObject(includeInstance, f), - bytesProcessed: jspb.Message.getFieldWithDefault(msg, 2, 0), - recordsProcessed: jspb.Message.getFieldWithDefault(msg, 3, 0) +timing: (f = msg.getTiming()) && proto.px.api.vizierpb.QueryTimingInfo.toObject(includeInstance, f), +bytesProcessed: jspb.Message.getFieldWithDefault(msg, 2, 0), +recordsProcessed: jspb.Message.getFieldWithDefault(msg, 3, 0) }; if (includeInstance) { @@ -5958,7 +5945,7 @@ proto.px.api.vizierpb.QueryExecutionStats.toObject = function(includeInstance, m /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.QueryExecutionStats} */ proto.px.api.vizierpb.QueryExecutionStats.deserializeBinary = function(bytes) { @@ -6154,9 +6141,9 @@ proto.px.api.vizierpb.QueryMetadata.prototype.toObject = function(opt_includeIns */ proto.px.api.vizierpb.QueryMetadata.toObject = function(includeInstance, msg) { var f, obj = { - relation: (f = msg.getRelation()) && proto.px.api.vizierpb.Relation.toObject(includeInstance, f), - name: jspb.Message.getFieldWithDefault(msg, 2, ""), - id: jspb.Message.getFieldWithDefault(msg, 3, "") +relation: (f = msg.getRelation()) && proto.px.api.vizierpb.Relation.toObject(includeInstance, f), +name: jspb.Message.getFieldWithDefault(msg, 2, ""), +id: jspb.Message.getFieldWithDefault(msg, 3, "") }; if (includeInstance) { @@ -6169,7 +6156,7 @@ proto.px.api.vizierpb.QueryMetadata.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.QueryMetadata} */ proto.px.api.vizierpb.QueryMetadata.deserializeBinary = function(bytes) { @@ -6199,11 +6186,11 @@ proto.px.api.vizierpb.QueryMetadata.deserializeBinaryFromReader = function(msg, msg.setRelation(value); break; case 2: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setName(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setId(value); break; default: @@ -6365,9 +6352,9 @@ proto.px.api.vizierpb.QueryData.prototype.toObject = function(opt_includeInstanc */ proto.px.api.vizierpb.QueryData.toObject = function(includeInstance, msg) { var f, obj = { - batch: (f = msg.getBatch()) && proto.px.api.vizierpb.RowBatchData.toObject(includeInstance, f), - encryptedBatch: msg.getEncryptedBatch_asB64(), - executionStats: (f = msg.getExecutionStats()) && proto.px.api.vizierpb.QueryExecutionStats.toObject(includeInstance, f) +batch: (f = msg.getBatch()) && proto.px.api.vizierpb.RowBatchData.toObject(includeInstance, f), +encryptedBatch: msg.getEncryptedBatch_asB64(), +executionStats: (f = msg.getExecutionStats()) && proto.px.api.vizierpb.QueryExecutionStats.toObject(includeInstance, f) }; if (includeInstance) { @@ -6380,7 +6367,7 @@ proto.px.api.vizierpb.QueryData.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.QueryData} */ proto.px.api.vizierpb.QueryData.deserializeBinary = function(bytes) { @@ -6647,11 +6634,11 @@ proto.px.api.vizierpb.ExecuteScriptResponse.prototype.toObject = function(opt_in */ proto.px.api.vizierpb.ExecuteScriptResponse.toObject = function(includeInstance, msg) { var f, obj = { - status: (f = msg.getStatus()) && proto.px.api.vizierpb.Status.toObject(includeInstance, f), - queryId: jspb.Message.getFieldWithDefault(msg, 2, ""), - data: (f = msg.getData()) && proto.px.api.vizierpb.QueryData.toObject(includeInstance, f), - metaData: (f = msg.getMetaData()) && proto.px.api.vizierpb.QueryMetadata.toObject(includeInstance, f), - mutationInfo: (f = msg.getMutationInfo()) && proto.px.api.vizierpb.MutationInfo.toObject(includeInstance, f) +status: (f = msg.getStatus()) && proto.px.api.vizierpb.Status.toObject(includeInstance, f), +queryId: jspb.Message.getFieldWithDefault(msg, 2, ""), +data: (f = msg.getData()) && proto.px.api.vizierpb.QueryData.toObject(includeInstance, f), +metaData: (f = msg.getMetaData()) && proto.px.api.vizierpb.QueryMetadata.toObject(includeInstance, f), +mutationInfo: (f = msg.getMutationInfo()) && proto.px.api.vizierpb.MutationInfo.toObject(includeInstance, f) }; if (includeInstance) { @@ -6664,7 +6651,7 @@ proto.px.api.vizierpb.ExecuteScriptResponse.toObject = function(includeInstance, /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.ExecuteScriptResponse} */ proto.px.api.vizierpb.ExecuteScriptResponse.deserializeBinary = function(bytes) { @@ -6694,7 +6681,7 @@ proto.px.api.vizierpb.ExecuteScriptResponse.deserializeBinaryFromReader = functi msg.setStatus(value); break; case 2: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setQueryId(value); break; case 3: @@ -6988,8 +6975,8 @@ proto.px.api.vizierpb.MutationInfo.prototype.toObject = function(opt_includeInst */ proto.px.api.vizierpb.MutationInfo.toObject = function(includeInstance, msg) { var f, obj = { - status: (f = msg.getStatus()) && proto.px.api.vizierpb.Status.toObject(includeInstance, f), - statesList: jspb.Message.toObjectList(msg.getStatesList(), +status: (f = msg.getStatus()) && proto.px.api.vizierpb.Status.toObject(includeInstance, f), +statesList: jspb.Message.toObjectList(msg.getStatesList(), proto.px.api.vizierpb.MutationInfo.MutationState.toObject, includeInstance) }; @@ -7003,7 +6990,7 @@ proto.px.api.vizierpb.MutationInfo.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.MutationInfo} */ proto.px.api.vizierpb.MutationInfo.deserializeBinary = function(bytes) { @@ -7117,9 +7104,9 @@ proto.px.api.vizierpb.MutationInfo.MutationState.prototype.toObject = function(o */ proto.px.api.vizierpb.MutationInfo.MutationState.toObject = function(includeInstance, msg) { var f, obj = { - id: jspb.Message.getFieldWithDefault(msg, 1, ""), - state: jspb.Message.getFieldWithDefault(msg, 2, 0), - name: jspb.Message.getFieldWithDefault(msg, 3, "") +id: jspb.Message.getFieldWithDefault(msg, 1, ""), +state: jspb.Message.getFieldWithDefault(msg, 2, 0), +name: jspb.Message.getFieldWithDefault(msg, 3, "") }; if (includeInstance) { @@ -7132,7 +7119,7 @@ proto.px.api.vizierpb.MutationInfo.MutationState.toObject = function(includeInst /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.MutationInfo.MutationState} */ proto.px.api.vizierpb.MutationInfo.MutationState.deserializeBinary = function(bytes) { @@ -7157,7 +7144,7 @@ proto.px.api.vizierpb.MutationInfo.MutationState.deserializeBinaryFromReader = f var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setId(value); break; case 2: @@ -7165,7 +7152,7 @@ proto.px.api.vizierpb.MutationInfo.MutationState.deserializeBinaryFromReader = f msg.setState(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setName(value); break; default: @@ -7382,7 +7369,7 @@ proto.px.api.vizierpb.HealthCheckRequest.prototype.toObject = function(opt_inclu */ proto.px.api.vizierpb.HealthCheckRequest.toObject = function(includeInstance, msg) { var f, obj = { - clusterId: jspb.Message.getFieldWithDefault(msg, 1, "") +clusterId: jspb.Message.getFieldWithDefault(msg, 1, "") }; if (includeInstance) { @@ -7395,7 +7382,7 @@ proto.px.api.vizierpb.HealthCheckRequest.toObject = function(includeInstance, ms /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.HealthCheckRequest} */ proto.px.api.vizierpb.HealthCheckRequest.deserializeBinary = function(bytes) { @@ -7420,7 +7407,7 @@ proto.px.api.vizierpb.HealthCheckRequest.deserializeBinaryFromReader = function( var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setClusterId(value); break; default: @@ -7512,7 +7499,7 @@ proto.px.api.vizierpb.HealthCheckResponse.prototype.toObject = function(opt_incl */ proto.px.api.vizierpb.HealthCheckResponse.toObject = function(includeInstance, msg) { var f, obj = { - status: (f = msg.getStatus()) && proto.px.api.vizierpb.Status.toObject(includeInstance, f) +status: (f = msg.getStatus()) && proto.px.api.vizierpb.Status.toObject(includeInstance, f) }; if (includeInstance) { @@ -7525,7 +7512,7 @@ proto.px.api.vizierpb.HealthCheckResponse.toObject = function(includeInstance, m /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.HealthCheckResponse} */ proto.px.api.vizierpb.HealthCheckResponse.deserializeBinary = function(bytes) { @@ -7663,8 +7650,8 @@ proto.px.api.vizierpb.GenerateOTelScriptRequest.prototype.toObject = function(op */ proto.px.api.vizierpb.GenerateOTelScriptRequest.toObject = function(includeInstance, msg) { var f, obj = { - clusterId: jspb.Message.getFieldWithDefault(msg, 1, ""), - pxlScript: jspb.Message.getFieldWithDefault(msg, 2, "") +clusterId: jspb.Message.getFieldWithDefault(msg, 1, ""), +pxlScript: jspb.Message.getFieldWithDefault(msg, 2, "") }; if (includeInstance) { @@ -7677,7 +7664,7 @@ proto.px.api.vizierpb.GenerateOTelScriptRequest.toObject = function(includeInsta /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.GenerateOTelScriptRequest} */ proto.px.api.vizierpb.GenerateOTelScriptRequest.deserializeBinary = function(bytes) { @@ -7702,11 +7689,11 @@ proto.px.api.vizierpb.GenerateOTelScriptRequest.deserializeBinaryFromReader = fu var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setClusterId(value); break; case 2: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setPxlScript(value); break; default: @@ -7823,8 +7810,8 @@ proto.px.api.vizierpb.GenerateOTelScriptResponse.prototype.toObject = function(o */ proto.px.api.vizierpb.GenerateOTelScriptResponse.toObject = function(includeInstance, msg) { var f, obj = { - status: (f = msg.getStatus()) && proto.px.api.vizierpb.Status.toObject(includeInstance, f), - otelScript: jspb.Message.getFieldWithDefault(msg, 2, "") +status: (f = msg.getStatus()) && proto.px.api.vizierpb.Status.toObject(includeInstance, f), +otelScript: jspb.Message.getFieldWithDefault(msg, 2, "") }; if (includeInstance) { @@ -7837,7 +7824,7 @@ proto.px.api.vizierpb.GenerateOTelScriptResponse.toObject = function(includeInst /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.GenerateOTelScriptResponse} */ proto.px.api.vizierpb.GenerateOTelScriptResponse.deserializeBinary = function(bytes) { @@ -7867,7 +7854,7 @@ proto.px.api.vizierpb.GenerateOTelScriptResponse.deserializeBinaryFromReader = f msg.setStatus(value); break; case 2: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setOtelScript(value); break; default: @@ -8004,10 +7991,10 @@ proto.px.api.vizierpb.DebugLogRequest.prototype.toObject = function(opt_includeI */ proto.px.api.vizierpb.DebugLogRequest.toObject = function(includeInstance, msg) { var f, obj = { - clusterId: jspb.Message.getFieldWithDefault(msg, 1, ""), - podName: jspb.Message.getFieldWithDefault(msg, 2, ""), - previous: jspb.Message.getBooleanFieldWithDefault(msg, 3, false), - container: jspb.Message.getFieldWithDefault(msg, 4, "") +clusterId: jspb.Message.getFieldWithDefault(msg, 1, ""), +podName: jspb.Message.getFieldWithDefault(msg, 2, ""), +previous: jspb.Message.getBooleanFieldWithDefault(msg, 3, false), +container: jspb.Message.getFieldWithDefault(msg, 4, "") }; if (includeInstance) { @@ -8020,7 +8007,7 @@ proto.px.api.vizierpb.DebugLogRequest.toObject = function(includeInstance, msg) /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.DebugLogRequest} */ proto.px.api.vizierpb.DebugLogRequest.deserializeBinary = function(bytes) { @@ -8045,11 +8032,11 @@ proto.px.api.vizierpb.DebugLogRequest.deserializeBinaryFromReader = function(msg var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setClusterId(value); break; case 2: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setPodName(value); break; case 3: @@ -8057,7 +8044,7 @@ proto.px.api.vizierpb.DebugLogRequest.deserializeBinaryFromReader = function(msg msg.setPrevious(value); break; case 4: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setContainer(value); break; default: @@ -8224,7 +8211,7 @@ proto.px.api.vizierpb.DebugLogResponse.prototype.toObject = function(opt_include */ proto.px.api.vizierpb.DebugLogResponse.toObject = function(includeInstance, msg) { var f, obj = { - data: jspb.Message.getFieldWithDefault(msg, 2, "") +data: jspb.Message.getFieldWithDefault(msg, 2, "") }; if (includeInstance) { @@ -8237,7 +8224,7 @@ proto.px.api.vizierpb.DebugLogResponse.toObject = function(includeInstance, msg) /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.DebugLogResponse} */ proto.px.api.vizierpb.DebugLogResponse.deserializeBinary = function(bytes) { @@ -8262,7 +8249,7 @@ proto.px.api.vizierpb.DebugLogResponse.deserializeBinaryFromReader = function(ms var field = reader.getFieldNumber(); switch (field) { case 2: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setData(value); break; default: @@ -8354,12 +8341,12 @@ proto.px.api.vizierpb.ContainerStatus.prototype.toObject = function(opt_includeI */ proto.px.api.vizierpb.ContainerStatus.toObject = function(includeInstance, msg) { var f, obj = { - name: jspb.Message.getFieldWithDefault(msg, 1, ""), - containerState: jspb.Message.getFieldWithDefault(msg, 2, 0), - message: jspb.Message.getFieldWithDefault(msg, 3, ""), - reason: jspb.Message.getFieldWithDefault(msg, 4, ""), - startTimestampNs: jspb.Message.getFieldWithDefault(msg, 5, 0), - restartCount: jspb.Message.getFieldWithDefault(msg, 6, 0) +name: jspb.Message.getFieldWithDefault(msg, 1, ""), +containerState: jspb.Message.getFieldWithDefault(msg, 2, 0), +message: jspb.Message.getFieldWithDefault(msg, 3, ""), +reason: jspb.Message.getFieldWithDefault(msg, 4, ""), +startTimestampNs: jspb.Message.getFieldWithDefault(msg, 5, 0), +restartCount: jspb.Message.getFieldWithDefault(msg, 6, 0) }; if (includeInstance) { @@ -8372,7 +8359,7 @@ proto.px.api.vizierpb.ContainerStatus.toObject = function(includeInstance, msg) /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.ContainerStatus} */ proto.px.api.vizierpb.ContainerStatus.deserializeBinary = function(bytes) { @@ -8397,7 +8384,7 @@ proto.px.api.vizierpb.ContainerStatus.deserializeBinaryFromReader = function(msg var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setName(value); break; case 2: @@ -8405,11 +8392,11 @@ proto.px.api.vizierpb.ContainerStatus.deserializeBinaryFromReader = function(msg msg.setContainerState(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setMessage(value); break; case 4: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setReason(value); break; case 5: @@ -8641,14 +8628,14 @@ proto.px.api.vizierpb.VizierPodStatus.prototype.toObject = function(opt_includeI */ proto.px.api.vizierpb.VizierPodStatus.toObject = function(includeInstance, msg) { var f, obj = { - name: jspb.Message.getFieldWithDefault(msg, 1, ""), - phase: jspb.Message.getFieldWithDefault(msg, 2, 0), - message: jspb.Message.getFieldWithDefault(msg, 3, ""), - reason: jspb.Message.getFieldWithDefault(msg, 4, ""), - createdAt: jspb.Message.getFieldWithDefault(msg, 5, 0), - containerStatusesList: jspb.Message.toObjectList(msg.getContainerStatusesList(), +name: jspb.Message.getFieldWithDefault(msg, 1, ""), +phase: jspb.Message.getFieldWithDefault(msg, 2, 0), +message: jspb.Message.getFieldWithDefault(msg, 3, ""), +reason: jspb.Message.getFieldWithDefault(msg, 4, ""), +createdAt: jspb.Message.getFieldWithDefault(msg, 5, 0), +containerStatusesList: jspb.Message.toObjectList(msg.getContainerStatusesList(), proto.px.api.vizierpb.ContainerStatus.toObject, includeInstance), - restartCount: jspb.Message.getFieldWithDefault(msg, 7, 0) +restartCount: jspb.Message.getFieldWithDefault(msg, 7, 0) }; if (includeInstance) { @@ -8661,7 +8648,7 @@ proto.px.api.vizierpb.VizierPodStatus.toObject = function(includeInstance, msg) /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.VizierPodStatus} */ proto.px.api.vizierpb.VizierPodStatus.deserializeBinary = function(bytes) { @@ -8686,7 +8673,7 @@ proto.px.api.vizierpb.VizierPodStatus.deserializeBinaryFromReader = function(msg var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setName(value); break; case 2: @@ -8694,11 +8681,11 @@ proto.px.api.vizierpb.VizierPodStatus.deserializeBinaryFromReader = function(msg msg.setPhase(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setMessage(value); break; case 4: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setReason(value); break; case 5: @@ -8974,7 +8961,7 @@ proto.px.api.vizierpb.DebugPodsRequest.prototype.toObject = function(opt_include */ proto.px.api.vizierpb.DebugPodsRequest.toObject = function(includeInstance, msg) { var f, obj = { - clusterId: jspb.Message.getFieldWithDefault(msg, 1, "") +clusterId: jspb.Message.getFieldWithDefault(msg, 1, "") }; if (includeInstance) { @@ -8987,7 +8974,7 @@ proto.px.api.vizierpb.DebugPodsRequest.toObject = function(includeInstance, msg) /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.DebugPodsRequest} */ proto.px.api.vizierpb.DebugPodsRequest.deserializeBinary = function(bytes) { @@ -9012,7 +8999,7 @@ proto.px.api.vizierpb.DebugPodsRequest.deserializeBinaryFromReader = function(ms var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {string} */ (reader.readStringRequireUtf8()); msg.setClusterId(value); break; default: @@ -9111,9 +9098,9 @@ proto.px.api.vizierpb.DebugPodsResponse.prototype.toObject = function(opt_includ */ proto.px.api.vizierpb.DebugPodsResponse.toObject = function(includeInstance, msg) { var f, obj = { - dataPlanePodsList: jspb.Message.toObjectList(msg.getDataPlanePodsList(), +dataPlanePodsList: jspb.Message.toObjectList(msg.getDataPlanePodsList(), proto.px.api.vizierpb.VizierPodStatus.toObject, includeInstance), - controlPlanePodsList: jspb.Message.toObjectList(msg.getControlPlanePodsList(), +controlPlanePodsList: jspb.Message.toObjectList(msg.getControlPlanePodsList(), proto.px.api.vizierpb.VizierPodStatus.toObject, includeInstance) }; @@ -9127,7 +9114,7 @@ proto.px.api.vizierpb.DebugPodsResponse.toObject = function(includeInstance, msg /** * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @param {jspb.binary.bytesource.ByteSource} bytes The bytes to deserialize. * @return {!proto.px.api.vizierpb.DebugPodsResponse} */ proto.px.api.vizierpb.DebugPodsResponse.deserializeBinary = function(bytes) { From 58e1c4a911b9ff5057a7124b10dca4e7dadd49b6 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 23:29:51 +0000 Subject: [PATCH 13/17] Upgrade google-protobuf npm package to match protobuf version Signed-off-by: Dom Del Nano (cherry picked from commit 929b042996c0fa13871d0d3764e1e82a7bfd45fe) --- src/ui/package.json | 2 +- src/ui/yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ui/package.json b/src/ui/package.json index 11798ecec1e..4b437f9c2c6 100644 --- a/src/ui/package.json +++ b/src/ui/package.json @@ -101,7 +101,7 @@ "axios": "^0.21.4", "cross-fetch": "^3.1.5", "date-fns": "^2.29.3", - "google-protobuf": "^3.15.5", + "google-protobuf": "4.0.1", "graphql": "^15.5.0", "grpc-web": "^1.0.7", "history": "^4.10.1", diff --git a/src/ui/yarn.lock b/src/ui/yarn.lock index 9d3f45fa7f6..58828e1601a 100644 --- a/src/ui/yarn.lock +++ b/src/ui/yarn.lock @@ -2810,7 +2810,7 @@ __metadata: favicons-webpack-plugin: ^6.0.0 file-loader: ^6.2.0 fsevents: ^2.3.2 - google-protobuf: ^3.15.5 + google-protobuf: 4.0.1 graphql: ^15.5.0 graphql-schema-typescript: ^1.5.2 grpc-web: ^1.0.7 @@ -8562,10 +8562,10 @@ __metadata: languageName: node linkType: hard -"google-protobuf@npm:^3.15.5": - version: 3.15.7 - resolution: "google-protobuf@npm:3.15.7" - checksum: 532b36804b260cb30402ab0c715e3706e2adb81319320cb5c198861c207d193807ccd22d754da3f1e5c5ae90f61b4627893afb6e2f2316fcab40b87fdf1978e3 +"google-protobuf@npm:4.0.1": + version: 4.0.1 + resolution: "google-protobuf@npm:4.0.1" + checksum: d6ed3007b121ac28dbe9a686bdcc26ba4aba8bc41bd43bbaf59c2cbad96eba4d56338b9da56e8006fa89922eb5b15cb5c79f40b82d03ac39e006c9163435ad4b languageName: node linkType: hard From 9b80f0a55acbdf8e2368842c37fb5876f9a408f8 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Dec 2025 23:42:18 +0000 Subject: [PATCH 14/17] Exclude grpc_generator.cc from linting as its a vendored file Signed-off-by: Dom Del Nano --- .arclint | 1 + 1 file changed, 1 insertion(+) diff --git a/.arclint b/.arclint index 7b87106fe80..2bb8b3b8303 100644 --- a/.arclint +++ b/.arclint @@ -34,6 +34,7 @@ "(^src/ui/src/types/schema\\.ts$)", "(^third_party/cpplint/cpplint.py$)", "(^third_party/gogoproto/gogo.proto$)", + "(^third_party/protoc-gen-grpc-web/grpc_generator.cc$)", "(c_cpp_properties.json$)", "(go\\.mod$)", "(go\\.sum$)" From 8237a5345732aae62b8a60f042a64f303aff5597 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Fri, 12 Dec 2025 09:27:07 +0000 Subject: [PATCH 15/17] Upgrade grpc-web to 2.0.2. Remove vendored copy with bazel repo Signed-off-by: Dom Del Nano --- .../grpc-web_protobuf_v30_support.patch | 409 ++++ bazel/grpc_web.bzl | 2 +- bazel/repositories.bzl | 2 + bazel/repository_locations.bzl | 5 + src/ui/package.json | 2 +- src/ui/yarn.lock | 10 +- third_party/protoc-gen-grpc-web/BUILD.bazel | 27 - third_party/protoc-gen-grpc-web/LICENSE | 205 -- third_party/protoc-gen-grpc-web/README.md | 6 - .../protoc-gen-grpc-web/grpc_generator.cc | 1790 ----------------- 10 files changed, 423 insertions(+), 2035 deletions(-) create mode 100644 bazel/external/grpc-web_protobuf_v30_support.patch delete mode 100644 third_party/protoc-gen-grpc-web/BUILD.bazel delete mode 100644 third_party/protoc-gen-grpc-web/LICENSE delete mode 100644 third_party/protoc-gen-grpc-web/README.md delete mode 100644 third_party/protoc-gen-grpc-web/grpc_generator.cc diff --git a/bazel/external/grpc-web_protobuf_v30_support.patch b/bazel/external/grpc-web_protobuf_v30_support.patch new file mode 100644 index 00000000000..28fc8c55850 --- /dev/null +++ b/bazel/external/grpc-web_protobuf_v30_support.patch @@ -0,0 +1,409 @@ +diff --git a/javascript/net/grpc/web/generator/grpc_generator.cc b/javascript/net/grpc/web/generator/grpc_generator.cc +index 5695f31..52eec82 100644 +--- a/javascript/net/grpc/web/generator/grpc_generator.cc ++++ b/javascript/net/grpc/web/generator/grpc_generator.cc +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + using google::protobuf::Descriptor; + using google::protobuf::Edition; +@@ -132,7 +133,8 @@ std::string GetSerializeMethodReturnType(std::map vars) { + return "!Uint8Array"; + } + +-string LowercaseFirstLetter(string s) { ++string LowercaseFirstLetter(std::string_view sv) { ++ string s(sv); + if (s.empty()) { + return s; + } +@@ -140,7 +142,8 @@ string LowercaseFirstLetter(string s) { + return s; + } + +-string Lowercase(string s) { ++string Lowercase(std::string_view sv) { ++ string s(sv); + if (s.empty()) { + return s; + } +@@ -151,7 +154,8 @@ string Lowercase(string s) { + return s; + } + +-string UppercaseFirstLetter(string s) { ++string UppercaseFirstLetter(std::string_view sv) { ++ string s(sv); + if (s.empty()) { + return s; + } +@@ -159,7 +163,8 @@ string UppercaseFirstLetter(string s) { + return s; + } + +-string Uppercase(string s) { ++string Uppercase(std::string_view sv) { ++ string s(sv); + if (s.empty()) { + return s; + } +@@ -173,35 +178,35 @@ string Uppercase(string s) { + // The following 5 functions were copied from + // google/protobuf/src/google/protobuf/stubs/strutil.h + +-inline bool HasPrefixString(const string& str, const string& prefix) { ++inline bool HasPrefixString(std::string_view str, std::string_view prefix) { + return str.size() >= prefix.size() && + str.compare(0, prefix.size(), prefix) == 0; + } + + // Strips the given prefix from the string, as well as the remaining leading dot + // if it exists. +-inline string StripPrefixString(const string& str, const string& prefix) { ++inline string StripPrefixString(std::string_view str, std::string_view prefix) { + if (!HasPrefixString(str, prefix)) { +- return str; ++ return string(str); + } + +- string remaining_str = str.substr(prefix.size()); ++ string remaining_str(str.substr(prefix.size())); + if (!remaining_str.empty() && remaining_str[0] == '.') { + remaining_str = remaining_str.substr(1); + } + return remaining_str; + } + +-inline bool HasSuffixString(const string& str, const string& suffix) { ++inline bool HasSuffixString(std::string_view str, std::string_view suffix) { + return str.size() >= suffix.size() && + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; + } + +-inline string StripSuffixString(const string& str, const string& suffix) { ++inline string StripSuffixString(std::string_view str, std::string_view suffix) { + if (HasSuffixString(str, suffix)) { +- return str.substr(0, str.size() - suffix.size()); ++ return string(str.substr(0, str.size() - suffix.size())); + } else { +- return str; ++ return string(str); + } + } + +@@ -217,7 +222,7 @@ void ReplaceCharacters(string* s, const char* remove, char replacewith) { + // The following function was copied from + // google/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc + +-string StripProto(const string& filename) { ++string StripProto(std::string_view filename) { + if (HasSuffixString(filename, ".protodevel")) { + return StripSuffixString(filename, ".protodevel"); + } else { +@@ -236,7 +241,7 @@ char ToLowerASCII(char c) { + } + } + +-std::vector ParseLowerUnderscore(const string& input) { ++std::vector ParseLowerUnderscore(std::string_view input) { + std::vector words; + string running = ""; + for (size_t i = 0; i < input.size(); i++) { +@@ -269,7 +274,7 @@ string ToUpperCamel(const std::vector& words) { + + // Returns the alias we assign to the module of the given .proto filename + // when importing. +-string ModuleAlias(const string& filename) { ++string ModuleAlias(std::string_view filename) { + // This scheme could technically cause problems if a file includes any 2 of: + // foo/bar_baz.proto + // foo_bar_baz.proto +@@ -433,7 +438,7 @@ string GetNestedMessageName(const Descriptor* descriptor) { + + // Given a filename like foo/bar/baz.proto, returns the root directory + // path ../../ +-string GetRootPath(const string& from_filename, const string& to_filename) { ++string GetRootPath(std::string_view from_filename, std::string_view to_filename) { + if (HasPrefixString(to_filename, "google/protobuf")) { + // Well-known types (.proto files in the google/protobuf directory) are + // assumed to come from the 'google-protobuf' npm package. We may want to +@@ -494,8 +499,8 @@ std::map GetAllMessages(const FileDescriptor* file) { + const ServiceDescriptor* service = file->service(s); + for (int m = 0; m < service->method_count(); ++m) { + const MethodDescriptor* method = service->method(m); +- messages[method->input_type()->full_name()] = method->input_type(); +- messages[method->output_type()->full_name()] = method->output_type(); ++ messages[string(method->input_type()->full_name())] = method->input_type(); ++ messages[string(method->output_type()->full_name())] = method->output_type(); + } + } + +@@ -513,14 +518,14 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) { + std::map vars; + + for (int i = 0; i < file->dependency_count(); i++) { +- const string& name = file->dependency(i)->name(); ++ const string name(file->dependency(i)->name()); + vars["alias"] = ModuleAlias(name); + vars["dep_filename"] = GetRootPath(file->name(), name) + StripProto(name); + // we need to give each cross-file import an alias + printer->Print(vars, "\nvar $alias$ = require('$dep_filename$_pb.js')\n"); + } + +- const string& package = file->package(); ++ const string package(file->package()); + vars["package_name"] = package; + + if (!package.empty()) { +@@ -556,7 +561,7 @@ void PrintES6Imports(Printer* printer, const FileDescriptor* file) { + + std::set imports; + for (const auto& entry : GetAllMessages(file)) { +- const string& proto_filename = entry.second->file()->name(); ++ const string proto_filename(entry.second->file()->name()); + string dep_filename = GetRootPath(file->name(), proto_filename) + StripProto(proto_filename); + if (imports.find(dep_filename) != imports.end()) { + continue; +@@ -578,7 +583,7 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, + ++service_index) { + printer->Print("export class "); + const ServiceDescriptor* service = file->service(service_index); +- vars["service_name"] = service->name(); ++ vars["service_name"] = string(service->name()); + printer->Print(vars, "$service_name$Client {\n"); + printer->Indent(); + printer->Print( +@@ -607,7 +612,7 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, + ++method_index) { + const MethodDescriptor* method = service->method(method_index); + vars["js_method_name"] = LowercaseFirstLetter(method->name()); +- vars["method_name"] = method->name(); ++ vars["method_name"] = string(method->name()); + vars["input_type"] = JSMessageType(method->input_type()); + vars["output_type"] = JSMessageType(method->output_type()); + vars["serialize_func_name"] = GetSerializeMethodName(vars); +@@ -716,7 +721,7 @@ void PrintGrpcWebDtsClientClass(Printer* printer, const FileDescriptor* file, + ++service_index) { + printer->Print("export class "); + const ServiceDescriptor* service = file->service(service_index); +- vars["service_name"] = service->name(); ++ vars["service_name"] = string(service->name()); + printer->Print(vars, "$service_name$$client_type$ {\n"); + printer->Indent(); + printer->Print( +@@ -777,7 +782,7 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) { + + void PrintProtoDtsEnum(Printer* printer, const EnumDescriptor* desc) { + std::map vars; +- vars["enum_name"] = desc->name(); ++ vars["enum_name"] = string(desc->name()); + + // Use regular enums for broad TypeScript compatibility. `const enum` + // triggers TS2748 when `verbatimModuleSyntax` is enabled (default in +@@ -815,7 +820,7 @@ void PrintProtoDtsOneofCase(Printer* printer, const OneofDescriptor* desc) { + + void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc, + const FileDescriptor* file) { +- const string& class_name = desc->name(); ++ const string class_name(desc->name()); + std::map vars; + vars["class_name"] = class_name; + +@@ -941,7 +946,7 @@ void PrintProtoDtsFile(Printer* printer, const FileDescriptor* file) { + printer->Print("import * as jspb from 'google-protobuf'\n\n"); + + for (int i = 0; i < file->dependency_count(); i++) { +- const string& proto_filename = file->dependency(i)->name(); ++ const string proto_filename(file->dependency(i)->name()); + // We need to give each cross-file import an alias. + printer->Print("import * as $alias$ from '$dep_filename$_pb'; // proto import: \"$proto_filename$\"\n", + "alias", ModuleAlias(proto_filename), +@@ -1241,7 +1246,7 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, + // Print MethodDescriptor files. + for (int i = 0; i < file->service_count(); ++i) { + const ServiceDescriptor* service = file->service(i); +- vars["service_name"] = service->name(); ++ vars["service_name"] = string(service->name()); + vars["class_name"] = LowercaseFirstLetter(service->name()); + + for (int method_index = 0; method_index < service->method_count(); +@@ -1257,17 +1262,17 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, + context->Open(method_file_name)); + Printer printer(output.get(), '$'); + +- vars["method_name"] = method->name(); +- vars["in"] = method->input_type()->full_name(); +- vars["in_type"] = "proto." + method->input_type()->full_name(); +- vars["out"] = method->output_type()->full_name(); +- vars["out_type"] = "proto." + method->output_type()->full_name(); ++ vars["method_name"] = string(method->name()); ++ vars["in"] = string(method->input_type()->full_name()); ++ vars["in_type"] = "proto." + string(method->input_type()->full_name()); ++ vars["out"] = string(method->output_type()->full_name()); ++ vars["out_type"] = "proto." + string(method->output_type()->full_name()); + vars["method_type"] = method->server_streaming() + ? "grpc.web.MethodType.SERVER_STREAMING" + : "grpc.web.MethodType.UNARY"; + + PrintMethodDescriptorFile(&printer, vars); +- method_descriptors[service->name() + "." + method->name()] = ++ method_descriptors[string(service->name()) + "." + string(method->name())] = + "proto." + vars["package_dot"] + vars["class_name"] + "." + + vars["method_name"] + "MethodDescriptor"; + } +@@ -1286,7 +1291,7 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, + // Print the Promise and callback client. + for (int i = 0; i < file->service_count(); ++i) { + const ServiceDescriptor* service = file->service(i); +- vars["service_name"] = service->name(); ++ vars["service_name"] = string(service->name()); + printer1.Print(vars, + "goog.provide('proto.$package_dot$$service_name$" + "Client');\n\n"); +@@ -1326,7 +1331,7 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, + for (int service_index = 0; service_index < file->service_count(); + ++service_index) { + const ServiceDescriptor* service = file->service(service_index); +- vars["service_name"] = service->name(); ++ vars["service_name"] = string(service->name()); + PrintServiceConstructor(&printer1, vars, false); + PrintServiceConstructor(&printer2, vars, true); + +@@ -1336,13 +1341,13 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name, + const Descriptor* input_type = method->input_type(); + const Descriptor* output_type = method->output_type(); + vars["js_method_name"] = LowercaseFirstLetter(method->name()); +- vars["method_name"] = method->name(); +- vars["in"] = input_type->full_name(); +- vars["out"] = output_type->full_name(); ++ vars["method_name"] = string(method->name()); ++ vars["in"] = string(input_type->full_name()); ++ vars["out"] = string(output_type->full_name()); + vars["method_descriptor"] = +- method_descriptors[service->name() + "." + method->name()]; +- vars["in_type"] = "proto." + input_type->full_name(); +- vars["out_type"] = "proto." + output_type->full_name(); ++ method_descriptors[string(service->name()) + "." + string(method->name())]; ++ vars["in_type"] = "proto." + string(input_type->full_name()); ++ vars["out_type"] = "proto." + string(output_type->full_name()); + + // Client streaming is not supported yet + if (!method->client_streaming()) { +@@ -1369,14 +1374,14 @@ void PrintClosureES6Imports(Printer* printer, const FileDescriptor* file, + for (int i = 0; i < file->service_count(); ++i) { + const ServiceDescriptor* service = file->service(i); + +- string service_namespace = "proto." + package_dot + service->name(); ++ string service_namespace = "proto." + package_dot + string(service->name()); + printer->Print( + "import $service_name$Client_import from 'goog:$namespace$';\n", +- "service_name", service->name(), "namespace", ++ "service_name", string(service->name()), "namespace", + service_namespace + "Client"); + printer->Print( + "import $service_name$PromiseClient_import from 'goog:$namespace$';\n", +- "service_name", service->name(), "namespace", ++ "service_name", string(service->name()), "namespace", + service_namespace + "PromiseClient"); + } + +@@ -1384,7 +1389,7 @@ void PrintClosureES6Imports(Printer* printer, const FileDescriptor* file, + } + + void PrintGrpcWebClosureES6File(Printer* printer, const FileDescriptor* file) { +- string package_dot = file->package().empty() ? "" : file->package() + "."; ++ string package_dot = file->package().empty() ? "" : string(file->package()) + "."; + + printer->Print( + "/**\n" +@@ -1405,12 +1410,12 @@ void PrintGrpcWebClosureES6File(Printer* printer, const FileDescriptor* file) { + for (int i = 0; i < file->service_count(); ++i) { + const ServiceDescriptor* service = file->service(i); + +- string service_namespace = "proto." + package_dot + service->name(); ++ string service_namespace = "proto." + package_dot + string(service->name()); + printer->Print("export const $name$Client = $name$Client_import;\n", "name", +- service->name()); ++ string(service->name())); + printer->Print( + "export const $name$PromiseClient = $name$PromiseClient_import;\n", +- "name", service->name()); ++ "name", string(service->name())); + } + } + +@@ -1544,7 +1549,7 @@ class GrpcCodeGenerator : public CodeGenerator { + + std::map vars; + std::map method_descriptors; +- string package = file->package(); ++ string package(file->package()); + vars["package"] = package; + vars["package_dot"] = package.empty() ? "" : package + '.'; + vars["promise"] = "Promise"; +@@ -1585,9 +1590,9 @@ class GrpcCodeGenerator : public CodeGenerator { + + vars["version"] = GRPC_WEB_VERSION; + vars["protoc_version"] = GetProtocVersion(context); +- vars["source_file"] = file->name(); ++ vars["source_file"] = string(file->name()); + +- string file_name = generator_options.OutputFile(file->name()); ++ string file_name = generator_options.OutputFile(string(file->name())); + if (generator_options.multiple_files() && + ImportStyle::CLOSURE == generator_options.import_style()) { + PrintMultipleFilesMode(file, file_name, context, vars); +@@ -1605,7 +1610,7 @@ class GrpcCodeGenerator : public CodeGenerator { + + for (int i = 0; i < file->service_count(); ++i) { + const ServiceDescriptor* service = file->service(i); +- vars["service_name"] = service->name(); ++ vars["service_name"] = string(service->name()); + switch (generator_options.import_style()) { + case ImportStyle::CLOSURE: + printer.Print( +@@ -1652,7 +1657,7 @@ class GrpcCodeGenerator : public CodeGenerator { + for (int service_index = 0; service_index < file->service_count(); + ++service_index) { + const ServiceDescriptor* service = file->service(service_index); +- vars["service_name"] = service->name(); ++ vars["service_name"] = string(service->name()); + PrintServiceConstructor(&printer, vars, false); + PrintServiceConstructor(&printer, vars, true); + +@@ -1662,11 +1667,11 @@ class GrpcCodeGenerator : public CodeGenerator { + const Descriptor* input_type = method->input_type(); + const Descriptor* output_type = method->output_type(); + vars["js_method_name"] = LowercaseFirstLetter(method->name()); +- vars["method_name"] = method->name(); +- vars["in"] = input_type->full_name(); +- vars["out"] = output_type->full_name(); ++ vars["method_name"] = string(method->name()); ++ vars["in"] = string(input_type->full_name()); ++ vars["out"] = string(output_type->full_name()); + vars["method_descriptor"] = +- "methodDescriptor_" + service->name() + "_" + method->name(); ++ "methodDescriptor_" + string(service->name()) + "_" + string(method->name()); + + // Cross-file ref in CommonJS needs to use the module alias instead + // of the global name. +@@ -1675,14 +1680,14 @@ class GrpcCodeGenerator : public CodeGenerator { + vars["in_type"] = ModuleAlias(input_type->file()->name()) + + GetNestedMessageName(input_type); + } else { +- vars["in_type"] = "proto." + input_type->full_name(); ++ vars["in_type"] = "proto." + string(input_type->full_name()); + } + if (ImportStyle::COMMONJS == generator_options.import_style() && + output_type->file() != file) { + vars["out_type"] = ModuleAlias(output_type->file()->name()) + + GetNestedMessageName(output_type); + } else { +- vars["out_type"] = "proto." + output_type->full_name(); ++ vars["out_type"] = "proto." + string(output_type->full_name()); + } + + // Client streaming is not supported yet diff --git a/bazel/grpc_web.bzl b/bazel/grpc_web.bzl index 322e494a5fb..37b465064b5 100644 --- a/bazel/grpc_web.bzl +++ b/bazel/grpc_web.bzl @@ -189,7 +189,7 @@ pl_grpc_web_library = rule( cfg = "host", ), "_protoc_gen_grpc_web": attr.label( - default = Label("//third_party/protoc-gen-grpc-web:protoc-gen-grpc-web"), + default = Label("@com_github_grpc_grpcweb//javascript/net/grpc/web/generator:protoc-gen-grpc-web"), executable = True, cfg = "host", ), diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 9a5a7b21e77..0181203778f 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -259,6 +259,8 @@ def _pl_deps(): _bazel_repo("com_github_bazelbuild_buildtools") _bazel_repo("com_github_fmeum_rules_meta") _bazel_repo("com_google_protobuf_javascript", patches = ["//bazel/external:protobuf_javascript.patch"], patch_args = ["-p1"]) + # TODO(ddelnano): Remove patch once grpc-web upgrades to protobuf v30+. + _bazel_repo("com_github_grpc_grpcweb", patches = ["//bazel/external:grpc-web_protobuf_v30_support.patch"], patch_args = ["-p1"]) _com_llvm_lib() _cc_deps() diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 1cee298801f..9081cc0713f 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -110,6 +110,11 @@ REPOSITORY_LOCATIONS = dict( strip_prefix = "grpc-1.74.1", urls = ["https://github.com/grpc/grpc/archive/refs/tags/v1.74.1.tar.gz"], ), + com_github_grpc_grpcweb = dict( + sha256 = "0f0c8c0c1104306d67dad678be7c14efe52a698795a58b2b72ab67a8bb100c15", + strip_prefix = "grpc-web-2.0.2", + urls = ["https://github.com/grpc/grpc-web/archive/refs/tags/2.0.2.tar.gz"], + ), # August 19, 2020. com_github_google_sentencepiece = dict( sha256 = "1c0bd83e03f71a10fc934b7ce996e327488b838587f03159fd392c77c7701389", diff --git a/src/ui/package.json b/src/ui/package.json index 4b437f9c2c6..84cf4ca0322 100644 --- a/src/ui/package.json +++ b/src/ui/package.json @@ -103,7 +103,7 @@ "date-fns": "^2.29.3", "google-protobuf": "4.0.1", "graphql": "^15.5.0", - "grpc-web": "^1.0.7", + "grpc-web": "2.0.2", "history": "^4.10.1", "jose": "^4.9.3", "launchdarkly-react-client-sdk": "^2.20.0", diff --git a/src/ui/yarn.lock b/src/ui/yarn.lock index 58828e1601a..22e61e82bf9 100644 --- a/src/ui/yarn.lock +++ b/src/ui/yarn.lock @@ -2813,7 +2813,7 @@ __metadata: google-protobuf: 4.0.1 graphql: ^15.5.0 graphql-schema-typescript: ^1.5.2 - grpc-web: ^1.0.7 + grpc-web: 2.0.2 history: ^4.10.1 html-webpack-plugin: ^5.5.0 jest: ^27.3.1 @@ -8658,10 +8658,10 @@ __metadata: languageName: node linkType: hard -"grpc-web@npm:^1.0.7": - version: 1.2.1 - resolution: "grpc-web@npm:1.2.1" - checksum: 3860a3761793ccff10db513126957acf2794bcdb0fb82fc20fc4ffbc16e25b9742500d966acc88fbb258bf1d88ef7a4014189287bffbc79177560d7d83eadec1 +"grpc-web@npm:2.0.2": + version: 2.0.2 + resolution: "grpc-web@npm:2.0.2" + checksum: 3f587ca5d8da51ca126f2014259981ee4b2d18051449db8a03a2df572fa94c5304b0f5ac4d6ed371aa76d278e6cfe428e05b0c703e23aa0dfabfec2ce5ec5dbd languageName: node linkType: hard diff --git a/third_party/protoc-gen-grpc-web/BUILD.bazel b/third_party/protoc-gen-grpc-web/BUILD.bazel deleted file mode 100644 index 8e4d4644c63..00000000000 --- a/third_party/protoc-gen-grpc-web/BUILD.bazel +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2018- The Pixie Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# SPDX-License-Identifier: Apache-2.0 - -load("@rules_cc//cc:defs.bzl", "cc_binary") - -package(default_visibility = ["//visibility:public"]) - -cc_binary( - name = "protoc-gen-grpc-web", - srcs = ["grpc_generator.cc"], - deps = [ - "@com_google_protobuf//:protoc_lib", - ], -) diff --git a/third_party/protoc-gen-grpc-web/LICENSE b/third_party/protoc-gen-grpc-web/LICENSE deleted file mode 100644 index 458935fcf5a..00000000000 --- a/third_party/protoc-gen-grpc-web/LICENSE +++ /dev/null @@ -1,205 +0,0 @@ -########################################## -### This license only applies to this directory -########################################## - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/third_party/protoc-gen-grpc-web/README.md b/third_party/protoc-gen-grpc-web/README.md deleted file mode 100644 index e361f29549a..00000000000 --- a/third_party/protoc-gen-grpc-web/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Info -This file contains the protobuf generator. The source code is -located here: https://github.com/grpc/grpc-web - -When they finish their bazel toolchain port we can consider -just adding it as an external dependency. diff --git a/third_party/protoc-gen-grpc-web/grpc_generator.cc b/third_party/protoc-gen-grpc-web/grpc_generator.cc deleted file mode 100644 index 8136afeca1f..00000000000 --- a/third_party/protoc-gen-grpc-web/grpc_generator.cc +++ /dev/null @@ -1,1790 +0,0 @@ -/** - * - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -using google::protobuf::Descriptor; -using google::protobuf::Edition; -using google::protobuf::EnumDescriptor; -using google::protobuf::FieldDescriptor; -using google::protobuf::FileDescriptor; -using google::protobuf::MethodDescriptor; -using google::protobuf::ServiceDescriptor; -using google::protobuf::FieldOptions; -using google::protobuf::OneofDescriptor; -using google::protobuf::compiler::CodeGenerator; -using google::protobuf::compiler::GeneratorContext; -using google::protobuf::compiler::ParseGeneratorParameter; -using google::protobuf::compiler::PluginMain; -using google::protobuf::compiler::Version; -using google::protobuf::io::Printer; -using google::protobuf::io::ZeroCopyOutputStream; - -namespace grpc { -namespace web { -namespace { - -using std::string; - -enum Mode { - OP = 0, // first party google3 one platform services - GRPCWEB = 1, // client using the application/grpc-web wire format -}; - -enum ImportStyle { - CLOSURE = 0, // goog.require("grpc.web.*") - COMMONJS = 1, // const grpcWeb = require("grpc-web") - TYPESCRIPT = 2, // import * as grpcWeb from 'grpc-web' -}; - -const char GRPC_PROMISE[] = "grpc.web.promise.GrpcWebPromise"; - -const char* kKeyword[] = { - "abstract", "boolean", "break", "byte", "case", - "catch", "char", "class", "const", "continue", - "debugger", "default", "delete", "do", "double", - "else", "enum", "export", "extends", "false", - "final", "finally", "float", "for", "function", - "goto", "if", "implements", "import", "in", - "instanceof", "int", "interface", "long", "native", - "new", "null", "package", "private", "protected", - "public", "return", "short", "static", "super", - "switch", "synchronized", "this", "throw", "throws", - "transient", "try", "typeof", "var", "void", - "volatile", "while", "with", -}; - -// Edit the version here prior to release -static const std::string GRPC_WEB_VERSION = "2.0.2"; - -string GetProtocVersion(GeneratorContext* context) { - Version compiler_version; - context->GetCompilerVersion(&compiler_version); - return std::to_string(compiler_version.major()) + "." + - std::to_string(compiler_version.minor()) + "." + - std::to_string(compiler_version.patch()) + - compiler_version.suffix(); -} - -bool IsReserved(const string& ident) { - for (size_t i = 0; i < sizeof(kKeyword) / sizeof(kKeyword[0]); i++) { - if (ident == kKeyword[i]) { - return true; - } - } - return false; -} - -string GetModeVar(const Mode mode) { - switch (mode) { - case OP: - return "OP"; - case GRPCWEB: - return "GrpcWeb"; - } - return ""; -} - -string GetDeserializeMethodName(std::map vars) { - if (vars["mode"] == GetModeVar(Mode::OP) && vars["binary"] == "false") { - return "deserialize"; - } - return "deserializeBinary"; -} - -string GetSerializeMethodName(std::map vars) { - if (vars["mode"] == GetModeVar(Mode::OP) && vars["binary"] == "false") { - return "serialize"; - } - return "serializeBinary"; -} - -std::string GetSerializeMethodReturnType(std::map vars) { - if (vars["mode"] == GetModeVar(Mode::OP) && vars["binary"] == "false") { - return "string"; - } - return "!Uint8Array"; -} - -string LowercaseFirstLetter(std::string_view sv) { - string s(sv); - if (s.empty()) { - return s; - } - s[0] = ::tolower(s[0]); - return s; -} - -string Lowercase(std::string_view sv) { - string s(sv); - if (s.empty()) { - return s; - } - - for (size_t i = 0; i < s.size(); i++) { - s[i] = ::tolower(s[i]); - } - return s; -} - -string UppercaseFirstLetter(std::string_view sv) { - string s(sv); - if (s.empty()) { - return s; - } - s[0] = ::toupper(s[0]); - return s; -} - -string Uppercase(std::string_view sv) { - string s(sv); - if (s.empty()) { - return s; - } - - for (size_t i = 0; i < s.size(); i++) { - s[i] = ::toupper(s[i]); - } - return s; -} - -// The following 5 functions were copied from -// google/protobuf/src/google/protobuf/stubs/strutil.h - -inline bool HasPrefixString(std::string_view str, std::string_view prefix) { - return str.size() >= prefix.size() && - str.compare(0, prefix.size(), prefix) == 0; -} - -// Strips the given prefix from the string, as well as the remaining leading dot -// if it exists. -inline string StripPrefixString(std::string_view str, std::string_view prefix) { - if (!HasPrefixString(str, prefix)) { - return string(str); - } - - string remaining_str(str.substr(prefix.size())); - if (!remaining_str.empty() && remaining_str[0] == '.') { - remaining_str = remaining_str.substr(1); - } - return remaining_str; -} - -inline bool HasSuffixString(std::string_view str, std::string_view suffix) { - return str.size() >= suffix.size() && - str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; -} - -inline string StripSuffixString(std::string_view str, std::string_view suffix) { - if (HasSuffixString(str, suffix)) { - return string(str.substr(0, str.size() - suffix.size())); - } else { - return string(str); - } -} - -void ReplaceCharacters(string* s, const char* remove, char replacewith) { - const char* str_start = s->c_str(); - const char* str = str_start; - for (str = strpbrk(str, remove); str != nullptr; - str = strpbrk(str + 1, remove)) { - (*s)[str - str_start] = replacewith; - } -} - -// The following function was copied from -// google/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc - -string StripProto(std::string_view filename) { - if (HasSuffixString(filename, ".protodevel")) { - return StripSuffixString(filename, ".protodevel"); - } else { - return StripSuffixString(filename, ".proto"); - } -} - -// The following 6 functions were copied from -// google/protobuf/src/google/protobuf/compiler/js/js_generator.cc - -char ToLowerASCII(char c) { - if (c >= 'A' && c <= 'Z') { - return (c - 'A') + 'a'; - } else { - return c; - } -} - -std::vector ParseLowerUnderscore(std::string_view input) { - std::vector words; - string running = ""; - for (size_t i = 0; i < input.size(); i++) { - if (input[i] == '_') { - if (!running.empty()) { - words.push_back(running); - running.clear(); - } - } else { - running += ToLowerASCII(input[i]); - } - } - if (!running.empty()) { - words.push_back(running); - } - return words; -} - -string ToUpperCamel(const std::vector& words) { - string result; - for (size_t i = 0; i < words.size(); i++) { - string word = words[i]; - if (word[0] >= 'a' && word[0] <= 'z') { - word[0] = (word[0] - 'a') + 'A'; - } - result += word; - } - return result; -} - -// Returns the alias we assign to the module of the given .proto filename -// when importing. -string ModuleAlias(std::string_view filename) { - // This scheme could technically cause problems if a file includes any 2 of: - // foo/bar_baz.proto - // foo_bar_baz.proto - // foo_bar/baz.proto - // - // We'll worry about this problem if/when we actually see it. This name isn't - // exposed to users so we can change it later if we need to. - string basename = StripProto(filename); - ReplaceCharacters(&basename, "-", '$'); - ReplaceCharacters(&basename, "/", '_'); - ReplaceCharacters(&basename, ".", '_'); - return basename + "_pb"; -} - -string JSMessageType(const Descriptor* desc, const FileDescriptor* file) { - string class_name = StripPrefixString(desc->full_name(), desc->file()->package()); - if (desc->file() == file) { - // [for protobuf .d.ts files only] Do not add the module prefix for local - // messages. - return class_name; - } - return ModuleAlias(desc->file()->name()) + "." + class_name; -} - -string JSMessageType(const Descriptor* desc) { - return JSMessageType(desc, nullptr); -} - -string JSElementType(const FieldDescriptor* desc, const FileDescriptor* file) { - switch (desc->type()) { - case FieldDescriptor::TYPE_DOUBLE: - case FieldDescriptor::TYPE_FLOAT: - case FieldDescriptor::TYPE_INT32: - case FieldDescriptor::TYPE_UINT32: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_FIXED32: - case FieldDescriptor::TYPE_SFIXED32: - return "number"; - - case FieldDescriptor::TYPE_INT64: - case FieldDescriptor::TYPE_UINT64: - case FieldDescriptor::TYPE_SINT64: - case FieldDescriptor::TYPE_FIXED64: - case FieldDescriptor::TYPE_SFIXED64: - if (desc->options().jstype() == FieldOptions::JS_STRING) { - return "string"; - } else { - return "number"; - } - - case FieldDescriptor::TYPE_BOOL: - return "boolean"; - - case FieldDescriptor::TYPE_STRING: - return "string"; - - case FieldDescriptor::TYPE_BYTES: - return "Uint8Array | string"; - - case FieldDescriptor::TYPE_ENUM: - if (desc->enum_type()->file() == file) { - // [for protobuf .d.ts files only] Do not add the module prefix for - // local messages. - return StripPrefixString(desc->enum_type()->full_name(), - desc->enum_type()->file()->package()); - } - return ModuleAlias(desc->enum_type()->file()->name()) + "." + - StripPrefixString(desc->enum_type()->full_name(), - desc->enum_type()->file()->package()); - - case FieldDescriptor::TYPE_MESSAGE: - return JSMessageType(desc->message_type(), file); - - default: - return "{}"; - } -} - -string JSFieldType(const FieldDescriptor* desc, const FileDescriptor* file) { - string js_field_type = JSElementType(desc, file); - if (desc->is_map()) { - string key_type = JSFieldType(desc->message_type()->field(0), file); - string value_type = JSFieldType(desc->message_type()->field(1), file); - return "jspb.Map<" + key_type + ", " + value_type + ">"; - } - if (desc->is_repeated()) { - return "Array<" + js_field_type + ">"; - } - return js_field_type; -} - -string AsObjectFieldType(const FieldDescriptor* desc, - const FileDescriptor* file) { - if (desc->type() != FieldDescriptor::TYPE_MESSAGE) { - return JSFieldType(desc, file); - } - if (desc->is_map()) { - const Descriptor* message = desc->message_type(); - string key_type = AsObjectFieldType(message->field(0), file); - string value_type = AsObjectFieldType(message->field(1), file); - return "Array<[" + key_type + ", " + value_type + "]>"; - } - string field_type = JSMessageType(desc->message_type(), file) + ".AsObject"; - if (desc->is_repeated()) { - return "Array<" + field_type + ">"; - } - return field_type; -} - -string JSElementName(const FieldDescriptor* desc) { - return ToUpperCamel(ParseLowerUnderscore(desc->name())); -} - -string JSFieldName(const FieldDescriptor* desc) { - string js_field_name = JSElementName(desc); - if (desc->is_map()) { - js_field_name += "Map"; - } else if (desc->is_repeated()) { - js_field_name += "List"; - } - return js_field_name; -} - -// Like ToUpperCamel except the first letter is not converted. -string ToCamelCase(const std::vector& words) { - if (words.empty()) { - return ""; - } - string result = words[0]; - return result + ToUpperCamel(std::vector( - words.begin() + 1, words.begin() + words.size())); -} - -// Like JSFieldName, but with first letter not uppercased -string CamelCaseJSFieldName(const FieldDescriptor* desc) { - string js_field_name = ToCamelCase(ParseLowerUnderscore(desc->name())); - if (desc->is_map()) { - js_field_name += "Map"; - } else if (desc->is_repeated()) { - js_field_name += "List"; - } - return js_field_name; -} - -// Returns the name of the message with a leading dot and taking into account -// nesting, for example ".OuterMessage.InnerMessage", or returns empty if -// descriptor is null. This function does not handle namespacing, only message -// nesting. -string GetNestedMessageName(const Descriptor* descriptor) { - if (descriptor == nullptr) { - return ""; - } - string result = - StripPrefixString(descriptor->full_name(), descriptor->file()->package()); - // Add a leading dot if one is not already present. - if (!result.empty() && result[0] != '.') { - result = "." + result; - } - return result; -} - -// Given a filename like foo/bar/baz.proto, returns the root directory -// path ../../ -string GetRootPath(std::string_view from_filename, std::string_view to_filename) { - if (HasPrefixString(to_filename, "google/protobuf")) { - // Well-known types (.proto files in the google/protobuf directory) are - // assumed to come from the 'google-protobuf' npm package. We may want to - // generalize this exception later by letting others put generated code in - // their own npm packages. - return "google-protobuf/"; - } - - size_t slashes = std::count(from_filename.begin(), from_filename.end(), '/'); - if (slashes == 0) { - return "./"; - } - string result = ""; - for (size_t i = 0; i < slashes; i++) { - result += "../"; - } - return result; -} - -// Splits path immediately following the final slash, separating it into a -// directory and file name component. Directory will contain the last -// slash, if it's not empty. -// If there is no slash in path, Split returns an empty directory and -// basename set to path. -// Output values have the property that path = directory + basename. -void PathSplit(const string& path, string* directory, string* basename) { - string::size_type last_slash = path.rfind('/'); - if (last_slash == string::npos) { - if (directory) { - *directory = ""; - } - if (basename) { - *basename = path; - } - } else { - if (directory) { - *directory = path.substr(0, last_slash + 1); - } - if (basename) { - *basename = path.substr(last_slash + 1); - } - } -} - -// Returns the basename of a file. -string GetBasename(string filename) { - string basename; - PathSplit(filename, nullptr, &basename); - return basename; -} - -//Adds $ suffix to reserved method names to avoid conflicts. -static bool IsReservedMethodName(const std::string& name) { - static const std::unordered_set reserved = { - "extension", - "jspbmessageid" - }; - - std::string lower_name = Lowercase(name); - - return reserved.count(lower_name) > 0; -} - -static std::string SafeAccessorName(const std::string& name) { - std::string result = name; - if (IsReservedMethodName(name)) { - result += "$"; - } - return result; -} - -// Finds all message types used in all services in the file. Return results as a -// map of full names to descriptors to get sorted results and deterministic -// build outputs. -std::map GetAllMessages(const FileDescriptor* file) { - std::map messages; - for (int s = 0; s < file->service_count(); ++s) { - const ServiceDescriptor* service = file->service(s); - for (int m = 0; m < service->method_count(); ++m) { - const MethodDescriptor* method = service->method(m); - messages[string(method->input_type()->full_name())] = method->input_type(); - messages[string(method->output_type()->full_name())] = method->output_type(); - } - } - - return messages; -} - -void PrintClosureDependencies(Printer* printer, const FileDescriptor* file) { - for (const auto& entry : GetAllMessages(file)) { - printer->Print("goog.require('proto.$full_name$');\n", "full_name", - entry.second->full_name()); - } -} - -void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) { - std::map vars; - - for (int i = 0; i < file->dependency_count(); i++) { - const string name(file->dependency(i)->name()); - vars["alias"] = ModuleAlias(name); - vars["dep_filename"] = GetRootPath(file->name(), name) + StripProto(name); - // we need to give each cross-file import an alias - printer->Print(vars, "\nvar $alias$ = require('$dep_filename$_pb.js')\n"); - } - - const string package(file->package()); - vars["package_name"] = package; - - if (!package.empty()) { - size_t offset = 0; - size_t dotIndex = package.find('.'); - - printer->Print(vars, "const proto = {};\n"); - - while (dotIndex != string::npos) { - vars["current_package_ns"] = package.substr(0, dotIndex); - printer->Print(vars, "proto.$current_package_ns$ = {};\n"); - - offset = dotIndex + 1; - dotIndex = package.find('.', offset); - } - } - - // need to import the messages from our own file - vars["filename"] = GetBasename(StripProto(file->name())); - - if (!package.empty()) { - printer->Print(vars, - "proto.$package_name$ = require('./$filename$_pb.js');\n\n"); - } else { - printer->Print(vars, "const proto = require('./$filename$_pb.js');\n\n"); - } -} - -void PrintES6Imports(Printer* printer, const FileDescriptor* file) { - std::map vars; - - printer->Print("import * as grpcWeb from 'grpc-web';\n\n"); - - std::set imports; - for (const auto& entry : GetAllMessages(file)) { - const string proto_filename(entry.second->file()->name()); - string dep_filename = GetRootPath(file->name(), proto_filename) + StripProto(proto_filename); - if (imports.find(dep_filename) != imports.end()) { - continue; - } - imports.insert(dep_filename); - // We need to give each cross-file import an alias. - printer->Print("import * as $alias$ from '$dep_filename$_pb'; // proto import: \"$proto_filename$\"\n", - "alias", ModuleAlias(proto_filename), - "dep_filename", dep_filename, - "proto_filename", proto_filename); - } - printer->Print("\n\n"); -} - -void PrintTypescriptFile(Printer* printer, const FileDescriptor* file, - std::map vars) { - PrintES6Imports(printer, file); - for (int service_index = 0; service_index < file->service_count(); - ++service_index) { - printer->Print("export class "); - const ServiceDescriptor* service = file->service(service_index); - vars["service_name"] = string(service->name()); - printer->Print(vars, "$service_name$Client {\n"); - printer->Indent(); - printer->Print( - "client_: grpcWeb.AbstractClientBase;\n" - "hostname_: string;\n" - "credentials_: null | { [index: string]: string; };\n" - "options_: null | { [index: string]: any; };\n\n" - "constructor (hostname: string,\n" - " credentials?: null | { [index: string]: string; },\n" - " options?: null | { [index: string]: any; }) {\n"); - printer->Indent(); - printer->Print("if (!options) options = {};\n"); - printer->Print("if (!credentials) credentials = {};\n"); - if (vars["mode"] == GetModeVar(Mode::GRPCWEB)) { - printer->Print(vars, "options['format'] = '$format$';\n\n"); - } - printer->Print(vars, - "this.client_ = new grpcWeb.$mode$ClientBase(options);\n" - "this.hostname_ = hostname.replace(/\\/+$$/, '');\n" - "this.credentials_ = credentials;\n" - "this.options_ = options;\n"); - printer->Outdent(); - printer->Print("}\n\n"); - - for (int method_index = 0; method_index < service->method_count(); - ++method_index) { - const MethodDescriptor* method = service->method(method_index); - vars["js_method_name"] = LowercaseFirstLetter(method->name()); - vars["method_name"] = string(method->name()); - vars["input_type"] = JSMessageType(method->input_type()); - vars["output_type"] = JSMessageType(method->output_type()); - vars["serialize_func_name"] = GetSerializeMethodName(vars); - vars["deserialize_func_name"] = GetDeserializeMethodName(vars); - vars["method_type"] = method->server_streaming() - ? "grpcWeb.MethodType.SERVER_STREAMING" - : "grpcWeb.MethodType.UNARY"; - if (!method->client_streaming()) { - printer->Print(vars, - "methodDescriptor$method_name$ = " - "new grpcWeb.MethodDescriptor(\n"); - printer->Indent(); - printer->Print(vars, - "'/$package_dot$$service_name$/$method_name$',\n" - "$method_type$,\n" - "$input_type$,\n" - "$output_type$,\n" - "(request: $input_type$) => {\n" - " return request.$serialize_func_name$();\n" - "},\n" - "$output_type$.$deserialize_func_name$\n"); - printer->Outdent(); - printer->Print(");\n\n"); - if (method->server_streaming()) { - printer->Print(vars, "$js_method_name$(\n"); - printer->Indent(); - printer->Print(vars, - "request: $input_type$,\n" - "metadata?: grpcWeb.Metadata): " - "grpcWeb.ClientReadableStream<$output_type$> {\n"); - printer->Print(vars, "return this.client_.serverStreaming(\n"); - printer->Indent(); - printer->Print(vars, - "this.hostname_ +\n" - " '/$package_dot$$service_name$/$method_name$',\n" - "request,\n" - "metadata || {},\n" - "this.methodDescriptor$method_name$);\n"); - printer->Outdent(); - 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.RpcError,\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.RpcError,\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, - "this.hostname_ +\n" - " '/$package_dot$$service_name$/$method_name$',\n" - "request,\n" - "metadata || {},\n" - "this.methodDescriptor$method_name$,\n" - "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.methodDescriptor$method_name$);\n"); - printer->Outdent(); - printer->Print("}\n\n"); - } - } - } - printer->Outdent(); - printer->Print("}\n\n"); - } -} - -void PrintGrpcWebDtsClientClass(Printer* printer, const FileDescriptor* file, - const string& client_type) { - std::map vars; - vars["client_type"] = client_type; - vars["promise"] = "Promise"; - for (int service_index = 0; service_index < file->service_count(); - ++service_index) { - printer->Print("export class "); - const ServiceDescriptor* service = file->service(service_index); - vars["service_name"] = string(service->name()); - printer->Print(vars, "$service_name$$client_type$ {\n"); - printer->Indent(); - printer->Print( - "constructor (hostname: string,\n" - " credentials?: null | { [index: string]: string; },\n" - " options?: null | { [index: string]: any; });\n\n"); - for (int method_index = 0; method_index < service->method_count(); - ++method_index) { - const MethodDescriptor* method = service->method(method_index); - vars["js_method_name"] = LowercaseFirstLetter(method->name()); - vars["input_type"] = JSMessageType(method->input_type()); - vars["output_type"] = JSMessageType(method->output_type()); - if (!method->client_streaming()) { - if (method->server_streaming()) { - printer->Print(vars, "$js_method_name$(\n"); - printer->Indent(); - printer->Print(vars, - "request: $input_type$,\n" - "metadata?: grpcWeb.Metadata\n"); - printer->Outdent(); - printer->Print(vars, - "): grpcWeb.ClientReadableStream<$output_type$>;\n\n"); - } else { - if (vars["client_type"] == "PromiseClient") { - printer->Print(vars, "$js_method_name$(\n"); - printer->Indent(); - printer->Print(vars, - "request: $input_type$,\n" - "metadata?: grpcWeb.Metadata\n"); - printer->Outdent(); - printer->Print(vars, "): $promise$<$output_type$>;\n\n"); - } else { - printer->Print(vars, "$js_method_name$(\n"); - printer->Indent(); - printer->Print(vars, - "request: $input_type$,\n" - "metadata: grpcWeb.Metadata | undefined,\n" - "callback: (err: grpcWeb.RpcError,\n" - " response: $output_type$) => void\n"); - printer->Outdent(); - printer->Print(vars, - "): grpcWeb.ClientReadableStream<$output_type$>;"); - printer->Print("\n\n"); - } - } - } - } - printer->Outdent(); - printer->Print("}\n\n"); - } -} - -void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) { - PrintES6Imports(printer, file); - PrintGrpcWebDtsClientClass(printer, file, "Client"); - PrintGrpcWebDtsClientClass(printer, file, "PromiseClient"); -} - -void PrintProtoDtsEnum(Printer* printer, const EnumDescriptor* desc) { - std::map vars; - vars["enum_name"] = string(desc->name()); - - // Use regular enums for broad TypeScript compatibility. `const enum` - // triggers TS2748 when `verbatimModuleSyntax` is enabled (default in - // TypeScript 5.9+), so prefer `enum` here. - printer->Print(vars, "export enum $enum_name$ {\n"); - printer->Indent(); - for (int i = 0; i < desc->value_count(); i++) { - vars["value_name"] = Uppercase(desc->value(i)->name()); - vars["value_number"] = std::to_string(desc->value(i)->number()); - printer->Print(vars, "$value_name$ = $value_number$,\n"); - } - printer->Outdent(); - printer->Print("}\n"); -} - -void PrintProtoDtsOneofCase(Printer* printer, const OneofDescriptor* desc) { - std::map vars; - vars["oneof_name"] = ToUpperCamel(ParseLowerUnderscore(desc->name())); - vars["oneof_name_upper"] = Uppercase(desc->name()); - - // Oneof case enums also use regular enums to avoid ambient `const enum` - // issues under `verbatimModuleSyntax`. - printer->Print(vars, "export enum $oneof_name$Case {\n"); - printer->Indent(); - printer->Print(vars, "$oneof_name_upper$_NOT_SET = 0,\n"); - for (int i = 0; i < desc->field_count(); i++) { - const FieldDescriptor* field = desc->field(i); - vars["field_name"] = Uppercase(field->name()); - vars["field_number"] = std::to_string(field->number()); - printer->Print(vars, "$field_name$ = $field_number$,\n"); - } - printer->Outdent(); - printer->Print("}\n"); -} - -void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc, - const FileDescriptor* file) { - const string class_name(desc->name()); - std::map vars; - vars["class_name"] = class_name; - - printer->Print(vars, "export class $class_name$ extends jspb.Message {\n"); - printer->Indent(); - for (int i = 0; i < desc->field_count(); i++) { - const FieldDescriptor* field = desc->field(i); - - vars["js_field_name"] = SafeAccessorName(JSFieldName(field)); - vars["js_field_type"] = JSFieldType(field, file); - if (field->type() != FieldDescriptor::TYPE_MESSAGE || - field->is_repeated()) { - printer->Print(vars, "get$js_field_name$(): $js_field_type$;\n"); - } else { - printer->Print(vars, - "get$js_field_name$(): $js_field_type$ | undefined;\n"); - } - if (field->type() == FieldDescriptor::TYPE_BYTES && !field->is_repeated()) { - printer->Print(vars, - "get$js_field_name$_asU8(): Uint8Array;\n" - "get$js_field_name$_asB64(): string;\n"); - } - if (!field->is_map() && (field->type() != FieldDescriptor::TYPE_MESSAGE || - field->is_repeated())) { - printer->Print(vars, - "set$js_field_name$(value: $js_field_type$): " - "$class_name$;\n"); - } else if (!field->is_map()) { - printer->Print(vars, - "set$js_field_name$(value?: $js_field_type$): " - "$class_name$;\n"); - } - if (field->has_presence()) { - printer->Print(vars, "has$js_field_name$(): boolean;\n"); - } - if (field->type() == FieldDescriptor::TYPE_MESSAGE || - field->has_presence() || field->is_repeated() || field->is_map()) { - printer->Print(vars, "clear$js_field_name$(): $class_name$;\n"); - } - if (field->is_repeated() && !field->is_map()) { - - vars["js_field_name"] = SafeAccessorName(JSElementName(field)); - vars["js_field_type"] = JSElementType(field, file); - if (field->type() != FieldDescriptor::TYPE_MESSAGE) { - printer->Print(vars, - "add$js_field_name$(value: $js_field_type$, " - "index?: number): $class_name$;\n"); - } else { - printer->Print(vars, - "add$js_field_name$(value?: $js_field_type$, " - "index?: number): $js_field_type$;\n"); - } - } - - printer->Print("\n"); - } - - for (int i = 0; i < desc->real_oneof_decl_count(); i++) { - const OneofDescriptor *oneof = desc->real_oneof_decl(i); - vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name())); - printer->Print( - vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n"); - printer->Print("\n"); - } - - printer->Print( - vars, - "serializeBinary(): Uint8Array;\n" - "toObject(includeInstance?: boolean): " - "$class_name$.AsObject;\n" - "static toObject(includeInstance: boolean, msg: $class_name$): " - "$class_name$.AsObject;\n" - "static serializeBinaryToWriter(message: $class_name$, writer: " - "jspb.BinaryWriter): void;\n" - "static deserializeBinary(bytes: Uint8Array): $class_name$;\n" - "static deserializeBinaryFromReader(message: $class_name$, reader: " - "jspb.BinaryReader): $class_name$;\n"); - printer->Outdent(); - printer->Print("}\n\n"); - - printer->Print(vars, "export namespace $class_name$ {\n"); - printer->Indent(); - printer->Print("export type AsObject = {\n"); - printer->Indent(); - for (int i = 0; i < desc->field_count(); i++) { - const FieldDescriptor* field = desc->field(i); - - string js_field_name = CamelCaseJSFieldName(field); - if (IsReserved(js_field_name)) { - js_field_name = "pb_" + js_field_name; - } - - vars["js_field_name"] = js_field_name; - vars["js_field_type"] = AsObjectFieldType(field, file); - if (!field->has_presence()) { - printer->Print(vars, "$js_field_name$: $js_field_type$;\n"); - } else { - printer->Print(vars, "$js_field_name$?: $js_field_type$;\n"); - } - } - printer->Outdent(); - printer->Print("};\n"); - - for (int i = 0; i < desc->nested_type_count(); i++) { - if (desc->nested_type(i)->options().map_entry()) { - continue; - } - printer->Print("\n"); - PrintProtoDtsMessage(printer, desc->nested_type(i), file); - } - - for (int i = 0; i < desc->enum_type_count(); i++) { - printer->Print("\n"); - PrintProtoDtsEnum(printer, desc->enum_type(i)); - } - - for (int i = 0; i < desc->oneof_decl_count(); i++) { - printer->Print("\n"); - PrintProtoDtsOneofCase(printer, desc->oneof_decl(i)); - } - - printer->Outdent(); - printer->Print("}\n\n"); -} - -void PrintProtoDtsFile(Printer* printer, const FileDescriptor* file) { - printer->Print("import * as jspb from 'google-protobuf'\n\n"); - - for (int i = 0; i < file->dependency_count(); i++) { - const string proto_filename(file->dependency(i)->name()); - // We need to give each cross-file import an alias. - printer->Print("import * as $alias$ from '$dep_filename$_pb'; // proto import: \"$proto_filename$\"\n", - "alias", ModuleAlias(proto_filename), - "dep_filename", GetRootPath(file->name(), proto_filename) + StripProto(proto_filename), - "proto_filename", proto_filename); - } - printer->Print("\n\n"); - - for (int i = 0; i < file->message_type_count(); i++) { - PrintProtoDtsMessage(printer, file->message_type(i), file); - } - - for (int i = 0; i < file->enum_type_count(); i++) { - PrintProtoDtsEnum(printer, file->enum_type(i)); - } -} - -void PrintFileHeader(Printer* printer, const std::map& vars) { - printer->Print( - vars, - "/**\n" - " * @fileoverview gRPC-Web generated client stub for $package$\n" - " * @enhanceable\n" - " * @public\n" - " */\n\n" - "// Code generated by protoc-gen-grpc-web. DO NOT EDIT.\n" - "// versions:\n" - "// \tprotoc-gen-grpc-web v$version$\n" - "// \tprotoc v$protoc_version$\n" - "// source: $source_file$\n\n\n" - "/* eslint-disable */\n" - "// @ts-nocheck\n\n\n"); -} - -void PrintMethodDescriptorFile(Printer* printer, - std::map vars) { - printer->Print( - vars, - "/**\n" - " * @fileoverview gRPC-Web generated MethodDescriptors for $package$\n"); - if (vars["plugins"].empty()) { - printer->Print(" * @enhanceable\n"); - } - printer->Print( - " * @public\n" - " */\n\n" - "// Code generated by protoc-gen-grpc-web. DO NOT EDIT.\n" - "// versions:\n" - "// \tprotoc-gen-grpc-web v$version$\n" - "// \tprotoc v$protoc_version$\n" - "// source: $source_file$\n\n\n" - "/* eslint-disable */\n" - "// @ts-nocheck\n\n\n"); - - printer->Print(vars, - "goog.provide('proto.$package_dot$$class_name$.$" - "method_name$MethodDescriptor');\n\n"); - if (!vars["plugins"].empty()) { - printer->Print(vars, - "goog.require('$plugins$.$package_dot$$class_name$.$" - "method_name$MethodDescriptor');\n"); - } - printer->Print(vars, "goog.require('grpc.web.MethodDescriptor');\n"); - printer->Print(vars, "goog.require('grpc.web.MethodType');\n"); - printer->Print(vars, "goog.require('$in_type$');\n"); - if (vars["out_type"] != vars["in_type"]) { - printer->Print(vars, "goog.require('$out_type$');\n"); - } - printer->Print(vars, "\n\ngoog.scope(function() {\n\n"); - - printer->Print( - vars, - "/**\n" - " * @const\n" - " * @type {!grpc.web.MethodDescriptor<\n" - " * !proto.$in$,\n" - " * !proto.$out$>}\n" - " */\n" - "proto.$package_dot$$class_name$.$method_name$MethodDescriptor = \n"); - printer->Indent(); - printer->Indent(); - printer->Print(vars, "new grpc.web.MethodDescriptor(\n"); - printer->Indent(); - printer->Indent(); - printer->Print(vars, - "'/$package_dot$$service_name$/$method_name$',\n" - "$method_type$,\n" - "$in_type$,\n"); - printer->Print(vars, - "$out_type$,\n" - "/**\n" - " * @param {!proto.$in$} request\n"); - printer->Print( - (" * @return {" + GetSerializeMethodReturnType(vars) + "}\n").c_str()); - printer->Print( - " */\n" - "function(request) {\n"); - printer->Print( - (" return request." + GetSerializeMethodName(vars) + "();\n").c_str()); - printer->Print("},\n"); - printer->Print(vars, - ("$out_type$." + GetDeserializeMethodName(vars)).c_str()); - printer->Print(vars, ");\n\n\n"); - printer->Outdent(); - printer->Outdent(); - printer->Outdent(); - printer->Outdent(); - printer->Print("}); // goog.scope\n\n"); -} - -void PrintServiceConstructor(Printer* printer, std::map vars, - bool is_promise) { - vars["is_promise"] = is_promise ? "Promise" : ""; - printer->Print(vars, - "/**\n" - " * @param {string} hostname\n" - " * @param {?Object} credentials\n" - " * @param {?grpc.web.ClientOptions} options\n" - " * @constructor\n" - " * @struct\n" - " * @final\n" - " */\n" - "proto.$package_dot$$service_name$$is_promise$Client =\n" - " function(hostname, credentials, options) {\n" - " if (!options) options = {};\n"); - if (vars["mode"] == GetModeVar(Mode::GRPCWEB)) { - printer->Print(vars, " options.format = '$format$';\n\n"); - } - if (vars["mode"] == GetModeVar(Mode::OP)) { - printer->Print( - vars, - " /**\n" - " * @private @const {!grpc.web.$mode$ClientBase} The client\n" - " */\n" - " this.client_ = new grpc.web.$mode$ClientBase(options, " - "$binary$);\n\n"); - } else { - printer->Print( - vars, - " /**\n" - " * @private @const {!grpc.web.$mode$ClientBase} The client\n" - " */\n" - " this.client_ = new grpc.web.$mode$ClientBase(options);\n\n"); - } - printer->PrintRaw( - " /**\n" - " * @private @const {string} The hostname\n" - " */\n" - " this.hostname_ = hostname.replace(/\\/+$/, '');\n\n" - "};\n\n\n"); -} - -void PrintMethodDescriptor(Printer* printer, std::map vars) { - printer->Print(vars, - "/**\n" - " * @const\n" - " * @type {!grpc.web.MethodDescriptor<\n" - " * !proto.$in$,\n" - " * !proto.$out$>}\n" - " */\n" - "const methodDescriptor_$service_name$_$method_name$ = " - "new grpc.web.MethodDescriptor(\n"); - printer->Indent(); - printer->Print(vars, - "'/$package_dot$$service_name$/$method_name$',\n" - "$method_type$,\n" - "$in_type$,\n"); - printer->Print(vars, - "$out_type$,\n" - "/**\n" - " * @param {!proto.$in$} request\n"); - printer->Print( - (" * @return {" + GetSerializeMethodReturnType(vars) + "}\n").c_str()); - printer->Print( - " */\n" - "function(request) {\n"); - printer->Print( - (" return request." + GetSerializeMethodName(vars) + "();\n").c_str()); - printer->Print("},\n"); - printer->Print( - vars, ("$out_type$." + GetDeserializeMethodName(vars) + "\n").c_str()); - printer->Outdent(); - printer->Print(vars, ");\n\n\n"); -} - -void PrintUnaryCall(Printer* printer, std::map vars) { - printer->Print( - vars, - "/**\n" - " * @param {!proto.$in$} request The\n" - " * request proto\n" - " * @param {?Object} metadata User defined\n" - " * call metadata\n" - " * @param {function(?grpc.web.RpcError," - " ?proto.$out$)}\n" - " * callback The callback function(error, response)\n" - " * @return {!grpc.web.ClientReadableStream|undefined}\n" - " * The XHR Node Readable Stream\n" - " */\n" - "proto.$package_dot$$service_name$Client.prototype.$js_method_name$ =\n"); - printer->Indent(); - printer->Print(vars, - " function(request, metadata, callback) {\n" - "return this.client_.rpcCall(this.hostname_ +\n"); - printer->Indent(); - printer->Indent(); - if (vars["mode"] == GetModeVar(Mode::OP)) { - printer->Print(vars, - "'/$$rpc/$package_dot$$service_name$/$method_name$',\n"); - } else { - printer->Print(vars, "'/$package_dot$$service_name$/$method_name$',\n"); - } - printer->Print(vars, - "request,\n" - "metadata || {},\n" - "$method_descriptor$,\n" - "callback);\n"); - printer->Outdent(); - printer->Outdent(); - printer->Outdent(); - printer->Print("};\n\n\n"); -} - -void PrintPromiseUnaryCall(Printer* printer, std::map vars) { - printer->Print(vars, - "/**\n" - " * @param {!proto.$in$} request The\n" - " * request proto\n" - " * @param {?Object=} metadata User defined\n" - " * call metadata\n" - " * @return {!$promise$}\n" - " * Promise that resolves to the response\n" - " */\n" - "proto.$package_dot$$service_name$PromiseClient.prototype" - ".$js_method_name$ =\n"); - printer->Indent(); - printer->Print(vars, - " function(request, metadata) {\n" - "return this.client_.unaryCall(this.hostname_ +\n"); - printer->Indent(); - printer->Indent(); - if (vars["mode"] == GetModeVar(Mode::OP)) { - printer->Print(vars, - "'/$$rpc/$package_dot$$service_name$/$method_name$',\n"); - } else { - printer->Print(vars, "'/$package_dot$$service_name$/$method_name$',\n"); - } - printer->Print(vars, - "request,\n" - "metadata || {},\n" - "$method_descriptor$);\n"); - printer->Outdent(); - printer->Outdent(); - printer->Outdent(); - printer->Print("};\n\n\n"); -} - -void PrintServerStreamingCall(Printer* printer, std::map vars) { - printer->Print(vars, - "/**\n" - " * @param {!proto.$in$} request The request proto\n" - " * @param {?Object=} metadata User defined\n" - " * call metadata\n" - " * @return {!grpc.web.ClientReadableStream}\n" - " * The XHR Node Readable Stream\n" - " */\n" - "proto.$package_dot$$service_name$$client_type$.prototype." - "$js_method_name$ =\n"); - printer->Indent(); - printer->Print( - " function(request, metadata) {\n" - "return this.client_.serverStreaming(this.hostname_ +\n"); - printer->Indent(); - printer->Indent(); - if (vars["mode"] == GetModeVar(Mode::OP)) { - printer->Print(vars, - "'/$$rpc/$package_dot$$service_name$/$method_name$',\n"); - } else { - printer->Print(vars, "'/$package_dot$$service_name$/$method_name$',\n"); - } - printer->Print(vars, - "request,\n" - "metadata || {},\n" - "$method_descriptor$);\n"); - printer->Outdent(); - printer->Outdent(); - printer->Outdent(); - printer->Print("};\n\n\n"); -} - -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) { - const ServiceDescriptor* service = file->service(i); - vars["service_name"] = string(service->name()); - vars["class_name"] = LowercaseFirstLetter(service->name()); - - for (int method_index = 0; method_index < service->method_count(); - ++method_index) { - const MethodDescriptor* method = service->method(method_index); - 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(), '$'); - - vars["method_name"] = string(method->name()); - vars["in"] = string(method->input_type()->full_name()); - vars["in_type"] = "proto." + string(method->input_type()->full_name()); - vars["out"] = string(method->output_type()->full_name()); - vars["out_type"] = "proto." + string(method->output_type()->full_name()); - vars["method_type"] = method->server_streaming() - ? "grpc.web.MethodType.SERVER_STREAMING" - : "grpc.web.MethodType.UNARY"; - - PrintMethodDescriptorFile(&printer, vars); - method_descriptors[string(service->name()) + "." + string(method->name())] = - "proto." + vars["package_dot"] + vars["class_name"] + "." + - vars["method_name"] + "MethodDescriptor"; - } - } - - std::unique_ptr output1( - context->Open(file_name + "_client_pb.js")); - Printer printer1(output1.get(), '$'); - std::unique_ptr output2( - context->Open(file_name + "_promise_client_pb.js")); - Printer printer2(output2.get(), '$'); - - PrintFileHeader(&printer1, vars); - PrintFileHeader(&printer2, vars); - - // Print the Promise and callback client. - for (int i = 0; i < file->service_count(); ++i) { - const ServiceDescriptor* service = file->service(i); - vars["service_name"] = string(service->name()); - printer1.Print(vars, - "goog.provide('proto.$package_dot$$service_name$" - "Client');\n\n"); - printer2.Print(vars, - "goog.provide('proto.$package_dot$$service_name$" - "PromiseClient');\n\n"); - } - - if (vars["promise"] == GRPC_PROMISE) { - printer2.Print(vars, "goog.require('grpc.web.promise');\n"); - } - std::map::iterator it; - for (it = method_descriptors.begin(); it != method_descriptors.end(); it++) { - vars["import_mtd"] = it->second; - printer1.Print(vars, "goog.require('$import_mtd$');\n"); - printer2.Print(vars, "goog.require('$import_mtd$');\n"); - } - printer1.Print(vars, "goog.require('grpc.web.$mode$ClientBase');\n"); - printer1.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); - printer1.Print(vars, "goog.require('grpc.web.RpcError');\n"); - printer2.Print(vars, "goog.require('grpc.web.$mode$ClientBase');\n"); - if (has_server_streaming) { - printer2.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); - } - - PrintClosureDependencies(&printer1, file); - PrintClosureDependencies(&printer2, file); - - printer1.Print(vars, "\ngoog.requireType('grpc.web.ClientOptions');\n"); - printer2.Print(vars, "\ngoog.requireType('grpc.web.ClientOptions');\n"); - - printer1.Print("\n\n\n"); - printer2.Print("\n\n\n"); - printer1.Print("goog.scope(function() {\n\n"); - printer2.Print("goog.scope(function() {\n\n"); - - for (int service_index = 0; service_index < file->service_count(); - ++service_index) { - const ServiceDescriptor* service = file->service(service_index); - vars["service_name"] = string(service->name()); - PrintServiceConstructor(&printer1, vars, false); - PrintServiceConstructor(&printer2, vars, true); - - for (int method_index = 0; method_index < service->method_count(); - ++method_index) { - const MethodDescriptor* method = service->method(method_index); - const Descriptor* input_type = method->input_type(); - const Descriptor* output_type = method->output_type(); - vars["js_method_name"] = LowercaseFirstLetter(method->name()); - vars["method_name"] = string(method->name()); - vars["in"] = string(input_type->full_name()); - vars["out"] = string(output_type->full_name()); - vars["method_descriptor"] = - method_descriptors[string(service->name()) + "." + string(method->name())]; - vars["in_type"] = "proto." + string(input_type->full_name()); - vars["out_type"] = "proto." + string(output_type->full_name()); - - // Client streaming is not supported yet - if (!method->client_streaming()) { - if (method->server_streaming()) { - vars["method_type"] = "grpc.web.MethodType.SERVER_STREAMING"; - vars["client_type"] = "Client"; - PrintServerStreamingCall(&printer1, vars); - vars["client_type"] = "PromiseClient"; - PrintServerStreamingCall(&printer2, vars); - } else { - vars["method_type"] = "grpc.web.MethodType.UNARY"; - PrintUnaryCall(&printer1, vars); - PrintPromiseUnaryCall(&printer2, vars); - } - } - } - } - printer1.Print("}); // goog.scope\n\n"); - printer2.Print("}); // goog.scope\n\n"); -} - -void PrintClosureES6Imports(Printer* printer, const FileDescriptor* file, - string package_dot) { - for (int i = 0; i < file->service_count(); ++i) { - const ServiceDescriptor* service = file->service(i); - - string service_namespace = "proto." + package_dot + string(service->name()); - printer->Print( - "import $service_name$Client_import from 'goog:$namespace$';\n", - "service_name", string(service->name()), "namespace", - service_namespace + "Client"); - printer->Print( - "import $service_name$PromiseClient_import from 'goog:$namespace$';\n", - "service_name", string(service->name()), "namespace", - service_namespace + "PromiseClient"); - } - - printer->Print("\n\n\n"); -} - -void PrintGrpcWebClosureES6File(Printer* printer, const FileDescriptor* file) { - string package_dot = file->package().empty() ? "" : string(file->package()) + "."; - - printer->Print( - "/**\n" - " * @fileoverview gRPC-Web generated client stub for '$file$'\n" - " */\n" - "\n" - "// Code generated by protoc-gen-grpc-web. DO NOT EDIT.\n" - "// versions:\n" - "// \tprotoc-gen-grpc-web v$version$\n" - "// \tprotoc v$protoc_version$\n" - "// source: $source_file$\n" - "\n" - "\n", - "file", file->name()); - - PrintClosureES6Imports(printer, file, package_dot); - - for (int i = 0; i < file->service_count(); ++i) { - const ServiceDescriptor* service = file->service(i); - - string service_namespace = "proto." + package_dot + string(service->name()); - printer->Print("export const $name$Client = $name$Client_import;\n", "name", - string(service->name())); - printer->Print( - "export const $name$PromiseClient = $name$PromiseClient_import;\n", - "name", string(service->name())); - } -} - -class GeneratorOptions { - public: - GeneratorOptions(); - - bool ParseFromOptions(const string& parameter, string* error); - bool ParseFromOptions(const std::vector>& options, - string* error); - - // Returns the name of the output file for |proto_file|. - string OutputFile(const string& proto_file) const; - - string mode() const { return mode_; } - string plugins() const { return plugins_; } - ImportStyle import_style() const { return import_style_; } - bool generate_dts() const { return generate_dts_; } - bool generate_closure_es6() const { return generate_closure_es6_; } - bool multiple_files() const { return multiple_files_; } - bool goog_promise() const { return goog_promise_; } - - private: - string file_name_; - string mode_; - string plugins_; - ImportStyle import_style_; - bool generate_dts_; - bool generate_closure_es6_; - bool multiple_files_; - bool goog_promise_; -}; - -GeneratorOptions::GeneratorOptions() - : file_name_(""), - mode_(""), - plugins_(""), - import_style_(ImportStyle::CLOSURE), - generate_dts_(false), - generate_closure_es6_(false), - multiple_files_(false), - goog_promise_(false) {} - -bool GeneratorOptions::ParseFromOptions(const string& parameter, - string* error) { - std::vector> options; - ParseGeneratorParameter(parameter, &options); - return ParseFromOptions(options, error); -} - -bool GeneratorOptions::ParseFromOptions( - const std::vector>& options, string* error) { - for (const std::pair& option : options) { - if ("out" == option.first) { - file_name_ = option.second; - } else if ("mode" == option.first) { - mode_ = option.second; - } else if ("import_style" == option.first) { - if ("closure" == option.second) { - import_style_ = ImportStyle::CLOSURE; - } else if ("experimental_closure_es6" == option.second) { - import_style_ = ImportStyle::CLOSURE; - generate_closure_es6_ = true; - } else if ("commonjs" == option.second) { - import_style_ = ImportStyle::COMMONJS; - } else if ("commonjs+dts" == option.second) { - import_style_ = ImportStyle::COMMONJS; - generate_dts_ = true; - } else if ("typescript" == option.second) { - import_style_ = ImportStyle::TYPESCRIPT; - generate_dts_ = true; - } else { - *error = "options: invalid import_style - " + option.second; - return false; - } - } else if ("multiple_files" == option.first) { - multiple_files_ = "True" == option.second; - } else if ("plugins" == option.first) { - plugins_ = option.second; - } else if ("goog_promise" == option.first) { - goog_promise_ = "True" == option.second; - } else { - *error = "unsupported option: " + option.first; - return false; - } - } - - if (mode_.empty()) { - *error = "options: mode is required"; - return false; - } - - return true; -} - -string GeneratorOptions::OutputFile(const string& proto_file) const { - if (ImportStyle::TYPESCRIPT == import_style()) { - // Never use the value from the 'out' option when generating TypeScript. - string directory; - string basename; - PathSplit(proto_file, &directory, &basename); - return directory + UppercaseFirstLetter(StripProto(basename)) + - "ServiceClientPb.ts"; - } - if (!file_name_.empty()) { - return file_name_; - } - return StripProto(proto_file) + "_grpc_web_pb.js"; -} - -class GrpcCodeGenerator : public CodeGenerator { - public: - GrpcCodeGenerator() {} - ~GrpcCodeGenerator() override {} - - uint64_t GetSupportedFeatures() const override { - // Code generators must explicitly support proto3 optional. - return CodeGenerator::FEATURE_PROTO3_OPTIONAL | CodeGenerator::FEATURE_SUPPORTS_EDITIONS; - } - - // Keep synced with protoc-gen-js: https://github.com/protocolbuffers/protobuf-javascript/blob/861c8020a5c0cba9b7cdf915dffde96a4421a1f4/generator/js_generator.h#L157-L158 - Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; } - Edition GetMaximumEdition() const override { return Edition::EDITION_2023; } - - bool Generate(const FileDescriptor* file, const string& parameter, - GeneratorContext* context, string* error) const override { - GeneratorOptions generator_options; - if (!generator_options.ParseFromOptions(parameter, error)) { - return false; - } - - std::map vars; - std::map method_descriptors; - string package(file->package()); - vars["package"] = package; - vars["package_dot"] = package.empty() ? "" : package + '.'; - vars["promise"] = "Promise"; - vars["plugins"] = generator_options.plugins(); - - if ("binary" == generator_options.mode()) { - vars["mode"] = GetModeVar(Mode::OP); - vars["binary"] = "true"; - } else if ("grpcweb" == generator_options.mode()) { - vars["mode"] = GetModeVar(Mode::GRPCWEB); - vars["format"] = "binary"; - } else if ("grpcwebtext" == generator_options.mode()) { - vars["mode"] = GetModeVar(Mode::GRPCWEB); - vars["format"] = "text"; - } else if ("jspb" == generator_options.mode()) { - vars["mode"] = GetModeVar(Mode::OP); - vars["binary"] = "false"; - if (generator_options.goog_promise()) { - vars["promise"] = GRPC_PROMISE; - } - } else { - *error = "options: invalid mode - " + generator_options.mode(); - return false; - } - - if (generator_options.generate_dts()) { - string proto_dts_file_name = StripProto(file->name()) + "_pb.d.ts"; - std::unique_ptr proto_dts_output( - context->Open(proto_dts_file_name)); - Printer proto_dts_printer(proto_dts_output.get(), '$'); - PrintProtoDtsFile(&proto_dts_printer, file); - } - - if (!file->service_count()) { - // No services, nothing to do. - return true; - } - - vars["version"] = GRPC_WEB_VERSION; - vars["protoc_version"] = GetProtocVersion(context); - vars["source_file"] = string(file->name()); - - string file_name = generator_options.OutputFile(string(file->name())); - if (generator_options.multiple_files() && - ImportStyle::CLOSURE == generator_options.import_style()) { - PrintMultipleFilesMode(file, file_name, context, vars); - return true; - } - - std::unique_ptr output(context->Open(file_name)); - Printer printer(output.get(), '$'); - PrintFileHeader(&printer, vars); - - if (ImportStyle::TYPESCRIPT == generator_options.import_style()) { - PrintTypescriptFile(&printer, file, vars); - return true; - } - - for (int i = 0; i < file->service_count(); ++i) { - const ServiceDescriptor* service = file->service(i); - vars["service_name"] = string(service->name()); - switch (generator_options.import_style()) { - case ImportStyle::CLOSURE: - printer.Print( - vars, - "goog.provide('proto.$package_dot$$service_name$Client');\n"); - printer.Print(vars, - "goog.provide('proto.$package_dot$$service_name$" - "PromiseClient');\n"); - break; - case ImportStyle::COMMONJS: - break; - case ImportStyle::TYPESCRIPT: - break; - } - } - printer.Print("\n"); - - switch (generator_options.import_style()) { - case ImportStyle::CLOSURE: - if (vars["promise"] == GRPC_PROMISE) { - printer.Print(vars, "goog.require('grpc.web.promise');\n"); - } - printer.Print(vars, "goog.require('grpc.web.MethodDescriptor');\n"); - printer.Print(vars, "goog.require('grpc.web.MethodType');\n"); - printer.Print(vars, "goog.require('grpc.web.$mode$ClientBase');\n"); - printer.Print(vars, "goog.require('grpc.web.AbstractClientBase');\n"); - printer.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); - printer.Print(vars, "goog.require('grpc.web.RpcError');\n"); - - PrintClosureDependencies(&printer, file); - printer.Print(vars, "\ngoog.requireType('grpc.web.ClientOptions');\n"); - printer.Print("\n\n\n"); - printer.Print("goog.scope(function() {\n\n"); - break; - case ImportStyle::COMMONJS: - printer.Print(vars, "const grpc = {};\n"); - printer.Print(vars, "grpc.web = require('grpc-web');\n\n"); - PrintCommonJsMessagesDeps(&printer, file); - break; - case ImportStyle::TYPESCRIPT: - break; - } - - for (int service_index = 0; service_index < file->service_count(); - ++service_index) { - const ServiceDescriptor* service = file->service(service_index); - vars["service_name"] = string(service->name()); - PrintServiceConstructor(&printer, vars, false); - PrintServiceConstructor(&printer, vars, true); - - for (int method_index = 0; method_index < service->method_count(); - ++method_index) { - const MethodDescriptor* method = service->method(method_index); - const Descriptor* input_type = method->input_type(); - const Descriptor* output_type = method->output_type(); - vars["js_method_name"] = LowercaseFirstLetter(method->name()); - vars["method_name"] = string(method->name()); - vars["in"] = string(input_type->full_name()); - vars["out"] = string(output_type->full_name()); - vars["method_descriptor"] = - "methodDescriptor_" + string(service->name()) + "_" + string(method->name()); - - // Cross-file ref in CommonJS needs to use the module alias instead - // of the global name. - if (ImportStyle::COMMONJS == generator_options.import_style() && - input_type->file() != file) { - vars["in_type"] = ModuleAlias(input_type->file()->name()) + - GetNestedMessageName(input_type); - } else { - vars["in_type"] = "proto." + string(input_type->full_name()); - } - if (ImportStyle::COMMONJS == generator_options.import_style() && - output_type->file() != file) { - vars["out_type"] = ModuleAlias(output_type->file()->name()) + - GetNestedMessageName(output_type); - } else { - vars["out_type"] = "proto." + string(output_type->full_name()); - } - - // Client streaming is not supported yet - if (!method->client_streaming()) { - if (method->server_streaming()) { - vars["method_type"] = "grpc.web.MethodType.SERVER_STREAMING"; - PrintMethodDescriptor(&printer, vars); - vars["client_type"] = "Client"; - PrintServerStreamingCall(&printer, vars); - vars["client_type"] = "PromiseClient"; - PrintServerStreamingCall(&printer, vars); - } else { - vars["method_type"] = "grpc.web.MethodType.UNARY"; - PrintMethodDescriptor(&printer, vars); - PrintUnaryCall(&printer, vars); - PrintPromiseUnaryCall(&printer, vars); - } - } - } - } - - switch (generator_options.import_style()) { - case ImportStyle::CLOSURE: - printer.Print("}); // goog.scope\n\n"); - break; - case ImportStyle::COMMONJS: - if (!vars["package"].empty()) { - printer.Print(vars, "module.exports = proto.$package$;\n\n"); - } else { - printer.Print(vars, "module.exports = proto;\n\n"); - } - break; - case ImportStyle::TYPESCRIPT: - break; - } - - if (generator_options.generate_dts()) { - string grpcweb_dts_file_name = - StripProto(file->name()) + "_grpc_web_pb.d.ts"; - string proto_dts_file_name = StripProto(file->name()) + "_pb.d.ts"; - - std::unique_ptr grpcweb_dts_output( - context->Open(grpcweb_dts_file_name)); - Printer grpcweb_dts_printer(grpcweb_dts_output.get(), '$'); - - PrintGrpcWebDtsFile(&grpcweb_dts_printer, file); - } - - if (generator_options.generate_closure_es6()) { - string es6_file_name = StripProto(file->name()) + ".pb.grpc-web.js"; - - std::unique_ptr es6_output( - context->Open(es6_file_name)); - Printer es6_printer(es6_output.get(), '$'); - - PrintGrpcWebClosureES6File(&es6_printer, file); - } - - return true; - } -}; - -} // namespace -} // namespace web -} // namespace grpc - -int main(int argc, char* argv[]) { - if (argc == 2 && std::string(argv[1]) == "--version") { - std::cout << argv[0] << " " << grpc::web::GRPC_WEB_VERSION << std::endl; - return 0; - } - - grpc::web::GrpcCodeGenerator generator; - PluginMain(argc, argv, &generator); - return 0; -} From 95673033bafcc3e0c010fcbfc3d4024b274c068c Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Fri, 12 Dec 2025 09:29:48 +0000 Subject: [PATCH 16/17] Remove lint rule for removed file Signed-off-by: Dom Del Nano --- .arclint | 1 - 1 file changed, 1 deletion(-) diff --git a/.arclint b/.arclint index 2bb8b3b8303..7b87106fe80 100644 --- a/.arclint +++ b/.arclint @@ -34,7 +34,6 @@ "(^src/ui/src/types/schema\\.ts$)", "(^third_party/cpplint/cpplint.py$)", "(^third_party/gogoproto/gogo.proto$)", - "(^third_party/protoc-gen-grpc-web/grpc_generator.cc$)", "(c_cpp_properties.json$)", "(go\\.mod$)", "(go\\.sum$)" From f8f0d4898f0863d2fb4bdef55dddae4d50a7ed9f Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Fri, 12 Dec 2025 14:09:26 +0000 Subject: [PATCH 17/17] Use correct type for grpc error code Signed-off-by: Dom Del Nano --- src/ui/src/api/vizier-grpc-client.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/src/api/vizier-grpc-client.ts b/src/ui/src/api/vizier-grpc-client.ts index 7313b871154..25342cab57a 100644 --- a/src/ui/src/api/vizier-grpc-client.ts +++ b/src/ui/src/api/vizier-grpc-client.ts @@ -16,7 +16,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { ClientReadableStream } from 'grpc-web'; +import { ClientReadableStream, StatusCode } from 'grpc-web'; import { compactDecrypt } from 'jose'; import * as pako from 'pako'; import { Observable, of, from } from 'rxjs'; @@ -31,7 +31,7 @@ import { } from 'app/types/generated/vizierapi_pb'; import { VizierServiceClient } from 'app/types/generated/VizierapiServiceClientPb'; -import { GRPCStatusCode, VizierQueryError } from './vizier'; +import { VizierQueryError } from './vizier'; import { VizierTable } from './vizier-table'; const noop = () => {}; @@ -380,7 +380,7 @@ export class VizierGRPCClient { }); call.on('error', (grpcError) => { let error: VizierQueryError; - if (grpcError.code === GRPCStatusCode.Unavailable) { + if (grpcError.code === StatusCode.UNAVAILABLE) { error = new VizierQueryError('unavailable', grpcError.message); } else { error = new VizierQueryError('server', grpcError.message);