Phase 1 审计 (cmd-review/datasource.md) 标记 P0 必做: - webapi/dataSource.ts 已镜像 11 函数, 使用率 0% - 4 子命令 (list/create/test/delete) 100% 绕 webapi 修复: - list → loadDataSource.getDataSourceList - create → loadDataSource.createDataSource - delete → loadDataSource.delDataSource - test → loadDataSource.testDbConnection + getDataSourceInfo 收益: - 消除 ~150 行 c.get/postJson/del 硬编码 - 自动同步 web 端 schema 变更 - 与 v0.11+ 镜像架构对齐 (6 个 webapi 模块之一) Co-Authored-By: Claude <[email protected]>
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
/**
|
|
* commands/datasource/delete.ts — 删除数据源
|
|
*
|
|
* v0.11+ Phase 2 (2026-06-25): 改用 webapi 镜像 (loadDataSource.delDataSource)
|
|
* 替代 v0.10 直接 c.del('/system/DataSource/{id}')
|
|
*/
|
|
import { Command } from 'commander'
|
|
import { JnpfClient } from '../../core/client.ts'
|
|
import { installAiHelpHook } from '../../core/help.ts'
|
|
import { log } from '../../core/log.ts'
|
|
import { initWebapi, loadDataSource } from '../../webapi/dataSource.ts'
|
|
|
|
interface DeleteOpts {
|
|
id: string
|
|
yes?: boolean
|
|
}
|
|
|
|
export function buildDatasourceDeleteCommand(): Command {
|
|
const cmd = new Command('delete')
|
|
.description('删除数据源')
|
|
.requiredOption('--id <id>', '数据源 id')
|
|
.option('--yes', '跳过确认', false)
|
|
.action(async (opts: DeleteOpts) => {
|
|
if (!opts.yes) {
|
|
log.warn(`即将删除数据源 id=${opts.id}, 加 --yes 跳过确认`)
|
|
process.exit(2)
|
|
}
|
|
const c = await JnpfClient.fromToken()
|
|
await initWebapi(c)
|
|
const r = (await loadDataSource.delDataSource(opts.id)) as { code?: number; msg?: string }
|
|
if (r.code !== undefined && r.code !== 200) {
|
|
log.error(`datasource delete 失败: ${r.msg}`)
|
|
process.exit(1)
|
|
}
|
|
log.info(`✓ 数据源 id=${opts.id} 已删除`)
|
|
})
|
|
installAiHelpHook(cmd, {
|
|
purpose: '删除数据源 (硬删, 无回收)',
|
|
required: { '--id': '数据源 id', '--yes': '跳过确认' },
|
|
example: 'dacli datasource delete --id=1234567890 --yes',
|
|
source: {
|
|
web: 'web/apps/jnpf-web-apps-main/src/views/dataCenter/dataSource/index.vue',
|
|
api: 'DELETE /api/system/DataSource/{id}',
|
|
ref: 'web/.../api/systemData/dataSource.ts:24 delDataSource()',
|
|
},
|
|
notes: ['v0.11+ 改用 webapi 镜像', '删除后该数据源上的所有业务库表无法访问', '谨慎操作'],
|
|
})
|
|
return cmd
|
|
}
|