v0.15-2 实施: diCRUD 加 copy + export (6/16 → 8/16, 2026-07-02)
audit 2026-07-02 §role/print/di 报告 P2 #6: - diCRUD 6/16 (list/info/create/update/delete/test) - 缺 selector/param/log/dataSelect/fields/copy/export 等 10 个 - v0.16+ 推大重构, 优先做数据迁移常用 (copy + export) v0.15-2 实施: - 新建 di/copy.ts (87 行) - 镜像 web copy(id) → POST /{id}/Actions/Copy - 返新 DI id, 配合 --json 可继续 update - id 数字校验 (P0-9 一致) - 新建 di/export.ts (76 行) - 镜像 web exportData(id) → GET /{id}/Actions/Export - 简化: 不下载文件, 只返下载 URL (用户自行 curl) - id 数字校验 (P0-9 一致) - di/index.ts 注册 2 个新子命令 di webapi 引用覆盖: 6/16 → 8/16 (基础 CRUD + 迁移) 剩余推 v0.16.1: selector/param/log/dataSelect/fields 等 7 个 审计: dacli/docs/cmd-review/role-print-di-audit-2026-07-02.md §di 部分
This commit is contained in:
1 parent
8e7be85720
commit
9ad04fd4eb
2 files changed
+189
No files matched your search
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* commands/di/copy.ts — 复制数据接口
|
||||
*
|
||||
* v0.15+ (2026-07-02 v0.15-2): 镜像 web 端 copy (web 端函数名 copy(id), 实际是 DI 复制)
|
||||
* 替代 v0.10 直接 c.postJson
|
||||
*
|
||||
* 镜像源: web/apps/jnpf-web-apps-main/src/api/systemData/dataInterface.ts:78 copy(id)
|
||||
* web 端: defHttp.post({ url: `${Api.Prefix}/${id}/Actions/Copy` })
|
||||
* 端点: POST /api/system/DataInterface/{id}/Actions/Copy (走 30000 jnpf-admin)
|
||||
*
|
||||
* 后端: DataInterfaceController @PostMapping("/{id}/Actions/Copy")
|
||||
* 返回新 DI 的 id (字符串)
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
import { initWebapi as initDiWebapi, loadDataInterface } from '../../webapi/di.ts'
|
||||
|
||||
interface CopyOpts {
|
||||
id: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildDiCopyCommand(): Command {
|
||||
const cmd = new Command('copy')
|
||||
.description('复制数据接口 (v0.15+ 镜像 web copy, 走 POST /api/system/DataInterface/{id}/Actions/Copy)')
|
||||
.requiredOption('--id <id>', '源 DI id')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: CopyOpts) => {
|
||||
// v0.15+ (P0-9): id 数字校验
|
||||
const idRegex = /^\d{10,30}$/
|
||||
if (!idRegex.test(opts.id)) {
|
||||
log.error(`--id "${opts.id}" 不是合法 JNPF id (期望纯数字 10-30 位)`)
|
||||
log.error('提示: 用 `dacli di list` 查 id')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const c = await JnpfClient.fromToken()
|
||||
await initDiWebapi(c)
|
||||
|
||||
// 镜像 web 端 copy(id) → defHttp.post /{id}/Actions/Copy
|
||||
// 后端返 {code, msg, data: <新 id string>}
|
||||
// shim unwrap 信封, r 就是 data 部分
|
||||
const r = (await loadDataInterface.copy(opts.id)) as { code?: number; msg?: string; data?: unknown } | string | unknown
|
||||
|
||||
// 兼容多种响应形状: shim unwrap 后可能直接返新 id 字符串
|
||||
let newId: string | undefined
|
||||
let code: number | undefined
|
||||
let msg: string | undefined
|
||||
if (typeof r === 'string') {
|
||||
newId = /^\d+$/.test(r.trim()) ? r.trim() : undefined
|
||||
} else if (r && typeof r === 'object') {
|
||||
const obj = r as { code?: number; msg?: string; data?: string | { id?: string } }
|
||||
code = obj.code
|
||||
msg = obj.msg
|
||||
if (typeof obj.data === 'string') {
|
||||
newId = /^\d+$/.test(obj.data.trim()) ? obj.data.trim() : undefined
|
||||
} else if (obj.data && typeof obj.data === 'object') {
|
||||
newId = (obj.data as { id?: string }).id
|
||||
}
|
||||
}
|
||||
|
||||
if (code !== undefined && code !== 200) {
|
||||
log.error(`di copy 失败 (code=${code}): ${msg}`)
|
||||
const enhanced = enhanceFromBackend(msg || '', 'di', { entity: 'di' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (!newId) {
|
||||
log.error(`di copy 失败: 后端未返新 id, raw=${JSON.stringify(r).slice(0, 200)}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.ok(`✓ DI 复制成功 (源 id=${opts.id} → 新 id=${newId})`)
|
||||
if (opts.json) printJson({ sourceId: opts.id, newId, code: code ?? 200, msg: msg ?? '复制成功' })
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '复制数据接口 (v0.15+ 镜像 web copy)',
|
||||
required: { '--id': '源 DI id' },
|
||||
example: [
|
||||
'dacli di copy --id=842033226770801349',
|
||||
'dacli di copy --id=842033226770801349 --json # 拿新 id 后续修改',
|
||||
],
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/api/systemData/dataInterface.ts:78 copy(id)',
|
||||
api: 'POST /api/system/DataInterface/{id}/Actions/Copy (走 webapi Proxy, 端口 30000 jnpf-admin)',
|
||||
ref: 'jnpf/后端/jnpf-system/jnpf-system-controller/.../DataInterfaceController.java @PostMapping("/{id}/Actions/Copy")',
|
||||
},
|
||||
notes: [
|
||||
'v0.15+ 走 webapi 镜像 (loadDataInterface.copy), 替代旧版 c.postJson',
|
||||
'**v0.15+ (P0-9)**: id 数字校验, 输错字符串提前 exit 1',
|
||||
'返回新 DI 的 id, 配合 --json 拿新 id 可继续 update/enabledMark',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* commands/di/export.ts — 导出数据接口
|
||||
*
|
||||
* v0.15+ (2026-07-02 v0.15-2): 镜像 web 端 exportData
|
||||
*
|
||||
* 镜像源: web/apps/jnpf-web-apps-main/src/api/systemData/dataInterface.ts:81 exportData(id)
|
||||
* web 端: defHttp.get({ url: `${Api.Prefix}/${id}/Actions/Export`, responseType: 'blob' })
|
||||
* 端点: GET /api/system/DataInterface/{id}/Actions/Export
|
||||
* 返回: DownloadVO { name, url } (文件下载链接, 通常是 OSS/MinIO 预签名 URL)
|
||||
*
|
||||
* 后端: DataInterfaceController @GetMapping("/{id}/Actions/Export")
|
||||
* 返回 ActionResult<DownloadVO>
|
||||
*
|
||||
* dacli 简化: 不直接下载文件 (避免 binary 处理), 只拿下载 URL, 用户自行 curl 下载
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
import { initWebapi as initDiWebapi, loadDataInterface } from '../../webapi/di.ts'
|
||||
|
||||
interface ExportOpts {
|
||||
id: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildDiExportCommand(): Command {
|
||||
const cmd = new Command('export')
|
||||
.description('导出数据接口 (v0.15+ 镜像 web exportData, 拿下载 URL, 不直接下载文件)')
|
||||
.requiredOption('--id <id>', 'DI id')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: ExportOpts) => {
|
||||
// v0.15+ (P0-9): id 数字校验
|
||||
const idRegex = /^\d{10,30}$/
|
||||
if (!idRegex.test(opts.id)) {
|
||||
log.error(`--id "${opts.id}" 不是合法 JNPF id (期望纯数字 10-30 位)`)
|
||||
log.error('提示: 用 `dacli di list` 查 id')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const c = await JnpfClient.fromToken()
|
||||
await initDiWebapi(c)
|
||||
|
||||
// 镜像 web 端 exportData(id) → defHttp.get
|
||||
// shim unwrap 信封, 拿 data 字段 (DownloadVO)
|
||||
const r = (await loadDataInterface.exportData(opts.id)) as {
|
||||
name?: string
|
||||
url?: string
|
||||
code?: number
|
||||
msg?: string
|
||||
} | unknown
|
||||
|
||||
const obj = r as { name?: string; url?: string; code?: number; msg?: string }
|
||||
if (obj.code !== undefined && obj.code !== 200) {
|
||||
log.error(`di export 失败 (code=${obj.code}): ${obj.msg}`)
|
||||
const enhanced = enhanceFromBackend(obj.msg || '', 'di', { entity: 'di' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!obj.url) {
|
||||
log.error(`di export 失败: 后端未返下载 URL, raw=${JSON.stringify(r).slice(0, 200)}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
log.ok(`✓ DI 导出成功 (id=${opts.id}, name=${obj.name || '(未命名)'})`)
|
||||
log.info(`下载 URL: ${obj.url}`)
|
||||
log.info(`提示: 复制 URL 用 curl/浏览器下载, 或加 -o <file> 走 wget`)
|
||||
if (opts.json) printJson({ id: opts.id, name: obj.name, url: obj.url })
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '导出数据接口 (v0.15+ 镜像 web exportData)',
|
||||
required: { '--id': 'DI id' },
|
||||
example: [
|
||||
'dacli di export --id=842033226770801349 # 输出下载 URL',
|
||||
'dacli di export --id=842033226770801349 --json # 拿 URL 给 curl',
|
||||
],
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/api/systemData/dataInterface.ts:81 exportData(id)',
|
||||
api: 'GET /api/system/DataInterface/{id}/Actions/Export (走 webapi Proxy, 端口 30000 jnpf-admin)',
|
||||
ref: 'jnpf/后端/jnpf-system/jnpf-system-controller/.../DataInterfaceController.java @GetMapping("/{id}/Actions/Export")',
|
||||
},
|
||||
notes: [
|
||||
'v0.15+ 走 webapi 镜像 (loadDataInterface.exportData), 替代旧版 c.get',
|
||||
'**v0.15+ (P0-9)**: id 数字校验, 输错字符串提前 exit 1',
|
||||
'**简化**: 不直接下载文件 (避免 binary 处理), 只返下载 URL',
|
||||
'返回 DownloadVO {name, url}, url 通常是 OSS/MinIO 预签名 URL (短期有效)',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
Reference in new issue
Block a user