openpencil/packages/cli/src/rpc-data.ts
Danila Poyarkov 9bb9478833
refactor: replace complex conditional object spreads
- Add a typed, modular custom Oxlint rule package with direct regression coverage
- Replace complex conditional object spreads with explicit construction across the repository
- Preserve all existing custom rule registrations and diagnostic behavior
2026-09-01 19:49:57 +03:00

28 lines
972 B
TypeScript

import { executeRPCCommand } from '@open-pencil/core/rpc'
import { isAppMode, requireFile, rpc } from '#cli/app-client'
import { appTargetRPCArgs, type AppTargetCLIArgs } from '#cli/app-target'
import { loadDocument, prepareDocumentForRPC } from '#cli/headless'
type RPCArgs = { [key: string]: unknown }
function isRPCArgs(value: unknown): value is RPCArgs {
return Boolean(value && typeof value === 'object' && !Array.isArray(value))
}
export async function loadRPCData<Result>(
file: string | undefined,
command: string,
args?: unknown,
targetArgs?: AppTargetCLIArgs
): Promise<Result> {
if (isAppMode(file)) {
const rpcArgs: RPCArgs = isRPCArgs(args) ? { ...args } : {}
if (targetArgs) Object.assign(rpcArgs, appTargetRPCArgs(targetArgs))
return rpc<Result>(command, rpcArgs)
}
const graph = await loadDocument(requireFile(file))
prepareDocumentForRPC(graph, command, args)
return executeRPCCommand(graph, command, args) as Result
}