This sanity commit wires up the initial ZXDB integration and a minimal UI to explore it. Key changes: - Add Zod-based env parsing (`src/env.ts`) validating `ZXDB_URL` as a mysql:// URL (t3.gg style). - Configure Drizzle ORM with mysql2 connection pool (`src/server/db.ts`) driven by `ZXDB_URL`. - Define minimal ZXDB schema models (`src/server/schema/zxdb.ts`): `entries` and helper `search_by_titles`. - Implement repository search with pagination using helper table (`src/server/repo/zxdb.ts`). - Expose Next.js API route `GET /api/zxdb/search` with Zod query validation and Node runtime (`src/app/api/zxdb/search/route.ts`). - Create new app section “ZXDB Explorer” at `/zxdb` with search UI, results table, and pagination (`src/app/zxdb/*`). - Add navbar link to ZXDB (`src/components/Navbar.tsx`). - Update example.env with readonly-role notes and example `ZXDB_URL`. - Add drizzle-kit config scaffold (`drizzle.config.ts`). - Update package.json deps: drizzle-orm, mysql2, zod; devDeps: drizzle-kit. Lockfile updated. - Extend .gitignore to exclude large ZXDB structure dump. Notes: - Ensure ZXDB data and helper tables are loaded (see `ZXDB/scripts/ZXDB_help_search.sql`). - This commit provides structure-only browsing; future work can enrich schema (authors, labels, publishers) and UI filters. Signed-off-by: Junie@lucy.xalior.com
34 lines
999 B
TypeScript
34 lines
999 B
TypeScript
import { z } from "zod";
|
|
|
|
// Server-side environment schema (t3.gg style)
|
|
const serverSchema = z.object({
|
|
// Full MySQL connection URL, e.g. mysql://user:pass@host:3306/zxdb
|
|
ZXDB_URL: z
|
|
.string()
|
|
.url()
|
|
.refine((s) => s.startsWith("mysql://"), {
|
|
message: "ZXDB_URL must be a valid mysql:// URL",
|
|
}),
|
|
});
|
|
|
|
function formatErrors(errors: z.ZodFormattedError<Map<string, string>, string>) {
|
|
return Object.entries(errors)
|
|
.map(([name, value]) => {
|
|
if (value && "_errors" in value) {
|
|
return `${name}: ${(value as any)._errors.join(", ")}`;
|
|
}
|
|
return `${name}: invalid`;
|
|
})
|
|
.join("\n");
|
|
}
|
|
|
|
const parsed = serverSchema.safeParse(process.env);
|
|
if (!parsed.success) {
|
|
// Fail fast with helpful output in server context
|
|
// eslint-disable-next-line no-console
|
|
console.error("❌ Invalid environment variables:\n" + formatErrors(parsed.error.format()));
|
|
throw new Error("Invalid environment variables");
|
|
}
|
|
|
|
export const env = parsed.data;
|