Skip to main content

zod-schema

Add a new Zod validation schema to src/lib/validation.ts. All schemas MUST live in this file using zod/v4. Use when creating validation for new API endpoints.

跳到安装

来源信息

仓库
ahembree/librariarr
最近来源活动
2026年6月13日 20:16
检测到的 SKILL.md 语言
英语
星标
5
分支
1

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
zod-schema
description
Add a new Zod validation schema to src/lib/validation.ts. All schemas MUST live in this file using zod/v4. Use when creating validation for new API endpoints.
argument-hint
<schema-name> [field-descriptions]
# Zod Schema Generator Add a new validation schema for: $ARGUMENTS ## Rules (MANDATORY) 1. ALL schemas go in `src/lib/validation.ts` — NEVER define schemas inline in route files 2. Uses `zod/v4` subpath import: `import { z } from "zod/v4"` (already at top of file) 3. Export as `const`: `export const mySchema = z.object({ ... })` 4. Create schemas use required fields; Update schemas use `.partial()` on the create schema 5. Schema names use camelCase ending in `Schema` (e.g., `thingCreateSchema`, `thingUpdateSchema`) ## Common Patterns ### Required string: ```typescript name: z.string().min(1, "Name is required") ``` ### URL validation: ```typescript url: z.url("Invalid URL format") ``` ### Optional with default: ```typescript enabled: z.boolean().optional().default(true) ``` ### Enum: ```typescript type: z.enum(["MOVIE", "SERIES", "MUSIC"]) ``` ### Optional number with range: ```typescript delayDays: z.number().int().min(0).max(365).optional().default(7) ``` ### Optional string: ```typescript description: z.string().optional() ``` ### Nullable: ```typescript notes: z.string().nullable() ``` ### Array: ```typescript tags: z.array(z.string()).optional().default([]) ``` ## Create + Update Pair Pattern Most CRUD resources need both: ```typescript export const thingCreateSchema = z.object({ name: z.string().min(1, "Name is required"), url: z.url("Invalid URL format"), apiKey: z.string().min(1, "API key is required"), }); export const thingUpdateSchema = thingCreateSchema.partial(); ``` ## Existing Schema Examples for Reference - `arrInstanceCreateSchema` — name + url + apiKey (integration instances) - `blackoutCreateSchema` — complex with conditional fields and enums - `ruleSetCreateSchema` / `ruleSetUpdateSchema` — create + update pair - `syncScheduleSchema` — single field - `dashboardLayoutSchema` — nested objects with arrays - `customCardConfigSchema` — uses `.refine()` for cross-field validation ## Usage in API Routes After creating the schema, import and use it in the route: ```typescript import { validateRequest, thingCreateSchema } from "@/lib/validation"; const { data, error } = await validateRequest(request, thingCreateSchema); if (error) return error; ``` ## Steps 1. Read `src/lib/validation.ts` to find appropriate placement (schemas are loosely grouped by feature) 2. Define the schema following existing patterns 3. Export the schema 4. If a corresponding update schema is needed, create it with `.partial()` 5. Run `pnpm lint` to verify
在 GitHub 查看