Example 1
Example 1
import { createApplication } from '@setu-ts/kernel'; import { RuntimePlugin } from '@setu-ts/runtime'; import { GrpcPlugin } from '@setu-ts/grpc-plugin'; import { CAPABILITIES, type IGrpcService } from '@setu-ts/common'; const app = createApplication({ plugins: [RuntimePlugin(), GrpcPlugin()], }); await app.start({ port: 3000 }); // The plugin registers CAPABILITIES.GRPC during start(), so resolve it // only AFTER start() resolves — before that, the capability does not exist. const grpc = app.services.get<IGrpcService>(CAPABILITIES.GRPC);
Thrown when an embedded descriptor set cannot be decoded, or when a service the plugin expects to find inside one is absent — i.e. the committed base64 constant is truncated, swapped, or regenerated against an incompatible proto.
Thrown when any of the Connect runtime modules cannot be imported. Carries the exact specifier that failed and the suggested install command.
-
specifier: string
The specifier that failed to import.
The gRPC service applications use to register Connect/gRPC services.
-
addService<TDef extends GrpcServiceDefinition>(): voiddefinition: TDef,implementation?: unknown
Registers a gRPC service definition with an optional implementation.
-
available: boolean
Whether gRPC dispatch is available. Always
truesince the kernel now resolvesIGrpcServicefrom the service registry and dispatches after the middleware pipeline (M70a). The previous adapter-based seam is retired. -
claims(request: Request): boolean
Whether this service claims the request's path — that is, whether the path lies inside the configured
basePath. -
close(): void
Releases the built router and its handlers. Afterwards the plugin's own procedures answer
503instead of rebuilding a router for an application that is shutting down, while every other path falls through untouched. -
createFetchHandler(): RpcFetchHandler
The handler that used to be installed into
IHttpAdapter.setRpcHandler. Returnsnullfor any request outsidebasePath. -
handleRequest(request: Request): Promise<Response>
Handles an RPC request directly.
-
refuses(request: Request): Response | null
Refuses a native
application/grpcrequest from its HEADERS alone. -
serviceCount(): number
Number of application services registered. Read by the health indicator.
Adapts already-imported Connect and Protobuf-ES modules into the internal
ConnectRuntime port. Pure — it performs no I/O, so unit tests
drive it with a fake module bundle.
Creates the gRPC plugin.
The four modules the runtime is adapted from.
Options for the gRPC plugin.
-
basePath: string
Base path under which gRPC/Connect services are served. Defaults to the root (
'/', M70i). A gRPC-family client derives its path from the fully-qualified method name alone and has no prefix option, so a prefixed default puts every procedure at an address no such client asks for. At the root, unknown paths fall through to Hono and only registered procedure paths are claimed. This makes Connect and gRPC-Web reachable at their natural addresses; nativeapplication/grpcreaches the server too but is deliberately refused with a Trailers-OnlyUNIMPLEMENTED. Pass'/grpc'to restore the pre-M70i prefix. -
connectModule: ConnectRuntime
Injected Connect runtime module(s). When provided, avoids the lazy import. Used by tests to avoid network dependencies.
-
health: boolean
Whether to enable the gRPC Health v1 service (bridged to M20 health plugin). Defaults to
true. -
interceptors: readonly unknown[]
Application-supplied Connect interceptors, threaded into
createConnectRouter({ interceptors })(M70f §3.7). The plugin's built-in handler-error logging wraps each application service's implementation (innermost), so a handler throw is logged before an application interceptor observes it. Absent: no application interceptors are installed. -
reflection: boolean
Whether to enable server reflection (v1). Defaults to
true. -
services: Array<{ definition: unknown; implementation?: unknown; }>
Initial services to register. Each entry contains a service definition and an optional implementation object.
A gRPC service definition that satisfies the plugin's expectations.
This is a structural constraint satisfied by generated descriptor objects
from @bufbuild/protobuf. It contains only the fields the plugin
needs to route requests and build reflection data.
-
method: Readonly<Record<string, TMethod>>
Methods keyed by their camelCase local name.
-
typeName: string
The fully qualified name of the service, e.g.
"package.ServiceName".
The service contract that applications use to register gRPC/Connect services.
Provided by the grpc-plugin under the CAPABILITIES.GRPC token.
-
addService<TDef extends GrpcServiceDefinition>(): voiddefinition: TDef,implementation?: unknown
Registers a gRPC service definition with an optional implementation.
-
available: boolean
Whether gRPC dispatch is available.
-
claims(request: Request): boolean
Whether this service claims a request — that is, whether the request path lies inside the configured
basePath. -
handleRequest(request: Request): Promise<Response>
Handles an incoming RPC request directly.
-
refuses(request: Request): Response | null
Whether this service refuses the request outright, decided from its HEADERS alone.
The serving status returned by the health bridge. These values map onto the gRPC v1 Health response enum.
A fetch handler that attempts to handle a gRPC/Connect request.
Returns a Response if the request was handled as RPC,
otherwise returns null so the adapter falls through to normal
Hono handling.
Standard capability tokens provided by the first-party plugins.
-
AUDIT: string
Audit trail logging.
-
AUTH: string
Authentication service.
-
AUTHORIZATION: string
Authorization service (RBAC, permissions).
-
CACHE: string
Key/value caching.
-
CLI_COMMAND: string
CLI command contributions (multi-provider).
-
CLOUDFLARE: string
Cloudflare Workers platform bindings (KV, R2, D1, Queues, service and Durable Object namespaces) published as one typed accessor.
-
COMMAND_BUS: string
Command bus (CQRS).
-
CONFIG: string
Configuration access.
-
CQRS: string
CQRS facade.
-
DATABASE: string
Database access (repositories, unit of work).
-
DECORATOR_HANDLER: string
Decorator handler contributions (multi-provider).
-
DI_CONTAINER: string
Optional dependency injection container.
-
EVENTS: string
In-memory domain event bus.
-
FEATURE_FLAGS: string
Feature flag evaluation.
-
GRAPHQL: string
GraphQL plugin — schema-first and code-first GraphQL-over-HTTP.
-
GRPC: string
gRPC plugin — server-side Connect/gRPC/gRPC-Web co-serving.
-
HEALTH: string
Health checks.
-
HEALTH_INDICATOR: string
Health indicator contributions (multi-provider).
-
HTTP_ADAPTER: string
HTTP server adapter — the runtime plugin registers its IHttpAdapter here.
-
JWT: string
JWT sign/verify service.
-
LOGGER: string
Structured logger.
-
MAIL: string
Email sending.
-
MESSAGING: string
Message broker for integration events.
-
METADATA_STORE: string
Decorator metadata store (from the DecoratorPlugin, when registered).
-
METRICS: string
Metrics collection.
-
METRIC_REGISTRATION: string
Metric registration contributions (multi-provider).
-
MULTI_TENANCY: string
Multi-tenancy service.
-
NOTIFICATION: string
Multi-channel notifications.
-
OPENAPI: string
OpenAPI spec contribution and generation.
-
OPENAPI_SCHEMA: string
OpenAPI schema contributions (multi-provider).
-
QUERY_BUS: string
Query bus (CQRS).
-
QUEUE: string
Background job queue.
-
REALTIME_BACKPLANE: string
Pub/sub transport carrying real-time broadcasts between application instances, so WebSocket rooms and SSE channels fan out across replicas. Consumed optionally — absent means purely in-process broadcasting.
-
RESILIENCE: string
Resilience patterns (circuit breaker, retry, timeout, bulkhead).
-
RUNTIME: string
Runtime services provided by the RuntimePlugin. Mandatory in every application.
-
SCHEDULER: string
Job scheduling (cron, delayed, recurring).
-
SECRETS: string
Secret management.
-
SERVICE_DISCOVERY: string
Service discovery — logical service name to reachable instances.
-
SESSION: string
Cookie-backed sessions for server-rendered applications.
-
SSE: string
Server-Sent Events (SSE) hub for in-process real-time broadcasting.
-
SSR: string
Server-side rendering (SSR) — React Router or similar framework.
-
STATIC_FILES: string
Static file serving plugin.
-
STORAGE: string
File storage.
-
TELEMETRY: string
Distributed tracing.
-
VALIDATION: string
Request/data validation.
-
VIEW: string
View rendering (server-rendered HTML) — an
IViewEnginethat turns a view component and its props into an HTML string, so a handler can answer with markup it did not concatenate by hand. -
WEBSOCKET: string
WebSocket hub for bidirectional real-time messaging.
-
WORKER_POOL: string
Worker-thread pool for CPU-bound tasks.
Usage
import * as gRPC_plugin_for_Setu_TS___enables_co_serving_of_Connect_and_gRPC_Web_protocols__native__application_grpc__is_refused_with_a_Trailers_Only__UNIMPLEMENTED___on_the_same_port_as_ordinary_Hono_routes__The_plugin_registers_an___linkcode_IGrpcService__under__CAPABILITIES_GRPC___since_M70a_the_kernel_dispatches_RPC_from_its_terminal_handler_after_the_middleware_pipeline__so_no_HTTP_adapter_interceptor_is_involved__ from "grpc-plugin/src/index.ts";