rxjs-grpc-minimal
Based off the great work of rxjs-grpc. However, this library intends to very little except to offer you to wrap your server or client GRPC implementation the way you want it.
There is no cli as this library is trying to stay out of the way and allow grpc, or protobufjs do the amazing things they already do.
Install
> yarn add rxjs-grpc-minimal
Usage
Client
const path = ;const loadSync = ;const loadObject: toGrpc credentials = ;const Subject ReplaySubject = ; const toRxClient // used most often toRxServer // used most often utils errors} = ; const pbAPI = ; /*Wraps all service.prototype methods with RXJS implementations.Each method is appended to the prototype as `method${RX}` by default.Thus allowing you access to both RX and nonRx grpc implementations.*/const grpcAPI = ;/*Wraps all service.prototype methods with RXJS implementations. However,this overrides / overwrites all original prototype methods with the RX impl.*/const grpcApiOverride = ; const greeter = 'localhost:56001' credentials; // non streamconn; let calls = 0; // STREAMING REPLY FROM SERVERconn; calls = 0; /* console out { size: 1 }{ message: 'Hello Brody' }{ size: 1 }{ message: 'Hello Brody' }{ size: 0 }{ calls: 2 }*/ // streaming reply from serverconst multiHelloStream = conn;calls = 0;/* console out { size: 1 }{ message: 'Hello Brody' }{ size: 0 }{ calls: 1 }*/ // STREAMING REQUEST | client streaming to serverconst writer = ;const observable = conn; observable; consolegrpcAPIcancelCachesize // 1// ok we're now subscribedwriternext name: 'Al' ;writernext name: 'Bundy' ;writercomplete; console // 0 /* console out 1{ message: 'Hello Al' }{ calls: 1 }{ message: 'Hello Bundy' }{ calls: 2 }0*/ // CONNECTION CLEANUP/*Imagine we abort in between or crash but catch the problem.prior to conn.close we could clean up all. This guarantees that the observer on the sever side is cleaned up and released.This also allows you to truly close your connection without dangling a channel/subchannel.*/grpcAPIcancelCache;conn;
Server
See serverRx.js
API
toRxClient(grpcObject, methodExt)
-
#### grpcObject
Type:
Object
- initially created bygrpc.loadObject
w or w/o protobufjsload
|loadSync
-
#### methodExt
Type:
String
- defaults to'Rx'
This is the method naming extension where the original method name is appended with
something{RX}
.greetersayMultiHelloRx // RX functiongreetersayMultiHello // node stream function, and other functions could be callback, callback and steams;// ...greetersayMultiHello // RX function all node stream, callback etc hidden / wrapped// NOTE: all RX functions will always return observables (consistent!) .
toRxServer(service, rxImpl, serviceName)
-
#### service
Type:
Object
- GrpcService definitiongrpcAPI[serviceName]
-
#### rxImpl
Type:
Object
- Your RxJS server implementation which matches the service method handles to be implemented. -
#### serviceName (optional)
Type:
String
- aids in debug via debug-fabulous logging.