Git Product home page Git Product logo

rxjs-grpc's Introduction

Build Status npm version

rxjs-grpc

Installation

$ npm install rxjs-grpc rxjs grpc

Quickstart

Create your protobuf definition file sample.proto:

syntax = "proto3";

package sample;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

Generate your TypeScript interfaces:

$ ./node_modules/.bin/rxjs-grpc -o grpc-namespaces.ts *.proto

Implement your typesafe server returning Observable<sample.HelloReply>:

import { of } from 'rxjs';
import { serverBuilder } from 'rxjs-grpc';
import { sample } from './grpc-namespaces';

// Pass the path of proto file and the name of namespace
const server = serverBuilder<sample.ServerBuilder>('sample.proto', 'sample')
// Add implementation
server.addGreeter({
  sayHello(request: sample.HelloRequest) {
    return of({
      message: 'Hello ' + request.name
    });
  }
})
// Start the server to listen on port 50051
server.start('0.0.0.0:50051');

Call it from a client:

import { clientFactory } from 'rxjs-grpc';
import { sample } from './grpc-namespaces';

// Pass the path of proto file and the name of namespace
const Services = clientFactory<sample.ClientFactory>('sample.proto', 'sample');
// Create a client connecting to the server
const services = new Services('localhost:50051');
// Get a client for the Greeter service
const greeter = services.getGreeter();

// Call the service by passing a sample.HelloRequest
greeter.sayHello({ name: 'world' }).forEach(response => {
  console.log(`Greeting: ${response.message}`);
});

Generated interfaces

import { Observable } from 'rxjs';

export namespace sample {

  export interface ClientFactory {
    getGreeter(): sample.Greeter;
  }

  export interface ServerBuilder {
    addGreeter(impl: sample.Greeter): sample.ServerBuilder;
  }

  export interface Greeter {
    sayHello(request: sample.HelloRequest): Observable<sample.HelloReply>;
  }

  export interface HelloRequest {
    name?: string;
  }

  export interface HelloReply {
    message?: string;
  }

}

Examples

You can see a simple example project in the examples folder.

rxjs-grpc's People

Contributors

kondi avatar ksaldana1 avatar maikelh avatar slumbi 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxjs-grpc's Issues

Is it no longer under maintenance?

This is a cool project.
Thanks for publishing that.
If the author can no longer continue to maintain this project for any reason,
Can you transfer to someone who is more willing to maintain this project?
I prefer to continue to maintain this project.
Can you transfer it to me?

int64 refers to $protobuf.Long which is not defined

int64, sint64, fixed64 and sfixed64 will converted to (number|$protobuf.Long).
However, $protobuf is not defined in the namespace file.

inserting import * as $protobuf from 'protobufjs'; at the top of the namespace file will fix the problem.

Static generation

I'd love to see the ability to statically generate code (not just interfaces) as part of a build process, instead of creating it dynamically when the application starts. I'm currently using the static generation of grpc-node to build my client and server, but would like to move to the observable model because it feels like a much more natural API.

Perhaps this is what is intended by #30?

Translate protobuf oneof attribute values into string literal types

Given a .proto message declaration like

message MyRequest {
  oneof my_ref {
    bytes attribute1 = 1 [(validator.field) = {length_eq : 16}];
    string attribute2 = 2 [(validator.field) = {string_not_empty : true}];
  }
}

rxjs-grpc ends up creating an interface like:

export interface MyRequest {

    /**
     * MyRequest attribute1.
     * @type {Uint8Array|undefined}
     */
    attribute1?: Uint8Array;

    /**
     * MyRequest attribute2.
     * @type {string|undefined}
     */
    attribute2?: string;

    /**
     * MyRequest my_ref.
     * @name MyRequest#my_ref
     * @type {string|undefined}
     */
    my_ref?: string;
}

What gets lost in the namespace creation is the actual allowed values of my_ref. In this case the type of my_ref would better be set to ("attribute1"|"attribute2"). So, the more useful interface would be:

export interface MyRequest {

    /**
     * MyRequest attribute1.
     * @type {Uint8Array|undefined}
     */
    attribute1?: Uint8Array;

