Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 3x 3x 3x 64x 24x 2x 64x 64x 64x 8x 8x 64x 64x 1x 30x | import { z } from "zod";
import type { ProjectConfig } from "../config";
import { refineWithMessage } from "./zodHelpers";
const targetTagSchema = (projectConfig: ProjectConfig) =>
refineWithMessage(
z.string(),
(value) => projectConfig.tags.includes(value),
(value) => `Unknown tag "${value}"`,
);
export function getTargetZodSchema(projectConfig: ProjectConfig) {
const tagSchema = targetTagSchema(projectConfig);
const featurePatternSchema = z
.string()
.min(1)
.refine((value) => value.trim() === value, "Feature patterns cannot have surrounding spaces")
.refine((value) => !value.includes("**"), 'Use "*" for glob-like wildcard matching');
const featurePatternsSchema = z.union([z.literal("*"), z.array(featurePatternSchema).min(1)]);
return z
.object({
key: z.string().optional(),
promotable: z.boolean().optional(),
description: z.string({
error: (issue) => (issue.input === undefined ? "Required" : undefined),
}),
tag: tagSchema.optional(),
tags: z
.union([
z.array(tagSchema).min(1),
z.object({ or: z.array(tagSchema).min(1) }).strict(),
z.object({ and: z.array(tagSchema).min(1) }).strict(),
])
.optional(),
includeFeatures: featurePatternsSchema.optional(),
excludeFeatures: featurePatternsSchema.optional(),
context: z.record(z.string(), z.unknown()).optional(),
})
.strict()
.refine((target) => !(target.tag && target.tags), {
message: 'Only one of "tag" or "tags" can be defined',
path: ["tags"],
});
}
|