All Projects → niklaus0823 → protoc-gen-grpc-ts

niklaus0823 / protoc-gen-grpc-ts

Licence: MIT license
This repo has been moved from niklaus0823/protoc-gen-grpc-ts to stultuss/protoc-gen-grpc-ts, and future versions will be released on stultuss/protoc-gen-grpc-ts

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to protoc-gen-grpc-ts

Protoc Gen Validate
protoc plugin to generate polyglot message validators
Stars: ✭ 1,241 (+7656.25%)
Mutual labels:  protoc
Grpc Java Contrib
Useful extensions for the grpc-java library
Stars: ✭ 176 (+1000%)
Mutual labels:  protoc
vscode-buf
Visual Studio Code integration for Buf.
Stars: ✭ 40 (+150%)
Mutual labels:  protoc
Protobuf
Protocol Buffers - Google's data interchange format
Stars: ✭ 52,305 (+326806.25%)
Mutual labels:  protoc
Goprotowrap
A package-at-a-time wrapper for protoc, for generating Go protobuf code.
Stars: ✭ 147 (+818.75%)
Mutual labels:  protoc
Protobuf Dynamic
Protocol Buffers Dynamic Schema - create protobuf schemas programmatically
Stars: ✭ 186 (+1062.5%)
Mutual labels:  protoc
Protobuf Swift
Google ProtocolBuffers for Apple Swift
Stars: ✭ 925 (+5681.25%)
Mutual labels:  protoc
proto2gql
The project has been migrated to https://github.com/EGT-Ukraine/go2gql.
Stars: ✭ 21 (+31.25%)
Mutual labels:  protoc
Buf
A new way of working with Protocol Buffers.
Stars: ✭ 3,328 (+20700%)
Mutual labels:  protoc
go2gql
graphql-go schema generator by proto files
Stars: ✭ 33 (+106.25%)
Mutual labels:  protoc
Protodot
transforming your .proto files into .dot files (and .svg, .png if you happen to have graphviz installed)
Stars: ✭ 107 (+568.75%)
Mutual labels:  protoc
Pb And K
Kotlin Code Generator and Runtime for Protocol Buffers
Stars: ✭ 137 (+756.25%)
Mutual labels:  protoc
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (+1187.5%)
Mutual labels:  protoc
Protoc Jar
Protocol Buffers protobuf compiler - multi-platform executable protoc JAR and API
Stars: ✭ 103 (+543.75%)
Mutual labels:  protoc
protobuf-maven-plugin
Maven Plugin that executes the Protocol Buffers (protoc) compiler
Stars: ✭ 204 (+1175%)
Mutual labels:  protoc
Ts Protoc Gen
Protocol Buffers Compiler (protoc) plugin for TypeScript and gRPC-Web.
Stars: ✭ 913 (+5606.25%)
Mutual labels:  protoc
Protoc Jar Maven Plugin
Protocol Buffers protobuf maven plugin - based on protoc-jar multi-platform executable protoc JAR
Stars: ✭ 177 (+1006.25%)
Mutual labels:  protoc
protoc-gen-grpc-ts
Protocol compiler plugin for generating grpc interfaces in TypeScript.
Stars: ✭ 33 (+106.25%)
Mutual labels:  grpc-toolkit
powerproto
🎉 An awesome version control tool for protoc and its related plugins.
Stars: ✭ 161 (+906.25%)
Mutual labels:  protoc
protokit
A starter kit for building protoc plugins. Rather than write your own, you can just use an existing one.
Stars: ✭ 69 (+331.25%)
Mutual labels:  protoc

protoc-gen-grpc

NPM Version NPM Downloads Build Linux Build Windows Build Test Coverage

Protocol compiler plugin for generating grpc interfaces in TypeScript.

Notes

This repo has been moved from niklaus0823/protoc-gen-grpc-ts to stultuss/protoc-gen-grpc-ts, and future versions will be released on stultuss/protoc-gen-grpc-ts

Aim

This project was forked from agreatfool/grpc_tools_node_protoc_ts, and was intended to fix an error in Window10: %1 XXX not a valid win32 application

  • difference
    • No other tools (or npm global package) need to be installed. such as protoc, grpc_tools
    • Remove handlebar template engine.
    • Support: Linux, OSX, Windows

WARN

node-pre-gyp WARN Using needle for node-pre-gyp https download node-pre-gyp ERR! install error node-pre-gyp ERR! stack Error: There was a fatal problem while downloading/extracting the tarball

issue:mapbox/node-pre-gyp#462

npm install request -g

Install

npm config set unsafe-perm true
npm install protoc-gen-grpc -g

