npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

protoc-gen-elm-fork

v1.1.1

Published

Elm protoc plugin

Downloads

2

Readme

Elm Plugin for Protocol Buffers build status

This protoc plug-in generates Elm modules from .proto specification files. The generated modules make use of the elm-protocol-buffers library to handle the (de)serialization. They can be used to transmit bytes over HTTP(S) or via web-sockets. However, this plug-in itself does not implement or generate any Remote Procedure Call (RPC) logic.

Take a look here for a general introduction on Protocol Buffers.

Installation

This package is a plug-in for protoc, make sure you have installed it and protoc is available on your path. After installing protoc-gen-elm globally from NPM, protoc will automatically find the binary when you add the --elm_out flag to your command.

npm install --global protoc-gen-elm

You can now turn any .proto file into an Elm module. A similar approach can be used to generate code for C++, Dart, Go, Java, Python, Ruby, C#, Objective C, JavaScript, PHP or another language to build a compliant back-end server!

protoc --elm_out=. api.proto

Overview

The following table gives an overview of how .proto types correspond to Elm types and what their default values are.

| .proto type | Elm type | Default value** | | ------------- | ----------------------------------- | ------------------------------------------------------------------------ | | package | The name of the module | The .proto filename, e.g. proto/api.proto becomes module Proto.Api | | double | Float | 0 | | float | Float | 0 | | int32 | Int | 0 | | int64 | Int* | 0 | | uint32 | Int | 0 | | uint64 | Int* | 0 | | sint32 | Int | 0 | | sint64 | Int* | 0 | | fixed32 | Int | 0 | | fixed64 | Int* | 0 | | bool | Bool | False | | string | String | "" | | bytes | Bytes.Bytes | Empty bytes sequence | | required a | a | No default | | optional a | a | Default of a | | repeated a | List a | [] | | enum | Custom type | First element | | message | Record | All fields take their default value | | a | Maybe Record | Nothing | | oneof | Custom type with an associated data | Nothing | | map<k, v> | Dict.Dict k v | Dict.empty | | service | N/A | | | reserved | N/A | | | extensions | N/A | |

*) 64-bit integers are processed as 32-bit integers, see elm-protocol-buffers

**) Some default values can be overridden in proto2 specifications

Live Example

To run a live example in your browser, first start the example back-end server:

npm install
node example/server.js

The server implements a (basic) back-end for example/greeter.proto. You can now generate an Elm module from the same specification. The example code will use the generated example/src/Proto.Greeter.elm to communicate with the server. Start the reactor and give it a try on http://localhost:8000/src/Main.elm:

cd example
protoc --elm_out=src greeter.proto
elm reactor

Limitations

  • All limitations of elm-protocol-buffers apply;
  • This is still a beta release. Please report any issues you have generating your Elm modules;

Development

Note: Currently, this project won't run on Windows (WSL works) because of shell scripts/executable js files.

Execute npm install, npm run build and npm test and you should be good to go. You will need protoc installed and on your PATH.

  • The plugin logic is written in Elm itself. To be executable via node, there is a index.js wrapper. It converts the incoming bytes to base64, because there currently is no way to directly send the type Bytes through a port.
  • Main.elm essentially wires up the binding to JS: A request is received through a port, gets decoded, processed and then sent through another port.
  • For decoding the protoc request, it uses "itself", meaning that upgrading protoc versions should be done by running the plugin against the new include files from protoc to generate the new encoders/decoders.
  • A Mapper converts the request into a convenient internal structure
  • A Generator then uses this internal structure to build an Elm AST which is then pretty-printed to a file.