From d4506fe4ded87d9948d874700be341c6b1c799aa Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 25 Jun 2026 12:12:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(webapi):=20v0.11+=20Phase=201=20-=20webapi?= =?UTF-8?q?/visualDev=20+=20dataModel=20+=20dataSource=20=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=20import=20web=20=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现 docs/dacli/v0.11-mirror-refactor.md Step 1-3: - src/webapi/_loader.ts: 通用 web 端源码加载器 (读源→替换 import→写 tmp→dynamic import) - src/webapi/_defhttp_shim.ts: 用 JnpfClient 实现 web 端 defHttp (get/post/put/delete) - src/webapi/visualDev.ts: 30+ 函数直接 import web/.../api/onlineDev/visualDev.ts - src/webapi/dataModel.ts: 10 函数 import + lodash omit shim - src/webapi/dataSource.ts: 11 函数 import - src/commands/form/list.ts: 改造样板 (c.get → loadVisualDev.getVisualDevList) 关键技术: - 读 web 端源 → 替换 #/api/request → shim 路径 → 替换 #/ → WEB_SRC → 替换 lodash-es → Node 原生 - 用 globalThis 共享 client (避免 tsx/动态 import 多实例) - shim 自动 strip /api 前缀 (因 JnpfClient.baseUrl 已含 /api) Checkpoint PASS: - test-webapi-visualdev.ts: visualDev 11 函数 import + 实测 (getVisualDevList + getInfo 返回数据正确) - test-webapi-datamodel.ts: dataModel 10 函数 import + 实测 (getDataModelList 返回数据) - dataSource smoke test: getDataSourceSelector 返回 2 项 - form list 命令 webapi 版与原版输出完全一致 - baseline 跑通, 无新 fail Co-Authored-By: Claude --- src/commands/form/list.ts | 14 +++-- src/webapi/_defhttp_shim.ts | 99 +++++++++++++++++++++++++++++++ src/webapi/_loader.ts | 103 +++++++++++++++++++++++++++++++++ src/webapi/dataModel.ts | 36 ++++++++++++ src/webapi/dataSource.ts | 35 +++++++++++ src/webapi/visualDev.ts | 48 +++++++++++++++ tests/test-webapi-datamodel.ts | 82 ++++++++++++++++++++++++++ tests/test-webapi-visualdev.ts | 75 ++++++++++++++++++++++++ 8 files changed, 486 insertions(+), 6 deletions(-) create mode 100644 src/webapi/_defhttp_shim.ts create mode 100644 src/webapi/_loader.ts create mode 100644 src/webapi/dataModel.ts create mode 100644 src/webapi/dataSource.ts create mode 100644 src/webapi/visualDev.ts create mode 100644 tests/test-webapi-datamodel.ts create mode 100644 tests/test-webapi-visualdev.ts diff --git a/src/commands/form/list.ts b/src/commands/form/list.ts index 7bc77d6..5b1913d 100644 --- a/src/commands/form/list.ts +++ b/src/commands/form/list.ts @@ -2,13 +2,16 @@ * commands/form/list.ts — 列出当前应用的所有表单 (state/enCode/fullName) * * BS-53 (2026-06-23): state=2 = 已发布被编辑过, 前端 web 看不到直到 re-release. - * 本命令 v0.12+ 默认显示 STATE 列, --state filter 支持 0|1|2, --summary 输出 state 分布. + * 本命令 v0.12+ 默认显示 STATE 列, --state filter 支持 0|1/2, --summary 输出 state 分布. + * + * v0.11+ Phase 1 (2026-06-25): 用 webapi 调 web 端 getVisualDevList (替代 c.get('/visualdev/Base')) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import type { FormSummary } from '../../core/types.ts' +import { initWebapi, loadVisualDev } from '../../webapi/visualDev.ts' interface ListResp { list: FormSummary[] @@ -33,14 +36,13 @@ export function buildFormListCommand(): Command { .option('--summary', '输出 state 分布汇总 (不列明细)', false) .action(async (opts: { keyword?: string; state?: number; limit: number; json?: boolean; summary?: boolean }) => { const c = await JnpfClient.fromToken() - // GET /api/visualdev/Base — 公开方法 (返当前 systemId 下全部 form, - // 含 enableFlow=0/1/null). - const r = await c.get('/visualdev/Base', { + // v0.11+ Phase 1: 用 web 端 getVisualDevList (替代 c.get('/visualdev/Base')) + await initWebapi(c) + const data = (await loadVisualDev.getVisualDevList({ keyword: opts.keyword, currentPage: 1, pageSize: opts.limit, - }) - const data = c.ok(r) + })) as ListResp let list = data.list || [] if (opts.state !== undefined) list = list.filter((f) => f.state === opts.state) diff --git a/src/webapi/_defhttp_shim.ts b/src/webapi/_defhttp_shim.ts new file mode 100644 index 0000000..ab7854c --- /dev/null +++ b/src/webapi/_defhttp_shim.ts @@ -0,0 +1,99 @@ +/** + * _defhttp_shim.ts — 用 JnpfClient 实现 web 端的 defHttp (v0.11+ Phase 1) + * + * 设计: + * - web 端 request.ts 用 Vben 的 RequestClient, 依赖 axios + Vite + Vue ecosystem + * - dacli 是 Node CLI, 没 Vue/Vite, 但 defHttp.get/post/put/delete 签名是稳定的 + * - 此 shim 用 JnpfClient.fetch 实现, 签名与 web 完全一致 + * - 调用方 (visualDev.ts) 不感知 shim, 仍调 defHttp.x({ url, data, ...opts }) + * + * 注意: + * - 签名严格匹配 web Vben defHttp: + * defHttp.get({ url, params?, data? }) → GET (data 当 query) + * defHttp.post({ url, data }) → POST JSON + * defHttp.put({ url, data }) → PUT JSON + * defHttp.delete({ url, data? }) → DELETE + * - 响应统一返回 res.data (已经过 Vben transformResponseHook 解构) + * 即: { code: 200, msg: 'ok', data: ... } 解出 → 直接拿 .data + * - 不支持: useCipher 加密 / 上传下载进度 / axios 拦截器 + * (dacli 不需要这些, web 也只在 useCipher=true 时启用加密) + * - 用 globalThis 共享 client, 避免 tsx/动态 import 导致的多实例问题 + */ +import { JnpfClient } from '../core/client.ts' + +const GLOBAL_KEY = '__dacli_defhttp_shim_client__' +type GlobalWithClient = typeof globalThis & { [GLOBAL_KEY]?: JnpfClient } + +function getClient(): JnpfClient { + const client = (globalThis as GlobalWithClient)[GLOBAL_KEY] + if (!client) throw new Error('defHttp shim 未初始化, 请先调 initDefHttpShim(client)') + return client +} + +/** 初始化 shim, 必须先调一次 (visualDev / dataModel 模块加载前) */ +export function initDefHttpShim(client: JnpfClient): void { + ;(globalThis as GlobalWithClient)[GLOBAL_KEY] = client +} + +/** 把 undefined/null 值从 query 里去掉 (与 JnpfClient.get 行为一致) */ +function cleanQuery(data: Record | undefined): Record { + if (!data) return {} + const out: Record = {} + for (const [k, v] of Object.entries(data)) { + if (v === undefined || v === null) continue + if (typeof v === 'object') out[k] = JSON.stringify(v) + else out[k] = v as string | number + } + return out +} + +/** 统一响应包装: web 的 transformResponseHook 已经解出 {code,data,msg} → 取 data */ +async function unwrap(resp: { code: number; msg?: string; data: T | null }): Promise { + if (resp.code !== 200) { + throw new Error(`API code=${resp.code}: ${resp.msg ?? ''}`) + } + return resp.data as T +} + +/** + * 把 web 端 url 里的 /api 前缀去掉, 因为 JnpfClient.baseUrl 已含 /api + * + * web 端 url: '/api/visualdev/Base' → JNPF base 'http://nginx/api' + * dacli 期望: '/visualdev/Base' → 'http://nginx/api' + '/visualdev/Base' = 'http://nginx/api/visualdev/Base' + * + * 不改 baseUrl (会破坏现有命令), 仅在 shim 里 strip + */ +function stripApiPrefix(url: string): string { + if (url.startsWith('/api/')) return url.slice(4) + if (url === '/api') return '' + return url +} + +/** + * shim of web defHttp — 与 Vben defHttp 签名一致 + * 用法 (web 端 visualDev.ts 不感知): + * defHttp.get({ url: '/api/visualdev/Base', data: { keyword: 'foo' } }) + */ +export const defHttp = { + async get(config: { url: string; data?: Record }): Promise { + const c = getClient() + const r = await c.get(stripApiPrefix(config.url), cleanQuery(config.data)) + return unwrap(r) + }, + async post(config: { url: string; data?: unknown }): Promise { + const c = getClient() + const r = await c.postJson(stripApiPrefix(config.url), config.data ?? {}) + return unwrap(r) + }, + async put(config: { url: string; data?: unknown }): Promise { + const c = getClient() + const r = await c.putJson(stripApiPrefix(config.url), config.data ?? {}) + return unwrap(r) + }, + async delete(config: { url: string; data?: unknown }): Promise { + const c = getClient() + // 注意: web 端 defHttp.delete 也可能带 data (axios 支持), 我们忽略 + const r = await c.del(stripApiPrefix(config.url)) + return unwrap(r) + }, +} \ No newline at end of file diff --git a/src/webapi/_loader.ts b/src/webapi/_loader.ts new file mode 100644 index 0000000..e8306a4 --- /dev/null +++ b/src/webapi/_loader.ts @@ -0,0 +1,103 @@ +/** + * _loader.ts — 通用 web 端源码加载器 (v0.11+ Phase 1) + * + * 设计: 与 _buildformdata.ts 同样的技巧 — 读源码 → 替换 import → 写 tmp → dynamic import + * + * 替换规则 (按顺序, 避免误伤): + * 1. `from '#/api/request'` → `from ''` (defHttp shim, 优先于 #/) + * 2. `from '#/...'` → `from '${WEB_SRC}/...'` (其他 #/ alias) + * 3. `from '@jnpf/utils'` → `from '${JNPF_UTILS_UUID}'` (uuid only, 避开 Vite env) + * 4. `import { cloneDeep } from 'lodash-es';?` → `const cloneDeep = (x) => structuredClone(x);` + * 5. `import { omit } from 'lodash-es';?` → `function omit(obj, keys) { ... }` + * + * 注意: + * - 不修改 web/ 源码 (CLAUDE.md §15 禁止) + * - 单进程缓存: 同一 source 路径只 load 一次 + * - shim 路径指向 _defhttp_shim.ts (位于本目录) + */ +import { readFileSync, writeFileSync, mkdirSync } from 'fs' +import { tmpdir } from 'os' +import { join, dirname } from 'path' +import { pathToFileURL } from 'url' + +const WEB_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src' +const JNPF_UTILS_UUID = '/home/ubuntu/ccWorkDir/web/packages/jnpf/utils/src/helpers/uuid.ts' +const SHIM_PATH = join(dirname(new URL(import.meta.url).pathname), '_defhttp_shim.ts') + +/** lodash omit 的最小实现 (web dataModel.ts 用) */ +const LODASH_OMIT_STUB = ` +const omit = (obj, keys) => { + if (!obj) return obj; + const out = { ...obj }; + for (const k of (Array.isArray(keys) ? keys : [keys])) delete out[k]; + return out; +};` + +export interface LoadOptions { + /** 自定义 shim 路径 (默认 _defhttp_shim.ts) */ + shimPath?: string + /** 跳过 lodash 替换 (默认 true, visualDev.ts 不需要) */ + handleLodash?: boolean +} + +/** 单进程缓存: path → module */ +const cache = new Map>() + +/** + * 加载 web 端 TypeScript 文件, 替换 import, dynamic import + * @param sourcePath web 端 .ts 源文件绝对路径 + * @returns 加载后的 ES module (含所有 named export) + */ +export async function loadWebModule(sourcePath: string, opts: LoadOptions = {}): Promise { + if (cache.has(sourcePath)) return cache.get(sourcePath) as Promise + + const promise = (async () => { + const shimPath = opts.shimPath ?? SHIM_PATH + + // 1. 读源 + let src = readFileSync(sourcePath, 'utf-8') + + // 2. 替换 #/api/request → shim (必须在 #/ 通用规则之前) + src = src.replace(/from\s+['"]#\/api\/request['"]/g, `from '${shimPath}'`) + + // 3. 替换其他 #/... → WEB_SRC/... (但已替换的 #/api/request 不再被命中) + src = src.replace(/from\s+['"]#\/(.+?)['"]/g, (_, p) => `from '${WEB_SRC}/${p}'`) + + // 4. 替换 @jnpf/utils → uuid (避开 Vite env) + src = src.replace(/from\s+['"]@jnpf\/utils['"]/g, `from '${JNPF_UTILS_UUID}'`) + + // 5. 替换 lodash-es → Node 原生实现 (按需) + if (opts.handleLodash !== false) { + src = src.replace( + /import\s*\{\s*cloneDeep\s*\}\s*from\s+['"]lodash-es['"];?/g, + `const cloneDeep = (x) => structuredClone(x);`, + ) + src = src.replace( + /import\s*\{\s*omit\s*\}\s*from\s+['"]lodash-es['"];?/g, + LODASH_OMIT_STUB, + ) + } + + // 6. 写 tmp + const tmpDir = `${tmpdir()}/dacli-webapi-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}` + mkdirSync(tmpDir, { recursive: true }) + const tmpFile = join(tmpDir, sourcePath.split('/').pop()!) + writeFileSync(tmpFile, src) + + // 7. dynamic import + return await import(pathToFileURL(tmpFile).href) + })() + + cache.set(sourcePath, promise) + return promise +} + +/** 清空缓存 (测试用) */ +export function clearCache(): void { + cache.clear() +} + +/** 检查缓存状态 (调试用) */ +export function getCacheKeys(): string[] { + return Array.from(cache.keys()) +} \ No newline at end of file diff --git a/src/webapi/dataModel.ts b/src/webapi/dataModel.ts new file mode 100644 index 0000000..8d164ba --- /dev/null +++ b/src/webapi/dataModel.ts @@ -0,0 +1,36 @@ +/** + * webapi/dataModel.ts — 直接 import web 端 dataModel.ts (v0.11+ Phase 1) + * + * 注意: + * - dataModel.ts 用 `import { omit } from 'lodash-es'`, _loader.ts 已处理 + * - 9 个函数: getDataModelList / getDataModelListAll / previewDataModel / createDataModel / + * updateDataModel / getDataModelInfo / delDataModel / getDataModelFieldList / + * addTableFields / exportTable + */ +import { JnpfClient } from '../core/client.ts' +import { loadWebModule } from './_loader.ts' + +const DATA_MODEL_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/systemData/dataModel.ts' + +let cached: any = null + +export async function initWebapi(client: JnpfClient): Promise { + if (cached) return + // visualDev.ts 已经在 visualDev.ts 里 init 过 shim, 但单独用 dataModel 也要兜底 + const { initDefHttpShim } = await import('./_defhttp_shim.ts') + initDefHttpShim(client) + cached = await loadWebModule(DATA_MODEL_SRC) +} + +export function isWebapiLoaded(): boolean { + return cached !== null +} + +export const loadDataModel: any = new Proxy({} as any, { + get(_target, prop) { + if (!cached) { + throw new Error(`dataModel 模块未初始化, 请先 await initWebapi(client)`) + } + return cached[prop] + }, +}) \ No newline at end of file diff --git a/src/webapi/dataSource.ts b/src/webapi/dataSource.ts new file mode 100644 index 0000000..386726e --- /dev/null +++ b/src/webapi/dataSource.ts @@ -0,0 +1,35 @@ +/** + * webapi/dataSource.ts — 直接 import web 端 dataSource.ts (v0.11+ Phase 1) + * + * 注意: + * - dataSource.ts 仅用 `defHttp`, 不需 lodash-es + * - 11 个函数: getDataSourceList / getDataSourceSelector / createDataSource / + * updateDataSource / getDataSourceInfo / delDataSource / testDbConnection / + * dataSync / execute / batchExecute / checkDbLink + */ +import { JnpfClient } from '../core/client.ts' +import { loadWebModule } from './_loader.ts' + +const DATA_SOURCE_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/systemData/dataSource.ts' + +let cached: any = null + +export async function initWebapi(client: JnpfClient): Promise { + if (cached) return + const { initDefHttpShim } = await import('./_defhttp_shim.ts') + initDefHttpShim(client) + cached = await loadWebModule(DATA_SOURCE_SRC) +} + +export function isWebapiLoaded(): boolean { + return cached !== null +} + +export const loadDataSource: any = new Proxy({} as any, { + get(_target, prop) { + if (!cached) { + throw new Error(`dataSource 模块未初始化, 请先 await initWebapi(client)`) + } + return cached[prop] + }, +}) \ No newline at end of file diff --git a/src/webapi/visualDev.ts b/src/webapi/visualDev.ts new file mode 100644 index 0000000..a911bee --- /dev/null +++ b/src/webapi/visualDev.ts @@ -0,0 +1,48 @@ +/** + * webapi/visualDev.ts — 直接 import web 端 visualDev.ts 的 30+ 函数 (v0.11+ Phase 1) + * + * 设计: + * - 不重写 API wrapper, 而是从 web/apps/jnpf-web-apps-main/src/api/onlineDev/visualDev.ts 直接 import + * - web 端用 defHttp (#/api/request), 由 _loader.ts 替换为我们自己的 _defhttp_shim.ts + * - 缓存: _loader 单进程缓存, 同一 source 只 load 一次 + * + * 使用: + * import { loadVisualDev, initWebapi } from '../webapi/visualDev.ts' + * await initWebapi() // 必须先 await (初始化 defHttp shim + load 模块) + * const r = await loadVisualDev.getVisualDevList({ keyword: 'foo' }) + */ +import { JnpfClient } from '../core/client.ts' +import { loadWebModule } from './_loader.ts' + +const VISUAL_DEV_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/onlineDev/visualDev.ts' + +let cached: any = null + +/** + * 初始化 webapi 层: 必须先 await 一次 + * - initDefHttpShim(client): 让 visualDev 函数能用我们 JnpfClient + * - loadWebModule(VISUAL_DEV_SRC): 加载并缓存 visualDev 模块 + */ +export async function initWebapi(client: JnpfClient): Promise { + if (cached) return + // 1. 注入 shim 用的 JnpfClient (循环依赖解决: 在 _defhttp_shim.ts 直接 import JnpfClient) + const { initDefHttpShim } = await import('./_defhttp_shim.ts') + initDefHttpShim(client) + // 2. 加载 visualDev.ts + cached = await loadWebModule(VISUAL_DEV_SRC) +} + +/** 检查是否已初始化 (调试用) */ +export function isWebapiLoaded(): boolean { + return cached !== null +} + +/** 重新导出所有 web visualDev 函数 — 调用方用 `loadVisualDev.xxx(args)` */ +export const loadVisualDev: any = new Proxy({} as any, { + get(_target, prop) { + if (!cached) { + throw new Error(`visualDev 模块未初始化, 请先 await initWebapi(client)`) + } + return cached[prop] + }, +}) \ No newline at end of file diff --git a/tests/test-webapi-datamodel.ts b/tests/test-webapi-datamodel.ts new file mode 100644 index 0000000..a58e448 --- /dev/null +++ b/tests/test-webapi-datamodel.ts @@ -0,0 +1,82 @@ +/** + * tests/test-webapi-datamodel.ts — 验证 webapi/dataModel.ts (含 lodash omit shim) + * + * 与 test-webapi-visualdev.ts 同样的步骤, 重点验证 omit 处理正确 + */ +import { JnpfClient } from '../src/core/client.ts' +import { initWebapi, loadDataModel, isWebapiLoaded } from '../src/webapi/dataModel.ts' +import { log } from '../src/core/log.ts' + +async function main() { + log.info('=== test-webapi-datamodel ===') + + const c = await JnpfClient.fromToken() + log.ok(` 登录成功: baseUrl=${c.baseUrl} appCode=${c.appCode} dbLinkId=${c.dbLinkId}`) + + const t0 = Date.now() + await initWebapi(c) + log.ok(` 初始化成功 (${Date.now() - t0}ms), isWebapiLoaded=${isWebapiLoaded()}`) + + // 函数可用性 + const fns = [ + 'getDataModelList', + 'getDataModelListAll', + 'previewDataModel', + 'createDataModel', + 'updateDataModel', + 'getDataModelInfo', + 'delDataModel', + 'getDataModelFieldList', + 'addTableFields', + 'exportTable', + ] + for (const fn of fns) { + if (typeof loadDataModel[fn] !== 'function') { + throw new Error(`函数 ${fn} 不存在`) + } + } + log.ok(` ${fns.length} 个核心函数可用`) + + // 实测: getDataModelList (用 omit 剔除 linkId, 这是关键 lodash 测试点) + if (!c.dbLinkId) { + log.warn(' ⚠ 无 dbLinkId, 跳过实测调用') + log.ok('=== PASS (跳过实测) ===') + return + } + + log.info(`Step: 实测 getDataModelList({ linkId: '${c.dbLinkId}', currentPage: 1, pageSize: 3 })`) + const r = await loadDataModel.getDataModelList({ + linkId: c.dbLinkId, + currentPage: 1, + pageSize: 3, + }) + const arr = Array.isArray(r) ? r : r?.list ?? [] + log.ok(` 返回 ${arr.length} 条`) + if (arr.length > 0) { + const t = arr[0] + log.ok(` 示例: table=${t.table ?? t.tableName ?? '(无)'} fullName=${t.fullName ?? t.tableName ?? '(无)'}`) + } + + // 实测: previewDataModel (omit 2 个 key) + if (arr.length > 0) { + const t = arr[0] + const tname = t.table ?? t.tableName + if (tname) { + log.info(`Step: 实测 previewDataModel({ linkId: '${c.dbLinkId}', table: '${tname}' })`) + const preview = await loadDataModel.previewDataModel({ + linkId: c.dbLinkId, + table: tname, + }) + const cols = Array.isArray(preview) ? preview : preview?.data?.list ?? preview?.list ?? [] + log.ok(` 返回 ${cols.length} 列`) + } + } + + log.ok('=== 全部 PASS ===') +} + +main().catch((e) => { + log.error(`FAIL: ${(e as Error).message}`) + console.error(e) + process.exit(1) +}) \ No newline at end of file diff --git a/tests/test-webapi-visualdev.ts b/tests/test-webapi-visualdev.ts new file mode 100644 index 0000000..965ddf4 --- /dev/null +++ b/tests/test-webapi-visualdev.ts @@ -0,0 +1,75 @@ +/** + * tests/test-webapi-visualdev.ts — 验证 webapi/visualDev.ts 能成功 import + 调用 + * + * Checkpoint (docs/dacli/v0.11-mirror-refactor.md Step 1): + * - 能成功 import visualDev.ts (通过 _loader.ts + _defhttp_shim.ts) + * - 能调一个 web 函数 (getVisualDevList) + * + * 用法: cd /home/ubuntu/ccWorkDir/dacli && npx tsx tests/test-webapi-visualdev.ts + */ +import { JnpfClient } from '../src/core/client.ts' +import { initWebapi, loadVisualDev, isWebapiLoaded } from '../src/webapi/visualDev.ts' +import { log } from '../src/core/log.ts' + +async function main() { + log.info('=== test-webapi-visualdev ===') + + // 1. 登录 + log.info('Step 1: JnpfClient.fromToken()') + const c = await JnpfClient.fromToken() + log.ok(` 登录成功: baseUrl=${c.baseUrl} appCode=${c.appCode} dbLinkId=${c.dbLinkId}`) + + // 2. 初始化 webapi (注入 shim + load 模块) + log.info('Step 2: initWebapi(client)') + const t0 = Date.now() + await initWebapi(c) + log.ok(` 初始化成功 (${Date.now() - t0}ms), isWebapiLoaded=${isWebapiLoaded()}`) + + // 3. 列出已导入的函数 (Proxy 代理) + log.info('Step 3: 验证函数可用') + const fns = [ + 'getVisualDevList', + 'create', + 'update', + 'getInfo', + 'delVisualDev', + 'copy', + 'release', + 'getReleaseMenu', + 'createMenu', + 'getConfigData', + 'getFormData', + ] + for (const fn of fns) { + if (typeof loadVisualDev[fn] !== 'function') { + throw new Error(`函数 ${fn} 不存在`) + } + } + log.ok(` ${fns.length} 个核心函数可用`) + + // 4. 实测调用: getVisualDevList (只取 5 条, 不打印明细) + log.info('Step 4: 实测 getVisualDevList({ currentPage: 1, pageSize: 5 })') + const list = await loadVisualDev.getVisualDevList({ currentPage: 1, pageSize: 5 }) + const arr = Array.isArray(list) ? list : (list?.list ?? []) + log.ok(` 返回 ${arr.length} 条 (total key=${typeof list === 'object' && 'pagination' in list ? '✓' : '?'})`) + if (arr.length > 0) { + const f = arr[0] + log.ok(` 示例: id=${f.id} fullName=${f.fullName} state=${f.state}`) + } + + // 5. 实测调用: getInfo (用第一个 form) + if (arr.length > 0) { + log.info(`Step 5: 实测 getInfo(${arr[0].id})`) + const info = await loadVisualDev.getInfo(arr[0].id) + const f = info?.data ?? info + log.ok(` 返回 id=${f?.id} enCode=${f?.enCode} fullName=${f?.fullName}`) + } + + log.ok('=== 全部 PASS ===') +} + +main().catch((e) => { + log.error(`FAIL: ${(e as Error).message}`) + console.error(e) + process.exit(1) +}) \ No newline at end of file