@likec4/core 1.30.0 → 1.32.0

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