Files
hose-use/src/cli/commands/platform/shared.ts
T
gitea 6cb05ebc37 refactor(cli): split commands/platform.ts into platform/{shared,app-info,records,record-actions,index}.ts
Verbatim code moves grouped by concern: app metadata & permissions,
record query + ledger audit, and record write actions (incl. batch
safe edit). No behavior change: tsc clean, 316 tests pass.
2026-10-04 14:14:57 +08:00

34 lines
1.7 KiB
TypeScript

import { resolveEntity, resolvePlatform } from "../../../domains/datalink/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 };
}