    /**
     * MyRequest attribute2.
     * @type {string|undefined}
     */
    attribute2?: string;

    /**
     * MyRequest my_ref.
     * @name MyRequest#my_ref
     * @type {string|undefined}
     */
    my_ref?: ("attribute1"|"attribute2");
}

Type generation error

When rpc call starts with consecutive uppercase

rpc UMChannel (stream Request) returns (stream Response);

the generated definitions would contain

uMChannel(request: package.Request): Observable<package.Response>;

which would be undefined function, instead it should have generated

umChannel(request: package.Request): Observable<package.Response>;

Angular2 Support

I think this is a great project and show's real promise. Is it possible to use this within an Angular2 client? Any chance of getting a simple example?

I'm just learning angular and typescript and even hints in the right direction would be helpful.

Here is what I've done so far:
I have this service file (HelloService.ts)

import { Injectable }    from '@angular/core';

import { clientFactory } from 'rxjs-grpc';
import { helloworld } from './grpc-namespaces';

@Injectable()
export class HomeService {

  constructor() {}

  Services = clientFactory<helloworld.ClientFactory>('helloworld.proto', 'helloworld');
  services = new this.Services('localhost:50051');
  greeter = this.services.getGreeter();

  greet(user: String): void {
    this.greeter.sayHello({name: 'Test!!!'}).forEach(response => {
      console.log('Greeting:', response.message);
    });
  }
}

The helloworld.proto

syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.itsolut.learn";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";

package helloworld;

service Greeter {
    rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
    string name = 1;
}

message HelloReply {
    string message = 1;
}

The grpc-namespaces.ts (generated by this project)

import { Observable } from 'rxjs';

export namespace helloworld {

     export interface ClientFactory {
        getGreeter(): helloworld.Greeter;
    }

     export interface ServerBuilder {
        addGreeter(impl: helloworld.Greeter): helloworld.ServerBuilder;
    }

     export interface Greeter {
        sayHello(request: helloworld.HelloRequest): Observable<helloworld.HelloReply>;
    }

     export interface HelloRequest {
        name?: string;
    }

     export interface HelloReply {
        message?: string;
    }
}

The first error I got was "Can't resolve 'node-pre-gyp/lib/pre-binding'. So I install via npm this module.

After install the module, I get the following error in the browser and the app doesn't compile/load.

pre-binding.js:16 Uncaught TypeError: existsSync is not a function
    at Object.exports.find (pre-binding.js:16)
    at Object.<anonymous> (grpc_extension.js:37)
    at Object.splitPathRe (grpc_extension.js:40)
    at __webpack_require__ (bootstrap 305886d9b6402b5d859b:52)
    at Object.<anonymous> (client.js:55)
    at __webpack_require__ (bootstrap 305886d9b6402b5d859b:52)
    at Object.<anonymous> (index.js:45)
    at Object.<anonymous> (index.js:225)
    at __webpack_require__ (bootstrap 305886d9b6402b5d859b:52)
    at Object.<anonymous> (index.js:38)
    at __webpack_require__ (bootstrap 305886d9b6402b5d859b:52)
    at Object.92 (main.bundle.js:376)
    at __webpack_require__ (bootstrap 305886d9b6402b5d859b:52)
    at Object.151 (app.module.ts:33)
    at __webpack_require__ (bootstrap 305886d9b6402b5d859b:52)
