refactor(v0.11+): form codegen 4 调用 webapi 化
Phase 1 审计 P0: - form/codegen.ts 4 调用 → loadVisualDev.* - saveAlias + getInfo + getAliasInfo + codePreview - 累计 form 11 调用 webapi 化 (22 中) 剩余 form 11 调用: - form/import.ts (8 调用) - 最大 - form/create.ts (4 调用) Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
7bf7762839
commit
938c31da4d
1 file changed
+18
-11
@@ -29,6 +29,7 @@ import { dirname, join } from 'node:path'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { initWebapi, loadVisualDev } from '../../webapi/visualDev.ts'
|
||||
|
||||
interface CodegenOpts {
|
||||
/** 企业代码 (aibridge company_code), 默认 ssw */
|
||||
@@ -472,9 +473,11 @@ async function ensureAlias(
|
||||
return false
|
||||
}
|
||||
|
||||
log.info(`POST /visualdev/Generater/${formId}/Alias/Save (${aliasTables.length} 个表别名)`)
|
||||
const r = await c.postJson<unknown>(`/visualdev/Generater/${formId}/Alias/Save`, { tableList: aliasTables })
|
||||
if (r.code !== 200) {
|
||||
log.info(`loadVisualDev.saveAlias (formId=${formId}, ${aliasTables.length} 个表别名)`)
|
||||
// v0.11+ Phase 2: 改用 webapi
|
||||
await initWebapi(c)
|
||||
const r = (await loadVisualDev.saveAlias(formId, { tableList: aliasTables })) as { code?: number; msg?: string }
|
||||
if (r.code !== 200 && r.code !== undefined) {
|
||||
log.error(`Alias/Save 失败 (code=${r.code}): ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
@@ -524,13 +527,15 @@ export function buildFormCodegenCommand(): Command {
|
||||
}
|
||||
|
||||
const c = await JnpfClient.fromToken()
|
||||
// v0.11+ Phase 2: 改用 webapi
|
||||
await initWebapi(c)
|
||||
// BS-48 fix: '--dbLinkId=default' 字面量 → token.dbLinkId
|
||||
const dbLinkId = c.resolveDbLinkId(opts.dbLinkId)
|
||||
|
||||
// 1. 拿 form 概要 (拿 enCode 当默认 mainClassName / module)
|
||||
const info = await c.get<{ enCode?: string; fullName?: string }>(`/visualdev/Base/${formId}`)
|
||||
const enCode = info.data?.enCode || formId
|
||||
const fullName = info.data?.fullName || enCode
|
||||
// 1. 拿 form 概要 (拿 enCode 当默认 mainClassName / module) - v0.11+ webapi
|
||||
const info = (await loadVisualDev.getInfo(formId)) as { enCode?: string; fullName?: string }
|
||||
const enCode = info.enCode || formId
|
||||
const fullName = info.fullName || enCode
|
||||
const module = opts.module || enCode
|
||||
const moduleErr = validateCode(module, '--module (或 form.enCode)')
|
||||
if (moduleErr) {
|
||||
@@ -547,8 +552,9 @@ export function buildFormCodegenCommand(): Command {
|
||||
const needsTables = opts.autoAlias && !opts.aliasFile && !opts.alias
|
||||
if (needsTables || !opts.description) {
|
||||
try {
|
||||
const aliasInfo = await c.get<any[]>(`/visualdev/Generater/${formId}/Alias/Info`)
|
||||
const tables = Array.isArray(aliasInfo.data) ? aliasInfo.data : []
|
||||
// v0.11+ Phase 2: 改用 webapi (loadVisualDev.getAliasInfo)
|
||||
const aliasInfo = (await loadVisualDev.getAliasInfo(formId)) as any[]
|
||||
const tables = Array.isArray(aliasInfo) ? aliasInfo : []
|
||||
if (tables.length > 0) {
|
||||
formTables = tables
|
||||
.filter((t: any) => t.table)
|
||||
@@ -610,9 +616,10 @@ export function buildFormCodegenCommand(): Command {
|
||||
|
||||
log.info(`POST /visualdev/Generater/${formId}/Actions/CodePreview`)
|
||||
// 走 callWithDiagnosis 让 client.diagnoseError() 触发, 输出 trigger='' 等修复指引
|
||||
let r: Awaited<ReturnType<typeof c.postJson<unknown>>>
|
||||
let r: { code?: number; msg?: string; data?: unknown }
|
||||
try {
|
||||
r = await c.postJson<unknown>(`/visualdev/Generater/${formId}/Actions/CodePreview`, body)
|
||||
// v0.11+ Phase 2: 改用 webapi (loadVisualDev.codePreview)
|
||||
r = (await loadVisualDev.codePreview(formId, body)) as { code?: number; msg?: string; data?: unknown }
|
||||
} catch (e) {
|
||||
const err = e as Error
|
||||
log.error(`CodePreview 请求失败: ${err.message}`)
|
||||
|
||||
Reference in new issue
Block a user