From 2cadbb96f7e7dd454c5e625fd2c6f73e6f168cbd Mon Sep 17 00:00:00 2001 From: imbytecat Date: Sun, 18 Jan 2026 05:00:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=BE=85?= =?UTF-8?q?=E5=8A=9E=E4=BA=8B=E9=A1=B9=E5=90=88=E7=BA=A6=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=B8=8E=E5=AF=BC=E5=87=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新导入方式,将 todoContract 的导入改为命名空间导入并直接引用整个模块。 - 重构待办事项合约,将各操作方法从对象结构中提取为独立导出的常量。 --- src/orpc/contract.ts | 4 ++-- src/orpc/contracts/todo.ts | 36 +++++++++++++++++------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/orpc/contract.ts b/src/orpc/contract.ts index 19f8b05..c132aa1 100644 --- a/src/orpc/contract.ts +++ b/src/orpc/contract.ts @@ -1,5 +1,5 @@ -import { todoContract } from './contracts/todo' +import * as todo from './contracts/todo' export const contract = { - todo: todoContract, + todo, } diff --git a/src/orpc/contracts/todo.ts b/src/orpc/contracts/todo.ts index b9195a7..4e06241 100644 --- a/src/orpc/contracts/todo.ts +++ b/src/orpc/contracts/todo.ts @@ -21,25 +21,23 @@ const updateSchema = createUpdateSchema(todoTable).omit({ updatedAt: true, }) -export const todoContract = { - list: oc.input(z.void()).output(z.array(selectSchema)), +export const list = oc.input(z.void()).output(z.array(selectSchema)) - create: oc.input(insertSchema).output(selectSchema), +export const create = oc.input(insertSchema).output(selectSchema) - update: oc - .input( - z.object({ - id: z.uuid(), - data: updateSchema, - }), - ) - .output(selectSchema), +export const update = oc + .input( + z.object({ + id: z.uuid(), + data: updateSchema, + }), + ) + .output(selectSchema) - remove: oc - .input( - z.object({ - id: z.uuid(), - }), - ) - .output(z.void()), -} +export const remove = oc + .input( + z.object({ + id: z.uuid(), + }), + ) + .output(z.void())