Documentation / @super-line/core / defineContract
Function: defineContract()
defineContract<
C>(contract):C
Defined in: packages/core/src/contract.ts:95
Define a contract. An identity function — const preserves literal keys and subscribe: true so the full surface can be inferred on both ends.
Type Parameters
C
C extends Contract
Parameters
contract
C
Returns
C
Example
ts
import { z } from 'zod'
import { defineContract } from '@super-line/core'
export const api = defineContract({
shared: {
clientToServer: { join: { input: z.object({ room: z.string() }), output: z.object({ ok: z.boolean() }) } },
serverToClient: { message: { payload: z.object({ text: z.string() }) } },
},
roles: {
user: { clientToServer: { say: { input: z.object({ text: z.string() }), output: z.object({ id: z.string() }) } } },
agent: { clientToServer: { announce: { input: z.object({ text: z.string() }), output: z.object({ id: z.string() }) } } },
},
serverToServer: { rebalance: z.object({ shard: z.number() }) },
})