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

protos-ts

v0.1.4

Published

CLI compiler of protocol buffer schemas to typescript es modules

Downloads

3

Readme

protos-ts

This a CLI tool for transforming of .proto files into typescript modules. It is faster alternative to protobufjs package.

Install

# global install
npm install --global protos-ts

# local install
npm install -D protos-ts

Rationale

protobufjs is currently used as a main javascript(and typesript) compiler. But there are several problems with this tool.

It produces single large javascript file. It does not have typings by default. Types are introduced as external index.d.ts file.

What are the results of it? It is not easily tree-shakable.

Usually the case is that some messages in your project are "encode"-only and some of the are "decode" only. But since they are highly coupled - you must load both encoding and decoding functions. This tool for each message creates separated folder with all necessary function placed in it's own place.

Also protobufjs uses JS to read, parse and compile .proto schemas to javascript. This tool is written in Rust. So as a result it is faster than [protobufjs] alternative.

How to use

Example:

# if installed locally
protos-ts ./proto --out ./typescript-schemas

# via npx
npx protos-ts ./proto --out ./typescript-schemas

As you can see it has such structure:

protos-ts <input folder full of .proto files> --out <output folder>

input folder full of .proto files is a folder that contains all of your .proto files.

Example:

proto
 | Action.proto
 | Commons
    | Enums.proto
    | Types.proto

output folder is the folder where you want your typescript files to appear.

Result

out
  | Action
    | MyMessage
      | decode.ts
      | encode.ts
  | Commons
    | Enums
      | MyEnum.ts
    | types.ts

These typescript files use protobufjs/minimal to decode and encode protocol buffers types. So in order to use them after compilation you need protobufjs to be installed.

Performance

I didn't do it properly. But on my computer I've compared this implementation with official compiler; I've took protocol buffer files from my work project and compiled both of them several times and took minimum.

This compiler: 0.9s
official: 7s

Actually it is difficult to compare them because they do a different job.

Official protobuf.js compiler generates big large file. While this compiler produces hierarchy of different files. Therefore we have much more IO operations.

I've found that in my compiler 92% of the time is spent in IO operations to the harddrive.

collect file names 5.328ms
parsing files 44.7105ms
compiling files to typescript 33.6335ms
saving typescript files 1.0607062s
Full Time 1.1485477s