exports.find @ pre-binding.js:16
(anonymous) @ grpc_extension.js:37
splitPathRe @ grpc_extension.js:40
__webpack_require__ @ bootstrap 305886d9b6402b5d859b:52
(anonymous) @ client.js:55
__webpack_require__ @ bootstrap 305886d9b6402b5d859b:52
(anonymous) @ index.js:45
(anonymous) @ index.js:225
__webpack_require__ @ bootstrap 305886d9b6402b5d859b:52
(anonymous) @ index.js:38
__webpack_require__ @ bootstrap 305886d9b6402b5d859b:52
92 @ main.bundle.js:376
__webpack_require__ @ bootstrap 305886d9b6402b5d859b:52
151 @ app.module.ts:33
__webpack_require__ @ bootstrap 305886d9b6402b5d859b:52
150 @ app.component.ts:8
__webpack_require__ @ bootstrap 305886d9b6402b5d859b:52
139 @ src async:7
__webpack_require__ @ bootstrap 305886d9b6402b5d859b:52
319 @ main.bundle.js:359
__webpack_require__ @ bootstrap 305886d9b6402b5d859b:52
webpackJsonpCallback @ bootstrap 305886d9b6402b5d859b:23
(anonymous) @ main.bundle.js:1
client?ffdb:40 [WDS] Warnings while compiling.
client?ffdb:98 ./~/grpc/src/node/src/grpc_extension.js
38:14-35 Critical dependency: the request of a dependency is an expression
warnings @ client?ffdb:98
sock.onmessage @ socket.js:37
EventTarget.dispatchEvent @ eventtarget.js:51
(anonymous) @ main.js:274
SockJS._transportMessage @ main.js:272
EventEmitter.emit @ emitter.js:50
WebSocketTransport.ws.onmessage @ websocket.js:35
wrapFn @ zone.js:1242
ZoneDelegate.invokeTask @ zone.js:367
Zone.runTask @ zone.js:166
ZoneTask.invoke @ zone.js:420
client?ffdb:98 ./~/node-pre-gyp/lib/pre-binding.js
19:22-48 Critical dependency: the request of a dependency is an expression
warnings @ client?ffdb:98
sock.onmessage @ socket.js:37
EventTarget.dispatchEvent @ eventtarget.js:51
(anonymous) @ main.js:274
SockJS._transportMessage @ main.js:272
EventEmitter.emit @ emitter.js:50
WebSocketTransport.ws.onmessage @ websocket.js:35
wrapFn @ zone.js:1242
ZoneDelegate.invokeTask @ zone.js:367
Zone.runTask @ zone.js:166
ZoneTask.invoke @ zone.js:420
client?ffdb:98 ./~/node-pre-gyp/lib/util/versioning.js
15:20-67 Critical dependency: the request of a dependency is an expression
warnings @ client?ffdb:98
sock.onmessage @ socket.js:37
EventTarget.dispatchEvent @ eventtarget.js:51
(anonymous) @ main.js:274
SockJS._transportMessage @ main.js:272
EventEmitter.emit @ emitter.js:50
WebSocketTransport.ws.onmessage @ websocket.js:35
wrapFn @ zone.js:1242
ZoneDelegate.invokeTask @ zone.js:367
Zone.runTask @ zone.js:166
ZoneTask.invoke @ zone.js:420

Also, I get warning messages when I run > ng serve:

>ng serve
** NG Live Development Server is running on http://localhost:4200 **
Hash: 305886d9b6402b5d859b
Time: 15573ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 158 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 9.8 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 9.77 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 3.85 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

WARNING in ./~/grpc/src/node/src/grpc_extension.js
38:14-35 Critical dependency: the request of a dependency is an expression

WARNING in ./~/node-pre-gyp/lib/pre-binding.js
19:22-48 Critical dependency: the request of a dependency is an expression

WARNING in ./~/node-pre-gyp/lib/util/versioning.js
15:20-67 Critical dependency: the request of a dependency is an expression
webpack: Compiled with warnings.

Thoughts on what to try next?

Thanks,
Chris....

Not compatible with protobufjs 6.7.x

the rxjs-grpc cli produce this line:

sayHello(request: (sample.HelloRequest|{ [k: string]: any })): Observable<sample.HelloReply>;

You will get the error Property 'name' does not exist on type 'HelloRequest | { [k: string]: any; }'.
If you change the pipe-symbol | to an ampersand-symbol & it should work.

sayHello(request: (sample.HelloRequest & { [k: string]: any })): Observable<sample.HelloReply>;

Type 'ClientFactoryConstructor<{}>' cannot be converted to type 'ClientFactory'. Property 'getEmployeeRepo' is missing in type 'ClientFactoryConstructor<{}>'.

Relevant snippet

import { employee_repo } from './__generated__/grpc-namespaces';

const EMPLOYEE_REPO_PROTO = resolve(
  __dirname,
  '../../employee-repo/protos/employee-repo.proto',
);

