@likec4/core 1.31.0 → 1.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/README.md +407 -5
  2. package/dist/builder/index.d.mts +221 -42
  3. package/dist/builder/index.mjs +118 -65
  4. package/dist/compute-view/index.d.mts +23 -7
  5. package/dist/compute-view/index.mjs +11 -6
  6. package/dist/compute-view/relationships-view/index.d.mts +9 -7
  7. package/dist/compute-view/relationships-view/index.mjs +3 -2
  8. package/dist/index.d.mts +10 -14
  9. package/dist/index.mjs +9 -6
  10. package/dist/model/index.d.mts +173 -19
  11. package/dist/model/index.mjs +6 -1
  12. package/dist/shared/core.BaYE_r29.d.mts +258 -0
  13. package/dist/shared/core.Bk7wEZFG.mjs +276 -0
  14. package/dist/shared/core.BrCnZFTn.mjs +32 -0
  15. package/dist/shared/core.BuO4ncfY.d.mts +146 -0
  16. package/dist/shared/{core.Bq753SYD.mjs → core.CBpKAlhj.mjs} +2012 -4422
  17. package/dist/shared/core.CUYDgv2-.mjs +214 -0
  18. package/dist/shared/{core.Cu-UdkSl.mjs → core.CpXlRyE5.mjs} +7 -494
  19. package/dist/shared/{core.C-YXI-43.mjs → core.Cy9smucx.mjs} +3 -1
  20. package/dist/shared/core.CywrQs86.d.mts +31 -0
  21. package/dist/shared/core.DXzRBkuI.d.mts +1264 -0
  22. package/dist/shared/core.DoK86JEe.mjs +518 -0
  23. package/dist/shared/{core.D2830qgg.d.mts → core.Pf5I9o0e.d.mts} +1 -1
  24. package/dist/shared/core.cbA9VZ02.mjs +2681 -0
  25. package/dist/shared/{core.CQXU9DF7.mjs → core.rmvsy0n3.mjs} +23 -32
  26. package/dist/shared/core.znRaUX_A.d.mts +920 -0
  27. package/dist/types/aux.d.mts +3 -0
  28. package/dist/types/aux.mjs +1 -0
  29. package/dist/types/index.d.mts +7 -45
  30. package/dist/types/index.mjs +130 -3
  31. package/dist/utils/index.d.mts +221 -53
  32. package/dist/utils/index.mjs +14 -10
  33. package/package.json +16 -8
  34. package/src/builder/Builder.deploymentModel.ts +82 -18
  35. package/src/builder/Builder.element.ts +40 -20
  36. package/src/builder/Builder.model.ts +66 -17
  37. package/src/builder/Builder.ts +168 -76
  38. package/src/builder/Builder.view-common.ts +35 -17
  39. package/src/builder/Builder.view-deployment.ts +25 -25
  40. package/src/builder/Builder.view-element.ts +13 -12
  41. package/src/builder/Builder.views.ts +12 -7
  42. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +62 -34
  43. package/src/builder/__snapshots__/Builder-style2.compute-model.json5 +319 -0
  44. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +45 -24
  45. package/src/builder/_types.ts +34 -27
  46. package/src/compute-view/compute-view.ts +31 -34
  47. package/src/compute-view/deployment-view/__test__/TestHelper.ts +27 -14
  48. package/src/compute-view/deployment-view/__test__/fixture.ts +15 -13
  49. package/src/compute-view/deployment-view/_types.ts +10 -10
  50. package/src/compute-view/deployment-view/clean-connections.ts +5 -7
  51. package/src/compute-view/deployment-view/compute.ts +16 -13
  52. package/src/compute-view/deployment-view/memory/memory.ts +5 -6
  53. package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +4 -5
  54. package/src/compute-view/deployment-view/predicates/relation-direct.ts +25 -50
  55. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +5 -7
  56. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +7 -11
  57. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +7 -10
  58. package/src/compute-view/deployment-view/predicates/utils.ts +37 -31
  59. package/src/compute-view/deployment-view/predicates/wildcard.ts +3 -2
  60. package/src/compute-view/deployment-view/stages/stage-final.ts +2 -2
  61. package/src/compute-view/deployment-view/stages/stage-include.ts +1 -1
  62. package/src/compute-view/deployment-view/utils.ts +79 -72
  63. package/src/compute-view/dynamic-view/__test__/fixture.ts +20 -11
  64. package/src/compute-view/dynamic-view/compute.ts +60 -53
  65. package/src/compute-view/element-view/__test__/TestHelper.ts +53 -29
  66. package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +26 -26
  67. package/src/compute-view/element-view/__test__/fixture.ts +134 -83
  68. package/src/compute-view/element-view/_types.ts +14 -19
  69. package/src/compute-view/element-view/clean-connections.ts +12 -8
  70. package/src/compute-view/element-view/compute.ts +61 -51
  71. package/src/compute-view/element-view/memory/NodeGroup.ts +8 -9
  72. package/src/compute-view/element-view/memory/memory.ts +22 -22
  73. package/src/compute-view/element-view/memory/stage-include.ts +5 -3
  74. package/src/compute-view/element-view/predicates/_utils.ts +18 -14
  75. package/src/compute-view/element-view/predicates/element-expand.ts +4 -5
  76. package/src/compute-view/element-view/predicates/element-kind-tag.ts +3 -4
  77. package/src/compute-view/element-view/predicates/element-ref.ts +3 -4
  78. package/src/compute-view/element-view/predicates/relation-direct.ts +16 -12
  79. package/src/compute-view/element-view/predicates/relation-in-out.ts +7 -8
  80. package/src/compute-view/element-view/predicates/relation-in.ts +19 -26
  81. package/src/compute-view/element-view/predicates/relation-out.ts +20 -21
  82. package/src/compute-view/element-view/predicates/wildcard.ts +3 -3
  83. package/src/compute-view/element-view/utils.ts +25 -23
  84. package/src/compute-view/index.ts +1 -1
  85. package/src/compute-view/memory/AbstractStageExclude.ts +3 -4
  86. package/src/compute-view/memory/AbstractStageInclude.ts +1 -1
  87. package/src/compute-view/memory/_types.ts +3 -2
  88. package/src/compute-view/relationships-view/_types.ts +3 -4
  89. package/src/compute-view/relationships-view/compute.ts +8 -11
  90. package/src/compute-view/relationships-view/layout.ts +6 -6
  91. package/src/compute-view/relationships-view/utils.ts +4 -4
  92. package/src/compute-view/utils/ancestorsOfNode.ts +7 -7
  93. package/src/compute-view/utils/applyCustomElementProperties.ts +16 -8
  94. package/src/compute-view/utils/applyCustomRelationProperties.ts +19 -9
  95. package/src/compute-view/utils/applyViewRuleStyles.ts +18 -10
  96. package/src/compute-view/utils/buildComputedNodes.ts +40 -40
  97. package/src/compute-view/utils/buildElementNotations.ts +14 -14
  98. package/src/compute-view/utils/elementExpressionToPredicate.ts +14 -15
  99. package/src/compute-view/utils/link-nodes-with-edges.ts +6 -4
  100. package/src/compute-view/utils/merge-props-from-relationships.ts +52 -20
  101. package/src/compute-view/utils/relationExpressionToPredicates.ts +19 -19
  102. package/src/compute-view/utils/resolve-extended-views.ts +8 -7
  103. package/src/compute-view/utils/resolve-global-rules.ts +31 -26
  104. package/src/compute-view/utils/topological-sort.ts +14 -14
  105. package/src/compute-view/utils/view-hash.ts +2 -2
  106. package/src/compute-view/utils/with-readable-edges.ts +9 -5
  107. package/src/index.ts +0 -32
  108. package/src/model/DeploymentElementModel.ts +171 -144
  109. package/src/model/DeploymentModel.ts +88 -65
  110. package/src/model/ElementModel.ts +85 -74
  111. package/src/model/LikeC4Model.ts +430 -241
  112. package/src/model/RelationModel.ts +63 -29
  113. package/src/model/__test__/fixture.ts +50 -36
  114. package/src/model/connection/Connection.ts +2 -2
  115. package/src/model/connection/deployment/DeploymentConnectionModel.ts +21 -24
  116. package/src/model/connection/deployment/find.ts +1 -1
  117. package/src/model/connection/model/ConnectionModel.ts +21 -20
  118. package/src/model/connection/model/find.ts +7 -7
  119. package/src/model/connection/ops.ts +6 -6
  120. package/src/model/guards.ts +66 -14
  121. package/src/model/index.ts +20 -7
  122. package/src/model/types.ts +41 -97
  123. package/src/model/view/EdgeModel.ts +47 -41
  124. package/src/model/view/LikeC4ViewModel.ts +130 -80
  125. package/src/model/view/NodeModel.ts +102 -96
  126. package/src/theme/element.ts +1 -1
  127. package/src/theme/index.ts +9 -9
  128. package/src/theme/relationships.ts +1 -1
  129. package/src/types/_common.ts +21 -15
  130. package/src/types/aux.ts +285 -0
  131. package/src/types/const.ts +34 -0
  132. package/src/types/expression-model.ts +292 -0
  133. package/src/types/expression.ts +311 -0
  134. package/src/types/fqnRef.ts +88 -0
  135. package/src/types/geometry.ts +131 -0
  136. package/src/types/global.ts +10 -8
  137. package/src/types/index.ts +39 -201
  138. package/src/types/model-data.ts +52 -84
  139. package/src/types/model-deployment.ts +87 -0
  140. package/src/types/model-dump.ts +72 -0
  141. package/src/types/model-logical.ts +111 -0
  142. package/src/types/model-spec.ts +81 -0
  143. package/src/types/operators.ts +51 -52
  144. package/src/types/scalar.ts +114 -0
  145. package/src/types/{theme.ts → styles.ts} +55 -15
  146. package/src/types/view-changes.ts +4 -5
  147. package/src/types/view-common.ts +157 -0
  148. package/src/types/view-computed.ts +113 -0
  149. package/src/types/view-layouted.ts +82 -0
  150. package/src/types/view-parsed.deployment.ts +40 -0
  151. package/src/types/view-parsed.dynamic.ts +78 -0
  152. package/src/types/view-parsed.element.ts +65 -0
  153. package/src/types/view.ts +122 -542
  154. package/src/utils/compare-natural.ts +43 -1
  155. package/src/utils/getOrCreate.ts +0 -34
  156. package/src/utils/index.ts +7 -12
  157. package/src/utils/iterable/filter.ts +1 -1
  158. package/src/utils/iterable/find.ts +3 -1
  159. package/src/utils/iterable/head.ts +22 -0
  160. package/src/utils/iterable/index.ts +1 -0
  161. package/src/utils/iterable/map.ts +1 -1
  162. package/src/utils/iterable/reduce.ts +1 -1
  163. package/src/utils/iterable/some.ts +1 -1
  164. package/src/utils/memoize-prop.ts +30 -0
  165. package/src/utils/object-hash.ts +1 -1
  166. package/src/utils/relations.ts +14 -11
  167. package/src/utils/string-hash.ts +1 -1
  168. package/dist/shared/core.CQDU11hR.d.mts +0 -753
  169. package/dist/shared/core.DJvmfnEi.d.mts +0 -1153
  170. package/dist/shared/core.DgfwjBtu.mjs +0 -495
  171. package/dist/shared/core.Dx7siloV.d.mts +0 -146
  172. package/dist/shared/core.SjLhMA7a.d.mts +0 -62
  173. package/src/builder/__snapshots__/Builder.spec.ts.snap +0 -374
  174. package/src/compute-view/element-view/predicates.ts +0 -520
  175. package/src/compute-view/utils/uniqueTags.ts +0 -21
  176. package/src/types/deployments.ts +0 -170
  177. package/src/types/element.ts +0 -109
  178. package/src/types/expression-v2-model.ts +0 -314
  179. package/src/types/expression-v2.ts +0 -392
  180. package/src/types/overview-graph.ts +0 -43
  181. package/src/types/relation.ts +0 -61
  182. package/src/types/scalars.ts +0 -39
  183. package/src/types/view-notation.ts +0 -9
  184. package/src/utils/graphlib.ts +0 -10
  185. /package/src/{errors/index.ts → utils/invariant.ts} +0 -0
