diff --git a/.bazelignore b/.bazelignore index 9bc1218c91f8..0dcef45291d9 100644 --- a/.bazelignore +++ b/.bazelignore @@ -10,5 +10,6 @@ pkg/ui/workspaces/db-console/src/js/node_modules pkg/ui/workspaces/db-console/ccl/src/js/node_modules pkg/ui/workspaces/e2e-tests/node_modules pkg/ui/workspaces/eslint-plugin-crdb/node_modules +pkg/ui/workspaces/crdb-api-client/node_modules tmp vendor diff --git a/BUILD.bazel b/BUILD.bazel index 458e0816c8e6..3ed6c5a6797a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -102,6 +102,7 @@ exports_files([ # gazelle:exclude pkg/ui/workspaces/db-console/src/js/node_modules # gazelle:exclude pkg/ui/workspaces/e2e-tests/node_modules # gazelle:exclude pkg/ui/workspaces/eslint-plugin-crdb/node_modules +# gazelle:exclude pkg/ui/workspaces/crdb-api-client/node_modules # gazelle:exclude vendor # gazelle:exclude .vendor.tmp.* # gazelle:exclude **/zcgo_flags.go diff --git a/WORKSPACE b/WORKSPACE index 0ff404b13de2..ce9c32c89e52 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -275,6 +275,7 @@ npm_translate_lock( "//pkg/ui:pnpm-workspace.yaml", "//pkg/ui/patches:topojson@3.0.2.patch", "//pkg/ui/workspaces/cluster-ui:package.json", + "//pkg/ui/workspaces/crdb-api-client:package.json", "//pkg/ui/workspaces/db-console:package.json", "//pkg/ui/workspaces/db-console/src/js:package.json", "//pkg/ui/workspaces/e2e-tests:package.json", diff --git a/docs/generated/http/BUILD.bazel b/docs/generated/http/BUILD.bazel index e92109b20bbf..5ea9c1a990b6 100644 --- a/docs/generated/http/BUILD.bazel +++ b/docs/generated/http/BUILD.bazel @@ -1,64 +1,8 @@ +load(":defs.bzl", "PROTOBUF_TARGETS") + genrule( name = "http", - srcs = [ - "//pkg/build:build_proto", - "//pkg/clusterversion:clusterversion_proto", - "//pkg/config/zonepb:zonepb_proto", - "//pkg/geo/geopb:geopb_proto", - "//pkg/gossip:gossip_proto", - "//pkg/jobs/jobspb:jobspb_proto", - "//pkg/kv/kvpb:kvpb_proto", - "//pkg/kv/kvserver/concurrency/isolation:isolation_proto", - "//pkg/kv/kvserver/concurrency/lock:lock_proto", - "//pkg/kv/kvserver/kvserverpb:kvserverpb_proto", - "//pkg/kv/kvserver/liveness/livenesspb:livenesspb_proto", - "//pkg/kv/kvserver/loqrecovery/loqrecoverypb:loqrecoverypb_proto", - "//pkg/kv/kvserver/readsummary/rspb:rspb_proto", - "//pkg/multitenant/mtinfopb:mtinfopb_proto", - "//pkg/multitenant/tenantcapabilities/tenantcapabilitiespb:tenantcapabilitiespb_proto", - "//pkg/roachpb:roachpb_proto", - "//pkg/rpc/rpcpb:rpcpb_proto", - "//pkg/server/diagnostics/diagnosticspb:diagnosticspb_proto", - "//pkg/server/serverpb:serverpb_proto", - "//pkg/server/status/statuspb:statuspb_proto", - "//pkg/settings:settings_proto", - "//pkg/sql/appstatspb:appstatspb_proto", - "//pkg/sql/catalog/catenumpb:catenumpb_proto", - "//pkg/sql/catalog/catpb:catpb_proto", - "//pkg/sql/catalog/descpb:descpb_proto", - "//pkg/sql/catalog/fetchpb:fetchpb_proto", - "//pkg/sql/contentionpb:contentionpb_proto", - "//pkg/sql/execinfrapb:execinfrapb_proto", - "//pkg/sql/sem/semenumpb:semenumpb_proto", - "//pkg/sql/inverted:inverted_proto", - "//pkg/sql/lex:lex_proto", - "//pkg/sql/pgwire/pgerror:pgerror_proto", - "//pkg/sql/schemachanger/scpb:scpb_proto", - "//pkg/sql/sessiondatapb:sessiondatapb_proto", - "//pkg/sql/sqlstats/insights:insights_proto", - "//pkg/sql/types:types_proto", - "//pkg/storage/enginepb:enginepb_proto", - "//pkg/ts/catalog:catalog_proto", - "//pkg/ts/tspb:tspb_proto", - "//pkg/util/duration:duration_proto", - "//pkg/util/hlc:hlc_proto", - "//pkg/util/admission/admissionpb:admissionpb_proto", - "//pkg/util/log/logpb:logpb_proto", - "//pkg/util/metric:metric_proto", - "//pkg/util/timeutil/pgdate:pgdate_proto", - "//pkg/util/tracing/tracingpb:tracingpb_proto", - "//pkg/util:util_proto", - "@com_github_prometheus_client_model//io/prometheus/client:io_prometheus_client_proto", - "@com_github_cockroachdb_errors//errorspb:errorspb_proto", - "@com_github_gogo_protobuf//gogoproto:gogo_proto", - "@com_google_protobuf//:any_proto", - "@com_google_protobuf//:descriptor_proto", - "@com_google_protobuf//:duration_proto", - "@com_google_protobuf//:timestamp_proto", - "@go_googleapis//google/api:annotations_proto", - "@go_googleapis//google/api:http_proto", - "@io_etcd_go_raft_v3//raftpb:raftpb_proto", - ], + srcs = PROTOBUF_TARGETS, outs = [ "full.md", "health-other.md", diff --git a/docs/generated/http/defs.bzl b/docs/generated/http/defs.bzl new file mode 100644 index 000000000000..0ca7059c2d1f --- /dev/null +++ b/docs/generated/http/defs.bzl @@ -0,0 +1,62 @@ +# PROTOBUF_TARGETS lists the indirect dependencies needed to compile proto dependencies +# of //pkg/server/serverpb:serverpb_proto target +PROTOBUF_TARGETS = [ + "//pkg/build:build_proto", + "//pkg/clusterversion:clusterversion_proto", + "//pkg/config/zonepb:zonepb_proto", + "//pkg/geo/geopb:geopb_proto", + "//pkg/gossip:gossip_proto", + "//pkg/jobs/jobspb:jobspb_proto", + "//pkg/kv/kvpb:kvpb_proto", + "//pkg/kv/kvserver/concurrency/isolation:isolation_proto", + "//pkg/kv/kvserver/concurrency/lock:lock_proto", + "//pkg/kv/kvserver/kvserverpb:kvserverpb_proto", + "//pkg/kv/kvserver/liveness/livenesspb:livenesspb_proto", + "//pkg/kv/kvserver/loqrecovery/loqrecoverypb:loqrecoverypb_proto", + "//pkg/kv/kvserver/readsummary/rspb:rspb_proto", + "//pkg/kv/kvserver/kvflowcontrol/kvflowcontrolpb:kvflowcontrolpb_proto", + "//pkg/multitenant/mtinfopb:mtinfopb_proto", + "//pkg/multitenant/tenantcapabilities/tenantcapabilitiespb:tenantcapabilitiespb_proto", + "//pkg/roachpb:roachpb_proto", + "//pkg/rpc/rpcpb:rpcpb_proto", + "//pkg/server/diagnostics/diagnosticspb:diagnosticspb_proto", + "//pkg/server/serverpb:serverpb_proto", + "//pkg/server/status/statuspb:statuspb_proto", + "//pkg/settings:settings_proto", + "//pkg/sql/appstatspb:appstatspb_proto", + "//pkg/sql/catalog/catenumpb:catenumpb_proto", + "//pkg/sql/catalog/catpb:catpb_proto", + "//pkg/sql/catalog/descpb:descpb_proto", + "//pkg/sql/catalog/fetchpb:fetchpb_proto", + "//pkg/sql/contentionpb:contentionpb_proto", + "//pkg/sql/execinfrapb:execinfrapb_proto", + "//pkg/sql/sem/semenumpb:semenumpb_proto", + "//pkg/sql/inverted:inverted_proto", + "//pkg/sql/lex:lex_proto", + "//pkg/sql/pgwire/pgerror:pgerror_proto", + "//pkg/sql/schemachanger/scpb:scpb_proto", + "//pkg/sql/sessiondatapb:sessiondatapb_proto", + "//pkg/sql/sqlstats/insights:insights_proto", + "//pkg/sql/types:types_proto", + "//pkg/storage/enginepb:enginepb_proto", + "//pkg/ts/catalog:catalog_proto", + "//pkg/ts/tspb:tspb_proto", + "//pkg/util/duration:duration_proto", + "//pkg/util/hlc:hlc_proto", + "//pkg/util/admission/admissionpb:admissionpb_proto", + "//pkg/util/log/logpb:logpb_proto", + "//pkg/util/metric:metric_proto", + "//pkg/util/timeutil/pgdate:pgdate_proto", + "//pkg/util/tracing/tracingpb:tracingpb_proto", + "//pkg/util:util_proto", + "@com_github_prometheus_client_model//io/prometheus/client:io_prometheus_client_proto", + "@com_github_cockroachdb_errors//errorspb:errorspb_proto", + "@com_github_gogo_protobuf//gogoproto:gogo_proto", + "@com_google_protobuf//:any_proto", + "@com_google_protobuf//:descriptor_proto", + "@com_google_protobuf//:duration_proto", + "@com_google_protobuf//:timestamp_proto", + "@go_googleapis//google/api:annotations_proto", + "@go_googleapis//google/api:http_proto", + "@io_etcd_go_raft_v3//raftpb:raftpb_proto", +] diff --git a/pkg/ui/pnpm-lock.yaml b/pkg/ui/pnpm-lock.yaml index 33b0fdc8eb0d..668feed13b82 100644 --- a/pkg/ui/pnpm-lock.yaml +++ b/pkg/ui/pnpm-lock.yaml @@ -459,6 +459,19 @@ importers: specifier: ^5.0.0-3 version: 5.0.0-3(webpack@4.41.5) + workspaces/crdb-api-client: + dependencies: + '@bufbuild/protobuf': + specifier: ^1.7.2 + version: 1.7.2 + devDependencies: + '@bufbuild/protoc-gen-es': + specifier: ^1.7.2 + version: 1.7.2(@bufbuild/protobuf@1.7.2) + typescript: + specifier: 5.1.6 + version: 5.1.6 + workspaces/db-console: dependencies: '@babel/runtime': @@ -5151,6 +5164,35 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true + /@bufbuild/protobuf@1.7.2: + resolution: {integrity: sha512-i5GE2Dk5ekdlK1TR7SugY4LWRrKSfb5T1Qn4unpIMbfxoeGKERKQ59HG3iYewacGD10SR7UzevfPnh6my4tNmQ==} + + /@bufbuild/protoc-gen-es@1.7.2(@bufbuild/protobuf@1.7.2): + resolution: {integrity: sha512-yiRk/T+YGmpSVvIkybCjPt+QyM/pLWMO+MAiz6auvCsiAgfXfc5nFFosD4yBYXID55M6eIkgBcity1AoJ6I30A==} + engines: {node: '>=14'} + hasBin: true + peerDependencies: + '@bufbuild/protobuf': 1.7.2 + peerDependenciesMeta: + '@bufbuild/protobuf': + optional: true + dependencies: + '@bufbuild/protobuf': 1.7.2 + '@bufbuild/protoplugin': 1.7.2 + transitivePeerDependencies: + - supports-color + dev: true + + /@bufbuild/protoplugin@1.7.2: + resolution: {integrity: sha512-N3QtO8XWD4F4alMtASWtxBw6BWXp4aLz7rPBXH4KTULdjpUHnq46g15TsrG0/8szZw6pIklTO3lFe14dl6ZYdA==} + dependencies: + '@bufbuild/protobuf': 1.7.2 + '@typescript/vfs': 1.5.0 + typescript: 4.5.2 + transitivePeerDependencies: + - supports-color + dev: true + /@cockroachlabs/design-tokens@0.4.5: resolution: {integrity: sha512-az2aIuGjnD0UBN5igLmaKvVWnZJ9r7v2jQ9C4fNR6bxxiF5DkOcD1DXf8EXHIbgwJtorpB74zaic7MQhhMY45w==} @@ -8671,6 +8713,14 @@ packages: '@typescript-eslint/types': 5.26.0 eslint-visitor-keys: 3.4.1 + /@typescript/vfs@1.5.0: + resolution: {integrity: sha512-AJS307bPgbsZZ9ggCT3wwpg3VbTKMFNHfaY/uF0ahSkYYrPF2dSSKDNIDIQAHm9qJqbLvCsSJH7yN4Vs/CsMMg==} + dependencies: + debug: 4.3.4(supports-color@8.1.1) + transitivePeerDependencies: + - supports-color + dev: true + /@webassemblyjs/ast@1.8.5: resolution: {integrity: sha512-aJMfngIZ65+t71C3y2nBBg5FFG0Okt9m0XEgWZ7Ywgn1oMAT8cNwx00Uv1cQyHtidq0Xn94R4TAywO+LCQ+ZAQ==} dependencies: @@ -22969,6 +23019,12 @@ packages: dependencies: typescript-compare: 0.0.2 + /typescript@4.5.2: + resolution: {integrity: sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==} + engines: {node: '>=4.2.0'} + hasBin: true + dev: true + /typescript@5.1.6: resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==} engines: {node: '>=14.17'} diff --git a/pkg/ui/pnpm-workspace.yaml b/pkg/ui/pnpm-workspace.yaml index afa72f4633e8..55fd45b002d3 100644 --- a/pkg/ui/pnpm-workspace.yaml +++ b/pkg/ui/pnpm-workspace.yaml @@ -5,3 +5,4 @@ packages: - "./workspaces/cluster-ui" - "./workspaces/db-console" - "./workspaces/e2e-tests" + - "./workspaces/crdb-api-client" diff --git a/pkg/ui/workspaces/crdb-api-client/BUILD.bazel b/pkg/ui/workspaces/crdb-api-client/BUILD.bazel new file mode 100644 index 000000000000..d5a1dcf8dac3 --- /dev/null +++ b/pkg/ui/workspaces/crdb-api-client/BUILD.bazel @@ -0,0 +1,88 @@ +load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary", "js_test") +load("@aspect_rules_js//npm:defs.bzl", "npm_package") +load("@aspect_rules_ts//ts:defs.bzl", "ts_project") +load("@bazel_skylib//rules:write_file.bzl", "write_file") +load("@npm//:defs.bzl", "npm_link_all_packages") +load("@npm//:defs.bzl", "npm_link_all_packages") +load("//docs/generated/http:defs.bzl", "PROTOBUF_TARGETS") +load("//pkg/ui/workspaces/db-console/src/js:defs.bzl", "proto_sources") + +npm_link_all_packages(name = "node_modules") + +genrule( + name = "protos", + srcs = [ + ":node_modules/@bufbuild/protoc-gen-es/bin/protoc-gen-es", + ":proto_sources", + ] + PROTOBUF_TARGETS, + outs = ["dist"], + cmd = """ + mkdir -p $(OUTS); + DESCRIPTOR_SET_IN=$$(for word in $(SRCS); do echo $$word; done | grep '\\.bin$$' | tr -s '\\n' ':'); + PROTO_PATHS=$$(for f in $(locations :proto_sources); + do if [[ "$$f" =~ ^.*/pkg/.*/_virtual_imports/.*_proto/.*.proto$$ ]]; + then echo $$f | sed 's|.*pkg/.*/_virtual_imports/.*_proto/||' | sed 's|.bin$$||'; + fi; done | sort -u); + export PATH=$$PATH:$$(dirname $(NODE_PATH)) + $(location @com_google_protobuf//:protoc) \ + --plugin=$(location :node_modules/@bufbuild/protoc-gen-es/bin/protoc-gen-es) \ + --es_out $(OUTS) \ + --descriptor_set_in $$DESCRIPTOR_SET_IN \ + --es_opt target=js+dts \ + $$PROTO_PATHS""", + toolchains = ["@nodejs_toolchains//:resolved_toolchain"], + tools = [ + "@com_google_protobuf//:protoc", + "@nodejs_toolchains//:resolved_toolchain", + ], +) + +proto_sources( + name = "proto_sources", + protos = [ + "//pkg/server/serverpb:serverpb_proto", + "//pkg/ts/tspb:tspb_proto", + ], +) + +genrule( + name = "index_ts", + srcs = [":protos"], + outs = ["index.ts"], + cmd = """ + ABS_ROOT_PATH=$$(realpath $(SRCS)) + for f in $$(find $$ABS_ROOT_PATH -name *.js) + do + filename=$$(basename -s .js $$f) + filepath=$${f#$$ABS_ROOT_PATH/} + filepath=$${filepath%.js} + import_name=$${filepath/-/_}; \ + echo export "*" as $${import_name////_} from \\"./$$(basename $(SRCS))/$${filepath}\\"\\; >> $@ + done + """, +) + +ts_project( + name = "ts_project", + srcs = [ + "tsconfig.json", + ":index_ts", + ":protos", + ], + tsconfig = "tsconfig.json", + validate = True, + deps = [":node_modules"], +) + +npm_package( + name = "crdb-api-client", + srcs = [ + "package.json", + "tsconfig.json", + ":index_ts", + ":protos", + ":ts_project", + ], + package = "@cockroachlabs/crdb-api-client", + visibility = ["//visibility:public"], +) diff --git a/pkg/ui/workspaces/crdb-api-client/package.json b/pkg/ui/workspaces/crdb-api-client/package.json new file mode 100644 index 000000000000..b66489bdcaf1 --- /dev/null +++ b/pkg/ui/workspaces/crdb-api-client/package.json @@ -0,0 +1,12 @@ +{ + "name": "@cockroachlabs/crdb-api-client", + "version": "1.0.0", + "main": "index.ts", + "devDependencies": { + "@bufbuild/protoc-gen-es": "^1.7.2", + "typescript": "5.1.6" + }, + "dependencies": { + "@bufbuild/protobuf": "^1.7.2" + } +} diff --git a/pkg/ui/workspaces/crdb-api-client/tsconfig.json b/pkg/ui/workspaces/crdb-api-client/tsconfig.json new file mode 100644 index 000000000000..9e21daf38803 --- /dev/null +++ b/pkg/ui/workspaces/crdb-api-client/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es2016", + "lib": ["ESNext"], + "module": "ESNext", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": false + } +} diff --git a/pkg/ui/workspaces/db-console/src/js/defs.bzl b/pkg/ui/workspaces/db-console/src/js/defs.bzl index b5cc9e1bf0ed..daeea46599c7 100644 --- a/pkg/ui/workspaces/db-console/src/js/defs.bzl +++ b/pkg/ui/workspaces/db-console/src/js/defs.bzl @@ -10,7 +10,7 @@ def _proto_sources_impl(ctx): transitive = [p[ProtoInfo].transitive_sources for p in ctx.attr.protos], )) -_proto_sources = rule( +proto_sources = rule( doc = """Provider Adapter from ProtoInfo to DefaultInfo. Extracts the transitive_sources from the ProtoInfo provided by the proto attr. This allows a macro to access the complete set of .proto files needed during compilation. @@ -37,7 +37,7 @@ def protobufjs_library(name, out_name, protos, **kwargs): ts_target = "_%s_pbts" % name # grab the transitive .proto files needed to compile the given one - _proto_sources( + proto_sources( name = proto_target, protos = protos, )