Code Monkey home page Code Monkey logo

protoc-gen-grpc-ts's Introduction

protoc-gen-grpc

NPM Version NPM Downloads Build Test Coverage

Protocol compiler plugin for generating grpc interfaces in TypeScript.

WARN

About Apple M1 arm64

npm_config_target_arch=x64 npm i grpc-tools

About 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

Example

Please try ./example/build.sh

Support - grpc-js

bash

# generate js codes with @grpc/grpc-js
protoc-gen-grpc \
--js_out=import_style=commonjs,binary:${OUTPUT_DEST} \
--grpc_out=grpc_js:./examples/src/proto \
--proto_path ./examples/proto \
./examples/proto/student.proto

# generate d.ts codes with @grpc/grpc-js
protoc-gen-grpc-ts \
--ts_out=grpc_js:./examples/src/proto \
--proto_path ./examples/proto \
./examples/proto/student.proto

server.ts

// support grpc-js
import * as grpc from '@grpc/grpc-js';
...
...
const server = new grpc.Server();
server.addService(ProductServiceService, ServerImpl);

Support - grpc

bash

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

# generate d.ts codes with grpc
protoc-gen-grpc-ts \
--ts_out=./examples/src/proto \
--proto_path ./examples/proto \
./examples/proto/student.proto

server.ts

// support grpc-js
import * as grpc from 'grpc';
...
...
const server = new grpc.Server();
server.addService(ProductServiceService, new ServerImpl());

Example

There is a complete & runnable example in folder examples.

## bash1
cd ./examples
npm install
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
npm install
sh ./bash/client.sh # start the grpc client & send requests

product.proto

syntax = "proto3";

package com.product;

message Product {
    int64 id = 1;
    string name = 2;
    string category = 3;
}

message GetProductRequest {
    int64 id = 1;
}

message GetProductViaCategoryRequest {
    string category = 1;
}

service ProductService {
    rpc GetProduct (GetProductRequest) returns (Product) {}
    rpc GetProductViaCategory (GetProductViaCategoryRequest) returns (stream Product) {}
    rpc GetBestProduct (stream GetProductRequest) returns (Product) {}
    rpc GetProducts (stream GetProductRequest) returns (stream Product) {}
}

message Shop {
    string name = 1;
    map<int64, Product> list = 2;
}

product_grpc_pb.d.ts

// package: com.product
// file: product.proto

import * as grpc from '@grpc/grpc-js';
import * as product_pb from './product_pb';

interface IProductServiceService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
  getProduct: IProductServiceService_IGetProduct;
  getProductViaCategory: IProductServiceService_IGetProductViaCategory;
  getBestProduct: IProductServiceService_IGetBestProduct;
  getProducts: IProductServiceService_IGetProducts;
}

interface IProductServiceService_IGetProduct extends grpc.MethodDefinition<product_pb.GetProductRequest, product_pb.Product> {
  path: '/com.product.ProductService/GetProduct'
  requestStream: false
  responseStream: false
  requestSerialize: grpc.serialize<product_pb.GetProductRequest>;
  requestDeserialize: grpc.deserialize<product_pb.GetProductRequest>;
  responseSerialize: grpc.serialize<product_pb.Product>;
  responseDeserialize: grpc.deserialize<product_pb.Product>;
}

interface IProductServiceService_IGetProductViaCategory extends grpc.MethodDefinition<product_pb.GetProductViaCategoryRequest, product_pb.Product> {
  path: '/com.product.ProductService/GetProductViaCategory'
  requestStream: false
  responseStream: true
  requestSerialize: grpc.serialize<product_pb.GetProductViaCategoryRequest>;
  requestDeserialize: grpc.deserialize<product_pb.GetProductViaCategoryRequest>;
  responseSerialize: grpc.serialize<product_pb.Product>;
  responseDeserialize: grpc.deserialize<product_pb.Product>;
}

interface IProductServiceService_IGetBestProduct extends grpc.MethodDefinition<product_pb.GetProductRequest, product_pb.Product> {
  path: '/com.product.ProductService/GetBestProduct'
  requestStream: true
  responseStream: false
  requestSerialize: grpc.serialize<product_pb.GetProductRequest>;
  requestDeserialize: grpc.deserialize<product_pb.GetProductRequest>;
  responseSerialize: grpc.serialize<product_pb.Product>;
  responseDeserialize: grpc.deserialize<product_pb.Product>;
}

