This is a tool for consuming Protocol Buffer DSL files and extracting Messages and Enums out, converting them into TypeScript native code.
This is somewhat similar to the
official protoc
binary, in that
it can be used to generate code from the DSL, but this tool is very different in
that it is fully written in TypeScript, and is designed to only output
TypeScript.
To install:
# Needs `--allow-read` to be able to read .proto files
# Needs `--allow-write` to be able to write pb.ts files
deno install --allow-read --allow-write https://deno.land/x/protod/protod.ts
protod gen my.proto
You can compare the example .proto
and .pb.ts
files in the
./testdata/
directory. They are designed to look like files a
human might actually write; readability is important for debugability!
That would have potentially been much easier than writing an entire Protocol Buffers DSL parser from scratch, but there are several reasons why this tool was created:
protoc
binary is seriously unwieldy to use.Having said that, this tool - not being officially supported - should be considered caveat emptor. There are likely bugs or inconsistencies between this and official implementations. If you find one, please send a PR with a failing test!
Well, aside from answering some of that in the above question, there are also some problems with the official JS plugin. Chiefly:
setName()
, setAge()
are used rather than simple field properties.