package/src/types/view.ts CHANGED
@@ -1,560 +1,140 @@
1
- import { isArray, isNullish } from 'remeda'
2
- import type { Tagged } from 'type-fest'
3
- import type { NonEmptyArray, Point, XYPoint } from './_common'
4
- import {
5
- type BorderStyle,
6
- type ElementShape,
7
- type ElementStyle,
8
- type Link,
9
- ElementKind,
10
- } from './element'
11
- import type { ExpressionV2, FqnExpr } from './expression-v2'
12
- import type { ModelLayer } from './expression-v2-model'
13
- import type { GlobalPredicateId, GlobalStyleID } from './global'
14
- import type { RelationId, RelationshipArrowType, RelationshipKind, RelationshipLineType } from './relation'
15
- import type { Fqn, IconUrl, Tag } from './scalars'
16
- import type { Color, ShapeSize, SpacingSize, TextSize, ThemeColorValues } from './theme'
17
- import type { ElementNotation } from './view-notation'
18
-
19
- export type ViewId<Id extends string = string> = Tagged<Id, 'ViewID'>
20
-
21
- export type ViewRulePredicate =
22
- | {
23
- include: ModelLayer.Expression[]
24
- exclude?: never
25
- }
26
- | {
27
- include?: never
28
- exclude: ModelLayer.Expression[]
29
- }
30
-
31
- export function isViewRulePredicate(rule: DeploymentViewRule): rule is DeploymentViewRulePredicate
32
- export function isViewRulePredicate(rule: DynamicViewRule): rule is DynamicViewIncludeRule
33
- export function isViewRulePredicate(rule: ViewRule): rule is ViewRulePredicate
34
- export function isViewRulePredicate(rule: object) {
35
- return (
36
- ('include' in rule && Array.isArray(rule.include))
37
- || ('exclude' in rule && Array.isArray(rule.exclude))
38
- )
39
- }
40
-
41
- export interface ViewRuleGlobalPredicateRef {
42
- predicateId: GlobalPredicateId
43
- }
44
- export function isViewRuleGlobalPredicateRef(rule: ViewRule): rule is ViewRuleGlobalPredicateRef {
45
- return 'predicateId' in rule
46
- }
47
-
48
- export interface ViewRuleStyle {
49
- targets: ModelLayer.FqnExpr[]
50
- notation?: string
51
- style: ElementStyle & {
52
- color?: Color
53
- shape?: ElementShape
54
- icon?: IconUrl
55
- }
56
- }
57
- export function isViewRuleStyle(rule: DeploymentViewRule): rule is DeploymentViewRuleStyle
58
- export function isViewRuleStyle(rule: ViewRule): rule is ViewRuleStyle
59
- export function isViewRuleStyle(rule: object) {
60
- return 'style' in rule && 'targets' in rule && Array.isArray(rule.targets)
61
- }
62
-
63
- export interface ViewRuleGlobalStyle {
64
- styleId: GlobalStyleID
65
- }
66
- export function isViewRuleGlobalStyle(rule: ViewRule): rule is ViewRuleGlobalStyle {
67
- return 'styleId' in rule
68
- }
69
-
70
- export type ViewRuleStyleOrGlobalRef = ViewRuleStyle | ViewRuleGlobalStyle
71
-
72
- export type AutoLayoutDirection = 'TB' | 'BT' | 'LR' | 'RL'
73
- export function isAutoLayoutDirection(autoLayout: unknown): autoLayout is AutoLayoutDirection {
74
- return autoLayout === 'TB' || autoLayout === 'BT' || autoLayout === 'LR' || autoLayout === 'RL'
75
- }
76
-
77
- export interface ViewRuleAutoLayout {
78
- direction: AutoLayoutDirection
79
- nodeSep?: number
80
- rankSep?: number
81
- }
82
-
83
- export function isViewRuleAutoLayout(
84
- rule: DeploymentViewRule | DynamicViewRule | ViewRule,
85
- ): rule is ViewRuleAutoLayout {
86
- return 'direction' in rule
87
- }
88
-
89
- export interface ViewRuleGroup {
90
- groupRules: Array<ViewRulePredicate | ViewRuleGroup>
91
- title: string | null
92
- color?: Color
93
- border?: BorderStyle
94
- // 0-100
95
- opacity?: number
96
- multiple?: boolean
97
- size?: ShapeSize
98
- padding?: SpacingSize
99
- textSize?: TextSize
100
- }
101
-
102
- export function isViewRuleGroup(rule: ViewRule): rule is ViewRuleGroup {
103
- return 'title' in rule && 'groupRules' in rule && Array.isArray(rule.groupRules)
104
- }
105
-
106
- export type ViewRule =
107
- | ViewRulePredicate
108
- | ViewRuleGlobalPredicateRef
109
- | ViewRuleGroup
110
- | ViewRuleStyle
111
- | ViewRuleGlobalStyle
112
- | ViewRuleAutoLayout
113
-
114
- export interface BasicView<
115
- ViewType extends 'element' | 'dynamic' | 'deployment',
116
- ViewIDs extends string,
117
- Tags extends string,
1
+ import { isTruthy } from 'remeda'
2
+ import type { Any } from './aux'
3
+ import * as aux from './aux'
4
+ import type { _stage, _type, ExtractOnStage, ModelStage } from './const'
5
+ import type { ViewType } from './view-common'
6
+ import type {
7
+ ComputedDeploymentView,
8
+ ComputedDynamicView,
9
+ ComputedElementView,
10
+ } from './view-computed'
11
+ import type {
12
+ LayoutedDeploymentView,
13
+ LayoutedDynamicView,
14
+ LayoutedElementView,
15
+ } from './view-layouted'
16
+ import type { ParsedDeploymentView } from './view-parsed.deployment'
17
+ import type { ParsedDynamicView } from './view-parsed.dynamic'
18
+ import type { ParsedElementView } from './view-parsed.element'
19
+
20
+ export type ParsedView<A extends Any = Any> =
21
+ | ParsedElementView<A>
22
+ | ParsedDeploymentView<A>
23
+ | ParsedDynamicView<A>
24
+
25
+ // export type ParsedView<A extends Any = Any> = ExclusiveUnion<{
26
+ // Element: ParsedElementView<A>
27
+ // Deployment: ParsedDeploymentView<A>
28
+ // Dynamic: ParsedDynamicView<A>
29
+ // }>
30
+ /**
31
+ * Should be `ParsedView` but keep it for backward compatibility
32
+ * @deprecated use `ParsedView`
33
+ */
34
+ export type { ParsedView as LikeC4View }
35
+
36
+ export type ComputedView<A extends Any = Any> =
37
+ | ComputedElementView<A>
38
+ | ComputedDeploymentView<A>
39
+ | ComputedDynamicView<A>
40
+ // export type ComputedView<A extends Any = Any> = ExclusiveUnion<{
41
+ // Element: ComputedElementView<A>
42
+ // Deployment: ComputedDeploymentView<A>
43
+ // Dynamic: ComputedDynamicView<A>
44
+ // }>
45
+
46
+ // export type LayoutedView<A extends Any = Any> = ExclusiveUnion<{
47
+ // Element: LayoutedElementView<A>
48
+ // Deployment: LayoutedDeploymentView<A>
49
+ // Dynamic: LayoutedDynamicView<A>
50
+ // }>
51
+
52
+ export type LayoutedView<A extends Any = Any> =
53
+ | LayoutedElementView<A>
54
+ | LayoutedDeploymentView<A>
55
+ | LayoutedDynamicView<A>
56
+
57
+ export type ProcessedView<A extends Any = Any> =
58
+ | ComputedView<A>
59
+ | LayoutedView<A>
60
+
61
+ /**
62
+ * @alias DiagramView
63
+ */
64
+ export type { LayoutedView as DiagramView }
65
+ export type AnyView<A extends Any = Any> =
66
+ | ParsedElementView<A>
67
+ | ParsedDeploymentView<A>
68
+ | ParsedDynamicView<A>
69
+ | ComputedElementView<A>
70
+ | ComputedDeploymentView<A>
71
+ | ComputedDynamicView<A>
72
+ | LayoutedElementView<A>
73
+ | LayoutedDeploymentView<A>
74
+ | LayoutedDynamicView<A>
75
+ // export type AnyView<A extends Any = Any> = ExclusiveUnion<{
76
+ // ParsedElement: ParsedElementView<A>
77
+ // ParsedDeployment: ParsedDeploymentView<A>
78
+ // ParsedDynamic: ParsedDynamicView<A>
79
+ // ComputedElement: ComputedElementView<A>
80
+ // ComputedDeployment: ComputedDeploymentView<A>
81
+ // ComputedDynamic: ComputedDynamicView<A>
82
+ // LayoutedElement: LayoutedElementView<A>
83
+ // LayoutedDeployment: LayoutedDeploymentView<A>
84
+ // LayoutedDynamic: LayoutedDynamicView<A>
85
+ // }>
86
+
87
+ export type ViewOnStage<V extends AnyView<Any>, T extends ModelStage> = Extract<V, { [_stage]: T }>
88
+ export type ViewWithType<V extends AnyView<Any>, T extends ViewType> = Extract<V, { [_type]: T }>
89
+
90
+ export type ViewRule<A extends Any = Any> = ParsedView<A>['rules'][number]
91
+ export type ViewRulePredicate<A extends Any = Any> = Extract<
92
+ ViewRule<A>,
93
+ { include: any[] } | { exclude: any[] }
94
+ >
95
+
96
+ export function isViewRulePredicate<V extends ViewRule<any>>(rule: V): rule is Extract<
97
+ V,
98
+ { include: any[] } | { exclude: any[] }
118
99
  > {
119
- readonly __?: ViewType
120
- readonly id: ViewId<ViewIDs>
121
- readonly title: string | null
122
- readonly description: string | null
123
- readonly tags: NonEmptyArray<Tag<Tags>> | null
124
- readonly links: NonEmptyArray<Link> | null
125
-
126
- /**
127
- * URI to the source file of this view.
128
- * Undefined if the view is auto-generated.
129
- */
130
- readonly docUri?: string
131
- /**
132
- * For all views we find common ancestor path.
133
- * This is used to generate relative paths, i.e.:
134
- * - "/home/project/index.c4" becomes "index.c4"
135
- * - "/home/project/subdir/views.c4" becomes "subdir/views.c4"
136
- *
137
- * Undefined if the view is auto-generated.
138
- */
139
- readonly relativePath?: string
140
-
141
- /**
142
- * If the view is changed manually this field contains the layout data.
143
- */
144
- readonly manualLayout?: ViewManualLayout | undefined
145
-
146
- readonly customColorDefinitions: CustomColorDefinitions
147
- }
148
-
149
- export interface BasicElementView<ViewIDs extends string, Tags extends string>
150
- extends BasicView<'element', ViewIDs, Tags>
151
- {
152
- readonly viewOf?: Fqn
153
- readonly rules: ViewRule[]
154
- }
155
- export interface ScopedElementView<ViewIDs extends string, Tags extends string>
156
- extends BasicElementView<ViewIDs, Tags>
157
- {
158
- readonly viewOf: Fqn
159
- }
160
-
161
- export interface ExtendsElementView<ViewIDs extends string, Tags extends string>
162
- extends BasicElementView<ViewIDs, Tags>
163
- {
164
- readonly extends: ViewId<ViewIDs>
165
- }
166
- export type ElementView<
167
- ViewIDs extends string = string,
168
- Tags extends string = string,
169
- > =
170
- | ScopedElementView<ViewIDs, Tags>
171
- | ExtendsElementView<ViewIDs, Tags>
172
- | BasicElementView<ViewIDs, Tags>
173
-
174
- export interface DynamicViewStep {
175
- readonly source: Fqn
176
- readonly target: Fqn
177
- readonly title: string | null
178
- readonly description?: string
179
- readonly technology?: string
180
- readonly notation?: string
181
- // Notes for walkthrough
182
- readonly notes?: string
183
- readonly color?: Color
184
- readonly line?: RelationshipLineType
185
- readonly head?: RelationshipArrowType
186
- readonly tail?: RelationshipArrowType
187
- readonly isBackward?: boolean
188
- // Link to dynamic view
189
- readonly navigateTo?: ViewId
190
- __parallel?: never
191
- }
192
-
193
- export interface DynamicViewParallelSteps {
194
- readonly __parallel: DynamicViewStep[]
195
- }
196
-
197
- export type DynamicViewStepOrParallel = DynamicViewStep | DynamicViewParallelSteps
198
-
199
- export type DynamicViewIncludeRule = {
200
- include: ModelLayer.AnyFqnExpr[]
201
- }
202
-
203
- export type DynamicViewRule =
204
- | DynamicViewIncludeRule
205
- | ViewRuleGlobalPredicateRef
206
- | ViewRuleStyle
207
- | ViewRuleGlobalStyle
208
- | ViewRuleAutoLayout
209
- export interface DynamicView<
210
- ViewIDs extends string = string,
211
- Tags extends string = string,
212
- > extends BasicView<'dynamic', ViewIDs, Tags> {
213
- readonly __: 'dynamic'
214
-
215
- readonly steps: DynamicViewStepOrParallel[]
216
-
217
- readonly rules: DynamicViewRule[]
218
- }
219
-
220
- export function isDynamicViewParallelSteps(step: DynamicViewStepOrParallel): step is DynamicViewParallelSteps {
221
- return '__parallel' in step && isArray(step.__parallel)
222
- }
223
-
224
- export type CustomColorDefinitions = { [key: string]: ThemeColorValues }
225
-
226
- export type DeploymentViewRulePredicate =
227
- | {
228
- include: ExpressionV2[]
229
- exclude?: never
230
- }
231
- | {
232
- include?: never
233
- exclude: ExpressionV2[]
234
- }
235
- export type DeploymentViewRuleStyle = {
236
- targets: FqnExpr[]
237
- notation?: string
238
- style: ElementStyle & {
239
- color?: Color
240
- shape?: ElementShape
241
- icon?: IconUrl
242
- }
243
- }
244
- export type DeploymentViewRule = DeploymentViewRulePredicate | ViewRuleAutoLayout | DeploymentViewRuleStyle
245
-
246
- export interface DeploymentView<
247
- ViewIDs extends string = string,
248
- Tags extends string = string,
249
- > extends BasicView<'deployment', ViewIDs, Tags> {
250
- readonly __: 'deployment'
251
- readonly rules: DeploymentViewRule[]
252
- }
253
-
254
- export type LikeC4View<
255
- ViewIDs extends string = string,
256
- Tags extends string = string,
257
- > = ElementView<ViewIDs, Tags> | DynamicView<ViewIDs, Tags> | DeploymentView<ViewIDs, Tags>
258
-
259
- export function isDeploymentView(view: LikeC4View): view is DeploymentView
260
- export function isDeploymentView<V extends { __?: string }>(view: V): boolean
261
- export function isDeploymentView(view: LikeC4View): view is DeploymentView {
262
- return view.__ === 'deployment'
263
- }
264
-
265
- export function isDynamicView(view: LikeC4View): view is DynamicView {
266
- return view.__ === 'dynamic'
267
- }
268
-
269
- export function isElementView(view: LikeC4View): view is ElementView {
270
- return isNullish(view.__) || view.__ === 'element'
271
- }
272
-
273
- export function isExtendsElementView(view: LikeC4View): view is ExtendsElementView<string, string> {
274
- return isElementView(view) && 'extends' in view
275
- }
276
-
277
- export function isScopedElementView(view: LikeC4View): view is ScopedElementView<string, string> {
278
- return isElementView(view) && 'viewOf' in view
279
- }
280
-
281
- export type NodeId<IDs extends string = string> = Tagged<IDs, 'Fqn'>
282
-
283
- export type EdgeId = Tagged<string, 'EdgeId'>
284
- export type StepEdgeIdLiteral = `step-${number}` | `step-${number}.${number}`
285
- export type StepEdgeId = Tagged<StepEdgeIdLiteral, 'EdgeId'>
286
- export function stepEdgeId(step: number, parallelStep?: number): StepEdgeId {
287
- const id = `step-${String(step).padStart(2, '0')}` as StepEdgeId
288
- return parallelStep ? `${id}.${parallelStep}` as StepEdgeId : id
100
+ return 'include' in rule || 'exclude' in rule
289
101
  }
