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

Function handleEdgeOperationTx

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

Source from the content-addressed store, hash-verified

1243}
1244
1245async function handleEdgeOperationTx(tx: any, workflowId: string, operation: string, payload: any) {
1246 switch (operation) {
1247 case EDGE_OPERATIONS.ADD: {
1248 if (!payload.id || !payload.source || !payload.target) {
1249 throw new Error('Missing required fields for add edge operation')
1250 }
1251
1252 const edgeBlocks = await tx
1253 .select({
1254 id: workflowBlocks.id,
1255 locked: workflowBlocks.locked,
1256 data: workflowBlocks.data,
1257 })
1258 .from(workflowBlocks)
1259 .where(
1260 and(
1261 eq(workflowBlocks.workflowId, workflowId),
1262 inArray(workflowBlocks.id, [payload.source, payload.target])
1263 )
1264 )
1265
1266 type EdgeBlockRecord = (typeof edgeBlocks)[number]
1267 const blocksById: Record<string, EdgeBlockRecord> = Object.fromEntries(
1268 edgeBlocks.map((b: EdgeBlockRecord) => [b.id, b])
1269 )
1270
1271 const parentIds = new Set<string>()
1272 for (const block of edgeBlocks) {
1273 const parentId = (block.data as Record<string, unknown> | null)?.parentId as
1274 | string
1275 | undefined
1276 if (parentId && !blocksById[parentId]) {
1277 parentIds.add(parentId)
1278 }
1279 }
1280
1281 // Fetch parent blocks if needed
1282 if (parentIds.size > 0) {
1283 const parentBlocks = await tx
1284 .select({
1285 id: workflowBlocks.id,
1286 locked: workflowBlocks.locked,
1287 data: workflowBlocks.data,
1288 })
1289 .from(workflowBlocks)
1290 .where(
1291 and(
1292 eq(workflowBlocks.workflowId, workflowId),
1293 inArray(workflowBlocks.id, Array.from(parentIds))
1294 )
1295 )
1296 for (const b of parentBlocks) {
1297 blocksById[b.id] = b
1298 }
1299 }
1300
1301 if (isWorkflowBlockProtected(payload.target, blocksById)) {
1302 logger.info(`Skipping edge add - target block is protected`)

Callers 1

persistWorkflowOperationFunction · 0.85

Calls 7

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

Tested by

no test coverage detected