Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e2b3159

Browse files
committedJun 18, 2025·
Add WIP JS routeguide
1 parent 6905880 commit e2b3159

File tree

22 files changed

+440
-71
lines changed

22 files changed

+440
-71
lines changed
 

‎.bazelci/presubmit.yml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@ tasks:
1111
- "//examples/routeguide:cpp_cpp"
1212
- "//examples/routeguide:cpp_go"
1313
- "//examples/routeguide:cpp_java"
14+
- "//examples/routeguide:cpp_js"
1415
- "//examples/routeguide:cpp_python"
1516
- "//examples/routeguide:go_cpp"
1617
- "//examples/routeguide:go_go"
1718
- "//examples/routeguide:go_java"
19+
- "//examples/routeguide:go_js"
1820
- "//examples/routeguide:go_python"
1921
- "//examples/routeguide:java_cpp"
2022
- "//examples/routeguide:java_go"
2123
- "//examples/routeguide:java_java"
24+
- "//examples/routeguide:java_js"
2225
- "//examples/routeguide:java_python"
26+
- "//examples/routeguide:js_cpp"
27+
- "//examples/routeguide:js_go"
28+
- "//examples/routeguide:js_java"
29+
- "//examples/routeguide:js_js"
30+
- "//examples/routeguide:js_python"
2331
- "//examples/routeguide:python_cpp"
2432
- "//examples/routeguide:python_go"
2533
- "//examples/routeguide:python_java"
34+
- "//examples/routeguide:python_js"
2635
- "//examples/routeguide:python_python"
2736
- "//examples/routeguide:scala_cpp"
2837
- "//examples/routeguide:scala_go"
2938
- "//examples/routeguide:scala_java"
39+
- "//examples/routeguide:scala_js"
3040
- "//examples/routeguide:scala_python"
3141

3242
main_macos:
@@ -40,22 +50,32 @@ tasks:
4050
- "//examples/routeguide:cpp_cpp"
4151
- "//examples/routeguide:cpp_go"
4252
- "//examples/routeguide:cpp_java"
53+
- "//examples/routeguide:cpp_js"
4354
- "//examples/routeguide:cpp_python"
4455
- "//examples/routeguide:go_cpp"
4556
- "//examples/routeguide:go_go"
4657
- "//examples/routeguide:go_java"
58+
- "//examples/routeguide:go_js"
4759
- "//examples/routeguide:go_python"
4860
- "//examples/routeguide:java_cpp"
4961
- "//examples/routeguide:java_go"
5062
- "//examples/routeguide:java_java"
63+
- "//examples/routeguide:java_js"
5164
- "//examples/routeguide:java_python"
65+
- "//examples/routeguide:js_cpp"
66+
- "//examples/routeguide:js_go"
67+
- "//examples/routeguide:js_java"
68+
- "//examples/routeguide:js_js"
69+
- "//examples/routeguide:js_python"
5270
- "//examples/routeguide:python_cpp"
5371
- "//examples/routeguide:python_go"
5472
- "//examples/routeguide:python_java"
73+
- "//examples/routeguide:python_js"
5574
- "//examples/routeguide:python_python"
5675
- "//examples/routeguide:scala_cpp"
5776
- "//examples/routeguide:scala_go"
5877
- "//examples/routeguide:scala_java"
78+
- "//examples/routeguide:scala_js"
5979
- "//examples/routeguide:scala_python"
6080

6181
main_macos_arm64:
@@ -68,15 +88,23 @@ tasks:
6888
test_targets:
6989
- "//examples/routeguide:cpp_cpp"
7090
- "//examples/routeguide:cpp_go"
91+
- "//examples/routeguide:cpp_js"
7192
- "//examples/routeguide:cpp_python"
7293
- "//examples/routeguide:go_cpp"
7394
- "//examples/routeguide:go_go"
95+
- "//examples/routeguide:go_js"
7496
- "//examples/routeguide:go_python"
97+
- "//examples/routeguide:js_cpp"
98+
- "//examples/routeguide:js_go"
99+
- "//examples/routeguide:js_js"
100+
- "//examples/routeguide:js_python"
75101
- "//examples/routeguide:python_cpp"
76102
- "//examples/routeguide:python_go"
103+
- "//examples/routeguide:python_js"
77104
- "//examples/routeguide:python_python"
78105
- "//examples/routeguide:scala_cpp"
79106
- "//examples/routeguide:scala_go"
107+
- "//examples/routeguide:scala_js"
80108
- "//examples/routeguide:scala_python"
81109

82110
buf_ubuntu2204_examples:
@@ -295,10 +323,10 @@ tasks:
295323
shell_commands:
296324
- set -x
297325
- make js_js_proto_compile_example
298-
- make js_js_grpc_node_compile_example
326+
- make js_js_grpc_compile_example
299327
- make js_js_grpc_web_compile_example
300328
- make js_js_proto_library_example
301-
- make js_js_grpc_node_library_example
329+
- make js_js_grpc_library_example
302330
- make js_js_grpc_web_library_example
303331

304332
js_macos_examples:
@@ -309,10 +337,10 @@ tasks:
309337
shell_commands:
310338
- set -x
311339
- make js_js_proto_compile_example
312-
- make js_js_grpc_node_compile_example
340+
- make js_js_grpc_compile_example
313341
- make js_js_grpc_web_compile_example
314342
- make js_js_proto_library_example
315-
- make js_js_grpc_node_library_example
343+
- make js_js_grpc_library_example
316344
- make js_js_grpc_web_library_example
317345

