Skip to main content

Type Alias: XRPCHandler()<TInput, TOutput>

XRPCHandler<TInput, TOutput>: (c, input) => Promise<TOutput>

Defined in: src/api/types/handlers.ts:72

XRPC handler function type.

Type Parameters

TInput

Validated input type from Zod schema

TOutput

Output type matching output schema

Parameters

c

Context<ChiveEnv>

input

TInput

Returns

Promise<TOutput>

Remarks

Handlers receive the Hono context and validated input parameters. They should return the output directly; errors should be thrown as ChiveError subclasses for centralized handling.

Example

const handler: XRPCHandler<GetSubmissionInput, GetSubmissionOutput> =
async (c, input) => {
const { preprint } = c.get('services');
const result = await preprint.getPreprint(input.uri);
if (!result) {
throw new NotFoundError('Preprint', input.uri);
}
return { uri: result.uri, ... };
};