@cyoda/workflow-graph
v0.2.0
Published
Cyoda workflow graph projection: domain → nodes/edges/annotations; canvas edits → domain patches.
Readme
@cyoda/workflow-graph
Projects Cyoda workflow documents into graph nodes, edges, and annotations for visual rendering and editing.
Install
npm install @cyoda/workflow-core @cyoda/workflow-graphProjection rules
projectToGraph(document) converts a WorkflowEditorDocument into a
GraphDocument containing:
StateNode— one per state; carriesstateCode,role(initial / terminal / initial-terminal / normal),workflow, andannotations(validation issues mapped by code).StartMarkerNode+ start edge — one per workflow; non-interactive, points to the initial state.TransitionEdge— one per transition; carries criterion/processor/ execution summaries,isSelf,parallelIndex,parallelGroupSize,manual,disabled, and optional per-edge anchor overrides frommeta.workflowUi.
What does NOT appear in the graph:
- Layout positions — live in
WorkflowUiMeta.layout; consumed by@cyoda/workflow-layout. - Canvas comments — live in
WorkflowUiMeta.comments; rendered by the editor shell. - Criterion or processor nodes — these are summaries on edges only.
- Synthetic UUIDs never leak into exported Cyoda workflow JSON.
Usage
import { parseImportPayload } from "@cyoda/workflow-core";
import { projectToGraph } from "@cyoda/workflow-graph";
const { document } = parseImportPayload(workflowJson);
const graph = projectToGraph(document);
// graph.nodes — StateNode | StartMarkerNode
// graph.edges — TransitionEdge | StartMarkerEdge
// graph.annotations — GraphAnnotation[]applyGraphEdit
Translates canvas events into DomainPatch[]:
import { applyGraphEdit } from "@cyoda/workflow-graph";
const patches = applyGraphEdit(document, {
kind: "toggleDisabled",
transitionUuid: "...",
disabled: true,
});Supported event kinds: moveState (no-op — use setNodePosition in
@cyoda/workflow-core instead), renameState, deleteState,
addTransition, deleteTransition, reorderTransition, toggleDisabled,
toggleManual.
Documentation
See the repository README.
License
Apache-2.0
