@likec4/core 1.31.0 → 1.32.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/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.CCWXGc6G.d.mts +920 -0
- 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.DoK86JEe.mjs +518 -0
- package/dist/shared/core.Dpq3P3YJ.d.mts +1265 -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/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 +15 -7
- 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/styles.ts +123 -0
- 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/theme.ts +0 -82
- 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,22 +1,19 @@
|
|
|
1
1
|
import { filter, findLast, flatMap, hasAtLeast, isTruthy, map, only, pipe, reduce, unique } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import type { ElementModel } from '../../model/ElementModel'
|
|
6
|
-
import type { AnyAux } from '../../model/types'
|
|
2
|
+
import type { ElementModel, LikeC4Model } from '../../model'
|
|
3
|
+
import { modelConnection } from '../../model'
|
|
4
|
+
import type { AnyAux, aux, scalar } from '../../types'
|
|
7
5
|
import {
|
|
8
6
|
type Color,
|
|
9
7
|
type ComputedDynamicView,
|
|
10
8
|
type ComputedEdge,
|
|
11
|
-
type DynamicView,
|
|
12
9
|
type DynamicViewStep,
|
|
13
10
|
type NonEmptyArray,
|
|
14
|
-
type
|
|
11
|
+
type ParsedDynamicView as DynamicView,
|
|
15
12
|
type RelationshipArrowType,
|
|
16
13
|
type RelationshipLineType,
|
|
17
14
|
type StepEdgeId,
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
_stage,
|
|
16
|
+
_type,
|
|
20
17
|
DefaultArrowType,
|
|
21
18
|
DefaultLineStyle,
|
|
22
19
|
DefaultRelationshipColor,
|
|
@@ -25,22 +22,25 @@ import {
|
|
|
25
22
|
isViewRulePredicate,
|
|
26
23
|
stepEdgeId,
|
|
27
24
|
} from '../../types'
|
|
25
|
+
import { nonNullable } from '../../utils'
|
|
28
26
|
import { ancestorsFqn, commonAncestor, parentFqn } from '../../utils/fqn'
|
|
29
27
|
import { applyCustomElementProperties } from '../utils/applyCustomElementProperties'
|
|
30
28
|
import { applyViewRuleStyles } from '../utils/applyViewRuleStyles'
|
|
31
|
-
import {
|
|
29
|
+
import { buildComputedNodes, elementModelToNodeSource } from '../utils/buildComputedNodes'
|
|
32
30
|
import { buildElementNotations } from '../utils/buildElementNotations'
|
|
33
31
|
import { elementExprToPredicate } from '../utils/elementExpressionToPredicate'
|
|
34
32
|
import { resolveGlobalRulesInDynamicView } from '../utils/resolve-global-rules'
|
|
35
33
|
import { calcViewLayoutHash } from '../utils/view-hash'
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
const { findConnection } = modelConnection
|
|
36
|
+
|
|
37
|
+
type Element<A extends AnyAux> = ElementModel<A>
|
|
38
38
|
|
|
39
39
|
namespace DynamicViewCompute {
|
|
40
|
-
export interface Step {
|
|
40
|
+
export interface Step<A extends AnyAux> {
|
|
41
41
|
id: StepEdgeId
|
|
42
|
-
source: Element
|
|
43
|
-
target: Element
|
|
42
|
+
source: Element<A>
|
|
43
|
+
target: Element<A>
|
|
44
44
|
title: string | null
|
|
45
45
|
description?: string
|
|
46
46
|
technology?: string
|
|
@@ -48,21 +48,21 @@ namespace DynamicViewCompute {
|
|
|
48
48
|
line?: RelationshipLineType
|
|
49
49
|
head?: RelationshipArrowType
|
|
50
50
|
tail?: RelationshipArrowType
|
|
51
|
-
relations: RelationId[]
|
|
51
|
+
relations: scalar.RelationId[]
|
|
52
52
|
isBackward: boolean
|
|
53
|
-
navigateTo?:
|
|
54
|
-
tags?:
|
|
53
|
+
navigateTo?: aux.StrictViewId<A>
|
|
54
|
+
tags?: aux.Tags<A>
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
class DynamicViewCompute {
|
|
58
|
+
class DynamicViewCompute<A extends AnyAux> {
|
|
59
59
|
// Intermediate state
|
|
60
|
-
private explicits = new Set<Element
|
|
61
|
-
private steps = [] as DynamicViewCompute.Step[]
|
|
60
|
+
private explicits = new Set<Element<A>>()
|
|
61
|
+
private steps = [] as DynamicViewCompute.Step<A>[]
|
|
62
62
|
|
|
63
63
|
constructor(
|
|
64
|
-
protected model: LikeC4Model
|
|
65
|
-
protected view: DynamicView
|
|
64
|
+
protected model: LikeC4Model<A>,
|
|
65
|
+
protected view: DynamicView<A>,
|
|
66
66
|
) {}
|
|
67
67
|
|
|
68
68
|
private addStep(
|
|
@@ -73,7 +73,7 @@ class DynamicViewCompute {
|
|
|
73
73
|
isBackward,
|
|
74
74
|
navigateTo: stepNavigateTo,
|
|
75
75
|
...step
|
|
76
|
-
}: DynamicViewStep
|
|
76
|
+
}: DynamicViewStep<A>,
|
|
77
77
|
index: number,
|
|
78
78
|
parent?: number,
|
|
79
79
|
) {
|
|
@@ -110,7 +110,7 @@ class DynamicViewCompute {
|
|
|
110
110
|
})
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
compute(): ComputedDynamicView {
|
|
113
|
+
compute(): ComputedDynamicView<A> {
|
|
114
114
|
const {
|
|
115
115
|
docUri: _docUri, // exclude docUri
|
|
116
116
|
rules: _rules, // exclude rules
|
|
@@ -135,7 +135,7 @@ class DynamicViewCompute {
|
|
|
135
135
|
stepNum++
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
const rules = resolveGlobalRulesInDynamicView(_rules, this.model.globals
|
|
138
|
+
const rules = resolveGlobalRulesInDynamicView(_rules, this.model.globals)
|
|
139
139
|
|
|
140
140
|
for (const rule of rules) {
|
|
141
141
|
if (isViewRulePredicate(rule)) {
|
|
@@ -150,21 +150,24 @@ class DynamicViewCompute {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
const
|
|
154
|
-
|
|
153
|
+
const nodesMap = buildComputedNodes(
|
|
154
|
+
[...this.explicits].map(elementModelToNodeSource),
|
|
155
|
+
)
|
|
155
156
|
|
|
156
|
-
const edges = this.steps.map(({ source, target, relations, title, isBackward, ...step }) => {
|
|
157
|
-
const sourceNode = nonNullable(nodesMap.get(source.id), `Source node ${source.id} not found`)
|
|
158
|
-
const targetNode = nonNullable(nodesMap.get(target.id), `Target node ${target.id} not found`)
|
|
159
|
-
const edge: ComputedEdge = {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
const edges = this.steps.map(({ id, source, target, relations, title, isBackward, tags, ...step }) => {
|
|
158
|
+
const sourceNode = nonNullable(nodesMap.get(source.id as scalar.NodeId), `Source node ${source.id} not found`)
|
|
159
|
+
const targetNode = nonNullable(nodesMap.get(target.id as scalar.NodeId), `Target node ${target.id} not found`)
|
|
160
|
+
const edge: ComputedEdge<A> = {
|
|
161
|
+
id: id as unknown as aux.EdgeId,
|
|
162
|
+
parent: commonAncestor(source.id, target.id) as scalar.NodeId | null,
|
|
163
|
+
source: sourceNode.id,
|
|
164
|
+
target: targetNode.id,
|
|
163
165
|
label: title,
|
|
164
166
|
relations,
|
|
165
167
|
color: DefaultRelationshipColor,
|
|
166
168
|
line: DefaultLineStyle,
|
|
167
169
|
head: DefaultArrowType,
|
|
170
|
+
tags: tags ?? [],
|
|
168
171
|
...step,
|
|
169
172
|
}
|
|
170
173
|
if (isBackward) {
|
|
@@ -198,16 +201,18 @@ class DynamicViewCompute {
|
|
|
198
201
|
applyViewRuleStyles(
|
|
199
202
|
rules,
|
|
200
203
|
// Keep order of elements
|
|
201
|
-
|
|
204
|
+
[...this.explicits].map(e => nonNullable(nodesMap.get(e.id as scalar.NodeId))),
|
|
202
205
|
),
|
|
203
206
|
)
|
|
204
207
|
|
|
205
208
|
const autoLayoutRule = findLast(rules, isViewRuleAutoLayout)
|
|
206
209
|
|
|
207
|
-
const
|
|
210
|
+
const nodeNotations = buildElementNotations(nodes)
|
|
208
211
|
|
|
209
212
|
return calcViewLayoutHash({
|
|
210
213
|
...view,
|
|
214
|
+
[_type]: 'dynamic',
|
|
215
|
+
[_stage]: 'computed',
|
|
211
216
|
autoLayout: {
|
|
212
217
|
direction: autoLayoutRule?.direction ?? 'LR',
|
|
213
218
|
...(autoLayoutRule?.nodeSep && { nodeSep: autoLayoutRule.nodeSep }),
|
|
@@ -220,19 +225,19 @@ class DynamicViewCompute {
|
|
|
220
225
|
return n
|
|
221
226
|
}),
|
|
222
227
|
edges,
|
|
223
|
-
...(
|
|
228
|
+
...(nodeNotations.length > 0 && {
|
|
224
229
|
notation: {
|
|
225
|
-
|
|
230
|
+
nodes: nodeNotations,
|
|
226
231
|
},
|
|
227
232
|
}),
|
|
228
233
|
})
|
|
229
234
|
}
|
|
230
235
|
|
|
231
|
-
private findRelations(source: Element
|
|
236
|
+
private findRelations(source: Element<A>, target: Element<A>): {
|
|
232
237
|
title: string | null
|
|
233
|
-
tags:
|
|
234
|
-
relations: NonEmptyArray<RelationId> | null
|
|
235
|
-
navigateTo:
|
|
238
|
+
tags: aux.Tags<A> | null
|
|
239
|
+
relations: NonEmptyArray<aux.RelationId> | null
|
|
240
|
+
navigateTo: aux.StrictViewId<A> | null
|
|
236
241
|
color: Color | null
|
|
237
242
|
line: RelationshipLineType | null
|
|
238
243
|
} {
|
|
@@ -252,7 +257,7 @@ class DynamicViewCompute {
|
|
|
252
257
|
flatMap(r => r.tags),
|
|
253
258
|
filter(isTruthy),
|
|
254
259
|
unique(),
|
|
255
|
-
)
|
|
260
|
+
) as aux.Tags<A>
|
|
256
261
|
const tags = hasAtLeast(alltags, 1) ? alltags : null
|
|
257
262
|
const relations = hasAtLeast(relationships, 1) ? map(relationships, r => r.id) : null
|
|
258
263
|
|
|
@@ -260,14 +265,16 @@ class DynamicViewCompute {
|
|
|
260
265
|
const relation = only(relationships) || relationships.find(r => r.source === source && r.target === target)
|
|
261
266
|
const relationNavigateTo = relation?.$relationship.navigateTo ?? null
|
|
262
267
|
|
|
263
|
-
const navigateTo = relationNavigateTo && relationNavigateTo !== this.view.id
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
const navigateTo = relationNavigateTo && relationNavigateTo !== this.view.id
|
|
269
|
+
? relationNavigateTo as aux.StrictViewId<A>
|
|
270
|
+
: pipe(
|
|
271
|
+
relationships,
|
|
272
|
+
map(r => r.$relationship.navigateTo as aux.StrictViewId<A>),
|
|
273
|
+
filter(isTruthy),
|
|
274
|
+
filter(v => v !== this.view.id),
|
|
275
|
+
unique(),
|
|
276
|
+
only(),
|
|
277
|
+
)
|
|
271
278
|
|
|
272
279
|
const commonProperties = pipe(
|
|
273
280
|
relationships,
|
|
@@ -295,7 +302,7 @@ class DynamicViewCompute {
|
|
|
295
302
|
}
|
|
296
303
|
export function computeDynamicView<M extends AnyAux>(
|
|
297
304
|
model: LikeC4Model<M>,
|
|
298
|
-
view: DynamicView
|
|
299
|
-
): ComputedDynamicView {
|
|
305
|
+
view: DynamicView<M>,
|
|
306
|
+
): ComputedDynamicView<M> {
|
|
300
307
|
return new DynamicViewCompute(model, view).compute()
|
|
301
308
|
}
|
|
@@ -11,15 +11,24 @@ import {
|
|
|
11
11
|
} from '../../../builder'
|
|
12
12
|
import * as viewhelpers from '../../../builder/Builder.view-common'
|
|
13
13
|
import { mkViewBuilder } from '../../../builder/Builder.views'
|
|
14
|
+
import type { ConnectionModel, ElementModel, LikeC4Model } from '../../../model'
|
|
14
15
|
import { differenceConnections } from '../../../model/connection'
|
|
15
|
-
import
|
|
16
|
+
import {
|
|
17
|
+
type Any,
|
|
18
|
+
type ComputedElementView,
|
|
19
|
+
type ComputedView,
|
|
20
|
+
type ParsedElementView as ElementView,
|
|
21
|
+
type ViewId,
|
|
22
|
+
type ViewRule,
|
|
23
|
+
_stage,
|
|
24
|
+
_type,
|
|
25
|
+
} from '../../../types'
|
|
16
26
|
import { compareNatural } from '../../../utils'
|
|
17
27
|
import { imap, toArray } from '../../../utils/iterable'
|
|
18
28
|
import { difference as differenceSet } from '../../../utils/set'
|
|
19
|
-
import type { CtxConnection, CtxElement } from '../../memory'
|
|
20
29
|
import { withReadableEdges } from '../../utils/with-readable-edges'
|
|
21
30
|
import { processPredicates as processPredicatesImpl } from '../compute'
|
|
22
|
-
import {
|
|
31
|
+
import { Memory } from '../memory'
|
|
23
32
|
|
|
24
33
|
type ConnectionExpression<T extends AnyTypes> = `${T['Fqn']} -> ${T['Fqn']}`
|
|
25
34
|
|
|
@@ -38,11 +47,13 @@ type ConnectionEqual<T extends AnyTypes> = [ConnectionsDeepMatcher<ConnectionExp
|
|
|
38
47
|
...ConnectionExpression<T>[],
|
|
39
48
|
]
|
|
40
49
|
|
|
41
|
-
type Elem = CtxElement<Ctx>
|
|
42
|
-
type Connection = CtxConnection<Ctx>
|
|
43
|
-
|
|
44
50
|
export class TestHelper<T extends AnyTypes> {
|
|
45
|
-
model: Types.
|
|
51
|
+
model: LikeC4Model.Computed<Types.ToAux<T>>
|
|
52
|
+
|
|
53
|
+
Aux!: typeof this.model.Aux
|
|
54
|
+
Elem!: ElementModel<typeof this.Aux>
|
|
55
|
+
Connection!: ConnectionModel<typeof this.Aux>
|
|
56
|
+
CompView!: ComputedElementView<typeof this.Aux>
|
|
46
57
|
|
|
47
58
|
static $include = viewhelpers.$include
|
|
48
59
|
static $exclude = viewhelpers.$exclude
|
|
@@ -53,7 +64,10 @@ export class TestHelper<T extends AnyTypes> {
|
|
|
53
64
|
$exclude = viewhelpers.$exclude
|
|
54
65
|
$style = viewhelpers.$style
|
|
55
66
|
|
|
56
|
-
static from<const T extends AnyTypes>(
|
|
67
|
+
static from<const T extends AnyTypes>(
|
|
68
|
+
builder: Builder<T>,
|
|
69
|
+
expect = vitestExpect,
|
|
70
|
+
): TestHelper<T> {
|
|
57
71
|
return new TestHelper(builder, expect)
|
|
58
72
|
}
|
|
59
73
|
|
|
@@ -61,7 +75,7 @@ export class TestHelper<T extends AnyTypes> {
|
|
|
61
75
|
private builder: Builder<T>,
|
|
62
76
|
private _expect: ExpectStatic,
|
|
63
77
|
) {
|
|
64
|
-
this.model = builder.toLikeC4Model()
|
|
78
|
+
this.model = builder.toLikeC4Model()
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
computeView = (...rules: ElementViewRulesBuilder<T>[]) => {
|
|
@@ -71,7 +85,7 @@ export class TestHelper<T extends AnyTypes> {
|
|
|
71
85
|
.views(_ => _.view('dev').with(...rules))
|
|
72
86
|
.toLikeC4Model()
|
|
73
87
|
.view('dev')
|
|
74
|
-
.$view
|
|
88
|
+
.$view,
|
|
75
89
|
' -> ',
|
|
76
90
|
)
|
|
77
91
|
}
|
|
@@ -83,7 +97,7 @@ export class TestHelper<T extends AnyTypes> {
|
|
|
83
97
|
return ProcessPredicates.executeWithScope(this, scope, ...rules)
|
|
84
98
|
}
|
|
85
99
|
|
|
86
|
-
expectView(view:
|
|
100
|
+
expectView(view: ComputedView) {
|
|
87
101
|
return {
|
|
88
102
|
toHave: (nodesAndEdges: { nodes: Array<T['Fqn']>; edges: Array<ConnectionExpression<T>> }) => {
|
|
89
103
|
const actual = {
|
|
@@ -116,17 +130,17 @@ export class TestHelper<T extends AnyTypes> {
|
|
|
116
130
|
this._expect(map([...memory.final], prop('id'))).toEqual(ids)
|
|
117
131
|
},
|
|
118
132
|
toHaveConnections: (...matchers: ConnectionEqual<T>) => {
|
|
119
|
-
this.expectConnections(memory.connections).toEqual(...matchers)
|
|
133
|
+
this.expectConnections(memory.connections as any).toEqual(...matchers)
|
|
120
134
|
},
|
|
121
135
|
})
|
|
122
136
|
|
|
123
|
-
expectElements = (elements: ReadonlySet<
|
|
137
|
+
expectElements = (elements: ReadonlySet<ElementModel<Any>>) => ({
|
|
124
138
|
toEqual: <const Id extends ViewPredicate.DeploymentConnectionExpression<T>>(...ids: Id[]) => {
|
|
125
139
|
this._expect(toArray(imap(elements, prop('id')))).toEqual(ids)
|
|
126
140
|
},
|
|
127
141
|
})
|
|
128
142
|
|
|
129
|
-
expectConnections = (connections: ReadonlyArray<Connection>) => ({
|
|
143
|
+
expectConnections = (connections: ReadonlyArray<typeof this.Connection>) => ({
|
|
130
144
|
toBeEmpty: () => {
|
|
131
145
|
this._expect(connections.map(c => c.expression)).to.be.empty
|
|
132
146
|
},
|
|
@@ -150,11 +164,18 @@ export class TestHelper<T extends AnyTypes> {
|
|
|
150
164
|
...this.expectMemory(step.memory),
|
|
151
165
|
})
|
|
152
166
|
|
|
153
|
-
expect(value:
|
|
154
|
-
expect(value: Set<
|
|
155
|
-
expect(value: ReadonlyArray<Connection>): ReturnType<typeof this['expectConnections']>
|
|
167
|
+
expect(value: typeof this.CompView): ReturnType<typeof this['expectView']>
|
|
168
|
+
expect(value: Set<ElementModel<Any>>): ReturnType<typeof this['expectElements']>
|
|
169
|
+
expect(value: ReadonlyArray<typeof this.Connection>): ReturnType<typeof this['expectConnections']>
|
|
156
170
|
expect(value: Memory | ProcessPredicates<T>): ReturnType<typeof this['expectMemory']>
|
|
157
|
-
expect(
|
|
171
|
+
expect(
|
|
172
|
+
value:
|
|
173
|
+
| Memory
|
|
174
|
+
| ProcessPredicates<T>
|
|
175
|
+
| Set<ElementModel<Any>>
|
|
176
|
+
| typeof this.CompView
|
|
177
|
+
| ReadonlyArray<typeof this.Connection>,
|
|
178
|
+
) {
|
|
158
179
|
if (value instanceof Memory) {
|
|
159
180
|
return this.expectMemory(value)
|
|
160
181
|
}
|
|
@@ -172,11 +193,11 @@ export class TestHelper<T extends AnyTypes> {
|
|
|
172
193
|
}
|
|
173
194
|
|
|
174
195
|
class ProcessPredicates<T extends AnyTypes> {
|
|
175
|
-
static execute<
|
|
176
|
-
test: TestHelper<
|
|
177
|
-
...rules: ElementViewRulesBuilder<
|
|
178
|
-
)
|
|
179
|
-
const processor = new ProcessPredicates(test)
|
|
196
|
+
static execute<B extends AnyTypes>(
|
|
197
|
+
test: TestHelper<B>,
|
|
198
|
+
...rules: ElementViewRulesBuilder<B>[]
|
|
199
|
+
) {
|
|
200
|
+
const processor = new ProcessPredicates<B>(test)
|
|
180
201
|
processor.next(...rules)
|
|
181
202
|
return processor
|
|
182
203
|
}
|
|
@@ -185,13 +206,13 @@ class ProcessPredicates<T extends AnyTypes> {
|
|
|
185
206
|
test: TestHelper<A>,
|
|
186
207
|
scope: A['Fqn'],
|
|
187
208
|
...rules: ElementViewRulesBuilder<A>[]
|
|
188
|
-
)
|
|
189
|
-
const processor = new ProcessPredicates(test, scope)
|
|
209
|
+
) {
|
|
210
|
+
const processor = new ProcessPredicates<A>(test, scope)
|
|
190
211
|
processor.next(...rules)
|
|
191
212
|
return processor
|
|
192
213
|
}
|
|
193
214
|
|
|
194
|
-
public viewrules: ReadonlyArray<ViewRule
|
|
215
|
+
public viewrules: ReadonlyArray<ViewRule<typeof this.t.model.Aux>> = []
|
|
195
216
|
|
|
196
217
|
public previousMemory: Memory = Memory.empty(null)
|
|
197
218
|
public memory: Memory = Memory.empty(null)
|
|
@@ -233,9 +254,12 @@ class ProcessPredicates<T extends AnyTypes> {
|
|
|
233
254
|
next(...predicates: ElementViewRulesBuilder<T>[]): this {
|
|
234
255
|
const view = {
|
|
235
256
|
id: 'test' as ViewId,
|
|
236
|
-
|
|
257
|
+
[_stage]: 'parsed',
|
|
258
|
+
[_type]: 'element',
|
|
237
259
|
rules: [],
|
|
238
|
-
|
|
260
|
+
title: null,
|
|
261
|
+
description: null,
|
|
262
|
+
} as Writable<ElementView<typeof this.t.model.Aux>>
|
|
239
263
|
let vb = mkViewBuilder(view) as any
|
|
240
264
|
this.predicates = [
|
|
241
265
|
...this.predicates,
|
|
@@ -249,7 +273,7 @@ class ProcessPredicates<T extends AnyTypes> {
|
|
|
249
273
|
const scope = this.scope ? this.t.model.element(this.scope) : null
|
|
250
274
|
this.memory = processPredicatesImpl(
|
|
251
275
|
this.t.model,
|
|
252
|
-
Memory.empty(scope),
|
|
276
|
+
Memory.empty(scope as any),
|
|
253
277
|
view.rules,
|
|
254
278
|
)
|
|
255
279
|
this.age++
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`compute-element-view > view of cloud 1`] = `
|
|
4
4
|
{
|
|
5
|
-
"
|
|
5
|
+
"_stage": "computed",
|
|
6
|
+
"_type": "element",
|
|
6
7
|
"autoLayout": {
|
|
7
8
|
"direction": "TB",
|
|
8
9
|
},
|
|
9
|
-
"customColorDefinitions": {},
|
|
10
10
|
"description": null,
|
|
11
11
|
"edges": [
|
|
12
12
|
{
|
|
@@ -89,14 +89,14 @@ exports[`compute-element-view > view of cloud 1`] = `
|
|
|
89
89
|
"kind": "actor",
|
|
90
90
|
"level": 0,
|
|
91
91
|
"links": null,
|
|
92
|
-
"modelRef":
|
|
92
|
+
"modelRef": "customer",
|
|
93
93
|
"outEdges": [
|
|
94
94
|
"customer:cloud.frontend",
|
|
95
95
|
],
|
|
96
96
|
"parent": null,
|
|
97
97
|
"shape": "person",
|
|
98
98
|
"style": {},
|
|
99
|
-
"tags":
|
|
99
|
+
"tags": [],
|
|
100
100
|
"technology": null,
|
|
101
101
|
"title": "customer",
|
|
102
102
|
},
|
|
@@ -109,14 +109,14 @@ exports[`compute-element-view > view of cloud 1`] = `
|
|
|
109
109
|
"kind": "actor",
|
|
110
110
|
"level": 0,
|
|
111
111
|
"links": null,
|
|
112
|
-
"modelRef":
|
|
112
|
+
"modelRef": "support",
|
|
113
113
|
"outEdges": [
|
|
114
114
|
"support:cloud.frontend",
|
|
115
115
|
],
|
|
116
116
|
"parent": null,
|
|
117
117
|
"shape": "person",
|
|
118
118
|
"style": {},
|
|
119
|
-
"tags":
|
|
119
|
+
"tags": [],
|
|
120
120
|
"technology": null,
|
|
121
121
|
"title": "support",
|
|
122
122
|
},
|
|
@@ -136,7 +136,7 @@ exports[`compute-element-view > view of cloud 1`] = `
|
|
|
136
136
|
"kind": "system",
|
|
137
137
|
"level": 0,
|
|
138
138
|
"links": null,
|
|
139
|
-
"modelRef":
|
|
139
|
+
"modelRef": "cloud",
|
|
140
140
|
"outEdges": [
|
|
141
141
|
"cloud.backend:email",
|
|
142
142
|
"cloud.backend:amazon",
|
|
@@ -163,14 +163,14 @@ exports[`compute-element-view > view of cloud 1`] = `
|
|
|
163
163
|
"kind": "container",
|
|
164
164
|
"level": 1,
|
|
165
165
|
"links": null,
|
|
166
|
-
"modelRef":
|
|
166
|
+
"modelRef": "cloud.frontend",
|
|
167
167
|
"outEdges": [
|
|
168
168
|
"cloud.frontend:cloud.backend",
|
|
169
169
|
],
|
|
170
170
|
"parent": "cloud",
|
|
171
171
|
"shape": "browser",
|
|
172
172
|
"style": {},
|
|
173
|
-
"tags":
|
|
173
|
+
"tags": [],
|
|
174
174
|
"technology": null,
|
|
175
175
|
"title": "frontend",
|
|
176
176
|
},
|
|
@@ -185,7 +185,7 @@ exports[`compute-element-view > view of cloud 1`] = `
|
|
|
185
185
|
"kind": "container",
|
|
186
186
|
"level": 1,
|
|
187
187
|
"links": null,
|
|
188
|
-
"modelRef":
|
|
188
|
+
"modelRef": "cloud.backend",
|
|
189
189
|
"outEdges": [
|
|
190
190
|
"cloud.backend:email",
|
|
191
191
|
"cloud.backend:amazon",
|
|
@@ -193,7 +193,7 @@ exports[`compute-element-view > view of cloud 1`] = `
|
|
|
193
193
|
"parent": "cloud",
|
|
194
194
|
"shape": "rectangle",
|
|
195
195
|
"style": {},
|
|
196
|
-
"tags":
|
|
196
|
+
"tags": [],
|
|
197
197
|
"technology": null,
|
|
198
198
|
"title": "backend",
|
|
199
199
|
},
|
|
@@ -208,12 +208,12 @@ exports[`compute-element-view > view of cloud 1`] = `
|
|
|
208
208
|
"kind": "system",
|
|
209
209
|
"level": 0,
|
|
210
210
|
"links": null,
|
|
211
|
-
"modelRef":
|
|
211
|
+
"modelRef": "email",
|
|
212
212
|
"outEdges": [],
|
|
213
213
|
"parent": null,
|
|
214
214
|
"shape": "rectangle",
|
|
215
215
|
"style": {},
|
|
216
|
-
"tags":
|
|
216
|
+
"tags": [],
|
|
217
217
|
"technology": null,
|
|
218
218
|
"title": "email",
|
|
219
219
|
},
|
|
@@ -229,7 +229,7 @@ exports[`compute-element-view > view of cloud 1`] = `
|
|
|
229
229
|
"kind": "system",
|
|
230
230
|
"level": 0,
|
|
231
231
|
"links": null,
|
|
232
|
-
"modelRef":
|
|
232
|
+
"modelRef": "amazon",
|
|
233
233
|
"outEdges": [],
|
|
234
234
|
"parent": null,
|
|
235
235
|
"shape": "rectangle",
|
|
@@ -249,11 +249,11 @@ exports[`compute-element-view > view of cloud 1`] = `
|
|
|
249
249
|
|
|
250
250
|
exports[`compute-element-view > view of cloud.frontend 1`] = `
|
|
251
251
|
{
|
|
252
|
-
"
|
|
252
|
+
"_stage": "computed",
|
|
253
|
+
"_type": "element",
|
|
253
254
|
"autoLayout": {
|
|
254
255
|
"direction": "TB",
|
|
255
256
|
},
|
|
256
|
-
"customColorDefinitions": {},
|
|
257
257
|
"description": null,
|
|
258
258
|
"edges": [
|
|
259
259
|
{
|
|
@@ -321,14 +321,14 @@ exports[`compute-element-view > view of cloud.frontend 1`] = `
|
|
|
321
321
|
"kind": "actor",
|
|
322
322
|
"level": 0,
|
|
323
323
|
"links": null,
|
|
324
|
-
"modelRef":
|
|
324
|
+
"modelRef": "customer",
|
|
325
325
|
"outEdges": [
|
|
326
326
|
"customer:cloud.frontend.dashboard",
|
|
327
327
|
],
|
|
328
328
|
"parent": null,
|
|
329
329
|
"shape": "person",
|
|
330
330
|
"style": {},
|
|
331
|
-
"tags":
|
|
331
|
+
"tags": [],
|
|
332
332
|
"technology": null,
|
|
333
333
|
"title": "customer",
|
|
334
334
|
},
|
|
@@ -341,14 +341,14 @@ exports[`compute-element-view > view of cloud.frontend 1`] = `
|
|
|
341
341
|
"kind": "actor",
|
|
342
342
|
"level": 0,
|
|
343
343
|
"links": null,
|
|
344
|
-
"modelRef":
|
|
344
|
+
"modelRef": "support",
|
|
345
345
|
"outEdges": [
|
|
346
346
|
"support:cloud.frontend.supportPanel",
|
|
347
347
|
],
|
|
348
348
|
"parent": null,
|
|
349
349
|
"shape": "person",
|
|
350
350
|
"style": {},
|
|
351
|
-
"tags":
|
|
351
|
+
"tags": [],
|
|
352
352
|
"technology": null,
|
|
353
353
|
"title": "support",
|
|
354
354
|
},
|
|
@@ -368,7 +368,7 @@ exports[`compute-element-view > view of cloud.frontend 1`] = `
|
|
|
368
368
|
"kind": "container",
|
|
369
369
|
"level": 0,
|
|
370
370
|
"links": null,
|
|
371
|
-
"modelRef":
|
|
371
|
+
"modelRef": "cloud.frontend",
|
|
372
372
|
"outEdges": [
|
|
373
373
|
"cloud.frontend.dashboard:cloud.backend",
|
|
374
374
|
"cloud.frontend.supportPanel:cloud.backend",
|
|
@@ -376,7 +376,7 @@ exports[`compute-element-view > view of cloud.frontend 1`] = `
|
|
|
376
376
|
"parent": null,
|
|
377
377
|
"shape": "browser",
|
|
378
378
|
"style": {},
|
|
379
|
-
"tags":
|
|
379
|
+
"tags": [],
|
|
380
380
|
"technology": null,
|
|
381
381
|
"title": "frontend",
|
|
382
382
|
},
|
|
@@ -392,7 +392,7 @@ exports[`compute-element-view > view of cloud.frontend 1`] = `
|
|
|
392
392
|
"kind": "component",
|
|
393
393
|
"level": 1,
|
|
394
394
|
"links": null,
|
|
395
|
-
"modelRef":
|
|
395
|
+
"modelRef": "cloud.frontend.dashboard",
|
|
396
396
|
"outEdges": [
|
|
397
397
|
"cloud.frontend.dashboard:cloud.backend",
|
|
398
398
|
],
|
|
@@ -416,7 +416,7 @@ exports[`compute-element-view > view of cloud.frontend 1`] = `
|
|
|
416
416
|
"kind": "component",
|
|
417
417
|
"level": 1,
|
|
418
418
|
"links": null,
|
|
419
|
-
"modelRef":
|
|
419
|
+
"modelRef": "cloud.frontend.supportPanel",
|
|
420
420
|
"outEdges": [
|
|
421
421
|
"cloud.frontend.supportPanel:cloud.backend",
|
|
422
422
|
],
|
|
@@ -441,12 +441,12 @@ exports[`compute-element-view > view of cloud.frontend 1`] = `
|
|
|
441
441
|
"kind": "container",
|
|
442
442
|
"level": 0,
|
|
443
443
|
"links": null,
|
|
444
|
-
"modelRef":
|
|
444
|
+
"modelRef": "cloud.backend",
|
|
445
445
|
"outEdges": [],
|
|
446
446
|
"parent": null,
|
|
447
447
|
"shape": "rectangle",
|
|
448
448
|
"style": {},
|
|
449
|
-
"tags":
|
|
449
|
+
"tags": [],
|
|
450
450
|
"technology": null,
|
|
451
451
|
"title": "backend",
|
|
452
452
|
},
|