UNPKG

@code-pushup/models

Version:

Model definitions and validators for the Code PushUp CLI

39 lines 1.5 kB
import { z } from 'zod'; import { tableCellValueSchema } from './implementation/schemas.js'; export const tableAlignmentSchema = z .enum(['left', 'center', 'right']) .describe('Cell alignment'); export const tableColumnPrimitiveSchema = tableAlignmentSchema; export const tableColumnObjectSchema = z.object({ key: z.string(), label: z.string().optional(), align: tableAlignmentSchema.optional(), }); export const tableRowObjectSchema = z .record(z.string(), tableCellValueSchema) .describe('Object row'); export const tableRowPrimitiveSchema = z .array(tableCellValueSchema) .describe('Primitive row'); const tableSharedSchema = z.object({ title: z.string().optional().describe('Display title for table'), }); const tablePrimitiveSchema = tableSharedSchema .merge(z.object({ columns: z.array(tableAlignmentSchema).optional(), rows: z.array(tableRowPrimitiveSchema), })) .describe('Table with primitive rows and optional alignment columns'); const tableObjectSchema = tableSharedSchema .merge(z.object({ columns: z .union([ z.array(tableAlignmentSchema), z.array(tableColumnObjectSchema), ]) .optional(), rows: z.array(tableRowObjectSchema), })) .describe('Table with object rows and optional alignment or object columns'); export const tableSchema = (description = 'Table information') => z.union([tablePrimitiveSchema, tableObjectSchema]).describe(description); //# sourceMappingURL=table.js.map