feat(v0.11+): workflow info/update/delete P0 NEW-CMD (闭环 CRUD)
Phase 1 审计 (cmd-review/workflow.md) 标记 P0:
- workflow 之前 5 子 (list/create/launch/approve/selector) 缺基础 CRUD 闭环
- info/update/delete 是 CRUD 必需
新增 3 子命令:
- workflow info (查 schema + 关联 form, 验证 create 结果)
- workflow update (改 fullName/enCode/category/enabledMark/description)
- workflow delete (硬删, --yes 确认)
- 累计 workflow 9 子命令 (从 6 → 9)
API: GET/PUT/DELETE /api/workflow/template/{id}
Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
801a2049e6
commit
5ec47e35f2
4 files changed
+168
-2
No files matched your search
@@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* commands/workflow/delete.ts — 流程模板删除
|
||||||
|
*
|
||||||
|
* v0.11+ Phase 2 新增: 流程模板 CRUD 闭环
|
||||||
|
*
|
||||||
|
* API: DELETE /api/workflow/template/{id}
|
||||||
|
*/
|
||||||
|
import { Command } from 'commander'
|
||||||
|
import { JnpfClient } from '../../core/client.ts'
|
||||||
|
import { installAiHelpHook } from '../../core/help.ts'
|
||||||
|
import { log } from '../../core/log.ts'
|
||||||
|
|
||||||
|
interface Opts { id: string; yes?: boolean }
|
||||||
|
|
||||||
|
export function buildWorkflowDeleteCommand(): Command {
|
||||||
|
const cmd = new Command('delete')
|
||||||
|
.description('流程模板删除 (硬删, 无回收)')
|
||||||
|
.requiredOption('--id <id>', '流程模板 id')
|
||||||
|
.option('--yes', '跳过确认', false)
|
||||||
|
.action(async (opts: Opts) => {
|
||||||
|
if (!opts.yes) {
|
||||||
|
log.warn(`即将删除流程模板 id=${opts.id}, 加 --yes 跳过确认`)
|
||||||
|
process.exit(2)
|
||||||
|
}
|
||||||
|
const c = await JnpfClient.fromToken()
|
||||||
|
const r = await c.del(`/workflow/template/${opts.id}`)
|
||||||
|
if (r.code !== 200) {
|
||||||
|
log.error(`workflow delete 失败: ${r.msg}`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
log.ok(`✓ 流程模板已删除 (id=${opts.id})`)
|
||||||
|
})
|
||||||
|
installAiHelpHook(cmd, {
|
||||||
|
purpose: '流程模板删除. 引用该流程的 form 会失效.',
|
||||||
|
required: { '--id': '流程模板 id', '--yes': '跳过确认' },
|
||||||
|
example: 'dacli workflow delete --id=1234567890 --yes',
|
||||||
|
source: { api: 'DELETE /api/workflow/template/{id}' },
|
||||||
|
notes: ['v0.11+ P0 新增', '引用该流程的 form 会失效', '谨慎操作'],
|
||||||
|
})
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
@@ -1,18 +1,27 @@
|
|||||||
/**
|
/**
|
||||||
* commands/workflow/index.ts — workflow 父命令
|
* commands/workflow/index.ts — workflow 父命令
|
||||||
|
*
|
||||||
|
* v0.11+ Phase 2: 9 子命令 (list/info/create/update/delete/launch/approve/decision/selector)
|
||||||
|
* 闭环 CRUD + 流程引擎
|
||||||
*/
|
*/
|
||||||
import { Command } from 'commander'
|
import { Command } from 'commander'
|
||||||
import { buildWorkflowListCommand } from './list.ts'
|
import { buildWorkflowListCommand } from './list.ts'
|
||||||
|
import { buildWorkflowInfoCommand } from './info.ts'
|
||||||
|
import { buildWorkflowCreateCommand } from './create.ts'
|
||||||
|
import { buildWorkflowUpdateCommand } from './update.ts'
|
||||||
|
import { buildWorkflowDeleteCommand } from './delete.ts'
|
||||||
import { buildWorkflowLaunchCommand } from './launch.ts'
|
import { buildWorkflowLaunchCommand } from './launch.ts'
|
||||||
import { buildWorkflowApproveCommand } from './approve.ts'
|
import { buildWorkflowApproveCommand } from './approve.ts'
|
||||||
import { buildWorkflowCreateCommand } from './create.ts'
|
|
||||||
import { buildWorkflowDecisionCommand } from './decision.ts'
|
import { buildWorkflowDecisionCommand } from './decision.ts'
|
||||||
import { buildWorkflowSelectorCommand } from './selector.ts'
|
import { buildWorkflowSelectorCommand } from './selector.ts'
|
||||||
|
|
||||||
export function buildWorkflowCommand(): Command {
|
export function buildWorkflowCommand(): Command {
|
||||||
const cmd = new Command('workflow').description('流程引擎 (模板/发起/审批 + 5.6.5 决策流参数)')
|
const cmd = new Command('workflow').description('流程引擎 (模板 CRUD + 发起/审批 + 决策流)')
|
||||||
cmd.addCommand(buildWorkflowListCommand())
|
cmd.addCommand(buildWorkflowListCommand())
|
||||||
|
cmd.addCommand(buildWorkflowInfoCommand())
|
||||||
cmd.addCommand(buildWorkflowCreateCommand())
|
cmd.addCommand(buildWorkflowCreateCommand())
|
||||||
|
cmd.addCommand(buildWorkflowUpdateCommand())
|
||||||
|
cmd.addCommand(buildWorkflowDeleteCommand())
|
||||||
cmd.addCommand(buildWorkflowLaunchCommand())
|
cmd.addCommand(buildWorkflowLaunchCommand())
|
||||||
cmd.addCommand(buildWorkflowApproveCommand())
|
cmd.addCommand(buildWorkflowApproveCommand())
|
||||||
cmd.addCommand(buildWorkflowDecisionCommand())
|
cmd.addCommand(buildWorkflowDecisionCommand())
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* commands/workflow/info.ts — 流程模板详情
|
||||||
|
*
|
||||||
|
* v0.11+ Phase 2 新增: 流程模板 CRUD 闭环 (P0)
|
||||||
|
*
|
||||||
|
* API: GET /api/workflow/template/{id}
|
||||||
|
*/
|
||||||
|
import { Command } from 'commander'
|
||||||
|
import { JnpfClient } from '../../core/client.ts'
|
||||||
|
import { installAiHelpHook } from '../../core/help.ts'
|
||||||
|
import { log, printJson } from '../../core/log.ts'
|
||||||
|
|
||||||
|
interface Opts { id: string; json?: boolean }
|
||||||
|
|
||||||
|
export function buildWorkflowInfoCommand(): Command {
|
||||||
|
const cmd = new Command('info')
|
||||||
|
.description('流程模板详情 (含 category/enabledMark/version/关联 form)')
|
||||||
|
.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>>(`/workflow/template/${opts.id}`)
|
||||||
|
if (r.code !== 200 || !r.data) {
|
||||||
|
log.error(`workflow info 失败: ${r.msg || 'id 不存在'}`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
if (opts.json) {
|
||||||
|
printJson(r.data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const d = r.data
|
||||||
|
log.info(`流程模板详情 (id=${opts.id})`)
|
||||||
|
console.log(` fullName : ${d.fullName}`)
|
||||||
|
console.log(` enCode : ${d.enCode}`)
|
||||||
|
console.log(` category : ${d.category}`)
|
||||||
|
console.log(` enabledMark : ${d.enabledMark === 1 ? '启用' : '禁用'}`)
|
||||||
|
console.log(` version : ${d.version || '1'}`)
|
||||||
|
console.log(` formId : ${d.formId || '-'}`)
|
||||||
|
console.log(` description : ${d.description || '-'}`)
|
||||||
|
})
|
||||||
|
installAiHelpHook(cmd, {
|
||||||
|
purpose: '流程模板详情. AI 引用 workflow id 验证 (P0 闭环, 之前只有 list/launch/approve/decision).',
|
||||||
|
required: { '--id': '流程模板 id' },
|
||||||
|
optional: { '--json': '原始 JSON 输出' },
|
||||||
|
example: 'dacli workflow info --id=1234567890',
|
||||||
|
source: { api: 'GET /api/workflow/template/{id}' },
|
||||||
|
notes: ['v0.11+ P0 新增, 闭环 CRUD 必需'],
|
||||||
|
})
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* commands/workflow/update.ts — 流程模板修改
|
||||||
|
*
|
||||||
|
* v0.11+ Phase 2 新增: 流程模板 CRUD 闭环
|
||||||
|
*
|
||||||
|
* API: PUT /api/workflow/template/{id}
|
||||||
|
*/
|
||||||
|
import { Command } from 'commander'
|
||||||
|
import { JnpfClient } from '../../core/client.ts'
|
||||||
|
import { installAiHelpHook } from '../../core/help.ts'
|
||||||
|
import { log, printJson } from '../../core/log.ts'
|
||||||
|
|
||||||
|
interface Opts {
|
||||||
|
id: string
|
||||||
|
fullName?: string
|
||||||
|
enCode?: string
|
||||||
|
category?: string
|
||||||
|
enabledMark?: string
|
||||||
|
description?: string
|
||||||
|
json?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildWorkflowUpdateCommand(): Command {
|
||||||
|
const cmd = new Command('update')
|
||||||
|
.description('流程模板修改 (改 fullName/enCode/category/enabledMark, PUT 语义)')
|
||||||
|
.requiredOption('--id <id>', '流程模板 id')
|
||||||
|
.option('--fullName <n>', '中文名')
|
||||||
|
.option('--enCode <e>', '英文编码')
|
||||||
|
.option('--category <c>', '分类 id')
|
||||||
|
.option('--enabledMark <0|1>', '启用/禁用')
|
||||||
|
.option('--description <d>', '描述')
|
||||||
|
.option('--json', '原始 JSON 输出', false)
|
||||||
|
.action(async (opts: Opts) => {
|
||||||
|
const c = await JnpfClient.fromToken()
|
||||||
|
// 拉原模板
|
||||||
|
const orig = (await c.get<Record<string, unknown>>(`/workflow/template/${opts.id}`)).data
|
||||||
|
if (!orig) {
|
||||||
|
log.error(`workflow update 失败: 拉原模板 id=${opts.id} 失败`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
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.category) body.category = opts.category
|
||||||
|
if (opts.enabledMark !== undefined) body.enabledMark = parseInt(opts.enabledMark, 10)
|
||||||
|
if (opts.description) body.description = opts.description
|
||||||
|
log.info(`PUT /workflow/template/${opts.id}`)
|
||||||
|
const r = await c.putJson<unknown>(`/workflow/template/${opts.id}`, body)
|
||||||
|
if (r.code !== 200) {
|
||||||
|
log.error(`workflow update 失败 (code=${r.code}): ${r.msg}`)
|
||||||
|
if (opts.json) printJson(r)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
log.ok(`✓ 流程模板更新成功 (id=${opts.id})`)
|
||||||
|
if (opts.json) printJson(r.data)
|
||||||
|
})
|
||||||
|
installAiHelpHook(cmd, {
|
||||||
|
purpose: '流程模板修改 (改 fullName/enCode/category/enabledMark/description). PUT 语义, 未传保留.',
|
||||||
|
required: { '--id': '流程模板 id' },
|
||||||
|
optional: { '--fullName': '中文名', '--enCode': '英文编码', '--category': '分类 id', '--enabledMark': '启用/禁用 0|1', '--description': '描述' },
|
||||||
|
example: 'dacli workflow update --id=123 --enabledMark=0',
|
||||||
|
source: { api: 'PUT /api/workflow/template/{id}' },
|
||||||
|
notes: ['v0.11+ P0 新增', '未传字段保留 (PUT 语义)'],
|
||||||
|
})
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
Reference in new issue
Block a user