Code Monkey home page Code Monkey logo

deno-protod's Introduction

Protod

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

Potential Questions Asked

What does the output look like?

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!

Why isn't this a plugin for protoc?

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:

  • The protoc binary is seriously unwieldy to use.
  • The Protocol Buffer "standard" is a single C library which is a manually written tokenizer/parser, and could really do with some alternative implementations.
  • Being fully written in TypeScript (the parser and generator) makes it easier for developers to get involved in the tooling.
  • The plan for this tool is to grow into linting, formatting, and doc generation, in the spirit of Deno/Go.

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!

Why not just use the JS protoc plugin?

Well, aside from answering some of that in the above question, there are also some problems with the official JS plugin. Chiefly:

  • It's written JS first, and while it does have TypeScript definitions, which means for example Enums are not TypeScript first class Enums.
  • The output is also relatively difficult to read - given it uses non-standard JS features such as the Google Closure Compiler module system.
  • The API the generated code features is a little unwieldy too. Method names like setName(), setAge() are used rather than simple field properties.

deno-protod's People

Contributors

ablause avatar jul-sh avatar kaaninel avatar keithamus avatar seishun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.