基于 AST 的 TypeScript CMS
通过抽象语法树实现端到端类型安全,自动生成 API、数据库架构和前端类型定义
AST 解析引擎运行中
类型检查通过
Schema 设计器
内容类型
生成的 TypeScript 类型
AST 可视化
节点数: 0
深度: 0
实时预览
API 端点
GET
/api/posts
POST
/api/posts
PUT
/api/posts/:id
类型安全保证
基于 AST 的静态分析确保编译时类型检查,消除运行时类型错误。
Schema 即代码
使用 TypeScript 定义内容模型,享受 IDE 自动补全和类型检查,Schema 变更自动迁移数据库。
自动关系处理
智能解析内容类型间的关系,自动生成 GraphQL 解析器和数据库外键约束。
端到端类型
从数据库到前端 UI,全程 TypeScript 类型覆盖,重构无忧,API 变更即时反馈。
使用示例
定义 Schema → 生成类型 → 类型安全地查询内容
Server
Client
定义内容模型 (Schema.ts)
import { defineSchema } from 'emdash'; export const PostSchema = defineSchema({ name: 'Post', fields: { title: { type: 'string', required: true, validate: (val) => val.length > 5 }, content: { type: 'richText' }, author: { type: 'reference', to: 'Author' }, tags: { type: 'array', of: { type: 'string' } }, publishedAt: { type: 'date' } } });
类型安全查询 (Client.ts)
import { useContent } from 'emdash/react'; import type { Post } from './generated-types'; function BlogPost({ id }: { id: string }) { // 完全类型化的数据获取 const { data: post } = useContent<Post>('Post', id); if (!post) return null; return ( <article> <h1>{post.title}</h1> <time>{post.publishedAt.toLocaleDateString()}</time> <div>{post.author.name}</div> </article> ); }