Files
DevFlow/docs/02-架构设计/前后端类型对齐-2026-06-12.md
绝尘 f3c0967f41 修复: AR-3 审批 reason 查项目名拼对象名(用户再反馈 P0)
build_approval_reason 改 async + 接收 db,对 delete/restore/purge/update/bind/create_task 的 id/project_id 查 ProjectRepo.get_by_id 拼「项目名」(id=x)(原只拼裸 id,用户反馈'只返回 ID 不知道是什么数据')
新增 resolve_project_label helper;process_tool_calls 调用改 await
来源 aichat审查报告 第二章 + 用户 2026-06-14 再反馈;cargo 0 err
2026-06-14 17:16:28 +08:00

83 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 前后端类型对齐
> 创建: 2026-06-10 | 状态: 初稿
---
## 概述
DevFlow 前端 (TypeScript) 和后端 (Rust) 通过 Tauri IPC 和 JSON 序列化通信。两侧的类型定义必须保持一致。
## 类型映射
### 基础类型
| Rust | TypeScript | 说明 |
|------|-----------|------|
| `String` | `string` | 文本字段 |
| `i64` | `number` | 时间戳 (Unix timestamp) |
| `Option<String>` | `string \| null` | 可空字段 |
| `Vec<String>` | `string[]` | 数组 (JSON 序列化) |
| `bool` | `boolean` | 布尔值 |
### ID 类型
| 实体 | Rust | TypeScript | 格式 |
|------|------|-----------|------|
| 所有 ID | `String` | `string` | UUID v4 |
所有 ID 统一使用 UUID v4 字符串,便于前后端传递。
### 枚举对齐
#### IdeaStatus (8 值)
| Rust | TypeScript |
|------|-----------|
| `Draft` | `"Draft"` |
| `Evaluating` | `"Evaluating"` |
| `Scored` | `"Scored"` |
| `Hot` | `"Hot"` |
| `Promoted` | `"Promoted"` |
| `Parked` | `"Parked"` |
| `Merged` | `"Merged"` |
| `Discarded` | `"Discarded"` |
#### TaskStatus (6 值)
| Rust | TypeScript |
|------|-----------|
| `Created` | `"Created"` |
| `BranchCreated` | `"BranchCreated"` |
| `InProgress` | `"InProgress"` |
| `ReviewReady` | `"ReviewReady"` |
| `Merged` | `"Merged"` |
| `Abandoned` | `"Abandoned"` |
#### WorkflowRunStatus (6 值)
| Rust | TypeScript |
|------|-----------|
| `Pending` | `"Pending"` |
| `Running` | `"Running"` |
| `Paused` | `"Paused"` |
| `Completed` | `"Completed"` |
| `Failed` | `"Failed"` |
| `Cancelled` | `"Cancelled"` |
#### ProjectStatus (4 值)
| Rust | TypeScript |
|------|-----------|
| `Active` | `"Active"` |
| `Paused` | `"Paused"` |
| `Completed` | `"Completed"` |
| `Archived` | `"Archived"` |
## 约定
1. 枚举值使用 PascalCase 字符串,前后端保持一致
2. JSON 字段(如 `scores``tags`)在 Rust 侧用 `TEXT` 存储 JSON 字符串,前端解析为对象/数组
3. 时间字段统一用 `i64` (Unix timestamp),前端用 `new Date(ts * 1000)` 转换
4. 新增枚举值时Rust 和 TypeScript 两侧必须同步更新