Registry / messaging / grpc-web-utils

grpc-web-utils

JSON →
library0.1.0jsnpmunverified

grpc-web-utils provides Node.js utilities for gRPC-Web including deadline and cancellation support. Current version 0.1.0 (stable, infrequent releases). Key differentiators: offers a SignalStreamInterceptor for AbortController-based cancellation and helper types like MetadataWithSignal. Supports TypeScript types. Primarily for streaming cancellation; note that createPromiseClient may not support cancellation.

npm install grpc-web-utils
INSTALL
IMPORT
SIG · GRPC-WEB-UTILS
G
grpc-web-utils
messagingjavascriptv0.1.0
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.

SignalStreamInterceptor
import { SignalStreamInterceptor } from 'grpc-web-utils'
const { SignalStreamInterceptor } = require('grpc-web-utils')
ESM-only; named export
MetadataWithSignal
import { MetadataWithSignal } from 'grpc-web-utils'
TypeScript type/interface for combining gRPC metadata with AbortSignal

Demonstrates deadline setting and AbortController-based cancellation for gRPC-Web streaming.

import { SignalStreamInterceptor } from 'grpc-web-utils'; import { EchoServiceClient } from './generated/proto/EchoServiceClientPb'; import { ServerStreamingEchoRequest } from './generated/proto/echo_pb'; const deadline = new Date(); deadline.setMilliseconds(deadline.getMilliseconds() + 1000); const md = {}; md['deadline'] = deadline.getTime().toString(); const options = { streamInterceptors: [new SignalStreamInterceptor()], }; const client = new EchoServiceClient('http://localhost:8080', null, options); const req = new ServerStreamingEchoRequest(); const controller = new AbortController(); const stream = client.serverStreamingEcho(req, { signal: controller.signal } as MetadataWithSignal); setTimeout(() => controller.abort(), 500);
Debug
Known issues
gotchacreatePromiseClient does not support cancellation; use client with interceptor approach.
fix
Use direct RPC client with SignalStreamInterceptor instead of createPromiseClient.
affects: >=0.1.0
gotchaThe MetadataWithSignal type must be cast explicitly; TypeScript may not infer correctly.
fix
Import MetadataWithSignal and use 'as MetadataWithSignal' on metadata object.
affects: >=0.1.0
gotchaStreamInterceptor only works with streaming RPCs; unary calls not supported for cancellation via this lib.
fix
Use deadline metadata for unary calls instead.
affects: >=0.1.0
gotchaDeadline must be passed as string (milliseconds) in metadata 'deadline' key.
fix
Use 'md["deadline"] = deadline.getTime().toString()' instead of number.
affects: >=0.1.0
Errors
Common errors & fixes
Property 'streamInterceptors' does not exist on type 'GRPCWebClientOptions'.
Missing or incorrect type definitions; SignalStreamInterceptor may not be recognized.
fix
Ensure you have installed grpc-web-utils and imported SignalStreamInterceptor. Use 'as any' or extend types if needed.
Cannot read properties of undefined (reading 'abort')
Controller.abort() called before controller is created or signal is not passed correctly.
fix
Ensure AbortController is instantiated and signal is passed in metadata options.
No overload matches this call. Overload 1 of 2, '(request: ServerStreamingEchoRequest, metadata?: grpc.Metadata | null, callback?: (error: grpc.ServiceError | null, response: ServerStreamingEchoResponse) => void): ClientReadableStream<ServerStreamingEchoResponse>', gave the following error.
MetadataWithSignal is not recognized as valid metadata type by grpc-web types.
fix
Use type assertion: 'client.serverStreamingEcho(req, { signal: controller.signal } as any)' or define custom type.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
15
Amazon
1
OpenAI (training)
1
Resources
grpc-web-utils — npm install grpc-web-utils · libregistry