@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,321 +0,0 @@
|
|
|
1
|
-
import { concat, constant, filter, flatMap, hasAtLeast, map, partition, pipe, piped, prop, when } from 'remeda'
|
|
2
|
-
import type { ElementModel, RelationshipModel } from '../../../model'
|
|
3
|
-
import { ConnectionModel } from '../../../model'
|
|
4
|
-
import { type AnyAux, type ModelRelationExpr, FqnRef, ModelFqnExpr } from '../../../types'
|
|
5
|
-
import { invariant, isSameHierarchy } from '../../../utils'
|
|
6
|
-
import { ifilter, iflat, iunique, toArray, toSet } from '../../../utils/iterable'
|
|
7
|
-
import { intersection, union } from '../../../utils/set'
|
|
8
|
-
import type { Elem, PredicateCtx, PredicateExecutor } from '../_types'
|
|
9
|
-
import { NoWhere } from '../utils'
|
|
10
|
-
import {
|
|
11
|
-
findConnectionsBetween,
|
|
12
|
-
findConnectionsWithin,
|
|
13
|
-
includeDescendantsFromMemory,
|
|
14
|
-
resolveAndIncludeFromMemory,
|
|
15
|
-
resolveElements,
|
|
16
|
-
} from './_utils'
|
|
17
|
-
|
|
18
|
-
const isWildcard = ModelFqnExpr.isWildcard
|
|
19
|
-
const isAncestorOrDescendantOf = (a: ElementModel<AnyAux>, b: ElementModel<AnyAux>) =>
|
|
20
|
-
a.isAncestorOf(b) || a.isDescendantOf(b)
|
|
21
|
-
|
|
22
|
-
export const DirectRelationExprPredicate: PredicateExecutor<ModelRelationExpr.Direct<AnyAux>> = {
|
|
23
|
-
include: ({ expr: { source, target, isBidirectional = false }, memory, model, stage, where, filterWhere }) => {
|
|
24
|
-
const sourceIsWildcard = isWildcard(source)
|
|
25
|
-
const targetIsWildcard = isWildcard(target)
|
|
26
|
-
|
|
27
|
-
const connections = [] as ConnectionModel<AnyAux>[]
|
|
28
|
-
switch (true) {
|
|
29
|
-
// This is a special case, we look for all relationships that satisfy the where clause
|
|
30
|
-
// * -> * ; Empty memory; Where clause
|
|
31
|
-
case sourceIsWildcard && targetIsWildcard && memory.isEmpty() && where !== NoWhere: {
|
|
32
|
-
const connections = pipe(
|
|
33
|
-
model.relationships(),
|
|
34
|
-
ifilter(where),
|
|
35
|
-
toArray(),
|
|
36
|
-
map(r => new ConnectionModel(r.source, r.target, new Set([r]))),
|
|
37
|
-
)
|
|
38
|
-
stage.addConnections(connections)
|
|
39
|
-
return stage
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// This is a special case, we look for all relationships between elements that satisfy the where clause
|
|
43
|
-
// * -> *; Not empty memory; Where clause
|
|
44
|
-
case sourceIsWildcard && targetIsWildcard && !memory.isEmpty() && where !== NoWhere: {
|
|
45
|
-
connections.push(
|
|
46
|
-
...findConnectionsWithin(memory.elements),
|
|
47
|
-
)
|
|
48
|
-
break
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// * -> *
|
|
52
|
-
case sourceIsWildcard && targetIsWildcard: {
|
|
53
|
-
connections.push(
|
|
54
|
-
...findConnectionsWithin(model.roots()),
|
|
55
|
-
)
|
|
56
|
-
break
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// This is a special case, we look for all relationships that satisfy the where clause
|
|
60
|
-
// element -> *; Where clause
|
|
61
|
-
case !sourceIsWildcard && targetIsWildcard && where !== NoWhere: {
|
|
62
|
-
const sources = resolveElements(model, source)
|
|
63
|
-
const connections = pipe(
|
|
64
|
-
sources,
|
|
65
|
-
flatMap(source =>
|
|
66
|
-
pipe(
|
|
67
|
-
source,
|
|
68
|
-
when(constant(isBidirectional === true), {
|
|
69
|
-
onTrue: s => union(s.allIncoming, s.allOutgoing),
|
|
70
|
-
onFalse: s => s.allOutgoing,
|
|
71
|
-
}),
|
|
72
|
-
ifilter(where),
|
|
73
|
-
iunique(),
|
|
74
|
-
toArray(),
|
|
75
|
-
partition(r => r.source === source),
|
|
76
|
-
([outgoing, incoming]) =>
|
|
77
|
-
concat(
|
|
78
|
-
pipe(
|
|
79
|
-
outgoing,
|
|
80
|
-
filter(r => !isAncestorOrDescendantOf(source, r.target)),
|
|
81
|
-
map(outgoing =>
|
|
82
|
-
new ConnectionModel(
|
|
83
|
-
source,
|
|
84
|
-
outgoing.target,
|
|
85
|
-
new Set([outgoing]),
|
|
86
|
-
)
|
|
87
|
-
),
|
|
88
|
-
),
|
|
89
|
-
pipe(
|
|
90
|
-
incoming,
|
|
91
|
-
filter(r => !isAncestorOrDescendantOf(source, r.source)),
|
|
92
|
-
map(incoming =>
|
|
93
|
-
new ConnectionModel(
|
|
94
|
-
incoming.source,
|
|
95
|
-
source,
|
|
96
|
-
new Set([incoming]),
|
|
97
|
-
)
|
|
98
|
-
),
|
|
99
|
-
),
|
|
100
|
-
),
|
|
101
|
-
)
|
|
102
|
-
),
|
|
103
|
-
)
|
|
104
|
-
stage.addConnections(connections)
|
|
105
|
-
return stage
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// element -> *
|
|
109
|
-
case !sourceIsWildcard && targetIsWildcard: {
|
|
110
|
-
const [sources, targets] = resolveWildcard(source, { memory, model })
|
|
111
|
-
const dir = isBidirectional ? 'both' : 'directed'
|
|
112
|
-
for (const source of sources) {
|
|
113
|
-
connections.push(
|
|
114
|
-
...findConnectionsBetween(source, targets, dir),
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
break
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// This is a special case, we look for all relationships that satisfy the where clause
|
|
121
|
-
// * -> element; Where clause
|
|
122
|
-
case sourceIsWildcard && !targetIsWildcard && where !== NoWhere: {
|
|
123
|
-
const targets = resolveElements(model, target)
|
|
124
|
-
const connections = pipe(
|
|
125
|
-
targets,
|
|
126
|
-
flatMap(target =>
|
|
127
|
-
pipe(
|
|
128
|
-
target,
|
|
129
|
-
when(constant(isBidirectional === true), {
|
|
130
|
-
onTrue: s => union(s.allIncoming, s.allOutgoing),
|
|
131
|
-
onFalse: s => s.allIncoming,
|
|
132
|
-
}),
|
|
133
|
-
ifilter(where),
|
|
134
|
-
toArray(),
|
|
135
|
-
partition(r => r.target === target),
|
|
136
|
-
([incoming, outgoing]) =>
|
|
137
|
-
concat(
|
|
138
|
-
pipe(
|
|
139
|
-
outgoing,
|
|
140
|
-
filter(r => !isAncestorOrDescendantOf(target, r.target)),
|
|
141
|
-
map(outgoing =>
|
|
142
|
-
new ConnectionModel(
|
|
143
|
-
target,
|
|
144
|
-
outgoing.target,
|
|
145
|
-
new Set([outgoing]),
|
|
146
|
-
)
|
|
147
|
-
),
|
|
148
|
-
),
|
|
149
|
-
pipe(
|
|
150
|
-
incoming,
|
|
151
|
-
filter(r => !isAncestorOrDescendantOf(target, r.source)),
|
|
152
|
-
map(incoming =>
|
|
153
|
-
new ConnectionModel(
|
|
154
|
-
incoming.source,
|
|
155
|
-
target,
|
|
156
|
-
new Set([incoming]),
|
|
157
|
-
)
|
|
158
|
-
),
|
|
159
|
-
),
|
|
160
|
-
),
|
|
161
|
-
)
|
|
162
|
-
),
|
|
163
|
-
)
|
|
164
|
-
stage.addConnections(connections)
|
|
165
|
-
return stage
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// * -> element
|
|
169
|
-
case sourceIsWildcard && !targetIsWildcard: {
|
|
170
|
-
const [targets, sources] = resolveWildcard(target, { memory, model })
|
|
171
|
-
const dir = isBidirectional ? 'both' : 'directed'
|
|
172
|
-
for (const source of sources) {
|
|
173
|
-
connections.push(
|
|
174
|
-
...findConnectionsBetween(source, targets, dir),
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
break
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
default: {
|
|
181
|
-
invariant(!isWildcard(source), 'Inference failed - source must be not a wildcard')
|
|
182
|
-
invariant(!isWildcard(target), 'Inference failed - target must be not a wildcard')
|
|
183
|
-
const sources = resolveAndIncludeFromMemory(source, { memory, model })
|
|
184
|
-
const targets = resolveAndIncludeFromMemory(target, { memory, model })
|
|
185
|
-
const dir = isBidirectional ? 'both' : 'directed'
|
|
186
|
-
for (const source of sources) {
|
|
187
|
-
connections.push(
|
|
188
|
-
...findConnectionsBetween(source, targets, dir),
|
|
189
|
-
)
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
stage.addConnections(
|
|
195
|
-
filterWhere(connections),
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
return stage
|
|
199
|
-
},
|
|
200
|
-
exclude: ({ expr: { source, target, isBidirectional }, model, memory, stage, where }) => {
|
|
201
|
-
const sourceIsWildcard = isWildcard(source)
|
|
202
|
-
const targetIsWildcard = isWildcard(target)
|
|
203
|
-
|
|
204
|
-
let relations: Set<RelationshipModel<AnyAux>>
|
|
205
|
-
|
|
206
|
-
switch (true) {
|
|
207
|
-
// * -> *
|
|
208
|
-
case sourceIsWildcard && targetIsWildcard: {
|
|
209
|
-
relations = pipe(
|
|
210
|
-
memory.connections,
|
|
211
|
-
flatMap(piped(
|
|
212
|
-
prop('relations'),
|
|
213
|
-
ifilter(where),
|
|
214
|
-
toArray(),
|
|
215
|
-
)),
|
|
216
|
-
toSet(),
|
|
217
|
-
)
|
|
218
|
-
break
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// element -> *
|
|
222
|
-
case !sourceIsWildcard && targetIsWildcard: {
|
|
223
|
-
const sources = resolveElements(model, source)
|
|
224
|
-
relations = pipe(
|
|
225
|
-
sources,
|
|
226
|
-
flatMap(source =>
|
|
227
|
-
pipe(
|
|
228
|
-
source,
|
|
229
|
-
when(constant(isBidirectional === true), {
|
|
230
|
-
onTrue: s => union(s.allIncoming, s.allOutgoing),
|
|
231
|
-
onFalse: s => s.allOutgoing,
|
|
232
|
-
}),
|
|
233
|
-
ifilter(where),
|
|
234
|
-
toArray(),
|
|
235
|
-
)
|
|
236
|
-
),
|
|
237
|
-
toSet(),
|
|
238
|
-
)
|
|
239
|
-
break
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// * -> element
|
|
243
|
-
case sourceIsWildcard && !targetIsWildcard: {
|
|
244
|
-
const targets = resolveElements(model, target)
|
|
245
|
-
relations = pipe(
|
|
246
|
-
targets,
|
|
247
|
-
flatMap(target =>
|
|
248
|
-
pipe(
|
|
249
|
-
target,
|
|
250
|
-
when(constant(isBidirectional === true), {
|
|
251
|
-
onTrue: s => union(s.allIncoming, s.allOutgoing),
|
|
252
|
-
onFalse: s => s.allIncoming,
|
|
253
|
-
}),
|
|
254
|
-
ifilter(where),
|
|
255
|
-
toArray(),
|
|
256
|
-
)
|
|
257
|
-
),
|
|
258
|
-
toSet(),
|
|
259
|
-
)
|
|
260
|
-
break
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
default: {
|
|
264
|
-
invariant(!isWildcard(source), 'Inferrence failed - source must be not a wildcard')
|
|
265
|
-
invariant(!isWildcard(target), 'Inferrence failed - target must be not a wildcard')
|
|
266
|
-
const sources = resolveElements(model, source)
|
|
267
|
-
const targets = resolveElements(model, target)
|
|
268
|
-
|
|
269
|
-
let accum = new Set<RelationshipModel<AnyAux>>()
|
|
270
|
-
for (const source of sources) {
|
|
271
|
-
for (const target of targets) {
|
|
272
|
-
if (isSameHierarchy(source, target)) {
|
|
273
|
-
continue
|
|
274
|
-
}
|
|
275
|
-
accum = union(
|
|
276
|
-
accum,
|
|
277
|
-
intersection(source.allOutgoing, target.allIncoming),
|
|
278
|
-
isBidirectional ? intersection(target.allOutgoing, source.allIncoming) : new Set(),
|
|
279
|
-
)
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
relations = toSet(ifilter(accum, where))
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
stage.excludeRelations(relations)
|
|
288
|
-
return stage
|
|
289
|
-
},
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Resolve elements for both source and target, when one of them is a wildcard
|
|
294
|
-
*/
|
|
295
|
-
function resolveWildcard(
|
|
296
|
-
nonWildcard: ModelFqnExpr.NonWildcard,
|
|
297
|
-
{ memory, model }: Pick<PredicateCtx, 'model' | 'memory'>,
|
|
298
|
-
): [elements: Elem[], wildcard: Elem[]] {
|
|
299
|
-
let sources = resolveElements(model, nonWildcard)
|
|
300
|
-
if (!hasAtLeast(sources, 1)) {
|
|
301
|
-
return [[], []]
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (ModelFqnExpr.isModelRef(nonWildcard)) {
|
|
305
|
-
const parent = model.element(FqnRef.flatten(nonWildcard.ref))
|
|
306
|
-
const targets = toArray(parent.ascendingSiblings())
|
|
307
|
-
return [
|
|
308
|
-
includeDescendantsFromMemory(sources, memory),
|
|
309
|
-
includeDescendantsFromMemory(targets, memory),
|
|
310
|
-
]
|
|
311
|
-
}
|
|
312
|
-
const targets = pipe(
|
|
313
|
-
sources,
|
|
314
|
-
map(el => el.ascendingSiblings()),
|
|
315
|
-
iflat(),
|
|
316
|
-
iunique(),
|
|
317
|
-
toArray(),
|
|
318
|
-
all => includeDescendantsFromMemory(all, memory),
|
|
319
|
-
)
|
|
320
|
-
return [sources, targets]
|
|
321
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { unique } from 'remeda'
|
|
2
|
-
import { type ConnectionModel } from '../../../model'
|
|
3
|
-
import type { RelationshipModel } from '../../../model'
|
|
4
|
-
import { type AnyAux, type ModelRelationExpr, ModelFqnExpr } from '../../../types'
|
|
5
|
-
import { toArray, toSet } from '../../../utils/iterable/to'
|
|
6
|
-
import type { PredicateExecutor } from '../_types'
|
|
7
|
-
import { findConnectionsBetween, resolveAndIncludeFromMemory, resolveElements } from './_utils'
|
|
8
|
-
|
|
9
|
-
export const InOutRelationPredicate: PredicateExecutor<ModelRelationExpr.InOut<AnyAux>> = {
|
|
10
|
-
include: ({ expr: { inout }, scope, model, memory, stage, filterWhere }) => {
|
|
11
|
-
const connections = [] as ConnectionModel<AnyAux>[]
|
|
12
|
-
if (ModelFqnExpr.isWildcard(inout)) {
|
|
13
|
-
if (!scope) {
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
connections.push(
|
|
17
|
-
...findConnectionsBetween(
|
|
18
|
-
scope,
|
|
19
|
-
scope.ascendingSiblings(),
|
|
20
|
-
),
|
|
21
|
-
)
|
|
22
|
-
} else {
|
|
23
|
-
const elements = resolveAndIncludeFromMemory(inout, { memory, model })
|
|
24
|
-
let visibleElements = [...memory.elements]
|
|
25
|
-
if (visibleElements.length === 0) {
|
|
26
|
-
visibleElements = unique(
|
|
27
|
-
elements.flatMap(el => toArray(el.ascendingSiblings())),
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
for (const el of elements) {
|
|
31
|
-
connections.push(
|
|
32
|
-
...findConnectionsBetween(
|
|
33
|
-
el,
|
|
34
|
-
visibleElements,
|
|
35
|
-
),
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
stage.addConnections(
|
|
41
|
-
filterWhere(connections),
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
return stage
|
|
45
|
-
},
|
|
46
|
-
exclude: ({ expr: { inout }, model, scope, stage, where }) => {
|
|
47
|
-
const excluded = [] as RelationshipModel[]
|
|
48
|
-
if (ModelFqnExpr.isWildcard(inout)) {
|
|
49
|
-
if (!scope) {
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
excluded.push(...scope.allOutgoing)
|
|
53
|
-
excluded.push(...scope.allIncoming)
|
|
54
|
-
} else {
|
|
55
|
-
const elements = resolveElements(model, inout)
|
|
56
|
-
excluded.push(
|
|
57
|
-
...elements.flatMap(e => [...e.allOutgoing, ...e.allIncoming]),
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
stage.excludeRelations(toSet(excluded.filter(where)))
|
|
61
|
-
|
|
62
|
-
return stage
|
|
63
|
-
},
|
|
64
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { anyPass, unique } from 'remeda'
|
|
2
|
-
import { type ConnectionModel, type LikeC4Model, type RelationshipModel, Connection } from '../../../model'
|
|
3
|
-
import type { ModelRelationExpr } from '../../../types'
|
|
4
|
-
import { type AnyAux, FqnRef, ModelFqnExpr } from '../../../types'
|
|
5
|
-
import { nonexhaustive } from '../../../utils'
|
|
6
|
-
import { elementExprToPredicate } from '../../utils/elementExpressionToPredicate'
|
|
7
|
-
import type { ConnectionWhere, PredicateExecutor } from '../_types'
|
|
8
|
-
import { findConnection, findConnectionsBetween, resolveAndIncludeFromMemory, resolveElements } from './_utils'
|
|
9
|
-
|
|
10
|
-
export const IncomingExprPredicate: PredicateExecutor<ModelRelationExpr.Incoming<AnyAux>> = {
|
|
11
|
-
include: ({ expr, scope, model, memory, stage, filterWhere }) => {
|
|
12
|
-
const target = expr.incoming
|
|
13
|
-
const connections = [] as ConnectionModel<AnyAux>[]
|
|
14
|
-
if (ModelFqnExpr.isWildcard(target)) {
|
|
15
|
-
if (!scope) {
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
for (const sibling of scope.ascendingSiblings()) {
|
|
19
|
-
connections.push(
|
|
20
|
-
...findConnection(
|
|
21
|
-
sibling,
|
|
22
|
-
scope,
|
|
23
|
-
'directed',
|
|
24
|
-
),
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
const targets = resolveAndIncludeFromMemory(target, { memory, model })
|
|
29
|
-
const visibleElements = [...memory.elements]
|
|
30
|
-
if (visibleElements.length === 0) {
|
|
31
|
-
visibleElements.push(
|
|
32
|
-
...unique(
|
|
33
|
-
targets.flatMap(el => [...el.ascendingSiblings()]),
|
|
34
|
-
),
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
const ensureIncoming = incomingConnectionPredicate(model, target)
|
|
38
|
-
for (const visible of visibleElements) {
|
|
39
|
-
connections.push(
|
|
40
|
-
...findConnectionsBetween(
|
|
41
|
-
visible,
|
|
42
|
-
targets,
|
|
43
|
-
'directed',
|
|
44
|
-
).filter(ensureIncoming),
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
stage.addConnections(
|
|
50
|
-
filterWhere(connections),
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
return stage
|
|
54
|
-
},
|
|
55
|
-
exclude: ({ expr: { incoming }, model, scope, stage, where }) => {
|
|
56
|
-
const excluded = [] as RelationshipModel[]
|
|
57
|
-
if (ModelFqnExpr.isWildcard(incoming)) {
|
|
58
|
-
if (!scope) {
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
excluded.push(...scope.allIncoming)
|
|
62
|
-
} else {
|
|
63
|
-
const elements = resolveElements(model, incoming)
|
|
64
|
-
excluded.push(
|
|
65
|
-
...elements.flatMap(e => [...e.allIncoming]),
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
stage.excludeRelations(new Set(excluded.filter(where)))
|
|
69
|
-
|
|
70
|
-
return stage
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function incomingConnectionPredicate(
|
|
75
|
-
model: LikeC4Model,
|
|
76
|
-
expr: ModelFqnExpr.NonWildcard,
|
|
77
|
-
): ConnectionWhere {
|
|
78
|
-
switch (true) {
|
|
79
|
-
case ModelFqnExpr.isElementKindExpr(expr):
|
|
80
|
-
case ModelFqnExpr.isElementTagExpr(expr): {
|
|
81
|
-
const isElement = elementExprToPredicate(expr)
|
|
82
|
-
return (connection) => isElement(connection.target)
|
|
83
|
-
}
|
|
84
|
-
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'children': {
|
|
85
|
-
const fqn = FqnRef.flatten(expr.ref)
|
|
86
|
-
return anyPass(
|
|
87
|
-
[...model.children(fqn)].map(
|
|
88
|
-
el => Connection.isIncoming(el.id),
|
|
89
|
-
),
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'descendants': {
|
|
93
|
-
const fqn = FqnRef.flatten(expr.ref)
|
|
94
|
-
return anyPass([
|
|
95
|
-
Connection.isInside(fqn),
|
|
96
|
-
...[...model.children(fqn)].map(
|
|
97
|
-
el => Connection.isIncoming(el.id),
|
|
98
|
-
),
|
|
99
|
-
])
|
|
100
|
-
}
|
|
101
|
-
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'expanded': {
|
|
102
|
-
const fqn = FqnRef.flatten(expr.ref)
|
|
103
|
-
return anyPass([
|
|
104
|
-
Connection.isIncoming(fqn),
|
|
105
|
-
Connection.isInside(fqn),
|
|
106
|
-
])
|
|
107
|
-
}
|
|
108
|
-
case ModelFqnExpr.isModelRef(expr): {
|
|
109
|
-
const fqn = FqnRef.flatten(expr.ref)
|
|
110
|
-
return Connection.isIncoming(fqn)
|
|
111
|
-
}
|
|
112
|
-
default:
|
|
113
|
-
nonexhaustive(expr)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { anyPass, unique } from 'remeda'
|
|
2
|
-
import type { LikeC4Model, RelationshipModel } from '../../../model'
|
|
3
|
-
import { type ConnectionModel, Connection } from '../../../model'
|
|
4
|
-
import type { AnyAux } from '../../../types'
|
|
5
|
-
import { type ModelRelationExpr, FqnRef, ModelFqnExpr } from '../../../types'
|
|
6
|
-
import { nonexhaustive } from '../../../utils'
|
|
7
|
-
import { toSet } from '../../../utils/iterable/to'
|
|
8
|
-
import { elementExprToPredicate } from '../../utils/elementExpressionToPredicate'
|
|
9
|
-
import type { ConnectionWhere, PredicateExecutor } from '../_types'
|
|
10
|
-
import { findConnectionsBetween, resolveAndIncludeFromMemory, resolveElements } from './_utils'
|
|
11
|
-
|
|
12
|
-
export const OutgoingExprPredicate: PredicateExecutor<ModelRelationExpr.Outgoing<AnyAux>> = {
|
|
13
|
-
include: ({ expr, scope, model, memory, stage, filterWhere }) => {
|
|
14
|
-
const target = expr.outgoing
|
|
15
|
-
const connections = [] as ConnectionModel<AnyAux>[]
|
|
16
|
-
if (ModelFqnExpr.isWildcard(target)) {
|
|
17
|
-
if (!scope) {
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
connections.push(
|
|
22
|
-
...findConnectionsBetween(
|
|
23
|
-
scope,
|
|
24
|
-
scope.ascendingSiblings(),
|
|
25
|
-
'directed',
|
|
26
|
-
),
|
|
27
|
-
)
|
|
28
|
-
} else {
|
|
29
|
-
const elements = resolveAndIncludeFromMemory(target, { memory, model })
|
|
30
|
-
const visibleElements = [...memory.elements]
|
|
31
|
-
if (visibleElements.length === 0) {
|
|
32
|
-
visibleElements.push(
|
|
33
|
-
...unique(
|
|
34
|
-
elements.flatMap(el => [...el.ascendingSiblings()]),
|
|
35
|
-
),
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
const ensureOutgoing = outgoingConnectionPredicate(model, target)
|
|
39
|
-
|
|
40
|
-
for (const source of elements) {
|
|
41
|
-
connections.push(
|
|
42
|
-
...findConnectionsBetween(
|
|
43
|
-
source,
|
|
44
|
-
visibleElements,
|
|
45
|
-
'directed',
|
|
46
|
-
).filter(ensureOutgoing),
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
stage.addConnections(
|
|
52
|
-
filterWhere(connections),
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
return stage
|
|
56
|
-
},
|
|
57
|
-
exclude: ({ expr: { outgoing }, model, scope, stage, where }) => {
|
|
58
|
-
const excluded = [] as RelationshipModel[]
|
|
59
|
-
if (ModelFqnExpr.isWildcard(outgoing)) {
|
|
60
|
-
if (!scope) {
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
excluded.push(...scope.allOutgoing)
|
|
64
|
-
} else {
|
|
65
|
-
const elements = resolveElements(model, outgoing)
|
|
66
|
-
excluded.push(
|
|
67
|
-
...elements.flatMap(e => [...e.allOutgoing]),
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
stage.excludeRelations(
|
|
71
|
-
toSet(excluded.filter(where)),
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
return stage
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function outgoingConnectionPredicate(
|
|
79
|
-
model: LikeC4Model,
|
|
80
|
-
expr: ModelFqnExpr.NonWildcard,
|
|
81
|
-
): ConnectionWhere {
|
|
82
|
-
switch (true) {
|
|
83
|
-
case ModelFqnExpr.isElementKindExpr(expr):
|
|
84
|
-
case ModelFqnExpr.isElementTagExpr(expr): {
|
|
85
|
-
const isElement = elementExprToPredicate(expr)
|
|
86
|
-
return (connection) => isElement(connection.source)
|
|
87
|
-
}
|
|
88
|
-
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'children': {
|
|
89
|
-
const fqn = FqnRef.flatten(expr.ref)
|
|
90
|
-
return anyPass(
|
|
91
|
-
[...model.children(fqn)].map(
|
|
92
|
-
el => Connection.isOutgoing(el.id),
|
|
93
|
-
),
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'descendants': {
|
|
97
|
-
const fqn = FqnRef.flatten(expr.ref)
|
|
98
|
-
return anyPass([
|
|
99
|
-
Connection.isInside(fqn),
|
|
100
|
-
...[...model.children(fqn)].map(
|
|
101
|
-
el => Connection.isOutgoing(el.id),
|
|
102
|
-
),
|
|
103
|
-
])
|
|
104
|
-
}
|
|
105
|
-
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'expanded': {
|
|
106
|
-
const fqn = FqnRef.flatten(expr.ref)
|
|
107
|
-
return anyPass([
|
|
108
|
-
Connection.isOutgoing(fqn),
|
|
109
|
-
Connection.isInside(fqn),
|
|
110
|
-
])
|
|
111
|
-
}
|
|
112
|
-
case ModelFqnExpr.isModelRef(expr): {
|
|
113
|
-
const fqn = FqnRef.flatten(expr.ref)
|
|
114
|
-
return Connection.isOutgoing(fqn)
|
|
115
|
-
}
|
|
116
|
-
default:
|
|
117
|
-
nonexhaustive(expr)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { filter } from 'remeda'
|
|
2
|
-
import type { ModelFqnExpr } from '../../../types'
|
|
3
|
-
import { ifilter, toArray } from '../../../utils/iterable'
|
|
4
|
-
import { toSet } from '../../../utils/iterable/to'
|
|
5
|
-
import { type PredicateExecutor, Memory } from '../_types'
|
|
6
|
-
import { NoWhere } from '../utils'
|
|
7
|
-
import { findConnectionsBetween, findConnectionsWithin } from './_utils'
|
|
8
|
-
|
|
9
|
-
export const WildcardPredicate: PredicateExecutor<ModelFqnExpr.Wildcard> = {
|
|
10
|
-
include: ({ scope, model, stage, memory, where }) => {
|
|
11
|
-
if (!scope) {
|
|
12
|
-
const rootElements = [...model.roots()].filter(where)
|
|
13
|
-
if (rootElements.length === 0) {
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
stage.addExplicit(rootElements)
|
|
17
|
-
stage.addConnections(findConnectionsWithin(rootElements))
|
|
18
|
-
|
|
19
|
-
stage.connectWithExisting(rootElements)
|
|
20
|
-
|
|
21
|
-
return stage
|
|
22
|
-
}
|
|
23
|
-
const root = where(scope) ? scope : null
|
|
24
|
-
|
|
25
|
-
const children = toArray(ifilter(scope.children(), where))
|
|
26
|
-
const hasChildren = children.length > 0
|
|
27
|
-
if (!hasChildren) {
|
|
28
|
-
if (!root) {
|
|
29
|
-
return stage
|
|
30
|
-
} else {
|
|
31
|
-
// Any edges with siblings?
|
|
32
|
-
const edgesWithSiblings = findConnectionsBetween(root, root.siblings())
|
|
33
|
-
if (edgesWithSiblings.length === 0) {
|
|
34
|
-
// If no edges with siblings, i.e. root is orphan
|
|
35
|
-
// Lets add parent for better view
|
|
36
|
-
const parent = root.parent
|
|
37
|
-
if (parent && where(parent)) {
|
|
38
|
-
stage.addExplicit(parent)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
children.push(root)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (root) {
|
|
46
|
-
stage.addExplicit(root)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const neighbours = toSet([
|
|
50
|
-
...memory.elements,
|
|
51
|
-
...scope.descendingSiblings(),
|
|
52
|
-
])
|
|
53
|
-
|
|
54
|
-
// Add incoming connections
|
|
55
|
-
for (const neighbour of neighbours) {
|
|
56
|
-
stage.addConnections(findConnectionsBetween(neighbour, children, 'directed'))
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// connection between children
|
|
60
|
-
if (hasChildren) {
|
|
61
|
-
stage.addConnections(findConnectionsWithin(children))
|
|
62
|
-
stage.addExplicit(children)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Add outgoing connections
|
|
66
|
-
for (const child of children) {
|
|
67
|
-
stage.addConnections(findConnectionsBetween(child, neighbours, 'directed'))
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return stage
|
|
71
|
-
},
|
|
72
|
-
exclude: ({ scope, memory, stage, where }) => {
|
|
73
|
-
if (where !== NoWhere) {
|
|
74
|
-
stage.exclude(
|
|
75
|
-
filter(
|
|
76
|
-
[...memory.elements],
|
|
77
|
-
where,
|
|
78
|
-
),
|
|
79
|
-
)
|
|
80
|
-
return stage
|
|
81
|
-
}
|
|
82
|
-
if (scope) {
|
|
83
|
-
stage.exclude([scope, ...scope.descendants()])
|
|
84
|
-
return stage
|
|
85
|
-
}
|
|
86
|
-
return Memory.empty(memory.scope).stageExclude(stage.expression)
|
|
87
|
-
},
|
|
88
|
-
}
|