* Persist the cleaned inputMapping to the database * * @param workflowId - The workflow ID * @param blockId - The block ID * @param cleanedMapping - The cleaned inputMapping value
( workflowId: string, blockId: string, cleanedMapping: Record<string, any> )
| 96 | * @param cleanedMapping - The cleaned inputMapping value |
| 97 | */ |
| 98 | async function persistCleanedMapping( |
| 99 | workflowId: string, |
| 100 | blockId: string, |
| 101 | cleanedMapping: Record<string, any> |
| 102 | ): Promise<void> { |
| 103 | try { |
| 104 | await db.transaction(async (tx) => { |
| 105 | const [block] = await tx |
| 106 | .select({ subBlocks: workflowBlocks.subBlocks }) |
| 107 | .from(workflowBlocks) |
| 108 | .where(and(eq(workflowBlocks.id, blockId), eq(workflowBlocks.workflowId, workflowId))) |
| 109 | .limit(1) |
| 110 | |
| 111 | if (!block) { |
| 112 | logger.warn(`Block ${blockId} not found in workflow ${workflowId}, skipping persistence`) |
| 113 | return |
| 114 | } |
| 115 | |
| 116 | const subBlocks = (block.subBlocks as Record<string, any>) || {} |
| 117 | |
| 118 | if (subBlocks.inputMapping) { |
| 119 | subBlocks.inputMapping = { |
| 120 | ...subBlocks.inputMapping, |
| 121 | value: cleanedMapping, |
| 122 | } |
| 123 | |
| 124 | // Persist updated subBlocks |
| 125 | await tx |
| 126 | .update(workflowBlocks) |
| 127 | .set({ |
| 128 | subBlocks: subBlocks, |
| 129 | updatedAt: new Date(), |
| 130 | }) |
| 131 | .where(and(eq(workflowBlocks.id, blockId), eq(workflowBlocks.workflowId, workflowId))) |
| 132 | |
| 133 | logger.info(`Successfully persisted cleaned inputMapping for block ${blockId}`) |
| 134 | } |
| 135 | }) |
| 136 | } catch (error) { |
| 137 | logger.error('Error persisting cleaned mapping:', error) |
| 138 | throw error |
| 139 | } |
| 140 | } |