Skip to content
TypeWire

@tahanabavi/typefetch-grpc

v0.1.0

gRPC transport for TypeFetch contracts — Connect unary JSON out of the box, binary grpc-web behind a codec seam, zero dependencies.

Contracts

ts
import { z } from 'zod'

export const contracts = {
user: {
getUser: {
transport: 'grpc',
service: 'user.v1.UserService',
rpc: 'GetUser',
request: z.object({ id: z.string() }),
response: z.object({ id: z.string(), name: z.string() }),
deadlineMs: 5_000,
},
},
}

transport: "grpc" does not compile until this package is installed — the module augmentation is what adds it to typefetch's registry. Once it is, a gRPC route is fully checked, including that it may not carry path, method, bodyType or responseType. None of those mean anything for a unary RPC.

Fields

FieldRequiredMeaning
serviceyesFully-qualified service, "user.v1.UserService"
rpcyesMethod name, "GetUser"
deadlineMsnoServer-side deadline (Connect-Timeout-Ms / grpc-timeout)
codecnoSwitches this RPC to binary protobuf — see below

deadlineMs is not RequestOptions.timeout. The timeout aborts locally; a deadline asks the server to stop working, which is what stops an abandoned query from holding a database connection. Setting both is normal — make the local timeout the more generous one.