ysd20265694

Define customer and lead schemas using Zod, returning field-level error messages in Chinese when parsing fails. Intended for Zod validation, schema validation, or customer form rule scenarios.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "ysd20265694" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-5b1f453ddc348e2630422dfb35a300338e08f50060b483bf2efd40173d3103ba. Verify the upstream source and version against https://skillhub.cn/skills/user_f1b049da/ysd20265694 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Define customer and lead schemas using Zod, returning field-level error messages in Chinese when parsing fails. Intended for Zod validation, schema validation, or customer form rule scenarios.

0 Downloads

Introduction source: third_party · user_f1b049da · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: ysd20265694
slug: ysd20265694
displayName: ZodSchema校验
version: 1.0.0
summary: 用 Zod 做 TypeScript-first 客户/线索 Schema 校验,前后端可共用规则。
license: MIT
description: 用 zod 定义客户与线索 Schema,解析失败给出字段级中文错误。当用户要 Zod 校验、Schema 校验、客户表单规则时使用。

Zod Schema 校验(zod)

灵感:能力工具箱 zod(pkg: zod)。

小四原创:一份 Schema,类型推断 + 运行时校验;表单提交前 safeParse,错误映射到字段。

何时使用

  • 客户/线索表单要统一校验规则
  • 前后端共用同一套字段约束
  • 比手写 if 更清晰的嵌套对象校验

硬约束

  1. 使用 zod;优先 safeParse,避免未捕获抛错白屏。
  2. 错误文案中文、对用户可读(errorMap 或字段 message)。
  3. 手机等格式可轻校验;深度运营商识别交给其它 Skill。
  4. 与 Yup 二选一作主方案时写清,勿双栈同字段。
  5. 实现要点注释标 小四原创。

推荐实现

import { z } from 'zod'

// 小四原创:客户最小 Schema
export const customerSchema = z.object({
  company: z.string().trim().min(2, '请填写公司名'),
  contact: z.string().trim().min(1, '请填写联系人'),
  mobile: z
    .string()
    .trim()
    .regex(/^1\d{10}$/, '手机号须为11位'),
  city: z.string().optional(),
  remark: z.string().max(500, '备注过长').optional(),
})

export type CustomerInput = z.infer<typeof customerSchema>

export function parseCustomer(data: unknown) {
  const r = customerSchema.safeParse(data)
  if (r.success) return { ok: true as const, data: r.data }
  const fieldErrors: Record<string, string> = {}
  for (const issue of r.error.issues) {
    const key = issue.path.join('.') || '_form'
    if (!fieldErrors[key]) fieldErrors[key] = issue.message
  }
  return { ok: false as const, fieldErrors }
}

Agent 步骤

  1. 定义 Schema + z.infer 类型。
  2. 表单提交调用 parseCustomer;失败写回控件错误。
  3. 可选:z.array(customerSchema) 做批量导入预检。
  4. 自测:缺字段、手机非法、合法对象三条路径。

不要做

  • 把 Zod 当唯一权限/鉴权层。
  • 在 Schema 里发网络请求。

附加

Current listing version

1.0.0

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value75/100

Highlights

  • 提供客户/线索表单校验的通用解决方案,前后端可共用规则
  • 适用于表单校验、批量导入预检等明确场景
Trigger Precision85/100

Highlights

  • 触发词精准覆盖 Zod 校验、Schema 校验、客户表单规则等核心场景
  • 边界清晰,不易与其他 Skill 重叠
Structure and Standards88/100

Highlights

  • 结构完整,包含使用场景、约束、实现示例、步骤和自测路径
  • frontmatter 完整,代码示例清晰,文档规范
Execution Reliability85/100

Highlights

  • 使用 safeParse 避免未捕获错误,错误映射到字段
  • 覆盖主要异常路径,实现可靠
Evidence Verifiability (mean of the first four)83/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.