290
102
 
291
- export function isStepEdgeId(id: string): id is StepEdgeId {
292
- return id.startsWith('step-')
103
+ export function isViewRuleStyle<V extends ViewRule<any>>(
104
+ rule: V,
105
+ ): rule is Extract<V, { targets: any[]; style: {} }> {
106
+ return 'targets' in rule && 'style' in rule
293
107
  }
294
108
 
295
- export function extractStep(id: EdgeId): number {
296
- if (!isStepEdgeId(id)) {
297
- throw new Error(`Invalid step edge id: ${id}`)
298
- }
299
- return parseFloat(id.slice('step-'.length))
109
+ export function isComputedView<V extends AnyView<any>>(view: V): view is ExtractOnStage<V, 'computed'> {
110
+ return view._stage === 'computed'
300
111
  }
301
112
 
302
- // Get the prefix of the parallel steps
303
- // i.e. step-01.1 -> step-01.
304
- export function getParallelStepsPrefix(id: string): string | null {
305
- if (isStepEdgeId(id) && id.includes('.')) {
306
- return id.slice(0, id.indexOf('.') + 1)
307
- }
308
- return null
113
+ export function isDiagramView<V extends AnyView<any>>(view: V): view is ExtractOnStage<V, 'layouted'> {
114
+ return view._stage === 'layouted'
309
115
  }
116
+ export { isDiagramView as isLayoutedView }
310
117
 
311
- export interface ComputedNode {
312
- id: NodeId
313
- kind: string // TODO: fix ElementKind | DeploymentNodeKind
314
- parent: NodeId | null
315
- /**
316
- * Reference to model element
317
- * If 1 - node id is a reference
318
- */
319
- modelRef?: 1 | Fqn
320
- /**
321
- * Reference to deployment element
322
- * If 1 - node id is a reference
323
- */
324
- deploymentRef?: 1 | Fqn
325
- title: string
326
- description: string | null
327
- technology: string | null
328
- notation?: string
329
- tags: NonEmptyArray<Tag> | null
330
- links: NonEmptyArray<Link> | null
331
- children: NodeId[]
332
- inEdges: EdgeId[]
333
- outEdges: EdgeId[]
334
- shape: ElementShape
335
- color: Color
336
- /**
337
- * @deprecated Use `style` instead
338
- */
339
- icon?: IconUrl
340
- style: ElementStyle
341
- navigateTo?: ViewId | null
342
- level: number
343
- // For compound nodes, the max depth of nested nodes
344
- depth?: number
345
- /**
346
- * If this node was customized in the view
347
- */
348
- isCustomized?: boolean
349
- }
350
- export namespace ComputedNode {
351
- export function modelRef(node: ComputedNode): Fqn | null {
352
- return node.modelRef === 1 ? node.id : (node.modelRef ?? null)
353
- }
354
- export function deploymentRef(node: ComputedNode): Fqn | null {
355
- return node.deploymentRef === 1 ? node.id : (node.deploymentRef ?? null)
356
- }
357
- /**
358
- * Nodes group is a special kind of node, exisiting only in view
359
- */
360
- export function isNodesGroup(node: ComputedNode): boolean {
361
- return node.kind === ElementKind.Group
362
- }
363
- }
364
-
365
- export interface ComputedEdge {
366
- id: EdgeId
367
- parent: NodeId | null
368
- source: NodeId
369
- target: NodeId
370
- label: string | null
371
- description?: string
372
- technology?: string
373
- relations: RelationId[]
374
- kind?: RelationshipKind
375
- notation?: string
376
- // Notes for walkthrough
377
- notes?: string
378
- color?: Color
379
- line?: RelationshipLineType
380
- head?: RelationshipArrowType
381
- tail?: RelationshipArrowType
382
- tags?: NonEmptyArray<Tag>
383
- // Link to dynamic view
384
- navigateTo?: ViewId
385
- /**
386
- * If this edge is derived from custom relationship predicate
387
- */
388
- isCustomized?: boolean
389
- /**
390
- * For layouting purposes
391
- * @default 'forward'
392
- */
393
- dir?: 'forward' | 'back' | 'both'
394
- }
395
-
396
- export interface ViewWithHash {
397
- /**
398
- * Hash of the view object.
399
- * This is used to detect changes in layout
400
- */
401
- hash: string
402
- }
403
-
404
- export interface ViewWithNotation {
405
- notation?: {
406
- elements: ElementNotation[]
407
- }
408
- }
409
- export interface ViewAutoLayout {
410
- direction: ViewRuleAutoLayout['direction']
411
- rankSep?: number
412
- nodeSep?: number
413
- }
414
- export interface ComputedElementView<
415
- ViewIDs extends string = string,
416
- Tags extends string = string,
417
- > extends Omit<ElementView<ViewIDs, Tags>, 'rules' | 'docUri'>, ViewWithHash, ViewWithNotation {
418
- readonly extends?: ViewId<ViewIDs>
419
- readonly autoLayout: ViewAutoLayout
420
- readonly nodes: ComputedNode[]
421
- readonly edges: ComputedEdge[]
422
- rules?: never
423
- docUri?: never
424
- }
425
- export interface ComputedDynamicView<
426
- ViewIDs extends string = string,
427
- Tags extends string = string,
428
- > extends Omit<DynamicView<ViewIDs, Tags>, 'rules' | 'steps' | 'docUri'>, ViewWithHash, ViewWithNotation {
429
- readonly autoLayout: ViewAutoLayout
430
- readonly nodes: ComputedNode[]
431
- readonly edges: ComputedEdge[]
432
- steps?: never
433
- rules?: never
434
- docUri?: never
435
- }
436
-
437
- export interface ComputedDeploymentView<
438
- ViewIDs extends string = string,
439
- Tags extends string = string,
440
- > extends Omit<DeploymentView<ViewIDs, Tags>, 'rules' | 'docUri'>, ViewWithHash, ViewWithNotation {
441
- readonly autoLayout: ViewAutoLayout
442
- readonly nodes: ComputedNode[]
443
- readonly edges: ComputedEdge[]
444
- rules?: never
445
- docUri?: never
446
- }
447
-
448
- export type ComputedView<
449
- ViewIDs extends string = string,
450
- Tags extends string = string,
451
- > = ComputedElementView<ViewIDs, Tags> | ComputedDynamicView<ViewIDs, Tags> | ComputedDeploymentView<ViewIDs, Tags>
452
-
453
- export namespace ComputedView {
454
- export function isDeployment(view: ComputedView): view is ComputedDeploymentView {
455
- return view.__ === 'deployment'
456
- }
457
- export function isDynamic(view: ComputedView): view is ComputedDynamicView {
458
- return view.__ === 'dynamic'
459
- }
460
- export function isElement(view: ComputedView): view is ComputedElementView {
461
- return isNullish(view.__) || view.__ === 'element'
462
- }
463
- }
464
-
465
- // Bounding box
466
- export type BBox = {
467
- x: number
468
- y: number
469
- width: number
470
- height: number
118
+ export function isElementView<V extends AnyView<any>>(view: V): view is ViewWithType<V, 'element'> {
119
+ return view._type === 'element'
471
120
  }
472
121
 
473
- export function getBBoxCenter({
474
- x,
475
- y,
476
- width,
477
- height,
478
- }: BBox): XYPoint {
479
- return {
480
- x: x + width / 2,
481
- y: y + height / 2,
482
- }
122
+ export function isScopedElementView<V extends AnyView<any>>(
123
+ view: V,
124
+ ): view is ViewWithType<V, 'element'> & { viewOf: aux.StrictFqn<Any> } {
125
+ return isElementView(view) && isTruthy(view.viewOf)
483
126
  }
484
127
 
485
- export interface DiagramNode extends ComputedNode {
486
- width: number
487
- height: number
488
- // Absolute position, top left
489
- position: Point
490
- labelBBox: BBox
128
+ export function isExtendsElementView<V extends AnyView<any>>(
129
+ view: V,
130
+ ): view is ViewWithType<V, 'element'> & { extends: aux.StrictViewId<Any> } {
131
+ return isElementView(view) && isTruthy(view.extends)
491
132
  }
492
133
 
493
- export namespace DiagramNode {
494
- export function modelRef(node: Pick<DiagramNode, 'id' | 'modelRef'>): Fqn | null {
495
- return node.modelRef === 1 ? node.id : (node.modelRef ?? null)
496
- }
497
- export function deploymentRef(node: Pick<DiagramNode, 'id' | 'deploymentRef'>): Fqn | null {
498
- return node.deploymentRef === 1 ? node.id : (node.deploymentRef ?? null)
499
- }
500
- /**
501
- * Nodes group is a special kind of node, exisiting only in view
502
- */
503
- export function isNodesGroup(node: Pick<DiagramNode, 'kind'>): boolean {
504
- return node.kind === ElementKind.Group
505
- }
506
- }
507
-
508
- export interface DiagramEdge extends ComputedEdge {
509
- // Bezier points
510
- points: NonEmptyArray<Point>
511
- // Control points to adjust the edge
512
- controlPoints?: NonEmptyArray<XYPoint>
513
- labelBBox?: BBox | null
514
- // Graphviz edge POS
515
- // TODO: temporary solution, should be moved out
516
- dotpos?: string
517
- }
518
-
519
- export interface DiagramView<
520
- ViewIDs extends string = string,
521
- Tags extends string = string,
522
- > extends Omit<ComputedView<ViewIDs, Tags>, 'nodes' | 'edges' | 'manualLayout'> {
523
- readonly nodes: DiagramNode[]
524
- readonly edges: DiagramEdge[]
525
- readonly bounds: BBox
526
-
527
- /**
528
- * If diagram has manual layout
529
- * But was changed and layout should be recalculated
530
- */
531
- hasLayoutDrift?: boolean
532
- // Should not exist in DiagramView
533
- manualLayout?: never
134
+ export function isDeploymentView<V extends AnyView<any>>(view: V): view is ViewWithType<V, 'deployment'> {
135
+ return view._type === 'deployment'
534
136
  }
535
137
 
536
- export type ViewManualLayout = {
537
- // Object hash of previous layout
538
- readonly hash: string
539
- readonly x: number
540
- readonly y: number
541
- readonly width: number
542
- readonly height: number
543
- readonly autoLayout: ViewAutoLayout
544
- readonly nodes: Record<string, {
545
- isCompound: boolean
546
- x: number
547
- y: number
548
- width: number
549
- height: number
550
- }>
551
- readonly edges: Record<string, {
552
- // Graphviz edge POS
553
- dotpos?: string
554
- // Bezier points
555
- points: NonEmptyArray<Point>
556
- // Control points to adjust the edge
557
- controlPoints?: NonEmptyArray<XYPoint>
558
- labelBBox?: BBox
559
- }>
138
+ export function isDynamicView<V extends AnyView<any>>(view: V): view is ViewWithType<V, 'dynamic'> {
139
+ return view._type === 'dynamic'
560
140
  }