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

Function remapConditionIds

apps/sim/stores/workflows/utils.ts:422–447  ·  view source on GitHub ↗
(
  subBlocks: Record<string, SubBlockState>,
  subBlockValues: Record<string, unknown>,
  oldBlockId: string,
  newBlockId: string
)

Source from the content-addressed store, hash-verified

420 * Mutates both `subBlocks` and `subBlockValues` in place (callers must pass cloned data).
421 */
422export function remapConditionIds(
423 subBlocks: Record<string, SubBlockState>,
424 subBlockValues: Record<string, unknown>,
425 oldBlockId: string,
426 newBlockId: string
427): void {
428 for (const [subBlockId, subBlock] of Object.entries(subBlocks)) {
429 if (subBlock.type !== 'condition-input' && subBlock.type !== 'router-input') continue
430
431 const value = subBlockValues[subBlockId] ?? subBlock.value
432 if (typeof value !== 'string') continue
433
434 try {
435 const parsed = JSON.parse(value)
436 if (!Array.isArray(parsed)) continue
437
438 if (remapConditionBlockIds(parsed, oldBlockId, newBlockId)) {
439 const newValue = JSON.stringify(parsed)
440 subBlock.value = newValue
441 subBlockValues[subBlockId] = newValue
442 }
443 } catch {
444 // Not valid JSON, skip
445 }
446 }
447}
448
449export function regenerateBlockIds(
450 blocks: Record<string, BlockState>,

Callers 3

store.tsFile · 0.90
regenerateWorkflowIdsFunction · 0.85
regenerateBlockIdsFunction · 0.85

Calls 2

remapConditionBlockIdsFunction · 0.90
parseMethod · 0.80

Tested by

no test coverage detected