Files
hose-use/src/cli/commands/platform/shared.ts
T
gitea 4e03c9bcd7 refactor: 将应用数据与工作流统一归入应用平台子模块
建立 applications 的应用模型和查询出口,保留基础及详情投影差异。
下沉 DataLink,将工作流模型、API、编排及执行上下文归回 workflow。
同步 CLI、SDK、生成脚本、测试和活跃文档引用,公开命令与 SDK 名称保持兼容。

验证:943 项测试、类型和版本检查通过;三份生成规范字节一致,README 审计通过。
2026-10-30 16:56:09 +08:00

35 lines
1.7 KiB
TypeScript

import { resolveEntity } from "../../../domains/platform/datalink/services.js";
import { resolvePlatform } from "../../../domains/platform/applications/services.js";
import { createClientsForCorp } from "../../helpers.js";
import type { CliParsedArgs, CliRuntime } from "../../types.js";
export function requiredTarget(parsed: CliParsedArgs, index: number, usage: string): string {
const target = parsed.args[index]?.trim();
if (!target) throw new Error(`请提供目标参数: ${usage}`);
return target;
}
export function splitFields(value?: string): string[] {
return value ? value.split(",").map((field) => field.trim()).filter(Boolean) : [];
}
export function cell(value: unknown): string {
if (value === undefined || value === null) return "";
if (typeof value === "object") return JSON.stringify(value);
return String(value);
}
export async function resolveAppAndEntity(parsed: CliParsedArgs, runtime: CliRuntime, appIndex = 0, entityIndex = 1) {
const appTarget = requiredTarget(parsed, appIndex, "hose-use platform <子命令> <应用 ID|名称>");
const clients = await createClientsForCorp(runtime.selectedCorp!);
const corpId = runtime.selectedCorp!.credentials.corpId;
const platform = await resolvePlatform(clients.ekbClient, corpId, appTarget);
if (!platform) throw new Error(`[NOT FOUND] 当前企业下未找到自建应用: ${appTarget}`);
const entityTarget = parsed.args[entityIndex]?.trim();
if (!entityTarget) return { clients, corpId, platform, entity: undefined };
const entity = await resolveEntity(clients.ekbClient, corpId, platform, entityTarget);
if (!entity) throw new Error(`[NOT FOUND] 应用 [${platform.name}] 下未找到业务对象: ${entityTarget}`);
return { clients, corpId, platform, entity };
}