refactor: 重构RPC合约与客户端类型体系

- 更新客户端类型引用,将APIClient替换为RouterClient以保持类型一致性。
- 删除旧的 RPC 合约定义文件,移除过时的类型和验证逻辑。
- 添加合约入口文件并导出待办事项合约
- 添加待办事项合约,定义列表、创建、更新和删除操作的输入输出验证规则。
- 更新 todo 处理程序以使用统一的合约导入并简化导入路径。
- 调整导出内容,仅导出客户端的orpc函数和类型模块。
- 使用合约类型替换原有路由客户端类型,并引入合约输入输出的类型推断。
This commit is contained in:
2026-01-18 03:37:51 +08:00
parent 1d8479c063
commit ae36575256
7 changed files with 71 additions and 63 deletions

View File

@@ -1,11 +1,11 @@
import { createORPCClient } from '@orpc/client'
import { RPCLink } from '@orpc/client/fetch'
import { createRouterClient, type RouterClient } from '@orpc/server'
import { createRouterClient } from '@orpc/server'
import { createTanstackQueryUtils } from '@orpc/tanstack-query'
import { createIsomorphicFn } from '@tanstack/react-start'
import { getRequestHeaders } from '@tanstack/react-start/server'
import { router } from './router'
import type { APIClient } from './types'
import type { RouterClient } from './types'
const getORPCClient = createIsomorphicFn()
.server(() =>
@@ -19,9 +19,9 @@ const getORPCClient = createIsomorphicFn()
const link = new RPCLink({
url: `${window.location.origin}/api/rpc`,
})
return createORPCClient<APIClient>(link)
return createORPCClient<RouterClient>(link)
})
const client: APIClient = getORPCClient()
const client: RouterClient = getORPCClient()
export const orpc = createTanstackQueryUtils(client)