refactor(v0.11+): di 4 个 NEW-CMD 改走 webapi 镜像 (loadDataInterface)

- 新建 webapi/di.ts (镜像 web/api/systemData/dataInterface.ts 11 函数)
- di/info: c.get → loadDataInterface.getDataInterfaceInfo
- di/test: c.postJson → loadDataInterface.getDataInterfaceRes
- di/update: c.get+c.putJson → loadDataInterface.getDataInterfaceInfo+updateDataInterface
- di/delete: c.del → loadDataInterface.delDataInterface

webapi 镜像累计 14 个模块 (visualDev, dataModel, dataSource, dict, menu, workflow, role, log, monitor, message, schedule, visualdata, report, di)

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
sswandClaude committed 2026-06-25 15:31:34 +08:00
1 parent 4669e35480
commit d1284c45cb
5 files changed
+81 -54

No files matched your search

+10 -8
View File
@@ -1,20 +1,20 @@
/** /**
* commands/di/delete.ts — 数据接口删除 * commands/di/delete.ts — 数据接口删除
* *
* v0.11+ Phase 2 新增: 闭环 DI CRUD * v0.11+ Phase 2: webapi 化 (loadDataInterface.delDataInterface)
* * 替代 v0.10 直接 c.del
* API: DELETE /api/system/DataInterface/{id}
*/ */
import { Command } from 'commander' import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts' import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts' import { installAiHelpHook } from '../../core/help.ts'
import { log } from '../../core/log.ts' import { log } from '../../core/log.ts'
import { initWebapi, loadDataInterface } from '../../webapi/di.ts'
interface Opts { id: string; yes?: boolean } interface Opts { id: string; yes?: boolean }
export function buildDiDeleteCommand(): Command { export function buildDiDeleteCommand(): Command {
const cmd = new Command('delete') const cmd = new Command('delete')
.description('数据接口删除 (硬删, 无回收)') .description('数据接口删除 (硬删, 无回收, v0.11+ webapi)')
.requiredOption('--id <id>', '数据接口 id') .requiredOption('--id <id>', '数据接口 id')
.option('--yes', '跳过确认', false) .option('--yes', '跳过确认', false)
.action(async (opts: Opts) => { .action(async (opts: Opts) => {
@@ -23,8 +23,10 @@ export function buildDiDeleteCommand(): Command {
process.exit(2) process.exit(2)
} }
const c = await JnpfClient.fromToken() const c = await JnpfClient.fromToken()
const r = await c.del(`/system/DataInterface/${opts.id}`) await initWebapi(c)
if (r.code !== 200) { log.info(`loadDataInterface.delDataInterface (id=${opts.id})`)
const r = (await loadDataInterface.delDataInterface(opts.id)) as { code?: number; msg?: string }
if (r.code !== 200 && r.code !== undefined) {
log.error(`di delete 失败: ${r.msg}`) log.error(`di delete 失败: ${r.msg}`)
process.exit(1) process.exit(1)
} }
@@ -34,8 +36,8 @@ export function buildDiDeleteCommand(): Command {
purpose: '数据接口删除. 引用该 DI 的 form 会失效.', purpose: '数据接口删除. 引用该 DI 的 form 会失效.',
required: { '--id': 'DI id', '--yes': '跳过确认' }, required: { '--id': 'DI id', '--yes': '跳过确认' },
example: 'dacli di delete --id=1234567890 --yes', example: 'dacli di delete --id=1234567890 --yes',
source: { api: 'DELETE /api/system/DataInterface/{id}' }, source: { api: 'DELETE /api/system/DataInterface/{id}', ref: 'web/.../api/systemData/dataInterface.ts delDataInterface()' },
notes: ['v0.11+ P0 新增, 引用 DI 的 form 会失效', '谨慎操作'], notes: ['v0.11+ 改用 webapi 镜像 (loadDataInterface.delDataInterface)', '引用 DI 的 form 会失效', '谨慎操作'],
}) })
return cmd return cmd
} }
+12 -12
View File
@@ -1,34 +1,34 @@
/** /**
* commands/di/info.ts — 数据接口详情 * commands/di/info.ts — 数据接口详情
* *
* v0.11+ Phase 2 新增: AI 拿到 di id 后查 schema + 参数 (form 引用 DI 闭环必需) * v0.11+ Phase 2: webapi 化 (loadDataInterface.getDataInterfaceInfo)
* * 替代 v0.10 直接 c.get
* API: GET /api/system/DataInterface/{id}
*/ */
import { Command } from 'commander' import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts' import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts' import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts' import { log, printJson } from '../../core/log.ts'
import { initWebapi, loadDataInterface } from '../../webapi/di.ts'
interface Opts { id: string; json?: boolean } interface Opts { id: string; json?: boolean }
export function buildDiInfoCommand(): Command { export function buildDiInfoCommand(): Command {
const cmd = new Command('info') const cmd = new Command('info')
.description('数据接口详情 (含 request/response schema + 参数)') .description('数据接口详情 (含 request/response schema + 参数, v0.11+ webapi)')
.requiredOption('--id <id>', '数据接口 id') .requiredOption('--id <id>', '数据接口 id')
.option('--json', '原始 JSON 输出', false) .option('--json', '原始 JSON 输出', false)
.action(async (opts: Opts) => { .action(async (opts: Opts) => {
const c = await JnpfClient.fromToken() const c = await JnpfClient.fromToken()
const r = await c.get<Record<string, unknown>>(`/system/DataInterface/${opts.id}`) await initWebapi(c)
if (r.code !== 200 || !r.data) { const d = (await loadDataInterface.getDataInterfaceInfo(opts.id)) as Record<string, unknown>
log.error(`di info 失败: ${r.msg || 'id 不存在'}`) if (!d) {
log.error(`di info 失败: id=${opts.id} 不存在`)
process.exit(1) process.exit(1)
} }
if (opts.json) { if (opts.json) {
printJson(r.data) printJson(d)
return return
} }
const d = r.data
log.info(`数据接口详情 (id=${opts.id})`) log.info(`数据接口详情 (id=${opts.id})`)
console.log(` fullName : ${d.fullName}`) console.log(` fullName : ${d.fullName}`)
console.log(` enCode : ${d.enCode}`) console.log(` enCode : ${d.enCode}`)
@@ -41,12 +41,12 @@ export function buildDiInfoCommand(): Command {
if (d.responseParams) console.log(` responseParams : ${JSON.stringify(d.responseParams).slice(0, 200)}`) if (d.responseParams) console.log(` responseParams : ${JSON.stringify(d.responseParams).slice(0, 200)}`)
}) })
installAiHelpHook(cmd, { installAiHelpHook(cmd, {
purpose: '数据接口详情 (含 request/response schema + 参数). AI 引用 DI 时查 schema 必需.', purpose: '数据接口详情 (含 request/response schema + 参数).',
required: { '--id': '数据接口 id' }, required: { '--id': '数据接口 id' },
optional: { '--json': '原始 JSON 输出' }, optional: { '--json': '原始 JSON 输出' },
example: 'dacli di info --id=1234567890', example: 'dacli di info --id=1234567890',
source: { api: 'GET /api/system/DataInterface/{id}' }, source: { api: 'GET /api/system/DataInterface/{id}', ref: 'web/.../api/systemData/dataInterface.ts getDataInterfaceInfo()' },
notes: ['v0.11+ P0 新增, 之前 di 只有 list, AI 完全无法闭环'], notes: ['v0.11+ 改用 webapi 镜像 (loadDataInterface.getDataInterfaceInfo)'],
}) })
return cmd return cmd
} }
+11 -13
View File
@@ -1,14 +1,14 @@
/** /**
* commands/di/test.ts — 数据接口测试调用 * commands/di/test.ts — 数据接口测试调用
* *
* v0.11+ Phase 2 新增: AI 测试 DI 是否能正常调用 (校验链路) * v0.11+ Phase 2: webapi 化 (loadDataInterface.getDataInterfaceRes)
* * 替代 v0.10 直接 c.postJson
* API: POST /api/system/DataInterface/{id}/Actions/Preview
*/ */
import { Command } from 'commander' import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts' import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts' import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts' import { log, printJson } from '../../core/log.ts'
import { initWebapi, loadDataInterface } from '../../webapi/di.ts'
interface Opts { interface Opts {
id: string id: string
@@ -18,12 +18,13 @@ interface Opts {
export function buildDiTestCommand(): Command { export function buildDiTestCommand(): Command {
const cmd = new Command('test') const cmd = new Command('test')
.description('数据接口测试调用 (Preview)') .description('数据接口测试调用 (Preview, v0.11+ webapi)')
.requiredOption('--id <id>', '数据接口 id') .requiredOption('--id <id>', '数据接口 id')
.option('--data <json>', '请求参数 JSON (默认空 {})', '{}') .option('--data <json>', '请求参数 JSON (默认空 {})', '{}')
.option('--json', '原始 JSON 输出', false) .option('--json', '原始 JSON 输出', false)
.action(async (opts: Opts) => { .action(async (opts: Opts) => {
const c = await JnpfClient.fromToken() const c = await JnpfClient.fromToken()
await initWebapi(c)
let body: Record<string, unknown> = {} let body: Record<string, unknown> = {}
try { try {
body = JSON.parse(opts.data || '{}') body = JSON.parse(opts.data || '{}')
@@ -31,9 +32,9 @@ export function buildDiTestCommand(): Command {
log.error(`--data JSON 解析失败: ${(e as Error).message}`) log.error(`--data JSON 解析失败: ${(e as Error).message}`)
process.exit(2) process.exit(2)
} }
log.info(`POST /system/DataInterface/${opts.id}/Actions/Preview`) log.info(`loadDataInterface.getDataInterfaceRes (id=${opts.id})`)
const r = await c.postJson<unknown>(`/system/DataInterface/${opts.id}/Actions/Preview`, body) const r = (await loadDataInterface.getDataInterfaceRes(opts.id, body)) as { code?: number; msg?: string; data?: unknown }
if (r.code !== 200) { if (r.code !== 200 && r.code !== undefined) {
log.error(`di test 失败 (code=${r.code}): ${r.msg}`) log.error(`di test 失败 (code=${r.code}): ${r.msg}`)
if (opts.json) printJson(r) if (opts.json) printJson(r)
process.exit(1) process.exit(1)
@@ -46,12 +47,9 @@ export function buildDiTestCommand(): Command {
purpose: '数据接口测试调用. AI 验证 DI 配置正确性 (链路, 鉴权, 返回值).', purpose: '数据接口测试调用. AI 验证 DI 配置正确性 (链路, 鉴权, 返回值).',
required: { '--id': '数据接口 id' }, required: { '--id': '数据接口 id' },
optional: { '--data': '请求参数 JSON (默认 {})', '--json': '原始 JSON 输出' }, optional: { '--data': '请求参数 JSON (默认 {})', '--json': '原始 JSON 输出' },
example: [ example: ['dacli di test --id=1234567890', 'dacli di test --id=1234567890 --data=\'{"userId":"u1"}\''],
'dacli di test --id=1234567890', source: { api: 'POST /api/system/DataInterface/{id}/Actions/Preview', ref: 'web/.../api/systemData/dataInterface.ts getDataInterfaceRes()' },
'dacli di test --id=1234567890 --data=\'{"userId":"u1"}\'', notes: ['v0.11+ 改用 webapi 镜像 (loadDataInterface.getDataInterfaceRes)'],
],
source: { api: 'POST /api/system/DataInterface/{id}/Actions/Preview' },
notes: ['v0.11+ P0 新增, 之前 DI 测试需走 web 端, AI 无法独立验证'],
}) })
return cmd return cmd
} }
+15 -21
View File
@@ -1,14 +1,14 @@
/** /**
* commands/di/update.ts — 数据接口修改 * commands/di/update.ts — 数据接口修改
* *
* v0.11+ Phase 2 新增: AI 改 DI 配置 (webType/path 等) * v0.11+ Phase 2: webapi 化 (loadDataInterface.getDataInterfaceInfo + updateDataInterface)
* * 替代 v0.10 直接 c.get/c.putJson
* API: PUT /api/system/DataInterface/{id}
*/ */
import { Command } from 'commander' import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts' import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts' import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts' import { log, printJson } from '../../core/log.ts'
import { initWebapi, loadDataInterface } from '../../webapi/di.ts'
interface Opts { interface Opts {
id: string id: string
@@ -22,7 +22,7 @@ interface Opts {
export function buildDiUpdateCommand(): Command { export function buildDiUpdateCommand(): Command {
const cmd = new Command('update') const cmd = new Command('update')
.description('数据接口修改 (改 schema/path/参数)') .description('数据接口修改 (PUT 语义, v0.11+ webapi)')
.requiredOption('--id <id>', '数据接口 id') .requiredOption('--id <id>', '数据接口 id')
.option('--fullName <n>', '中文名') .option('--fullName <n>', '中文名')
.option('--enCode <e>', '英文编码') .option('--enCode <e>', '英文编码')
@@ -32,21 +32,21 @@ export function buildDiUpdateCommand(): Command {
.option('--json', '原始 JSON 输出', false) .option('--json', '原始 JSON 输出', false)
.action(async (opts: Opts) => { .action(async (opts: Opts) => {
const c = await JnpfClient.fromToken() const c = await JnpfClient.fromToken()
// 先 GET 拉原 form, 然后合并更新 await initWebapi(c)
const origR = await c.get<Record<string, unknown>>(`/system/DataInterface/${opts.id}`) const orig = (await loadDataInterface.getDataInterfaceInfo(opts.id)) as Record<string, unknown>
if (origR.code !== 200 || !origR.data) { if (!orig) {
log.error(`di update 失败 (拉原 DI): ${origR.msg || 'id 不存在'}`) log.error(`di update 失败: 拉原 DI id=${opts.id} 失败`)
process.exit(1) process.exit(1)
} }
const body: Record<string, unknown> = { ...origR.data, id: opts.id } const body: Record<string, unknown> = { ...orig, id: opts.id }
if (opts.fullName) body.fullName = opts.fullName if (opts.fullName) body.fullName = opts.fullName
if (opts.enCode) body.enCode = opts.enCode if (opts.enCode) body.enCode = opts.enCode
if (opts.categoryId) body.categoryId = opts.categoryId if (opts.categoryId) body.categoryId = opts.categoryId
if (opts.requestMethod) body.requestMethod = opts.requestMethod if (opts.requestMethod) body.requestMethod = opts.requestMethod
if (opts.url) body.url = opts.url if (opts.url) body.url = opts.url
log.info(`PUT /system/DataInterface/${opts.id}`) log.info(`loadDataInterface.updateDataInterface (id=${opts.id})`)
const r = await c.putJson<unknown>(`/system/DataInterface/${opts.id}`, body) const r = (await loadDataInterface.updateDataInterface(body)) as { code?: number; msg?: string; data?: unknown }
if (r.code !== 200) { if (r.code !== 200 && r.code !== undefined) {
log.error(`di update 失败 (code=${r.code}): ${r.msg}`) log.error(`di update 失败 (code=${r.code}): ${r.msg}`)
if (opts.json) printJson(r) if (opts.json) printJson(r)
process.exit(1) process.exit(1)
@@ -57,16 +57,10 @@ export function buildDiUpdateCommand(): Command {
installAiHelpHook(cmd, { installAiHelpHook(cmd, {
purpose: '数据接口修改 (改 schema/path/参数). PUT 语义, 未传字段保留原值.', purpose: '数据接口修改 (改 schema/path/参数). PUT 语义, 未传字段保留原值.',
required: { '--id': '数据接口 id' }, required: { '--id': '数据接口 id' },
optional: { optional: { '--fullName': '中文名', '--enCode': '英文编码', '--categoryId': '分类 id', '--requestMethod': '请求方法', '--url': '接口路径/URL' },
'--fullName': '中文名',
'--enCode': '英文编码',
'--categoryId': '分类 id',
'--requestMethod': '请求方法',
'--url': '接口路径/URL',
},
example: 'dacli di update --id=123 --url=/api/new/path', example: 'dacli di update --id=123 --url=/api/new/path',
source: { api: 'PUT /api/system/DataInterface/{id}' }, source: { api: 'PUT /api/system/DataInterface/{id}', ref: 'web/.../api/systemData/dataInterface.ts updateDataInterface()' },
notes: ['v0.11+ P0 新增, 未传字段保留原值 (PUT 语义)'], notes: ['v0.11+ 改用 webapi 镜像 (loadDataInterface.updateDataInterface)'],
}) })
return cmd return cmd
} }
+33
View File
@@ -0,0 +1,33 @@
/**
* webapi/di.ts — 直接 import web 端 dataInterface.ts (v0.11+ Phase 2)
*
* 镜像 web/apps/jnpf-web-apps-main/src/api/systemData/dataInterface.ts 11 函数:
* getDataInterfaceList / getDataInterfaceSelector / createDataInterface /
* updateDataInterface / getDataInterfaceInfo / delDataInterface /
* getDataInterfaceRes (Preview) / getDataInterfaceParam / exportData /
* getDataInterfaceLog / getDataInterfaceDataSelect
*/
import { JnpfClient } from '../core/client.ts'
import { loadWebModule } from './_loader.ts'
const DI_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/systemData/dataInterface.ts'
let cached: any = null
export async function initWebapi(client: JnpfClient): Promise<void> {
if (cached) return
const { initDefHttpShim } = await import('./_defhttp_shim.ts')
initDefHttpShim(client)
cached = await loadWebModule(DI_SRC)
}
export function isWebapiLoaded(): boolean {
return cached !== null
}
export const loadDataInterface: any = new Proxy({} as any, {
get(_target, prop) {
if (!cached) throw new Error('di 模块未初始化, 请先 await initWebapi(client)')
return cached[prop]
},
})