refactor: ♻️ Use a typed wrapper for all API endpoints

This commit is contained in:
Jesse Wierzbinski 2024-08-19 20:06:38 +02:00 committed by April John
parent af931b8ade
commit 1a8e063f87
97 changed files with 479 additions and 382 deletions

View file

@ -1,5 +1,5 @@
import { errorResponse } from "@/response";
import type { Context } from "@hono/hono";
import type { Context, Hono } from "@hono/hono";
import { createMiddleware } from "@hono/hono/factory";
import type { StatusCode } from "@hono/hono/utils/http-status";
import { validator } from "@hono/hono/validator";
@ -44,6 +44,14 @@ export const applyConfig = (routeMeta: ApiRouteMetadata) => {
return newMeta;
};
export const apiRoute = (
fn: (
app: Hono /* <{
Bindings: {};
}> */,
) => void,
) => fn;
export const idValidator = createRegExp(
anyOf(digit, charIn("ABCDEF")).times(8),
exactly("-"),