@likec4/core 1.41.0 → 1.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder/package.json +4 -0
- package/compute-view/package.json +4 -0
- package/compute-view/relationships/package.json +4 -0
- package/dist/builder/index.d.mts +13 -11
- package/dist/builder/index.mjs +111 -91
- package/dist/compute-view/index.d.mts +8 -7
- package/dist/compute-view/index.mjs +14 -11
- package/dist/compute-view/relationships-view/index.d.mts +9 -8
- package/dist/compute-view/relationships-view/index.mjs +6 -6
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +11 -11
- package/dist/model/connection/deployment/index.d.mts +11 -10
- package/dist/model/connection/deployment/index.mjs +2 -2
- package/dist/model/connection/index.d.mts +12 -11
- package/dist/model/connection/index.mjs +3 -3
- package/dist/model/connection/model/index.d.mts +11 -10
- package/dist/model/connection/model/index.mjs +2 -2
- package/dist/model/index.d.mts +14 -14
- package/dist/model/index.mjs +4 -5
- package/dist/shared/{core.Ae86Y3tB.mjs → core.01VTr9qu.mjs} +8 -26
- package/dist/shared/core.1vX5a9AY.mjs +86 -0
- package/dist/shared/{core.BVNaR17u.mjs → core.B7KhhkRY.mjs} +1 -1
- package/dist/shared/core.B85MJLTf.mjs +5 -0
- package/dist/shared/{core.DA5vzwZ9.mjs → core.BIqHjQiH.mjs} +56 -42
- package/dist/shared/core.BKlholso.mjs +3 -0
- package/dist/shared/core.BR4zXDH-.mjs +13 -0
- package/dist/shared/{core.CXy1NLUG.mjs → core.BYNkXQ8A.mjs} +21 -12
- package/dist/shared/{core.BuoXfSMj.mjs → core.BbE4y-yl.mjs} +1 -1
- package/dist/shared/core.BoYfZOBm.mjs +3 -0
- package/dist/shared/core.BsSXS-_R.mjs +7 -0
- package/dist/shared/{core.DJp8fgok.mjs → core.BzTakU3I.mjs} +14 -10
- package/dist/shared/{core.4u1dVmfX.mjs → core.C2TiyjI6.mjs} +2 -2
- package/dist/shared/{core.DLpidoWc.mjs → core.C3JowhaZ.mjs} +3 -3
- package/dist/shared/{core.CNGyqkJh.mjs → core.C4x8aaWa.mjs} +3 -1
- package/dist/shared/{core.BB6zA-UU.mjs → core.C8YY6Uub.mjs} +38 -9
- package/dist/shared/{core.Asc11Mjy.mjs → core.C8sl5Y8Z.mjs} +122 -58
- package/dist/shared/{core.BvMRMo7Z.mjs → core.CNgZvKb8.mjs} +3 -5198
- package/dist/shared/{core.CUG6vpyL.d.mts → core.CQngdcuj.d.mts} +85 -4
- package/dist/shared/{core.Be1n9a0i.mjs → core.C_Ni6yHl.mjs} +5 -4
- package/dist/shared/core.CbT8JVYL.mjs +5 -0
- package/dist/shared/core.CqAJJpK_.mjs +3 -0
- package/dist/shared/{core.BXsxn-hf.d.mts → core.D0PjZzIS.d.mts} +27 -15
- package/dist/shared/{core.DgesAwC8.d.mts → core.D5fzJWbF.d.mts} +2 -2
- package/dist/shared/{core.hfOE3RfK.d.mts → core.DACpKp35.d.mts} +5 -5
- package/dist/shared/core.DFi2dOTl.mjs +39548 -0
- package/dist/shared/{core.xSQO0XYD.d.mts → core.DIol3syK.d.mts} +2 -2
- package/dist/shared/{core.DlG1xWt2.mjs → core.DMMOWQqc.mjs} +3 -2
- package/dist/shared/core.DNbUPnve.mjs +3990 -0
- package/dist/shared/{core.CCD1ID81.mjs → core.DRJma0Ol.mjs} +4 -3
- package/dist/shared/{core.DgttqsJc.mjs → core.DRhg-gVU.mjs} +9 -9
- package/dist/shared/core.DSO_rTC2.mjs +5322 -0
- package/dist/shared/{core.FUPplpae.d.mts → core.D_vkffV4.d.mts} +4 -2
- package/dist/shared/core.DdMJk7nx.d.mts +476 -0
- package/dist/shared/{core.BhpgpOep.d.mts → core.Dgs6-nuz.d.mts} +2 -2
- package/dist/shared/{core.Be4Jy9Qx.mjs → core.FZ305VYd.mjs} +2 -2
- package/dist/shared/core.OHD4KXm9.mjs +5 -0
- package/dist/shared/{core.GTgsmXS_.mjs → core.QJD_fcrc.mjs} +2 -2
- package/dist/shared/core.RfnaEmgA.mjs +7 -0
- package/dist/shared/core.fHR_8Tnq.d.mts +450 -0
- package/dist/shared/{core.D0EgVMQK.mjs → core.lRvxPoao.mjs} +14 -12
- package/dist/shared/{core.CaT0SUUK.mjs → core.rCeaAqgW.mjs} +1 -84
- package/dist/shared/{core.zxTBF_PD.d.mts → core.s9uwOt60.d.mts} +4 -4
- package/dist/shared/core.yna0OdV5.d.mts +98 -0
- package/dist/styles/index.d.mts +106 -0
- package/dist/styles/index.mjs +1 -0
- package/dist/types/_aux.d.mts +2 -2
- package/dist/types/expression-model.d.mts +3 -4
- package/dist/types/expression.d.mts +3 -4
- package/dist/types/fqnRef.d.mts +2 -2
- package/dist/types/fqnRef.mjs +3 -3
- package/dist/types/index.d.mts +8 -8
- package/dist/types/index.mjs +150 -5
- package/dist/types/scalar.mjs +3 -2
- package/dist/utils/graphology/index.d.mts +1864 -0
- package/dist/utils/graphology/index.mjs +1 -0
- package/dist/utils/index.d.mts +11 -6
- package/dist/utils/index.mjs +21 -37
- package/dist/utils/iterable/index.d.mts +1 -1
- package/dist/utils/iterable/index.mjs +45 -7
- package/model/package.json +4 -0
- package/package.json +42 -24
- package/styles/package.json +4 -0
- package/types/package.json +4 -0
- package/utils/graphology/package.json +4 -0
- package/utils/package.json +4 -0
- package/dist/shared/core.6_Vp2iiN.mjs +0 -172
- package/dist/shared/core.CUw_2J9j.mjs +0 -47
- package/dist/shared/core.CzdwsPmY.d.mts +0 -69
- package/dist/shared/core.D-ZGWDDt.d.mts +0 -831
- package/dist/shared/core.DoM6aM9N.mjs +0 -7
- package/dist/shared/core.ILwny7BV.mjs +0 -38
- package/dist/theme/index.d.mts +0 -11
- package/dist/theme/index.mjs +0 -232
- package/src/builder/Builder.deployment.ts +0 -224
- package/src/builder/Builder.deploymentModel.ts +0 -449
- package/src/builder/Builder.element.ts +0 -241
- package/src/builder/Builder.model.ts +0 -494
- package/src/builder/Builder.ts +0 -946
- package/src/builder/Builder.view-common.ts +0 -273
- package/src/builder/Builder.view-deployment.ts +0 -135
- package/src/builder/Builder.view-element.ts +0 -202
- package/src/builder/Builder.views.ts +0 -399
- package/src/builder/Builder.with.ts +0 -156
- package/src/builder/_types.ts +0 -324
- package/src/builder/index.ts +0 -11
- package/src/compute-view/compute-view.ts +0 -80
- package/src/compute-view/deployment-view/_types.ts +0 -38
- package/src/compute-view/deployment-view/clean-connections.ts +0 -236
- package/src/compute-view/deployment-view/compute.ts +0 -94
- package/src/compute-view/deployment-view/memory/index.ts +0 -9
- package/src/compute-view/deployment-view/memory/memory.ts +0 -96
- package/src/compute-view/deployment-view/predicates/deploymentRefs-where.ts +0 -18
- package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +0 -154
- package/src/compute-view/deployment-view/predicates/index.ts +0 -8
- package/src/compute-view/deployment-view/predicates/relation-direct.ts +0 -243
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +0 -70
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +0 -101
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +0 -95
- package/src/compute-view/deployment-view/predicates/relation-where.ts +0 -18
- package/src/compute-view/deployment-view/predicates/utils.ts +0 -282
- package/src/compute-view/deployment-view/predicates/wildcard.ts +0 -41
- package/src/compute-view/deployment-view/stages/stage-exclude.ts +0 -5
- package/src/compute-view/deployment-view/stages/stage-final.ts +0 -245
- package/src/compute-view/deployment-view/stages/stage-include.ts +0 -95
- package/src/compute-view/deployment-view/utils.ts +0 -297
- package/src/compute-view/dynamic-view/compute.ts +0 -312
- package/src/compute-view/element-view/_types.ts +0 -47
- package/src/compute-view/element-view/clean-connections.ts +0 -117
- package/src/compute-view/element-view/compute.ts +0 -324
- package/src/compute-view/element-view/memory/NodeGroup.ts +0 -31
- package/src/compute-view/element-view/memory/index.ts +0 -10
- package/src/compute-view/element-view/memory/memory.ts +0 -178
- package/src/compute-view/element-view/memory/stage-exclude.ts +0 -59
- package/src/compute-view/element-view/memory/stage-final.ts +0 -129
- package/src/compute-view/element-view/memory/stage-include.ts +0 -130
- package/src/compute-view/element-view/predicates/_utils.ts +0 -91
- package/src/compute-view/element-view/predicates/element-expand.ts +0 -29
- package/src/compute-view/element-view/predicates/element-kind-tag.ts +0 -27
- package/src/compute-view/element-view/predicates/element-ref.ts +0 -24
- package/src/compute-view/element-view/predicates/relation-direct.ts +0 -321
- package/src/compute-view/element-view/predicates/relation-in-out.ts +0 -64
- package/src/compute-view/element-view/predicates/relation-in.ts +0 -115
- package/src/compute-view/element-view/predicates/relation-out.ts +0 -119
- package/src/compute-view/element-view/predicates/wildcard.ts +0 -88
- package/src/compute-view/element-view/utils.ts +0 -65
- package/src/compute-view/index.ts +0 -4
- package/src/compute-view/memory/AbstractMemory.ts +0 -45
- package/src/compute-view/memory/AbstractStageExclude.ts +0 -215
- package/src/compute-view/memory/AbstractStageInclude.ts +0 -200
- package/src/compute-view/memory/_types.ts +0 -148
- package/src/compute-view/memory/index.ts +0 -5
- package/src/compute-view/memory/ops.ts +0 -43
- package/src/compute-view/relationships-view/_types.ts +0 -16
- package/src/compute-view/relationships-view/compute.ts +0 -159
- package/src/compute-view/relationships-view/index.ts +0 -3
- package/src/compute-view/relationships-view/layout.ts +0 -358
- package/src/compute-view/relationships-view/utils.ts +0 -73
- package/src/compute-view/utils/ancestorsOfNode.ts +0 -19
- package/src/compute-view/utils/applyCustomElementProperties.ts +0 -107
- package/src/compute-view/utils/applyCustomRelationProperties.ts +0 -58
- package/src/compute-view/utils/applyViewRuleStyles.ts +0 -73
- package/src/compute-view/utils/buildComputedNodes.ts +0 -166
- package/src/compute-view/utils/buildElementNotations.ts +0 -64
- package/src/compute-view/utils/elementExpressionToPredicate.ts +0 -50
- package/src/compute-view/utils/link-nodes-with-edges.ts +0 -56
- package/src/compute-view/utils/merge-props-from-relationships.ts +0 -161
- package/src/compute-view/utils/relationExpressionToPredicates.ts +0 -55
- package/src/compute-view/utils/resolve-extended-views.ts +0 -85
- package/src/compute-view/utils/resolve-global-rules.ts +0 -88
- package/src/compute-view/utils/topological-sort.ts +0 -256
- package/src/compute-view/utils/view-hash.ts +0 -45
- package/src/compute-view/utils/with-readable-edges.ts +0 -40
- package/src/index.ts +0 -32
- package/src/model/DeploymentElementModel.ts +0 -712
- package/src/model/DeploymentModel.ts +0 -393
- package/src/model/ElementModel.ts +0 -316
- package/src/model/LikeC4Model.ts +0 -882
- package/src/model/RelationModel.ts +0 -152
- package/src/model/connection/Connection.ts +0 -72
- package/src/model/connection/deployment/DeploymentConnectionModel.ts +0 -185
- package/src/model/connection/deployment/find.ts +0 -120
- package/src/model/connection/deployment/index.ts +0 -8
- package/src/model/connection/index.ts +0 -22
- package/src/model/connection/model/ConnectionModel.ts +0 -158
- package/src/model/connection/model/find.ts +0 -117
- package/src/model/connection/model/index.ts +0 -8
- package/src/model/connection/ops.ts +0 -276
- package/src/model/guards.ts +0 -77
- package/src/model/index.ts +0 -72
- package/src/model/types.ts +0 -67
- package/src/model/utils.ts +0 -66
- package/src/model/view/EdgeModel.ts +0 -121
- package/src/model/view/LikeC4ViewModel.ts +0 -361
- package/src/model/view/LikeC4ViewsFolder.ts +0 -151
- package/src/model/view/NodeModel.ts +0 -247
- package/src/theme/element.ts +0 -61
- package/src/theme/index.ts +0 -127
- package/src/theme/relationships.ts +0 -54
- package/src/types/RichText.ts +0 -205
- package/src/types/_aux.ts +0 -317
- package/src/types/_common.ts +0 -102
- package/src/types/const.ts +0 -34
- package/src/types/expression-model.ts +0 -294
- package/src/types/expression.ts +0 -313
- package/src/types/fqnRef.ts +0 -91
- package/src/types/geometry.ts +0 -159
- package/src/types/global.ts +0 -21
- package/src/types/index.ts +0 -44
- package/src/types/model-data.ts +0 -77
- package/src/types/model-deployment.ts +0 -78
- package/src/types/model-dump.ts +0 -79
- package/src/types/model-logical.ts +0 -126
- package/src/types/model-spec.ts +0 -88
- package/src/types/operators.ts +0 -156
- package/src/types/project.ts +0 -14
- package/src/types/scalar.ts +0 -162
- package/src/types/styles.ts +0 -122
- package/src/types/view-changes.ts +0 -32
- package/src/types/view-common.ts +0 -157
- package/src/types/view-computed.ts +0 -126
- package/src/types/view-layouted.ts +0 -94
- package/src/types/view-parsed.deployment.ts +0 -39
- package/src/types/view-parsed.dynamic.ts +0 -89
- package/src/types/view-parsed.element.ts +0 -65
- package/src/types/view.ts +0 -113
- package/src/utils/common-head.ts +0 -22
- package/src/utils/compare-natural.ts +0 -60
- package/src/utils/const.ts +0 -1
- package/src/utils/fqn.ts +0 -302
- package/src/utils/getOrCreate.ts +0 -8
- package/src/utils/guards.ts +0 -9
- package/src/utils/index.ts +0 -68
- package/src/utils/invariant.ts +0 -29
- package/src/utils/iterable/_types.ts +0 -5
- package/src/utils/iterable/filter.ts +0 -55
- package/src/utils/iterable/find.ts +0 -38
- package/src/utils/iterable/first.ts +0 -48
- package/src/utils/iterable/flat.ts +0 -17
- package/src/utils/iterable/head.ts +0 -22
- package/src/utils/iterable/index.ts +0 -15
- package/src/utils/iterable/map.ts +0 -40
- package/src/utils/iterable/reduce.ts +0 -24
- package/src/utils/iterable/some.ts +0 -36
- package/src/utils/iterable/to.ts +0 -19
- package/src/utils/iterable/unique.ts +0 -23
- package/src/utils/markdown/index.ts +0 -2
- package/src/utils/markdown/to-html.ts +0 -32
- package/src/utils/markdown/to-text.ts +0 -14
- package/src/utils/memoize-prop.ts +0 -30
- package/src/utils/mnemonist.ts +0 -9
- package/src/utils/object-hash.ts +0 -14
- package/src/utils/promises.ts +0 -24
- package/src/utils/relations.ts +0 -36
- package/src/utils/set.ts +0 -83
- package/src/utils/string-hash.ts +0 -16
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { forEach, only, pipe } from 'remeda'
|
|
2
|
-
import { differenceConnections } from '../../../model'
|
|
3
|
-
import type { RelationshipModel } from '../../../model'
|
|
4
|
-
import { isAncestor, sortByFqnHierarchically } from '../../../utils/fqn'
|
|
5
|
-
import { ifilter, isome, toArray } from '../../../utils/iterable'
|
|
6
|
-
import { DefaultMap } from '../../../utils/mnemonist'
|
|
7
|
-
import { difference, union } from '../../../utils/set'
|
|
8
|
-
import { treeFromMemoryState } from '../../memory'
|
|
9
|
-
import { cleanCrossBoundary, cleanRedundantRelationships } from '../clean-connections'
|
|
10
|
-
import type { Ctx, Memory } from '../memory'
|
|
11
|
-
|
|
12
|
-
type Elem = Ctx['Element']
|
|
13
|
-
/**
|
|
14
|
-
* This patch:
|
|
15
|
-
* 1. Keeps connections between leafs or having direct deployment relations
|
|
16
|
-
* 2. Removes cross-boundary model relations, that already exist inside boundaries
|
|
17
|
-
* (e.g. prefer relations inside same deployment node over relations between nodes)
|
|
18
|
-
* 3. Removes implicit connections between elements, if their descendants have same connection
|
|
19
|
-
*/
|
|
20
|
-
export class StageFinal {
|
|
21
|
-
static for(memory: Memory) {
|
|
22
|
-
return new StageFinal(memory)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private constructor(
|
|
26
|
-
protected readonly memory: Memory,
|
|
27
|
-
) {
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public step1CleanConnections(memory: Memory): Memory {
|
|
31
|
-
if (memory.connections.length < 2) {
|
|
32
|
-
return memory
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// const leafs = new Set<Elem>()
|
|
36
|
-
|
|
37
|
-
// for (const element of memory.final) {
|
|
38
|
-
// // Instance is always leaf
|
|
39
|
-
// if (element.isInstance()) {
|
|
40
|
-
// leafs.add(element)
|
|
41
|
-
// continue
|
|
42
|
-
// }
|
|
43
|
-
// // Check if element is ancestor of any element in elements
|
|
44
|
-
// let isLeaf = true
|
|
45
|
-
// for (const el of memory.final) {
|
|
46
|
-
// if (isAncestor(element.id, el.id)) {
|
|
47
|
-
// isLeaf = false
|
|
48
|
-
// break
|
|
49
|
-
// }
|
|
50
|
-
// }
|
|
51
|
-
// if (isLeaf) {
|
|
52
|
-
// leafs.add(element)
|
|
53
|
-
// }
|
|
54
|
-
// }
|
|
55
|
-
|
|
56
|
-
const connections = pipe(
|
|
57
|
-
memory.connections,
|
|
58
|
-
// Keep connections
|
|
59
|
-
// - between leafs
|
|
60
|
-
// - has direct deployment relation
|
|
61
|
-
// filter(c => {
|
|
62
|
-
// return (leafs.has(c.source) && leafs.has(c.target)) || c.hasDirectDeploymentRelation()
|
|
63
|
-
// }),
|
|
64
|
-
cleanCrossBoundary,
|
|
65
|
-
cleanRedundantRelationships,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
const connectionsToExclude = differenceConnections(
|
|
69
|
-
memory.connections,
|
|
70
|
-
connections,
|
|
71
|
-
)
|
|
72
|
-
if (connectionsToExclude.length === 0) {
|
|
73
|
-
return memory
|
|
74
|
-
}
|
|
75
|
-
const stage = memory.stageExclude({} as any)
|
|
76
|
-
stage.excludeConnections(connectionsToExclude, true)
|
|
77
|
-
return stage.commit()
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public step2ProcessImplicits(memory: Memory): Memory {
|
|
81
|
-
const implicits = union(this.memory.elements, memory.elements)
|
|
82
|
-
const final = union(memory.final, this.memory.explicits)
|
|
83
|
-
|
|
84
|
-
// Find connections based on same relation but different boundaries
|
|
85
|
-
const groupedByRelation = new DefaultMap<RelationshipModel, Set<Elem>>(() => new Set())
|
|
86
|
-
for (const conn of memory.connections) {
|
|
87
|
-
if (conn.boundary) {
|
|
88
|
-
for (const relation of conn.relations.model) {
|
|
89
|
-
groupedByRelation.get(relation).add(conn.boundary)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
for (const [_, boundaries] of groupedByRelation) {
|
|
94
|
-
if (boundaries.size < 2) {
|
|
95
|
-
continue
|
|
96
|
-
}
|
|
97
|
-
for (const boundary of boundaries) {
|
|
98
|
-
if (implicits.delete(boundary)) {
|
|
99
|
-
final.add(boundary)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const snapshot = new Set(final)
|
|
105
|
-
const isFinalOrHasIncludedDescendant = (el: Elem) => {
|
|
106
|
-
for (const final of snapshot) {
|
|
107
|
-
if (el === final || isAncestor(el, final)) {
|
|
108
|
-
return true
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return false
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Pick from implicit elements
|
|
115
|
-
pipe(
|
|
116
|
-
difference(implicits, snapshot),
|
|
117
|
-
ifilter(e => e.isDeploymentNode()),
|
|
118
|
-
toArray(),
|
|
119
|
-
sortByFqnHierarchically,
|
|
120
|
-
forEach((el) => {
|
|
121
|
-
// If element has more 2 or more children included
|
|
122
|
-
// It can "box" around
|
|
123
|
-
const childrensToWrap = [...el.children()].filter(isFinalOrHasIncludedDescendant).length
|
|
124
|
-
if (childrensToWrap >= 2) {
|
|
125
|
-
final.add(el)
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
// If Element has only one child included
|
|
129
|
-
// and has "similar" sibling with included descendant
|
|
130
|
-
if (childrensToWrap === 1 && isome(el.siblings(), isFinalOrHasIncludedDescendant)) {
|
|
131
|
-
final.add(el)
|
|
132
|
-
}
|
|
133
|
-
}),
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
return memory.update({ final })
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
public step3ProcessBoundaries(memory: Memory): Memory {
|
|
140
|
-
const boundaries = new Set<Elem>()
|
|
141
|
-
for (const conn of memory.connections) {
|
|
142
|
-
if (conn.boundary) {
|
|
143
|
-
boundaries.add(conn.boundary)
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const tree = treeFromMemoryState<Ctx>(memory, 'final')
|
|
147
|
-
const stage = memory.stageExclude({} as any)
|
|
148
|
-
|
|
149
|
-
const isRemovable = (el: Elem) =>
|
|
150
|
-
!(
|
|
151
|
-
boundaries.has(el)
|
|
152
|
-
|| memory.explicits.has(el)
|
|
153
|
-
|| tree.hasInOut(el)
|
|
154
|
-
|| tree.root.has(el)
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
const singleRoot = only([...tree.root])
|
|
158
|
-
if (singleRoot && !memory.explicits.has(singleRoot)) {
|
|
159
|
-
stage.exclude(singleRoot)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
for (const el of memory.final) {
|
|
163
|
-
const singleChild = only(tree.children(el))
|
|
164
|
-
if (singleChild && !tree.hasInOut(singleChild) && isRemovable(el)) {
|
|
165
|
-
stage.exclude(el)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (stage.isDirty()) {
|
|
170
|
-
return stage.commit()
|
|
171
|
-
}
|
|
172
|
-
return memory
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// TODO: Lot of corner cases to cover, skip for now
|
|
176
|
-
// public step3FlatNodes(memory: Memory): Memory {
|
|
177
|
-
// // final implicits
|
|
178
|
-
// const explicits = new Set<Elem>([
|
|
179
|
-
// ...memory.explicits,
|
|
180
|
-
// ...memory.connections.flatMap(c => [c.source, c.target]),
|
|
181
|
-
// ])
|
|
182
|
-
// const sorted = sortParentsFirst(toArray(memory.final))
|
|
183
|
-
|
|
184
|
-
// const toplevel = new Set<Elem>(sorted)
|
|
185
|
-
// const children = sorted.reduce((acc, el, index, all) => {
|
|
186
|
-
// acc.set(
|
|
187
|
-
// el,
|
|
188
|
-
// new Set(
|
|
189
|
-
// all
|
|
190
|
-
// .slice(index + 1)
|
|
191
|
-
// .filter(e => isAncestor(el, e))
|
|
192
|
-
// .reduce((acc, el) => {
|
|
193
|
-
// if (!acc.some(e => isAncestor(e, el))) {
|
|
194
|
-
// toplevel.delete(el)
|
|
195
|
-
// acc.push(el)
|
|
196
|
-
// }
|
|
197
|
-
// return acc
|
|
198
|
-
// }, [] as Elem[]),
|
|
199
|
-
// ),
|
|
200
|
-
// )
|
|
201
|
-
// return acc
|
|
202
|
-
// }, new DefaultMap<Elem, Set<Elem>>(() => new Set()))
|
|
203
|
-
|
|
204
|
-
// const state = memory.mutableState()
|
|
205
|
-
|
|
206
|
-
// function flattenNode(node: Elem) {
|
|
207
|
-
// const _children = [...children.get(node)]
|
|
208
|
-
// if (_children.length > 1) {
|
|
209
|
-
// for (const child of _children) {
|
|
210
|
-
// flattenNode(child)
|
|
211
|
-
// }
|
|
212
|
-
// return !explicits.has(node)
|
|
213
|
-
// }
|
|
214
|
-
// if (hasAtLeast(_children, 1)) {
|
|
215
|
-
// if (flattenNode(_children[0])) {
|
|
216
|
-
// state.final.delete(_children[0])
|
|
217
|
-
// }
|
|
218
|
-
// }
|
|
219
|
-
// return !explicits.has(node)
|
|
220
|
-
// }
|
|
221
|
-
|
|
222
|
-
// const root = [...toplevel]
|
|
223
|
-
// for (const node of root) {
|
|
224
|
-
// flattenNode(node)
|
|
225
|
-
// if (!explicits.has(node) && children.get(node).size === 1) {
|
|
226
|
-
// state.final.delete(node)
|
|
227
|
-
// }
|
|
228
|
-
// }
|
|
229
|
-
// if (root.length === 1 && !explicits.has(root[0]!)) {
|
|
230
|
-
// state.final.delete(root[0]!)
|
|
231
|
-
// }
|
|
232
|
-
|
|
233
|
-
// return memory.update(state)
|
|
234
|
-
// }
|
|
235
|
-
|
|
236
|
-
public commit(): Memory {
|
|
237
|
-
// return []
|
|
238
|
-
const step1 = this.step1CleanConnections(this.memory)
|
|
239
|
-
const step2 = this.step2ProcessImplicits(step1)
|
|
240
|
-
return this.step3ProcessBoundaries(step2)
|
|
241
|
-
// return step2memory
|
|
242
|
-
// const step3m?emory = this.step3FlatNodes(step2memory)
|
|
243
|
-
// return step3memory
|
|
244
|
-
}
|
|
245
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { dropWhile, forEach, pipe, take, zip } from 'remeda'
|
|
2
|
-
import { isIterable } from '../../../utils'
|
|
3
|
-
import { toArray } from '../../../utils/iterable'
|
|
4
|
-
import { type CtxConnection, type CtxElement, AbstractStageInclude } from '../../memory'
|
|
5
|
-
import { cleanCrossBoundary, cleanRedundantRelationships } from '../clean-connections'
|
|
6
|
-
import { type Ctx } from '../memory/memory'
|
|
7
|
-
import { findConnection, findConnectionsBetween } from '../utils'
|
|
8
|
-
|
|
9
|
-
type Elem = CtxElement<Ctx>
|
|
10
|
-
type Connection = CtxConnection<Ctx>
|
|
11
|
-
|
|
12
|
-
export class StageInclude extends AbstractStageInclude<Ctx> {
|
|
13
|
-
/**
|
|
14
|
-
* Connects elements with existing ones in the memory
|
|
15
|
-
*/
|
|
16
|
-
public override connectWithExisting(
|
|
17
|
-
elements: Elem | Iterable<Elem>,
|
|
18
|
-
direction: 'in' | 'out' | 'both' = 'both',
|
|
19
|
-
): boolean {
|
|
20
|
-
const before = this._connections.length
|
|
21
|
-
const hasChanged = () => this._connections.length > before
|
|
22
|
-
if (!isIterable(elements)) {
|
|
23
|
-
if (direction === 'in' || direction === 'both') {
|
|
24
|
-
for (const el of this.memory.elements) {
|
|
25
|
-
this.addConnections(
|
|
26
|
-
findConnection(el, elements, 'directed'),
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (direction === 'out' || direction === 'both') {
|
|
31
|
-
this.addConnections(
|
|
32
|
-
findConnectionsBetween(elements, this.memory.elements, 'directed'),
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
return hasChanged()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const targets = [...elements]
|
|
39
|
-
if (direction === 'in' || direction === 'both') {
|
|
40
|
-
for (const el of this.memory.elements) {
|
|
41
|
-
this.addConnections(
|
|
42
|
-
findConnectionsBetween(el, targets, 'directed'),
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (direction === 'out' || direction === 'both') {
|
|
47
|
-
for (const el of targets) {
|
|
48
|
-
this.addConnections(
|
|
49
|
-
findConnectionsBetween(el, this.memory.elements, 'directed'),
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return hasChanged()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected override processConnections(connections: Connection[]) {
|
|
57
|
-
const clean = pipe(
|
|
58
|
-
connections,
|
|
59
|
-
cleanCrossBoundary,
|
|
60
|
-
cleanRedundantRelationships,
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
pipe(
|
|
64
|
-
clean,
|
|
65
|
-
// Process only connection from this stage
|
|
66
|
-
// filter(c => this._connections.some(c2 => c2.id === c.id)),
|
|
67
|
-
forEach(({ source, target, boundary }) => {
|
|
68
|
-
pipe(
|
|
69
|
-
zip(
|
|
70
|
-
[...toArray(source.ancestors()).reverse(), source],
|
|
71
|
-
[...toArray(target.ancestors()).reverse(), target],
|
|
72
|
-
),
|
|
73
|
-
// Filter out common ancestors
|
|
74
|
-
dropWhile(([sourceAncestor, targetAncestor]) => sourceAncestor === targetAncestor),
|
|
75
|
-
take(1),
|
|
76
|
-
forEach(([sourceAncestor, targetAncestor]) => {
|
|
77
|
-
if (source === sourceAncestor && target === targetAncestor) {
|
|
78
|
-
this.addImplicit(boundary)
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
if (sourceAncestor !== source && sourceAncestor.isDeploymentNode() && !sourceAncestor.onlyOneInstance()) {
|
|
82
|
-
// state.final.add(source)
|
|
83
|
-
this.addImplicit(sourceAncestor)
|
|
84
|
-
}
|
|
85
|
-
if (targetAncestor !== target && targetAncestor.isDeploymentNode() && !targetAncestor.onlyOneInstance()) {
|
|
86
|
-
// state.final.add(source)
|
|
87
|
-
this.addImplicit(targetAncestor)
|
|
88
|
-
}
|
|
89
|
-
}),
|
|
90
|
-
)
|
|
91
|
-
}),
|
|
92
|
-
)
|
|
93
|
-
return clean
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import { hasAtLeast, unique } from 'remeda'
|
|
2
|
-
import type {
|
|
3
|
-
DeployedInstanceModel,
|
|
4
|
-
DeploymentConnectionModel,
|
|
5
|
-
DeploymentElementModel,
|
|
6
|
-
DeploymentNodeModel,
|
|
7
|
-
ElementModel,
|
|
8
|
-
LikeC4DeploymentModel,
|
|
9
|
-
} from '../../model'
|
|
10
|
-
import { deploymentConnection } from '../../model'
|
|
11
|
-
import {
|
|
12
|
-
type AnyAux,
|
|
13
|
-
type aux,
|
|
14
|
-
type ComputedEdge,
|
|
15
|
-
type ComputedNode,
|
|
16
|
-
type DeploymentViewRule,
|
|
17
|
-
type scalar,
|
|
18
|
-
type Unknown,
|
|
19
|
-
DefaultArrowType,
|
|
20
|
-
DefaultElementShape,
|
|
21
|
-
DefaultThemeColor,
|
|
22
|
-
FqnExpr,
|
|
23
|
-
isViewRuleStyle,
|
|
24
|
-
omitUndefined,
|
|
25
|
-
preferSummary,
|
|
26
|
-
} from '../../types'
|
|
27
|
-
import { invariant, nameFromFqn, nonexhaustive, parentFqn } from '../../utils'
|
|
28
|
-
import { applyViewRuleStyle } from '../utils/applyViewRuleStyles'
|
|
29
|
-
import { type ComputedNodeSource, buildComputedNodes } from '../utils/buildComputedNodes'
|
|
30
|
-
import { mergePropsFromRelationships } from '../utils/merge-props-from-relationships'
|
|
31
|
-
import type { Memory } from './_types'
|
|
32
|
-
|
|
33
|
-
export const { findConnection, findConnectionsBetween, findConnectionsWithin } = deploymentConnection
|
|
34
|
-
|
|
35
|
-
type Predicate<T> = (x: T) => boolean
|
|
36
|
-
|
|
37
|
-
export function resolveElements<A extends AnyAux>(
|
|
38
|
-
model: LikeC4DeploymentModel<A>,
|
|
39
|
-
expr: FqnExpr.DeploymentRef<A>,
|
|
40
|
-
): DeploymentElementModel<A>[] {
|
|
41
|
-
const ref = model.element(expr.ref.deployment)
|
|
42
|
-
if (ref.isDeploymentNode()) {
|
|
43
|
-
if (expr.selector === 'children') {
|
|
44
|
-
return [...ref.children()]
|
|
45
|
-
}
|
|
46
|
-
if (expr.selector === 'expanded') {
|
|
47
|
-
return [ref, ...ref.children()]
|
|
48
|
-
}
|
|
49
|
-
if (expr.selector === 'descendants') {
|
|
50
|
-
return [...ref.descendants()]
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return [ref]
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function resolveModelElements<A extends AnyAux>(
|
|
57
|
-
model: LikeC4DeploymentModel<A>,
|
|
58
|
-
expr: FqnExpr.ModelRef<A>,
|
|
59
|
-
): ElementModel<A>[] {
|
|
60
|
-
const ref = model.$model.element(expr.ref.model)
|
|
61
|
-
if (expr.selector === 'children') {
|
|
62
|
-
return [...ref.children()]
|
|
63
|
-
}
|
|
64
|
-
if (expr.selector === 'expanded') {
|
|
65
|
-
return [ref, ...ref.children()]
|
|
66
|
-
}
|
|
67
|
-
if (expr.selector === 'descendants') {
|
|
68
|
-
return [...ref.descendants()]
|
|
69
|
-
}
|
|
70
|
-
return [ref]
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function deploymentExpressionToPredicate<
|
|
74
|
-
A extends AnyAux,
|
|
75
|
-
N extends { id: string | aux.DeploymentFqn<A>; modelRef?: aux.Fqn<A> | undefined },
|
|
76
|
-
>(
|
|
77
|
-
target: FqnExpr<A>,
|
|
78
|
-
): Predicate<N> {
|
|
79
|
-
if (FqnExpr.isWildcard(target)) {
|
|
80
|
-
return () => true
|
|
81
|
-
}
|
|
82
|
-
if (FqnExpr.isElementTagExpr(target) || FqnExpr.isElementKindExpr(target)) {
|
|
83
|
-
throw new Error('element kind and tag expressions are not supported in deployment view rules')
|
|
84
|
-
}
|
|
85
|
-
if (FqnExpr.isDeploymentRef(target)) {
|
|
86
|
-
const fqn = target.ref.deployment
|
|
87
|
-
if (target.selector === 'expanded') {
|
|
88
|
-
const fqnWithDot = fqn + '.'
|
|
89
|
-
return n => n.id === fqn || n.id.startsWith(fqnWithDot)
|
|
90
|
-
}
|
|
91
|
-
if (target.selector === 'descendants') {
|
|
92
|
-
const fqnWithDot = fqn + '.'
|
|
93
|
-
return n => n.id.startsWith(fqnWithDot)
|
|
94
|
-
}
|
|
95
|
-
if (target.selector === 'children') {
|
|
96
|
-
return n => parentFqn(n.id) === fqn
|
|
97
|
-
}
|
|
98
|
-
return n => n.id === fqn
|
|
99
|
-
}
|
|
100
|
-
if (FqnExpr.isModelRef(target)) {
|
|
101
|
-
const fqn = target.ref.model
|
|
102
|
-
if (target.selector === 'expanded') {
|
|
103
|
-
const fqnWithDot = fqn + '.'
|
|
104
|
-
return (n: N) => {
|
|
105
|
-
const m = n.modelRef ?? null
|
|
106
|
-
if (!m) {
|
|
107
|
-
return true
|
|
108
|
-
}
|
|
109
|
-
return m === fqn || m.startsWith(fqnWithDot)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (target.selector === 'descendants') {
|
|
113
|
-
const fqnWithDot = fqn + '.'
|
|
114
|
-
return (n: N) => {
|
|
115
|
-
const m = n.modelRef ?? null
|
|
116
|
-
if (!m) {
|
|
117
|
-
return true
|
|
118
|
-
}
|
|
119
|
-
return m.startsWith(fqnWithDot)
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (target.selector === 'children') {
|
|
123
|
-
return (n: N) => {
|
|
124
|
-
const m = n.modelRef ?? null
|
|
125
|
-
if (!m) {
|
|
126
|
-
return true
|
|
127
|
-
}
|
|
128
|
-
return parentFqn(m) === fqn
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return (n: N) => {
|
|
132
|
-
const m = n.modelRef ?? null
|
|
133
|
-
if (!m) {
|
|
134
|
-
return true
|
|
135
|
-
}
|
|
136
|
-
return m === fqn
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
nonexhaustive(target)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function instanceSummary(model: DeployedInstanceModel<any>) {
|
|
143
|
-
return preferSummary(model.$instance) ?? preferSummary(model.element.$element)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function toNodeSource<A extends AnyAux>(
|
|
147
|
-
el: DeploymentNodeModel<A> | DeployedInstanceModel<A>,
|
|
148
|
-
): ComputedNodeSource<A> {
|
|
149
|
-
if (el.isDeploymentNode()) {
|
|
150
|
-
const onlyOneInstance = el.onlyOneInstance()
|
|
151
|
-
let {
|
|
152
|
-
title,
|
|
153
|
-
id,
|
|
154
|
-
description,
|
|
155
|
-
summary,
|
|
156
|
-
metadata,
|
|
157
|
-
style,
|
|
158
|
-
element,
|
|
159
|
-
tags: _tags, // omit
|
|
160
|
-
...$node
|
|
161
|
-
} = el.$node
|
|
162
|
-
let icon = style.icon
|
|
163
|
-
let tags = [...el.tags]
|
|
164
|
-
// let description
|
|
165
|
-
// If there is only one instance
|
|
166
|
-
summary ??= description
|
|
167
|
-
if (onlyOneInstance) {
|
|
168
|
-
tags = unique([...tags, ...onlyOneInstance.tags])
|
|
169
|
-
// If title was not overriden, take title from the instance
|
|
170
|
-
if (title === nameFromFqn(el.id)) {
|
|
171
|
-
title = onlyOneInstance.title
|
|
172
|
-
}
|
|
173
|
-
icon ??= onlyOneInstance.style.icon
|
|
174
|
-
summary ??= instanceSummary(onlyOneInstance)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return omitUndefined({
|
|
178
|
-
id: id as scalar.NodeId,
|
|
179
|
-
deploymentRef: id,
|
|
180
|
-
title,
|
|
181
|
-
...$node,
|
|
182
|
-
color: style.color ?? onlyOneInstance?.color ?? DefaultThemeColor,
|
|
183
|
-
shape: style.shape ?? DefaultElementShape,
|
|
184
|
-
...(onlyOneInstance && {
|
|
185
|
-
modelRef: onlyOneInstance.element.id,
|
|
186
|
-
}),
|
|
187
|
-
icon,
|
|
188
|
-
description: summary,
|
|
189
|
-
tags,
|
|
190
|
-
style,
|
|
191
|
-
})
|
|
192
|
-
}
|
|
193
|
-
invariant(el.isInstance(), 'Expected Instance')
|
|
194
|
-
const instance = el.$instance
|
|
195
|
-
const element = el.element
|
|
196
|
-
const { icon, color, shape, ...style } = el.style
|
|
197
|
-
|
|
198
|
-
const links = [
|
|
199
|
-
...element.links,
|
|
200
|
-
...(instance.links ?? []),
|
|
201
|
-
]
|
|
202
|
-
|
|
203
|
-
const notation = instance.notation ?? element.$element.notation
|
|
204
|
-
|
|
205
|
-
const description = instanceSummary(el)
|
|
206
|
-
|
|
207
|
-
const technology = el.technology ?? undefined
|
|
208
|
-
|
|
209
|
-
return omitUndefined({
|
|
210
|
-
id: el.id as scalar.NodeId,
|
|
211
|
-
kind: 'instance' as unknown as aux.DeploymentKind<A>,
|
|
212
|
-
title: el.title,
|
|
213
|
-
description,
|
|
214
|
-
technology,
|
|
215
|
-
tags: [...el.tags],
|
|
216
|
-
links: hasAtLeast(links, 1) ? links : undefined,
|
|
217
|
-
icon,
|
|
218
|
-
color,
|
|
219
|
-
shape,
|
|
220
|
-
style,
|
|
221
|
-
deploymentRef: instance.id,
|
|
222
|
-
modelRef: element.id,
|
|
223
|
-
notation,
|
|
224
|
-
})
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export function toComputedEdges<A extends AnyAux>(
|
|
228
|
-
connections: ReadonlyArray<DeploymentConnectionModel<A>>,
|
|
229
|
-
): ComputedEdge<A>[] {
|
|
230
|
-
return connections.reduce((acc, e) => {
|
|
231
|
-
// const modelRelations = []
|
|
232
|
-
// const deploymentRelations = []
|
|
233
|
-
const relations = [
|
|
234
|
-
...e.relations.model,
|
|
235
|
-
...e.relations.deployment,
|
|
236
|
-
]
|
|
237
|
-
invariant(hasAtLeast(relations, 1), 'Edge must have at least one relation')
|
|
238
|
-
|
|
239
|
-
const source = e.source.id as scalar.NodeId
|
|
240
|
-
const target = e.target.id as scalar.NodeId
|
|
241
|
-
|
|
242
|
-
const {
|
|
243
|
-
title,
|
|
244
|
-
...props
|
|
245
|
-
} = mergePropsFromRelationships(relations.map(r => r.$relationship)) // || relations.find(r => r.source === source && r.target === target)
|
|
246
|
-
|
|
247
|
-
const edge: ComputedEdge<A> = {
|
|
248
|
-
id: e.id,
|
|
249
|
-
parent: e.boundary?.id as scalar.NodeId ?? null,
|
|
250
|
-
source,
|
|
251
|
-
target,
|
|
252
|
-
label: title ?? null,
|
|
253
|
-
relations: relations.map((r) => r.id),
|
|
254
|
-
...props,
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// If exists same edge but in opposite direction
|
|
258
|
-
const existing = acc.find(e => e.source === target && e.target === source)
|
|
259
|
-
if (existing && edge.label === existing.label) {
|
|
260
|
-
existing.dir = 'both'
|
|
261
|
-
const head = existing.head ?? edge.head ?? DefaultArrowType
|
|
262
|
-
existing.head ??= head
|
|
263
|
-
existing.tail ??= head
|
|
264
|
-
|
|
265
|
-
if (edge.color) {
|
|
266
|
-
existing.color ??= edge.color
|
|
267
|
-
}
|
|
268
|
-
if (edge.line) {
|
|
269
|
-
existing.line ??= edge.line
|
|
270
|
-
}
|
|
271
|
-
return acc
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
acc.push(edge)
|
|
275
|
-
return acc
|
|
276
|
-
}, [] as ComputedEdge<A>[])
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export function buildNodes<A extends AnyAux = Unknown>(
|
|
280
|
-
memory: Memory,
|
|
281
|
-
): ReadonlyMap<aux.NodeId, ComputedNode<A>> {
|
|
282
|
-
return buildComputedNodes([...memory.final].map(toNodeSource))
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export function applyDeploymentViewRuleStyles<A extends AnyAux>(
|
|
286
|
-
rules: DeploymentViewRule<A>[],
|
|
287
|
-
nodes: ComputedNode<A>[],
|
|
288
|
-
): ComputedNode<A>[] {
|
|
289
|
-
for (const rule of rules) {
|
|
290
|
-
if (!isViewRuleStyle(rule) || rule.targets.length === 0) {
|
|
291
|
-
continue
|
|
292
|
-
}
|
|
293
|
-
const predicates = rule.targets.map(deploymentExpressionToPredicate)
|
|
294
|
-
applyViewRuleStyle(rule, predicates, nodes)
|
|
295
|
-
}
|
|
296
|
-
return nodes
|
|
297
|
-
}
|