If you don't want to set up a public configuration for NPM, you can try to add after the installation command -unsafe-perm parameters.

How to use

# generate js codes
protoc-gen-grpc \
--js_out=import_style=commonjs,binary:./examples/src/proto \
--grpc_out=./examples/src/proto \
--proto_path ./examples/proto \
./examples/proto/book.proto

# generate d.ts codes
protoc-gen-grpc-ts \
--ts_out=service=true:./examples/src/proto \
--proto_path ./examples/proto \
./examples/proto/book.proto

Example

There is a complete & runnable example in folder examples.

## bash1
cd ./examples
sh ./bash/build.sh  # build js & d.ts codes from proto file, and tsc to build/*.js
sh ./bash/server.sh # start the grpc server

## bash2
cd ./examples
sh ./bash/client.sh # start the grpc client & send requests

book.proto

syntax = "proto3";

package com.book;

message Book {
    int64 isbn = 1;
    string title = 2;
    string author = 3;
}

message GetBookRequest {
    int64 isbn = 1;
}

message GetBookViaAuthorRequest {
    string author = 1;
}

service BookService {
    rpc GetBook (GetBookRequest) returns (Book) {}
    rpc GetBooksViaAuthor (GetBookViaAuthorRequest) returns (stream Book) {}
    rpc GetGreatestBook (stream GetBookRequest) returns (Book) {}
    rpc GetBooks (stream GetBookRequest) returns (stream Book) {}
}

message BookStore {
    string name = 1;
    map<int64, string> books = 2;
}

enum EnumSample {
    option allow_alias = true;
    UNKNOWN = 0;
    STARTED = 1;
    RUNNING = 1;
}

book_pb.d.ts

// package: com.book
// file: book.proto

import * as jspb from 'google-protobuf';

export class Book extends jspb.Message {
  getIsbn(): number;
  setIsbn(value: number): void;

  getTitle(): string;
  setTitle(value: string): void;

  getAuthor(): string;
  setAuthor(value: string): void;

  serializeBinary(): Uint8Array;
  toObject(includeInstance?: boolean): Book.AsObject;
  static toObject(includeInstance: boolean, msg: Book): Book.AsObject;
  static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
  static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
  static serializeBinaryToWriter(message: Book, writer: jspb.BinaryWriter): void;
  static deserializeBinary(bytes: Uint8Array): Book;
  static deserializeBinaryFromReader(message: Book, reader: jspb.BinaryReader): Book;
}

export namespace Book {
  export type AsObject = {
    isbn: number,
    title: string,
    author: string,
  }
}

export class GetBookRequest extends jspb.Message {
  getIsbn(): number;
  setIsbn(value: number): void;

  serializeBinary(): Uint8Array;
  toObject(includeInstance?: boolean): GetBookRequest.AsObject;
  static toObject(includeInstance: boolean, msg: GetBookRequest): GetBookRequest.AsObject;
  static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
  static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
  static serializeBinaryToWriter(message: GetBookRequest, writer: jspb.BinaryWriter): void;
  static deserializeBinary(bytes: Uint8Array): GetBookRequest;
  static deserializeBinaryFromReader(message: GetBookRequest, reader: jspb.BinaryReader): GetBookRequest;
}

export namespace GetBookRequest {
  export type AsObject = {
    isbn: number,
  }
}

export class GetBookViaAuthorRequest extends jspb.Message {
  getAuthor(): string;
  setAuthor(value: string): void;

  serializeBinary(): Uint8Array;
  toObject(includeInstance?: boolean): GetBookViaAuthorRequest.AsObject;
  static toObject(includeInstance: boolean, msg: GetBookViaAuthorRequest): GetBookViaAuthorRequest.AsObject;
  static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
  static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
  static serializeBinaryToWriter(message: GetBookViaAuthorRequest, writer: jspb.BinaryWriter): void;
  static deserializeBinary(bytes: Uint8Array): GetBookViaAuthorRequest;
  static deserializeBinaryFromReader(message: GetBookViaAuthorRequest, reader: jspb.BinaryReader): GetBookViaAuthorRequest;
}

export namespace GetBookViaAuthorRequest {
  export type AsObject = {
    author: string,
  }
}

export class BookStore extends jspb.Message {
  getName(): string;
  setName(value: string): void;

  getBooksMap(): jspb.Map<number, string>;
  clearBooksMap(): void;
  serializeBinary(): Uint8Array;
  toObject(includeInstance?: boolean): BookStore.AsObject;
  static toObject(includeInstance: boolean, msg: BookStore): BookStore.AsObject;
  static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
  static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
  static serializeBinaryToWriter(message: BookStore, writer: jspb.BinaryWriter): void;
  static deserializeBinary(bytes: Uint8Array): BookStore;
  static deserializeBinaryFromReader(message: BookStore, reader: jspb.BinaryReader): BookStore;
}

