@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,24 +1,17 @@
|
|
|
1
1
|
import { anyPass, unique } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
Connection,
|
|
7
|
-
findConnection,
|
|
8
|
-
findConnectionsBetween,
|
|
9
|
-
} from '../../../model/connection/model'
|
|
10
|
-
import type { RelationshipModel } from '../../../model/RelationModel'
|
|
11
|
-
import type { AnyAux } from '../../../model/types'
|
|
12
|
-
import { ModelLayer } from '../../../types/expression-v2-model'
|
|
2
|
+
import { type ConnectionModel, type LikeC4Model, type RelationshipModel, Connection } from '../../../model'
|
|
3
|
+
import type { ModelRelationExpr } from '../../../types'
|
|
4
|
+
import { type AnyAux, FqnRef, ModelFqnExpr } from '../../../types'
|
|
5
|
+
import { nonexhaustive } from '../../../utils'
|
|
13
6
|
import { elementExprToPredicate } from '../../utils/elementExpressionToPredicate'
|
|
14
7
|
import type { ConnectionWhere, PredicateExecutor } from '../_types'
|
|
15
|
-
import { resolveAndIncludeFromMemory, resolveElements } from './_utils'
|
|
8
|
+
import { findConnection, findConnectionsBetween, resolveAndIncludeFromMemory, resolveElements } from './_utils'
|
|
16
9
|
|
|
17
|
-
export const IncomingExprPredicate: PredicateExecutor<
|
|
10
|
+
export const IncomingExprPredicate: PredicateExecutor<ModelRelationExpr.Incoming<AnyAux>> = {
|
|
18
11
|
include: ({ expr, scope, model, memory, stage, filterWhere }) => {
|
|
19
12
|
const target = expr.incoming
|
|
20
13
|
const connections = [] as ConnectionModel<AnyAux>[]
|
|
21
|
-
if (
|
|
14
|
+
if (ModelFqnExpr.isWildcard(target)) {
|
|
22
15
|
if (!scope) {
|
|
23
16
|
return
|
|
24
17
|
}
|
|
@@ -61,7 +54,7 @@ export const IncomingExprPredicate: PredicateExecutor<ModelLayer.RelationExpr.In
|
|
|
61
54
|
},
|
|
62
55
|
exclude: ({ expr: { incoming }, model, scope, stage, where }) => {
|
|
63
56
|
const excluded = [] as RelationshipModel[]
|
|
64
|
-
if (
|
|
57
|
+
if (ModelFqnExpr.isWildcard(incoming)) {
|
|
65
58
|
if (!scope) {
|
|
66
59
|
return
|
|
67
60
|
}
|
|
@@ -80,24 +73,24 @@ export const IncomingExprPredicate: PredicateExecutor<ModelLayer.RelationExpr.In
|
|
|
80
73
|
|
|
81
74
|
export function incomingConnectionPredicate(
|
|
82
75
|
model: LikeC4Model,
|
|
83
|
-
expr:
|
|
76
|
+
expr: ModelFqnExpr.NonWildcard,
|
|
84
77
|
): ConnectionWhere {
|
|
85
78
|
switch (true) {
|
|
86
|
-
case
|
|
87
|
-
case
|
|
79
|
+
case ModelFqnExpr.isElementKindExpr(expr):
|
|
80
|
+
case ModelFqnExpr.isElementTagExpr(expr): {
|
|
88
81
|
const isElement = elementExprToPredicate(expr)
|
|
89
82
|
return (connection) => isElement(connection.target)
|
|
90
83
|
}
|
|
91
|
-
case
|
|
92
|
-
const fqn =
|
|
84
|
+
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'children': {
|
|
85
|
+
const fqn = FqnRef.flatten(expr.ref)
|
|
93
86
|
return anyPass(
|
|
94
87
|
[...model.children(fqn)].map(
|
|
95
88
|
el => Connection.isIncoming(el.id),
|
|
96
89
|
),
|
|
97
90
|
)
|
|
98
91
|
}
|
|
99
|
-
case
|
|
100
|
-
const fqn =
|
|
92
|
+
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'descendants': {
|
|
93
|
+
const fqn = FqnRef.flatten(expr.ref)
|
|
101
94
|
return anyPass([
|
|
102
95
|
Connection.isInside(fqn),
|
|
103
96
|
...[...model.children(fqn)].map(
|
|
@@ -105,15 +98,15 @@ export function incomingConnectionPredicate(
|
|
|
105
98
|
),
|
|
106
99
|
])
|
|
107
100
|
}
|
|
108
|
-
case
|
|
109
|
-
const fqn =
|
|
101
|
+
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'expanded': {
|
|
102
|
+
const fqn = FqnRef.flatten(expr.ref)
|
|
110
103
|
return anyPass([
|
|
111
104
|
Connection.isIncoming(fqn),
|
|
112
105
|
Connection.isInside(fqn),
|
|
113
106
|
])
|
|
114
107
|
}
|
|
115
|
-
case
|
|
116
|
-
const fqn =
|
|
108
|
+
case ModelFqnExpr.isModelRef(expr): {
|
|
109
|
+
const fqn = FqnRef.flatten(expr.ref)
|
|
117
110
|
return Connection.isIncoming(fqn)
|
|
118
111
|
}
|
|
119
112
|
default:
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { anyPass, unique } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import { type ConnectionModel, Connection
|
|
4
|
-
import type {
|
|
5
|
-
import type
|
|
6
|
-
import
|
|
7
|
-
import { ModelLayer } from '../../../types/expression-v2-model'
|
|
2
|
+
import type { LikeC4Model, RelationshipModel } from '../../../model'
|
|
3
|
+
import { type ConnectionModel, Connection } from '../../../model'
|
|
4
|
+
import type { AnyAux } from '../../../types'
|
|
5
|
+
import { type ModelRelationExpr, FqnRef, ModelFqnExpr } from '../../../types'
|
|
6
|
+
import { nonexhaustive } from '../../../utils'
|
|
8
7
|
import { toSet } from '../../../utils/iterable/to'
|
|
9
8
|
import { elementExprToPredicate } from '../../utils/elementExpressionToPredicate'
|
|
10
9
|
import type { ConnectionWhere, PredicateExecutor } from '../_types'
|
|
11
|
-
import { resolveAndIncludeFromMemory, resolveElements } from './_utils'
|
|
10
|
+
import { findConnectionsBetween, resolveAndIncludeFromMemory, resolveElements } from './_utils'
|
|
12
11
|
|
|
13
|
-
export const OutgoingExprPredicate: PredicateExecutor<
|
|
12
|
+
export const OutgoingExprPredicate: PredicateExecutor<ModelRelationExpr.Outgoing<AnyAux>> = {
|
|
14
13
|
include: ({ expr, scope, model, memory, stage, filterWhere }) => {
|
|
15
14
|
const target = expr.outgoing
|
|
16
15
|
const connections = [] as ConnectionModel<AnyAux>[]
|
|
17
|
-
if (
|
|
16
|
+
if (ModelFqnExpr.isWildcard(target)) {
|
|
18
17
|
if (!scope) {
|
|
19
18
|
return
|
|
20
19
|
}
|
|
@@ -57,7 +56,7 @@ export const OutgoingExprPredicate: PredicateExecutor<ModelLayer.RelationExpr.Ou
|
|
|
57
56
|
},
|
|
58
57
|
exclude: ({ expr: { outgoing }, model, scope, stage, where }) => {
|
|
59
58
|
const excluded = [] as RelationshipModel[]
|
|
60
|
-
if (
|
|
59
|
+
if (ModelFqnExpr.isWildcard(outgoing)) {
|
|
61
60
|
if (!scope) {
|
|
62
61
|
return
|
|
63
62
|
}
|
|
@@ -78,24 +77,24 @@ export const OutgoingExprPredicate: PredicateExecutor<ModelLayer.RelationExpr.Ou
|
|
|
78
77
|
|
|
79
78
|
export function outgoingConnectionPredicate(
|
|
80
79
|
model: LikeC4Model,
|
|
81
|
-
expr:
|
|
80
|
+
expr: ModelFqnExpr.NonWildcard,
|
|
82
81
|
): ConnectionWhere {
|
|
83
82
|
switch (true) {
|
|
84
|
-
case
|
|
85
|
-
case
|
|
83
|
+
case ModelFqnExpr.isElementKindExpr(expr):
|
|
84
|
+
case ModelFqnExpr.isElementTagExpr(expr): {
|
|
86
85
|
const isElement = elementExprToPredicate(expr)
|
|
87
86
|
return (connection) => isElement(connection.source)
|
|
88
87
|
}
|
|
89
|
-
case
|
|
90
|
-
const fqn =
|
|
88
|
+
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'children': {
|
|
89
|
+
const fqn = FqnRef.flatten(expr.ref)
|
|
91
90
|
return anyPass(
|
|
92
91
|
[...model.children(fqn)].map(
|
|
93
92
|
el => Connection.isOutgoing(el.id),
|
|
94
93
|
),
|
|
95
94
|
)
|
|
96
95
|
}
|
|
97
|
-
case
|
|
98
|
-
const fqn =
|
|
96
|
+
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'descendants': {
|
|
97
|
+
const fqn = FqnRef.flatten(expr.ref)
|
|
99
98
|
return anyPass([
|
|
100
99
|
Connection.isInside(fqn),
|
|
101
100
|
...[...model.children(fqn)].map(
|
|
@@ -103,15 +102,15 @@ export function outgoingConnectionPredicate(
|
|
|
103
102
|
),
|
|
104
103
|
])
|
|
105
104
|
}
|
|
106
|
-
case
|
|
107
|
-
const fqn =
|
|
105
|
+
case ModelFqnExpr.isModelRef(expr) && expr.selector === 'expanded': {
|
|
106
|
+
const fqn = FqnRef.flatten(expr.ref)
|
|
108
107
|
return anyPass([
|
|
109
108
|
Connection.isOutgoing(fqn),
|
|
110
109
|
Connection.isInside(fqn),
|
|
111
110
|
])
|
|
112
111
|
}
|
|
113
|
-
case
|
|
114
|
-
const fqn =
|
|
112
|
+
case ModelFqnExpr.isModelRef(expr): {
|
|
113
|
+
const fqn = FqnRef.flatten(expr.ref)
|
|
115
114
|
return Connection.isOutgoing(fqn)
|
|
116
115
|
}
|
|
117
116
|
default:
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { filter } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import type { ModelLayer } from '../../../types/expression-v2-model'
|
|
2
|
+
import type { ModelFqnExpr } from '../../../types'
|
|
4
3
|
import { ifilter, toArray } from '../../../utils/iterable'
|
|
5
4
|
import { toSet } from '../../../utils/iterable/to'
|
|
6
5
|
import { type PredicateExecutor, Memory } from '../_types'
|
|
7
6
|
import { NoWhere } from '../utils'
|
|
7
|
+
import { findConnectionsBetween, findConnectionsWithin } from './_utils'
|
|
8
8
|
|
|
9
|
-
export const WildcardPredicate: PredicateExecutor<
|
|
9
|
+
export const WildcardPredicate: PredicateExecutor<ModelFqnExpr.Wildcard> = {
|
|
10
10
|
include: ({ scope, model, stage, memory, where }) => {
|
|
11
11
|
if (!scope) {
|
|
12
12
|
const rootElements = [...model.roots()].filter(where)
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { filter, hasAtLeast, only } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import type { ConnectionModel } from '../../model'
|
|
3
|
+
import {
|
|
4
|
+
type AnyAux,
|
|
5
|
+
type ComputedEdge,
|
|
6
|
+
type ComputedNode,
|
|
7
|
+
type scalar,
|
|
8
|
+
} from '../../types'
|
|
9
|
+
import { invariant } from '../../utils'
|
|
10
|
+
import { buildComputedNodes, elementModelToNodeSource } from '../utils/buildComputedNodes'
|
|
5
11
|
import { mergePropsFromRelationships } from '../utils/merge-props-from-relationships'
|
|
6
|
-
import type {
|
|
12
|
+
import type { Memory } from './_types'
|
|
7
13
|
|
|
8
14
|
export const NoWhere = () => true
|
|
9
15
|
export const NoFilter = <T>(x: T[] | readonly T[]): T[] => x as T[]
|
|
10
16
|
|
|
11
|
-
export function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
modelRef: 1,
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function toComputedEdges(
|
|
19
|
-
connections: ReadonlyArray<Connection>,
|
|
20
|
-
): ComputedEdge[] {
|
|
17
|
+
export function toComputedEdges<A extends AnyAux>(
|
|
18
|
+
connections: ReadonlyArray<ConnectionModel<A>>,
|
|
19
|
+
): ComputedEdge<A>[] {
|
|
21
20
|
return connections.reduce((acc, e) => {
|
|
22
21
|
// const modelRelations = []
|
|
23
22
|
// const deploymentRelations = []
|
|
@@ -41,11 +40,11 @@ export function toComputedEdges(
|
|
|
41
40
|
)?.$relationship,
|
|
42
41
|
)
|
|
43
42
|
|
|
44
|
-
const edge: ComputedEdge = {
|
|
43
|
+
const edge: ComputedEdge<A> = {
|
|
45
44
|
id: e.id,
|
|
46
|
-
parent: e.boundary?.id ?? null,
|
|
47
|
-
source,
|
|
48
|
-
target,
|
|
45
|
+
parent: e.boundary?.id as scalar.NodeId ?? null,
|
|
46
|
+
source: source as scalar.NodeId,
|
|
47
|
+
target: target as scalar.NodeId,
|
|
49
48
|
label: title ?? null,
|
|
50
49
|
relations: relations.map((r) => r.id),
|
|
51
50
|
...props,
|
|
@@ -53,11 +52,14 @@ export function toComputedEdges(
|
|
|
53
52
|
|
|
54
53
|
acc.push(edge)
|
|
55
54
|
return acc
|
|
56
|
-
}, [] as ComputedEdge[])
|
|
55
|
+
}, [] as ComputedEdge<A>[])
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
export function buildNodes
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return buildComputedNodes(
|
|
58
|
+
export function buildNodes<A extends AnyAux>(
|
|
59
|
+
memory: Memory,
|
|
60
|
+
): ReadonlyMap<scalar.NodeId, ComputedNode<A>> {
|
|
61
|
+
return buildComputedNodes(
|
|
62
|
+
[...memory.final].map(elementModelToNodeSource),
|
|
63
|
+
memory.groups,
|
|
64
|
+
)
|
|
63
65
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { computeLikeC4Model, computeParsedModelData, computeView, unsafeComputeView } from './compute-view'
|
|
2
2
|
export type { ComputeViewResult } from './compute-view'
|
|
3
3
|
export { resolveRulesExtendedViews } from './utils/resolve-extended-views'
|
|
4
4
|
export { viewsWithReadableEdges, withReadableEdges } from './utils/with-readable-edges'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isBoolean, pipe } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { difference, intersection, isDescendantOf, isIterable } from '../../utils'
|
|
2
|
+
import { findAscendingConnections } from '../../model'
|
|
3
|
+
import { difference, intersection, invariant, isDescendantOf, isIterable } from '../../utils'
|
|
5
4
|
import { ifilter, isome, toSet } from '../../utils/iterable'
|
|
6
5
|
import type { AnyCtx, CtxConnection, CtxElement, MutableState, StageExclude, StageExpression } from './_types'
|
|
7
6
|
|
|
@@ -209,7 +208,7 @@ export abstract class AbstractStageExclude<T extends AnyCtx> implements StageExc
|
|
|
209
208
|
state = this.removeElements(state)
|
|
210
209
|
}
|
|
211
210
|
|
|
212
|
-
//state = this.moveDisconnectedExplicitsToImplicits(state)
|
|
211
|
+
// state = this.moveDisconnectedExplicitsToImplicits(state)
|
|
213
212
|
|
|
214
213
|
return this.memory.update(this.postcommit(state))
|
|
215
214
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Connection } from '../../model/connection'
|
|
2
2
|
import type { DeploymentElementModel } from '../../model/DeploymentElementModel'
|
|
3
3
|
import type { ElementModel } from '../../model/ElementModel'
|
|
4
|
+
import type { AnyAux } from '../../types'
|
|
4
5
|
|
|
5
|
-
type Element = ElementModel | DeploymentElementModel
|
|
6
|
+
type Element<A extends AnyAux> = ElementModel<A> | DeploymentElementModel<A>
|
|
6
7
|
|
|
7
8
|
export interface ComputeCtx<
|
|
8
|
-
E extends Element
|
|
9
|
+
E extends Element<AnyAux>,
|
|
9
10
|
C extends Connection<E, any>,
|
|
10
11
|
M extends ComputeMemory<any>,
|
|
11
12
|
Inc extends StageInclude<any>,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type { AnyAux } from '../../model/types'
|
|
1
|
+
import type { ElementModel, RelationshipModel } from '../../model'
|
|
2
|
+
import type { AnyAux, Unknown } from '../../types'
|
|
4
3
|
|
|
5
4
|
// type Pair = {
|
|
6
5
|
// left: ReadonlySet<ElementModel>
|
|
@@ -8,7 +7,7 @@ import type { AnyAux } from '../../model/types'
|
|
|
8
7
|
// right: ReadonlySet<ElementModel>
|
|
9
8
|
// }
|
|
10
9
|
|
|
11
|
-
export type RelationshipsViewData<M extends AnyAux =
|
|
10
|
+
export type RelationshipsViewData<M extends AnyAux = Unknown> = {
|
|
12
11
|
incomers: ReadonlySet<ElementModel<M>>
|
|
13
12
|
incoming: ReadonlySet<RelationshipModel<M>>
|
|
14
13
|
subjects: ReadonlySet<ElementModel<M>>
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { pipe } from 'remeda'
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
5
|
-
import type { RelationshipModel } from '../../model/RelationModel'
|
|
6
|
-
import type { AnyAux } from '../../model/types'
|
|
7
|
-
import type { LikeC4ViewModel } from '../../model/view/LikeC4ViewModel'
|
|
2
|
+
import type { ElementModel, LikeC4Model, LikeC4ViewModel, RelationshipModel } from '../../model'
|
|
3
|
+
import type { AnyAux, aux } from '../../types'
|
|
4
|
+
import { invariant } from '../../utils'
|
|
8
5
|
import { isDescendantOf, sortParentsFirst } from '../../utils/fqn'
|
|
9
6
|
import { ifilter, imap, toArray, toSet } from '../../utils/iterable'
|
|
10
7
|
import type { RelationshipsViewData } from './_types'
|
|
@@ -104,10 +101,10 @@ function computeRelationships<const M extends AnyAux>(
|
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
103
|
|
|
107
|
-
export function computeRelationshipsView<
|
|
108
|
-
subjectId:
|
|
104
|
+
export function computeRelationshipsView<M extends AnyAux>(
|
|
105
|
+
subjectId: aux.ElementId<M>,
|
|
109
106
|
likec4model: LikeC4Model<M>,
|
|
110
|
-
scopeViewId:
|
|
107
|
+
scopeViewId: aux.ViewId<M> | null,
|
|
111
108
|
scope: 'global' | 'view' = 'global',
|
|
112
109
|
): RelationshipsViewData<M> {
|
|
113
110
|
let subjectExistsInScope = true
|
|
@@ -132,8 +129,8 @@ export function computeRelationshipsView<const M extends AnyAux>(
|
|
|
132
129
|
)
|
|
133
130
|
}
|
|
134
131
|
|
|
135
|
-
function computeScopedRelationshipsView<
|
|
136
|
-
subjectId: NoInfer<M
|
|
132
|
+
function computeScopedRelationshipsView<M extends AnyAux>(
|
|
133
|
+
subjectId: NoInfer<aux.ElementId<M>>,
|
|
137
134
|
view: LikeC4ViewModel<M>,
|
|
138
135
|
likec4model: LikeC4Model<M>,
|
|
139
136
|
): RelationshipsViewData<M> {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import dagre, { type EdgeConfig, type GraphLabel } from '@dagrejs/dagre'
|
|
2
2
|
import { concat, filter, forEachObj, groupBy, map, mapToObj, pipe, prop, reduce, tap } from 'remeda'
|
|
3
|
-
import { invariant } from '../../errors'
|
|
4
3
|
import type { ElementModel } from '../../model/ElementModel'
|
|
5
4
|
import type { RelationshipModel } from '../../model/RelationModel'
|
|
6
5
|
import type { DiagramNode, DiagramView, Fqn, NodeId } from '../../types'
|
|
7
|
-
import { sortParentsFirst } from '../../utils'
|
|
6
|
+
import { invariant, sortParentsFirst } from '../../utils'
|
|
8
7
|
import { toArray } from '../../utils/iterable'
|
|
9
8
|
import { DefaultMap } from '../../utils/mnemonist'
|
|
10
9
|
import type { RelationshipsViewData } from './_types'
|
|
@@ -43,7 +42,7 @@ const Sizes = {
|
|
|
43
42
|
}
|
|
44
43
|
type NodeData = {
|
|
45
44
|
portId: string
|
|
46
|
-
element: ElementModel
|
|
45
|
+
element: ElementModel<any>
|
|
47
46
|
isCompound: boolean
|
|
48
47
|
}
|
|
49
48
|
function createGraph() {
|
|
@@ -80,7 +79,7 @@ const PortSuffix = '-port'
|
|
|
80
79
|
|
|
81
80
|
function createNodes(
|
|
82
81
|
prefix: string,
|
|
83
|
-
elements: ReadonlySet<ElementModel
|
|
82
|
+
elements: ReadonlySet<ElementModel<any>>,
|
|
84
83
|
g: G,
|
|
85
84
|
) {
|
|
86
85
|
const graphNodes = new DefaultMap<Fqn, { id: string; portId: string }>(key => ({
|
|
@@ -315,11 +314,12 @@ export function layoutRelationshipsView(data: RelationshipsViewData): Pick<Diagr
|
|
|
315
314
|
return {
|
|
316
315
|
id: id as NodeId,
|
|
317
316
|
parent: parentId as NodeId ?? null,
|
|
318
|
-
position: [position.x, position.y],
|
|
319
317
|
title: element.title,
|
|
318
|
+
...position,
|
|
319
|
+
position: [position.x, position.y],
|
|
320
320
|
description: element.description,
|
|
321
321
|
technology: element.technology,
|
|
322
|
-
tags:
|
|
322
|
+
tags: [],
|
|
323
323
|
links: null,
|
|
324
324
|
color: element.color,
|
|
325
325
|
shape: element.shape,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { nonNullable } from '../../errors'
|
|
2
1
|
import type { ElementModel } from '../../model/ElementModel'
|
|
3
|
-
import type { AnyAux } from '../../
|
|
2
|
+
import type { AnyAux, aux } from '../../types'
|
|
3
|
+
import { nonNullable } from '../../utils'
|
|
4
4
|
import { isAncestor, isDescendantOf, sortParentsFirst } from '../../utils/fqn'
|
|
5
5
|
import { DefaultMap } from '../../utils/mnemonist'
|
|
6
6
|
|
|
7
|
-
export function treeFromElements<
|
|
7
|
+
export function treeFromElements<M extends AnyAux>(elements: Iterable<ElementModel<M>>) {
|
|
8
8
|
const sorted = sortParentsFirst([...elements]) as ReadonlyArray<ElementModel<M>>
|
|
9
9
|
const root = new Set(sorted)
|
|
10
10
|
const map = new Map(sorted.map(e => [e._literalId, e]))
|
|
@@ -32,7 +32,7 @@ export function treeFromElements<const M extends AnyAux>(elements: Iterable<Elem
|
|
|
32
32
|
|
|
33
33
|
return {
|
|
34
34
|
sorted,
|
|
35
|
-
byId: (id: M
|
|
35
|
+
byId: (id: aux.ElementId<M>): ElementModel<M> => nonNullable(map.get(id), `Element not found by id: ${id}`),
|
|
36
36
|
root: root as ReadonlySet<ElementModel<M>>,
|
|
37
37
|
parent: (el: ElementModel<M>): ElementModel<M> | null => parents.get(el),
|
|
38
38
|
children: (el: ElementModel<M>): ReadonlyArray<ElementModel<M>> => children.get(el),
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { AnyAux, ComputedNode } from '../../types'
|
|
2
|
+
import { nonNullable } from '../../utils'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the ancestors of given computed node, starting with the direct parent and ending with the root node.
|
|
6
6
|
*/
|
|
7
|
-
export function ancestorsOfNode(
|
|
8
|
-
node: ComputedNode
|
|
9
|
-
nodes: ReadonlyMap<
|
|
10
|
-
): ReadonlyArray<ComputedNode
|
|
11
|
-
const ancestors = [] as ComputedNode[]
|
|
7
|
+
export function ancestorsOfNode<A extends AnyAux>(
|
|
8
|
+
node: ComputedNode<A>,
|
|
9
|
+
nodes: ReadonlyMap<string, ComputedNode<A>>,
|
|
10
|
+
): ReadonlyArray<ComputedNode<A>> {
|
|
11
|
+
const ancestors = [] as ComputedNode<A>[]
|
|
12
12
|
let parentId = node.parent
|
|
13
13
|
while (parentId) {
|
|
14
14
|
const parentNode = nonNullable(nodes.get(parentId), `Parent node ${parentId} not found`)
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { isEmpty, isNullish, omitBy } from 'remeda'
|
|
2
2
|
import {
|
|
3
|
-
type
|
|
4
|
-
ComputedNode,
|
|
3
|
+
type AnyAux,
|
|
4
|
+
type ComputedNode,
|
|
5
|
+
type ElementViewRule,
|
|
6
|
+
type ModelExpression,
|
|
7
|
+
isGroupElementKind,
|
|
5
8
|
isViewRuleGroup,
|
|
6
9
|
isViewRulePredicate,
|
|
7
|
-
|
|
10
|
+
ModelFqnExpr,
|
|
8
11
|
} from '../../types'
|
|
9
12
|
import { elementExprToPredicate } from './elementExpressionToPredicate'
|
|
10
13
|
|
|
11
|
-
export function flattenGroupRules<
|
|
12
|
-
|
|
14
|
+
export function flattenGroupRules<A extends AnyAux, T extends ModelExpression<A>>(
|
|
15
|
+
guard: (expr: ModelExpression<A>) => expr is T,
|
|
16
|
+
) {
|
|
17
|
+
return (rule: ElementViewRule<A>): Array<T> => {
|
|
13
18
|
if (isViewRuleGroup(rule)) {
|
|
14
19
|
return rule.groupRules.flatMap(flattenGroupRules(guard))
|
|
15
20
|
}
|
|
@@ -21,8 +26,11 @@ export function flattenGroupRules<T extends ModelLayer.Expression>(guard: (expr:
|
|
|
21
26
|
}
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
export function applyCustomElementProperties
|
|
25
|
-
|
|
29
|
+
export function applyCustomElementProperties<A extends AnyAux>(
|
|
30
|
+
_rules: ElementViewRule<A>[],
|
|
31
|
+
_nodes: ComputedNode<A>[],
|
|
32
|
+
) {
|
|
33
|
+
const rules = _rules.flatMap(flattenGroupRules(ModelFqnExpr.isCustom))
|
|
26
34
|
if (rules.length === 0) {
|
|
27
35
|
return _nodes
|
|
28
36
|
}
|
|
@@ -44,7 +52,7 @@ export function applyCustomElementProperties(_rules: ViewRule[], _nodes: Compute
|
|
|
44
52
|
const notEmpty = !isEmpty(rest)
|
|
45
53
|
const satisfies = elementExprToPredicate(expr)
|
|
46
54
|
nodes.forEach((node, i) => {
|
|
47
|
-
if (
|
|
55
|
+
if (isGroupElementKind(node) || !satisfies(node)) {
|
|
48
56
|
return
|
|
49
57
|
}
|
|
50
58
|
if (notEmpty) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { isNullish, omitBy, pick } from 'remeda'
|
|
2
|
-
import { type ComputedEdge, type ComputedNode, type
|
|
2
|
+
import { type AnyAux, type ComputedEdge, type ComputedNode, type ElementViewRule, ModelRelationExpr } from '../../types'
|
|
3
3
|
import { flattenGroupRules } from './applyCustomElementProperties'
|
|
4
4
|
import { relationExpressionToPredicates } from './relationExpressionToPredicates'
|
|
5
5
|
|
|
6
|
-
export function applyCustomRelationProperties(
|
|
7
|
-
_rules:
|
|
8
|
-
nodes: ComputedNode[],
|
|
9
|
-
_edges: Iterable<ComputedEdge
|
|
10
|
-
): ComputedEdge[] {
|
|
11
|
-
const rules = _rules.flatMap(flattenGroupRules(
|
|
6
|
+
export function applyCustomRelationProperties<A extends AnyAux>(
|
|
7
|
+
_rules: ElementViewRule<A>[],
|
|
8
|
+
nodes: ComputedNode<A>[],
|
|
9
|
+
_edges: Iterable<ComputedEdge<A>>,
|
|
10
|
+
): ComputedEdge<A>[] {
|
|
11
|
+
const rules = _rules.flatMap(flattenGroupRules(ModelRelationExpr.isCustom))
|
|
12
12
|
const edges = Array.from(_edges)
|
|
13
13
|
if (rules.length === 0 || edges.length === 0) {
|
|
14
14
|
return edges
|
|
@@ -25,8 +25,18 @@ export function applyCustomRelationProperties(
|
|
|
25
25
|
const props = omitBy(customprops, isNullish)
|
|
26
26
|
const satisfies = relationExpressionToPredicates(expr)
|
|
27
27
|
edges.forEach((edge, i) => {
|
|
28
|
-
|
|
29
|
-
const
|
|
28
|
+
let source, target
|
|
29
|
+
for (const node of nodes) {
|
|
30
|
+
if (node.id === edge.source) {
|
|
31
|
+
source = node
|
|
32
|
+
}
|
|
33
|
+
if (node.id === edge.target) {
|
|
34
|
+
target = node
|
|
35
|
+
}
|
|
36
|
+
if (source && target) {
|
|
37
|
+
break
|
|
38
|
+
}
|
|
39
|
+
}
|
|
30
40
|
if (!source || !target) {
|
|
31
41
|
return
|
|
32
42
|
}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { anyPass, filter, forEach, isDefined, isNot, pipe } from 'remeda'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type AnyAux,
|
|
4
|
+
type AnyViewRuleStyle,
|
|
5
|
+
type ComputedNode,
|
|
6
|
+
type ElementViewRule,
|
|
7
|
+
isGroupElementKind,
|
|
8
|
+
isViewRuleStyle,
|
|
9
|
+
} from '../../types'
|
|
3
10
|
import { elementExprToPredicate } from './elementExpressionToPredicate'
|
|
4
11
|
|
|
5
12
|
type Predicate<T> = (x: T) => boolean
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
nodes: ComputedNode[],
|
|
13
|
-
) {
|
|
14
|
+
export function applyViewRuleStyle<A extends AnyAux>(
|
|
15
|
+
rule: Pick<AnyViewRuleStyle<A>, 'style' | 'notation'>,
|
|
16
|
+
predicates: Predicate<ComputedNode<A>>[],
|
|
17
|
+
nodes: ComputedNode<A>[],
|
|
18
|
+
): void {
|
|
14
19
|
pipe(
|
|
15
20
|
nodes,
|
|
16
|
-
filter(isNot(
|
|
21
|
+
filter(isNot(isGroupElementKind)),
|
|
17
22
|
filter(anyPass(predicates)),
|
|
18
23
|
forEach(n => {
|
|
19
24
|
n.shape = rule.style.shape ?? n.shape
|
|
@@ -53,7 +58,10 @@ export function applyViewRuleStyle<Rule extends CommonViewRuleStyle>(
|
|
|
53
58
|
)
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
export function applyViewRuleStyles
|
|
61
|
+
export function applyViewRuleStyles<A extends AnyAux, N extends ComputedNode<A>[]>(
|
|
62
|
+
rules: ElementViewRule<A>[],
|
|
63
|
+
nodes: N,
|
|
64
|
+
): N {
|
|
57
65
|
for (const rule of rules) {
|
|
58
66
|
if (!isViewRuleStyle(rule) || rule.targets.length === 0) {
|
|
59
67
|
continue
|