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

protobuf2flowtype-typetool

v1.1.9

Published

Given protobuf file will generate node packages which export protobufjs builders annotated with flowtype type anotations

Downloads

9

Readme

This is the forked branch from https://github.com/netproteus/protobuf2flowtype

npm version CircleCI codecov

protobuf2flowtype

The aim of this project is to allow flowtype checking of protobuf messages created using protobufjs

This is achieved by generating modules that match the namespaces within your protobuf deinition which export the protobufjs builder for that namespace but also include all the nessisary flowtype annotations for the messages and enums declared in that namespace.

The generated code has a runtime dependency on this module for flowtype checking only. The generated code includes the flowtype annotations inside special comment blocks so the code is fully ES5 compatible and doesn't require transpiling to run.

Usage

CLI

npm install --save protobuf2flowtype
node_modules/.bin/protobuf2flowtype --outDir src/proto --protoFile main.proto --protoRoot proto

API

const generate = require('protobuf2flowtype/build/generate'); 

generate('src/proto', 'main.proto', 'proto');

Example

###main.proto

package foo;

message Greeting {

    required string text = 1;

};

message Chat {

    required Greeting greeting = 1;
    optional string body = 2;
};

###generated code

.
├── foo
│   ├── Chat
│   │   └── index.js
│   ├── Greeting
│   │   └── index.js
│   └── index.js
└── index.js

###index.js

// @flow
Object.defineProperty(exports, "__esModule", {
  value: true
});

const _package = require('./package.json');

const jsonDescriptor = {
  "package": "foo",
  "messages": [{
    "name": "Greeting",
    "fields": [{
      "rule": "required",
      "type": "string",
      "name": "text",
      "id": 1
    }]
  }, {
    "name": "Chat",
    "fields": [{
      "rule": "required",
      "type": "Greeting",
      "name": "greeting",
      "id": 1
    }, {
      "rule": "optional",
      "type": "string",
      "name": "body",
      "id": 2
    }]
  }]
};

const ProtoBuf = require('protobufjs');

const builder = exports.builder = ProtoBuf.loadJson(jsonDescriptor);
exports.default = builder;

###foo/index.js

// @flow
Object.defineProperty(exports, "__esModule", {
  value: true
});

const _ = require('../index');

exports.builder = _.builder; /*::
import { Protobuf$Message } from 'protobuf2flowtype';
import type { ByteBuffer, ProtoBuf$Builder, ProtoBuf$MessageLiteral, Protobuf$RefectType } from 'protobuf2flowtype';
interface GreetingInterface extends ProtoBuf$MessageLiteral {
  text: string
}
;
type GreetingReflect = Protobuf$RefectType<GreetingInterface>;
declare class GreetingBuilder extends Protobuf$Message<GreetingInterface, GreetingReflect> {
  constructor: (values: GreetingInterface) => GreetingBuilder;
  text: string;
  getText: () => string;
  setText: (text: string) => void;
}
;
interface ChatInterface extends ProtoBuf$MessageLiteral {
  greeting: $Subtype<GreetingInterface>;
  body?: ?string;
}
;
type ChatReflect = Protobuf$RefectType<ChatInterface>;
declare class ChatBuilder extends Protobuf$Message<ChatInterface, ChatReflect> {
  constructor: (values: ChatInterface) => ChatBuilder;
  greeting: GreetingBuilder;
  getGreeting: () => GreetingBuilder;
  setGreeting: (greeting: GreetingBuilder) => void;
  body?: ?string;
  getBody: () => ?string;
  setBody: (body: ?string) => void;
}
;
type foo = {
  Greeting: Class<GreetingBuilder>;
  Chat: Class<ChatBuilder>;
};
export type { GreetingInterface, GreetingBuilder, GreetingReflect, ChatInterface, ChatBuilder, ChatReflect }; */

const namespace /*: foo */ = _.builder.build('foo');

exports.Greeting = namespace.Greeting; /*::
export const Greeting = namespace.Greeting; */
exports.Chat = namespace.Chat; /*::
export const Chat = namespace.Chat; */
exports.default = namespace; /*::
export default namespace; */

###Usage

/* @flow */
import {Chat, Greating} from './proto/foo';

const chat: Chat = new Chat({
    greeting: new Greating({ text: 'hello'}),
    body: 'some text'
});

##Missing features Currently doesn't support

  • Passing constructor arguments to protobufjs builders
  • service definitions
  • map fields