@lark-apaas/coding-miaoda-sandbox-skills 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,8 +9,10 @@ Shadcn Form + React Hook Form + Zod 表单开发。
9
9
 
10
10
  ## Guidelines
11
11
 
12
- - 类型必须用 `z.infer` 推导,禁止手动定义
13
- - 所有字段必须有默认值
12
+ - 表单类型由 zod schema 推导;所有字段必须有 `defaultValues`;运行时校验用 `zodResolver`
13
+ - 提交到必填 API/service Request 时,submit 的类型边界用业务 Request:Request 类型可读就 `const payload: XxxRequest = { ... }` 逐字段补齐;不可读但函数签名可读用 `Parameters<typeof submit>[0]` 派生
14
+ - 补 `useForm<TFieldValues, TContext, TTransformedValues>` 的泛型参数解决不了这个问题
15
+ - API 合同允许字段可选的查询、筛选、搜索表单,继续提交 `z.infer` 值
14
16
  - 必须用 Shadcn 组件,禁止原生 input
15
17
  - 同行 FormField 必须等宽
16
18
  - 表单提交到必填 API/DTO/Request/interface 前,先读目标 shared/server 类型,在 `handleSubmit` 回调里用 `data` 逐字段构造 typed request(见 Patterns);不要整体传 `data`、`schema.parse(data)` 或 `.required().parse(data)`,也不要用 `any`/`as` 绕过 TS2322。修完后跑 LSP 或 `typecheck`。
@@ -37,15 +39,34 @@ const studentSchema = z.object({
37
39
 
38
40
  type StudentFormData = z.infer<typeof studentSchema>;
39
41
 
42
+ interface CreateStudentRequest {
43
+ name: string;
44
+ age: number;
45
+ grade: string;
46
+ }
47
+
48
+ async function createStudent(payload: CreateStudentRequest) {
49
+ logger.info(payload);
50
+ }
51
+
40
52
  export function StudentForm() {
41
53
  const form = useForm<StudentFormData>({
42
54
  resolver: zodResolver(studentSchema),
43
55
  defaultValues: { name: "", age: 0, grade: "" },
44
56
  });
45
57
 
58
+ const handleSubmit = async (values: StudentFormData) => {
59
+ const payload: CreateStudentRequest = {
60
+ name: values.name,
61
+ age: values.age,
62
+ grade: values.grade,
63
+ };
64
+ await createStudent(payload);
65
+ };
66
+
46
67
  return (
47
68
  <Form {...form}>
48
- <form onSubmit={form.handleSubmit((data) => logger.info(data))} className="space-y-6">
69
+ <form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-6">
49
70
  <div className="flex flex-wrap gap-4">
50
71
  <FormField control={form.control} name="name" render={({ field }) => (
51
72
  <FormItem className="flex-1">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/coding-miaoda-sandbox-skills",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Miaoda 合并沙箱 skills 包(包含原 miaoda-skills 的 miaoda / miaoda-modern / miaoda-design / shared 四条业务线);发布公网 npm,随沙箱运行时经 update-skills 同步到 .agent/skills/",
5
5
  "type": "module",
6
6
  "files": [