Socket
Socket
Sign inDemoInstall

grpc_tools_node_protoc_ts

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grpc_tools_node_protoc_ts - npm Package Compare versions

Comparing version 5.3.0 to 5.3.1

.idea/dbnavigator.xml

52

doc/server_impl_signature.md

@@ -102,4 +102,2 @@ # @grpc/grpc-js server implementation signature issue

This style is `recommended`. Since you can append more attributes in the `Impl` object, though they are not defined in `IBookServiceServer`, and you don't need to add `[name: string]: grpc.UntypedHandleCall` in your codes.
### Class Style

@@ -124,2 +122,50 @@

This style is `NOT` recommended. Since only those already defined in the `IBookServiceServer` can be existing in this `Impl` class, and `[name: string]: grpc.UntypedHandleCall` is required for Class style.
Only those already defined in the `IBookServiceServer` can be existing in this `Impl` class, and `[name: string]: grpc.UntypedHandleCall;` is required for Class style.
**Class style with magic generics**
The following is how you can break the restriction above, to add attributes to a class style implementation of a server:
```typescript
// First we need to set up some magic generics inspired by https://github.com/agreatfool/grpc_tools_node_protoc_ts/issues/79#issuecomment-770173789
type KnownKeys<T> = {
[K in keyof T]: string extends K ? never : number extends K ? never : K
} extends { [_ in keyof T]: infer U } ? U : never;
type KnownOnly<T extends Record<any, any>> = Pick<T, KnownKeys<T>>;
// Next we declare a new type using the above generics:
type ITypedBookServer = KnownOnly<IBookServiceServer>;
// Now we declare the class
class Impl implements ITypedBookServer {
attr: string;
constructor(attr: string) {
this.attr = attr;
}
public getBook(call: grpc.ServerUnaryCall<GetBookRequest, Book>, callback: sendUnaryData<Book>): void {}
public getBooks(call: grpc.ServerDuplexStream<GetBookRequest, Book>) {}
public getBooksViaAuthor(call: grpc.ServerWritableStream<GetBookViaAuthor, Book>) {}
public getGreatestBook(call: grpc.ServerReadableStream<GetBookRequest, Book>, callback: sendUnaryData<Book>) {}
}
// now we need to initialize the above Impl. First we need to extend grpc.Server
class TypedServerOverride extends grpc.Server {
addTypedService<TypedServiceImplementation extends Record<any,any>>(service: ServiceDefinition, implementation: TypedServiceImplementation): void {
this.addService(service, implementation);
}
}
// now perform the actual initialization
const server = new TypedServerOverride();
server.addTypedService<ITypedBookServer>(BookServiceService, new Impl("hello world"));
```
Runnable example could be found here:
* [examples/bash/grpcjs/server.magic_generics.sh](https://github.com/agreatfool/grpc_tools_node_protoc_ts/blob/v5.3.1/examples/bash/grpcjs/server.magic_generics.sh)
* [examples/src/grpcjs/server.magic_generics.ts](https://github.com/agreatfool/grpc_tools_node_protoc_ts/blob/v5.3.1/examples/src/grpcjs/server.magic_generics.ts)

2

package.json
{
"name": "grpc_tools_node_protoc_ts",
"version": "5.3.0",
"version": "5.3.1",
"description": "Generate d.ts definitions for generated js files from grpc_tools_node_protoc",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -650,2 +650,7 @@ grpc_tools_node_protoc_ts

## Changes
### 5.3.1
Update doc and Add runnable example for magic generics class style server implementation. See [Issue#79](https://github.com/agreatfool/grpc_tools_node_protoc_ts/issues/79#issuecomment-890109586) and [Issue#108](https://github.com/agreatfool/grpc_tools_node_protoc_ts/issues/108) and [PR#109](https://github.com/agreatfool/grpc_tools_node_protoc_ts/pull/109).
Updated doc could be found here: [@grpc/grpc-js server implementation signature issue](https://github.com/agreatfool/grpc_tools_node_protoc_ts/blob/v5.3.1/doc/server_impl_signature.md).
### 5.3.0

@@ -652,0 +657,0 @@ Fix signature issue of `handleClientStreamingCall` exporting. See [PR#105](https://github.com/agreatfool/grpc_tools_node_protoc_ts/pull/105).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc