import { z } from "zod" import { buildApp } from "../../index.js" export const coverageEntrySchema = z.object({ method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]), path: z.string().min(1), status: z.enum(["mediated", "excluded", "pending"]), operations: z.array(z.string()).max(100), reason: z.string().min(15) }).strict() export const coverageSchema = z.object({ version: z.literal(1), routes: z.array(coverageEntrySchema) }).strict() export type CoverageEntry = z.infer export const routeKey = (route: Pick) => route.method + " " + route.path export async function collectApplicationRoutes() { const routes = new Map>() const app = await buildApp({ logger: false, startScheduler: false, onRoute: route => { for (const method of Array.isArray(route.method) ? route.method : [route.method]) { if (!["GET", "POST", "PUT", "PATCH", "DELETE"].includes(method)) continue const item = { method: method as CoverageEntry["method"], path: route.url } routes.set(routeKey(item), item) } } }) try { await app.ready(); return [...routes.values()].sort((a, b) => routeKey(a).localeCompare(routeKey(b))) } finally { await app.close() } }