MCPcopy Index your code
hub / github.com/simstudioai/sim / serializeWorkflow

Method serializeWorkflow

apps/sim/serializer/index.ts:148–181  ·  view source on GitHub ↗
(
    blocks: Record<string, BlockState>,
    edges: Edge[],
    loops?: Record<string, Loop>,
    parallels?: Record<string, Parallel>,
    validateRequired = false
  )

Source from the content-addressed store, hash-verified

146
147export class Serializer {
148 serializeWorkflow(
149 blocks: Record<string, BlockState>,
150 edges: Edge[],
151 loops?: Record<string, Loop>,
152 parallels?: Record<string, Parallel>,
153 validateRequired = false
154 ): SerializedWorkflow {
155 const canonicalLoops = generateLoopBlocks(blocks)
156 const canonicalParallels = generateParallelBlocks(blocks)
157 const safeLoops = Object.keys(canonicalLoops).length > 0 ? canonicalLoops : loops || {}
158 const safeParallels =
159 Object.keys(canonicalParallels).length > 0 ? canonicalParallels : parallels || {}
160 if (validateRequired) {
161 this.validateSubflowsBeforeExecution(blocks, safeLoops, safeParallels)
162 }
163
164 return {
165 version: '1.0',
166 blocks: Object.values(blocks).map((block) =>
167 this.serializeBlock(block, {
168 validateRequired,
169 allBlocks: blocks,
170 })
171 ),
172 connections: edges.map((edge) => ({
173 source: edge.source,
174 target: edge.target,
175 sourceHandle: edge.sourceHandle || undefined,
176 targetHandle: edge.targetHandle || undefined,
177 })),
178 loops: safeLoops,
179 parallels: safeParallels,
180 }
181 }
182
183 /**
184 * Validate loop and parallel subflows for required inputs when running in "each/collection" modes

Callers 9

requiredFieldsCheckFunction · 0.95
store.tsFile · 0.80
executeWorkflowCoreFunction · 0.80
index.test.tsFile · 0.80
handleExecutePostFunction · 0.80
loadChildWorkflowMethod · 0.80

Calls 4

serializeBlockMethod · 0.95
generateLoopBlocksFunction · 0.90
generateParallelBlocksFunction · 0.90

Tested by

no test coverage detected