import { z } from 'zod';
// 用户模式
export const UserSchema = z.object({
id: z.number(),
username: z.string().min(3),
email: z.string().email(),
role: z.enum(['admin', 'editor', 'viewer']),
createdAt: z.string().datetime(),
updatedAt: z.string().datetime(),
});
// 文章模式
export const ArticleSchema = z.object({
id: z.number(),
slug: z.string(),
title: z.string().min(1),
description: z.string(),
body: z.string(),
author: UserSchema,
tagList: z.array(z.string()),
createdAt: z.string().datetime(),
updatedAt: z.string().datetime(),
});
// 文章响应模式
export const ArticleResponseSchema = z.object({
article: ArticleSchema,
});
// 文章列表响应模式
export const ArticlesResponseSchema = z.object({
articles: z.array(ArticleSchema),
articlesCount: z.number(),
});
// 推断类型
export type User = z.infer<typeof UserSchema>;
export type Article = z.infer<typeof ArticleSchema>;
export type ArticleResponse = z.infer<typeof ArticleResponseSchema>;
export type ArticlesResponse = z.infer<typeof ArticlesResponseSchema>;