@likec4/core 1.40.0 → 1.42.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 (257) hide show
  1. package/builder/package.json +4 -0
  2. package/compute-view/package.json +4 -0
  3. package/compute-view/relationships/package.json +4 -0
  4. package/dist/builder/index.d.mts +83 -20
  5. package/dist/builder/index.mjs +210 -126
  6. package/dist/compute-view/index.d.mts +8 -7
  7. package/dist/compute-view/index.mjs +14 -11
  8. package/dist/compute-view/relationships-view/index.d.mts +9 -8
  9. package/dist/compute-view/relationships-view/index.mjs +6 -6
  10. package/dist/index.d.mts +7 -7
  11. package/dist/index.mjs +12 -12
  12. package/dist/model/connection/deployment/index.d.mts +11 -10
  13. package/dist/model/connection/deployment/index.mjs +2 -2
  14. package/dist/model/connection/index.d.mts +12 -11
  15. package/dist/model/connection/index.mjs +3 -3
  16. package/dist/model/connection/model/index.d.mts +11 -10
  17. package/dist/model/connection/model/index.mjs +2 -2
  18. package/dist/model/index.d.mts +14 -14
  19. package/dist/model/index.mjs +4 -5
  20. package/dist/shared/{core.DHQ32OHa.mjs → core.01VTr9qu.mjs} +10 -29
  21. package/dist/shared/core.1vX5a9AY.mjs +86 -0
  22. package/dist/shared/{core.BVNaR17u.mjs → core.B7KhhkRY.mjs} +1 -1
  23. package/dist/shared/core.B85MJLTf.mjs +5 -0
  24. package/dist/shared/{core.BIAlzwKc.mjs → core.BIqHjQiH.mjs} +85 -45
  25. package/dist/shared/core.BKlholso.mjs +3 -0
  26. package/dist/shared/core.BR4zXDH-.mjs +13 -0
  27. package/dist/shared/{core.yHe79zEl.mjs → core.BYNkXQ8A.mjs} +21 -12
  28. package/dist/shared/core.BazD6cot.mjs +14 -0
  29. package/dist/shared/{core.BuoXfSMj.mjs → core.BbE4y-yl.mjs} +1 -1
  30. package/dist/shared/core.BoYfZOBm.mjs +3 -0
  31. package/dist/shared/core.BsSXS-_R.mjs +7 -0
  32. package/dist/shared/{core.T-eLZTW_.mjs → core.BzTakU3I.mjs} +15 -7
  33. package/dist/shared/{core.4u1dVmfX.mjs → core.C2TiyjI6.mjs} +2 -2
  34. package/dist/shared/{core.DLpidoWc.mjs → core.C3JowhaZ.mjs} +3 -3
  35. package/dist/shared/{core.CNGyqkJh.mjs → core.C4x8aaWa.mjs} +3 -1
  36. package/dist/shared/{core.BB6zA-UU.mjs → core.C8YY6Uub.mjs} +38 -9
  37. package/dist/shared/{core.FPITT8Vx.mjs → core.C8sl5Y8Z.mjs} +144 -61
  38. package/dist/shared/{core.DuR3R-xJ.mjs → core.CNgZvKb8.mjs} +3 -5176
  39. package/dist/shared/{core.BbThmf6M.d.mts → core.CQngdcuj.d.mts} +85 -4
  40. package/dist/shared/{core.Be1n9a0i.mjs → core.C_Ni6yHl.mjs} +5 -4
  41. package/dist/shared/core.CbT8JVYL.mjs +5 -0
  42. package/dist/shared/core.CqAJJpK_.mjs +3 -0
  43. package/dist/shared/{core.CySf-2gP.d.mts → core.D0PjZzIS.d.mts} +52 -15
  44. package/dist/shared/{core.DrvfVXkh.d.mts → core.D5fzJWbF.d.mts} +11 -2
  45. package/dist/shared/{core.DrVOJuxX.d.mts → core.DACpKp35.d.mts} +5 -5
  46. package/dist/shared/core.DFi2dOTl.mjs +39548 -0
  47. package/dist/shared/{core.D704WZES.d.mts → core.DIol3syK.d.mts} +2 -2
  48. package/dist/shared/{core.DlG1xWt2.mjs → core.DMMOWQqc.mjs} +3 -2
  49. package/dist/shared/core.DNbUPnve.mjs +3990 -0
  50. package/dist/shared/{core.CCD1ID81.mjs → core.DRJma0Ol.mjs} +4 -3
  51. package/dist/shared/{core.DgttqsJc.mjs → core.DRhg-gVU.mjs} +9 -9
  52. package/dist/shared/core.DSO_rTC2.mjs +5322 -0
  53. package/dist/shared/{core.vWJTxpLV.d.mts → core.D_vkffV4.d.mts} +4 -2
  54. package/dist/shared/core.DdMJk7nx.d.mts +476 -0
  55. package/dist/shared/{core.D_fI5Lf6.d.mts → core.Dgs6-nuz.d.mts} +24 -4
  56. package/dist/shared/{core.Be4Jy9Qx.mjs → core.FZ305VYd.mjs} +2 -2
  57. package/dist/shared/core.OHD4KXm9.mjs +5 -0
  58. package/dist/shared/{core.GTgsmXS_.mjs → core.QJD_fcrc.mjs} +2 -2
  59. package/dist/shared/core.RfnaEmgA.mjs +7 -0
  60. package/dist/shared/core.fHR_8Tnq.d.mts +450 -0
  61. package/dist/shared/{core.D0EgVMQK.mjs → core.lRvxPoao.mjs} +14 -12
  62. package/dist/shared/{core.CaT0SUUK.mjs → core.rCeaAqgW.mjs} +1 -84
  63. package/dist/shared/{core.kxeJe0OY.d.mts → core.s9uwOt60.d.mts} +4 -4
  64. package/dist/shared/core.yna0OdV5.d.mts +98 -0
  65. package/dist/styles/index.d.mts +106 -0
  66. package/dist/styles/index.mjs +1 -0
  67. package/dist/types/_aux.d.mts +2 -2
  68. package/dist/types/_aux.mjs +1 -5
  69. package/dist/types/expression-model.d.mts +3 -4
  70. package/dist/types/expression.d.mts +3 -4
  71. package/dist/types/fqnRef.d.mts +2 -2
  72. package/dist/types/fqnRef.mjs +3 -3
  73. package/dist/types/index.d.mts +8 -8
  74. package/dist/types/index.mjs +151 -6
  75. package/dist/types/scalar.mjs +3 -2
  76. package/dist/utils/graphology/index.d.mts +1864 -0
  77. package/dist/utils/graphology/index.mjs +1 -0
  78. package/dist/utils/index.d.mts +11 -6
  79. package/dist/utils/index.mjs +21 -37
  80. package/dist/utils/iterable/index.d.mts +1 -1
  81. package/dist/utils/iterable/index.mjs +45 -7
  82. package/model/package.json +4 -0
  83. package/package.json +42 -24
  84. package/styles/package.json +4 -0
  85. package/types/package.json +4 -0
  86. package/utils/graphology/package.json +4 -0
  87. package/utils/package.json +4 -0
  88. package/dist/shared/core.6_Vp2iiN.mjs +0 -172
  89. package/dist/shared/core.Bpou6c2f.d.mts +0 -850
  90. package/dist/shared/core.CUw_2J9j.mjs +0 -47
  91. package/dist/shared/core.CzdwsPmY.d.mts +0 -69
  92. package/dist/shared/core.DoM6aM9N.mjs +0 -7
  93. package/dist/shared/core.ILwny7BV.mjs +0 -38
  94. package/dist/theme/index.d.mts +0 -11
  95. package/dist/theme/index.mjs +0 -232
  96. package/src/builder/Builder.deployment.ts +0 -224
  97. package/src/builder/Builder.deploymentModel.ts +0 -449
  98. package/src/builder/Builder.element.ts +0 -241
  99. package/src/builder/Builder.model.ts +0 -494
  100. package/src/builder/Builder.ts +0 -870
  101. package/src/builder/Builder.view-common.ts +0 -273
  102. package/src/builder/Builder.view-deployment.ts +0 -135
  103. package/src/builder/Builder.view-element.ts +0 -202
  104. package/src/builder/Builder.views.ts +0 -399
  105. package/src/builder/Builder.with.ts +0 -156
  106. package/src/builder/_types.ts +0 -320
  107. package/src/builder/index.ts +0 -11
  108. package/src/compute-view/compute-view.ts +0 -80
  109. package/src/compute-view/deployment-view/_types.ts +0 -38
  110. package/src/compute-view/deployment-view/clean-connections.ts +0 -236
  111. package/src/compute-view/deployment-view/compute.ts +0 -94
  112. package/src/compute-view/deployment-view/memory/index.ts +0 -9
  113. package/src/compute-view/deployment-view/memory/memory.ts +0 -96
  114. package/src/compute-view/deployment-view/predicates/deploymentRefs-where.ts +0 -18
  115. package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +0 -154
  116. package/src/compute-view/deployment-view/predicates/index.ts +0 -8
  117. package/src/compute-view/deployment-view/predicates/relation-direct.ts +0 -243
  118. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +0 -70
  119. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +0 -101
  120. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +0 -95
  121. package/src/compute-view/deployment-view/predicates/relation-where.ts +0 -18
  122. package/src/compute-view/deployment-view/predicates/utils.ts +0 -282
  123. package/src/compute-view/deployment-view/predicates/wildcard.ts +0 -41
  124. package/src/compute-view/deployment-view/stages/stage-exclude.ts +0 -5
  125. package/src/compute-view/deployment-view/stages/stage-final.ts +0 -245
  126. package/src/compute-view/deployment-view/stages/stage-include.ts +0 -95
  127. package/src/compute-view/deployment-view/utils.ts +0 -286
  128. package/src/compute-view/dynamic-view/compute.ts +0 -312
  129. package/src/compute-view/element-view/_types.ts +0 -47
  130. package/src/compute-view/element-view/clean-connections.ts +0 -117
  131. package/src/compute-view/element-view/compute.ts +0 -324
  132. package/src/compute-view/element-view/memory/NodeGroup.ts +0 -31
  133. package/src/compute-view/element-view/memory/index.ts +0 -10
  134. package/src/compute-view/element-view/memory/memory.ts +0 -178
  135. package/src/compute-view/element-view/memory/stage-exclude.ts +0 -59
  136. package/src/compute-view/element-view/memory/stage-final.ts +0 -129
  137. package/src/compute-view/element-view/memory/stage-include.ts +0 -130
  138. package/src/compute-view/element-view/predicates/_utils.ts +0 -91
  139. package/src/compute-view/element-view/predicates/element-expand.ts +0 -29
  140. package/src/compute-view/element-view/predicates/element-kind-tag.ts +0 -27
  141. package/src/compute-view/element-view/predicates/element-ref.ts +0 -24
  142. package/src/compute-view/element-view/predicates/relation-direct.ts +0 -321
  143. package/src/compute-view/element-view/predicates/relation-in-out.ts +0 -64
  144. package/src/compute-view/element-view/predicates/relation-in.ts +0 -115
  145. package/src/compute-view/element-view/predicates/relation-out.ts +0 -119
  146. package/src/compute-view/element-view/predicates/wildcard.ts +0 -88
  147. package/src/compute-view/element-view/utils.ts +0 -65
  148. package/src/compute-view/index.ts +0 -4
  149. package/src/compute-view/memory/AbstractMemory.ts +0 -45
  150. package/src/compute-view/memory/AbstractStageExclude.ts +0 -215
  151. package/src/compute-view/memory/AbstractStageInclude.ts +0 -200
  152. package/src/compute-view/memory/_types.ts +0 -148
  153. package/src/compute-view/memory/index.ts +0 -5
  154. package/src/compute-view/memory/ops.ts +0 -43
  155. package/src/compute-view/relationships-view/_types.ts +0 -16
  156. package/src/compute-view/relationships-view/compute.ts +0 -159
  157. package/src/compute-view/relationships-view/index.ts +0 -3
  158. package/src/compute-view/relationships-view/layout.ts +0 -357
  159. package/src/compute-view/relationships-view/utils.ts +0 -73
  160. package/src/compute-view/utils/ancestorsOfNode.ts +0 -19
  161. package/src/compute-view/utils/applyCustomElementProperties.ts +0 -107
  162. package/src/compute-view/utils/applyCustomRelationProperties.ts +0 -58
  163. package/src/compute-view/utils/applyViewRuleStyles.ts +0 -73
  164. package/src/compute-view/utils/buildComputedNodes.ts +0 -153
  165. package/src/compute-view/utils/buildElementNotations.ts +0 -63
  166. package/src/compute-view/utils/elementExpressionToPredicate.ts +0 -50
  167. package/src/compute-view/utils/link-nodes-with-edges.ts +0 -56
  168. package/src/compute-view/utils/merge-props-from-relationships.ts +0 -161
  169. package/src/compute-view/utils/relationExpressionToPredicates.ts +0 -55
  170. package/src/compute-view/utils/resolve-extended-views.ts +0 -85
  171. package/src/compute-view/utils/resolve-global-rules.ts +0 -88
  172. package/src/compute-view/utils/topological-sort.ts +0 -256
  173. package/src/compute-view/utils/view-hash.ts +0 -45
  174. package/src/compute-view/utils/with-readable-edges.ts +0 -40
  175. package/src/index.ts +0 -32
  176. package/src/model/DeploymentElementModel.ts +0 -682
  177. package/src/model/DeploymentModel.ts +0 -393
  178. package/src/model/ElementModel.ts +0 -293
  179. package/src/model/LikeC4Model.ts +0 -882
  180. package/src/model/RelationModel.ts +0 -152
  181. package/src/model/connection/Connection.ts +0 -72
  182. package/src/model/connection/deployment/DeploymentConnectionModel.ts +0 -185
  183. package/src/model/connection/deployment/find.ts +0 -120
  184. package/src/model/connection/deployment/index.ts +0 -8
  185. package/src/model/connection/index.ts +0 -22
  186. package/src/model/connection/model/ConnectionModel.ts +0 -158
  187. package/src/model/connection/model/find.ts +0 -117
  188. package/src/model/connection/model/index.ts +0 -8
  189. package/src/model/connection/ops.ts +0 -276
  190. package/src/model/guards.ts +0 -77
  191. package/src/model/index.ts +0 -72
  192. package/src/model/types.ts +0 -67
  193. package/src/model/utils.ts +0 -66
  194. package/src/model/view/EdgeModel.ts +0 -120
  195. package/src/model/view/LikeC4ViewModel.ts +0 -361
  196. package/src/model/view/LikeC4ViewsFolder.ts +0 -151
  197. package/src/model/view/NodeModel.ts +0 -247
  198. package/src/theme/element.ts +0 -61
  199. package/src/theme/index.ts +0 -127
  200. package/src/theme/relationships.ts +0 -54
  201. package/src/types/RichText.ts +0 -206
  202. package/src/types/_aux.ts +0 -291
  203. package/src/types/_common.ts +0 -80
  204. package/src/types/const.ts +0 -34
  205. package/src/types/expression-model.ts +0 -294
  206. package/src/types/expression.ts +0 -313
  207. package/src/types/fqnRef.ts +0 -91
  208. package/src/types/geometry.ts +0 -159
  209. package/src/types/global.ts +0 -21
  210. package/src/types/index.ts +0 -42
  211. package/src/types/model-data.ts +0 -77
  212. package/src/types/model-deployment.ts +0 -88
  213. package/src/types/model-dump.ts +0 -79
  214. package/src/types/model-logical.ts +0 -135
  215. package/src/types/model-spec.ts +0 -85
  216. package/src/types/operators.ts +0 -156
  217. package/src/types/project.ts +0 -14
  218. package/src/types/scalar.ts +0 -162
  219. package/src/types/styles.ts +0 -122
  220. package/src/types/view-changes.ts +0 -32
  221. package/src/types/view-common.ts +0 -157
  222. package/src/types/view-computed.ts +0 -118
  223. package/src/types/view-layouted.ts +0 -98
  224. package/src/types/view-parsed.deployment.ts +0 -39
  225. package/src/types/view-parsed.dynamic.ts +0 -89
  226. package/src/types/view-parsed.element.ts +0 -65
  227. package/src/types/view.ts +0 -113
  228. package/src/utils/common-head.ts +0 -22
  229. package/src/utils/compare-natural.ts +0 -60
  230. package/src/utils/const.ts +0 -1
  231. package/src/utils/fqn.ts +0 -302
  232. package/src/utils/getOrCreate.ts +0 -8
  233. package/src/utils/guards.ts +0 -9
  234. package/src/utils/index.ts +0 -68
  235. package/src/utils/invariant.ts +0 -29
  236. package/src/utils/iterable/_types.ts +0 -5
  237. package/src/utils/iterable/filter.ts +0 -55
  238. package/src/utils/iterable/find.ts +0 -38
  239. package/src/utils/iterable/first.ts +0 -48
  240. package/src/utils/iterable/flat.ts +0 -17
  241. package/src/utils/iterable/head.ts +0 -22
  242. package/src/utils/iterable/index.ts +0 -15
  243. package/src/utils/iterable/map.ts +0 -40
  244. package/src/utils/iterable/reduce.ts +0 -24
  245. package/src/utils/iterable/some.ts +0 -36
  246. package/src/utils/iterable/to.ts +0 -19
  247. package/src/utils/iterable/unique.ts +0 -23
  248. package/src/utils/markdown/index.ts +0 -2
  249. package/src/utils/markdown/to-html.ts +0 -32
  250. package/src/utils/markdown/to-text.ts +0 -14
  251. package/src/utils/memoize-prop.ts +0 -30
  252. package/src/utils/mnemonist.ts +0 -9
  253. package/src/utils/object-hash.ts +0 -14
  254. package/src/utils/promises.ts +0 -24
  255. package/src/utils/relations.ts +0 -36
  256. package/src/utils/set.ts +0 -83
  257. package/src/utils/string-hash.ts +0 -16
