({
diagram,
newDiagram,
diffMap,
changedRelationships,
relationshipIdMap,
attributes,
changedRelationshipsAttributes,
changeTypes,
relationshipMatcher,
}: {
diagram: Diagram;
newDiagram: Diagram;
diffMap: DiffMap;
changedRelationships: Map<string, boolean>;
relationshipIdMap: Map<string, string>;
attributes?: RelationshipDiffAttribute[];
changedRelationshipsAttributes?: RelationshipDiffAttribute[];
changeTypes?: RelationshipDiff['type'][];
relationshipMatcher: (
relationship: DBRelationship,
relationships: DBRelationship[]
) => DBRelationship | undefined;
})
| 1316 | |
| 1317 | // Compare relationships between diagrams |
| 1318 | function compareRelationships({ |
| 1319 | diagram, |
| 1320 | newDiagram, |
| 1321 | diffMap, |
| 1322 | changedRelationships, |
| 1323 | relationshipIdMap, |
| 1324 | attributes, |
| 1325 | changedRelationshipsAttributes, |
| 1326 | changeTypes, |
| 1327 | relationshipMatcher, |
| 1328 | }: { |
| 1329 | diagram: Diagram; |
| 1330 | newDiagram: Diagram; |
| 1331 | diffMap: DiffMap; |
| 1332 | changedRelationships: Map<string, boolean>; |
| 1333 | relationshipIdMap: Map<string, string>; |
| 1334 | attributes?: RelationshipDiffAttribute[]; |
| 1335 | changedRelationshipsAttributes?: RelationshipDiffAttribute[]; |
| 1336 | changeTypes?: RelationshipDiff['type'][]; |
| 1337 | relationshipMatcher: ( |
| 1338 | relationship: DBRelationship, |
| 1339 | relationships: DBRelationship[] |
| 1340 | ) => DBRelationship | undefined; |
| 1341 | }) { |
| 1342 | // If changeTypes is empty array, don't check any changes |
| 1343 | if (changeTypes && changeTypes.length === 0) { |
| 1344 | return; |
| 1345 | } |
| 1346 | |
| 1347 | // If changeTypes is undefined, check all types |
| 1348 | const typesToCheck = changeTypes ?? ['added', 'removed', 'changed']; |
| 1349 | const oldRelationships = diagram.relationships || []; |
| 1350 | const newRelationships = newDiagram.relationships || []; |
| 1351 | |
| 1352 | // Check for added relationships |
| 1353 | if (typesToCheck.includes('added')) { |
| 1354 | for (const newRelationship of newRelationships) { |
| 1355 | if (!relationshipMatcher(newRelationship, oldRelationships)) { |
| 1356 | diffMap.set( |
| 1357 | getDiffMapKey({ |
| 1358 | diffObject: 'relationship', |
| 1359 | objectId: newRelationship.id, |
| 1360 | }), |
| 1361 | { |
| 1362 | object: 'relationship', |
| 1363 | type: 'added', |
| 1364 | newRelationship, |
| 1365 | } |
| 1366 | ); |
| 1367 | changedRelationships.set(newRelationship.id, true); |
| 1368 | } |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | // Check for removed relationships |
| 1373 | if (typesToCheck.includes('removed')) { |
| 1374 | for (const oldRelationship of oldRelationships) { |
| 1375 | if (!relationshipMatcher(oldRelationship, newRelationships)) { |
no test coverage detected