UNPKG

@code-pushup/models

Version:

Model definitions and validators for the Code PushUp CLI

41 lines 2 kB
import { z } from 'zod'; import { createDuplicateSlugsCheck, createDuplicatesCheck, } from './implementation/checks.js'; import { metaSchema, scorableSchema, scoreTargetSchema, slugSchema, weightedRefSchema, } from './implementation/schemas.js'; import { formatRef } from './implementation/utils.js'; export const categoryRefSchema = weightedRefSchema('Weighted references to audits and/or groups for the category', 'Slug of an audit or group (depending on `type`)') .extend({ type: z.enum(['audit', 'group']).meta({ description: 'Discriminant for reference kind, affects where `slug` is looked up', }), plugin: slugSchema.describe('Plugin slug (plugin should contain referenced audit or group)'), }) .meta({ title: 'CategoryRef' }); export const categoryConfigSchema = scorableSchema('Category with a score calculated from audits and groups from various plugins', categoryRefSchema, createDuplicatesCheck(serializeCategoryRefTarget, duplicates => `Category has duplicate references: ${formatSerializedCategoryRefTargets(duplicates)}`)) .extend(metaSchema({ titleDescription: 'Category Title', docsUrlDescription: 'Category docs URL', descriptionDescription: 'Category description', description: 'Meta info for category', }).shape) .extend({ scoreTarget: scoreTargetSchema }) .meta({ title: 'CategoryConfig' }); const CATEGORY_REF_SEP = '||'; function serializeCategoryRefTarget(ref) { return [ref.type, ref.plugin, ref.slug].join(CATEGORY_REF_SEP); } function formatSerializedCategoryRefTargets(keys) { return keys .map(key => { const [type, plugin, slug] = key.split(CATEGORY_REF_SEP); return formatRef({ type, plugin, slug }); }) .join(', '); } export const categoriesSchema = z .array(categoryConfigSchema) .check(createDuplicateSlugsCheck('Category')) .meta({ title: 'Categories', description: 'Categorization of individual audits', }); //# sourceMappingURL=category-config.js.map