export namespace BookStore {
  export type AsObject = {
    name: string,
    booksMap: Array<[number, string]>,
  }
}

export enum EnumSample {
  UNKNOWN = 0,
  STARTED = 1,
  RUNNING = 1,
}

book_grpc_pb.d.ts

// package: com.book
// file: book.proto

import * as grpc from 'grpc';
import * as book_pb from './book_pb';

interface IBookServiceService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
  getBook: IBookServiceService_IGetBook;
  getBooksViaAuthor: IBookServiceService_IGetBooksViaAuthor;
  getGreatestBook: IBookServiceService_IGetGreatestBook;
  getBooks: IBookServiceService_IGetBooks;
}

interface IBookServiceService_IGetBook {
  path: string; // "/com.book.BookService/GetBook"
  requestStream: boolean; // false
  responseStream: boolean; // false
  requestSerialize: grpc.serialize<book_pb.GetBookRequest>;
  requestDeserialize: grpc.deserialize<book_pb.GetBookRequest>;
  responseSerialize: grpc.serialize<book_pb.Book>;
  responseDeserialize: grpc.deserialize<book_pb.Book>;
}

interface IBookServiceService_IGetBooksViaAuthor {
  path: string; // "/com.book.BookService/GetBooksViaAuthor"
  requestStream: boolean; // false
  responseStream: boolean; // true
  requestSerialize: grpc.serialize<book_pb.GetBookViaAuthorRequest>;
  requestDeserialize: grpc.deserialize<book_pb.GetBookViaAuthorRequest>;
  responseSerialize: grpc.serialize<book_pb.Book>;
  responseDeserialize: grpc.deserialize<book_pb.Book>;
}

interface IBookServiceService_IGetGreatestBook {
  path: string; // "/com.book.BookService/GetGreatestBook"
  requestStream: boolean; // true
  responseStream: boolean; // false
  requestSerialize: grpc.serialize<book_pb.GetBookRequest>;
  requestDeserialize: grpc.deserialize<book_pb.GetBookRequest>;
  responseSerialize: grpc.serialize<book_pb.Book>;
  responseDeserialize: grpc.deserialize<book_pb.Book>;
}

interface IBookServiceService_IGetBooks {
  path: string; // "/com.book.BookService/GetBooks"
  requestStream: boolean; // true
  responseStream: boolean; // true
  requestSerialize: grpc.serialize<book_pb.GetBookRequest>;
  requestDeserialize: grpc.deserialize<book_pb.GetBookRequest>;
  responseSerialize: grpc.serialize<book_pb.Book>;
  responseDeserialize: grpc.deserialize<book_pb.Book>;
}

export const BookServiceService: IBookServiceService;
export interface IBookServiceServer {
  getBook: grpc.handleUnaryCall<book_pb.GetBookRequest, book_pb.Book>;
  getBooksViaAuthor: grpc.handleServerStreamingCall<book_pb.GetBookViaAuthorRequest, book_pb.Book>;
  getGreatestBook: grpc.handleClientStreamingCall<book_pb.GetBookRequest, book_pb.Book>;
  getBooks: grpc.handleBidiStreamingCall<book_pb.GetBookRequest, book_pb.Book>;
}

export interface IBookServiceClient {
  getBook(request: book_pb.GetBookRequest, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
  getBook(request: book_pb.GetBookRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
  getBooksViaAuthor(request: book_pb.GetBookViaAuthorRequest, metadata?: grpc.Metadata): grpc.ClientReadableStream<book_pb.Book>;
  getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.Book>;
  getGreatestBook(metadata: grpc.Metadata, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.Book>;
  getBooks(metadata?: grpc.Metadata): grpc.ClientDuplexStream<book_pb.GetBookRequest, book_pb.Book>;
}

export class BookServiceClient extends grpc.Client implements IBookServiceClient {
  constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
  public getBook(request: book_pb.GetBookRequest, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
  public getBook(request: book_pb.GetBookRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
  public getBooksViaAuthor(request: book_pb.GetBookViaAuthorRequest, metadata?: grpc.Metadata): grpc.ClientReadableStream<book_pb.Book>;
  public getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.Book>;
  public getGreatestBook(metadata: grpc.Metadata, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.Book>;
  public getBooks(metadata?: grpc.Metadata): grpc.ClientDuplexStream<book_pb.GetBookRequest, book_pb.Book>;
}

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].