Skip to content

@forinda/kickjs-grpc

Connect RPC transport for KickJS — serves gRPC, gRPC-Web, and the Connect protocol from the same app and port as your HTTP routes, using the same decorator-driven approach as HTTP controllers.

See the gRPC guide for the full walkthrough.

Installation

bash
pnpm add @forinda/kickjs-grpc @connectrpc/connect @connectrpc/connect-node @bufbuild/protobuf

@connectrpc/connect, @connectrpc/connect-node, and @bufbuild/protobuf are peer dependencies — they carry the protocol implementation and the generated descriptor runtime.

Exports

Decorators

DecoratorDescription
@GrpcService(descriptor)Bind a DI-registered class to a generated protobuf DescService
@GrpcMethod(rpc?)Bind a class method to an RPC (defaults to the method's own name)

Adapter

ExportDescription
GrpcAdapterAppAdapter that mounts Connect RPC on the existing HTTP server
GRPC_ADAPTERDI token resolving to { getStats(), listServices() }

Context

ExportDescription
GrpcContextPer-RPC context; implements the transport-neutral ExecutionContext

Errors

ExportDescription
toConnectError(err)Normalize any thrown value into a ConnectError. Unexpected errors are redacted to INTERNAL_ERROR_MESSAGE; the original stays on cause
INTERNAL_ERROR_MESSAGEThe opaque message sent for every Code.Internal response ("Internal error")
codeForStatus(n)Map an HTTP status onto the corresponding Connect Code

Lower-level

ExportDescription
collectServices()Read decorated service classes out of the registry
buildConnectRoutes(opts)Turn service entries into a Connect routes function
grpcServiceRegistryThe Set of @GrpcService-decorated classes
GRPC_METADATAMetadata keys this package writes

Types

ExportDescription
GrpcAdapterOptionsOptions accepted by GrpcAdapter
GrpcAdapterExtensionsPublic surface behind the GRPC_ADAPTER token
GrpcServiceEntryA service class paired with its descriptor
GrpcHandlerDefinitionOne @GrpcMethod binding
GrpcStatsSnapshot returned by getStats()
BuildConnectRoutesOptionsInput to buildConnectRoutes

Adapter options

OptionDefaultDescription
prefix''Path prefix for all RPCs. Leave empty for native gRPC clients.
grpctrueEnable the binary gRPC protocol (requires HTTP/2 in front)
grpcWebtrueEnable gRPC-Web (works over HTTP/1.1)
connecttrueEnable the Connect protocol (JSON over HTTP, curl-able)
contributors[]Context Contributors applied to every RPC, at the adapter level of the method > class > module > adapter > global chain. module and global are HTTP-only and never reach an RPC — this is the way to cover all of them.
routesRegister services Connect-style, bypassing decorators
readMaxBytesMax size of an inbound message
writeMaxBytesMax size of an outbound message
onErrorRewrite a failure before it goes on the wire

Protocol support

The adapter rides the KickJS HTTP server, which speaks HTTP/1.1:

ProtocolWorksNotes
ConnectJSON or binary over HTTP/1.1
gRPC-WebBrowser clients
native gRPCNeeds HTTP/2 + trailers — terminate with a proxy first

Released under the MIT License. Built with TypeScript — runs on Express, Fastify, or h3.