const Services = <employee_repo.ClientFactory>clientFactory(
  EMPLOYEE_REPO_PROTO,
  'employee_repo',
);

Results in:

src/app.ts(17,18): error TS2352: Type 'ClientFactoryConstructor<{}>' cannot be converted to type 'ClientFactory'.
  Property 'getEmployeeRepo' is missing in type 'ClientFactoryConstructor<{}>'.

The generated types:

import { Observable } from 'rxjs/Observable';

/**
 * Namespace employee_repo.
 * @exports employee_repo
 * @namespace
 */
export namespace employee_repo {

    /**
     * Contains all the RPC service clients.
     * @exports employee_repo.ClientFactory
     * @interface
     */
    export interface ClientFactory {

        /**
         * Returns the EmployeeRepo service client.
         * @returns {employee_repo.EmployeeRepo}
         */
        getEmployeeRepo(): employee_repo.EmployeeRepo;
    }

    /**
     * Builder for an RPC service server.
     * @exports employee_repo.ServerBuilder
     * @interface
     */
    export interface ServerBuilder {

        /**
         * Adds a EmployeeRepo service implementation.
         * @param {employee_repo.EmployeeRepo} impl EmployeeRepo service implementation
         * @returns {employee_repo.ServerBuilder}
         */
        addEmployeeRepo(impl: employee_repo.EmployeeRepo): employee_repo.ServerBuilder;
    }

    /**
     * Constructs a new EmployeeRepo service.
     * @exports employee_repo.EmployeeRepo
     * @interface
     */
    export interface EmployeeRepo {

        /**
         * Calls Get.
         * @param {employee_repo.GetEmployeeRequest} request GetEmployeeRequest message or plain object
         * @returns {Observable<employee_repo.Employee>}
         */
        get(request: employee_repo.GetEmployeeRequest): Observable<employee_repo.Employee>;
    }

    /**
     * Constructs a new Employee.
     * @exports employee_repo.Employee
     * @interface
     */
    export interface Employee {

        /**
         * Employee id.
         * @type {string|undefined}
         */
        id?: string;
    }

    /**
     * Constructs a new GetEmployeeRequest.
     * @exports employee_repo.GetEmployeeRequest
     * @interface
     */
    export interface GetEmployeeRequest {

        /**
         * GetEmployeeRequest id.
         * @type {string|undefined}
         */
        id?: string;
    }
}

I've tried this with node 10 and node 9. Also with rxjs@5 and rxjs@6`.

Any ideas as to what might be wrong? The serverBuilder works with the same generated types I should add. It is just the client that does not work.

Unable to run example with TypeScript 2.5.x

Upstream issue microsoft/TypeScript#18301

npm install -g typescript@latest solved this for me in combination with running tsc in examples folder then running node client.js and node server.js to avoid using ts-node.

Worked with tsc Version 2.6.0-dev.20170919.

Not sure what version I had before (sorry oops) but judging by the issue seems the fix will land in 2.6.0.

Server#addProtoService is deprecated warning

When a creating a new service using the addService on the servicebuilder the following warning is emitted:

Server#addProtoService is deprecated. Use addService instead

This is caused by the deprecation of addProtoService in grpc 1.3.

Add Optional Metadata Parameter to Service Interface

Currently, the generated service interface methods accept a single parameter as an argument.
Example:
getPage(request: logbook.getPageRequest): Observable<logbook.Page>;

gRPC allows you to pass optional parameters to service calls in the form of metadata. This information is passed through correctly at the moment due to ...args spread, however the type signature causes the compiler to complain. I could just add things such as the JWT token to the request proto definition itself, but metadata feels like the appropriate use case.

Do you think it would be appropriate for the interface service definitions to include metadata as an optional parameter?
getPage(request: logbook.getPageRequest, metadata?: any): Observable<logbook.Page>;

I can try to get a PR together if you'd like.

Update README example

first of all I would like to say thank you for this great piece of work.

The server code on the README wouldn't work because addGreeter returns a sample.ServerBuilder, which does not include the GenericServerBuilder (= no start function).

Therefore it's not possible to write the server-config in a chain. it should look like the helloworld-example.

