@likec4/core 1.31.0 → 1.32.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/README.md +407 -5
- package/dist/builder/index.d.mts +221 -42
- package/dist/builder/index.mjs +118 -65
- package/dist/compute-view/index.d.mts +23 -7
- package/dist/compute-view/index.mjs +11 -6
- package/dist/compute-view/relationships-view/index.d.mts +9 -7
- package/dist/compute-view/relationships-view/index.mjs +3 -2
- package/dist/index.d.mts +10 -14
- package/dist/index.mjs +9 -6
- package/dist/model/index.d.mts +173 -19
- package/dist/model/index.mjs +6 -1
- package/dist/shared/core.BaYE_r29.d.mts +258 -0
- package/dist/shared/core.Bk7wEZFG.mjs +276 -0
- package/dist/shared/core.BrCnZFTn.mjs +32 -0
- package/dist/shared/core.BuO4ncfY.d.mts +146 -0
- package/dist/shared/{core.Bq753SYD.mjs → core.CBpKAlhj.mjs} +2012 -4422
- package/dist/shared/core.CUYDgv2-.mjs +214 -0
- package/dist/shared/{core.Cu-UdkSl.mjs → core.CpXlRyE5.mjs} +7 -494
- package/dist/shared/{core.C-YXI-43.mjs → core.Cy9smucx.mjs} +3 -1
- package/dist/shared/core.CywrQs86.d.mts +31 -0
- package/dist/shared/core.DXzRBkuI.d.mts +1264 -0
- package/dist/shared/core.DoK86JEe.mjs +518 -0
- package/dist/shared/{core.D2830qgg.d.mts → core.Pf5I9o0e.d.mts} +1 -1
- package/dist/shared/core.cbA9VZ02.mjs +2681 -0
- package/dist/shared/{core.CQXU9DF7.mjs → core.rmvsy0n3.mjs} +23 -32
- package/dist/shared/core.znRaUX_A.d.mts +920 -0
- package/dist/types/aux.d.mts +3 -0
- package/dist/types/aux.mjs +1 -0
- package/dist/types/index.d.mts +7 -45
- package/dist/types/index.mjs +130 -3
- package/dist/utils/index.d.mts +221 -53
- package/dist/utils/index.mjs +14 -10
- package/package.json +16 -8
- package/src/builder/Builder.deploymentModel.ts +82 -18
- package/src/builder/Builder.element.ts +40 -20
- package/src/builder/Builder.model.ts +66 -17
- package/src/builder/Builder.ts +168 -76
- package/src/builder/Builder.view-common.ts +35 -17
- package/src/builder/Builder.view-deployment.ts +25 -25
- package/src/builder/Builder.view-element.ts +13 -12
- package/src/builder/Builder.views.ts +12 -7
- package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +62 -34
- package/src/builder/__snapshots__/Builder-style2.compute-model.json5 +319 -0
- package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +45 -24
- package/src/builder/_types.ts +34 -27
- package/src/compute-view/compute-view.ts +31 -34
- package/src/compute-view/deployment-view/__test__/TestHelper.ts +27 -14
- package/src/compute-view/deployment-view/__test__/fixture.ts +15 -13
- package/src/compute-view/deployment-view/_types.ts +10 -10
- package/src/compute-view/deployment-view/clean-connections.ts +5 -7
- package/src/compute-view/deployment-view/compute.ts +16 -13
- package/src/compute-view/deployment-view/memory/memory.ts +5 -6
- package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +4 -5
- package/src/compute-view/deployment-view/predicates/relation-direct.ts +25 -50
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +5 -7
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +7 -11
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +7 -10
- package/src/compute-view/deployment-view/predicates/utils.ts +37 -31
- package/src/compute-view/deployment-view/predicates/wildcard.ts +3 -2
- package/src/compute-view/deployment-view/stages/stage-final.ts +2 -2
- package/src/compute-view/deployment-view/stages/stage-include.ts +1 -1
- package/src/compute-view/deployment-view/utils.ts +79 -72
- package/src/compute-view/dynamic-view/__test__/fixture.ts +20 -11
- package/src/compute-view/dynamic-view/compute.ts +60 -53
- package/src/compute-view/element-view/__test__/TestHelper.ts +53 -29
- package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +26 -26
- package/src/compute-view/element-view/__test__/fixture.ts +134 -83
- package/src/compute-view/element-view/_types.ts +14 -19
- package/src/compute-view/element-view/clean-connections.ts +12 -8
- package/src/compute-view/element-view/compute.ts +61 -51
- package/src/compute-view/element-view/memory/NodeGroup.ts +8 -9
- package/src/compute-view/element-view/memory/memory.ts +22 -22
- package/src/compute-view/element-view/memory/stage-include.ts +5 -3
- package/src/compute-view/element-view/predicates/_utils.ts +18 -14
- package/src/compute-view/element-view/predicates/element-expand.ts +4 -5
- package/src/compute-view/element-view/predicates/element-kind-tag.ts +3 -4
- package/src/compute-view/element-view/predicates/element-ref.ts +3 -4
- package/src/compute-view/element-view/predicates/relation-direct.ts +16 -12
- package/src/compute-view/element-view/predicates/relation-in-out.ts +7 -8
- package/src/compute-view/element-view/predicates/relation-in.ts +19 -26
- package/src/compute-view/element-view/predicates/relation-out.ts +20 -21
- package/src/compute-view/element-view/predicates/wildcard.ts +3 -3
- package/src/compute-view/element-view/utils.ts +25 -23
- package/src/compute-view/index.ts +1 -1
- package/src/compute-view/memory/AbstractStageExclude.ts +3 -4
- package/src/compute-view/memory/AbstractStageInclude.ts +1 -1
- package/src/compute-view/memory/_types.ts +3 -2
- package/src/compute-view/relationships-view/_types.ts +3 -4
- package/src/compute-view/relationships-view/compute.ts +8 -11
- package/src/compute-view/relationships-view/layout.ts +6 -6
- package/src/compute-view/relationships-view/utils.ts +4 -4
- package/src/compute-view/utils/ancestorsOfNode.ts +7 -7
- package/src/compute-view/utils/applyCustomElementProperties.ts +16 -8
- package/src/compute-view/utils/applyCustomRelationProperties.ts +19 -9
- package/src/compute-view/utils/applyViewRuleStyles.ts +18 -10
- package/src/compute-view/utils/buildComputedNodes.ts +40 -40
- package/src/compute-view/utils/buildElementNotations.ts +14 -14
- package/src/compute-view/utils/elementExpressionToPredicate.ts +14 -15
- package/src/compute-view/utils/link-nodes-with-edges.ts +6 -4
- package/src/compute-view/utils/merge-props-from-relationships.ts +52 -20
- package/src/compute-view/utils/relationExpressionToPredicates.ts +19 -19
- package/src/compute-view/utils/resolve-extended-views.ts +8 -7
- package/src/compute-view/utils/resolve-global-rules.ts +31 -26
- package/src/compute-view/utils/topological-sort.ts +14 -14
- package/src/compute-view/utils/view-hash.ts +2 -2
- package/src/compute-view/utils/with-readable-edges.ts +9 -5
- package/src/index.ts +0 -32
- package/src/model/DeploymentElementModel.ts +171 -144
- package/src/model/DeploymentModel.ts +88 -65
- package/src/model/ElementModel.ts +85 -74
- package/src/model/LikeC4Model.ts +430 -241
- package/src/model/RelationModel.ts +63 -29
- package/src/model/__test__/fixture.ts +50 -36
- package/src/model/connection/Connection.ts +2 -2
- package/src/model/connection/deployment/DeploymentConnectionModel.ts +21 -24
- package/src/model/connection/deployment/find.ts +1 -1
- package/src/model/connection/model/ConnectionModel.ts +21 -20
- package/src/model/connection/model/find.ts +7 -7
- package/src/model/connection/ops.ts +6 -6
- package/src/model/guards.ts +66 -14
- package/src/model/index.ts +20 -7
- package/src/model/types.ts +41 -97
- package/src/model/view/EdgeModel.ts +47 -41
- package/src/model/view/LikeC4ViewModel.ts +130 -80
- package/src/model/view/NodeModel.ts +102 -96
- package/src/theme/element.ts +1 -1
- package/src/theme/index.ts +9 -9
- package/src/theme/relationships.ts +1 -1
- package/src/types/_common.ts +21 -15
- package/src/types/aux.ts +285 -0
- package/src/types/const.ts +34 -0
- package/src/types/expression-model.ts +292 -0
- package/src/types/expression.ts +311 -0
- package/src/types/fqnRef.ts +88 -0
- package/src/types/geometry.ts +131 -0
- package/src/types/global.ts +10 -8
- package/src/types/index.ts +39 -201
- package/src/types/model-data.ts +52 -84
- package/src/types/model-deployment.ts +87 -0
- package/src/types/model-dump.ts +72 -0
- package/src/types/model-logical.ts +111 -0
- package/src/types/model-spec.ts +81 -0
- package/src/types/operators.ts +51 -52
- package/src/types/scalar.ts +114 -0
- package/src/types/{theme.ts → styles.ts} +55 -15
- package/src/types/view-changes.ts +4 -5
- package/src/types/view-common.ts +157 -0
- package/src/types/view-computed.ts +113 -0
- package/src/types/view-layouted.ts +82 -0
- package/src/types/view-parsed.deployment.ts +40 -0
- package/src/types/view-parsed.dynamic.ts +78 -0
- package/src/types/view-parsed.element.ts +65 -0
- package/src/types/view.ts +122 -542
- package/src/utils/compare-natural.ts +43 -1
- package/src/utils/getOrCreate.ts +0 -34
- package/src/utils/index.ts +7 -12
- package/src/utils/iterable/filter.ts +1 -1
- package/src/utils/iterable/find.ts +3 -1
- package/src/utils/iterable/head.ts +22 -0
- package/src/utils/iterable/index.ts +1 -0
- package/src/utils/iterable/map.ts +1 -1
- package/src/utils/iterable/reduce.ts +1 -1
- package/src/utils/iterable/some.ts +1 -1
- package/src/utils/memoize-prop.ts +30 -0
- package/src/utils/object-hash.ts +1 -1
- package/src/utils/relations.ts +14 -11
- package/src/utils/string-hash.ts +1 -1
- package/dist/shared/core.CQDU11hR.d.mts +0 -753
- package/dist/shared/core.DJvmfnEi.d.mts +0 -1153
- package/dist/shared/core.DgfwjBtu.mjs +0 -495
- package/dist/shared/core.Dx7siloV.d.mts +0 -146
- package/dist/shared/core.SjLhMA7a.d.mts +0 -62
- package/src/builder/__snapshots__/Builder.spec.ts.snap +0 -374
- package/src/compute-view/element-view/predicates.ts +0 -520
- package/src/compute-view/utils/uniqueTags.ts +0 -21
- package/src/types/deployments.ts +0 -170
- package/src/types/element.ts +0 -109
- package/src/types/expression-v2-model.ts +0 -314
- package/src/types/expression-v2.ts +0 -392
- package/src/types/overview-graph.ts +0 -43
- package/src/types/relation.ts +0 -61
- package/src/types/scalars.ts +0 -39
- package/src/types/view-notation.ts +0 -9
- package/src/utils/graphlib.ts +0 -10
- /package/src/{errors/index.ts → utils/invariant.ts} +0 -0
|
@@ -1,520 +0,0 @@
|
|
|
1
|
-
// import { allPass, filter as remedaFilter, flatMap, isNullish as isNil, map, pipe, unique } from 'remeda'
|
|
2
|
-
// import type { Writable } from 'type-fest'
|
|
3
|
-
// import { nonexhaustive } from '../../errors'
|
|
4
|
-
// import type { Element, Filterable, ModelRelation } from '../../types'
|
|
5
|
-
// import * as Expr from '../../types/expression'
|
|
6
|
-
// import { isAncestor, parentFqn } from '../../utils/fqn'
|
|
7
|
-
// import { elementExprToPredicate } from '../utils/elementExpressionToPredicate'
|
|
8
|
-
// import type { ComputeCtx } from './compute'
|
|
9
|
-
|
|
10
|
-
// type Predicate<T> = (x: T) => boolean
|
|
11
|
-
// export type ElementPredicateFn = Predicate<Element>
|
|
12
|
-
// export type RelationPredicateFn = Predicate<Filterable>
|
|
13
|
-
// // export type RelationPredicateFn = Predicate<ModelRelation>
|
|
14
|
-
// // // type ElementPredicate = Predicate<Element>
|
|
15
|
-
// // type ElementPredicates<T> = T extends Element[] ? (x: T) => T : (T extends Element ? (x: T) => (Element | null) : never)
|
|
16
|
-
// // type ElementPredicate = ElementPredicates<Element | Element[]>
|
|
17
|
-
|
|
18
|
-
// const NoFilter: ElementPredicateFn = () => true
|
|
19
|
-
// const Identity = <T>(x: T) => x
|
|
20
|
-
// const filterBy = <T>(pred: Predicate<T>) => pred === NoFilter ? Identity : remedaFilter(pred)
|
|
21
|
-
// const filterOne = <T>(pred: Predicate<T>) => pred === NoFilter ? Identity : (x: T) => pred(x) ? x : null
|
|
22
|
-
|
|
23
|
-
// export function expandWildcardRef(this: ComputeCtx, expr: Expr.ElementRefExpr) {
|
|
24
|
-
// if (expr.isChildren) {
|
|
25
|
-
// const children = this.graph.children(expr.element)
|
|
26
|
-
// return children.length > 0 ? children : [this.graph.element(expr.element)]
|
|
27
|
-
// } else if (expr.isDescendants) {
|
|
28
|
-
// return this.graph.descendants(expr.element)
|
|
29
|
-
// } else {
|
|
30
|
-
// return [this.graph.element(expr.element)]
|
|
31
|
-
// }
|
|
32
|
-
// }
|
|
33
|
-
|
|
34
|
-
// export function includeElementRef(this: ComputeCtx, expr: Expr.ElementRefExpr, where = NoFilter) {
|
|
35
|
-
// // Get the elements that are already in the Ctx before any mutations
|
|
36
|
-
// // Because we need to add edges between them and the new elements
|
|
37
|
-
// const currentElements = [...this.resolvedElements]
|
|
38
|
-
// const filter = filterBy(where)
|
|
39
|
-
|
|
40
|
-
// const elements = filter(expandWildcardRef.call(this, expr))
|
|
41
|
-
// if (elements.length === 0) {
|
|
42
|
-
// return
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
// this.addElement(...elements)
|
|
46
|
-
|
|
47
|
-
// if (elements.length > 1) {
|
|
48
|
-
// this.addEdges(this.graph.edgesWithin(elements))
|
|
49
|
-
// }
|
|
50
|
-
|
|
51
|
-
// if (currentElements.length > 0 && elements.length > 0) {
|
|
52
|
-
// for (const el of elements) {
|
|
53
|
-
// this.addEdges(this.graph.anyEdgesBetween(el, currentElements))
|
|
54
|
-
// }
|
|
55
|
-
// }
|
|
56
|
-
// }
|
|
57
|
-
|
|
58
|
-
// export function excludeElementRef(this: ComputeCtx, expr: Expr.ElementRefExpr, where = NoFilter) {
|
|
59
|
-
// const elements = [...this.resolvedElements].filter(allPass([
|
|
60
|
-
// elementExprToPredicate(expr),
|
|
61
|
-
// where
|
|
62
|
-
// ]))
|
|
63
|
-
// this.excludeElement(...elements)
|
|
64
|
-
// }
|
|
65
|
-
|
|
66
|
-
// export function includeWildcardRef(this: ComputeCtx, _expr: Expr.WildcardExpr, where = NoFilter) {
|
|
67
|
-
// const root = this.root
|
|
68
|
-
// if (!root) {
|
|
69
|
-
// // Take root elements
|
|
70
|
-
// const elements = this.graph.rootElements.filter(where)
|
|
71
|
-
// if (elements.length <= 0) {
|
|
72
|
-
// return
|
|
73
|
-
// }
|
|
74
|
-
// const currentElements = [...this.resolvedElements]
|
|
75
|
-
// this.addElement(...elements)
|
|
76
|
-
// this.addEdges(this.graph.edgesWithin(elements))
|
|
77
|
-
// if (currentElements.length > 0) {
|
|
78
|
-
// for (const el of elements) {
|
|
79
|
-
// this.addEdges(this.graph.anyEdgesBetween(el, currentElements))
|
|
80
|
-
// }
|
|
81
|
-
// }
|
|
82
|
-
// return
|
|
83
|
-
// }
|
|
84
|
-
|
|
85
|
-
// const currentElements = [...this.resolvedElements]
|
|
86
|
-
// const _elRoot = filterOne(where)(this.graph.element(root))
|
|
87
|
-
// if (_elRoot) {
|
|
88
|
-
// this.addElement(_elRoot)
|
|
89
|
-
// }
|
|
90
|
-
// const filter = filterBy(where)
|
|
91
|
-
|
|
92
|
-
// const children = filter(this.graph.children(root))
|
|
93
|
-
// const hasChildren = children.length > 0
|
|
94
|
-
// if (hasChildren) {
|
|
95
|
-
// this.addElement(...children)
|
|
96
|
-
// this.addEdges(this.graph.edgesWithin(children))
|
|
97
|
-
// } else if (_elRoot) {
|
|
98
|
-
// children.push(_elRoot)
|
|
99
|
-
// }
|
|
100
|
-
|
|
101
|
-
// // All neighbours that may have relations with root or its children
|
|
102
|
-
// const neighbours = [
|
|
103
|
-
// ...currentElements,
|
|
104
|
-
// ...filter([
|
|
105
|
-
// ...this.graph.siblings(root),
|
|
106
|
-
// ...this.graph.ancestors(root).flatMap(a => this.graph.siblings(a.id))
|
|
107
|
-
// ])
|
|
108
|
-
// ]
|
|
109
|
-
|
|
110
|
-
// for (const el of children) {
|
|
111
|
-
// this.addEdges(this.graph.anyEdgesBetween(el, neighbours)).forEach(edge => {
|
|
112
|
-
// this.addImplicit(edge.source, edge.target)
|
|
113
|
-
// })
|
|
114
|
-
// }
|
|
115
|
-
|
|
116
|
-
// // If root has no children
|
|
117
|
-
// if (!hasChildren && _elRoot) {
|
|
118
|
-
// // Any edges with siblings?
|
|
119
|
-
// const edgesWithSiblings = this.graph.anyEdgesBetween(_elRoot, this.graph.siblings(root))
|
|
120
|
-
// if (edgesWithSiblings.length === 0) {
|
|
121
|
-
// // If no edges with siblings, i.e. root is orphan
|
|
122
|
-
// // Lets add parent for better view
|
|
123
|
-
// const _parentId = parentFqn(root)
|
|
124
|
-
// const parent = _parentId && this.graph.element(_parentId)
|
|
125
|
-
// if (parent && where(parent)) {
|
|
126
|
-
// this.addElement(parent)
|
|
127
|
-
// }
|
|
128
|
-
// }
|
|
129
|
-
// }
|
|
130
|
-
// }
|
|
131
|
-
|
|
132
|
-
// export function excludeWildcardRef(this: ComputeCtx, _expr: Expr.WildcardExpr, where = NoFilter) {
|
|
133
|
-
// if (where !== NoFilter) {
|
|
134
|
-
// const elements = [...this.resolvedElements].filter(where)
|
|
135
|
-
// this.excludeElement(...elements)
|
|
136
|
-
// return
|
|
137
|
-
// }
|
|
138
|
-
// const root = this.root
|
|
139
|
-
// if (root) {
|
|
140
|
-
// this.excludeElement(
|
|
141
|
-
// this.graph.element(root),
|
|
142
|
-
// ...this.graph.children(root)
|
|
143
|
-
// )
|
|
144
|
-
// this.excludeRelation(
|
|
145
|
-
// ...this.graph.connectedRelations(root)
|
|
146
|
-
// )
|
|
147
|
-
// } else {
|
|
148
|
-
// this.reset()
|
|
149
|
-
// }
|
|
150
|
-
// }
|
|
151
|
-
|
|
152
|
-
// export function includeExpandedElementExpr(
|
|
153
|
-
// this: ComputeCtx,
|
|
154
|
-
// expr: Expr.ExpandedElementExpr,
|
|
155
|
-
// where = NoFilter
|
|
156
|
-
// ) {
|
|
157
|
-
// const filter = filterBy(where)
|
|
158
|
-
// const currentElements = [...this.resolvedElements]
|
|
159
|
-
|
|
160
|
-
// // Always add parent
|
|
161
|
-
// const parent = this.graph.element(expr.expanded)
|
|
162
|
-
// if (where(parent)) {
|
|
163
|
-
// this.addElement(parent)
|
|
164
|
-
// const anyEdgesBetween = this.graph.anyEdgesBetween(parent, currentElements)
|
|
165
|
-
// this.addEdges(anyEdgesBetween)
|
|
166
|
-
// }
|
|
167
|
-
|
|
168
|
-
// const expanded = [] as Element[]
|
|
169
|
-
|
|
170
|
-
// for (const el of filter(this.graph.children(expr.expanded))) {
|
|
171
|
-
// this.addImplicit(el)
|
|
172
|
-
// const edges = this.graph.anyEdgesBetween(el, currentElements)
|
|
173
|
-
// if (edges.length > 0) {
|
|
174
|
-
// this.addEdges(edges)
|
|
175
|
-
// expanded.push(el)
|
|
176
|
-
// }
|
|
177
|
-
// }
|
|
178
|
-
// if (expanded.length > 1) {
|
|
179
|
-
// this.addEdges(this.graph.edgesWithin(expanded))
|
|
180
|
-
// }
|
|
181
|
-
// }
|
|
182
|
-
|
|
183
|
-
// export function excludeExpandedElementExpr(
|
|
184
|
-
// this: ComputeCtx,
|
|
185
|
-
// expr: Expr.ExpandedElementExpr,
|
|
186
|
-
// where = NoFilter
|
|
187
|
-
// ) {
|
|
188
|
-
// const elements = [...this.resolvedElements].filter(allPass([
|
|
189
|
-
// elementExprToPredicate(expr),
|
|
190
|
-
// where
|
|
191
|
-
// ]))
|
|
192
|
-
// this.excludeElement(...elements)
|
|
193
|
-
// }
|
|
194
|
-
|
|
195
|
-
// const asElementPredicate = (
|
|
196
|
-
// expr: Expr.ElementKindExpr | Expr.ElementTagExpr
|
|
197
|
-
// ): Predicate<Element> => {
|
|
198
|
-
// if (expr.isEqual) {
|
|
199
|
-
// if (Expr.isElementKindExpr(expr)) {
|
|
200
|
-
// return e => e.kind === expr.elementKind
|
|
201
|
-
// } else {
|
|
202
|
-
// return ({ tags }) => !!tags && tags.includes(expr.elementTag)
|
|
203
|
-
// }
|
|
204
|
-
// } else {
|
|
205
|
-
// if (Expr.isElementKindExpr(expr)) {
|
|
206
|
-
// return e => e.kind !== expr.elementKind
|
|
207
|
-
// } else {
|
|
208
|
-
// return ({ tags }) => isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag)
|
|
209
|
-
// }
|
|
210
|
-
// }
|
|
211
|
-
// }
|
|
212
|
-
// export function includeElementKindOrTag(
|
|
213
|
-
// this: ComputeCtx,
|
|
214
|
-
// expr: Expr.ElementKindExpr | Expr.ElementTagExpr,
|
|
215
|
-
// where = NoFilter
|
|
216
|
-
// ) {
|
|
217
|
-
// const elements = this.graph.elements.filter(asElementPredicate(expr)).filter(where)
|
|
218
|
-
// if (elements.length > 0) {
|
|
219
|
-
// const currentElements = [...this.resolvedElements]
|
|
220
|
-
// this.addElement(...elements)
|
|
221
|
-
// this.addEdges(this.graph.edgesWithin(elements))
|
|
222
|
-
// for (const el of elements) {
|
|
223
|
-
// this.addEdges(this.graph.anyEdgesBetween(el, currentElements))
|
|
224
|
-
// }
|
|
225
|
-
// }
|
|
226
|
-
// }
|
|
227
|
-
|
|
228
|
-
// export function excludeElementKindOrTag(
|
|
229
|
-
// this: ComputeCtx,
|
|
230
|
-
// expr: Expr.ElementKindExpr | Expr.ElementTagExpr,
|
|
231
|
-
// where = NoFilter
|
|
232
|
-
// ) {
|
|
233
|
-
// const elements = [...this.resolvedElements].filter(asElementPredicate(expr)).filter(where)
|
|
234
|
-
// if (elements.length > 0) {
|
|
235
|
-
// this.excludeElement(...elements)
|
|
236
|
-
// }
|
|
237
|
-
// }
|
|
238
|
-
|
|
239
|
-
// function resolveNeighbours(this: ComputeCtx, expr: Expr.ElementExpression): Element[] {
|
|
240
|
-
// if (Expr.isElementRef(expr)) {
|
|
241
|
-
// return this.graph.ascendingSiblings(expr.element) as Writable<Element[]>
|
|
242
|
-
// }
|
|
243
|
-
// return this.root ? this.graph.ascendingSiblings(this.root) as Writable<Element[]> : this.graph.rootElements
|
|
244
|
-
// }
|
|
245
|
-
|
|
246
|
-
// function resolveElements(this: ComputeCtx, expr: Expr.ElementExpression): Element[] {
|
|
247
|
-
// if (Expr.isWildcard(expr)) {
|
|
248
|
-
// if (this.root) {
|
|
249
|
-
// return [...this.graph.children(this.root), this.graph.element(this.root)]
|
|
250
|
-
// } else {
|
|
251
|
-
// return this.graph.rootElements
|
|
252
|
-
// }
|
|
253
|
-
// }
|
|
254
|
-
// if (Expr.isElementKindExpr(expr)) {
|
|
255
|
-
// return this.graph.elements.filter(el => {
|
|
256
|
-
// if (expr.isEqual) {
|
|
257
|
-
// return el.kind === expr.elementKind
|
|
258
|
-
// }
|
|
259
|
-
// return el.kind !== expr.elementKind
|
|
260
|
-
// })
|
|
261
|
-
// }
|
|
262
|
-
// if (Expr.isElementTagExpr(expr)) {
|
|
263
|
-
// return this.graph.elements.filter(el => {
|
|
264
|
-
// const tags = el.tags
|
|
265
|
-
// if (expr.isEqual) {
|
|
266
|
-
// return !!tags && tags.includes(expr.elementTag)
|
|
267
|
-
// }
|
|
268
|
-
// return isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag)
|
|
269
|
-
// })
|
|
270
|
-
// }
|
|
271
|
-
// if (Expr.isExpandedElementExpr(expr)) {
|
|
272
|
-
// return [this.graph.element(expr.expanded)]
|
|
273
|
-
// }
|
|
274
|
-
|
|
275
|
-
// // Type guard
|
|
276
|
-
// if (!Expr.isElementRef(expr)) {
|
|
277
|
-
// return nonexhaustive(expr)
|
|
278
|
-
// }
|
|
279
|
-
|
|
280
|
-
// if (this.root === expr.element && expr.isChildren !== true && expr.isDescendants !== true) {
|
|
281
|
-
// return [...this.graph.children(this.root), this.graph.element(this.root)]
|
|
282
|
-
// }
|
|
283
|
-
|
|
284
|
-
// return expandWildcardRef.call(this, expr)
|
|
285
|
-
// }
|
|
286
|
-
|
|
287
|
-
// // --------------------------------
|
|
288
|
-
// // Incoming Expr
|
|
289
|
-
|
|
290
|
-
// function edgesIncomingExpr(this: ComputeCtx, expr: Expr.ElementExpression) {
|
|
291
|
-
// if (Expr.isWildcard(expr)) {
|
|
292
|
-
// if (!this.root) {
|
|
293
|
-
// return []
|
|
294
|
-
// }
|
|
295
|
-
// const sources = this.graph.ascendingSiblings(this.root)
|
|
296
|
-
// const targets = [...this.graph.children(this.root), this.graph.element(this.root)]
|
|
297
|
-
// return this.graph.edgesBetween(sources, targets)
|
|
298
|
-
// }
|
|
299
|
-
// const targets = resolveElements.call(this, expr)
|
|
300
|
-
// if (targets.length === 0) {
|
|
301
|
-
// return []
|
|
302
|
-
// }
|
|
303
|
-
// let sources = [...this.resolvedElements]
|
|
304
|
-
// if (Expr.isElementRef(expr) || Expr.isExpandedElementExpr(expr)) {
|
|
305
|
-
// const exprElement = expr.element ?? expr.expanded
|
|
306
|
-
// const isChildren = expr.isChildren ?? false
|
|
307
|
-
// sources = sources.filter(el =>
|
|
308
|
-
// // allow elements, that are not nested or are direct children
|
|
309
|
-
// !isAncestor(exprElement, el.id) || (isChildren && parentFqn(el.id) === exprElement)
|
|
310
|
-
// )
|
|
311
|
-
// }
|
|
312
|
-
// if (sources.length === 0) {
|
|
313
|
-
// sources = resolveNeighbours.call(this, expr)
|
|
314
|
-
// }
|
|
315
|
-
// return this.graph.edgesBetween(sources, targets)
|
|
316
|
-
// }
|
|
317
|
-
|
|
318
|
-
// function filterEdges(this: ComputeCtx, edges: ReadonlyArray<ComputeCtx.Edge>, where?: RelationPredicateFn) {
|
|
319
|
-
// if (!where) {
|
|
320
|
-
// return edges as ComputeCtx.Edge[]
|
|
321
|
-
// }
|
|
322
|
-
// return pipe(
|
|
323
|
-
// edges,
|
|
324
|
-
// map(e => ({ ...e, relations: filterRelations.call(this, [e], where) })),
|
|
325
|
-
// remedaFilter(e => e.relations.length > 0)
|
|
326
|
-
// ) as ComputeCtx.Edge[]
|
|
327
|
-
// }
|
|
328
|
-
|
|
329
|
-
// function filterRelations(this: ComputeCtx, edges: ComputeCtx.Edge[], where?: RelationPredicateFn) {
|
|
330
|
-
// return pipe(
|
|
331
|
-
// edges,
|
|
332
|
-
// flatMap(e => e.relations),
|
|
333
|
-
// map(x => ({ src: x, ...x, source: this.graph.element(x.source), target: this.graph.element(x.target) })),
|
|
334
|
-
// where ? remedaFilter<Filterable & { src: ModelRelation }>(where) : Identity,
|
|
335
|
-
// map(f => f.src),
|
|
336
|
-
// unique()
|
|
337
|
-
// )
|
|
338
|
-
// }
|
|
339
|
-
|
|
340
|
-
// export function includeIncomingExpr(this: ComputeCtx, expr: Expr.IncomingExpr, where?: RelationPredicateFn) {
|
|
341
|
-
// const edges = filterEdges.call(this, edgesIncomingExpr.call(this, expr.incoming), where)
|
|
342
|
-
// if (edges.length === 0) {
|
|
343
|
-
// return
|
|
344
|
-
// }
|
|
345
|
-
// this.addEdges(edges).forEach(edge => {
|
|
346
|
-
// this.addImplicit(edge.target)
|
|
347
|
-
// })
|
|
348
|
-
// }
|
|
349
|
-
// export function excludeIncomingExpr(this: ComputeCtx, expr: Expr.IncomingExpr, where?: RelationPredicateFn) {
|
|
350
|
-
// let relations = filterRelations.call(this, edgesIncomingExpr.call(this, expr.incoming), where)
|
|
351
|
-
// this.excludeRelation(...relations)
|
|
352
|
-
// }
|
|
353
|
-
|
|
354
|
-
// // --------------------------------
|
|
355
|
-
// // Outgoing Expr
|
|
356
|
-
|
|
357
|
-
// function edgesOutgoingExpr(this: ComputeCtx, expr: Expr.ElementExpression) {
|
|
358
|
-
// if (Expr.isWildcard(expr)) {
|
|
359
|
-
// if (!this.root) {
|
|
360
|
-
// return []
|
|
361
|
-
// }
|
|
362
|
-
// const targets = this.graph.ascendingSiblings(this.root)
|
|
363
|
-
// const sources = [...this.graph.children(this.root), this.graph.element(this.root)]
|
|
364
|
-
// return this.graph.edgesBetween(sources, targets)
|
|
365
|
-
// }
|
|
366
|
-
// const sources = resolveElements.call(this, expr)
|
|
367
|
-
// if (sources.length === 0) {
|
|
368
|
-
// return []
|
|
369
|
-
// }
|
|
370
|
-
// let targets = [...this.resolvedElements]
|
|
371
|
-
// if (Expr.isElementRef(expr) || Expr.isExpandedElementExpr(expr)) {
|
|
372
|
-
// const sourceElement = expr.element ?? expr.expanded
|
|
373
|
-
// const isChildren = expr.isChildren ?? false
|
|
374
|
-
// targets = targets.filter(el =>
|
|
375
|
-
// // allow elements, that are not nested or are direct children
|
|
376
|
-
// !isAncestor(sourceElement, el.id) || (isChildren && parentFqn(el.id) === sourceElement)
|
|
377
|
-
// )
|
|
378
|
-
// }
|
|
379
|
-
// if (targets.length === 0) {
|
|
380
|
-
// targets = [...resolveNeighbours.call(this, expr)]
|
|
381
|
-
// }
|
|
382
|
-
// return this.graph.edgesBetween(sources, targets)
|
|
383
|
-
// }
|
|
384
|
-
|
|
385
|
-
// export function includeOutgoingExpr(this: ComputeCtx, expr: Expr.OutgoingExpr, where?: RelationPredicateFn) {
|
|
386
|
-
// const edges = filterEdges.call(this, edgesOutgoingExpr.call(this, expr.outgoing), where)
|
|
387
|
-
// if (edges.length === 0) {
|
|
388
|
-
// return
|
|
389
|
-
// }
|
|
390
|
-
// this.addEdges(edges).forEach(edge => {
|
|
391
|
-
// this.addImplicit(edge.source)
|
|
392
|
-
// })
|
|
393
|
-
// }
|
|
394
|
-
// export function excludeOutgoingExpr(this: ComputeCtx, expr: Expr.OutgoingExpr, where?: RelationPredicateFn) {
|
|
395
|
-
// const relations = filterRelations.call(this, edgesOutgoingExpr.call(this, expr.outgoing), where)
|
|
396
|
-
// this.excludeRelation(...relations)
|
|
397
|
-
// }
|
|
398
|
-
|
|
399
|
-
// // --------------------------------
|
|
400
|
-
// // InOut Expr
|
|
401
|
-
// type EdgePredicateResult = {
|
|
402
|
-
// implicits: Element[]
|
|
403
|
-
// edges: ComputeCtx.Edge[]
|
|
404
|
-
// }
|
|
405
|
-
|
|
406
|
-
// namespace EdgePredicateResult {
|
|
407
|
-
// export const Empty: EdgePredicateResult = {
|
|
408
|
-
// implicits: [],
|
|
409
|
-
// edges: []
|
|
410
|
-
// }
|
|
411
|
-
// }
|
|
412
|
-
// function edgesInOutExpr(this: ComputeCtx, { inout }: Expr.InOutExpr, where?: RelationPredicateFn): EdgePredicateResult {
|
|
413
|
-
// if (Expr.isWildcard(inout)) {
|
|
414
|
-
// if (!this.root) {
|
|
415
|
-
// return EdgePredicateResult.Empty
|
|
416
|
-
// }
|
|
417
|
-
// const neighbours = this.graph.ascendingSiblings(this.root)
|
|
418
|
-
// return {
|
|
419
|
-
// edges: filterEdges.call(this, this.graph.anyEdgesBetween(this.graph.element(this.root), neighbours), where),
|
|
420
|
-
// implicits: []
|
|
421
|
-
// }
|
|
422
|
-
// }
|
|
423
|
-
// const elements = resolveElements.call(this, inout)
|
|
424
|
-
// if (elements.length === 0) {
|
|
425
|
-
// return EdgePredicateResult.Empty
|
|
426
|
-
// }
|
|
427
|
-
// let currentElements = [...this.resolvedElements]
|
|
428
|
-
|
|
429
|
-
// if (Expr.isElementRef(inout) || Expr.isExpandedElementExpr(inout)) {
|
|
430
|
-
// const exprElement = inout.element ?? inout.expanded
|
|
431
|
-
// const isChildren = inout.isChildren ?? false
|
|
432
|
-
// currentElements = currentElements.filter(el =>
|
|
433
|
-
// // allow elements, that are not nested or are direct children
|
|
434
|
-
// !isAncestor(exprElement, el.id) || (isChildren && parentFqn(el.id) === exprElement)
|
|
435
|
-
// )
|
|
436
|
-
// }
|
|
437
|
-
// if (currentElements.length === 0) {
|
|
438
|
-
// currentElements = resolveNeighbours.call(this, inout)
|
|
439
|
-
// }
|
|
440
|
-
// return elements.reduce((acc, el) => {
|
|
441
|
-
// const edges = filterEdges.call(this, this.graph.anyEdgesBetween(el, currentElements), where)
|
|
442
|
-
// if (edges.length > 0) {
|
|
443
|
-
// acc.implicits.push(el)
|
|
444
|
-
// acc.edges.push(...edges)
|
|
445
|
-
// }
|
|
446
|
-
// return acc
|
|
447
|
-
// }, { implicits: [], edges: [] } as EdgePredicateResult)
|
|
448
|
-
// }
|
|
449
|
-
|
|
450
|
-
// export function includeInOutExpr(this: ComputeCtx, expr: Expr.InOutExpr, where?: RelationPredicateFn) {
|
|
451
|
-
// const { implicits, edges } = edgesInOutExpr.call(this, expr, where)
|
|
452
|
-
// this.addEdges(edges)
|
|
453
|
-
// this.addImplicit(...implicits)
|
|
454
|
-
// }
|
|
455
|
-
// export function excludeInOutExpr(this: ComputeCtx, expr: Expr.InOutExpr, where?: RelationPredicateFn) {
|
|
456
|
-
// const { edges } = edgesInOutExpr.call(this, expr, where)
|
|
457
|
-
// this.excludeRelation(...edges.flatMap(e => e.relations))
|
|
458
|
-
// }
|
|
459
|
-
|
|
460
|
-
// /**
|
|
461
|
-
// * Expand element to its children and itself, if it is the root (and not ".*")
|
|
462
|
-
// * Example:
|
|
463
|
-
// *
|
|
464
|
-
// * view of api {
|
|
465
|
-
// * include some -> api
|
|
466
|
-
// * }
|
|
467
|
-
// *
|
|
468
|
-
// * Transform to:
|
|
469
|
-
// *
|
|
470
|
-
// * view of api {
|
|
471
|
-
// * include some -> api.*, some -> api
|
|
472
|
-
// * }
|
|
473
|
-
// */
|
|
474
|
-
// function resolveRelationExprElements(this: ComputeCtx, expr: Expr.ElementExpression) {
|
|
475
|
-
// if (
|
|
476
|
-
// Expr.isElementRef(expr) && this.root === expr.element && expr.isChildren !== true && expr.isDescendants !== true
|
|
477
|
-
// ) {
|
|
478
|
-
// return [...this.graph.children(expr.element), this.graph.element(expr.element)]
|
|
479
|
-
// }
|
|
480
|
-
// if (Expr.isExpandedElementExpr(expr) && this.root === expr.expanded) {
|
|
481
|
-
// return [...this.graph.children(expr.expanded), this.graph.element(expr.expanded)]
|
|
482
|
-
// }
|
|
483
|
-
// return resolveElements.call(this, expr)
|
|
484
|
-
// }
|
|
485
|
-
|
|
486
|
-
// export function includeRelationExpr(this: ComputeCtx, expr: Expr.RelationExpr_, where?: RelationPredicateFn) {
|
|
487
|
-
// let sources, targets
|
|
488
|
-
// if (Expr.isWildcard(expr.source) && !Expr.isWildcard(expr.target)) {
|
|
489
|
-
// sources = resolveNeighbours.call(this, expr.target)
|
|
490
|
-
// targets = resolveRelationExprElements.call(this, expr.target)
|
|
491
|
-
// } else if (!Expr.isWildcard(expr.source) && Expr.isWildcard(expr.target)) {
|
|
492
|
-
// sources = resolveRelationExprElements.call(this, expr.source)
|
|
493
|
-
// targets = resolveNeighbours.call(this, expr.source)
|
|
494
|
-
// } else {
|
|
495
|
-
// sources = resolveRelationExprElements.call(this, expr.source)
|
|
496
|
-
// targets = resolveRelationExprElements.call(this, expr.target)
|
|
497
|
-
// }
|
|
498
|
-
// const edges = this.graph.edgesBetween(sources, targets)
|
|
499
|
-
// if (expr.isBidirectional === true) {
|
|
500
|
-
// edges.push(...this.graph.edgesBetween(targets, sources))
|
|
501
|
-
// }
|
|
502
|
-
// this.addEdges(filterEdges.call(this, edges, where)).forEach(edge => {
|
|
503
|
-
// this.activeGroup.addImplicit(edge.source, edge.target)
|
|
504
|
-
// })
|
|
505
|
-
// }
|
|
506
|
-
|
|
507
|
-
// export function excludeRelationExpr(this: ComputeCtx, expr: Expr.RelationExpr_, where?: RelationPredicateFn) {
|
|
508
|
-
// const isSource = elementExprToPredicate(expr.source)
|
|
509
|
-
// const isTarget = elementExprToPredicate(expr.target)
|
|
510
|
-
// const satisfies = (edge: ComputeCtx.Edge) => {
|
|
511
|
-
// let result = isSource(edge.source) && isTarget(edge.target)
|
|
512
|
-
// if (!result && expr.isBidirectional) {
|
|
513
|
-
// result = isSource(edge.target) && isTarget(edge.source)
|
|
514
|
-
// }
|
|
515
|
-
// return result
|
|
516
|
-
// }
|
|
517
|
-
// const edges = this.edges.filter(satisfies)
|
|
518
|
-
// const relations = filterRelations.call(this, edges, where)
|
|
519
|
-
// this.excludeRelation(...relations)
|
|
520
|
-
// }
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { flatMap, hasAtLeast, pipe, sort, unique } from 'remeda'
|
|
2
|
-
import type { LiteralUnion } from 'type-fest'
|
|
3
|
-
import type { NonEmptyReadonlyArray } from '../../types/_common'
|
|
4
|
-
import type { Tag } from '../../types/scalars'
|
|
5
|
-
import { compareNatural } from '../../utils/compare-natural'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Extracts unique tags from an array of elements.
|
|
9
|
-
* and sort in natural order; returns null if no tags are present.
|
|
10
|
-
*/
|
|
11
|
-
export function uniqueTags<T extends { tags?: NonEmptyReadonlyArray<LiteralUnion<Tag, string>> | null }>(
|
|
12
|
-
elements: ReadonlyArray<T>,
|
|
13
|
-
) {
|
|
14
|
-
const tags = pipe(
|
|
15
|
-
elements,
|
|
16
|
-
flatMap(e => e.tags ?? []),
|
|
17
|
-
unique(),
|
|
18
|
-
sort(compareNatural),
|
|
19
|
-
)
|
|
20
|
-
return hasAtLeast(tags, 1) ? tags as NonEmptyReadonlyArray<Tag> : null
|
|
21
|
-
}
|