318346
js_macos_arm64_examples:
@@ -323,10 +351,10 @@ tasks:
323351
shell_commands:
324352
- set -x
325353
- make js_js_proto_compile_example
326-
- make js_js_grpc_node_compile_example
354+
- make js_js_grpc_compile_example
327355
- make js_js_grpc_web_compile_example
328356
- make js_js_proto_library_example
329-
- make js_js_grpc_node_library_example
357+
- make js_js_grpc_library_example
330358
- make js_js_grpc_web_library_example
331359

332360
python_ubuntu2204_examples:

‎.bazelignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ examples/java/java_proto_library
3030
examples/java/java_grpc_library
3131

3232
examples/js/js_proto_compile
33-
examples/js/js_grpc_node_compile
33+
examples/js/js_grpc_compile
3434
examples/js/js_grpc_web_compile
3535
examples/js/js_proto_library
36-
examples/js/js_grpc_node_library
36+
examples/js/js_grpc_library
3737
examples/js/js_grpc_web_library
3838

3939
examples/objc/objc_proto_compile

‎MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
bazel_dep(name = "aspect_rules_js", version = "2.3.7")
12
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2")
23
bazel_dep(name = "gazelle", version = "0.44.0")
34
bazel_dep(name = "protobuf", version = "31.1")

