Registry / messaging / rxjs-grpc-minimal

rxjs-grpc-minimal

JSON →
library0.2.31jsnpmunverified

A lightweight, non-opinionated proxy that wraps @grpc/grpc-js server and client implementations with RxJS Observables. Version 0.2.31 is the current stable release, with low release cadence. Unlike the original rxjs-grpc, this package has no CLI and does not impose build tools, allowing you to use @grpc/proto-loader directly. It supports unary, server-streaming, client-streaming, and bidirectional calls via Observables, and provides built-in cancellation via grpcCancel(). Replaces the deprecated grpc package with @grpc/grpc-js. Requires RxJS 7.x and Node.js >= 20.

npm install rxjs-grpc-minimal
INSTALL
IMPORT
SIG · RXJS-GRPC-MINIMAL
R
rxjs-grpc-minimal
messagingjavascriptv0.2.31
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

toRxClient
import { toRxClient } from 'rxjs-grpc-minimal'
const toRxClient = require('rxjs-grpc-minimal').toRxClient
The library is ESM-only since v0.2; it does not provide a CommonJS default export.
toRxServer
import { toRxServer } from 'rxjs-grpc-minimal'
import toRxServer from 'rxjs-grpc-minimal'
Named export only; default import is undefined.
RPCMethod
import type { RPCMethod } from 'rxjs-grpc-minimal'
TypeScript users may need this type for method signatures; it is not a runtime value.

Demonstrates loading a proto file, creating an RxJS client for unary calls, and setting up an RxJS server with async implementations.

import grpc from '@grpc/grpc-js'; import protoLoader from '@grpc/proto-loader'; import { toRxClient, toRxServer } from 'rxjs-grpc-minimal'; import { of, Observable, Subject } from 'rxjs'; // 1. Load proto const packageDefinition = protoLoader.loadSync('./helloworld.proto', { keepCase: false, longs: String, enums: String, defaults: true, oneofs: true }); const proto = grpc.loadPackageDefinition(packageDefinition).helloworld; // 2. Create RxJS client (wrapping proto) const RxClient = toRxClient(proto); // 3. Instantiate client const greeter = new RxClient.Greeter('localhost:50051', grpc.credentials.createInsecure()); // 4. Make unary call await greeter.sayHelloRx({ name: 'World' }).forEach((resp: { message: string }) => { console.log(resp.message); // 'Hello World!' }); // 5. Create RxJS server implementation const rxImpl = { sayHello({ value: { name } }: { value: { name: string } }) { return of({ message: `Hello ${name}!` }); }, sayMultiHello({ value: { name, numGreetings } }: { value: { name: string; numGreetings: number } }) { return new Observable((observer) => { for (let i = 0; i < numGreetings; i++) { observer.next({ message: `Hello ${name} (${i + 1})` }); } observer.complete(); }); } }; const server = new grpc.Server(); const rxServer = toRxServer(server, 'helloworld.Greeter', rxImpl); server.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => { server.start(); });
Debug
Known issues
breakingThe library is ESM-only since v0.2. CommonJS require() or dynamic imports may fail.
fix
Use ES module import syntax ('import { toRxClient } from 'rxjs-grpc-minimal'') and ensure your project is configured for ESM (e.g., 'type': 'module' in package.json).
affects: >=0.2.0
deprecatedThe original 'grpc' npm package is deprecated. This library only supports @grpc/grpc-js.
fix
Replace 'grpc' dependency with '@grpc/grpc-js' and use its loadPackageDefinition API.
affects: >=0.0.0
gotchaClient streaming requires passing a Subject/Observable to the Rx method. If you pass a plain stream, it will be treated as a unary message.
fix
Always use Rx.Subject or another Observable from RxJS for client stream calls.
affects: >=0.0.0
gotchaMethod names in the proto are automatically suffixed with 'Rx' (e.g., 'sayHello' becomes 'sayHelloRx'). If you omit the suffix, the method is undefined.
fix
Always append 'Rx' to the protobuf method name when calling on the client. For server implementations, do NOT use the 'Rx' suffix.
affects: >=0.0.0
deprecatedUsing 'grpc-tools' to generate JavaScript code is not recommended. Use '@grpc/proto-loader' instead.
fix
Install '@grpc/proto-loader' and use protoLoader.loadSync() to load .proto files directly.
affects: >=0.0.0
breakingNode.js <20 is not supported. The library uses modern ESM features and APIs unavailable in older versions.
fix
Upgrade to Node.js >=20.
affects: >=0.2.0
gotchaCancellation via grpcCancel() is a custom property attached to the Observable, not part of the RxJS contract. Use it carefully with operators that may unsubscribe the upstream Observable.
fix
Call stream$.grpcCancel() before unsubscribing, or use takeUntil() with a cancellation subject to properly clean up.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: greeter.sayHello is not a function
Forgot to append 'Rx' suffix to the method name when calling on the client.
fix
Change to greeter.sayHelloRx({ name: 'World' }).forEach(...).
ERR_REQUIRE_ESM: require() of ES Module /node_modules/rxjs-grpc-minimal/index.js not supported
The library is ESM-only and cannot be required via CommonJS.
fix
Use import syntax: import { toRxClient } from 'rxjs-grpc-minimal'. Set 'type': 'module' in package.json or use .mjs extension.
Cannot read properties of undefined (reading 'Greeter')
Proto file not properly loaded or wrapped: the grpcAPI object lacks the service namespace.
fix
Ensure you call toRxClient(grpcAPI.helloworld) where 'helloworld' is your proto package name, and that the proto is loaded correctly via '@grpc/proto-loader'.
Warning: The 'grpc' package is deprecated. Please use '@grpc/grpc-js' instead.
Installed deprecated 'grpc' package instead of '@grpc/grpc-js'.
fix
npm uninstall grpc && npm install @grpc/grpc-js
TypeError: observer is not a function
Incorrect usage when passing a plain function instead of RxJS Subject for client streaming.
fix
Use new Subject() as the argument to the Rx method: const writer = new Subject(); greeter.streamSayHelloRx(writer).
Upgrade
Version history
0.2.31latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredRuntime peer dependency for gRPC core functionality
@grpc/proto-loaderoptionalAlternative to grpc-tools for loading .proto files (recommended)
rxjsrequiredPeer dependency for Observable patterns (v7.x)
Agent activity
17 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources