Skip to content

midwayjs/grpc-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f450dff · Oct 15, 2022

History

25 Commits
Oct 15, 2022
Oct 15, 2022
Oct 15, 2022
Oct 15, 2022
Feb 17, 2021
Feb 17, 2021
Jan 12, 2021
Feb 17, 2021
Oct 15, 2022
Mar 16, 2021
Oct 15, 2022
Oct 15, 2022
Apr 22, 2021
Jan 12, 2021

Repository files navigation

Midway gRPC interface generator

code fork from https://github.com/AlexDaSoul/nestjs-proto-gen-ts

Installation

$ npm install @midwayjs/grpc-helper --save-dev

Example

Protobuf file hero-proto/hero.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:

$ tsproto --path ./hero-proto

Output:

import * as grpc from '@midwayjs/grpc';

export namespace hero {
  export interface HeroService {
    findOne(data: HeroById): Promise<Hero>;
  }
  /**
   * HeroService client interface
   */
  export interface HeroServiceClient {
    findOne(options?: grpc.IClientOptions): grpc.IClientUnaryService<HeroById, Hero>;
  }
  export interface HeroById {
    id?: number;
  }
  export interface Hero {
    id?: number;
    name?: string;
  }
}

Usage

Base usage:

$ tsproto --path grpc-proto

Output dir:

$ tsproto --path grpc-proto --output any-dir

Target files:

$ tsproto --path grpc-proto --target one.proto two.proto

Ignore directories or files:

$ 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]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published