用户拍板 (2026-06-25): 架构已改, 移除 'v0.10 LEGACY FILE' 误标头. 清理 6 个被误标 LEGACY 但实际仍在用的文件: - src/commands/_precheck.ts (form/dm/menu create 依赖检查) - src/commands/_blindspot_guards.ts (22 条高频盲点 guard) - src/commands/form/_blindspots.ts (6 类盲点规则, form lint + validate 共享) - src/commands/form/_simplify.ts (--fields 路径核心) - src/commands/form/validate.ts (dacli form validate 命令) - src/commands/form/fixcolumndata.ts (dacli form fixcolumndata 命令) 替换为正常 header, 注明 'v0.11+: 仍为单一事实源' / '调用方' 等实际状态. 删除 src/commands/form/_browser_construct.ts (384 行): - grep 全 src/ 无引用 (除自引用) - 与 _browser_verify.ts 功能重叠 (后者被 clone/fixcolumndata/create/import 调用) 验证: npx tsc --noEmit 报预存 TS 错误 (dm/create.ts data 属性, form/selector.ts note/notes 等), 与本次清理无关. 运行时验证: dacli form --help + dacli user list --keyword=admin 正常.
76 lines
3.4 KiB
TypeScript
76 lines
3.4 KiB
TypeScript
/**
|
|
* commands/form/validate.ts — 校验表单结构 (columnData __config__ 完整性)
|
|
*
|
|
* v0.11+: webapi 镜像化 (loadVisualDev), 调用 form/_blindspots.ts 6 类检查.
|
|
* 仍为 dacli 命令, 用于发布前快速排查.
|
|
* 共享 _blindspots.ts 的 6 类检查 (BS-23/31/32/15/V2/52)
|
|
* - formData.fields 每项有 __config__ (新 form: {fields:[]}; 老 form 流程表单: 直接是 array)
|
|
* - columnData.fields 每项有 __config__ (新版 JNPF 缺会白屏)
|
|
* - tables 有 dbLinkId
|
|
* - columnData.btnsList 含"新增"按钮 + columnBtnsList 含"编辑"按钮 (BS-52, v0.11+)
|
|
*
|
|
* 修复 (v0.8.1): formData=null / formData="[]" / 老 formData 直接是 array 不再误报 WARN.
|
|
* - 已知盲点 (v0.7.1): 老流程表单 formData 是 flat array, validate 报 "fields 不是数组"
|
|
* - 修复: 兼容 {fields:[...]} 和 直接 array 两种形态, 都视为合法
|
|
*
|
|
* v0.9 重构: 5 类检查抽到 _blindspots.ts, validate 与 lint 共享 (零 drift).
|
|
* v0.11 (2026-06-22): 新增 BS-52 (按钮存在性) 运行时校验, 修复 tds2 复盘 28/28 TC 假 PASS.
|
|
*/
|
|
import { Command } from 'commander'
|
|
import { JnpfClient } from '../../core/client.ts'
|
|
import { installAiHelpHook } from '../../core/help.ts'
|
|
import { log, printJson } from '../../core/log.ts'
|
|
import type { FormDetail } from '../../core/types.ts'
|
|
import { initWebapi, loadVisualDev } from '../../webapi/visualDev.ts'
|
|
import { checkBsV2, checkBs23, checkBs31, checkBs32, checkBs15, checkBs52, type BlindspotIssue } from './_blindspots.ts'
|
|
|
|
export type ValidationIssue = BlindspotIssue
|
|
|
|
function validate(form: FormDetail): ValidationIssue[] {
|
|
return [
|
|
...checkBsV2(form),
|
|
...checkBs23(form.columnData),
|
|
...checkBs31(form.formData),
|
|
...checkBs32(form.formData),
|
|
...checkBs15(form.tables, form.enableFlow as number | undefined),
|
|
...checkBs52(form.columnData, form.webType as number | undefined),
|
|
]
|
|
}
|
|
|
|
export function buildFormValidateCommand(): Command {
|
|
const cmd = new Command('validate')
|
|
.description('校验表单结构 (columnData __config__ 完整性等)')
|
|
.argument('<id>', '表单 id')
|
|
.option('--json', '原始 JSON', false)
|
|
.action(async (id: string, opts: { json?: boolean }) => {
|
|
const c = await JnpfClient.fromToken()
|
|
// v0.11+ Phase 2: 用 webapi 调 web 端 getInfo (替代 c.get('/visualdev/Base/{id}'))
|
|
await initWebapi(c)
|
|
const form = (await loadVisualDev.getInfo(id)) as FormDetail
|
|
const issues = validate(form)
|
|
if (opts.json) {
|
|
printJson({ id, enCode: form.enCode, issues, pass: issues.filter((i) => i.level === 'ERROR').length === 0 })
|
|
return
|
|
}
|
|
if (issues.length === 0) {
|
|
log.ok(`PASS ${form.enCode} (${id})`)
|
|
return
|
|
}
|
|
log.warn(`${form.enCode} 发现 ${issues.length} 个问题`)
|
|
for (const i of issues) {
|
|
const fn = i.level === 'ERROR' ? log.error : log.warn
|
|
fn(`[${i.level}] ${i.path}: ${i.message}`)
|
|
}
|
|
const failed = issues.filter((i) => i.level === 'ERROR').length > 0
|
|
if (failed) process.exit(2)
|
|
})
|
|
|
|
installAiHelpHook(cmd, {
|
|
purpose: '校验表单结构. columnData 缺 __config__ 会浏览器白屏',
|
|
required: { '<id>': '表单 id' },
|
|
example: 'dacli form validate 12345',
|
|
notes: ['ERROR → 退出码 2', 'Java 版有 --fix 自动修复, TS 版 W2+ 实现', 'v0.9 起 5 类盲点 (BS-23/31/32/15/V2) 抽到 _blindspots.ts 与 form lint 共享'],
|
|
})
|
|
|
|
return cmd
|
|
} |