API Reference
new KizunaServer()
Bind a contract to a server handle for defining guards, request context, and the router.
new KizunaServer(contract) is a server handle bound to your contract. It is the server-side counterpart to k: define guards, request context, and the router without passing the contract again.
pnpm add @ts-kizuna/expressbun add @ts-kizuna/expressnpm install @ts-kizuna/expressimport { KizunaServer } from '@ts-kizuna/express';pnpm add @ts-kizuna/fastifybun add @ts-kizuna/fastifynpm install @ts-kizuna/fastifyimport { KizunaServer } from '@ts-kizuna/fastify';pnpm add @ts-kizuna/honobun add @ts-kizuna/hononpm install @ts-kizuna/honoimport { KizunaServer } from '@ts-kizuna/hono';pnpm add @ts-kizuna/nextbun add @ts-kizuna/nextnpm install @ts-kizuna/nextimport { KizunaServer } from '@ts-kizuna/next';Parameters
new KizunaServer(contract: Contract, options?: ServerOptions): Server| Parameter | Type | Description |
|---|---|---|
contract | Contract | The contract from k.contract |
options.jobTransport | JobTransport | Where a queued job goes. See Jobs. |
options.onJobError | (job: string, error: unknown) => void | Called when a job queued without a transport rejects. |
import { KizunaServer } from '@ts-kizuna/express';
import { contract } from './contract';
export const server = new KizunaServer(contract);Returns
The handle. Keep it as server, the serving surface for this contract:
| Method | Description |
|---|---|
server.guard | Define the guard for one identity. See server.guard. |
server.requestContext | Resolve one declared request-context value. See server.requestContext. |
server.router | Bind typed handlers to the contract or one group. See server.router. |
server.jobs | Bind a handler to each declared job. See server.jobs. |
server.api | Assemble it all into the object you mount. See server.api. |
With jobs that you queue from your own code, name a transport here. Without one, queue runs the job in this process and it is lost on a crash:
export const server = new KizunaServer(contract, {
jobTransport: myQueue,
});Without a transport, a job that fails has already outlived its request and has nowhere to report. onJobError is where it surfaces; without one it is logged.
export const server = new KizunaServer(contract, {
onJobError: (job, error) => Sentry.captureException(error, { tags: { job } }),
});