@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
package/src/model/guards.ts
CHANGED
|
@@ -1,25 +1,77 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { Any, AnyAux } from '../types'
|
|
2
|
+
import {
|
|
3
|
+
type DeploymentElementModel,
|
|
4
|
+
DeployedInstanceModel,
|
|
5
|
+
DeploymentNodeModel,
|
|
6
|
+
DeploymentRelationModel,
|
|
4
7
|
NestedElementOfDeployedInstanceModel,
|
|
5
8
|
} from './DeploymentElementModel'
|
|
6
|
-
import {
|
|
7
|
-
import type
|
|
9
|
+
import { ElementModel } from './ElementModel'
|
|
10
|
+
import { type AnyRelationshipModel, RelationshipModel } from './RelationModel'
|
|
11
|
+
import { EdgeModel } from './view/EdgeModel'
|
|
12
|
+
import { LikeC4ViewModel } from './view/LikeC4ViewModel'
|
|
13
|
+
import { NodeModel } from './view/NodeModel'
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
type AnyModel<A extends AnyAux> =
|
|
16
|
+
| DeploymentNodeModel<A>
|
|
17
|
+
| DeployedInstanceModel<A>
|
|
18
|
+
| DeploymentRelationModel<A>
|
|
19
|
+
| AnyRelationshipModel<A>
|
|
20
|
+
| NestedElementOfDeployedInstanceModel<A>
|
|
21
|
+
| ElementModel<A>
|
|
22
|
+
| RelationshipModel<A>
|
|
23
|
+
| LikeC4ViewModel<A>
|
|
24
|
+
| NodeModel<A>
|
|
25
|
+
| EdgeModel<A>
|
|
26
|
+
|
|
27
|
+
export function isDeploymentNodeModel<M extends AnyAux>(
|
|
28
|
+
model: AnyModel<M>,
|
|
29
|
+
): model is DeploymentNodeModel<M> {
|
|
30
|
+
return model instanceof DeploymentNodeModel
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isDeployedInstanceModel<M extends AnyAux>(
|
|
34
|
+
model: AnyModel<M>,
|
|
35
|
+
): model is DeployedInstanceModel<M> {
|
|
36
|
+
return model instanceof DeployedInstanceModel
|
|
11
37
|
}
|
|
12
38
|
|
|
13
|
-
export function
|
|
14
|
-
return model
|
|
39
|
+
export function isDeploymentElementModel<M extends AnyAux>(model: AnyModel<M>): model is DeploymentElementModel<M> {
|
|
40
|
+
return isDeploymentNodeModel(model) || isDeployedInstanceModel(model)
|
|
15
41
|
}
|
|
16
42
|
|
|
17
|
-
export function isNestedElementOfDeployedInstanceModel<M extends AnyAux
|
|
18
|
-
model:
|
|
43
|
+
export function isNestedElementOfDeployedInstanceModel<M extends AnyAux>(
|
|
44
|
+
model: AnyModel<M>,
|
|
19
45
|
): model is NestedElementOfDeployedInstanceModel<M> {
|
|
20
|
-
return
|
|
46
|
+
return model instanceof NestedElementOfDeployedInstanceModel
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function isDeploymentRelationModel<M extends AnyAux>(
|
|
50
|
+
x: AnyModel<M>,
|
|
51
|
+
): x is DeploymentRelationModel<M> {
|
|
52
|
+
return x instanceof DeploymentRelationModel
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isRelationModel<M extends AnyAux>(x: AnyModel<M>): x is RelationshipModel<M> {
|
|
56
|
+
return x instanceof RelationshipModel
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
isRelationModel as isModelRelation,
|
|
60
|
+
isRelationModel as isRelationshipModel,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function isElementModel<M extends Any>(element: AnyModel<M>): element is ElementModel<M> {
|
|
64
|
+
return element instanceof ElementModel
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function isLikeC4ViewModel<M extends Any>(view: AnyModel<M>): view is LikeC4ViewModel<M> {
|
|
68
|
+
return view instanceof LikeC4ViewModel
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function isNodeModel<M extends Any>(node: AnyModel<M>): node is NodeModel<M> {
|
|
72
|
+
return node instanceof NodeModel
|
|
21
73
|
}
|
|
22
74
|
|
|
23
|
-
export function
|
|
24
|
-
return
|
|
75
|
+
export function isEdgeModel<M extends Any>(edge: AnyModel<M>): edge is EdgeModel<M> {
|
|
76
|
+
return edge instanceof EdgeModel
|
|
25
77
|
}
|
package/src/model/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ElementModel } from './ElementModel'
|
|
2
|
-
export { LikeC4Model } from './LikeC4Model'
|
|
2
|
+
export { type AnyLikeC4Model, LikeC4Model } from './LikeC4Model'
|
|
3
3
|
export { RelationshipModel } from './RelationModel'
|
|
4
4
|
|
|
5
5
|
export {
|
|
@@ -28,7 +28,9 @@ export {
|
|
|
28
28
|
DeployedInstanceModel,
|
|
29
29
|
type DeploymentElementModel,
|
|
30
30
|
DeploymentNodeModel,
|
|
31
|
+
type DeploymentRelationEndpoint,
|
|
31
32
|
DeploymentRelationModel,
|
|
33
|
+
RelationshipsAccum,
|
|
32
34
|
} from './DeploymentElementModel'
|
|
33
35
|
export { LikeC4DeploymentModel } from './DeploymentModel'
|
|
34
36
|
|
|
@@ -37,11 +39,22 @@ export { LikeC4ViewModel } from './view/LikeC4ViewModel'
|
|
|
37
39
|
export { NodeModel } from './view/NodeModel'
|
|
38
40
|
|
|
39
41
|
export type {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
DeploymentOrFqn,
|
|
43
|
+
EdgeOrId,
|
|
44
|
+
ElementOrFqn,
|
|
45
|
+
IncomingFilter,
|
|
46
|
+
NodeOrId,
|
|
47
|
+
OutgoingFilter,
|
|
42
48
|
} from './types'
|
|
43
49
|
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
export * from './guards'
|
|
51
|
+
|
|
52
|
+
export type {
|
|
53
|
+
Any,
|
|
54
|
+
AnyAux,
|
|
55
|
+
Aux,
|
|
56
|
+
aux,
|
|
57
|
+
AuxFromDump,
|
|
58
|
+
AuxFromLikeC4ModelData,
|
|
59
|
+
SpecAux,
|
|
60
|
+
} from '../types'
|
package/src/model/types.ts
CHANGED
|
@@ -1,119 +1,63 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Tagged } from 'type-fest'
|
|
2
2
|
import type {
|
|
3
|
+
AnyAux,
|
|
4
|
+
ComputedLikeC4ModelData,
|
|
3
5
|
ComputedView,
|
|
4
6
|
DiagramView,
|
|
5
|
-
EdgeId,
|
|
6
|
-
Fqn,
|
|
7
|
-
GenericLikeC4ModelData,
|
|
8
|
-
KeysOf,
|
|
9
7
|
LayoutedLikeC4ModelData,
|
|
10
|
-
LikeC4ModelDump,
|
|
11
|
-
NodeId,
|
|
12
8
|
ParsedLikeC4ModelData,
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
scalar,
|
|
10
|
+
ViewType,
|
|
11
|
+
ViewWithType,
|
|
15
12
|
} from '../types'
|
|
16
|
-
import
|
|
13
|
+
import type * as aux from '../types/aux'
|
|
14
|
+
import type { LikeC4ViewModel } from './view/LikeC4ViewModel'
|
|
17
15
|
|
|
18
16
|
export type IncomingFilter = 'all' | 'direct' | 'to-descendants'
|
|
19
17
|
export type OutgoingFilter = 'all' | 'direct' | 'from-descendants'
|
|
20
18
|
|
|
19
|
+
type AnyScalar<V extends string> =
|
|
20
|
+
| Tagged<V, 'Fqn'>
|
|
21
|
+
| Tagged<V, 'DeploymentFqn'>
|
|
22
|
+
| Tagged<V, 'ViewId'>
|
|
23
|
+
| Tagged<V, 'NodeId'>
|
|
24
|
+
| Tagged<V, 'EdgeId'>
|
|
25
|
+
| Tagged<V, 'RelationId'>
|
|
26
|
+
|
|
21
27
|
/**
|
|
22
28
|
* Utility function to extract `id` from the given element.
|
|
23
29
|
*/
|
|
24
|
-
export function getId<Id extends string
|
|
25
|
-
return
|
|
30
|
+
export function getId<Id extends string, Scalar extends AnyScalar<Id>>(element: Id | { id: Scalar }): Scalar {
|
|
31
|
+
return typeof element === 'string' ? element as unknown as Scalar : element.id
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
type
|
|
29
|
-
|
|
30
|
-
type WithViews<Id extends string, ViewType> = { views: Record<Id, ViewType> }
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Auxilary type to keep track
|
|
34
|
-
*/
|
|
35
|
-
export interface Aux<
|
|
36
|
-
Element extends string,
|
|
37
|
-
Deployment extends string,
|
|
38
|
-
View extends string,
|
|
39
|
-
ViewType,
|
|
40
|
-
> {
|
|
41
|
-
Element: Element
|
|
42
|
-
Deployment: Deployment
|
|
43
|
-
View: View
|
|
44
|
-
|
|
45
|
-
// Wrapped Element
|
|
46
|
-
// If Fqn is just a string, then we use generic Fqn to have better hints in the editor
|
|
47
|
-
Fqn: IsStringLiteral<Element> extends true ? Fqn<Element> : Fqn
|
|
48
|
-
ElementOrFqn: Element | WithId<this['Fqn']>
|
|
34
|
+
export type ElementOrFqn<A extends AnyAux> = aux.ElementId<A> | { id: aux.Fqn<A> }
|
|
49
35
|
|
|
50
|
-
|
|
51
|
-
DeploymentFqn: IsStringLiteral<Deployment> extends true ? Fqn<Deployment> : Fqn
|
|
52
|
-
DeploymentOrFqn: Deployment | WithId<this['DeploymentFqn']>
|
|
36
|
+
export type DeploymentOrFqn<A extends AnyAux> = aux.DeploymentId<A> | { id: aux.DeploymentFqn<A> }
|
|
53
37
|
|
|
54
|
-
|
|
55
|
-
ViewId: IsStringLiteral<View> extends true ? ViewId<View> : ViewId
|
|
38
|
+
export type ViewOrId<A extends AnyAux> = aux.ViewId<A> | { id: aux.StrictViewId<A> }
|
|
56
39
|
|
|
57
|
-
|
|
40
|
+
export type NodeOrId = string | { id: scalar.NodeId }
|
|
41
|
+
export type EdgeOrId = string | { id: scalar.EdgeId }
|
|
42
|
+
export type RelationOrId = string | { id: scalar.RelationId }
|
|
58
43
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
export type $View<A extends AnyAux> = {
|
|
45
|
+
parsed: never
|
|
46
|
+
computed: ComputedView<A>
|
|
47
|
+
layouted: DiagramView<A>
|
|
48
|
+
}[aux.Stage<A>]
|
|
64
49
|
|
|
65
|
-
|
|
66
|
-
EdgeOrId: LiteralUnion<this['EdgeIdLiteral'], string> | WithId<this['EdgeId']>
|
|
50
|
+
export type $ViewWithType<A extends AnyAux, V extends ViewType> = ViewWithType<$View<A>, V>
|
|
67
51
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
string,
|
|
74
|
-
string,
|
|
75
|
-
any
|
|
76
|
-
>
|
|
77
|
-
|
|
78
|
-
export namespace Strict {
|
|
79
|
-
export type Fqn<A extends AnyAux> = A['Element']
|
|
80
|
-
export type Deployment<A extends AnyAux> = A['Deployment']
|
|
81
|
-
export type ViewId<A extends AnyAux> = A['View']
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export namespace Aux {
|
|
85
|
-
export type FromParsed<M> = M extends ParsedLikeC4ModelData ? Aux<
|
|
86
|
-
KeysOf<M['elements']>,
|
|
87
|
-
KeysOf<M['deployments']['elements']>,
|
|
88
|
-
KeysOf<M['views']>,
|
|
89
|
-
ComputedView<ViewId<KeysOf<M['views']>>, string>
|
|
90
|
-
>
|
|
91
|
-
: never
|
|
92
|
-
|
|
93
|
-
export type FromModel<M> = M extends GenericLikeC4ModelData ? Aux<
|
|
94
|
-
KeysOf<M['elements']>,
|
|
95
|
-
KeysOf<M['deployments']['elements']>,
|
|
96
|
-
KeysOf<M['views']>,
|
|
97
|
-
M extends LayoutedLikeC4ModelData ? DiagramView<ViewId<KeysOf<M['views']>>, string>
|
|
98
|
-
: ComputedView<ViewId<KeysOf<M['views']>>, string>
|
|
99
|
-
>
|
|
100
|
-
: never
|
|
101
|
-
|
|
102
|
-
export type FromDump<M> = M extends LikeC4ModelDump ? Aux<
|
|
103
|
-
KeysOf<M['elements']>,
|
|
104
|
-
KeysOf<M['deployments']['elements']>,
|
|
105
|
-
KeysOf<M['views']>,
|
|
106
|
-
DiagramView<ViewId<KeysOf<M['views']>>, string>
|
|
107
|
-
>
|
|
108
|
-
: never
|
|
109
|
-
}
|
|
52
|
+
export type $ViewModel<A extends AnyAux> = {
|
|
53
|
+
parsed: never
|
|
54
|
+
computed: LikeC4ViewModel<A>
|
|
55
|
+
layouted: LikeC4ViewModel<A>
|
|
56
|
+
}[aux.Stage<A>]
|
|
110
57
|
|
|
111
|
-
// export type
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// > ? Aux<Fqn, Deployment, ViewId, M>
|
|
118
|
-
// : Aux<KeysOf<>, string, string, ComputedLikeC4Model | LayoutedLikeC4Model>
|
|
119
|
-
// >
|
|
58
|
+
// export type $ModelData<A> = A extends infer T extends Any ? {
|
|
59
|
+
export type $ModelData<A extends AnyAux> = {
|
|
60
|
+
parsed: ParsedLikeC4ModelData<A>
|
|
61
|
+
computed: ComputedLikeC4ModelData<A>
|
|
62
|
+
layouted: LayoutedLikeC4ModelData<A>
|
|
63
|
+
}[aux.Stage<A>]
|
|
@@ -1,89 +1,90 @@
|
|
|
1
|
-
import { isNonNullish } from 'remeda'
|
|
2
|
-
import type { LiteralUnion } from 'type-fest'
|
|
3
1
|
import {
|
|
2
|
+
type Any,
|
|
3
|
+
type aux,
|
|
4
4
|
type Color,
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type DiagramView,
|
|
5
|
+
type ComputedEdge,
|
|
6
|
+
type DiagramEdge,
|
|
8
7
|
type IteratorLike,
|
|
9
|
-
type RelationId as C4RelationID,
|
|
10
8
|
type RelationshipLineType,
|
|
9
|
+
type scalar,
|
|
11
10
|
type StepEdgeId,
|
|
12
|
-
type Tag as C4Tag,
|
|
13
11
|
extractStep,
|
|
14
12
|
isStepEdgeId,
|
|
15
13
|
} from '../../types'
|
|
16
14
|
import type { DeploymentRelationModel } from '../DeploymentElementModel'
|
|
17
|
-
import type { LikeC4Model } from '../LikeC4Model'
|
|
18
15
|
import type { RelationshipModel } from '../RelationModel'
|
|
19
|
-
import type {
|
|
16
|
+
import type { $View } from '../types'
|
|
20
17
|
import type { LikeC4ViewModel } from './LikeC4ViewModel'
|
|
21
18
|
import type { NodeModel } from './NodeModel'
|
|
22
19
|
|
|
23
|
-
export type EdgesIterator<
|
|
20
|
+
export type EdgesIterator<A extends Any, V extends $View<A>> = IteratorLike<EdgeModel<A, V>>
|
|
24
21
|
|
|
25
|
-
export class EdgeModel<
|
|
22
|
+
export class EdgeModel<A extends Any = Any, View extends $View<A> = $View<A>> {
|
|
23
|
+
#edge: ComputedEdge<A> | DiagramEdge<A>
|
|
26
24
|
constructor(
|
|
27
|
-
public readonly view: LikeC4ViewModel<
|
|
28
|
-
public readonly $edge:
|
|
29
|
-
public readonly source: NodeModel<
|
|
30
|
-
public readonly target: NodeModel<
|
|
25
|
+
public readonly view: LikeC4ViewModel<A, View>,
|
|
26
|
+
public readonly $edge: View['edges'][number],
|
|
27
|
+
public readonly source: NodeModel<A, View>,
|
|
28
|
+
public readonly target: NodeModel<A, View>,
|
|
31
29
|
) {
|
|
30
|
+
this.#edge = $edge
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
get id():
|
|
35
|
-
return this
|
|
33
|
+
get id(): scalar.EdgeId {
|
|
34
|
+
return this.#edge.id
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
get parent(): NodeModel<
|
|
39
|
-
return this
|
|
37
|
+
get parent(): NodeModel<A, View> | null {
|
|
38
|
+
return this.#edge.parent ? this.view.node(this.#edge.parent) : null
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
get label(): string | null {
|
|
43
|
-
return this
|
|
42
|
+
return this.#edge.label
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
get description(): string | null {
|
|
47
|
-
return this
|
|
46
|
+
return this.#edge.description ?? null
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
get technology(): string | null {
|
|
51
|
-
return this
|
|
50
|
+
return this.#edge.technology ?? null
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
public hasParent(): this is EdgeModel.WithParent<
|
|
55
|
-
return this
|
|
53
|
+
public hasParent(): this is EdgeModel.WithParent<A, View> {
|
|
54
|
+
return this.#edge.parent !== null
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
get tags():
|
|
59
|
-
return this
|
|
57
|
+
get tags(): aux.Tags<A> {
|
|
58
|
+
return this.#edge.tags ?? []
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
get stepNumber(): number | null {
|
|
63
62
|
return this.isStep() ? extractStep(this.id) : null
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
get navigateTo(): LikeC4ViewModel<
|
|
67
|
-
return this
|
|
65
|
+
get navigateTo(): LikeC4ViewModel<A> | null {
|
|
66
|
+
return this.#edge.navigateTo ? this.view.$model.view(this.#edge.navigateTo) : null
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
get color(): Color {
|
|
71
|
-
return this
|
|
70
|
+
return this.#edge.color ?? 'gray'
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
get line(): RelationshipLineType {
|
|
75
|
-
return this
|
|
74
|
+
return this.#edge.line ?? 'dashed'
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
public isStep(): this is EdgeModel.StepEdge<
|
|
77
|
+
public isStep(): this is EdgeModel.StepEdge<A, View> {
|
|
79
78
|
return isStepEdgeId(this.id)
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
public relationships(type: 'model'): IteratorLike<RelationshipModel<
|
|
83
|
-
public relationships(type: 'deployment'): IteratorLike<DeploymentRelationModel<
|
|
84
|
-
public relationships(type?: 'model' | 'deployment'): IteratorLike<
|
|
85
|
-
public *relationships(
|
|
86
|
-
|
|
81
|
+
public relationships(type: 'model'): IteratorLike<RelationshipModel<A>>
|
|
82
|
+
public relationships(type: 'deployment'): IteratorLike<DeploymentRelationModel<A>>
|
|
83
|
+
public relationships(type?: 'model' | 'deployment'): IteratorLike<RelationshipModel<A> | DeploymentRelationModel<A>>
|
|
84
|
+
public *relationships(
|
|
85
|
+
type: 'model' | 'deployment' | undefined,
|
|
86
|
+
): IteratorLike<RelationshipModel<A> | DeploymentRelationModel<A>> {
|
|
87
|
+
for (const id of this.#edge.relations) {
|
|
87
88
|
// if type is provided, then we need to filter relationships
|
|
88
89
|
if (type) {
|
|
89
90
|
const rel = this.view.$model.findRelationship(id, type)
|
|
@@ -97,17 +98,22 @@ export class EdgeModel<M extends AnyAux, V extends ComputedView | DiagramView =
|
|
|
97
98
|
return
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
public includesRelation(rel:
|
|
101
|
-
|
|
101
|
+
public includesRelation(rel: aux.RelationId | { id: aux.RelationId }): boolean {
|
|
102
|
+
const id = typeof rel === 'string' ? rel : rel.id
|
|
103
|
+
return this.#edge.relations.includes(id)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public isTagged(tag: aux.LooseTag<A>): boolean {
|
|
107
|
+
return this.tags.includes(tag as aux.Tag<A>)
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
namespace EdgeModel {
|
|
106
|
-
export interface StepEdge<
|
|
112
|
+
export interface StepEdge<A extends Any, V extends $View<A>> extends EdgeModel<A, V> {
|
|
107
113
|
id: StepEdgeId
|
|
108
114
|
stepNumber: number
|
|
109
115
|
}
|
|
110
|
-
export interface WithParent<
|
|
111
|
-
parent: NodeModel<
|
|
116
|
+
export interface WithParent<A extends Any, V extends $View<A>> extends EdgeModel<A, V> {
|
|
117
|
+
parent: NodeModel<A, V>
|
|
112
118
|
}
|
|
113
119
|
}
|