|
1 | 1 | // Add weight property for low coupling dependencies to Typescript module DEPENDS_ON relationships |
2 | 2 |
|
3 | | - MATCH (source:TS:Module)-[moduleDependency:DEPENDS_ON]->(target:ExternalModule) |
4 | 3 | // Get the top level dependency between a Typescript module and the external modules it uses |
5 | | - WITH source |
6 | | - ,target |
7 | | - ,moduleDependency |
8 | | - ,count(DISTINCT target) AS externalModuleCount |
9 | | - ,sum(moduleDependency.cardinality) AS externalModuleCardinalities |
10 | | -OPTIONAL MATCH (source)-[rd:DEPENDS_ON]->(declaration:ExternalDeclaration)<-[:EXPORTS]-(target) |
| 4 | + MATCH (source:TS:Module)-[moduleDependency:DEPENDS_ON]->(target:ExternalModule) |
11 | 5 | // Get optional external (e.g. type) declarations that the external module (target) provides and the source module uses |
| 6 | +OPTIONAL MATCH (source)-[rd:DEPENDS_ON]->(declaration:ExternalDeclaration)<-[:EXPORTS]-(target) |
12 | 7 | WITH source |
13 | 8 | ,target |
14 | 9 | ,moduleDependency |
15 | | - ,externalModuleCount |
16 | | - ,externalModuleCardinalities |
17 | | - ,count(DISTINCT declaration) AS declarationCount |
18 | | - ,sum(rd.cardinality) AS declarationCardinalities |
| 10 | + ,count(DISTINCT rd) AS declarationCount |
| 11 | + ,sum(rd.cardinality) AS declarationCardinalities |
19 | 12 | ,collect(DISTINCT declaration.globalFqn)[0..4] AS declarationExamples |
20 | | -OPTIONAL MATCH (source)-[:DECLARES]->(abstraction:TypeAlias|Interface)-[ra:DEPENDS_ON]->(target) |
21 | 13 | // Get optional low coupling elements (TypeAlias, Interface) that the source module contains and defines (low level) that depend on the external module (target) |
| 14 | +OPTIONAL MATCH (source)-[:DECLARES]->(abstraction:TypeAlias|Interface)-[ra:DEPENDS_ON]->(target) |
22 | 15 | WITH source |
23 | 16 | ,target |
24 | 17 | ,moduleDependency |
25 | | - ,externalModuleCount |
26 | | - ,externalModuleCardinalities |
27 | 18 | ,declarationCount |
28 | 19 | ,declarationCardinalities |
29 | 20 | ,declarationExamples |
30 | | - ,count(DISTINCT abstraction) AS abstractionCount |
31 | | - ,sum(ra.cardinality) AS abstractionCardinalities |
| 21 | + ,count(DISTINCT ra) AS abstractionCount |
| 22 | + ,sum(ra.cardinality) AS abstractionCardinalities |
32 | 23 | ,collect(DISTINCT abstraction.globalFqn)[0..4] AS abstractionExamples |
33 | | -OPTIONAL MATCH (source)-[:DECLARES]->(implementation:!TypeAlias&!Interface)-[ri:DEPENDS_ON]->(target) |
34 | 24 | // Get optional higher coupling elements (Class, Function) that the source module contains and defines (low level) that depend on the external module (target) |
| 25 | +OPTIONAL MATCH (source)-[:DECLARES]->(implementation:!TypeAlias&!Interface)-[ri:DEPENDS_ON]->(target) |
35 | 26 | WITH source |
36 | 27 | ,target |
37 | 28 | ,moduleDependency |
38 | | - ,externalModuleCount |
39 | | - ,externalModuleCardinalities |
40 | 29 | ,declarationCount |
41 | 30 | ,declarationCardinalities |
42 | 31 | ,declarationExamples |
43 | 32 | ,abstractionCount |
44 | 33 | ,abstractionCardinalities |
45 | 34 | ,abstractionExamples |
46 | | - ,count(DISTINCT implementation) AS implementationCount |
47 | | - ,sum(ri.cardinality) AS implementationCardinalities |
| 35 | + ,count(DISTINCT ri) AS implementationCount |
| 36 | + ,sum(ri.cardinality) AS implementationCardinalities |
48 | 37 | ,collect(DISTINCT implementation.globalFqn)[0..4] AS implementationExamples |
49 | 38 | // Set additional fine grained relationship properties (weights) to distinguish low and high coupling elements. |
50 | 39 | // The "cardinality" property is similar to "weight" property for Java dependencies and comes from the jQAssistant Typescript Plugin. |
51 | | -// - "weightLowCouplingElements" is the sum of all TypeAlias, Interface and external declaration cardinalities |
| 40 | +// - "lowCouplingElementWeight" is the sum of all TypeAlias, Interface and external declaration cardinalities |
52 | 41 | // and corresponds to the "weightInterfaces" relationship property for Java. |
53 | | -// - "weight25PercentLowCouplingElements" only takes 25% of the weight for elements that are considered as low coupling |
| 42 | +// - "lowCouplingElement25PercentWeight" only takes 25% of the weight for elements that are considered as low coupling |
54 | 43 | // like Type Declarations and Interfaces and adds the unchanged (100%) weight of "high coupling" elements like Functions and Classes. |
55 | | - SET moduleDependency.weightDeclarations = declarationCardinalities |
56 | | - ,moduleDependency.weightAbstractions = abstractionCardinalities |
57 | | - ,moduleDependency.weightImplementations = implementationCardinalities |
58 | | - ,moduleDependency.weightLowCouplingElements = declarationCardinalities + abstractionCardinalities |
59 | | - ,moduleDependency.weight25PercentLowCouplingElements = toInteger(implementationCardinalities + round((declarationCardinalities + abstractionCardinalities) * 0.25)) |
60 | | - ,moduleDependency.weight10PercentLowCouplingElements = toInteger(implementationCardinalities + round((declarationCardinalities + abstractionCardinalities) * 0.10)) |
| 44 | + SET moduleDependency.declarationCount = declarationCount |
| 45 | + ,moduleDependency.abstractionCount = abstractionCount |
| 46 | + ,moduleDependency.implementationCount = implementationCount |
| 47 | + ,moduleDependency.declarationWeight = declarationCardinalities |
| 48 | + ,moduleDependency.abstractionWeight = abstractionCardinalities |
| 49 | + ,moduleDependency.implementationWeight = implementationCardinalities |
| 50 | + ,moduleDependency.lowCouplingElementWeight = declarationCardinalities + abstractionCardinalities |
| 51 | + ,moduleDependency.lowCouplingElement25PercentWeight = toInteger(implementationCardinalities + round((declarationCardinalities + abstractionCardinalities) * 0.25)) |
| 52 | + ,moduleDependency.lowCouplingElement10PercentWeight = toInteger(implementationCardinalities + round((declarationCardinalities + abstractionCardinalities) * 0.10)) |
61 | 53 | // Aggregate all gathered information for each (grouped by) source module |
62 | 54 | WITH source |
63 | | - ,source.globalFqn AS sourceGlobalName |
64 | | - ,source.localFqn AS sourceLocalName |
65 | | - ,sum(externalModuleCount) AS externalModuleCount |
66 | | - ,sum(declarationCount) AS declarationCount |
67 | | - ,sum(abstractionCount) AS abstractionCount |
68 | | - ,sum(implementationCount) AS implementationCount |
69 | | - ,sum(externalModuleCardinalities) AS externalModuleCardinalities |
70 | | - ,sum(declarationCardinalities) AS declarationCardinalities |
71 | | - ,sum(abstractionCardinalities) AS abstractionCardinalities |
72 | | - ,sum(implementationCardinalities) AS implementationCardinalities |
| 55 | + ,source.globalFqn AS sourceGlobalName |
| 56 | + ,source.localFqn AS sourceLocalName |
| 57 | + ,count(DISTINCT target.globalFqn) AS externalModuleCount |
| 58 | + ,sum(moduleDependency.declarationCount) AS declarationCount |
| 59 | + ,sum(moduleDependency.abstractionCount) AS abstractionCount |
| 60 | + ,sum(moduleDependency.implementationCount) AS implementationCount |
| 61 | + ,sum(moduleDependency.cardinality) AS externalModuleCardinalities |
| 62 | + ,sum(moduleDependency.declarationWeight) AS declarationCardinalities |
| 63 | + ,sum(moduleDependency.abstractionWeight) AS abstractionCardinalities |
| 64 | + ,sum(moduleDependency.implementationWeight) AS implementationCardinalities |
73 | 65 | ,collect(DISTINCT target.globalFqn)[0..4] AS externalModuleExamples |
74 | 66 | ,apoc.coll.flatten(collect(declarationExamples))[0..4] AS declarationExamples |
75 | 67 | ,apoc.coll.flatten(collect(abstractionExamples))[0..4] AS abstractionExamples |
76 | 68 | ,apoc.coll.flatten(collect(implementationExamples))[0..4] AS implementationExamples |
77 | | - SET source.outgoingDependencies = declarationCount + abstractionCount + implementationCount |
78 | | - ,source.outgoingDependenciesWeight = declarationCardinalities + abstractionCardinalities + implementationCardinalities |
79 | | - ,source.outgoingDependentImplementations = implementationCount |
80 | | - ,source.outgoingDependentLowCouplingElements = declarationCount + abstractionCount |
81 | | - ,source.outgoingDependentModules = externalModuleCount |
| 69 | + SET source.outgoingDependencies = declarationCount + abstractionCount + implementationCount |
| 70 | + ,source.outgoingDependenciesWeight = declarationCardinalities + abstractionCardinalities + implementationCardinalities |
| 71 | + ,source.outgoingDependentImplementations = implementationCount |
| 72 | + ,source.outgoingDependentLowCouplingElements = declarationCount + abstractionCount |
| 73 | + ,source.outgoingDependentModules = externalModuleCount |
82 | 74 | RETURN sourceGlobalName |
83 | 75 | ,sourceLocalName |
84 | 76 | ,externalModuleCount |
|
0 commit comments