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

Function handleEdgesOperationTx

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

Source from the content-addressed store, hash-verified

1406}
1407
1408async function handleEdgesOperationTx(
1409 tx: any,
1410 workflowId: string,
1411 operation: string,
1412 payload: any
1413) {
1414 switch (operation) {
1415 case EDGES_OPERATIONS.BATCH_REMOVE_EDGES: {
1416 const { ids } = payload
1417 if (!Array.isArray(ids) || ids.length === 0) {
1418 logger.debug('No edge IDs provided for batch remove')
1419 return
1420 }
1421
1422 logger.info(`Batch removing ${ids.length} edges from workflow ${workflowId}`)
1423
1424 // Get edges to check connected blocks
1425 const edgesToRemove = await tx
1426 .select({
1427 id: workflowEdges.id,
1428 sourceBlockId: workflowEdges.sourceBlockId,
1429 targetBlockId: workflowEdges.targetBlockId,
1430 })
1431 .from(workflowEdges)
1432 .where(and(eq(workflowEdges.workflowId, workflowId), inArray(workflowEdges.id, ids)))
1433
1434 if (edgesToRemove.length === 0) {
1435 logger.debug('No edges found to remove')
1436 return
1437 }
1438
1439 type EdgeToRemove = (typeof edgesToRemove)[number]
1440
1441 // Get all connected block IDs
1442 const connectedBlockIds = new Set<string>()
1443 edgesToRemove.forEach((e: EdgeToRemove) => {
1444 connectedBlockIds.add(e.sourceBlockId)
1445 connectedBlockIds.add(e.targetBlockId)
1446 })
1447
1448 // Fetch blocks to check lock status
1449 const connectedBlocks = await tx
1450 .select({
1451 id: workflowBlocks.id,
1452 locked: workflowBlocks.locked,
1453 data: workflowBlocks.data,
1454 })
1455 .from(workflowBlocks)
1456 .where(
1457 and(
1458 eq(workflowBlocks.workflowId, workflowId),
1459 inArray(workflowBlocks.id, Array.from(connectedBlockIds))
1460 )
1461 )
1462
1463 type EdgeBlockRecord = (typeof connectedBlocks)[number]
1464 const blocksById: Record<string, EdgeBlockRecord> = Object.fromEntries(
1465 connectedBlocks.map((b: EdgeBlockRecord) => [b.id, b])

Callers 1

persistWorkflowOperationFunction · 0.85

Calls 7

isWorkflowBlockProtectedFunction · 0.90
debugMethod · 0.80
infoMethod · 0.80
deleteMethod · 0.65
warnMethod · 0.65
eqFunction · 0.50
addMethod · 0.45

Tested by

no test coverage detected