Skip to content

A protoc plugin that generates Protobuf.js service implementations for Twirp

License

Notifications You must be signed in to change notification settings

tesspib/protoc-gen-twirp_javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protoc-gen-twirp_javascript

A protoc plugin that generates Protobuf.js service implementations for Twirp.

This plugin supports the following Protobuf.js output formats:

  1. JSON descriptors, which rely on reflection
  2. Static JavaScript modules

See Protobuf.js documentation for more details about those formats.

Parameters

This plugin has two parameters, explained below. Bold values are the defaults.

Name Description Values
pbjs_format Output format of the file generated by pbjs
  • json
  • static-module
twirp_version Version of the Twirp protocol specification to use.
  • v6
  • v5

Usage

The plugin generates code with import paths that expect files generated by pbjs to be in the same directory as the plugin output file(s), with the same name as the source .proto file.

With JSON descriptors

Consider the following directory structure:

.
├── foo
│   ├── bar.proto           # Source Protobuf file
│   └── bar.json            # JSON descriptors that correspond to the Protobuf file, generated by Protobuf.js
└── ...

To generate the RPC client:

$ protoc --proto_path=. --twirp_javascript_output=pbjs_format=json:. ./foo/bar.proto

Result:

.
├── foo
│   ├── bar.json
│   ├── bar.proto
│   └── bar.twirp.js        # Plugin output file
└── ...

A few things to note:

  • Contrary to the JSON file generated by pbjs, the source .proto is not directly used by the generated RPC client. This is a plugin limitation, as Protobuf.js itself supports loading of .proto files. Support may be added at a later point.
  • The JSON file is only used at runtime and the plugin does not need it to generate the RPC client. That property can be taken advantage of when protoc output directory layout is not known in advance: first invoke protoc-gen-twirp_javascript, and then pbjs with the now known target directory.

With static modules

Almost all of the information in the JSON descriptors section also applies here. .json extension is replaced by .pb.js.

To generate the RPC client:

$ protoc --proto_path=. --twirp_javascript_output=pbjs_format=static-module:. ./foo/bar.proto

About

A protoc plugin that generates Protobuf.js service implementations for Twirp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published