Skip to content
File

Blob: worker/src/server/routes/context.ts

typescript11 lines
1import type { Context } from 'hono';
2import type { z } from 'zod';
3import { body, parse, rpcResponse } from '@/server/http.ts';
4import type { HttpApp } from '@/server/http.ts';
5 
6export const room = (c: Context<HttpApp>) => c.env.ROBOTS.getByName(c.env.ROBOT_NAME);
7export const result = <T>(c: Context<HttpApp>, value: Parameters<typeof rpcResponse<T>>[0]) =>
8 rpcResponse(value, c.get('requestId'));
9export const input = async <T>(c: Context<HttpApp>, schema: z.ZodType<T>) =>
10 parse(schema, await body(c.req.raw));