‎README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ Full documentation for the current and previous versions [can be found here](htt
9494
| [Java](https://rules-proto-grpc.com/en/latest/lang/java.html) | [java_proto_library](https://rules-proto-grpc.com/en/latest/lang/java.html#java-proto-library) | Generates a Java protobuf library using ``java_library`` ([example](/examples/java/java_proto_library)) |
9595
| [Java](https://rules-proto-grpc.com/en/latest/lang/java.html) | [java_grpc_library](https://rules-proto-grpc.com/en/latest/lang/java.html#java-grpc-library) | Generates a Java protobuf and gRPC library using ``java_library`` ([example](/examples/java/java_grpc_library)) |
9696
| [JavaScript](https://rules-proto-grpc.com/en/latest/lang/js.html) | [js_proto_compile](https://rules-proto-grpc.com/en/latest/lang/js.html#js-proto-compile) | Generates JavaScript protobuf ``.js`` and ``.d.ts`` files ([example](/examples/js/js_proto_compile)) |
97-
| [JavaScript](https://rules-proto-grpc.com/en/latest/lang/js.html) | [js_grpc_node_compile](https://rules-proto-grpc.com/en/latest/lang/js.html#js-grpc-node-compile) | Generates JavaScript protobuf and gRPC-node ``.js`` and ``.d.ts`` files ([example](/examples/js/js_grpc_node_compile)) |
97+
| [JavaScript](https://rules-proto-grpc.com/en/latest/lang/js.html) | [js_grpc_compile](https://rules-proto-grpc.com/en/latest/lang/js.html#js-grpc-compile) | Generates JavaScript protobuf and gRPC-js ``.js`` and ``.d.ts`` files ([example](/examples/js/js_grpc_compile)) |
9898
| [JavaScript](https://rules-proto-grpc.com/en/latest/lang/js.html) | [js_grpc_web_compile](https://rules-proto-grpc.com/en/latest/lang/js.html#js-grpc-web-compile) | Generates JavaScript protobuf and gRPC-Web ``.js`` and ``.d.ts`` files ([example](/examples/js/js_grpc_web_compile)) |
9999
| [JavaScript](https://rules-proto-grpc.com/en/latest/lang/js.html) | [js_proto_library](https://rules-proto-grpc.com/en/latest/lang/js.html#js-proto-library) | Generates a JavaScript protobuf library using ``js_library`` from ``aspect_rules_js`` ([example](/examples/js/js_proto_library)) |
100-
| [JavaScript](https://rules-proto-grpc.com/en/latest/lang/js.html) | [js_grpc_node_library](https://rules-proto-grpc.com/en/latest/lang/js.html#js-grpc-node-library) | Generates a Node.js protobuf + gRPC-node library using ``js_library`` from ``aspect_rules_js`` ([example](/examples/js/js_grpc_node_library)) |
100+
| [JavaScript](https://rules-proto-grpc.com/en/latest/lang/js.html) | [js_grpc_library](https://rules-proto-grpc.com/en/latest/lang/js.html#js-grpc-library) | Generates a Node.js protobuf + gRPC-js library using ``js_library`` from ``aspect_rules_js`` ([example](/examples/js/js_grpc_library)) |
101101
| [JavaScript](https://rules-proto-grpc.com/en/latest/lang/js.html) | [js_grpc_web_library](https://rules-proto-grpc.com/en/latest/lang/js.html#js-grpc-web-library) | Generates a JavaScript protobuf + gRPC-Web library using ``js_library`` from ``aspect_rules_js`` ([example](/examples/js/js_grpc_web_library)) |
102102
| [Objective-C](https://rules-proto-grpc.com/en/latest/lang/objc.html) | [objc_proto_compile](https://rules-proto-grpc.com/en/latest/lang/objc.html#objc-proto-compile) | Generates Objective-C protobuf ``.m`` & ``.h`` files ([example](/examples/objc/objc_proto_compile)) |
103103
| [Objective-C](https://rules-proto-grpc.com/en/latest/lang/objc.html) | [objc_grpc_compile](https://rules-proto-grpc.com/en/latest/lang/objc.html#objc-grpc-compile) | Generates Objective-C protobuf and gRPC ``.m`` & ``.h`` files ([example](/examples/objc/objc_grpc_compile)) |

‎docs/lang/js.rst

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
JavaScript
77
==========
88

9-
Rules for generating JavaScript protobuf, gRPC-node and gRPC-Web ``.js`` and ``.d.ts`` files using standard Protocol Buffers and gRPC.
9+
Rules for generating JavaScript protobuf, gRPC-js and gRPC-Web ``.js`` and ``.d.ts`` files using standard Protocol Buffers and gRPC.
1010

1111
.. list-table:: Rules
1212
:widths: 1 2
@@ -16,14 +16,14 @@ Rules for generating JavaScript protobuf, gRPC-node and gRPC-Web ``.js`` and ``.
1616
- Description
1717
* - `js_proto_compile`_
1818
- Generates JavaScript protobuf ``.js`` and ``.d.ts`` files
19-
* - `js_grpc_node_compile`_
20-
- Generates JavaScript protobuf and gRPC-node ``.js`` and ``.d.ts`` files
19+
* - `js_grpc_compile`_
20+
- Generates JavaScript protobuf and gRPC-js ``.js`` and ``.d.ts`` files
2121
* - `js_grpc_web_compile`_
2222
- Generates JavaScript protobuf and gRPC-Web ``.js`` and ``.d.ts`` files
2323
* - `js_proto_library`_
2424
- Generates a JavaScript protobuf library using ``js_library`` from ``aspect_rules_js``
25-
* - `js_grpc_node_library`_
26-
- Generates a Node.js protobuf + gRPC-node library using ``js_library`` from ``aspect_rules_js``
25+
* - `js_grpc_library`_
26+
- Generates a Node.js protobuf + gRPC-js library using ``js_library`` from ``aspect_rules_js``
2727
* - `js_grpc_web_library`_
2828
- Generates a JavaScript protobuf + gRPC-Web library using ``js_library`` from ``aspect_rules_js``
2929

@@ -124,39 +124,39 @@ Plugins
124124
- `@rules_proto_grpc_js//:proto_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/modules/js/BUILD.bazel>`__
125125
- `@rules_proto_grpc_js//:proto_ts_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/modules/js/BUILD.bazel>`__
126126

127-
.. _js_grpc_node_compile:
127+
.. _js_grpc_compile:
128128

129-
js_grpc_node_compile
130-
--------------------
129+
js_grpc_compile
130+
---------------
131131

132-
Generates JavaScript protobuf and gRPC-node ``.js`` and ``.d.ts`` files
132+
Generates JavaScript protobuf and gRPC-js ``.js`` and ``.d.ts`` files
133133

134134
Example
135135
*******
136136

137-
Full example project can be found `here <https://github.com/rules-proto-grpc/rules_proto_grpc/tree/master/examples/js/js_grpc_node_compile>`__
137+
Full example project can be found `here <https://github.com/rules-proto-grpc/rules_proto_grpc/tree/master/examples/js/js_grpc_compile>`__
138138

139139
``BUILD.bazel``
140140
^^^^^^^^^^^^^^^
141141

142142
.. code-block:: python
143143
144-
load("@rules_proto_grpc_js//:defs.bzl", "js_grpc_node_compile")
144+
load("@rules_proto_grpc_js//:defs.bzl", "js_grpc_compile")
145145
146-
js_grpc_node_compile(
146+
js_grpc_compile(
147147
name = "thing_js_grpc",
148148
protos = ["@rules_proto_grpc_example_protos//:thing_proto"],
149149
)
150150
151-
js_grpc_node_compile(
151+
js_grpc_compile(
152152
name = "greeter_js_grpc",
153153
protos = ["@rules_proto_grpc_example_protos//:greeter_grpc"],
154154
)
155155
156156
Attributes
157157
**********
158158

159-
.. list-table:: Attributes for js_grpc_node_compile
159+
.. list-table:: Attributes for js_grpc_compile
160160
:widths: 1 1 1 1 4
161161
:header-rows: 1
162162

@@ -206,8 +206,8 @@ Plugins
206206

207207
- `@rules_proto_grpc_js//:proto_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/modules/js/BUILD.bazel>`__
208208
- `@rules_proto_grpc_js//:proto_ts_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/modules/js/BUILD.bazel>`__
209-
- `@rules_proto_grpc_js//:grpc_node_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/modules/js/BUILD.bazel>`__
210-
- `@rules_proto_grpc_js//:grpc_node_ts_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/modules/js/BUILD.bazel>`__
209+
- `@rules_proto_grpc_js//:grpc_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/modules/js/BUILD.bazel>`__
210+
- `@rules_proto_grpc_js//:grpc_ts_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/modules/js/BUILD.bazel>`__
211211

212212
.. _js_grpc_web_compile:
213213

@@ -397,31 +397,31 @@ Attributes
397397
- ``False``
398398
- Use the legacy <name>_pb path segment from the generated library require path.
399399

400-
.. _js_grpc_node_library:
400+
.. _js_grpc_library:
401401

402-
js_grpc_node_library
403-
--------------------
402+
js_grpc_library
403+
---------------
404404

405-
Generates a Node.js protobuf + gRPC-node library using ``js_library`` from ``aspect_rules_js``
405+
Generates a Node.js protobuf + gRPC-js library using ``js_library`` from ``aspect_rules_js``
406406

407407
Example
408408
*******
409409

410-
Full example project can be found `here <https://github.com/rules-proto-grpc/rules_proto_grpc/tree/master/examples/js/js_grpc_node_library>`__
410+
Full example project can be found `here <https://github.com/rules-proto-grpc/rules_proto_grpc/tree/master/examples/js/js_grpc_library>`__
411411

412412
``BUILD.bazel``
413413
^^^^^^^^^^^^^^^
414414

415415
.. code-block:: python
416416
417-
load("@rules_proto_grpc_js//:defs.bzl", "js_grpc_node_library")
417+
load("@rules_proto_grpc_js//:defs.bzl", "js_grpc_library")
418418
419-
js_grpc_node_library(
419+
js_grpc_library(
420420
name = "thing_js_grpc",
421421
protos = ["@rules_proto_grpc_example_protos//:thing_proto"],
422422
)
423423
424-
js_grpc_node_library(
424+
js_grpc_library(
425425
name = "greeter_js_grpc",
426426
protos = ["@rules_proto_grpc_example_protos//:greeter_grpc"],
427427
deps = ["thing_js_grpc"],
@@ -430,7 +430,7 @@ Full example project can be found `here <https://github.com/rules-proto-grpc/rul
430430
Attributes
431431
**********
432432

433-
.. list-table:: Attributes for js_grpc_node_library
433+
.. list-table:: Attributes for js_grpc_library
434434
:widths: 1 1 1 1 4
435435
:header-rows: 1
436436

‎examples/Makefile.mk

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ js_js_proto_compile_example:
131131
cd examples/js/js_proto_compile; \
132132
bazel --batch build ${BAZEL_EXTRA_FLAGS} --verbose_failures --disk_cache=../../bazel-disk-cache //...
133133

134-
.PHONY: js_js_grpc_node_compile_example
135-
js_js_grpc_node_compile_example:
136-
cd examples/js/js_grpc_node_compile; \
134+
.PHONY: js_js_grpc_compile_example
135+
js_js_grpc_compile_example:
136+
cd examples/js/js_grpc_compile; \
137137
bazel --batch build ${BAZEL_EXTRA_FLAGS} --verbose_failures --disk_cache=../../bazel-disk-cache //...
138138

139139
.PHONY: js_js_grpc_web_compile_example
@@ -146,9 +146,9 @@ js_js_proto_library_example:
146146
cd examples/js/js_proto_library; \
147147
bazel --batch build ${BAZEL_EXTRA_FLAGS} --verbose_failures --disk_cache=../../bazel-disk-cache //...
148148

149-
.PHONY: js_js_grpc_node_library_example
150-
js_js_grpc_node_library_example:
151-
cd examples/js/js_grpc_node_library; \
149+
.PHONY: js_js_grpc_library_example
150+
js_js_grpc_library_example:
151+
cd examples/js/js_grpc_library; \
152152
bazel --batch build ${BAZEL_EXTRA_FLAGS} --verbose_failures --disk_cache=../../bazel-disk-cache //...
153153

154154
.PHONY: js_js_grpc_web_library_example
@@ -157,7 +157,7 @@ js_js_grpc_web_library_example:
157157
bazel --batch build ${BAZEL_EXTRA_FLAGS} --verbose_failures --disk_cache=../../bazel-disk-cache //...
158158

159159
.PHONY: js_examples
160-
js_examples: js_js_proto_compile_example js_js_grpc_node_compile_example js_js_grpc_web_compile_example js_js_proto_library_example js_js_grpc_node_library_example js_js_grpc_web_library_example
160+
js_examples: js_js_proto_compile_example js_js_grpc_compile_example js_js_grpc_web_compile_example js_js_proto_library_example js_js_grpc_library_example js_js_grpc_web_library_example
161161

162162
.PHONY: objc_objc_proto_compile_example
163163
objc_objc_proto_compile_example:
@@ -262,4 +262,4 @@ swift_swift_grpc_library_example:
262262
swift_examples: swift_swift_proto_compile_example swift_swift_grpc_compile_example swift_swift_proto_library_example swift_swift_grpc_library_example
263263

264264
.PHONY: all_examples
265-
all_examples: buf_buf_proto_breaking_test_example buf_buf_proto_lint_test_example cpp_cpp_proto_compile_example cpp_cpp_grpc_compile_example cpp_cpp_proto_library_example cpp_cpp_grpc_library_example doc_doc_docbook_compile_example doc_doc_html_compile_example doc_doc_json_compile_example doc_doc_markdown_compile_example doc_doc_template_compile_example go_go_proto_compile_example go_go_grpc_compile_example go_go_proto_library_example go_go_grpc_library_example grpc_gateway_gateway_grpc_compile_example grpc_gateway_gateway_openapiv2_compile_example grpc_gateway_gateway_grpc_library_example java_java_proto_compile_example java_java_grpc_compile_example java_java_proto_library_example java_java_grpc_library_example js_js_proto_compile_example js_js_grpc_node_compile_example js_js_grpc_web_compile_example js_js_proto_library_example js_js_grpc_node_library_example js_js_grpc_web_library_example objc_objc_proto_compile_example objc_objc_grpc_compile_example objc_objc_proto_library_example objc_objc_grpc_library_example python_python_proto_compile_example python_python_grpc_compile_example python_python_grpclib_compile_example python_python_proto_library_example python_python_grpc_library_example python_python_grpclib_library_example scala_scala_proto_compile_example scala_scala_grpc_compile_example scala_scala_proto_library_example scala_scala_grpc_library_example swift_swift_proto_compile_example swift_swift_grpc_compile_example swift_swift_proto_library_example swift_swift_grpc_library_example
265+
all_examples: buf_buf_proto_breaking_test_example buf_buf_proto_lint_test_example cpp_cpp_proto_compile_example cpp_cpp_grpc_compile_example cpp_cpp_proto_library_example cpp_cpp_grpc_library_example doc_doc_docbook_compile_example doc_doc_html_compile_example doc_doc_json_compile_example doc_doc_markdown_compile_example doc_doc_template_compile_example go_go_proto_compile_example go_go_grpc_compile_example go_go_proto_library_example go_go_grpc_library_example grpc_gateway_gateway_grpc_compile_example grpc_gateway_gateway_openapiv2_compile_example grpc_gateway_gateway_grpc_library_example java_java_proto_compile_example java_java_grpc_compile_example java_java_proto_library_example java_java_grpc_library_example js_js_proto_compile_example js_js_grpc_compile_example js_js_grpc_web_compile_example js_js_proto_library_example js_js_grpc_library_example js_js_grpc_web_library_example objc_objc_proto_compile_example objc_objc_grpc_compile_example objc_objc_proto_library_example objc_objc_grpc_library_example python_python_proto_compile_example python_python_grpc_compile_example python_python_grpclib_compile_example python_python_proto_library_example python_python_grpc_library_example python_python_grpclib_library_example scala_scala_proto_compile_example scala_scala_grpc_compile_example scala_scala_proto_library_example scala_scala_grpc_library_example swift_swift_proto_compile_example swift_swift_grpc_compile_example swift_swift_proto_library_example swift_swift_grpc_library_example
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
load("@rules_proto_grpc_js//:defs.bzl", "js_grpc_node_compile")
1+
load("@rules_proto_grpc_js//:defs.bzl", "js_grpc_compile")
22

3-
js_grpc_node_compile(
3+
js_grpc_compile(
44
name = "thing_js_grpc",
55
protos = ["@rules_proto_grpc_example_protos//:thing_proto"],
66
)
77

8-
js_grpc_node_compile(
8+
js_grpc_compile(
99
name = "greeter_js_grpc",
1010
protos = ["@rules_proto_grpc_example_protos//:greeter_grpc"],
1111
)

‎examples/js/js_grpc_node_library/BUILD.bazel renamed to ‎examples/js/js_grpc_library/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
load("@rules_proto_grpc_js//:defs.bzl", "js_grpc_node_library")
1+
load("@rules_proto_grpc_js//:defs.bzl", "js_grpc_library")
22

3-
js_grpc_node_library(
3+
js_grpc_library(
44
name = "thing_js_grpc",
55
protos = ["@rules_proto_grpc_example_protos//:thing_proto"],
66
)
77

8-
js_grpc_node_library(
8+
js_grpc_library(
99
name = "greeter_js_grpc",
1010
protos = ["@rules_proto_grpc_example_protos//:greeter_grpc"],
1111
deps = ["thing_js_grpc"],

‎examples/js/routeguide/BUILD.bazel

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
load("@aspect_rules_js//js:defs.bzl", "js_binary")
2+
load("@rules_proto_grpc_js//:defs.bzl", "js_grpc_library")
3+
4+
js_grpc_library(
5+
name = "routeguide",
6+
protos = ["@rules_proto_grpc_example_protos//:routeguide_proto"],
7+
)
8+
9+
js_binary(
10+
name = "client",
11+
data = [
12+
"client.js",
13+
":routeguide",
14+
],
15+
entry_point = "client.js",
16+
visibility = ["//examples/routeguide:__pkg__"],
17+
)
18+
19+
js_binary(
20+
name = "server",
21+
data = [
22+
"server.js",
23+
":routeguide",
24+
],
25+
entry_point = "server.js",
26+
visibility = ["//examples/routeguide:__pkg__"],
27+
)

‎examples/js/routeguide/client.js

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
const util = require('util');
2+
const grpc = require('@grpc/grpc-js');
3+
4+
const messages = require('routeguide/routeguide_pb/example/proto/routeguide_pb.js')
5+
const services = require('routeguide/routeguide_pb/example/proto/routeguide_grpc_pb.js')
6+
7+
// This is included as data in the client, so we can load this database as a constant.
8+
const featureList = require('rules_proto_grpc/example/proto/routeguide_features.json');
9+
console.log(`Loaded ${featureList.length} from feature database`);
10+
const COORD_FACTOR = 1e7;
11+
12+
13+
function newPoint(latitude, longitude) {
14+
const point = new messages.Point()
15+
point.setLatitude(latitude);
16+
point.setLongitude(longitude);
17+
return point;
18+
}
19+
20+
function newRectangle(lo, hi) {
21+
const rect = new messages.Rectangle()
22+
rect.setLo(lo);
23+
rect.setHi(hi);
24+
return rect;
25+
}
26+
27+
function newNote(point, message) {
28+
const note = new messages.RouteNote()
29+
note.setLocation(point);
30+
note.setMessage(message);
31+
return note;
32+
}
33+
34+
35+
async function runGetFeature(client) {
36+
const method = util.promisify(client.getFeature).bind(client);
37+
for (const point of [
38+
newPoint(409146138, -746188906),
39+
newPoint(1, 1)
40+
]) {
41+
const feature = await method(point);
42+
if (feature.getName() && feature.getName() != "undefined") {
43+
console.log(
44+
'Found feature called "' + feature.getName() + '" at ' +
45+
feature.getLocation().getLatitude() / COORD_FACTOR + ', ' +
46+
feature.getLocation().getLongitude() / COORD_FACTOR
47+
);
48+
} else {
49+
console.log('Found no feature');
50+
}
51+
}
52+
}
53+
54+
55+
function runListFeatures(client) {
56+
return new Promise((resolve, reject) => {
57+
const rectangle = newRectangle(
58+
newPoint(400000000, -750000000),
59+
newPoint(420000000, -73000000)
60+
);
61+
console.log('Looking for features between 40, -75 and 42, -73');
62+
63+
const call = client.listFeatures(rectangle);
64+
call.on('data', (feature) => {
65+
console.log(
66+
'Found feature called "' + feature.getName() + '" at ' +
67+
feature.getLocation().getLatitude() / COORD_FACTOR + ', ' +
68+
feature.getLocation().getLongitude() / COORD_FACTOR
69+
);
70+
});
71+
call.on('end', resolve);
72+
});
73+
}
74+
75+
76+
function runRecordRoute(client) {
77+
return new Promise((resolve, reject) => {
78+
const call = client.recordRoute((error, stats) => {
79+
if (error) return reject(error);
80+
console.log('Finished trip with', stats.getPointCount(), 'points');
81+
console.log('Passed', stats.getFeatureCount(), 'features');
82+
console.log('Traveled', stats.getDistance(), 'meters');
83+
console.log('It took', stats.getElapsedTime(), 'seconds');
84+
resolve();
85+
});
86+
87+
for (let i = 0; i < 10; i++) {
88+
const randIndex = ~~(Math.random() * (featureList.length - 1))
89+
console.log("randomIndex", randIndex);
90+
const randomPointJson = featureList[randIndex];
91+
const randomPoint = newPoint(
92+
randomPointJson.location.latitude, randomPointJson.location.longitude
93+
)
94+
console.log("randomPoint", randomPointJson, randomPoint.toObject());
95+
call.write(randomPoint);
96+
}
97+
98+
call.end();
99+
});
100+
}
101+
102+
103+
function runRouteChat(client) {
104+
return new Promise((resolve, reject) => {
105+
const call = client.routeChat();
106+
call.on('data', (note) => {
107+
console.log(
108+
'Got message "' + note.getMessage() + '" at ' +
109+
note.getLocation().getLatitude() + ', ' + note.getLocation().getLongitude()
110+
);
111+
});
112+
call.on('end', resolve);
113+
114+
const notes = [
115+
newNote(newPoint(0, 0), 'First message'),
116+
newNote(newPoint(0, 1), 'Second message'),
117+
newNote(newPoint(1, 0), 'Third message'),
118+
newNote(newPoint(0, 0), 'Fourth message'),
119+
]
120+
for (const note of notes) {
121+
console.log(
122+
'Sending message "' + note.getMessage() + '" at ' +
123+
note.getLocation().getLatitude() + ', ' + note.getLocation().getLongitude()
124+
);
125+
call.write(note);
126+
}
127+
128+
call.end();
129+
});
130+
}
131+
132+
133+
async function main() {
134+
let port = '50051';
135+
if (process.env.SERVER_PORT) port = process.env.SERVER_PORT;
136+
const addr = 'localhost:' + port;
137+
const client = new services.RouteGuideClient(addr, grpc.credentials.createInsecure());
138+
139+
client.waitForReady(4000, async () => {
140+
await runGetFeature(client);
141+
await runListFeatures(client);
142+
await runRecordRoute(client);
143+
await runRouteChat(client);
144+
});
145+
}
146+
147+
if (require.main === module) {
148+
main().catch((e) => {
149+
console.log(e)
150+
process.exit(1);
151+
});
152+
}

‎examples/js/routeguide/server.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
const grpc = require('@grpc/grpc-js');
2+
3+
const messages = require('routeguide_package/example/proto/routeguide_pb.js')
4+
const services = require('routeguide_package/example/proto/routeguide_grpc_pb.js')
5+
const featureDb = require('rules_proto_grpc/example/proto/routeguide_features.json');
6+
7+
const COORD_FACTOR = 1e7;
8+
let feature_list = [];
9+
10+
11+
function checkFeature(point) {
12+
// Check if there is already a feature object for the given point
13+
for (const feature of feature_list) {
14+
if (feature.getLocation().getLatitude() === point.getLatitude() &&
15+
feature.getLocation().getLongitude() === point.getLongitude()) {
16+
return feature;
17+
}
18+
}
19+
20+
// Create empty feature
21+
const name = '';
22+
const feature = new messages.Feature();
23+
feature.setName(name);
24+
feature.setLocation(point);
25+
return feature;
26+
}
27+
28+
29+
function getFeature(call, callback) {
30+
callback(null, checkFeature(call.request));
31+
}
32+
33+
34+
function listFeatures(call) {
35+
const lo = call.request.getLo();
36+
const hi = call.request.getHi();
37+
const left = Math.min([lo.getLongitude(), hi.getLongitude()]);
38+
const right = Math.max([lo.getLongitude(), hi.getLongitude()]);
39+
const top = Math.max([lo.getLatitude(), hi.getLatitude()]);
40+
const bottom = Math.min([lo.getLatitude(), hi.getLatitude()]);
41+
42+
// For each feature, check if it is in the given bounding box
43+
feature_list.forEach((feature) => {
44+
if (feature.getName() === '') return;
45+
if (feature.getLocation().getLongitude() >= left &&
46+
feature.getLocation().getLongitude() <= right &&
47+
feature.getLocation().getLatitude() >= bottom &&
48+
feature.getLocation().getLatitude() <= top) {
49+
call.write(feature);
50+
}
51+
});
52+
53+
call.end();
54+
}
55+
56+
57+
function getDistance(start, end) {
58+
function toRadians(num) {
59+
return num * Math.PI / 180;
60+
}
61+
62+
const R = 6371000; // earth radius in metres
63+
const lat1 = toRadians(start.getLatitude() / COORD_FACTOR);
64+
const lat2 = toRadians(end.getLatitude() / COORD_FACTOR);
65+
const lon1 = toRadians(start.getLongitude() / COORD_FACTOR);
66+
const lon2 = toRadians(end.getLongitude() / COORD_FACTOR);
67+
68+
const deltalat = lat2-lat1;
69+
const deltalon = lon2-lon1;
70+
const a = Math.sin(deltalat / 2) * Math.sin(deltalat / 2) +
71+
Math.cos(lat1) * Math.cos(lat2) *
72+
Math.sin(deltalon / 2) * Math.sin(deltalon / 2);
73+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
74+
return R * c;
75+
}
76+
77+
78+
function recordRoute(call, callback) {
79+
let pointCount = 0;
80+
let featureCount = 0;
81+
let distance = 0;
82+
let previous = null;
83+
84+
// Start a timer
85+
const start_time = process.hrtime();
86+
call.on('data', (point) => {
87+
pointCount++;
88+
if (checkFeature(point).name !== '') featureCount += 1;
89+
if (previous != null) distance += getDistance(previous, point);
90+
previous = point;
91+
});
92+
93+
call.on('end', () => {
94+
const summary = new messages.RouteSummary();
95+
summary.setPointCount(pointCount);
96+
summary.setFeatureCount(featureCount);
97+
summary.setDistance(distance|0);
98+
summary.setElapsedTime(process.hrtime(start_time)[0]);
99+
callback(null, summary);
100+
});
101+
}
102+
103+
104+
const route_notes = new Map();
105+
106+
function pointKey(point) {
107+
return point.getLatitude() + ' ' + point.getLongitude();
108+
}
109+
110+
111+
function routeChat(call) {
112+
call.on('data', function(note) {
113+
const key = pointKey(note.getLocation());
114+
if (route_notes.has(key)) {
115+
route_notes[key].forEach((note) => {
116+
call.write(note);
117+
});
118+
} else {
119+
route_notes[key] = [];
120+
}
121+
122+
// Then add the new note to the list
123+
route_notes[key].push(note);
124+
});
125+
126+
call.on('end', call.end);
127+
}
128+
129+
130+
if (require.main === module) {
131+
let port = '50051';
132+
if (process.env.SERVER_PORT) port = process.env.SERVER_PORT;
133+
const addr = '0.0.0.0:' + port;
134+
const routeServer = new grpc.Server();
135+
routeServer.addService(services.RouteGuideService, {
136+
getFeature: getFeature,
137+
listFeatures: listFeatures,
138+
recordRoute: recordRoute,
139+
routeChat: routeChat
140+
});
141+
142+
routeServer.bindAsync(addr, grpc.ServerCredentials.createInsecure(), () => {
143+
// Transform the loaded features to Feature objects
144+
feature_list = featureDb.map(function(value) {
145+
const feature = new messages.Feature();
146+
feature.setName(value.name);
147+
const location = new messages.Point();
148+
location.setLatitude(value.location.latitude);
149+
location.setLongitude(value.location.longitude);
150+
feature.setLocation(location);
151+
return feature;
152+
});
153+
154+
console.log(`Feature database contains ${feature_list.length} entries.`);
155+
console.log(`Node server listening at ${addr}...`)
156+
routeServer.start();
157+
});
158+
}

‎examples/routeguide/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ routeguide_test_matrix(
1515
"//examples/cpp/routeguide:client",
1616
"//examples/go/routeguide/client:client",
1717
"//examples/java/routeguide:client",
18+
"//examples/js/routeguide:client",
1819
"//examples/python/routeguide:client",
1920
"//examples/scala/routeguide:client",
2021
],
2122
servers = [
2223
"//examples/cpp/routeguide:server",
2324
"//examples/go/routeguide/server:server",
2425
"//examples/java/routeguide:server",
26+
"//examples/js/routeguide:server",
2527
"//examples/python/routeguide:server",
2628
# "//examples/scala/routeguide:server", # Doesn't exist yet
2729
],

‎modules/js/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ proto_plugin(
3131
grpc_tools.grpc_tools_node_protoc_plugin_binary(name = "grpc_tools_node_protoc_plugin_binary")
3232

3333
proto_plugin(
34-
name = "grpc_node_plugin",
34+
name = "grpc_plugin",
3535
empty_template = "empty.template",
3636
exclusions = [
3737
"google/protobuf",
@@ -45,7 +45,7 @@ proto_plugin(
4545
)
4646

4747
proto_plugin(
48-
name = "grpc_node_ts_plugin",
48+
name = "grpc_ts_plugin",
4949
empty_template = "empty.template",
5050
options = [
5151
"service=grpc-node",

‎modules/js/defs.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""js protobuf and grpc rules."""
22

3-
load(":js_grpc_node_compile.bzl", _js_grpc_node_compile = "js_grpc_node_compile")
4-
load(":js_grpc_node_library.bzl", _js_grpc_node_library = "js_grpc_node_library")
3+
load(":js_grpc_compile.bzl", _js_grpc_compile = "js_grpc_compile")
4+
load(":js_grpc_library.bzl", _js_grpc_library = "js_grpc_library")
55
load(":js_grpc_web_compile.bzl", _js_grpc_web_compile = "js_grpc_web_compile")
66
load(":js_grpc_web_library.bzl", _js_grpc_web_library = "js_grpc_web_library")
77
load(":js_proto_compile.bzl", _js_proto_compile = "js_proto_compile")
88
load(":js_proto_library.bzl", _js_proto_library = "js_proto_library")
99

1010
# Export js rules
1111
js_proto_compile = _js_proto_compile
12-
js_grpc_node_compile = _js_grpc_node_compile
12+
js_grpc_compile = _js_grpc_compile
1313
js_grpc_web_compile = _js_grpc_web_compile
1414
js_proto_library = _js_proto_library
15-
js_grpc_node_library = _js_grpc_node_library
15+
js_grpc_library = _js_grpc_library
1616
js_grpc_web_library = _js_grpc_web_library

‎modules/js/js_grpc_node_compile.bzl renamed to ‎modules/js/js_grpc_compile.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Generated definition of js_grpc_node_compile."""
1+
"""Generated definition of js_grpc_compile."""
22

33
load(
44
"@rules_proto_grpc//:defs.bzl",
@@ -9,7 +9,7 @@ load(
99
)
1010

1111
# Create compile rule
12-
js_grpc_node_compile = rule(
12+
js_grpc_compile = rule(
1313
implementation = proto_compile_impl,
1414
attrs = dict(
1515
proto_compile_attrs,
@@ -18,8 +18,8 @@ js_grpc_node_compile = rule(
1818
default = [
1919
Label("//:proto_plugin"),
2020
Label("//:proto_ts_plugin"),
21-
Label("//:grpc_node_plugin"),
22-
Label("//:grpc_node_ts_plugin"),
21+
Label("//:grpc_plugin"),
22+
Label("//:grpc_ts_plugin"),
2323
],
2424
cfg = "exec",
2525
doc = "List of protoc plugins to apply",

‎modules/js/js_grpc_node_library.bzl renamed to ‎modules/js/js_grpc_library.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
"""Generated definition of js_grpc_node_library."""
1+
"""Generated definition of js_grpc_library."""
22

33
load("@aspect_rules_js//js:defs.bzl", "js_library")
44
load("@rules_proto_grpc//:defs.bzl", "bazel_build_rule_common_attrs", "proto_compile_attrs")
5-
load("//:js_grpc_node_compile.bzl", "js_grpc_node_compile")
5+
load("//:js_grpc_compile.bzl", "js_grpc_compile")
66

7-
def js_grpc_node_library(name, **kwargs):
7+
def js_grpc_library(name, **kwargs):
88
# Compile protos
99
name_pb = name + "_pb"
10-
js_grpc_node_compile(
10+
js_grpc_compile(
1111
name = name_pb,
1212
**{
1313
k: v

‎tools/rulegen/MODULE.bazel.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
bazel_dep(name = "aspect_rules_js", version = "2.3.7")
12
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2")
23
bazel_dep(name = "gazelle", version = "0.44.0")
34
bazel_dep(name = "protobuf", version = "31.1")

‎tools/rulegen/js.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ PROTO_DEPS = [
2626

2727
var jsGrpcLibraryRuleTemplate = mustTemplate(`load("@aspect_rules_js//js:defs.bzl", "js_library")
2828
load("@rules_proto_grpc//:defs.bzl", "bazel_build_rule_common_attrs", "proto_compile_attrs")
29-
load("//:js_grpc_node_compile.bzl", "js_grpc_node_compile")
29+
load("//:js_grpc_compile.bzl", "js_grpc_compile")
3030
3131
def {{ .Rule.Name }}(name, **kwargs):
3232
# Compile protos
3333
name_pb = name + "_pb"
34-
js_grpc_node_compile(
34+
js_grpc_compile(
3535
name = name_pb,
3636
{{ .Common.CompileArgsForwardingSnippet }}
3737
)
@@ -102,7 +102,7 @@ func makeJs() *Language {
102102
return &Language{
103103
Name: "js",
104104
DisplayName: "JavaScript",
105-
Notes: mustTemplate("Rules for generating JavaScript protobuf, gRPC-node and gRPC-Web ``.js`` and ``.d.ts`` files using standard Protocol Buffers and gRPC."),
105+
Notes: mustTemplate("Rules for generating JavaScript protobuf, gRPC-js and gRPC-Web ``.js`` and ``.d.ts`` files using standard Protocol Buffers and gRPC."),
106106
Rules: []*Rule{
107107
&Rule{
108108
Name: "js_proto_compile",
@@ -114,12 +114,12 @@ func makeJs() *Language {
114114
Attrs: compileRuleAttrs,
115115
},
116116
&Rule{
117-
Name: "js_grpc_node_compile",
117+
Name: "js_grpc_compile",
118118
Kind: "grpc",
119119
Implementation: compileRuleTemplate,
120-
Plugins: []string{"//:proto_plugin", "//:proto_ts_plugin", "//:grpc_node_plugin", "//:grpc_node_ts_plugin"},
120+
Plugins: []string{"//:proto_plugin", "//:proto_ts_plugin", "//:grpc_plugin", "//:grpc_ts_plugin"},
121121
BuildExample: grpcCompileExampleTemplate,
122-
Doc: "Generates JavaScript protobuf and gRPC-node ``.js`` and ``.d.ts`` files",
122+
Doc: "Generates JavaScript protobuf and gRPC-js ``.js`` and ``.d.ts`` files",
123123
Attrs: compileRuleAttrs,
124124
},
125125
&Rule{
@@ -140,11 +140,11 @@ func makeJs() *Language {
140140
Attrs: jsLibraryRuleAttrs,
141141
},
142142
&Rule{
143-
Name: "js_grpc_node_library",
143+
Name: "js_grpc_library",
144144
Kind: "grpc",
145145
Implementation: jsGrpcLibraryRuleTemplate,
146146
BuildExample: grpcLibraryExampleTemplate,
147-
Doc: "Generates a Node.js protobuf + gRPC-node library using ``js_library`` from ``aspect_rules_js``",
147+
Doc: "Generates a Node.js protobuf + gRPC-js library using ``js_library`` from ``aspect_rules_js``",
148148
Attrs: jsLibraryRuleAttrs,
149149
},
150150
&Rule{

0 commit comments

Comments
 (0)
Please sign in to comment.