import type { Context } from "hono"; /** Parse a route param as a positive integer id. Returns null if invalid. */ export function parseId(raw: string | undefined): number | null { if (!raw) return null; const n = Number.parseInt(raw, 10); return Number.isFinite(n) && n > 0 ? n : null; } /** * Require a positive integer id param. Returns the id, or responds 400 * and returns null. Callers check for null and return the response. */ export function requireId(c: Context, name: string): number | null { const id = parseId(c.req.param(name)); if (id == null) { c.status(400); return null; } return id; } /** True if value is one of the allowed strings. */ export function isOneOf(value: unknown, allowed: readonly T[]): value is T { return typeof value === "string" && (allowed as readonly string[]).includes(value); }