@likec4/core 1.30.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 +10 -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.CAcZ6_cP.mjs → core.CBpKAlhj.mjs} +1742 -4128
- 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 +19 -10
- 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 +182 -137
- package/src/model/DeploymentModel.ts +88 -65
- package/src/model/ElementModel.ts +92 -72
- package/src/model/LikeC4Model.ts +430 -241
- package/src/model/RelationModel.ts +69 -26
- 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.CZR9J1Qx.d.mts +0 -146
- package/dist/shared/core.CiFKryGW.d.mts +0 -745
- package/dist/shared/core.DJvmfnEi.d.mts +0 -1153
- package/dist/shared/core.DgfwjBtu.mjs +0 -495
- 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,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { nonexhaustive } from '../errors'
|
|
1
|
+
import { indexBy, values } from 'remeda'
|
|
3
2
|
import { LikeC4Model } from '../model'
|
|
4
3
|
import {
|
|
4
|
+
type AnyAux,
|
|
5
5
|
type ComputedLikeC4ModelData,
|
|
6
6
|
type ComputedView,
|
|
7
|
-
type LikeC4View,
|
|
8
7
|
type ParsedLikeC4ModelData,
|
|
8
|
+
type ParsedView,
|
|
9
|
+
_stage,
|
|
9
10
|
isDeploymentView,
|
|
10
11
|
isDynamicView,
|
|
11
12
|
isElementView,
|
|
12
13
|
} from '../types'
|
|
14
|
+
import { nonexhaustive } from '../utils'
|
|
13
15
|
import { computeDeploymentView } from './deployment-view/compute'
|
|
14
16
|
import { computeDynamicView } from './dynamic-view/compute'
|
|
15
17
|
import { computeElementView } from './element-view/compute'
|
|
16
18
|
|
|
17
|
-
export type ComputeViewResult<V
|
|
19
|
+
export type ComputeViewResult<V> =
|
|
18
20
|
| {
|
|
19
21
|
isSuccess: true
|
|
20
22
|
error?: undefined
|
|
@@ -26,27 +28,26 @@ export type ComputeViewResult<V extends ComputedView = ComputedView> =
|
|
|
26
28
|
view: undefined
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
export function unsafeComputeView(
|
|
30
|
-
viewsource:
|
|
31
|
-
likec4model: LikeC4Model
|
|
32
|
-
): ComputedView {
|
|
31
|
+
export function unsafeComputeView<A extends AnyAux>(
|
|
32
|
+
viewsource: ParsedView<A>,
|
|
33
|
+
likec4model: LikeC4Model<any>,
|
|
34
|
+
): ComputedView<A> {
|
|
33
35
|
switch (true) {
|
|
34
|
-
case
|
|
36
|
+
case isElementView(viewsource):
|
|
37
|
+
return computeElementView(likec4model, viewsource)
|
|
38
|
+
case isDeploymentView(viewsource):
|
|
35
39
|
return computeDeploymentView(likec4model, viewsource)
|
|
36
|
-
}
|
|
37
40
|
case isDynamicView(viewsource):
|
|
38
41
|
return computeDynamicView(likec4model, viewsource)
|
|
39
|
-
case isElementView(viewsource):
|
|
40
|
-
return computeElementView(likec4model, viewsource)
|
|
41
42
|
default:
|
|
42
43
|
nonexhaustive(viewsource)
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
export function computeView<
|
|
47
|
-
viewsource:
|
|
48
|
-
likec4model: LikeC4Model
|
|
49
|
-
): ComputeViewResult {
|
|
47
|
+
export function computeView<A extends AnyAux>(
|
|
48
|
+
viewsource: ParsedView<A>,
|
|
49
|
+
likec4model: LikeC4Model<A>,
|
|
50
|
+
): ComputeViewResult<ComputedView<A>> {
|
|
50
51
|
try {
|
|
51
52
|
return {
|
|
52
53
|
isSuccess: true,
|
|
@@ -61,23 +62,19 @@ export function computeView<V extends LikeC4View>(
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
export function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const compute = (source: LikeC4View): ComputedView => {
|
|
71
|
-
const result = computeView(source, likec4model)
|
|
72
|
-
if (result.isSuccess) {
|
|
73
|
-
return result.view
|
|
74
|
-
} else {
|
|
75
|
-
throw result.error
|
|
76
|
-
}
|
|
77
|
-
}
|
|
65
|
+
export function computeParsedModelData<A extends AnyAux>(
|
|
66
|
+
parsed: ParsedLikeC4ModelData<A>,
|
|
67
|
+
): ComputedLikeC4ModelData<A> {
|
|
68
|
+
const likec4model = LikeC4Model.create(parsed)
|
|
69
|
+
const views = values(parsed.views as Record<string, ParsedView<A>>)
|
|
70
|
+
.map(v => unsafeComputeView(v, likec4model))
|
|
78
71
|
return {
|
|
79
|
-
...
|
|
80
|
-
|
|
81
|
-
views:
|
|
82
|
-
}
|
|
72
|
+
...parsed,
|
|
73
|
+
[_stage]: 'computed',
|
|
74
|
+
views: indexBy(views, v => v.id),
|
|
75
|
+
} as ComputedLikeC4ModelData<A>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function computeLikeC4Model<A extends AnyAux>(parsed: ParsedLikeC4ModelData<A>): LikeC4Model.Computed<A> {
|
|
79
|
+
return LikeC4Model.create(computeParsedModelData(parsed))
|
|
83
80
|
}
|
|
@@ -11,10 +11,17 @@ 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 { AnyAux, LikeC4Model } from '../../../model'
|
|
14
15
|
import { differenceConnections } from '../../../model/connection'
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
import {
|
|
17
|
+
type ComputedDeploymentView,
|
|
18
|
+
type DeploymentViewRule,
|
|
19
|
+
type ParsedDeploymentView as DeploymentView,
|
|
20
|
+
type ViewId,
|
|
21
|
+
_stage,
|
|
22
|
+
_type,
|
|
23
|
+
} from '../../../types'
|
|
24
|
+
import { difference as differenceSet, imap, invariant, toArray } from '../../../utils'
|
|
18
25
|
import { withReadableEdges } from '../../utils/with-readable-edges'
|
|
19
26
|
import { processPredicates as processPredicatesImpl } from '../compute'
|
|
20
27
|
import { Memory } from '../memory'
|
|
@@ -36,7 +43,9 @@ type Elem = Memory['Ctx']['Element']
|
|
|
36
43
|
type Connection = Memory['Ctx']['Connection']
|
|
37
44
|
|
|
38
45
|
export class TestHelper<T extends AnyTypes> {
|
|
39
|
-
|
|
46
|
+
Aux!: Types.ToAux<T>
|
|
47
|
+
|
|
48
|
+
model: LikeC4Model.Computed<typeof this.Aux>
|
|
40
49
|
|
|
41
50
|
static $include = viewhelpers.$include
|
|
42
51
|
static $exclude = viewhelpers.$exclude
|
|
@@ -54,17 +63,18 @@ export class TestHelper<T extends AnyTypes> {
|
|
|
54
63
|
private builder: Builder<T>,
|
|
55
64
|
private _expect: ExpectStatic,
|
|
56
65
|
) {
|
|
57
|
-
this.model = builder.toLikeC4Model()
|
|
66
|
+
this.model = builder.toLikeC4Model()
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
computeView = (...rules: DeploymentRulesBuilderOp<T>[]) => {
|
|
70
|
+
const view = this.builder
|
|
71
|
+
.clone()
|
|
72
|
+
.views(_ => _.deploymentView('dev').with(...rules))
|
|
73
|
+
.toLikeC4Model()
|
|
74
|
+
.view('dev')
|
|
75
|
+
invariant(view.isDeploymentView())
|
|
61
76
|
return withReadableEdges(
|
|
62
|
-
|
|
63
|
-
.clone()
|
|
64
|
-
.views(_ => _.deploymentView('dev').with(...rules))
|
|
65
|
-
.toLikeC4Model()
|
|
66
|
-
.view('dev')
|
|
67
|
-
.$view as ComputedDeploymentView<'dev'>,
|
|
77
|
+
view.$view,
|
|
68
78
|
' -> ',
|
|
69
79
|
)
|
|
70
80
|
}
|
|
@@ -175,7 +185,7 @@ class ProcessPredicates<T extends AnyTypes> {
|
|
|
175
185
|
return processor
|
|
176
186
|
}
|
|
177
187
|
|
|
178
|
-
public viewrules: ReadonlyArray<DeploymentViewRule
|
|
188
|
+
public viewrules: ReadonlyArray<DeploymentViewRule<AnyAux>> = []
|
|
179
189
|
|
|
180
190
|
public previousMemory: Memory = Memory.empty()
|
|
181
191
|
public memory: Memory = Memory.empty()
|
|
@@ -216,9 +226,12 @@ class ProcessPredicates<T extends AnyTypes> {
|
|
|
216
226
|
next(...predicates: DeploymentRulesBuilderOp<T>[]): this {
|
|
217
227
|
const view = {
|
|
218
228
|
id: 'test' as ViewId,
|
|
219
|
-
|
|
229
|
+
[_stage]: 'parsed',
|
|
230
|
+
[_type]: 'deployment',
|
|
220
231
|
rules: [],
|
|
221
|
-
|
|
232
|
+
title: null,
|
|
233
|
+
description: null,
|
|
234
|
+
} as Writable<DeploymentView<typeof this.t.model.Aux>>
|
|
222
235
|
let vb = mkViewBuilder(view) as any
|
|
223
236
|
this.predicates = [
|
|
224
237
|
...this.predicates,
|
|
@@ -2,7 +2,7 @@ import { map, prop } from 'remeda'
|
|
|
2
2
|
import type { DeploymentRulesBuilderOp } from '../../../builder'
|
|
3
3
|
import { Builder } from '../../../builder'
|
|
4
4
|
import { LikeC4Model } from '../../../model'
|
|
5
|
-
import type { DeploymentView } from '../../../types'
|
|
5
|
+
import type { ParsedDeploymentView as DeploymentView } from '../../../types'
|
|
6
6
|
import { withReadableEdges } from '../../utils/with-readable-edges'
|
|
7
7
|
import { computeDeploymentView } from '../compute'
|
|
8
8
|
|
|
@@ -57,7 +57,17 @@ const {
|
|
|
57
57
|
zone: {},
|
|
58
58
|
node: {},
|
|
59
59
|
},
|
|
60
|
-
tags:
|
|
60
|
+
tags: {
|
|
61
|
+
old: {
|
|
62
|
+
color: 'red',
|
|
63
|
+
},
|
|
64
|
+
next: {
|
|
65
|
+
color: 'green',
|
|
66
|
+
},
|
|
67
|
+
temp: {
|
|
68
|
+
color: 'blue',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
61
71
|
relationships: { 'https': {} },
|
|
62
72
|
})
|
|
63
73
|
|
|
@@ -194,12 +204,9 @@ export function computeView(...rules: DeploymentRulesBuilderOp<Types>[]) {
|
|
|
194
204
|
),
|
|
195
205
|
).build()
|
|
196
206
|
|
|
197
|
-
const model = LikeC4Model.
|
|
198
|
-
...modelsource,
|
|
199
|
-
views: {},
|
|
200
|
-
})
|
|
207
|
+
const model = LikeC4Model.fromParsed(modelsource)
|
|
201
208
|
|
|
202
|
-
const view = withReadableEdges(computeDeploymentView(model, modelsource.views.index as DeploymentView))
|
|
209
|
+
const view = withReadableEdges(computeDeploymentView(model, modelsource.views.index as DeploymentView<any>))
|
|
203
210
|
|
|
204
211
|
return Object.assign(view, {
|
|
205
212
|
nodeIds: map(view.nodes, prop('id')) as string[],
|
|
@@ -217,10 +224,5 @@ export function computeNodesAndEdges(...rules: DeploymentRulesBuilderOp<Types>[]
|
|
|
217
224
|
}
|
|
218
225
|
|
|
219
226
|
export function createModel() {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return LikeC4Model.create({
|
|
223
|
-
...modelsource,
|
|
224
|
-
views: {},
|
|
225
|
-
})
|
|
227
|
+
return LikeC4Model.fromParsed(builder.build())
|
|
226
228
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
1
|
+
import type { RelationshipModel } from '../../model'
|
|
2
|
+
import { LikeC4DeploymentModel } from '../../model'
|
|
3
|
+
import type { AnyAux, Expression, OperatorPredicate } from '../../types'
|
|
4
4
|
import type { Ctx, Memory, Stage, StageExclude, StageInclude } from './memory'
|
|
5
5
|
|
|
6
6
|
export { Memory, type Stage } from './memory'
|
|
@@ -13,26 +13,26 @@ export type Connection = Ctx['Connection']
|
|
|
13
13
|
export type ElementWhere = Where<Elem>
|
|
14
14
|
export type ElementWhereFilter = (elements: readonly Elem[]) => Elem[]
|
|
15
15
|
export type ConnectionWhere = Where<Connection>
|
|
16
|
-
export type RelationshipWhere = Where<RelationshipModel
|
|
16
|
+
export type RelationshipWhere = Where<RelationshipModel<any>>
|
|
17
17
|
export type ConnectionWhereFilter = (connections: readonly Connection[]) => Connection[]
|
|
18
18
|
|
|
19
19
|
export type Connections = ReadonlyArray<Connection>
|
|
20
20
|
|
|
21
|
-
export interface PredicateCtx<Expr
|
|
21
|
+
export interface PredicateCtx<Expr = Expression<AnyAux>> {
|
|
22
22
|
expr: Expr
|
|
23
23
|
stage: Stage
|
|
24
|
-
model: LikeC4DeploymentModel
|
|
24
|
+
model: LikeC4DeploymentModel<AnyAux>
|
|
25
25
|
memory: Memory
|
|
26
|
-
where: OperatorPredicate<
|
|
26
|
+
where: OperatorPredicate<AnyAux> | null
|
|
27
27
|
}
|
|
28
|
-
export interface IncludePredicateCtx<Expr
|
|
28
|
+
export interface IncludePredicateCtx<Expr = Expression<AnyAux>> extends PredicateCtx<Expr> {
|
|
29
29
|
stage: StageInclude
|
|
30
30
|
}
|
|
31
|
-
export interface ExcludePredicateCtx<Expr
|
|
31
|
+
export interface ExcludePredicateCtx<Expr = Expression<AnyAux>> extends PredicateCtx<Expr> {
|
|
32
32
|
stage: StageExclude
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export interface PredicateExecutor<Expr extends
|
|
35
|
+
export interface PredicateExecutor<Expr extends Expression<AnyAux> = Expression<AnyAux>> {
|
|
36
36
|
include(ctx: IncludePredicateCtx<Expr>): StageInclude | undefined
|
|
37
37
|
exclude(ctx: ExcludePredicateCtx<Expr>): StageExclude | undefined
|
|
38
38
|
}
|
|
@@ -12,23 +12,21 @@ import {
|
|
|
12
12
|
reduce,
|
|
13
13
|
values,
|
|
14
14
|
} from 'remeda'
|
|
15
|
-
import {
|
|
15
|
+
import type { RelationshipModel } from '../../model'
|
|
16
16
|
import {
|
|
17
17
|
DeploymentConnectionModel,
|
|
18
18
|
differenceConnections,
|
|
19
19
|
isNestedConnection,
|
|
20
20
|
mergeConnections,
|
|
21
|
+
RelationshipsAccum,
|
|
21
22
|
sortConnectionsByBoundaryHierarchy,
|
|
22
|
-
} from '../../model
|
|
23
|
-
import {
|
|
24
|
-
import { RelationshipsAccum } from '../../model/DeploymentElementModel'
|
|
25
|
-
import type { RelationshipModel } from '../../model/RelationModel'
|
|
23
|
+
} from '../../model'
|
|
24
|
+
import { invariant } from '../../utils'
|
|
26
25
|
import { imap, toArray } from '../../utils/iterable'
|
|
27
26
|
import { DefaultMap } from '../../utils/mnemonist'
|
|
28
27
|
import { intersection, union } from '../../utils/set'
|
|
29
28
|
import type { Connection, Connections } from './_types'
|
|
30
|
-
|
|
31
|
-
const filterEmptyConnection = filter((c: DeploymentConnectionModel<any>) => c.nonEmpty())
|
|
29
|
+
import { findConnection } from './utils'
|
|
32
30
|
|
|
33
31
|
type MapOfExcludesFromConnection = DefaultMap<DeploymentConnectionModel, Set<RelationshipModel>>
|
|
34
32
|
function findCrossBoundarySameSourceOrTarget(connections: Connections): MapOfExcludesFromConnection {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { findLast, map } from 'remeda'
|
|
2
|
-
import { type LikeC4DeploymentModel, LikeC4Model } from '../../model'
|
|
3
|
-
import type { AnyAux } from '../../
|
|
4
|
-
import type { DeploymentViewRule } from '../../types'
|
|
2
|
+
import { type DeploymentConnectionModel, type LikeC4DeploymentModel, LikeC4Model } from '../../model'
|
|
3
|
+
import type { AnyAux, DeploymentViewRule } from '../../types'
|
|
5
4
|
import {
|
|
6
5
|
type ComputedDeploymentView,
|
|
7
|
-
type DeploymentView,
|
|
6
|
+
type ParsedDeploymentView as DeploymentView,
|
|
7
|
+
_stage,
|
|
8
|
+
_type,
|
|
8
9
|
isViewRuleAutoLayout,
|
|
9
10
|
isViewRulePredicate,
|
|
10
11
|
} from '../../types'
|
|
@@ -17,9 +18,9 @@ import { predicateToPatch } from './predicates'
|
|
|
17
18
|
import { StageFinal } from './stages/stage-final'
|
|
18
19
|
import { applyDeploymentViewRuleStyles, buildNodes, toComputedEdges } from './utils'
|
|
19
20
|
|
|
20
|
-
export function processPredicates
|
|
21
|
-
model: LikeC4DeploymentModel<
|
|
22
|
-
rules: DeploymentViewRule[],
|
|
21
|
+
export function processPredicates(
|
|
22
|
+
model: LikeC4DeploymentModel<any>,
|
|
23
|
+
rules: DeploymentViewRule<any>[],
|
|
23
24
|
) {
|
|
24
25
|
let memory = Memory.empty()
|
|
25
26
|
|
|
@@ -44,13 +45,13 @@ export function computeDeploymentView<M extends AnyAux>(
|
|
|
44
45
|
docUri: _docUri, // exclude docUri
|
|
45
46
|
rules, // exclude rules
|
|
46
47
|
...view
|
|
47
|
-
}: DeploymentView
|
|
48
|
-
): ComputedDeploymentView<M
|
|
49
|
-
const memory = processPredicates
|
|
48
|
+
}: DeploymentView<NoInfer<M>>,
|
|
49
|
+
): ComputedDeploymentView<M> {
|
|
50
|
+
const memory = processPredicates(likec4model.deployment, rules)
|
|
50
51
|
|
|
51
|
-
const nodesMap = buildNodes(memory)
|
|
52
|
+
const nodesMap = buildNodes<M>(memory)
|
|
52
53
|
|
|
53
|
-
const computedEdges = toComputedEdges(memory.connections)
|
|
54
|
+
const computedEdges = toComputedEdges(memory.connections as unknown as DeploymentConnectionModel<M>[])
|
|
54
55
|
|
|
55
56
|
linkNodesWithEdges(nodesMap, computedEdges)
|
|
56
57
|
|
|
@@ -70,6 +71,8 @@ export function computeDeploymentView<M extends AnyAux>(
|
|
|
70
71
|
|
|
71
72
|
return calcViewLayoutHash({
|
|
72
73
|
...view,
|
|
74
|
+
[_stage]: 'computed',
|
|
75
|
+
[_type]: 'deployment',
|
|
73
76
|
autoLayout: {
|
|
74
77
|
direction: autoLayoutRule?.direction ?? 'TB',
|
|
75
78
|
...(autoLayoutRule?.nodeSep && { nodeSep: autoLayoutRule.nodeSep }),
|
|
@@ -84,7 +87,7 @@ export function computeDeploymentView<M extends AnyAux>(
|
|
|
84
87
|
}),
|
|
85
88
|
...(elementNotations.length > 0 && {
|
|
86
89
|
notation: {
|
|
87
|
-
|
|
90
|
+
nodes: elementNotations,
|
|
88
91
|
},
|
|
89
92
|
}),
|
|
90
93
|
})
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { isDeepEqual } from 'remeda'
|
|
2
|
-
import
|
|
3
|
-
import type
|
|
4
|
-
import type { AnyAux } from '../../../
|
|
5
|
-
import type { ExpressionV2 } from '../../../types'
|
|
2
|
+
import type { DeploymentElementModel } from '../../../model'
|
|
3
|
+
import { type DeploymentConnectionModel, differenceConnections } from '../../../model'
|
|
4
|
+
import type { AnyAux, Expression } from '../../../types'
|
|
6
5
|
import { difference as differenceSet } from '../../../utils'
|
|
7
6
|
import { customInspectSymbol } from '../../../utils/const'
|
|
8
7
|
import { toArray } from '../../../utils/iterable'
|
|
9
|
-
import {
|
|
8
|
+
import { type ComputeCtx, type StageExpression, AbstractMemory } from '../../memory'
|
|
10
9
|
import { StageExclude } from '../stages/stage-exclude'
|
|
11
10
|
import { StageInclude } from '../stages/stage-include'
|
|
12
11
|
|
|
@@ -16,7 +15,7 @@ export type Ctx = ComputeCtx<
|
|
|
16
15
|
Memory,
|
|
17
16
|
StageInclude,
|
|
18
17
|
StageExclude,
|
|
19
|
-
|
|
18
|
+
Expression<AnyAux>
|
|
20
19
|
>
|
|
21
20
|
|
|
22
21
|
export class Memory extends AbstractMemory<Ctx> {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { filter, forEach, pipe, reduce } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type { DeploymentElementModel, DeploymentNodeModel } from '../../../model/DeploymentElementModel'
|
|
2
|
+
import type { DeploymentElementModel, DeploymentNodeModel } from '../../../model'
|
|
3
|
+
import { isDeployedInstanceModel as isDeployedInstance } from '../../../model'
|
|
5
4
|
import type { FqnExpr } from '../../../types'
|
|
6
5
|
import type { Elem, IncludePredicateCtx, PredicateExecutor } from '../_types'
|
|
7
6
|
import { cleanCrossBoundary, cleanRedundantRelationships } from '../clean-connections'
|
|
8
7
|
import type { StageInclude } from '../memory'
|
|
9
|
-
import { deploymentExpressionToPredicate } from '../utils'
|
|
8
|
+
import { deploymentExpressionToPredicate, findConnectionsBetween, findConnectionsWithin } from '../utils'
|
|
10
9
|
import { applyElementPredicate } from './utils'
|
|
11
10
|
|
|
12
11
|
export const DeploymentRefPredicate: PredicateExecutor<FqnExpr.DeploymentRef> = {
|
|
@@ -46,7 +45,7 @@ export const DeploymentRefPredicate: PredicateExecutor<FqnExpr.DeploymentRef> =
|
|
|
46
45
|
const exprPredicate = deploymentExpressionToPredicate(expr)
|
|
47
46
|
const toExclude = pipe(
|
|
48
47
|
[...memory.elements],
|
|
49
|
-
filter
|
|
48
|
+
filter(exprPredicate),
|
|
50
49
|
applyElementPredicate(where),
|
|
51
50
|
)
|
|
52
51
|
stage.exclude(toExclude)
|
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import { filter, flatMap, isNonNullish, map,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { filter, flatMap, isNonNullish, map, pipe } from 'remeda'
|
|
2
|
+
import type {
|
|
3
|
+
DeploymentConnectionModel,
|
|
4
|
+
DeploymentElementModel,
|
|
5
|
+
LikeC4DeploymentModel,
|
|
6
|
+
RelationshipModel,
|
|
7
|
+
} from '../../../model'
|
|
5
8
|
import {
|
|
6
9
|
type ConnectionModel,
|
|
7
10
|
findConnectionsBetween as findModelConnectionsBetween,
|
|
8
11
|
} from '../../../model/connection/model'
|
|
9
|
-
import type {
|
|
10
|
-
import type
|
|
11
|
-
import
|
|
12
|
-
import type { AnyAux } from '../../../model/types'
|
|
13
|
-
import { type Filterable, type OperatorPredicate, type RelationExpr, FqnExpr } from '../../../types'
|
|
12
|
+
import type { AnyAux } from '../../../types'
|
|
13
|
+
import { type RelationExpr, FqnExpr } from '../../../types'
|
|
14
|
+
import { invariant } from '../../../utils'
|
|
14
15
|
import type { PredicateExecutor } from '../_types'
|
|
15
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
deploymentExpressionToPredicate,
|
|
18
|
+
findConnection,
|
|
19
|
+
findConnectionsBetween,
|
|
20
|
+
findConnectionsWithin,
|
|
21
|
+
resolveElements,
|
|
22
|
+
resolveModelElements,
|
|
23
|
+
} from '../utils'
|
|
16
24
|
import { filterIncomingConnections, resolveAllImcomingRelations } from './relation-incoming'
|
|
17
25
|
import { filterOutgoingConnections, resolveAllOutgoingRelations } from './relation-outgoing'
|
|
18
26
|
import { applyPredicate, excludeModelRelations } from './utils'
|
|
@@ -30,7 +38,7 @@ export const resolveAscendingSiblings = (element: DeploymentElementModel) => {
|
|
|
30
38
|
return siblings
|
|
31
39
|
}
|
|
32
40
|
|
|
33
|
-
const resolveWildcard = (model: LikeC4DeploymentModel
|
|
41
|
+
const resolveWildcard = (model: LikeC4DeploymentModel<AnyAux>, nonWildcard: FqnExpr.DeploymentRef) => {
|
|
34
42
|
const sources = resolveElements(model, nonWildcard)
|
|
35
43
|
return sources.map(source => {
|
|
36
44
|
const targets = resolveAscendingSiblings(source)
|
|
@@ -210,59 +218,26 @@ export const DirectRelationPredicate: PredicateExecutor<RelationExpr.Direct> = {
|
|
|
210
218
|
},
|
|
211
219
|
}
|
|
212
220
|
|
|
213
|
-
function resolveRelationsBetweenModelElements({
|
|
221
|
+
function resolveRelationsBetweenModelElements<A extends AnyAux>({
|
|
214
222
|
source,
|
|
215
223
|
target,
|
|
216
224
|
expr,
|
|
217
225
|
model,
|
|
218
226
|
}: {
|
|
219
|
-
source: FqnExpr.ModelRef
|
|
220
|
-
target: FqnExpr.ModelRef
|
|
221
|
-
expr: RelationExpr.Direct
|
|
222
|
-
model: LikeC4DeploymentModel
|
|
227
|
+
source: FqnExpr.ModelRef<A>
|
|
228
|
+
target: FqnExpr.ModelRef<A>
|
|
229
|
+
expr: RelationExpr.Direct<A>
|
|
230
|
+
model: LikeC4DeploymentModel<A>
|
|
223
231
|
}) {
|
|
224
232
|
const sources = resolveModelElements(model, source)
|
|
225
233
|
const targets = resolveModelElements(model, target)
|
|
226
234
|
|
|
227
235
|
const dir = expr.isBidirectional ? 'both' : 'directed'
|
|
228
236
|
|
|
229
|
-
const modelConnections = [] as ConnectionModel[]
|
|
237
|
+
const modelConnections = [] as ConnectionModel<A>[]
|
|
230
238
|
for (const source of sources) {
|
|
231
239
|
modelConnections.push(...findModelConnectionsBetween(source, targets, dir))
|
|
232
240
|
}
|
|
233
241
|
|
|
234
242
|
return new Set(modelConnections.flatMap(c => [...c.relations]))
|
|
235
243
|
}
|
|
236
|
-
|
|
237
|
-
function elementToFilterable<M extends AnyAux>(element: DeploymentElementModel<M>) {
|
|
238
|
-
return pick(element, ['tags', 'kind'])
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function toFilterableRelation<M extends AnyAux>(
|
|
242
|
-
source: DeploymentElementModel<M>,
|
|
243
|
-
target: DeploymentElementModel<M>,
|
|
244
|
-
) {
|
|
245
|
-
return (
|
|
246
|
-
relation: RelationshipModel<M> | DeploymentRelationModel<M>,
|
|
247
|
-
) => ({
|
|
248
|
-
tags: relation.tags,
|
|
249
|
-
kind: relation.kind,
|
|
250
|
-
source: elementToFilterable(source),
|
|
251
|
-
target: elementToFilterable(target),
|
|
252
|
-
})
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function matchConnection<M extends AnyAux>(
|
|
256
|
-
c: DeploymentConnectionModel<M>,
|
|
257
|
-
where: OperatorPredicate<Filterable> | null,
|
|
258
|
-
): boolean {
|
|
259
|
-
if (!where) {
|
|
260
|
-
return true
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return [
|
|
264
|
-
...Array.from(c.relations.deployment.values()).map(toFilterableRelation(c.source, c.target)),
|
|
265
|
-
...Array.from(c.relations.model.values()).map(toFilterableRelation(c.source, c.target)),
|
|
266
|
-
]
|
|
267
|
-
.filter(where).length > 0
|
|
268
|
-
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { filter, pipe } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import type { AnyAux } from '../../../model/types'
|
|
6
|
-
import { type RelationExpr, FqnExpr } from '../../../types/expression-v2'
|
|
2
|
+
import type { RelationshipModel } from '../../../model'
|
|
3
|
+
import { type RelationExpr, FqnExpr } from '../../../types'
|
|
4
|
+
import { invariant } from '../../../utils'
|
|
7
5
|
import { union } from '../../../utils/set'
|
|
8
6
|
import type { PredicateExecutor } from '../_types'
|
|
9
|
-
import { resolveElements, resolveModelElements } from '../utils'
|
|
7
|
+
import { findConnectionsBetween, resolveElements, resolveModelElements } from '../utils'
|
|
10
8
|
import { resolveAscendingSiblings } from './relation-direct'
|
|
11
9
|
import { filterIncomingConnections } from './relation-incoming'
|
|
12
10
|
import { filterOutgoingConnections } from './relation-outgoing'
|
|
@@ -46,7 +44,7 @@ export const InOutRelationPredicate: PredicateExecutor<RelationExpr.InOut> = {
|
|
|
46
44
|
return stage
|
|
47
45
|
}
|
|
48
46
|
const excludedRelations = union(
|
|
49
|
-
new Set<RelationshipModel
|
|
47
|
+
new Set<RelationshipModel>(),
|
|
50
48
|
...elements.flatMap(e => [e.allIncoming, e.allOutgoing]),
|
|
51
49
|
)
|
|
52
50
|
return excludeModelRelations(excludedRelations, { stage, memory }, where)
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { anyPass, filter, pipe } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import { findConnectionsBetween } from '../../../model/connection/deployment'
|
|
4
|
-
import type { LikeC4DeploymentModel } from '../../../model/DeploymentModel'
|
|
5
|
-
import type { RelationshipModel } from '../../../model/RelationModel'
|
|
6
|
-
import type { AnyAux } from '../../../model/types'
|
|
2
|
+
import type { AnyAux, LikeC4DeploymentModel, RelationshipModel } from '../../../model'
|
|
7
3
|
import { type RelationExpr, FqnExpr } from '../../../types'
|
|
8
|
-
import { isAncestor } from '../../../utils'
|
|
4
|
+
import { invariant, isAncestor } from '../../../utils'
|
|
9
5
|
import type { Connection, Elem, PredicateExecutor } from '../_types'
|
|
10
|
-
import { resolveElements, resolveModelElements } from '../utils'
|
|
6
|
+
import { findConnectionsBetween, resolveElements, resolveModelElements } from '../utils'
|
|
11
7
|
import { resolveAscendingSiblings } from './relation-direct'
|
|
12
8
|
import { applyPredicate, excludeModelRelations } from './utils'
|
|
13
9
|
|
|
@@ -96,10 +92,10 @@ export function filterIncomingConnections(
|
|
|
96
92
|
// }
|
|
97
93
|
// }
|
|
98
94
|
|
|
99
|
-
export function resolveAllImcomingRelations(
|
|
100
|
-
model: LikeC4DeploymentModel
|
|
101
|
-
moodelRef: FqnExpr.ModelRef
|
|
102
|
-
): Set<RelationshipModel<
|
|
95
|
+
export function resolveAllImcomingRelations<A extends AnyAux>(
|
|
96
|
+
model: LikeC4DeploymentModel<A>,
|
|
97
|
+
moodelRef: FqnExpr.ModelRef<A>,
|
|
98
|
+
): Set<RelationshipModel<A>> {
|
|
103
99
|
const targets = resolveModelElements(model, moodelRef)
|
|
104
100
|
return new Set(targets.flatMap(e => [...e.allIncoming]))
|
|
105
101
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { anyPass, filter, pipe } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import { findConnection, findConnectionsBetween } from '../../../model/connection/deployment'
|
|
4
|
-
import type { LikeC4DeploymentModel } from '../../../model/DeploymentModel'
|
|
5
|
-
import type { RelationshipModel } from '../../../model/RelationModel'
|
|
2
|
+
import type { AnyAux, LikeC4DeploymentModel, RelationshipModel } from '../../../model'
|
|
6
3
|
import { type RelationExpr, FqnExpr } from '../../../types'
|
|
7
|
-
import { isAncestor } from '../../../utils'
|
|
4
|
+
import { invariant, isAncestor } from '../../../utils'
|
|
8
5
|
import type { Connection, Elem, PredicateExecutor } from '../_types'
|
|
9
|
-
import { resolveElements, resolveModelElements } from '../utils'
|
|
6
|
+
import { findConnection, findConnectionsBetween, resolveElements, resolveModelElements } from '../utils'
|
|
10
7
|
import { resolveAscendingSiblings } from './relation-direct'
|
|
11
8
|
import { applyPredicate, excludeModelRelations } from './utils'
|
|
12
9
|
|
|
@@ -89,10 +86,10 @@ export function filterOutgoingConnections(
|
|
|
89
86
|
// }
|
|
90
87
|
}
|
|
91
88
|
|
|
92
|
-
export function resolveAllOutgoingRelations(
|
|
93
|
-
model: LikeC4DeploymentModel
|
|
94
|
-
moodelRef: FqnExpr.ModelRef
|
|
95
|
-
): Set<RelationshipModel
|
|
89
|
+
export function resolveAllOutgoingRelations<A extends AnyAux>(
|
|
90
|
+
model: LikeC4DeploymentModel<A>,
|
|
91
|
+
moodelRef: FqnExpr.ModelRef<A>,
|
|
92
|
+
): Set<RelationshipModel<A>> {
|
|
96
93
|
const targets = resolveModelElements(model, moodelRef)
|
|
97
94
|
return new Set(targets.flatMap(e => [...e.allOutgoing]))
|
|
98
95
|
}
|