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