type ServerBuilder = sample.ServerBuilder;
// Pass the path of proto file and the name of namespace
const server = serverBuilder<ServerBuilder>('sample.proto', 'sample');
// Add implementation
server.addGreeter({
  sayHello(request: sample.HelloReply) {
    return Observable.of({
      message: 'Hello ' + request.name
    });
  }
});
// Start the server to listen on port 50051
server.start('0.0.0.0:50051');

Generated Enum Types Need to be Compiled

The types that are generated by the CLI tool are all compile-time only types aside from the enum type. Regular typescript enums contain both compile-time and runtime information and so need to be compiled into a js source in order to be correctly used.

If we switch to using const enums, then there is no need to compile the generated type file and it can behave more like a declaration file - which based on the structure of the output, seems like the original intent.

Support OS allocated random TCP port

Hi,

We would like to let the OS decide on which port our gRPC service listens on. This is achieved by passing port 0 all the way down.

Requesting for a random port already works, but we have no way of knowing which port is allocated because rxjs-grpc doesn't expose the return value of this line.

Any chance you could expose it?
Thank you

Don't work in Angular

$ ng serve

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
10% building 3/3 modules 0 active[HPM] Proxy created: /api -> http://localhost:3000

Date: 2019-06-11T22:48:57.730Z
Hash: c29506e37eae8eb873f3
Time: 18016ms
chunk {main} main.js, main.js.map (main) 42.7 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 149 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 17.4 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 4.22 MB [initial] [rendered]

WARNING in pnode_modules/grpc/src/grpc_extension.js 32:12-33
Critical dependency: the request of a dependency is an expression

WARNING in project/node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js 20:22-48
Critical dependency: the request of a dependency is an expression

WARNING in project/node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js 17:20-67
Critical dependency: the request of a dependency is an expression

WARNING in project/node_modules/grpc/node_modules/minimatch/minimatch.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc/node_modules/minimatch'

ERROR in project/node_modules/grpc/node_modules/detect-libc/lib/detect-libc.js
Module not found: Error: Can't resolve 'child_process' in 'project/node_modules/grpc/node_modules/detect-libc/lib'
ERROR in project/node_modules/grpc/index.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc'
ERROR in project/node_modules/grpc/node_modules/detect-libc/lib/detect-libc.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc/node_modules/detect-libc/lib'
ERROR in project/node_modules/grpc/node_modules/fs.realpath/index.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc/node_modules/fs.realpath'
ERROR in project/node_modules/grpc/node_modules/fs.realpath/old.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc/node_modules/fs.realpath'
ERROR in project/node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc/node_modules/node-pre-gyp/lib'
ERROR in project/node_modules/grpc/node_modules/node-pre-gyp/lib/util/napi.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc/node_modules/node-pre-gyp/lib/util'
ERROR in project/node_modules/grpc/node_modules/rimraf/rimraf.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc/node_modules/rimraf'
ERROR in project/node_modules/grpc/node_modules/rimraf/node_modules/glob/sync.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc/node_modules/rimraf/node_modules/glob'
ERROR in project/node_modules/grpc/node_modules/rimraf/node_modules/glob/glob.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc/node_modules/rimraf/node_modules/glob'
ERROR in project/node_modules/grpc/src/grpc_extension.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/grpc/src'
ERROR in project/node_modules/rxjs-grpc/node_modules/@grpc/proto-loader/build/src/index.js
Module not found: Error: Can't resolve 'fs' in 'project/node_modules/rxjs-grpc/node_modules/@grpc/proto-loader/build/src'
ERROR in project/node_modules/grpc/node_modules/detect-libc/lib/detect-libc.js
Module not found: Error: Can't resolve 'os' in 'project/node_modules/grpc/node_modules/detect-libc/lib'
ERROR in project/node_modules/grpc/node_modules/has-unicode/index.js
Module not found: Error: Can't resolve 'os' in 'project/node_modules/grpc/node_modules/has-unicode'
ERROR in project/node_modules/grpc/index.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc'[22m
ERROR in project/node_modules/grpc/node_modules/fs.realpath/old.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc/node_modules/fs.realpath'
ERROR in project/node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc/node_modules/node-pre-gyp/lib'
ERROR in project/node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc/node_modules/node-pre-gyp/lib/util'
ERROR in project/node_modules/grpc/node_modules/rimraf/rimraf.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc/node_modules/rimraf'
ERROR in project/node_modules/grpc/node_modules/rimraf/node_modules/glob/glob.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc/node_modules/rimraf/node_modules/glob'
ERROR in project/node_modules/grpc/node_modules/rimraf/node_modules/glob/sync.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc/node_modules/rimraf/node_modules/glob'
ERROR in project/node_modules/grpc/node_modules/rimraf/node_modules/glob/common.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc/node_modules/rimraf/node_modules/glob'
ERROR in project/node_modules/grpc/src/grpc_extension.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/grpc/src'
ERROR in project/node_modules/rxjs-grpc/node_modules/@grpc/proto-loader/build/src/index.js
Module not found: Error: Can't resolve 'path' in 'project/node_modules/rxjs-grpc/node_modules/@grpc/proto-loader/build/src'
ERROR in project/node_modules/grpc/src/client.js
Module not found: Error: Can't resolve 'stream' in 'project/node_modules/grpc/src'
ERROR in project/node_modules/grpc/src/server.js
Module not found: Error: Can't resolve 'stream' in 'project/node_modules/grpc/src'
ℹ 「wdm」: Failed to compile.
^C

