https://github.com/midwayjs/grpc-helper
https://github.com/midwayjs/grpc-helper
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/midwayjs/grpc-helper
- Owner: midwayjs
- Created: 2021-01-12T15:01:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-10-15T03:50:35.000Z (almost 4 years ago)
- Last Synced: 2025-03-21T23:02:58.978Z (over 1 year ago)
- Language: TypeScript
- Size: 42 KB
- Stars: 2
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
Awesome Lists containing this project
README
# Midway gRPC interface generator
code fork from https://github.com/AlexDaSoul/nestjs-proto-gen-ts
## Installation
```bash
$ npm install @midwayjs/grpc-helper --save-dev
```
## Example
Protobuf file hero-proto/hero.proto:
```proto
syntax = "proto3";
package hero;
service HeroesService {
rpc FindOne (HeroById) returns (Hero) {}
}
message HeroById {
int32 id = 1;
}
message Hero {
int32 id = 1;
string name = 2;
}
```
Generate interfaces:
```bash
$ tsproto --path ./hero-proto
```
Output:
```ts
import * as grpc from '@midwayjs/grpc';
export namespace hero {
export interface HeroService {
findOne(data: HeroById): Promise;
}
/**
* HeroService client interface
*/
export interface HeroServiceClient {
findOne(options?: grpc.IClientOptions): grpc.IClientUnaryService;
}
export interface HeroById {
id?: number;
}
export interface Hero {
id?: number;
name?: string;
}
}
```
## Usage
Base usage:
```bash
$ tsproto --path grpc-proto
```
Output dir:
```bash
$ tsproto --path grpc-proto --output any-dir
```
Target files:
```bash
$ tsproto --path grpc-proto --target one.proto two.proto
```
Ignore directories or files:
```bash
$ tsproto --path grpc-proto --ignore grpc-proto/ignore-dir
```
## Options
The following options are available:
```
--version, -v Show version number [boolean]
--help, -h Show help [boolean]
--path, -p Path to root directory [array] [required]
--output, -o Path to output directory [string]
--target, -t Proto files [array] [default: [".proto"]]
--ignore, -i Ignore file or directories
[array] [default: ["node_modules","dist"]]
--comments, -c Add comments from proto [boolean] [default: true]
--verbose Log all output to console [boolean] [default: true]
--keepCase, -k keep property case [boolean] [default: true]
```