GrpcStream
Class: GrpcStream<RequestType, ResponseType>
Defined in: grpc/src/grpc-stream.ts:28
gRPC bidirectional stream handler.
Manages frame parsing (5-byte header: compressed flag + 4-byte big-endian length), message deserialization, and response framing for HTTP/2 gRPC streams.
Supports all four gRPC patterns:
- Unary (single request, single response)
- Server streaming (single request, stream of responses)
- Client streaming (stream of requests, single response)
- Bidirectional streaming (stream of requests, stream of responses)
Type Parameters
RequestType
RequestType = any
ResponseType
ResponseType = any
Constructors
Constructor
new GrpcStream<
RequestType,ResponseType>(req,res,definition):GrpcStream<RequestType,ResponseType>
Defined in: grpc/src/grpc-stream.ts:47
Create a new GrpcStream to handle a single gRPC request/response lifecycle.
Parameters
req
IncomingMessage | Http2ServerRequest
the incoming HTTP/2 request carrying the gRPC frames
res
ServerResponse<IncomingMessage> | Http2ServerResponse<Http2ServerRequest>
the HTTP/2 response used to write gRPC frames and trailers
definition
GrpcMethodDef<RequestType, ResponseType>
protobuf method definition providing serialize/deserialize functions
Returns
GrpcStream<RequestType, ResponseType>
Properties
OK
staticOK:symbol
Defined in: grpc/src/grpc-stream.ts:30
Sentinel value indicating successful stream setup
Methods
end()
end(
status?,message?):void
Defined in: grpc/src/grpc-stream.ts:143
End the response with gRPC status trailers.
Parameters
status?
number = 0
gRPC status code (0 = OK)
message?
string
optional status message included in grpc-message trailer
Returns
void
void
onCancel()
onCancel(
handler):this
Defined in: grpc/src/grpc-stream.ts:118
Register handler for stream cancellation (client disconnected)
Parameters
handler
() => void
callback invoked when the underlying connection is closed by the client
Returns
this
this instance for chaining
onEnd()
onEnd(
handler):this
Defined in: grpc/src/grpc-stream.ts:108
Register handler for stream end (client finished sending)
Parameters
handler
() => void
callback invoked when the client closes the send side of the stream
Returns
this
this instance for chaining
onMessage()
onMessage(
handler):this
Defined in: grpc/src/grpc-stream.ts:98
Register handler for incoming messages
Parameters
handler
(message) => void | Promise<void>
callback invoked with each deserialized request message
Returns
this
this instance for chaining
send()
send(
message):void
Defined in: grpc/src/grpc-stream.ts:128
Send a response message with gRPC framing.
Parameters
message
ResponseType
the response message to serialize and send
Returns
void
void
sendError()
sendError(
status,message):void
Defined in: grpc/src/grpc-stream.ts:168
Send an error response and close the stream.
Parameters
status
number
gRPC status code indicating the error type
message
string
human-readable error message included in grpc-message trailer
Returns
void
void
sendUnary()
sendUnary(
message):void
Defined in: grpc/src/grpc-stream.ts:157
Send a single unary response and close the stream.
Parameters
message
ResponseType
the response message to serialize and send before closing
Returns
void
void