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