MCPcopy
hub / github.com/chartdb/chartdb / compareAreas

Function compareAreas

src/lib/domain/diff/diff-check/diff-check.ts:1575–1803  ·  view source on GitHub ↗
({
    diagram,
    newDiagram,
    diffMap,
    changedAreas,
    attributes,
    changedAreasAttributes,
    changeTypes,
    areaMatcher,
}: {
    diagram: Diagram;
    newDiagram: Diagram;
    diffMap: DiffMap;
    changedAreas: Map<string, boolean>;
    attributes?: AreaDiffAttribute[];
    changedAreasAttributes?: AreaDiffAttribute[];
    changeTypes?: AreaDiff['type'][];
    areaMatcher: (area: Area, areas: Area[]) => Area | undefined;
})

Source from the content-addressed store, hash-verified

1573
1574// Compare areas between diagrams
1575function compareAreas({
1576 diagram,
1577 newDiagram,
1578 diffMap,
1579 changedAreas,
1580 attributes,
1581 changedAreasAttributes,
1582 changeTypes,
1583 areaMatcher,
1584}: {
1585 diagram: Diagram;
1586 newDiagram: Diagram;
1587 diffMap: DiffMap;
1588 changedAreas: Map<string, boolean>;
1589 attributes?: AreaDiffAttribute[];
1590 changedAreasAttributes?: AreaDiffAttribute[];
1591 changeTypes?: AreaDiff['type'][];
1592 areaMatcher: (area: Area, areas: Area[]) => Area | undefined;
1593}) {
1594 const oldAreas = diagram.areas || [];
1595 const newAreas = newDiagram.areas || [];
1596
1597 // If changeTypes is empty array, don't check any changes
1598 if (changeTypes && changeTypes.length === 0) {
1599 return;
1600 }
1601
1602 // If changeTypes is undefined, check all types
1603 const typesToCheck = changeTypes ?? ['added', 'removed', 'changed'];
1604
1605 // Check for added areas
1606 if (typesToCheck.includes('added')) {
1607 for (const newArea of newAreas) {
1608 if (!areaMatcher(newArea, oldAreas)) {
1609 diffMap.set(
1610 getDiffMapKey({
1611 diffObject: 'area',
1612 objectId: newArea.id,
1613 }),
1614 {
1615 object: 'area',
1616 type: 'added',
1617 areaAdded: newArea,
1618 }
1619 );
1620 changedAreas.set(newArea.id, true);
1621 }
1622 }
1623 }
1624
1625 // Check for removed areas
1626 if (typesToCheck.includes('removed')) {
1627 for (const oldArea of oldAreas) {
1628 if (!areaMatcher(oldArea, newAreas)) {
1629 diffMap.set(
1630 getDiffMapKey({
1631 diffObject: 'area',
1632 objectId: oldArea.id,

Callers 1

generateDiffFunction · 0.85

Calls 2

getDiffMapKeyFunction · 0.85
shouldAddToChangedMapFunction · 0.85

Tested by

no test coverage detected