@@ -1,312 +0,0 @@
1
- import { filter, findLast, flatMap, hasAtLeast, isTruthy, map, only, pipe, reduce, unique } from 'remeda'
2
- import type { ElementModel, LikeC4Model } from '../../model'
3
- import { modelConnection } from '../../model'
4
- import type { AnyAux, aux, scalar } from '../../types'
5
- import {
6
- type Color,
7
- type ComputedDynamicView,
8
- type ComputedEdge,
9
- type DynamicViewStep,
10
- type NonEmptyArray,
11
- type ParsedDynamicView as DynamicView,
12
- type RelationshipArrowType,
13
- type RelationshipLineType,
14
- type StepEdgeId,
15
- _stage,
16
- _type,
17
- DefaultArrowType,
18
- DefaultLineStyle,
19
- DefaultRelationshipColor,
20
- isDynamicViewParallelSteps,
21
- isViewRuleAutoLayout,
22
- isViewRulePredicate,
23
- stepEdgeId,
24
- } from '../../types'
25
- import { nonNullable } from '../../utils'
26
- import { ancestorsFqn, commonAncestor, parentFqn } from '../../utils/fqn'
27
- import { applyCustomElementProperties } from '../utils/applyCustomElementProperties'
28
- import { applyViewRuleStyles } from '../utils/applyViewRuleStyles'
29
- import { buildComputedNodes, elementModelToNodeSource } from '../utils/buildComputedNodes'
30
- import { buildElementNotations } from '../utils/buildElementNotations'
31
- import { elementExprToPredicate } from '../utils/elementExpressionToPredicate'
32
- import { resolveGlobalRulesInDynamicView } from '../utils/resolve-global-rules'
33
- import { calcViewLayoutHash } from '../utils/view-hash'
34
-
35
- const { findConnection } = modelConnection
36
-
37
- type Element<A extends AnyAux> = ElementModel<A>
38
-
39
- namespace DynamicViewCompute {
40
- export interface Step<A extends AnyAux> {
41
- id: StepEdgeId
42
- source: Element<A>
43
- target: Element<A>
44
- title: string | null
45
- description?: string
46
- technology?: string
47
- // Notes for walkthrough
48
- notes?: scalar.MarkdownOrString
49
- color?: Color
50
- line?: RelationshipLineType
51
- head?: RelationshipArrowType
52
- tail?: RelationshipArrowType
53
- relations: scalar.RelationId[]
54
- isBackward: boolean
55
- navigateTo?: aux.StrictViewId<A>
56
- tags?: aux.Tags<A>
57
- }
58
- }
59
-
60
- class DynamicViewCompute<A extends AnyAux> {
61
- // Intermediate state
62
- private explicits = new Set<Element<A>>()
63
- private steps = [] as DynamicViewCompute.Step<A>[]
64
-
65
- constructor(
66
- protected model: LikeC4Model<A>,
67
- protected view: DynamicView<A>,
68
- ) {}
69
-
70
- private addStep(
71
- {
72
- source: stepSource,
73
- target: stepTarget,
74
- title: stepTitle,
75
- isBackward,
76
- navigateTo: stepNavigateTo,
77
- ...step
78
- }: DynamicViewStep<A>,
79
- index: number,
80
- parent?: number,
81
- ) {
82
- const id = parent ? stepEdgeId(parent, index) : stepEdgeId(index)
83
- const source = this.model.element(stepSource)
84
- const target = this.model.element(stepTarget)
85
-
86
- this.explicits.add(source)
87
- this.explicits.add(target)
88
-
89
- const {
90
- title,
91
- relations,
92
- tags,
93
- navigateTo: derivedNavigateTo,
94
- color,
95
- line,
96
- } = this.findRelations(source, target)
97
-
98
- const navigateTo = isTruthy(stepNavigateTo) && stepNavigateTo !== this.view.id ? stepNavigateTo : derivedNavigateTo
99
-
100
- this.steps.push({
101
- id,
102
- ...step,
103
- source,
104
- target,
105
- title: stepTitle ?? title,
106
- relations: relations ?? [],
107
- isBackward: isBackward ?? false,
108
- ...(navigateTo ? { navigateTo } : {}),
109
- ...(tags ? { tags } : {}),
110
- ...(color ? { color } : {}),
111
- ...(line ? { line } : {}),
112
- })
113
- }
114
-
115
- compute(): ComputedDynamicView<A> {
116
- const {
117
- docUri: _docUri, // exclude docUri
118
- rules: _rules, // exclude rules
119
- steps: viewSteps,
120
- ...view
121
- } = this.view
122
-
123
- let stepNum = 1
124
- for (const step of viewSteps) {
125
- if (isDynamicViewParallelSteps(step)) {
126
- if (step.__parallel.length === 0) {
127
- continue
128
- }
129
- if (step.__parallel.length === 1) {
130
- this.addStep(step.__parallel[0]!, stepNum)
131
- } else {
132
- step.__parallel.forEach((s, i) => this.addStep(s, i + 1, stepNum))
133
- }
134
- } else {
135
- this.addStep(step, stepNum)
136
- }
137
- stepNum++
138
- }
139
-
140
- const rules = resolveGlobalRulesInDynamicView(_rules, this.model.globals)
141
-
142
- for (const rule of rules) {
143
- if (isViewRulePredicate(rule)) {
144
- for (const expr of rule.include) {
145
- const satisfies = elementExprToPredicate(expr)
146
- for (const e of this.model.elements()) {
147
- if (satisfies(e)) {
148
- this.explicits.add(e)
149
- }
150
- }
151
- }
152
- }
153
- }
154
-
155
- const nodesMap = buildComputedNodes(
156
- [...this.explicits].map(elementModelToNodeSource),
157
- )
158
-
159
- const edges = this.steps.map(({ id, source, target, relations, title, description, isBackward, tags, ...step }) => {
160
- const sourceNode = nonNullable(nodesMap.get(source.id as scalar.NodeId), `Source node ${source.id} not found`)
161
- const targetNode = nonNullable(nodesMap.get(target.id as scalar.NodeId), `Target node ${target.id} not found`)
162
- const edge: ComputedEdge<A> = {
163
- id: id as unknown as aux.EdgeId,
164
- parent: commonAncestor(source.id, target.id) as scalar.NodeId | null,
165
- source: sourceNode.id,
166
- target: targetNode.id,
167
- label: title,
168
- relations,
169
- description: description ? { txt: description } : null,
170
- color: DefaultRelationshipColor,
171
- line: DefaultLineStyle,
172
- head: DefaultArrowType,
173
- tags: tags ?? [],
174
- ...step,
175
- }
176
- if (isBackward) {
177
- edge.dir = 'back'
178
- }
179
-
180
- while (edge.parent && !nodesMap.has(edge.parent)) {
181
- edge.parent = parentFqn(edge.parent)
182
- }
183
- sourceNode.outEdges.push(edge.id)
184
- targetNode.inEdges.push(edge.id)
185
- // Process edge source ancestors
186
- for (const sourceAncestor of ancestorsFqn(edge.source)) {
187
- if (sourceAncestor === edge.parent) {
188
- break
189
- }
190
- nodesMap.get(sourceAncestor)?.outEdges.push(edge.id)
191
- }
192
- // Process target hierarchy
193
- for (const targetAncestor of ancestorsFqn(edge.target)) {
194
- if (targetAncestor === edge.parent) {
195
- break
196
- }
197
- nodesMap.get(targetAncestor)?.inEdges.push(edge.id)
198
- }
199
- return edge
200
- })
201
-
202
- const nodes = applyCustomElementProperties(
203
- rules,
204
- applyViewRuleStyles(
205
- rules,
206
- // Keep order of elements
207
- [...this.explicits].map(e => nonNullable(nodesMap.get(e.id as scalar.NodeId))),
208
- ),
209
- )
210
-
211
- const autoLayoutRule = findLast(rules, isViewRuleAutoLayout)
212
-
213
- const nodeNotations = buildElementNotations(nodes)
214
-
215
- return calcViewLayoutHash({
216
- ...view,
217
- [_type]: 'dynamic',
218
- [_stage]: 'computed',
219
- variant: view.variant ?? 'diagram',
220
- autoLayout: {
221
- direction: autoLayoutRule?.direction ?? 'LR',
222
- ...(autoLayoutRule?.nodeSep && { nodeSep: autoLayoutRule.nodeSep }),
223
- ...(autoLayoutRule?.rankSep && { rankSep: autoLayoutRule.rankSep }),
224
- },
225
- nodes: map(nodes, n => {
226
- if (n.icon === 'none') {
227
- delete n.icon
228
- }
229
- return n
230
- }),
231
- edges,
232
- ...(nodeNotations.length > 0 && {
233
- notation: {
234
- nodes: nodeNotations,
235
- },
236
- }),
237
- })
238
- }
239
-
240
- private findRelations(source: Element<A>, target: Element<A>): {
241
- title: string | null
242
- tags: aux.Tags<A> | null
243
- relations: NonEmptyArray<aux.RelationId> | null
244
- navigateTo: aux.StrictViewId<A> | null
245
- color: Color | null
246
- line: RelationshipLineType | null
247
- } {
248
- const relationships = findConnection(source, target, 'directed').flatMap(r => [...r.relations])
249
- if (relationships.length === 0) {
250
- return {
251
- title: null,
252
- tags: null,
253
- relations: null,
254
- navigateTo: null,
255
- color: null,
256
- line: null,
257
- }
258
- }
259
- const alltags = pipe(
260
- relationships,
261
- flatMap(r => r.tags),
262
- filter(isTruthy),
263
- unique(),
264
- ) as aux.Tags<A>
265
- const tags = hasAtLeast(alltags, 1) ? alltags : null
266
- const relations = hasAtLeast(relationships, 1) ? map(relationships, r => r.id) : null
267
-
268
- // Most closest relation
269
- const relation = only(relationships) || relationships.find(r => r.source === source && r.target === target)
270
- const relationNavigateTo = relation?.$relationship.navigateTo ?? null
271
-
272
- const navigateTo = relationNavigateTo && relationNavigateTo !== this.view.id
273
- ? relationNavigateTo as aux.StrictViewId<A>
274
- : pipe(
275
- relationships,
276
- map(r => r.$relationship.navigateTo as aux.StrictViewId<A>),
277
- filter(isTruthy),
278
- filter(v => v !== this.view.id),
279
- unique(),
280
- only(),
281
- )
282
-
283
- const commonProperties = pipe(
284
- relationships,
285
- reduce((acc, { title, $relationship: r }) => {
286
- isTruthy(title) && acc.title.add(title)
287
- isTruthy(r.color) && acc.color.add(r.color)
288
- isTruthy(r.line) && acc.line.add(r.line)
289
- return acc
290
- }, {
291
- color: new Set<Color>(),
292
- line: new Set<RelationshipLineType>(),
293
- title: new Set<string>(),
294
- }),
295
- )
296
-
297
- return {
298
- tags,
299
- relations,
300
- navigateTo: navigateTo ?? null,
301
- title: only([...commonProperties.title]) ?? null,
302
- color: only([...commonProperties.color]) ?? null,
303
- line: only([...commonProperties.line]) ?? null,
304
- }
305
- }
306
- }
307
- export function computeDynamicView<M extends AnyAux>(
308
- model: LikeC4Model<M>,
309
- view: DynamicView<M>,
310
- ): ComputedDynamicView<M> {
311
- return new DynamicViewCompute(model, view).compute()
312
- }
@@ -1,47 +0,0 @@
1
- import { type LikeC4Model } from '../../model'
2
- import type { ConnectionModel } from '../../model'
3
- import type { RelationshipModel } from '../../model'
4
- import type { ModelExpression, ModelFqnExpr, ModelRelationExpr } from '../../types'
5
-
6
- import type { Ctx, Memory, Stage, StageExclude, StageInclude } from './memory'
7
-
8
- export type Where<T extends {}> = (x: T) => boolean
9
-
10
- export type Elem = Ctx['Element']
11
- export type Connection = Ctx['Connection']
12
-
13
- export type ElementWhere = Where<Elem>
14
- export type ElementWhereFilter = (elements: readonly Elem[]) => Elem[]
15
- export type ConnectionWhere = Where<Connection>
16
- export type RelationshipWhere = Where<RelationshipModel<any>>
17
- export type ConnectionWhereFilter = (connections: readonly Connection[]) => Connection[]
18
-
19
- export { Memory } from './memory'
20
-
21
- export type Connections = ReadonlyArray<ConnectionModel<any>>
22
-
23
- export interface PredicateCtx<Expr = ModelExpression<any>> {
24
- expr: Expr
25
- stage: Stage
26
- // View scope
27
- scope: Elem | null
28
- model: LikeC4Model<any>
29
- memory: Memory
30
- where: Expr extends ModelRelationExpr<any> ? RelationshipWhere
31
- : Expr extends ModelFqnExpr<any> ? ElementWhere
32
- : never
33
- filterWhere: Expr extends ModelRelationExpr<any> ? ConnectionWhereFilter
34
- : Expr extends ModelFqnExpr<any> ? ElementWhereFilter
35
- : never
36
- }
37
- export interface IncludePredicateCtx<Expr = ModelExpression<any>> extends PredicateCtx<Expr> {
38
- stage: StageInclude
39
- }
40
- export interface ExcludePredicateCtx<Expr = ModelExpression<any>> extends PredicateCtx<Expr> {
41
- stage: StageExclude
42
- }
43
-
44
- export interface PredicateExecutor<Expr = ModelExpression<any>> {
45
- include(ctx: IncludePredicateCtx<Expr>): StageInclude | undefined
46
- exclude(ctx: ExcludePredicateCtx<Expr>): StageExclude | undefined
47
- }
@@ -1,117 +0,0 @@
1
- import { allPass, anyPass, pipe, prop, reduce } from 'remeda'
2
- import type { RelationshipModel } from '../../model'
3
- import {
4
- Connection,
5
- ConnectionModel,
6
- differenceConnections,
7
- findDeepestNestedConnection,
8
- findDescendantConnections,
9
- isAnyInOut,
10
- isIncoming,
11
- isOutgoing,
12
- mergeConnections,
13
- } from '../../model'
14
- import type { AnyAux } from '../../types'
15
- import { intersection, union } from '../../utils'
16
- import { ifilter, toSet } from '../../utils/iterable'
17
-
18
- export function allRelationshipsFrom(connections: Iterable<ConnectionModel>): Set<RelationshipModel> {
19
- const relations = new Set<RelationshipModel>()
20
- for (const c of connections) {
21
- for (const rel of c.relations) {
22
- relations.add(rel)
23
- }
24
- }
25
- return relations
26
- }
27
-
28
- function isInOutToDescendant(id: string): (c: ConnectionModel) => boolean {
29
- return anyPass([
30
- allPass([
31
- Connection.isOutgoing(id),
32
- c => c.source.id !== id,
33
- ]),
34
- allPass([
35
- Connection.isIncoming(id),
36
- c => c.target.id !== id,
37
- ]),
38
- ])
39
- }
40
-
41
- export function findRedundantConnections<A extends AnyAux>(
42
- connections: Iterable<ConnectionModel<A>>,
43
- ): Array<ConnectionModel<A>> {
44
- return pipe(
45
- [...connections],
46
- mergeConnections,
47
- reduce((reducedConnections, connection, _, all) => {
48
- const descendants = findDescendantConnections(all, connection)
49
- const nestedRelations = union(
50
- ...descendants.map(prop('relations')),
51
- )
52
-
53
- let accum = intersection(connection.relations, nestedRelations)
54
-
55
- if (descendants.length > 0) {
56
- accum = union(accum, connection.directRelations)
57
- }
58
- // Check if there is any reversed connection to descendant
59
- if (findDeepestNestedConnection(all, connection.reversed(false))) {
60
- accum = union(accum, connection.directRelations)
61
- }
62
-
63
- if (accum.size < connection.relations.size) {
64
- const isSourceExpanded = all.some(isAnyInOut(connection.source))
65
- const isTargetExpanded = all.some(isAnyInOut(connection.target))
66
-
67
- // Check if source expandaded
68
- if (isSourceExpanded) {
69
- accum = union(
70
- accum,
71
- toSet(
72
- ifilter(
73
- connection.relations,
74
- isOutgoing(connection.source),
75
- ),
76
- ),
77
- )
78
- }
79
-
80
- // Check if target expandaded
81
- if (isTargetExpanded) {
82
- accum = union(
83
- accum,
84
- toSet(
85
- ifilter(
86
- connection.relations,
87
- isIncoming(connection.target),
88
- ),
89
- ),
90
- )
91
- }
92
- }
93
-
94
- if (accum.size > 0) {
95
- reducedConnections.push(connection.update(accum))
96
- }
97
-
98
- return reducedConnections
99
- }, [] as ConnectionModel<A>[]),
100
- )
101
- }
102
-
103
- /**
104
- * Remove relationships from connection model, that are already included in the connections between descendants.
105
- * In other words - if there is same connection down the hierarchy.
106
- *
107
- * @returns New connection without redundant relationships
108
- * Connection may be empty if all relationships are redundant, in this case it should be removed
109
- */
110
- export function cleanRedundantRelationships<A extends AnyAux>(
111
- connections: Iterable<ConnectionModel<A>>,
112
- ): Array<ConnectionModel<A>> {
113
- return differenceConnections(
114
- connections,
115
- findRedundantConnections(connections),
116
- )
117
- }