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