chore: bump @kevisual/router to version 0.0.80, update QueryApi to handle optional fields in metadata args, and enhance JSON Schema conversion

This commit is contained in:
2026-02-18 12:58:44 +08:00
parent 73a9868c19
commit 05dace0c79
10 changed files with 183 additions and 37 deletions

View File

@@ -1,3 +1,4 @@
import { optional } from 'zod';
import { createQueryApi } from '../src/query-api.ts';
// ============ 示例 1: 基础 JSON Schema 推断 ============
@@ -9,7 +10,8 @@ const api1 = {
"metadata": {
"args": {
"userId": {
"type": "string"
"type": "string",
"optional": true
},
"includeProfile": {
"type": "boolean"
@@ -53,7 +55,8 @@ const api2 = {
"domain": {
"type": "string"
}
}
},
"optional": true,
}
}
}
@@ -63,7 +66,7 @@ const api2 = {
const queryApi2 = createQueryApi({ api: api2 });
// ✅ 类型推断正常工作 - data 参数被推断为 { id: string, domain: string }
// ✅ 类型推断正常工作 - data 参数被推断为 { id?: string, domain?: string }没有required字段所有字段可选
queryApi2.app_domain_manager.get({
data: {
id: '123',
@@ -208,7 +211,8 @@ const api5 = {
"type": "string",
"enum": ["active", "inactive"] as const
}
}
},
// optional: true, // 单个 data 参数是可选的
// 没有 required 字段,所以所有字段都是可选的
}
}