Enums are received as string, while the generated enum types them as number

I have a proto-file containing a enum, which get's interpreted as an enum of numbers, however when sending down an enum (as number) from the server the client receives it as string.

Setup

I've create a runnable example, based on your helloworld in my fork:
You can see the adjustments here: master...micmro:enum-bug-example

Behaviour

Input value on the server: Room.SECOND (Room.SECOND === 1)
Output of npm run client:

Greeting: Hello world
Multi greeting: Hello world, SECOND (string)
Multi greeting: Hello world, SECOND (string)
Multi greeting: Hello world, SECOND (string)

Expected output based on types:

Greeting: Hello world
Multi greeting: Hello world, 1 (number)
Multi greeting: Hello world, 1 (number)
Multi greeting: Hello world, 1 (number)

Thoughts

Could this be related to an upstream protobuf.js (e.g. this issue)?

ServerBuilder/ClientBuilder for nested namespaces/packages

Hello,

I've got some protobuf service definitions with nested namespaces/package names.

syntax = "proto3";

package foo.bar;

service Dummy {
    rpc Echo(EchoMessage) returns (EchoMessage) {}
}

message EchoMessage {
    string payload = 1;
}

Unfortunately the serverBuilder failes to create the server as I cannot pass the correct package name. The generated TypeScript code has the following structure:

export namespace foo {
      export interface ServerBuilder {}

      // ...

     export namespace bar {
          export interface Echo {
                 // ....
          }

          export interface ServerBuilder {
              addEcho(echo: Echo): void;
          }
     }
}

I assume that I need to pass "foo.bar" as the package name to serverBuilder() like below:

const server = serverBuilder<foo.bar.ServerBuilder>('dummy.proto', 'foo.bar');

Using "foo.bar" fails at grpc.load(XXX)[pkgName].

Did I make a mistake or are nested packages/namespaces not yet supported by rxjs-grpc?

Best regards
Patrick

Usage without RxJS? (Pure gRPC to TypeScript)

I'm just getting into gRPC so forgive any ignorance =) I'd like to have gRPC output static codegen for TypeScript, but there's nothing on the horizon: grpc/grpc#6630

However, it seems this project leverages protobufjs pretty well to annotate the RxJS-based api surface; could we refactor some of it to expose a non-RxJS interface akin to what the official examples show?

Again, I'm just digging into gRPC and protobuf, so I'm not keen on all the nuances. I'd be happy to help once I'm more familiar with the lay of the land.

protobuf enums support

Hello,
Firstly, really great project!

Secondly, I found that below code generates RoleType as number value without defining enum.
It would be very helpful it that could be auto-generated.

Best Regards
Piotr

package example;

service Service {
    rpc Call(Message) returns (Message) {}
}

message Message{
    required RoleType role = 1;
}

enum RoleType{
    ONE = 0;
    TWO = 1;
}

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.