@likec4/core 1.40.0 → 1.42.0
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 +83 -20
- package/dist/builder/index.mjs +210 -126
- 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 +12 -12
- 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.DHQ32OHa.mjs → core.01VTr9qu.mjs} +10 -29
- 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.BIAlzwKc.mjs → core.BIqHjQiH.mjs} +85 -45
- package/dist/shared/core.BKlholso.mjs +3 -0
- package/dist/shared/core.BR4zXDH-.mjs +13 -0
- package/dist/shared/{core.yHe79zEl.mjs → core.BYNkXQ8A.mjs} +21 -12
- package/dist/shared/core.BazD6cot.mjs +14 -0
- 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.T-eLZTW_.mjs → core.BzTakU3I.mjs} +15 -7
- 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.FPITT8Vx.mjs → core.C8sl5Y8Z.mjs} +144 -61
- package/dist/shared/{core.DuR3R-xJ.mjs → core.CNgZvKb8.mjs} +3 -5176
- package/dist/shared/{core.BbThmf6M.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.CySf-2gP.d.mts → core.D0PjZzIS.d.mts} +52 -15
- package/dist/shared/{core.DrvfVXkh.d.mts → core.D5fzJWbF.d.mts} +11 -2
- package/dist/shared/{core.DrVOJuxX.d.mts → core.DACpKp35.d.mts} +5 -5
- package/dist/shared/core.DFi2dOTl.mjs +39548 -0
- package/dist/shared/{core.D704WZES.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.vWJTxpLV.d.mts → core.D_vkffV4.d.mts} +4 -2
- package/dist/shared/core.DdMJk7nx.d.mts +476 -0
- package/dist/shared/{core.D_fI5Lf6.d.mts → core.Dgs6-nuz.d.mts} +24 -4
- 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.kxeJe0OY.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/_aux.mjs +1 -5
- 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 +151 -6
- 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.Bpou6c2f.d.mts +0 -850
- package/dist/shared/core.CUw_2J9j.mjs +0 -47
- package/dist/shared/core.CzdwsPmY.d.mts +0 -69
- 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 -870
- 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 -320
- 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 -286
- 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 -357
- 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 -153
- package/src/compute-view/utils/buildElementNotations.ts +0 -63
- 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 -682
- package/src/model/DeploymentModel.ts +0 -393
- package/src/model/ElementModel.ts +0 -293
- 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 -120
- 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 -206
- package/src/types/_aux.ts +0 -291
- package/src/types/_common.ts +0 -80
- 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 -42
- package/src/types/model-data.ts +0 -77
- package/src/types/model-deployment.ts +0 -88
- package/src/types/model-dump.ts +0 -79
- package/src/types/model-logical.ts +0 -135
- package/src/types/model-spec.ts +0 -85
- 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 -118
- package/src/types/view-layouted.ts +0 -98
- 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,94 +0,0 @@
|
|
|
1
|
-
import { findLast, map } from 'remeda'
|
|
2
|
-
import { type DeploymentConnectionModel, type LikeC4DeploymentModel, LikeC4Model } from '../../model'
|
|
3
|
-
import type { AnyAux, DeploymentViewRule } from '../../types'
|
|
4
|
-
import {
|
|
5
|
-
type ComputedDeploymentView,
|
|
6
|
-
type ParsedDeploymentView as DeploymentView,
|
|
7
|
-
_stage,
|
|
8
|
-
_type,
|
|
9
|
-
isViewRuleAutoLayout,
|
|
10
|
-
isViewRulePredicate,
|
|
11
|
-
} from '../../types'
|
|
12
|
-
import { buildElementNotations } from '../utils/buildElementNotations'
|
|
13
|
-
import { linkNodesWithEdges } from '../utils/link-nodes-with-edges'
|
|
14
|
-
import { topologicalSort } from '../utils/topological-sort'
|
|
15
|
-
import { calcViewLayoutHash } from '../utils/view-hash'
|
|
16
|
-
import { Memory } from './memory'
|
|
17
|
-
import { predicateToPatch } from './predicates'
|
|
18
|
-
import { StageFinal } from './stages/stage-final'
|
|
19
|
-
import { applyDeploymentViewRuleStyles, buildNodes, toComputedEdges } from './utils'
|
|
20
|
-
|
|
21
|
-
export function processPredicates(
|
|
22
|
-
model: LikeC4DeploymentModel<any>,
|
|
23
|
-
rules: DeploymentViewRule<any>[],
|
|
24
|
-
) {
|
|
25
|
-
let memory = Memory.empty()
|
|
26
|
-
|
|
27
|
-
for (const rule of rules) {
|
|
28
|
-
if (isViewRulePredicate(rule)) {
|
|
29
|
-
const op = 'include' in rule ? 'include' : 'exclude'
|
|
30
|
-
const exprs = rule.include ?? rule.exclude
|
|
31
|
-
for (const expr of exprs) {
|
|
32
|
-
let stage = op === 'include' ? memory.stageInclude(expr) : memory.stageExclude(expr)
|
|
33
|
-
const ctx = { expr, model, stage, memory, where: null }
|
|
34
|
-
stage = predicateToPatch(op, ctx) ?? stage
|
|
35
|
-
memory = stage.commit()
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return StageFinal.for(memory).commit()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function computeDeploymentView<M extends AnyAux>(
|
|
43
|
-
likec4model: LikeC4Model<M>,
|
|
44
|
-
{
|
|
45
|
-
docUri: _docUri, // exclude docUri
|
|
46
|
-
rules, // exclude rules
|
|
47
|
-
...view
|
|
48
|
-
}: DeploymentView<NoInfer<M>>,
|
|
49
|
-
): ComputedDeploymentView<M> {
|
|
50
|
-
const memory = processPredicates(likec4model.deployment, rules)
|
|
51
|
-
|
|
52
|
-
const nodesMap = buildNodes<M>(memory)
|
|
53
|
-
|
|
54
|
-
const computedEdges = toComputedEdges(memory.connections as unknown as DeploymentConnectionModel<M>[])
|
|
55
|
-
|
|
56
|
-
linkNodesWithEdges(nodesMap, computedEdges)
|
|
57
|
-
|
|
58
|
-
const sorted = topologicalSort({
|
|
59
|
-
nodes: nodesMap,
|
|
60
|
-
edges: computedEdges,
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const nodes = applyDeploymentViewRuleStyles(
|
|
64
|
-
rules,
|
|
65
|
-
sorted.nodes,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
const autoLayoutRule = findLast(rules, isViewRuleAutoLayout)
|
|
69
|
-
|
|
70
|
-
const elementNotations = buildElementNotations(nodes)
|
|
71
|
-
|
|
72
|
-
return calcViewLayoutHash({
|
|
73
|
-
...view,
|
|
74
|
-
[_stage]: 'computed',
|
|
75
|
-
[_type]: 'deployment',
|
|
76
|
-
autoLayout: {
|
|
77
|
-
direction: autoLayoutRule?.direction ?? 'TB',
|
|
78
|
-
...(autoLayoutRule?.nodeSep && { nodeSep: autoLayoutRule.nodeSep }),
|
|
79
|
-
...(autoLayoutRule?.rankSep && { rankSep: autoLayoutRule.rankSep }),
|
|
80
|
-
},
|
|
81
|
-
edges: sorted.edges,
|
|
82
|
-
nodes: map(nodes, n => {
|
|
83
|
-
if (n.icon === 'none') {
|
|
84
|
-
delete n.icon
|
|
85
|
-
}
|
|
86
|
-
return n
|
|
87
|
-
}),
|
|
88
|
-
...(elementNotations.length > 0 && {
|
|
89
|
-
notation: {
|
|
90
|
-
nodes: elementNotations,
|
|
91
|
-
},
|
|
92
|
-
}),
|
|
93
|
-
})
|
|
94
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { StageExclude } from '../stages/stage-exclude'
|
|
2
|
-
import type { StageInclude } from '../stages/stage-include'
|
|
3
|
-
|
|
4
|
-
export { StageExclude } from '../stages/stage-exclude'
|
|
5
|
-
export { StageInclude } from '../stages/stage-include'
|
|
6
|
-
export { Memory } from './memory'
|
|
7
|
-
export type { Ctx } from './memory'
|
|
8
|
-
|
|
9
|
-
export type Stage = StageInclude | StageExclude
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { isDeepEqual } from 'remeda'
|
|
2
|
-
import type { DeploymentElementModel } from '../../../model'
|
|
3
|
-
import { type DeploymentConnectionModel, differenceConnections } from '../../../model'
|
|
4
|
-
import type { AnyAux, Expression } from '../../../types'
|
|
5
|
-
import { difference as differenceSet } from '../../../utils'
|
|
6
|
-
import { customInspectSymbol } from '../../../utils/const'
|
|
7
|
-
import { toArray } from '../../../utils/iterable'
|
|
8
|
-
import { type ComputeCtx, type StageExpression, AbstractMemory } from '../../memory'
|
|
9
|
-
import { StageExclude } from '../stages/stage-exclude'
|
|
10
|
-
import { StageInclude } from '../stages/stage-include'
|
|
11
|
-
|
|
12
|
-
export type Ctx = ComputeCtx<
|
|
13
|
-
DeploymentElementModel<AnyAux>,
|
|
14
|
-
DeploymentConnectionModel<AnyAux>,
|
|
15
|
-
Memory,
|
|
16
|
-
StageInclude,
|
|
17
|
-
StageExclude,
|
|
18
|
-
Expression<AnyAux>
|
|
19
|
-
>
|
|
20
|
-
|
|
21
|
-
export class Memory extends AbstractMemory<Ctx> {
|
|
22
|
-
static empty(): Memory {
|
|
23
|
-
return new Memory({
|
|
24
|
-
elements: new Set(),
|
|
25
|
-
explicits: new Set(),
|
|
26
|
-
final: new Set(),
|
|
27
|
-
connections: [],
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
override stageInclude(expr: StageExpression<Ctx>): StageInclude {
|
|
32
|
-
return new StageInclude(this, expr)
|
|
33
|
-
}
|
|
34
|
-
override stageExclude(expr: StageExpression<Ctx>): StageExclude {
|
|
35
|
-
return new StageExclude(this, expr)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
override mutableState(): Ctx['MutableState'] {
|
|
39
|
-
return ({
|
|
40
|
-
elements: new Set(this.state.elements),
|
|
41
|
-
explicits: new Set(this.state.explicits),
|
|
42
|
-
final: new Set(this.state.final),
|
|
43
|
-
connections: [...this.state.connections],
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
override update(newstate: Partial<Ctx['MutableState']>): Memory {
|
|
48
|
-
return new Memory({
|
|
49
|
-
...this.state,
|
|
50
|
-
...newstate,
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
equals(other: unknown): boolean {
|
|
55
|
-
return other instanceof Memory && isDeepEqual(this.state, other.state)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
diff(state: Memory) {
|
|
59
|
-
const current = this
|
|
60
|
-
return {
|
|
61
|
-
added: {
|
|
62
|
-
elements: toArray(differenceSet(state.elements, current.elements)),
|
|
63
|
-
explicits: toArray(differenceSet(state.explicits, current.explicits)),
|
|
64
|
-
final: toArray(differenceSet(state.final, current.final)),
|
|
65
|
-
connections: toArray(differenceConnections(state.connections, current.connections)),
|
|
66
|
-
},
|
|
67
|
-
removed: {
|
|
68
|
-
elements: toArray(differenceSet(current.elements, state.elements)),
|
|
69
|
-
explicits: toArray(differenceSet(current.explicits, state.explicits)),
|
|
70
|
-
final: toArray(differenceSet(current.final, state.final)),
|
|
71
|
-
connections: differenceConnections(current.connections, state.connections),
|
|
72
|
-
},
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public override toString(): string {
|
|
77
|
-
return [
|
|
78
|
-
'final:',
|
|
79
|
-
...[...this.final].map(e => ' ' + e.id),
|
|
80
|
-
'connections:',
|
|
81
|
-
...this.connections.map(c => ' ' + c.expression),
|
|
82
|
-
].join('\n')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
[customInspectSymbol](_depth: unknown, _inspectOptions: unknown, _inspect: unknown) {
|
|
86
|
-
const asString = this.toString()
|
|
87
|
-
|
|
88
|
-
// // Trick so that node displays the name of the constructor
|
|
89
|
-
// Object.defineProperty(asString, 'constructor', {
|
|
90
|
-
// value: this.constructor,
|
|
91
|
-
// enumerable: false,
|
|
92
|
-
// })
|
|
93
|
-
|
|
94
|
-
return asString
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type FqnExpr, type RelationExpr, whereOperatorAsPredicate } from '../../../types'
|
|
2
|
-
import type { PredicateExecutor } from '../_types'
|
|
3
|
-
import type { StageExclude, StageInclude } from '../memory'
|
|
4
|
-
import { predicateToPatch } from './utils'
|
|
5
|
-
|
|
6
|
-
// relation matches the condition
|
|
7
|
-
export const WhereDeploymentRefPredicate: PredicateExecutor<FqnExpr.Where> = {
|
|
8
|
-
include: ({ expr, model, memory, stage }) => {
|
|
9
|
-
const where = whereOperatorAsPredicate(expr.where.condition)
|
|
10
|
-
|
|
11
|
-
return predicateToPatch('include', { expr: expr.where.expr, model, stage, memory, where }) as StageInclude
|
|
12
|
-
},
|
|
13
|
-
exclude: ({ expr, model, memory, stage }) => {
|
|
14
|
-
const where = whereOperatorAsPredicate(expr.where.condition)
|
|
15
|
-
|
|
16
|
-
return predicateToPatch('exclude', { expr: expr.where.expr, model, stage, memory, where }) as StageExclude
|
|
17
|
-
},
|
|
18
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { filter, forEach, pipe, reduce } from 'remeda'
|
|
2
|
-
import type { DeploymentElementModel, DeploymentNodeModel } from '../../../model'
|
|
3
|
-
import { isDeployedInstanceModel as isDeployedInstance } from '../../../model'
|
|
4
|
-
import type { FqnExpr } from '../../../types'
|
|
5
|
-
import type { Elem, IncludePredicateCtx, PredicateExecutor } from '../_types'
|
|
6
|
-
import { cleanCrossBoundary, cleanRedundantRelationships } from '../clean-connections'
|
|
7
|
-
import type { StageInclude } from '../memory'
|
|
8
|
-
import { deploymentExpressionToPredicate, findConnectionsBetween, findConnectionsWithin } from '../utils'
|
|
9
|
-
import { applyElementPredicate } from './utils'
|
|
10
|
-
|
|
11
|
-
export const DeploymentRefPredicate: PredicateExecutor<FqnExpr.DeploymentRef> = {
|
|
12
|
-
include: (ctx) => {
|
|
13
|
-
const { expr, where } = ctx
|
|
14
|
-
const el = ctx.model.element(expr.ref.deployment)
|
|
15
|
-
|
|
16
|
-
if (isDeployedInstance(el)) {
|
|
17
|
-
if (applyElementPredicate(el, where)) {
|
|
18
|
-
ctx.stage.addExplicit(el)
|
|
19
|
-
ctx.stage.connectWithExisting(el)
|
|
20
|
-
}
|
|
21
|
-
return ctx.stage
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
switch (true) {
|
|
25
|
-
case expr.selector === 'expanded':
|
|
26
|
-
includeDeployedNodeWithExpanded(el, ctx)
|
|
27
|
-
break
|
|
28
|
-
case expr.selector === 'children':
|
|
29
|
-
includeDeployedNodeChildren(el, ctx)
|
|
30
|
-
break
|
|
31
|
-
case expr.selector === 'descendants':
|
|
32
|
-
includeDeployedNodeDescendants(el, ctx)
|
|
33
|
-
break
|
|
34
|
-
default: {
|
|
35
|
-
if (applyElementPredicate(el, where)) {
|
|
36
|
-
ctx.stage.addExplicit(el)
|
|
37
|
-
ctx.stage.connectWithExisting(el)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return ctx.stage
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
exclude: ({ expr, stage, memory, where }) => {
|
|
45
|
-
const exprPredicate = deploymentExpressionToPredicate(expr)
|
|
46
|
-
const toExclude = pipe(
|
|
47
|
-
[...memory.elements],
|
|
48
|
-
filter(exprPredicate),
|
|
49
|
-
applyElementPredicate(where),
|
|
50
|
-
)
|
|
51
|
-
stage.exclude(toExclude)
|
|
52
|
-
return stage
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* include node.*
|
|
58
|
-
*/
|
|
59
|
-
function includeDeployedNodeChildren(
|
|
60
|
-
node: DeploymentNodeModel,
|
|
61
|
-
{ stage, where }: IncludePredicateCtx,
|
|
62
|
-
) {
|
|
63
|
-
const children = applyElementPredicate([...node.children()], where)
|
|
64
|
-
if (children.length === 0) {
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
stage.addImplicit(node)
|
|
68
|
-
|
|
69
|
-
stage.addConnections(findConnectionsWithin(children))
|
|
70
|
-
stage.connectWithExisting(children)
|
|
71
|
-
|
|
72
|
-
stage.addExplicit(children)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* include node._
|
|
77
|
-
*/
|
|
78
|
-
function includeDeployedNodeWithExpanded(
|
|
79
|
-
node: DeploymentNodeModel,
|
|
80
|
-
{ memory, stage, where }: IncludePredicateCtx,
|
|
81
|
-
) {
|
|
82
|
-
stage.addImplicit(node)
|
|
83
|
-
stage.connectWithExisting(node)
|
|
84
|
-
|
|
85
|
-
const children = applyElementPredicate([...node.children()], where)
|
|
86
|
-
let hasConnectionsWithVisible = false
|
|
87
|
-
for (const child of children) {
|
|
88
|
-
if (findConnectionsBetween(child, memory.elements).length > 0) {
|
|
89
|
-
hasConnectionsWithVisible = true
|
|
90
|
-
break
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (hasConnectionsWithVisible) {
|
|
95
|
-
stage.connectWithExisting(children, 'in')
|
|
96
|
-
stage.addConnections(findConnectionsWithin(children))
|
|
97
|
-
stage.connectWithExisting(children, 'out')
|
|
98
|
-
}
|
|
99
|
-
stage.addImplicit(children)
|
|
100
|
-
|
|
101
|
-
if (stage.connections.length > 0) {
|
|
102
|
-
stage.addExplicit(node)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* include node.**
|
|
108
|
-
*/
|
|
109
|
-
function includeDeployedNodeDescendants(
|
|
110
|
-
node: DeploymentNodeModel,
|
|
111
|
-
{ stage, where }: IncludePredicateCtx,
|
|
112
|
-
) {
|
|
113
|
-
const dfs = (node: DeploymentNodeModel): DeploymentElementModel[] => {
|
|
114
|
-
const children = [] as DeploymentElementModel[]
|
|
115
|
-
for (const child of node.children()) {
|
|
116
|
-
if (child.isDeploymentNode()) {
|
|
117
|
-
children.push(...dfs(child))
|
|
118
|
-
}
|
|
119
|
-
if (applyElementPredicate(child, where)) {
|
|
120
|
-
children.push(child)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
stage.connectWithExisting(children, 'in')
|
|
124
|
-
stage.addConnections(findConnectionsWithin(children))
|
|
125
|
-
stage.addImplicit(children)
|
|
126
|
-
return children
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const descendants = dfs(node)
|
|
130
|
-
if (descendants.length === 0) {
|
|
131
|
-
return
|
|
132
|
-
}
|
|
133
|
-
stage.connectWithExisting(descendants, 'out')
|
|
134
|
-
|
|
135
|
-
const allConnected = findConnectedElements(stage)
|
|
136
|
-
pipe(
|
|
137
|
-
descendants,
|
|
138
|
-
filter(desc => allConnected.has(desc)),
|
|
139
|
-
forEach(desc => stage.addExplicit(desc)),
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function findConnectedElements(stage: StageInclude) {
|
|
144
|
-
return pipe(
|
|
145
|
-
stage.mergedConnections(),
|
|
146
|
-
cleanCrossBoundary,
|
|
147
|
-
cleanRedundantRelationships,
|
|
148
|
-
reduce((acc, c) => {
|
|
149
|
-
acc.add(c.source)
|
|
150
|
-
acc.add(c.target)
|
|
151
|
-
return acc
|
|
152
|
-
}, new Set<Elem>()),
|
|
153
|
-
)
|
|
154
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './deploymentRefs'
|
|
2
|
-
export * from './relation-direct'
|
|
3
|
-
export * from './relation-in-out'
|
|
4
|
-
export * from './relation-incoming'
|
|
5
|
-
export * from './relation-outgoing'
|
|
6
|
-
export * from './relation-where'
|
|
7
|
-
export * from './utils'
|
|
8
|
-
export * from './wildcard'
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { filter, flatMap, isNonNullish, map, pipe } from 'remeda'
|
|
2
|
-
import type {
|
|
3
|
-
DeploymentConnectionModel,
|
|
4
|
-
DeploymentElementModel,
|
|
5
|
-
LikeC4DeploymentModel,
|
|
6
|
-
RelationshipModel,
|
|
7
|
-
} from '../../../model'
|
|
8
|
-
import {
|
|
9
|
-
type ConnectionModel,
|
|
10
|
-
findConnectionsBetween as findModelConnectionsBetween,
|
|
11
|
-
} from '../../../model/connection/model'
|
|
12
|
-
import type { AnyAux } from '../../../types'
|
|
13
|
-
import { type RelationExpr, FqnExpr } from '../../../types'
|
|
14
|
-
import { invariant } from '../../../utils'
|
|
15
|
-
import type { PredicateExecutor } from '../_types'
|
|
16
|
-
import {
|
|
17
|
-
deploymentExpressionToPredicate,
|
|
18
|
-
findConnection,
|
|
19
|
-
findConnectionsBetween,
|
|
20
|
-
findConnectionsWithin,
|
|
21
|
-
resolveElements,
|
|
22
|
-
resolveModelElements,
|
|
23
|
-
} from '../utils'
|
|
24
|
-
import { filterIncomingConnections, resolveAllImcomingRelations } from './relation-incoming'
|
|
25
|
-
import { filterOutgoingConnections, resolveAllOutgoingRelations } from './relation-outgoing'
|
|
26
|
-
import { applyPredicate, excludeModelRelations } from './utils'
|
|
27
|
-
|
|
28
|
-
export const resolveAscendingSiblings = (element: DeploymentElementModel) => {
|
|
29
|
-
const siblings = new Set<DeploymentElementModel>()
|
|
30
|
-
for (let sibling of element.descendingSiblings()) {
|
|
31
|
-
// TODO: investigate if this is necessary
|
|
32
|
-
// if (element.isInstance() && sibling.isDeploymentNode()) {
|
|
33
|
-
// // we flatten nodes that contain only one instance
|
|
34
|
-
// sibling = sibling.onlyOneInstance() ?? sibling
|
|
35
|
-
// }
|
|
36
|
-
siblings.add(sibling)
|
|
37
|
-
}
|
|
38
|
-
return siblings
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const resolveWildcard = (model: LikeC4DeploymentModel<AnyAux>, nonWildcard: FqnExpr.DeploymentRef) => {
|
|
42
|
-
const sources = resolveElements(model, nonWildcard)
|
|
43
|
-
return sources.map(source => {
|
|
44
|
-
const targets = resolveAscendingSiblings(source)
|
|
45
|
-
return [source, targets] as const
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const DirectRelationPredicate: PredicateExecutor<RelationExpr.Direct> = {
|
|
50
|
-
include: ({ expr: { source, target, isBidirectional = false }, model, stage, where }) => {
|
|
51
|
-
if (FqnExpr.isElementTagExpr(source) || FqnExpr.isElementKindExpr(source)) {
|
|
52
|
-
throw new Error('element kind and tag expressions are not supported in include')
|
|
53
|
-
}
|
|
54
|
-
if (FqnExpr.isElementTagExpr(target) || FqnExpr.isElementKindExpr(target)) {
|
|
55
|
-
throw new Error('element kind and tag expressions are not supported in include')
|
|
56
|
-
}
|
|
57
|
-
invariant(!FqnExpr.isModelRef(source), 'Invalid source model ref in direct relation')
|
|
58
|
-
invariant(!FqnExpr.isModelRef(target), 'Invalid target model ref in direct relation')
|
|
59
|
-
const sourceIsWildcard = FqnExpr.isWildcard(source)
|
|
60
|
-
const targetIsWildcard = FqnExpr.isWildcard(target)
|
|
61
|
-
|
|
62
|
-
const dir = isBidirectional ? 'both' : 'directed'
|
|
63
|
-
|
|
64
|
-
let connections
|
|
65
|
-
|
|
66
|
-
switch (true) {
|
|
67
|
-
// * -> *
|
|
68
|
-
case sourceIsWildcard && targetIsWildcard: {
|
|
69
|
-
connections = pipe(
|
|
70
|
-
findConnectionsWithin(model.instances()),
|
|
71
|
-
applyPredicate(where),
|
|
72
|
-
map(c => {
|
|
73
|
-
stage.addImplicit(c.boundary)
|
|
74
|
-
return c
|
|
75
|
-
}),
|
|
76
|
-
)
|
|
77
|
-
break
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// source -> *; source <-> *
|
|
81
|
-
case !sourceIsWildcard && targetIsWildcard: {
|
|
82
|
-
const sources = resolveElements(model, source)
|
|
83
|
-
const isSource = filterOutgoingConnections(sources)
|
|
84
|
-
|
|
85
|
-
let postFilter = isSource
|
|
86
|
-
if (isBidirectional) {
|
|
87
|
-
const isTarget = filterIncomingConnections(sources)
|
|
88
|
-
postFilter = c => isSource(c) !== isTarget(c)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
connections = pipe(
|
|
92
|
-
sources,
|
|
93
|
-
flatMap(source => {
|
|
94
|
-
const targets = resolveAscendingSiblings(source)
|
|
95
|
-
return findConnectionsBetween(source, targets, dir)
|
|
96
|
-
}),
|
|
97
|
-
filter(postFilter),
|
|
98
|
-
applyPredicate(where),
|
|
99
|
-
)
|
|
100
|
-
break
|
|
101
|
-
}
|
|
102
|
-
// * -> target; * <-> target
|
|
103
|
-
case sourceIsWildcard && !targetIsWildcard: {
|
|
104
|
-
const targets = resolveElements(model, target)
|
|
105
|
-
const isTarget = filterIncomingConnections(targets)
|
|
106
|
-
|
|
107
|
-
let postFilter = isTarget
|
|
108
|
-
if (isBidirectional) {
|
|
109
|
-
const isSource = filterOutgoingConnections(targets)
|
|
110
|
-
postFilter = c => isSource(c) !== isTarget(c)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
connections = pipe(
|
|
114
|
-
targets,
|
|
115
|
-
flatMap(target => {
|
|
116
|
-
const sources = resolveAscendingSiblings(target)
|
|
117
|
-
return [...sources].flatMap(source => findConnection(source, target, dir))
|
|
118
|
-
}),
|
|
119
|
-
filter(postFilter),
|
|
120
|
-
applyPredicate(where),
|
|
121
|
-
)
|
|
122
|
-
break
|
|
123
|
-
}
|
|
124
|
-
default: {
|
|
125
|
-
invariant(!sourceIsWildcard, 'Inferrence failed - source should be a deployment ref')
|
|
126
|
-
invariant(!targetIsWildcard, 'Inferrence failed - target should be a deployment ref')
|
|
127
|
-
const sources = resolveElements(model, source)
|
|
128
|
-
const targets = resolveElements(model, target)
|
|
129
|
-
|
|
130
|
-
const isSource = filterOutgoingConnections(sources)
|
|
131
|
-
const isTarget = filterIncomingConnections(targets)
|
|
132
|
-
|
|
133
|
-
connections = pipe(
|
|
134
|
-
sources,
|
|
135
|
-
flatMap(s => findConnectionsBetween(s, targets, dir)),
|
|
136
|
-
filter(c => isSource(c) && isTarget(c)),
|
|
137
|
-
applyPredicate(where),
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
stage.addConnections(connections)
|
|
143
|
-
|
|
144
|
-
if (FqnExpr.isDeploymentRef(source) && isNonNullish(source.selector)) {
|
|
145
|
-
stage.addImplicit(model.element(source.ref.deployment))
|
|
146
|
-
}
|
|
147
|
-
if (FqnExpr.isDeploymentRef(target) && isNonNullish(target.selector)) {
|
|
148
|
-
stage.addImplicit(model.element(target.ref.deployment))
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return stage
|
|
152
|
-
},
|
|
153
|
-
exclude: ({ expr, model, memory, stage, where }) => {
|
|
154
|
-
const isTarget = deploymentExpressionToPredicate(expr.target)
|
|
155
|
-
const isSource = deploymentExpressionToPredicate(expr.source)
|
|
156
|
-
|
|
157
|
-
let modelRelationsToExclude: ReadonlySet<RelationshipModel<AnyAux>>
|
|
158
|
-
switch (true) {
|
|
159
|
-
// * -> *
|
|
160
|
-
case FqnExpr.isWildcard(expr.source) && FqnExpr.isWildcard(expr.target):
|
|
161
|
-
stage.excludeConnections(applyPredicate(memory.connections, where))
|
|
162
|
-
return stage
|
|
163
|
-
|
|
164
|
-
// model -> model
|
|
165
|
-
case FqnExpr.isModelRef(expr.source) && FqnExpr.isModelRef(expr.target):
|
|
166
|
-
modelRelationsToExclude = resolveRelationsBetweenModelElements({
|
|
167
|
-
source: expr.source,
|
|
168
|
-
target: expr.target,
|
|
169
|
-
expr,
|
|
170
|
-
model,
|
|
171
|
-
})
|
|
172
|
-
return excludeModelRelations(modelRelationsToExclude, { stage, memory }, where)
|
|
173
|
-
|
|
174
|
-
// model -> *
|
|
175
|
-
case FqnExpr.isModelRef(expr.source) && FqnExpr.isWildcard(expr.target):
|
|
176
|
-
modelRelationsToExclude = resolveAllOutgoingRelations(model, expr.source)
|
|
177
|
-
return excludeModelRelations(modelRelationsToExclude, { stage, memory }, where)
|
|
178
|
-
|
|
179
|
-
// model -> deployment
|
|
180
|
-
case FqnExpr.isModelRef(expr.source):
|
|
181
|
-
modelRelationsToExclude = resolveAllOutgoingRelations(model, expr.source)
|
|
182
|
-
return excludeModelRelations(
|
|
183
|
-
modelRelationsToExclude,
|
|
184
|
-
{ stage, memory },
|
|
185
|
-
where,
|
|
186
|
-
c => isTarget(c.target),
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
// deployment -> model
|
|
190
|
-
case FqnExpr.isModelRef(expr.target):
|
|
191
|
-
modelRelationsToExclude = resolveAllImcomingRelations(model, expr.target)
|
|
192
|
-
return excludeModelRelations(
|
|
193
|
-
modelRelationsToExclude,
|
|
194
|
-
{ stage, memory },
|
|
195
|
-
where,
|
|
196
|
-
c => isSource(c.source),
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
// deployment -> deployment
|
|
200
|
-
default:
|
|
201
|
-
const satisfies = (connection: DeploymentConnectionModel) => {
|
|
202
|
-
return (isSource(connection.source) && isTarget(connection.target))
|
|
203
|
-
|| (expr.isBidirectional === true && isSource(connection.target) && isTarget(connection.source))
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const deploymentRelationsToExclude = pipe(
|
|
207
|
-
memory.connections,
|
|
208
|
-
filter(satisfies),
|
|
209
|
-
applyPredicate(where),
|
|
210
|
-
)
|
|
211
|
-
if (deploymentRelationsToExclude.length === 0) {
|
|
212
|
-
return stage
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
stage.excludeConnections(deploymentRelationsToExclude)
|
|
216
|
-
return stage
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function resolveRelationsBetweenModelElements<A extends AnyAux>({
|
|
222
|
-
source,
|
|
223
|
-
target,
|
|
224
|
-
expr,
|
|
225
|
-
model,
|
|
226
|
-
}: {
|
|
227
|
-
source: FqnExpr.ModelRef<A>
|
|
228
|
-
target: FqnExpr.ModelRef<A>
|
|
229
|
-
expr: RelationExpr.Direct<A>
|
|
230
|
-
model: LikeC4DeploymentModel<A>
|
|
231
|
-
}) {
|
|
232
|
-
const sources = resolveModelElements(model, source)
|
|
233
|
-
const targets = resolveModelElements(model, target)
|
|
234
|
-
|
|
235
|
-
const dir = expr.isBidirectional ? 'both' : 'directed'
|
|
236
|
-
|
|
237
|
-
const modelConnections = [] as ConnectionModel<A>[]
|
|
238
|
-
for (const source of sources) {
|
|
239
|
-
modelConnections.push(...findModelConnectionsBetween(source, targets, dir))
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return new Set(modelConnections.flatMap(c => [...c.relations]))
|
|
243
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { filter, pipe } from 'remeda'
|
|
2
|
-
import type { RelationshipModel } from '../../../model'
|
|
3
|
-
import { type RelationExpr, FqnExpr } from '../../../types'
|
|
4
|
-
import { invariant } from '../../../utils'
|
|
5
|
-
import { union } from '../../../utils/set'
|
|
6
|
-
import type { PredicateExecutor } from '../_types'
|
|
7
|
-
import { findConnectionsBetween, resolveElements, resolveModelElements } from '../utils'
|
|
8
|
-
import { resolveAscendingSiblings } from './relation-direct'
|
|
9
|
-
import { filterIncomingConnections } from './relation-incoming'
|
|
10
|
-
import { filterOutgoingConnections } from './relation-outgoing'
|
|
11
|
-
import { applyPredicate, excludeModelRelations, matchConnections } from './utils'
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
export const InOutRelationPredicate: PredicateExecutor<RelationExpr.InOut> = {
|
|
15
|
-
include: ({ expr, model, memory, stage, where }) => {
|
|
16
|
-
const sources = [...memory.elements]
|
|
17
|
-
|
|
18
|
-
if (FqnExpr.isWildcard(expr.inout)) {
|
|
19
|
-
for (const source of sources) {
|
|
20
|
-
const targets = [...resolveAscendingSiblings(source)]
|
|
21
|
-
const toInclude = matchConnections(findConnectionsBetween(source, targets, 'both'), where)
|
|
22
|
-
stage.addConnections(toInclude)
|
|
23
|
-
}
|
|
24
|
-
return stage
|
|
25
|
-
}
|
|
26
|
-
invariant(FqnExpr.isDeploymentRef(expr.inout), 'Only deployment refs are supported in include')
|
|
27
|
-
|
|
28
|
-
const targets = resolveElements(model, expr.inout)
|
|
29
|
-
for (const source of sources) {
|
|
30
|
-
const toInclude = matchConnections(findConnectionsBetween(source, targets, 'both'), where)
|
|
31
|
-
stage.addConnections(toInclude)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return stage
|
|
35
|
-
},
|
|
36
|
-
exclude: ({ expr, model, memory, stage, where }) => {
|
|
37
|
-
if (FqnExpr.isElementTagExpr(expr.inout) || FqnExpr.isElementKindExpr(expr.inout)) {
|
|
38
|
-
throw new Error('element kind and tag expressions are not supported in exclude')
|
|
39
|
-
}
|
|
40
|
-
// Exclude all connections that have model relationshps with the elements
|
|
41
|
-
if (FqnExpr.isModelRef(expr.inout)) {
|
|
42
|
-
const elements = resolveModelElements(model, expr.inout)
|
|
43
|
-
if (elements.length === 0) {
|
|
44
|
-
return stage
|
|
45
|
-
}
|
|
46
|
-
const excludedRelations = union(
|
|
47
|
-
new Set<RelationshipModel>(),
|
|
48
|
-
...elements.flatMap(e => [e.allIncoming, e.allOutgoing]),
|
|
49
|
-
)
|
|
50
|
-
return excludeModelRelations(excludedRelations, { stage, memory }, where)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (FqnExpr.isWildcard(expr.inout)) {
|
|
54
|
-
// non-sense
|
|
55
|
-
return stage
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const elements = resolveElements(model, expr.inout)
|
|
59
|
-
const isIncoming = filterIncomingConnections(elements)
|
|
60
|
-
const isOutgoing = filterOutgoingConnections(elements)
|
|
61
|
-
|
|
62
|
-
const toExclude = pipe(
|
|
63
|
-
memory.connections,
|
|
64
|
-
filter(c => isIncoming(c) !== isOutgoing(c)),
|
|
65
|
-
applyPredicate(where),
|
|
66
|
-
)
|
|
67
|
-
stage.excludeConnections(toExclude)
|
|
68
|
-
return stage
|
|
69
|
-
},
|
|
70
|
-
}
|