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

proto-gen-dts

v0.20.0

Published

proto generate typescript dictionary type file

Downloads

681

Readme

npm size test NPM downloads

proto-gen-dts

Convert proto file to typescript type definition file;
All that is needed at present has been completed, enjoy 😊

Install

# global
npm i proto-gen-dts -g

Features

  • ✔︎ Support proto2 proto3
  • ✔︎ Support generate proto dependent modules
  • ✔︎ Support generate dts entry file
  • ✔︎ Support all proto message type
  • ✔︎ Support generate service to interfaces
  • ✔︎ Keep generating comments and order

Special comment support

  • @v: required interface field well required

Usage

// use in nodejs
const protoGenDts = require('proto-gen-dts');

const dtsFiles = protoGenDts.default({
  files: [
    {
      file: 'hello.proto',
      output: 'typings/hello.d.ts',
      generateDependentModules: true
    }
  ],
  referenceEntryFile: 'typings/index.d.ts'
})
# use in shell
# single file
proto-gen-dts hello.proto -o typings/hello.d.ts -e typings/index.d.ts
# dir
proto-gen-dts -d protos/ -o typings/
# use npx
npx proto-gen-dts -d protos/ -o typings/
# --keepcase, Converted to camel case by default
proto-gen-dts -d protos/ -o typings/ --keepcase

Example

Source hello.proto

syntax = "proto3";

import "core.proto";
import "google/protobuf/any.proto";
import "google/protobuf/descriptor.proto";

package hello;

service Hello {
  /**
   * hello
   */
  rpc SayName (SayNameReq) returns (SayNameRsp) {};
  // remark
  // get user list
  rpc GetUserList (GetUserListReq) returns (GetUserListRsp) {};

  rpc GetSayNameUser (SayNameReq.User) returns (SayNameReq.User) {}
}

message Core {
  string first_name = 1;
}

enum Direct {
  Nil = 0;
  Up = 1;
  Down = 2;
}

// 测试评论
message SayNameReq {
  // 用户模型
  message User {
    // 用户名
    string name = 1;
    string avatar = 2;

    enum Role {
      RoleNil = 0;
      // admin
      RoleAdmin = 1;
    }
  }
  string full_name = 1;
  Core core = 2;
  repeated User user = 3;
  Direct direct = 4;
}

message SayNameRsp {
  message Stock {
    // Stock-specific data
  }

  message Currency {
    // Currency-specific data
  }
  string realName = 1;
  map<uint32, SayNameReq.User> user_map = 2;
  map<uint32, SayNameReq.User.Role> role_map = 3;
  map<uint32, uint64> link_map = 4;
  repeated google.protobuf.Any details = 5;
  oneof instrument {
    Stock stock = 6;
    Currency currency = 7;
  }
  google.protobuf.FieldDescriptorProto field_descriptor = 8;
}

message GetUserListReq {
  core.XXX xxx = 1;
  core.ListOptions.Option option = 2;
}
message GetUserListRsp {}

Output typings/hello.d.ts

/** code generate by proto-gen-dts don't edit */

declare namespace hello {
  export interface HelloService {
    // hello
    SayName<R extends SayNameReq, O>(r: R, o?: O): Promise<SayNameRsp>;
    // remark
    // get user list
    GetUserList<R extends GetUserListReq, O>(
      r: R,
      o?: O
    ): Promise<GetUserListRsp>;

    GetSayNameUser<R extends SayNameReq_User, O>(
      r: R,
      o?: O
    ): Promise<SayNameReq_User>;
  }

  export interface Core {
    firstName?: string;
  }

  export const enum Direct {
    Nil = 0,
    Up = 1,
    Down = 2,
  }

  // 测试评论
  export interface SayNameReq {
    fullName?: string;
    core?: Core;
    user?: SayNameReq_User[];
    direct?: Direct;
  }

  // 用户模型
  export interface SayNameReq_User {
    // 用户名
    name?: string;
    avatar?: string;
  }

  export const enum SayNameReq_User_Role {
    RoleNil = 0,
    // admin
    RoleAdmin = 1,
  }

  export interface SayNameRsp {
    realName?: string;
    userMap?: Record<number, SayNameReq_User>;
    roleMap?: Record<number, SayNameReq_User_Role>;
    linkMap?: Record<number, string>;
    details?: google.protobuf.Any[];
    stock?: SayNameRsp_Stock;
    currency?: SayNameRsp_Currency;
    fieldDescriptor?: google.protobuf.FieldDescriptorProto;
  }

  export interface SayNameRsp_Stock {}

  export interface SayNameRsp_Currency {}

  export interface GetUserListReq {
    xxx?: core.XXX;
    option?: core.ListOptions_Option;
  }

  export interface GetUserListRsp {}
}

referenceEntryFile output typings/index.d.ts

/** code generate by proto-gen-dts don't edit */

/// <reference path="hello.d.ts" />
/// <reference path="core.d.ts" />
/// <reference path="google/protobuf/any.d.ts" />
/// <reference path="google/protobuf/descriptor.d.ts" />

generateDependentModules will generate dependent modules

  • typings/core.d.ts
  • typings/google/protobuf/any.d.ts
  • typings/google/protobuf/descriptor.d.ts