import type { SQLOutputValue } from "node:sqlite"; import type { Category } from "../../shared/category.ts"; export interface CategoryRow { id: string; slug: string; name: string; position: number; created_at: string; updated_at: string | null; [key: string]: SQLOutputValue; } export function isCategoryRow(obj: unknown): obj is CategoryRow { return !!obj && typeof obj === "object" && "id" in obj && typeof obj.id === "string" && "slug" in obj && typeof obj.slug === "string" && "name" in obj && typeof obj.name === "string" && "position" in obj && typeof obj.position === "number" && "created_at" in obj && typeof obj.created_at === "string" && "updated_at" in obj && (typeof obj.updated_at === "string" || obj.updated_at === null); } export function categoryRowToApi(row: CategoryRow): Category { return { id: row.id, slug: row.slug, name: row.name, position: row.position, createdAt: new Date(row.created_at), updatedAt: row.updated_at ? new Date(row.updated_at) : undefined, }; }