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

Function parseWorkflowVariables

apps/sim/app/api/v1/admin/types.ts:334–375  ·  view source on GitHub ↗
(
  dbVariables: DbWorkflow['variables']
)

Source from the content-addressed store, hash-verified

332 * Handles both legacy Array and current Record<string, Variable> formats.
333 */
334export function parseWorkflowVariables(
335 dbVariables: DbWorkflow['variables']
336): Record<string, WorkflowVariable> | undefined {
337 if (!dbVariables) return undefined
338
339 try {
340 const varsObj = typeof dbVariables === 'string' ? JSON.parse(dbVariables) : dbVariables
341
342 // Handle legacy Array format by converting to Record
343 if (Array.isArray(varsObj)) {
344 const result: Record<string, WorkflowVariable> = {}
345 for (const v of varsObj) {
346 result[v.id] = {
347 id: v.id,
348 name: v.name,
349 type: v.type,
350 value: v.value,
351 }
352 }
353 return result
354 }
355
356 // Already Record format - normalize and return
357 if (typeof varsObj === 'object' && varsObj !== null) {
358 const result: Record<string, WorkflowVariable> = {}
359 for (const [key, v] of Object.entries(varsObj)) {
360 const variable = v as { id: string; name: string; type: VariableType; value: unknown }
361 result[key] = {
362 id: variable.id,
363 name: variable.name,
364 type: variable.type,
365 value: variable.value,
366 }
367 }
368 return result
369 }
370 } catch {
371 // pass
372 }
373
374 return undefined
375}
376
377/**
378 * Extract workflow metadata from various export formats.

Callers 4

route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected