Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/means88/tsbuf
Generate TypeScript enum and interface from proto buffer.
https://github.com/means88/tsbuf
parser protobuf
Last synced: about 10 hours ago
JSON representation
Generate TypeScript enum and interface from proto buffer.
- Host: GitHub
- URL: https://github.com/means88/tsbuf
- Owner: Means88
- Created: 2018-10-25T15:06:27.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T16:33:38.000Z (11 months ago)
- Last Synced: 2025-01-09T09:10:46.214Z (1 day ago)
- Topics: parser, protobuf
- Language: TypeScript
- Homepage:
- Size: 3.28 MB
- Stars: 11
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tsbuf [![npm@version](https://img.shields.io/npm/v/tsbuf.svg)](https://www.npmjs.com/package/tsbuf) [![Build Status](https://travis-ci.org/Means88/tsbuf.svg?branch=master)](https://travis-ci.org/Means88/tsbuf) [![Coverage Status](https://coveralls.io/repos/github/Means88/tsbuf/badge.svg?branch=master)](https://coveralls.io/github/Means88/tsbuf?branch=master)
Generate TypeScript enum and interface with proto buffer.
## Usage
```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 output path (default: ".")
-m, --mode "global": Global Definition, "module": Module Definition (default: "global")
-h, --help output usage information```
## 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;
}```
### How to use interfaces from service?
Create specified types using TypeScript as follows.
```typescript
import { MyService } from '...';
import { Observable } from 'rxjs';interface BaseServiceDefinition {
[key: string]: {
request: any;
response: any;
};
}type RxService = {
[K in keyof T]: (request: T[K]['request']) => Observable;
};/**
* `RxService` equals:
*
* interface {
* rpcMethod(request: Request): Observable;
* }
*
**/```
## Roadmap
- [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## License
MIT