/** * commands/monitor/sql.ts — SQL 监控 (dataInterface 调用日志) * * v0.11+ Phase 2: webapi 化 (loadDataInterface.getDataInterfaceLog) * 替代 v0.10 直接 c.get */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { initWebapi, loadDataInterface } from '../../webapi/di.ts' interface SqlOpts { id: string json?: boolean } export function buildMonitorSqlCommand(): Command { const cmd = new Command('sql') .description('SQL 监控 (数据接口调用日志, v0.11+ webapi)') .requiredOption('--id ', '数据接口 id') .option('--json', '原始 JSON 输出', false) .action(async (opts: SqlOpts) => { const c = await JnpfClient.fromToken() await initWebapi(c) // web getDataInterfaceLog(id, data) 接受 (id, params) const r = (await loadDataInterface.getDataInterfaceLog(opts.id, { currentPage: 1, pageSize: 50, })) as { list?: Record[] } const list = r.list || [] if (opts.json) { printJson(r) return } log.info(`数据接口 id=${opts.id} 共 ${list.length} 条调用日志`) for (const d of list) { console.log(JSON.stringify(d)) } }) installHelpHook(cmd, { purpose: 'SQL 监控 (数据接口调用日志)', required: { '--id': '数据接口 id' }, example: 'dacli monitor sql --id=420587863533428357', source: { web: 'web/apps/jnpf-web-apps-main/src/views/monitor/platformMonitor/index.vue', api: 'GET /api/system/DataInterfaceLog/{id}', ref: 'doc/v0.8-endpoints.md §3.1', }, }) return cmd }