@@ -45,22 +45,50 @@ export class Flow {
4545 public static readonly RESOURCE_TAGS = [ "textTemplates" , "stages" ] as const ;
4646 public static readonly VARIABLE_TAGS = [ "choices" , "constants" , "dynamicChoiceSets" , "formulas" , "variables" ] as const ;
4747
48+ // Flow elements (excludes legacy start nodes)
4849 public elements : FlowElement [ ] = [ ] ;
49- public fsPath ?: string ;
50- public uri ?: string ;
51- public interviewLabel ?: string ;
50+
51+ // Path properties
52+ public fsPath ?: string ; // Resolved absolute path (Node.js only)
53+ public uri ?: string ; // Input path (could be relative, absolute, or virtual)
54+
55+ // Flow metadata
5256 public label : string = "" ;
57+ public interviewLabel ?: string ;
5358 public name : string = "unnamed" ;
5459 public processMetadataValues ?: any ;
5560 public processType : string = "AutoLaunchedFlow" ;
56- public type : string = "" ;
57- public root ?: any ;
61+ public type : string = "" ; // Alias for processType (backward compatibility)
62+ public status : string = "" ;
63+ public triggerOrder ?: number ;
64+
65+ // Start-related properties
66+ /**
67+ * @deprecated Use startNode.element instead. Kept for backward compatibility.
68+ */
5869 public start ?: any ;
70+
71+ /**
72+ * Direct reference to first element (from XML attribute).
73+ * Used in newer flows as an alternative to the start element.
74+ */
5975 public startElementReference ?: string ;
76+
77+ /**
78+ * Computed reference to the first element to execute.
79+ * This is what rules should use for traversal.
80+ */
6081 public startReference ?: string ;
82+
83+ /**
84+ * Parsed FlowNode object of the start element.
85+ * Contains trigger information and connectors.
86+ * Access start element data via startNode.element
87+ */
6188 public startNode ?: FlowNode ;
62- public status : string = "" ;
63- public triggerOrder ?: number ;
89+
90+ // Legacy/internal
91+ public root ?: any ;
6492 public xmldata : any ;
6593
6694 constructor ( path ?: string , data ?: unknown ) {
@@ -113,7 +141,6 @@ export class Flow {
113141 this . type = this . processType ;
114142 this . processMetadataValues = this . xmldata . processMetadataValues ;
115143 this . startElementReference = this . xmldata . startElementReference ;
116- this . start = this . xmldata . start ;
117144 this . status = this . xmldata . status || "Draft" ;
118145 this . triggerOrder = this . xmldata . triggerOrder ;
119146
@@ -127,14 +154,14 @@ export class Flow {
127154
128155 const data = this . xmldata [ nodeType ] ;
129156
130- // Handle start node separately - store in startNode, don't add to elements
157+ // Handle start nodes separately - store in startNode, don't add to elements
131158 if ( nodeType === "start" ) {
132159 if ( Array . isArray ( data ) && data . length > 0 ) {
133160 this . startNode = new FlowNode ( data [ 0 ] . name || "start" , "start" , data [ 0 ] ) ;
134161 } else if ( ! Array . isArray ( data ) ) {
135162 this . startNode = new FlowNode ( data . name || "start" , "start" , data ) ;
136163 }
137- continue ;
164+ continue ; // Don't add to elements array
138165 }
139166
140167 // Process other node types
@@ -168,39 +195,44 @@ export class Flow {
168195 }
169196 }
170197
198+ /**
199+ * Find the name of the first element to execute.
200+ * Priority order:
201+ * 1. startElementReference (newer flows, direct XML attribute)
202+ * 2. Start node connector (older flows, points to first element)
203+ * 3. Start node scheduledPaths (async flows)
204+ */
171205 private findStart ( ) : string {
172- // Priority 1: Explicit startElementReference
173- if ( this . startElementReference ) {
174- return this . startElementReference ;
175- }
206+ // Priority 1: Explicit startElementReference
207+ if ( this . startElementReference ) {
208+ return this . startElementReference ;
209+ }
176210
177- // Priority 2: Start node with regular connector
178- if ( this . startNode && this . startNode . connectors && this . startNode . connectors . length > 0 ) {
179- const connector = this . startNode . connectors [ 0 ] ;
180- // FlowElementConnector stores targetReference in the ' reference' property
181- if ( connector . reference ) {
182- return connector . reference ;
211+ // Priority 2: Start node with regular connector
212+ if ( this . startNode && this . startNode . connectors && this . startNode . connectors . length > 0 ) {
213+ const connector = this . startNode . connectors [ 0 ] ;
214+ if ( connector . reference ) {
215+ return connector . reference ;
216+ }
183217 }
184- }
185218
186- // Priority 3: Start node with scheduledPaths (async flows)
187- // scheduledPaths can be an array or a single object
188- if ( this . startNode ? .element ) {
189- const scheduledPaths = this . startNode . element [ ' scheduledPaths' ] ;
190- if ( scheduledPaths ) {
191- const paths = Array . isArray ( scheduledPaths ) ? scheduledPaths : [ scheduledPaths ] ;
192- if ( paths . length > 0 && paths [ 0 ] ? .connector ) {
193- const targetRef = paths [ 0 ] . connector . targetReference ;
194- if ( targetRef ) {
195- return targetRef ;
219+ // Priority 3: Start node with scheduledPaths (async flows)
220+ if ( this . startNode ?. element ) {
221+ const scheduledPaths = this . startNode . element [ 'scheduledPaths' ] ;
222+ if ( scheduledPaths ) {
223+ const paths = Array . isArray ( scheduledPaths ) ? scheduledPaths : [ scheduledPaths ] ;
224+ if ( paths . length > 0 && paths [ 0 ] ?. connector ) {
225+ const targetRef = paths [ 0 ] . connector . targetReference ;
226+ if ( targetRef ) {
227+ return targetRef ;
228+ }
196229 }
197230 }
198231 }
199- }
200232
201- // No valid start found
202- return "" ;
203- }
233+ // No valid start found
234+ return "" ;
235+ }
204236
205237 public toXMLString ( ) : string {
206238 try {
0 commit comments