diff --git a/src/commands/di/create.ts b/src/commands/di/create.ts index 95b2558..39143c0 100644 --- a/src/commands/di/create.ts +++ b/src/commands/di/create.ts @@ -16,7 +16,7 @@ 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' +import { initWebapi, loadDataInterface, getDataInterfaceList } from '../../webapi/di.ts' // v0.15+ (P0-8): getDataInterfaceList 替代 c.get import { validateDiUpdate, type DiOpts } from './_validate.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' @@ -160,13 +160,12 @@ export function buildDiCreateCommand(): Command { } let newId = (r.data as { id?: string })?.id if (!newId) { - // 拉列表查新 ID + // 拉列表查新 ID (v0.15+ 走 webapi, 替代 c.get) try { - const listR = await c.get<{ list?: Array<{ id: string; enCode: string }> }>( - '/system/DataInterface', - { currentPage: 1, pageSize: 100, category: opts.category }, // BS-17 fix: 用用户传的 category, 不硬编码 - ) - const listData = listR.data?.list || [] + const listR = (await getDataInterfaceList({ + currentPage: 1, pageSize: 100, category: opts.category, // BS-17 fix: 用用户传的 category, 不硬编码 + })) as { data?: { list?: Array<{ id: string; enCode: string }> } } | unknown + const listData = (listR as { data?: { list?: Array<{ id: string; enCode: string }> } })?.data?.list || [] const found = listData.find((d: { id: string; enCode: string }) => d.enCode === opts.enCode) newId = found?.id } catch { @@ -224,14 +223,15 @@ async function runDiStepMachineCreate( opts: CreateOpts, ): Promise { // 1. 拉全 DI 列表 (供 step 2 唯一性预校验, BS-47) + // v0.15+ (P0-8) 走 webapi/getDataInterfaceList, 替代 c.get let existingDIs: Array<{ fullName?: string; enCode?: string; id?: string }> = [] try { - const r = await c.get<{ data?: { list?: Array } }>('/system/DataInterface', { + const r = (await getDataInterfaceList({ currentPage: 1, pageSize: 1000, category: '30be5ef4e3074dd89385ad6b4540c63d', // BS-17 fix - }) - const list = (r.data as { list?: Array })?.list || [] + })) as { data?: { list?: Array } } | unknown + const list = ((r as { data?: { list?: Array } })?.data?.list) || [] existingDIs = list.map((d: any) => ({ fullName: d.fullName, enCode: d.enCode, diff --git a/src/commands/di/update.ts b/src/commands/di/update.ts index f1c283c..6c4428a 100644 --- a/src/commands/di/update.ts +++ b/src/commands/di/update.ts @@ -8,7 +8,7 @@ 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' +import { initWebapi, loadDataInterface, getDataInterfaceList } from '../../webapi/di.ts' // v0.15+ (P0-8): getDataInterfaceList 替代 c.get import { validateDiUpdate, type DiOpts } from './_validate.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' import { dirtyCheck, dirtyCheckFailAndExit } from '../_dirty_check.ts' @@ -127,14 +127,15 @@ async function runDiStepMachine( orig: Record, ): Promise { // 1. 拉全 DI 列表 (供 step 2 唯一性预校验, BS-47) + // v0.15+ (P0-8) 走 webapi/getDataInterfaceList, 替代 c.get // 注: 拉列表可能慢, 用 pageSize=1000 单页拉完 let existingDIs: Array<{ fullName?: string; enCode?: string; id?: string }> = [] try { - const r = await c.get<{ data?: { list?: Array } }>('/system/DataInterface', { + const r = (await getDataInterfaceList({ currentPage: 1, pageSize: 1000, - }) - const list = (r.data as { list?: Array })?.list || [] + })) as { data?: { list?: Array } } | unknown + const list = ((r as { data?: { list?: Array } })?.data?.list) || [] existingDIs = list.map((d: any) => ({ fullName: d.fullName, enCode: d.enCode, diff --git a/src/webapi/di.ts b/src/webapi/di.ts index 90bf38c..e61ce0d 100644 --- a/src/webapi/di.ts +++ b/src/webapi/di.ts @@ -31,3 +31,13 @@ export const loadDataInterface: any = new Proxy({} as any, { return cached[prop] }, }) + +/** v0.15+ (P0-8, 2026-07-02): 拉 DI 列表 (page list, 镜像 web getDataInterfaceList) + * 替代 create.ts:165, create.ts:229, update.ts:133 的 raw c.get('/system/DataInterface', ...) + * 统一 webapi 化, 后端路径迁移时自动跟随 + * @param params { currentPage?, pageSize?, category?, keyword? } + * @returns 后端 data 字段 (List) + */ +export async function getDataInterfaceList(params: Record = {}): Promise { + return loadDataInterface.getDataInterfaceList(params) +}