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

Function lazyCleanupInputMapping

apps/sim/executor/utils/lazy-cleanup.ts:36–89  ·  view source on GitHub ↗
(
  parentWorkflowId: string,
  parentBlockId: string,
  currentInputMapping: any,
  childWorkflowBlocks: Record<string, any>
)

Source from the content-addressed store, hash-verified

34 * @returns The cleaned inputMapping (only different if cleanup was needed)
35 */
36export async function lazyCleanupInputMapping(
37 parentWorkflowId: string,
38 parentBlockId: string,
39 currentInputMapping: any,
40 childWorkflowBlocks: Record<string, any>
41): Promise<any> {
42 try {
43 if (
44 !currentInputMapping ||
45 typeof currentInputMapping !== 'object' ||
46 Array.isArray(currentInputMapping)
47 ) {
48 return currentInputMapping
49 }
50
51 const validFieldNames = extractValidInputFieldNames(childWorkflowBlocks)
52
53 if (!validFieldNames || validFieldNames.size === 0) {
54 logger.debug('Child workflow has no inputFormat fields, skipping cleanup')
55 return currentInputMapping
56 }
57
58 const orphanedFields: string[] = []
59 for (const fieldName of Object.keys(currentInputMapping)) {
60 if (!validFieldNames.has(fieldName)) {
61 orphanedFields.push(fieldName)
62 }
63 }
64
65 if (orphanedFields.length === 0) {
66 return currentInputMapping
67 }
68
69 const cleanedMapping: Record<string, any> = {}
70 for (const [fieldName, fieldValue] of Object.entries(currentInputMapping)) {
71 if (validFieldNames.has(fieldName)) {
72 cleanedMapping[fieldName] = fieldValue
73 }
74 }
75
76 logger.info(
77 `Lazy cleanup: Removing ${orphanedFields.length} orphaned field(s) from inputMapping in workflow ${parentWorkflowId}, block ${parentBlockId}: ${orphanedFields.join(', ')}`
78 )
79
80 persistCleanedMapping(parentWorkflowId, parentBlockId, cleanedMapping).catch((error) => {
81 logger.error('Failed to persist cleaned inputMapping:', error)
82 })
83
84 return cleanedMapping
85 } catch (error) {
86 logger.error('Error in lazy cleanup:', error)
87 return currentInputMapping
88 }
89}
90
91/**
92 * Persist the cleaned inputMapping to the database

Callers 1

executeCoreMethod · 0.90

Calls 7

persistCleanedMappingFunction · 0.85
debugMethod · 0.80
infoMethod · 0.80
joinMethod · 0.80
errorMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected