Zod validation schemas for creating and updating catalog categories. Use these to enforce data integrity and length constraints on category inputs.
// Source: https://github.com/foxminchan/BookWorm | License: MIT | Copyright Nhan Nguyen (nguyenxuannhan407@gmail.com)
// Provided via justclaw.it.com; keep this notice with the code.
import { z } from "zod";
const MAX_CATEGORY_NAME_LENGTH = 50;
export const createCategorySchema = z.object({
name: z
.string()
.min(1, "Name is required")
.max(
MAX_CATEGORY_NAME_LENGTH,
`Name must be ${MAX_CATEGORY_NAME_LENGTH} characters or less`,
),
});
export const updateCategorySchema = z.object({
id: z.uuid({ error: "Invalid ID format" }),
name: z
.string()
.min(1, "Name is required")
.max(
MAX_CATEGORY_NAME_LENGTH,
`Name must be ${MAX_CATEGORY_NAME_LENGTH} characters or less`,
),
});
export type CreateCategoryInput = z.infer<typeof creat
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key