grpc_tools_node_protoc_ts
Aim
Generate corresponding TypeScript d.ts codes according to js codes generated by grpc_tools_node_protoc
More information about grpc_tools_node_protoc:
Breaking changes
v2.2.0
Fix definition changes according to the version change of grpc official TypeScript definition, see: index.d.ts@1.9.0.
Detailed changes could be found here: PR#14.
v2.0.0
Since v2.x.x, current project supports the official definition of grpc, see: index.d.ts@1.8.4.
Though the usage of tool, and generated codes shall not been changed, it's good to be double checked in your project when upgrade.
TSLint has been disabled in generated files. Please see the conversation: #13.
Note
This tools is using an unofficial grpc.d.ts definition, see: grpc-tsd.
If you want to use this tool, you have to use definition mentioned.
How to use
npm install grpc_tools_node_protoc_ts --save-dev # generate js codes via grpc-tools grpc_tools_node_protoc \--js_out=import_style=commonjs,binary:./your_dest_dir \--grpc_out=./your_dest_dir \--plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` \-I ./proto \./your_proto_dir/*.proto # generate d.ts codes protoc \--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \--ts_out=./your_dest_dir \-I ./proto \./your_proto_dir/*.proto
Sample
There is a complete & runnable sample in folder examples
.
Dirs:
- proto: sample proto definition
- bash: useful commands
- build.sh: build js & d.ts codes from proto file, and tsc to build/*.js
- server.sh: start the sample server
- client.sh: start the client & send requests
book.proto
syntax = "proto3"; package com.book; message Book { int64 isbn = 1; string title = 2; string author = 3;} message GetBookRequest { int64 isbn = 1;} message GetBookViaAuthor { string author = 1;} service BookService { rpc GetBook (GetBookRequest) returns (Book) {} rpc GetBooksViaAuthor (GetBookViaAuthor) returns (stream Book) {} rpc GetGreatestBook (stream GetBookRequest) returns (Book) {} rpc GetBooks (stream GetBookRequest) returns (stream Book) {}} message BookStore { string name = 1; map<int64, string> books = 2;} enum EnumSample { option allow_alias = true; UNKNOWN = 0; STARTED = 1; RUNNING = 1;} // Message with reserved keywords// see: https://github.com/google/protobuf/blob/cc3fa2ec80d196e045ae05797799f079188106f3/js/compatibility_tests/v3.0.0/test.proto#L66-L72message SpecialCases { string normal = 1; // Examples of Js reserved names that are converted to pb_<name>. string default = 2; string function = 3; string var = 4;}
book_pb.d.ts
// package: com.book// file: book.proto /* tslint:disable */ ;
book_grpc_pb.d.ts
// package: com.book// file: book.proto /* tslint:disable */ ;; ;
Changes
2.3.0
Add a new server implementation interface signature, with this the server implementation could be verified. See: Issue#22. And please also check the new example using this new feature: link.
2.2.5
Fix issue of reversed JavaScript keyword code generation. See: Issue#20 & PR#21.
2.2.4
Fix issue of conflicted I{$MethodName} name, see: Issue#19.
2.2.3
Fix definitions. fix: add missing argument grpc.Client~CallOptions for requests
Environment
# npm install grpc@1.9.0 --save node --version# v8.4.0 npm --version# 5.2.0 protoc --version# libprotoc 3.3.0 grpc_tools_node_protoc --version# libprotoc 3.4.0 npm list -g --depth=0 | grep grpc-tools# grpc-tools@1.6.6