Generate TypeScript enum and interface with proto buffer.
npm install tsbuf-nestjsGenerate TypeScript enum and interface with proto buffer.
bash
npm install -g tsbuf
tsbuf example/proto -o example/typescript/global
or
tsbuf example/proto -o example/typescript/module -m module`
See example/`console
$ tsbuf -h
Usage: tsbuf [options] protobuf-parser
Generate TypeScript interface with Protobuf.
Options:
-V, --version output the version number
-o, --output
`Example
`proto
syntax = "proto3";service MyService {
rpc rpcMethod(Fruit) returns (Package) {}
}
enum Fruit {
Apple = 0;
Banana = 1;
}
message Package {
string id = 1;
float price = 2;
}
`
Will be transformed to`typescript
interface MyService {
rpcMethod: {
request: Request;
response: Response;
};
}declare enum Fruit {
Apple = 0,
Banana = 1,
}
interface Package {
id: string;
price: number;
}
`
Or TypeScript module
`typescript
export interface MyService {
rpcMethod: {
request: Request;
response: Response;
};
}export enum Fruit {
Apple = 0,
Banana = 1,
}
export interface Package {
id: string;
price: number;
}
``- [x] Basic Support
- [x] ExtendedType Field
- [x] Cli
- [x] Oneof Field
- [x] Map Field
- [x] Nested Type
- [x] Generate Global Declaration
- [x] Import (Generate Module)
- [ ] Other Options