Files
MOH 0a5f77d8de REFACTORED - migrate the data layer from Prisma to Drizzle (unify the stack)
- Add lib/db (Drizzle schema: 7 tables + 6 enums + relations, postgres.js client),
  drizzle.config.ts, lib/db/enums.ts (Prisma-compatible enum objects)
- Rewrite all 14 app consumers + 4 admin components to Drizzle
- Move the test DB layer to Drizzle + in-process PGlite; convert all 8 integration
  test files + factories (371 tests green)
- Remove Prisma: deps, prisma/ schema+migrations, lib/prisma.ts, Dockerfile prisma
  generate; wire db:generate/migrate/push/studio to drizzle-kit; update Makefile
- Preserve the old seed as scripts/legacy-prisma-seed.cjs (needs a Drizzle rewrite)
2026-08-07 14:18:41 +02:00

43 lines
1.2 KiB
TypeScript

import { MediaKind } from "@/lib/db/enums";
import { z } from "zod";
const mediaModeSchema = z.enum(["library", "external", "upload"]);
const optionalTrimmedText = z.string().trim().optional().transform((value) => value ?? "");
export const mediaFieldInputSchema = z
.object({
mode: mediaModeSchema,
assetId: optionalTrimmedText,
url: optionalTrimmedText,
label: optionalTrimmedText,
kind: z.nativeEnum(MediaKind),
})
.superRefine((value, context) => {
if (value.mode === "library" && !value.assetId) {
context.addIssue({
code: z.ZodIssueCode.custom,
path: ["assetId"],
message: "Library selection requires a media asset.",
});
}
if (value.mode === "external" && !value.url) {
context.addIssue({
code: z.ZodIssueCode.custom,
path: ["url"],
message: "External media requires a URL.",
});
}
if (value.url && !/^https?:\/\//.test(value.url) && !value.url.startsWith("/")) {
context.addIssue({
code: z.ZodIssueCode.custom,
path: ["url"],
message: "Media URL must be an absolute URL or start with /.",
});
}
});
export type MediaFieldInput = z.infer<typeof mediaFieldInputSchema>;