marmar-context / web / context / server / schemas.ts
schemas.ts
Raw
import { z } from "zod";
export const sourcesSchema = z
  .array(
    z
      .object({
        id: z
          .string()
          .regex(/^[a-z0-9-]+$/)
          .max(60),
        title: z.string().min(1).max(120),
        kind: z.string().max(60),
        date: z.string().max(30),
        text: z.string().min(1).max(12000),
        clarification: z
          .object({
            sourceId: z
              .string()
              .regex(/^[a-z0-9-]+$/)
              .max(60),
            line: z.number().int().positive(),
            quote: z.string().min(1).max(12000),
            reason: z.string().trim().min(1).max(500),
            confirmedBy: z.string().trim().min(1).max(120),
          })
          .strict()
          .optional(),
      })
      .strict()
  )
  .min(1)
  .max(8)
  .refine(
    (sources) => new Set(sources.map((s) => s.id)).size === sources.length,
    "Source IDs must be unique"
  );
export const baseSchema = z.object({
  sources: sourcesSchema,
  syntheticOnly: z.literal(true),
});

export const coverageReviewSchema = z.record(z.string().max(250), z.object({
  fingerprint: z.string().length(64),
  reason: z.string().trim().min(10).max(500),
  confirmedBy: z.string().trim().min(1).max(120),
}).strict()).refine((value) => Object.keys(value).length <= 500, "Too many coverage resolutions").default({});