commits
tags
// Handtagsmodellen – speglar rpa/schema.py:node_handles().
// vanlig nod : in -> out
// if : in -> case0 … caseN, else
// loop : in -> each, done
import type { Step } from "./api";
import type { Schema } from "./schema";
export function nodeControl(schema: Schema, type: string): "if" | "loop" | undefined {
return schema.step_types.find((s) => s.type === type)?.control;
}
export function outputHandles(schema: Schema, node: Step): string[] {
const ctrl = nodeControl(schema, node.type);
if (ctrl === "if") {
const n = Math.max(1, node.branches?.length ?? 1);
return [...Array.from({ length: n }, (_, i) => `case${i}`), "else"];
}
if (ctrl === "loop") return ["each", "done"];
return ["out"];
}
export const HANDLE_LABEL: Record<string, string> = {
out: "",
each: "varje",
done: "klar",
else: "annars",
};
export function handleLabel(h: string): string {
if (h in HANDLE_LABEL) return HANDLE_LABEL[h];
if (h.startsWith("case")) return `gren ${Number(h.slice(4)) + 1}`;
return h;
}