chore: 更新版本号至0.0.76,并在 route.ts 中添加 extractArgs 函数
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package",
|
||||
"name": "@kevisual/router",
|
||||
"version": "0.0.75",
|
||||
"version": "0.0.76",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"main": "./dist/router.js",
|
||||
@@ -21,7 +21,6 @@
|
||||
"keywords": [],
|
||||
"author": "abearxiong",
|
||||
"license": "MIT",
|
||||
"packageManager": "pnpm@10.30.0",
|
||||
"devDependencies": {
|
||||
"@kevisual/code-builder": "^0.0.6",
|
||||
"@kevisual/context": "^0.0.6",
|
||||
|
||||
16
src/route.ts
16
src/route.ts
@@ -245,14 +245,20 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
|
||||
throw new CustomError(...args);
|
||||
}
|
||||
}
|
||||
export const extractArgs = (args: any) => {
|
||||
if (args && typeof args === 'object' && typeof args.shape === 'object') {
|
||||
return args.shape as z.ZodRawShape;
|
||||
}
|
||||
return args || {};
|
||||
};
|
||||
|
||||
export const toJSONSchema = (route: RouteInfo) => {
|
||||
const pickValues = pick(route, pickValue as any);
|
||||
if (pickValues?.metadata?.args) {
|
||||
const args = pickValues.metadata.args;
|
||||
if (args && typeof args === 'object' && args.toJSONSchema && typeof args.toJSONSchema === 'function') {
|
||||
pickValues.metadata.args = args.toJSONSchema();
|
||||
return pickValues;
|
||||
}
|
||||
let args = pickValues.metadata.args;
|
||||
// 如果 args 本身是一个 zod object schema,先提取 shape
|
||||
args = extractArgs(args);
|
||||
|
||||
const keys = Object.keys(args);
|
||||
const newArgs: { [key: string]: any } = {};
|
||||
for (let key of keys) {
|
||||
|
||||
Reference in New Issue
Block a user