interface IProductServiceService_IGetProducts extends grpc.MethodDefinition<product_pb.GetProductRequest, product_pb.Product> {
  path: '/com.product.ProductService/GetProducts'
  requestStream: true
  responseStream: true
  requestSerialize: grpc.serialize<product_pb.GetProductRequest>;
  requestDeserialize: grpc.deserialize<product_pb.GetProductRequest>;
  responseSerialize: grpc.serialize<product_pb.Product>;
  responseDeserialize: grpc.deserialize<product_pb.Product>;
}

export const ProductServiceService: IProductServiceService;
export interface IProductServiceServer extends grpc.UntypedServiceImplementation {
  getProduct: grpc.handleUnaryCall<product_pb.GetProductRequest, product_pb.Product>;
  getProductViaCategory: grpc.handleServerStreamingCall<product_pb.GetProductViaCategoryRequest, product_pb.Product>;
  getBestProduct: grpc.handleClientStreamingCall<product_pb.GetProductRequest, product_pb.Product>;
  getProducts: grpc.handleBidiStreamingCall<product_pb.GetProductRequest, product_pb.Product>;
}

export interface IProductServiceClient {
  getProduct(request: product_pb.GetProductRequest, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientUnaryCall;
  getProduct(request: product_pb.GetProductRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientUnaryCall;
  getProduct(request: product_pb.GetProductRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientUnaryCall;
  getProductViaCategory(request: product_pb.GetProductViaCategoryRequest, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<product_pb.Product>;
  getProductViaCategory(request: product_pb.GetProductViaCategoryRequest, metadata?: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<product_pb.Product>;
  getBestProduct(callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientWritableStream<product_pb.GetProductRequest>;
  getBestProduct(metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientWritableStream<product_pb.GetProductRequest>;
  getBestProduct(options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientWritableStream<product_pb.GetProductRequest>;
  getBestProduct(metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientWritableStream<product_pb.GetProductRequest>;
  getProducts(): grpc.ClientDuplexStream<product_pb.GetProductRequest, product_pb.Product>;
  getProducts(options: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<product_pb.GetProductRequest, product_pb.Product>;
  getProducts(metadata: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<product_pb.GetProductRequest, product_pb.Product>;
}

export class ProductServiceClient extends grpc.Client implements IProductServiceClient {
  constructor(address: string, credentials: grpc.ChannelCredentials, options?: Partial<grpc.ClientOptions>);
  public getProduct(request: product_pb.GetProductRequest, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientUnaryCall;
  public getProduct(request: product_pb.GetProductRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientUnaryCall;
  public getProduct(request: product_pb.GetProductRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientUnaryCall;
  public getProductViaCategory(request: product_pb.GetProductViaCategoryRequest, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<product_pb.Product>;
  public getProductViaCategory(request: product_pb.GetProductViaCategoryRequest, metadata?: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientReadableStream<product_pb.Product>;
  public getBestProduct(callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientWritableStream<product_pb.GetProductRequest>;
  public getBestProduct(metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientWritableStream<product_pb.GetProductRequest>;
  public getBestProduct(options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientWritableStream<product_pb.GetProductRequest>;
  public getBestProduct(metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: product_pb.Product) => void): grpc.ClientWritableStream<product_pb.GetProductRequest>;
  public getProducts(): grpc.ClientDuplexStream<product_pb.GetProductRequest, product_pb.Product>;
  public getProducts(options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<product_pb.GetProductRequest, product_pb.Product>;
  public getProducts(metadata?: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<product_pb.GetProductRequest, product_pb.Product>;
}

product_pb.d.ts

// package: com.product
// file: product.proto

import * as jspb from 'google-protobuf';

export class Product extends jspb.Message {
  getId(): number;
  setId(value: number): void;

  getName(): string;
  setName(value: string): void;

  getCategory(): string;
  setCategory(value: string): void;

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

export namespace Product {
  export type AsObject = {
    id: number,
    name: string,
    category: string,
  }
}

export class GetProductRequest extends jspb.Message {
  getId(): number;
  setId(value: number): void;

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

export namespace GetProductRequest {
  export type AsObject = {
    id: number,
  }
}

export class GetProductViaCategoryRequest extends jspb.Message {
  getCategory(): string;
  setCategory(value: string): void;

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

export namespace GetProductViaCategoryRequest {
  export type AsObject = {
    category: string,
  }
}

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

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

export namespace Shop {
  export type AsObject = {
    name: string,
    listMap: Array<[number, Product.AsObject]>,
  }
}

License

MIT

protoc-gen-grpc-ts's People

Contributors

dependabot[bot] avatar gregmagolan-codaio avatar jedrivisser avatar jkomyno avatar stultuss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

protoc-gen-grpc-ts's Issues

install script no longer works with npm>=7 on windows

This issue is related to a bug with npm

The resulting error looks like:

npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c "./node_modules/.bin/node-pre-gyp install"
npm ERR! '.' is not recognized as an internal or external command,
npm ERR! operable program or batch file.

Fortunately, there is a really easy fix.
We just have to change

"install": "./node_modules/.bin/node-pre-gyp install",

to

"install": "node-pre-gyp install",

Cannot install on Apple M1 arm64 running Linux on Docker

Host Machine Specification

I'm using the latest MacBook Pro 2021, with Apple M1 as CPU, which has anarm64 architecture.

Result of uname -a:
Darwin 192.168.1.77 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:01 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T6000 arm64

Docker Container Specification

I'm running Docker v20.10.10, and in particular I'm using the node:16.13.1-alpine image.

Issue

Trying to install protoc-gen-grpc with the following Dockerfile fails:

ARG NODE_VERSION=16.13.1
FROM node:${NODE_VERSION}-alpine

RUN npm install request -g
RUN npm config set unsafe-perm true

# this fails
RUN npm install protoc-gen-grpc -g

Error:

 > RUN npm install protoc-gen-grpc -g:
#29 9.286 npm ERR! code 1
#29 9.286 npm ERR! path /usr/local/lib/node_modules/protoc-gen-grpc
#29 9.287 npm ERR! command failed
#29 9.287 npm ERR! command sh -c ./node_modules/.bin/node-pre-gyp install
#29 9.287 npm ERR! response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.1/linux-arm64.tar.gz
#29 9.287 npm ERR! node-pre-gyp info it worked if it ends with ok
#29 9.287 npm ERR! node-pre-gyp info using [email protected]
#29 9.287 npm ERR! node-pre-gyp info using [email protected] | linux | arm64
#29 9.287 npm ERR! node-pre-gyp info check checked for "/usr/local/lib/node_modules/protoc-gen-grpc/bin/grpc_tools.node" (not found)
#29 9.287 npm ERR! node-pre-gyp http GET https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.1/linux-arm64.tar.gz
#29 9.287 npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.1/linux-arm64.tar.gz 
#29 9.287 npm ERR! node-pre-gyp ERR! install error 
#29 9.287 npm ERR! node-pre-gyp ERR! stack Error: response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.1/linux-arm64.tar.gz
#29 9.287 npm ERR! node-pre-gyp ERR! stack     at /usr/local/lib/node_modules/protoc-gen-grpc/node_modules/@mapbox/node-pre-gyp/lib/install.js:67:15
#29 9.287 npm ERR! node-pre-gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:96:5)
#29 9.287 npm ERR! node-pre-gyp ERR! System Linux 5.10.47-linuxkit
#29 9.287 npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/protoc-gen-grpc/node_modules/.bin/node-pre-gyp" "install"
#29 9.287 npm ERR! node-pre-gyp ERR! cwd /usr/local/lib/node_modules/protoc-gen-grpc
#29 9.287 npm ERR! node-pre-gyp ERR! node -v v16.13.1
#29 9.287 npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.5
#29 9.287 npm ERR! node-pre-gyp ERR! not ok
#29 9.293 
#29 9.293 npm ERR! A complete log of this run can be found in:
#29 9.293 npm ERR!     /root/.npm/_logs/2022-01-02T20_25_47_915Z-debug.log

I get errors even if I try building the library from source.
Here is the updated Dockerfile:

ARG NODE_VERSION=16.13.1
FROM node:${NODE_VERSION}-alpine

RUN npm install request -g
RUN npm config set unsafe-perm true

RUN apk add --no-cache python3 make g++

# this fails
RUN npm install --build-from-source protoc-gen-grpc -g

which yields the following error:

 > RUN npm install --build-from-source protoc-gen-grpc -g:
#30 17.06 npm ERR! code 1
#30 17.06 npm ERR! path /usr/local/lib/node_modules/protoc-gen-grpc
#30 17.06 npm ERR! command failed
#30 17.06 npm ERR! command sh -c ./node_modules/.bin/node-pre-gyp install
#30 17.06 npm ERR! Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --module=/usr/local/lib/node_modules/protoc-gen-grpc/bin/grpc_tools.node --module_name=grpc_tools --module_path=/usr/local/lib/node_modules/protoc-gen-grpc/bin --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
#30 17.06 npm ERR! node-pre-gyp info it worked if it ends with ok
#30 17.06 npm ERR! node-pre-gyp info using [email protected]
#30 17.06 npm ERR! node-pre-gyp info using [email protected] | linux | arm64
#30 17.06 npm ERR! node-pre-gyp info build requesting source compile
#30 17.06 npm ERR! gyp info it worked if it ends with ok
#30 17.06 npm ERR! gyp info using [email protected]
#30 17.06 npm ERR! gyp info using [email protected] | linux | arm64
#30 17.06 npm ERR! gyp info ok 
#30 17.06 npm ERR! gyp info it worked if it ends with ok
#30 17.06 npm ERR! gyp info using [email protected]
#30 17.06 npm ERR! gyp info using [email protected] | linux | arm64
#30 17.06 npm ERR! gyp info find Python using Python version 3.9.5 found at "/usr/bin/python3"
#30 17.06 npm ERR! gyp http GET https://nodejs.org/download/release/v16.13.1/node-v16.13.1-headers.tar.gz
#30 17.06 npm ERR! gyp http 200 https://nodejs.org/download/release/v16.13.1/node-v16.13.1-headers.tar.gz
#30 17.06 npm ERR! gyp http GET https://nodejs.org/download/release/v16.13.1/SHASUMS256.txt
#30 17.06 npm ERR! gyp http 200 https://nodejs.org/download/release/v16.13.1/SHASUMS256.txt
#30 17.06 npm ERR! gyp info spawn /usr/bin/python3
#30 17.06 npm ERR! gyp info spawn args [
#30 17.06 npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
#30 17.06 npm ERR! gyp info spawn args   'binding.gyp',
#30 17.06 npm ERR! gyp info spawn args   '-f',
#30 17.06 npm ERR! gyp info spawn args   'make',
#30 17.06 npm ERR! gyp info spawn args   '-I',
#30 17.06 npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/protoc-gen-grpc/build/config.gypi',
#30 17.06 npm ERR! gyp info spawn args   '-I',
#30 17.06 npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
#30 17.06 npm ERR! gyp info spawn args   '-I',
#30 17.06 npm ERR! gyp info spawn args   '/root/.cache/node-gyp/16.13.1/include/node/common.gypi',
#30 17.06 npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
#30 17.06 npm ERR! gyp info spawn args   '-Dvisibility=default',
#30 17.06 npm ERR! gyp info spawn args   '-Dnode_root_dir=/root/.cache/node-gyp/16.13.1',
#30 17.06 npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
#30 17.06 npm ERR! gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/16.13.1/<(target_arch)/node.lib',
#30 17.06 npm ERR! gyp info spawn args   '-Dmodule_root_dir=/usr/local/lib/node_modules/protoc-gen-grpc',
#30 17.06 npm ERR! gyp info spawn args   '-Dnode_engine=v8',
#30 17.06 npm ERR! gyp info spawn args   '--depth=.',
#30 17.06 npm ERR! gyp info spawn args   '--no-parallel',
#30 17.06 npm ERR! gyp info spawn args   '--generator-output',
#30 17.06 npm ERR! gyp info spawn args   'build',
#30 17.06 npm ERR! gyp info spawn args   '-Goutput_dir=.'
#30 17.06 npm ERR! gyp info spawn args ]
#30 17.06 npm ERR! gyp: binding.gyp not found (cwd: /usr/local/lib/node_modules/protoc-gen-grpc) while trying to load binding.gyp
#30 17.06 npm ERR! gyp ERR! configure error 
#30 17.06 npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
#30 17.06 npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:261:16)
#30 17.06 npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
#30 17.06 npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
#30 17.06 npm ERR! gyp ERR! System Linux 5.10.47-linuxkit
#30 17.06 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--module=/usr/local/lib/node_modules/protoc-gen-grpc/bin/grpc_tools.node" "--module_name=grpc_tools" "--module_path=/usr/local/lib/node_modules/protoc-gen-grpc/bin" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93"
#30 17.06 npm ERR! gyp ERR! cwd /usr/local/lib/node_modules/protoc-gen-grpc
#30 17.06 npm ERR! gyp ERR! node -v v16.13.1
#30 17.06 npm ERR! gyp ERR! node-gyp -v v8.3.0
#30 17.06 npm ERR! gyp ERR! not ok 
#30 17.06 npm ERR! node-pre-gyp ERR! build error 
#30 17.06 npm ERR! node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --module=/usr/local/lib/node_modules/protoc-gen-grpc/bin/grpc_tools.node --module_name=grpc_tools --module_path=/usr/local/lib/node_modules/protoc-gen-grpc/bin --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
#30 17.06 npm ERR! node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/protoc-gen-grpc/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
#30 17.06 npm ERR! node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
#30 17.06 npm ERR! node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
#30 17.06 npm ERR! node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
#30 17.06 npm ERR! node-pre-gyp ERR! System Linux 5.10.47-linuxkit
#30 17.06 npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/protoc-gen-grpc/node_modules/.bin/node-pre-gyp" "install"
#30 17.06 npm ERR! node-pre-gyp ERR! cwd /usr/local/lib/node_modules/protoc-gen-grpc
#30 17.06 npm ERR! node-pre-gyp ERR! node -v v16.13.1
#30 17.06 npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.5
#30 17.06 npm ERR! node-pre-gyp ERR! not ok
#30 17.07 
#30 17.07 npm ERR! A complete log of this run can be found in:
#30 17.07 npm ERR!     /root/.npm/_logs/2022-01-02T20_34_46_825Z-debug.log

Wrong TypeScript type for ClientWritableStream

Hi, I noticed a subtle bug in protoc-gen-grpc-ts. I'm using the latest version available, v1.4.2.

Take for example this gRPC service, where the procedure Update takes a stream as input:

// updater.proto

syntax = "proto3";
package updater;

service Updater {
  rpc Update (stream UpdateRequest) returns (UpdateResponse);
}

message UpdateRequest {
  bytes chunk = 1;
}

message UpdateResponse {
  bool is_ok = 1;
  repeated string result= 2;
}

Running protoc-gen-grpc-ts creates the following TypeScript definition:

// updater_grpc_pb.d.ts

// ...

export interface IUpdaterClient {
  update(callback: (error: Error | null, response: updater_pb.UpdateResponse) => void): grpc.ClientWritableStream<updater_pb.UpdateResponse>;
  update(metadata: grpc.Metadata, callback: (error: Error | null, response: updater_pb.UpdateResponse) => void): grpc.ClientWritableStream<updater_pb.UpdateResponse>;
}

export class UpdaterClient extends grpc.Client implements IUpdaterClient {
  constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
  public update(callback: (error: Error | null, response: updater_pb.UpdateResponse) => void): grpc.ClientWritableStream<warehouse_updater_pb.UpdateResponse>;
  public update(metadata: grpc.Metadata, callback: (error: Error | null, response: updater_pb.UpdateResponse) => void): grpc.ClientWritableStream<updater_pb.UpdateResponse>;
}

The return type of the IUpdaterClient and UpdaterClient methods update are wrong.
They should return grpc.ClientWritableStream<updater_pb.UpdateRequest>;

The JavaScript implementation is correct though, in fact in practice I have a working gRPC system where the client has type checking disabled (via TypeScript's // @ts-ignore).

hello, error in windows 10

at Object. (xx\client.js:17:16) => const client = new book_grpc_pb_1.BookServiceClient("127.0.0.1:50051", grpc.credentials.createInsecure());

this.$channel = new grpc.Channel(address, credentials, channel_options);
                  ^

TypeError: Channel's second argument (credentials) must be a ChannelCredentials
at ServiceClient.Client (xx\client.js:460:23)
at new ServiceClient (xx\client.js:987:12)
at Object. (xx\client.js:17:16)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
at internal/main/run_main_module.js:17:11

fields of type 'map<keyType, ValueType>' don't get setters generated

hey there,

Thanks for all your excellent work in providing this tooling :-) We've been using this CLI since October and it's been great for us.

I am currently working with a protobuf spec that has a types map<string, TransactionType> type_mapping = 8;

Unfortunately, there is not setter generated for this field. I do get a getter and a clear function like this:

getTypeMappingMap(): jspb.Map<string, TransactionType>;
clearTypeMappingMap(): void;

I would expect a function setTypeMappingMap(value: jspb.Map<string, TransactionType>) as part of the generated js and in the typescript declerations.

node-pre-gyp fails during yarn install

We just upgraded from protoc-gen-grpc 1.3.1 to 2.0.2 on a Windows OS:

yarn install v1.22.5
...
error path\to\app\node_modules\protoc-gen-grpc: Command failed.
Exit code: 1
Command: .\node_modules\.bin\node-pre-gyp install
Arguments:
Directory: path\to\app\node_modules\protoc-gen-grpc

It appears that a path\to\app\node_modules\protoc-gen-grpc\node_modules\.bin folder with node-pre-gyp in it is not being created.

Is this because node-pre-gyp was removed as a dependency?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.