MCPcopy
hub / github.com/simstudioai/sim / normalizeLoop

Function normalizeLoop

apps/sim/lib/workflows/comparison/normalize.ts:114–139  ·  view source on GitHub ↗
(loop: Loop | null | undefined)

Source from the content-addressed store, hash-verified

112 * @returns Normalized loop with only relevant fields
113 */
114export function normalizeLoop(loop: Loop | null | undefined): NormalizedLoop | null | undefined {
115 if (!loop) return undefined // Normalize null to undefined
116 const { id, nodes, loopType, iterations, forEachItems, whileCondition, doWhileCondition } = loop
117
118 // Sort nodes for consistent comparison (execution order is determined by edges, not array order)
119 const sortedNodes = [...nodes].sort()
120 const base: NormalizedLoop = { id, nodes: sortedNodes, loopType }
121
122 // Only add optional fields if they have non-null/undefined values
123 switch (loopType) {
124 case 'for':
125 if (iterations != null) base.iterations = iterations
126 break
127 case 'forEach':
128 if (forEachItems != null) base.forEachItems = forEachItems
129 break
130 case 'while':
131 if (whileCondition != null) base.whileCondition = whileCondition
132 break
133 case 'doWhile':
134 if (doWhileCondition != null) base.doWhileCondition = doWhileCondition
135 break
136 }
137
138 return base
139}
140
141/** Normalized parallel result type with only essential fields */
142interface NormalizedParallel {

Callers 3

normalize.test.tsFile · 0.90
normalizeWorkflowStateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected