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

Function handleWorkflowOperationTx

apps/realtime/src/database/operations.ts:1917–2012  ·  view source on GitHub ↗
(
  tx: any,
  workflowId: string,
  operation: string,
  payload: any
)

Source from the content-addressed store, hash-verified

1915
1916// Workflow operations - handles complete state replacement
1917async function handleWorkflowOperationTx(
1918 tx: any,
1919 workflowId: string,
1920 operation: string,
1921 payload: any
1922) {
1923 switch (operation) {
1924 case WORKFLOW_OPERATIONS.REPLACE_STATE: {
1925 if (!payload.state) {
1926 throw new Error('Missing state for replace-state operation')
1927 }
1928
1929 const { blocks, edges, loops, parallels } = payload.state
1930
1931 logger.info(`Replacing workflow state for ${workflowId}`, {
1932 blockCount: Object.keys(blocks || {}).length,
1933 edgeCount: (edges || []).length,
1934 loopCount: Object.keys(loops || {}).length,
1935 parallelCount: Object.keys(parallels || {}).length,
1936 })
1937
1938 await tx.delete(workflowBlocks).where(eq(workflowBlocks.workflowId, workflowId))
1939
1940 // Delete all existing subflows
1941 await tx.delete(workflowSubflows).where(eq(workflowSubflows.workflowId, workflowId))
1942
1943 // Insert all blocks from the new state
1944 if (blocks && Object.keys(blocks).length > 0) {
1945 const blockValues = Object.values(blocks).map((block: any) => ({
1946 id: block.id,
1947 workflowId,
1948 type: block.type,
1949 name: block.name,
1950 positionX: block.position.x,
1951 positionY: block.position.y,
1952 data: block.data || {},
1953 subBlocks: block.subBlocks || {},
1954 outputs: block.outputs || {},
1955 enabled: block.enabled ?? true,
1956 horizontalHandles: block.horizontalHandles ?? true,
1957 advancedMode: block.advancedMode ?? false,
1958 triggerMode: block.triggerMode ?? false,
1959 height: block.height || 0,
1960 locked: block.locked ?? false,
1961 }))
1962
1963 await tx.insert(workflowBlocks).values(blockValues)
1964 }
1965
1966 // Insert all edges from the new state
1967 if (edges && edges.length > 0) {
1968 const edgeValues = edges.map((edge: any) => ({
1969 id: edge.id,
1970 workflowId,
1971 sourceBlockId: edge.source,
1972 targetBlockId: edge.target,
1973 sourceHandle: edge.sourceHandle || null,
1974 targetHandle: edge.targetHandle || null,

Callers 1

persistWorkflowOperationFunction · 0.85

Calls 4

infoMethod · 0.80
deleteMethod · 0.65
warnMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected