@likec4/core 1.41.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 (255) 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 +13 -11
  5. package/dist/builder/index.mjs +111 -91
  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 +11 -11
  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.Ae86Y3tB.mjs → core.01VTr9qu.mjs} +8 -26
  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.DA5vzwZ9.mjs → core.BIqHjQiH.mjs} +56 -42
  25. package/dist/shared/core.BKlholso.mjs +3 -0
  26. package/dist/shared/core.BR4zXDH-.mjs +13 -0
  27. package/dist/shared/{core.CXy1NLUG.mjs → core.BYNkXQ8A.mjs} +21 -12
  28. package/dist/shared/{core.BuoXfSMj.mjs → core.BbE4y-yl.mjs} +1 -1
  29. package/dist/shared/core.BoYfZOBm.mjs +3 -0
  30. package/dist/shared/core.BsSXS-_R.mjs +7 -0
  31. package/dist/shared/{core.DJp8fgok.mjs → core.BzTakU3I.mjs} +14 -10
  32. package/dist/shared/{core.4u1dVmfX.mjs → core.C2TiyjI6.mjs} +2 -2
  33. package/dist/shared/{core.DLpidoWc.mjs → core.C3JowhaZ.mjs} +3 -3
  34. package/dist/shared/{core.CNGyqkJh.mjs → core.C4x8aaWa.mjs} +3 -1
  35. package/dist/shared/{core.BB6zA-UU.mjs → core.C8YY6Uub.mjs} +38 -9
  36. package/dist/shared/{core.Asc11Mjy.mjs → core.C8sl5Y8Z.mjs} +122 -58
  37. package/dist/shared/{core.BvMRMo7Z.mjs → core.CNgZvKb8.mjs} +3 -5198
  38. package/dist/shared/{core.CUG6vpyL.d.mts → core.CQngdcuj.d.mts} +85 -4
  39. package/dist/shared/{core.Be1n9a0i.mjs → core.C_Ni6yHl.mjs} +5 -4
  40. package/dist/shared/core.CbT8JVYL.mjs +5 -0
  41. package/dist/shared/core.CqAJJpK_.mjs +3 -0
  42. package/dist/shared/{core.BXsxn-hf.d.mts → core.D0PjZzIS.d.mts} +27 -15
  43. package/dist/shared/{core.DgesAwC8.d.mts → core.D5fzJWbF.d.mts} +2 -2
  44. package/dist/shared/{core.hfOE3RfK.d.mts → core.DACpKp35.d.mts} +5 -5
  45. package/dist/shared/core.DFi2dOTl.mjs +39548 -0
  46. package/dist/shared/{core.xSQO0XYD.d.mts → core.DIol3syK.d.mts} +2 -2
  47. package/dist/shared/{core.DlG1xWt2.mjs → core.DMMOWQqc.mjs} +3 -2
  48. package/dist/shared/core.DNbUPnve.mjs +3990 -0
  49. package/dist/shared/{core.CCD1ID81.mjs → core.DRJma0Ol.mjs} +4 -3
  50. package/dist/shared/{core.DgttqsJc.mjs → core.DRhg-gVU.mjs} +9 -9
  51. package/dist/shared/core.DSO_rTC2.mjs +5322 -0
  52. package/dist/shared/{core.FUPplpae.d.mts → core.D_vkffV4.d.mts} +4 -2
  53. package/dist/shared/core.DdMJk7nx.d.mts +476 -0
  54. package/dist/shared/{core.BhpgpOep.d.mts → core.Dgs6-nuz.d.mts} +2 -2
  55. package/dist/shared/{core.Be4Jy9Qx.mjs → core.FZ305VYd.mjs} +2 -2
  56. package/dist/shared/core.OHD4KXm9.mjs +5 -0
  57. package/dist/shared/{core.GTgsmXS_.mjs → core.QJD_fcrc.mjs} +2 -2
  58. package/dist/shared/core.RfnaEmgA.mjs +7 -0
  59. package/dist/shared/core.fHR_8Tnq.d.mts +450 -0
  60. package/dist/shared/{core.D0EgVMQK.mjs → core.lRvxPoao.mjs} +14 -12
  61. package/dist/shared/{core.CaT0SUUK.mjs → core.rCeaAqgW.mjs} +1 -84
  62. package/dist/shared/{core.zxTBF_PD.d.mts → core.s9uwOt60.d.mts} +4 -4
  63. package/dist/shared/core.yna0OdV5.d.mts +98 -0
  64. package/dist/styles/index.d.mts +106 -0
  65. package/dist/styles/index.mjs +1 -0
  66. package/dist/types/_aux.d.mts +2 -2
  67. package/dist/types/expression-model.d.mts +3 -4
  68. package/dist/types/expression.d.mts +3 -4
  69. package/dist/types/fqnRef.d.mts +2 -2
  70. package/dist/types/fqnRef.mjs +3 -3
  71. package/dist/types/index.d.mts +8 -8
  72. package/dist/types/index.mjs +150 -5
  73. package/dist/types/scalar.mjs +3 -2
  74. package/dist/utils/graphology/index.d.mts +1864 -0
  75. package/dist/utils/graphology/index.mjs +1 -0
  76. package/dist/utils/index.d.mts +11 -6
  77. package/dist/utils/index.mjs +21 -37
  78. package/dist/utils/iterable/index.d.mts +1 -1
  79. package/dist/utils/iterable/index.mjs +45 -7
  80. package/model/package.json +4 -0
  81. package/package.json +42 -24
  82. package/styles/package.json +4 -0
  83. package/types/package.json +4 -0
  84. package/utils/graphology/package.json +4 -0
  85. package/utils/package.json +4 -0
  86. package/dist/shared/core.6_Vp2iiN.mjs +0 -172
  87. package/dist/shared/core.CUw_2J9j.mjs +0 -47
  88. package/dist/shared/core.CzdwsPmY.d.mts +0 -69
  89. package/dist/shared/core.D-ZGWDDt.d.mts +0 -831
  90. package/dist/shared/core.DoM6aM9N.mjs +0 -7
  91. package/dist/shared/core.ILwny7BV.mjs +0 -38
  92. package/dist/theme/index.d.mts +0 -11
  93. package/dist/theme/index.mjs +0 -232
  94. package/src/builder/Builder.deployment.ts +0 -224
  95. package/src/builder/Builder.deploymentModel.ts +0 -449
  96. package/src/builder/Builder.element.ts +0 -241
  97. package/src/builder/Builder.model.ts +0 -494
  98. package/src/builder/Builder.ts +0 -946
  99. package/src/builder/Builder.view-common.ts +0 -273
  100. package/src/builder/Builder.view-deployment.ts +0 -135
  101. package/src/builder/Builder.view-element.ts +0 -202
  102. package/src/builder/Builder.views.ts +0 -399
  103. package/src/builder/Builder.with.ts +0 -156
  104. package/src/builder/_types.ts +0 -324
  105. package/src/builder/index.ts +0 -11
  106. package/src/compute-view/compute-view.ts +0 -80
  107. package/src/compute-view/deployment-view/_types.ts +0 -38
  108. package/src/compute-view/deployment-view/clean-connections.ts +0 -236
  109. package/src/compute-view/deployment-view/compute.ts +0 -94
  110. package/src/compute-view/deployment-view/memory/index.ts +0 -9
  111. package/src/compute-view/deployment-view/memory/memory.ts +0 -96
  112. package/src/compute-view/deployment-view/predicates/deploymentRefs-where.ts +0 -18
  113. package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +0 -154
  114. package/src/compute-view/deployment-view/predicates/index.ts +0 -8
  115. package/src/compute-view/deployment-view/predicates/relation-direct.ts +0 -243
  116. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +0 -70
  117. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +0 -101
  118. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +0 -95
  119. package/src/compute-view/deployment-view/predicates/relation-where.ts +0 -18
  120. package/src/compute-view/deployment-view/predicates/utils.ts +0 -282
  121. package/src/compute-view/deployment-view/predicates/wildcard.ts +0 -41
  122. package/src/compute-view/deployment-view/stages/stage-exclude.ts +0 -5
  123. package/src/compute-view/deployment-view/stages/stage-final.ts +0 -245
  124. package/src/compute-view/deployment-view/stages/stage-include.ts +0 -95
  125. package/src/compute-view/deployment-view/utils.ts +0 -297
  126. package/src/compute-view/dynamic-view/compute.ts +0 -312
  127. package/src/compute-view/element-view/_types.ts +0 -47
  128. package/src/compute-view/element-view/clean-connections.ts +0 -117
  129. package/src/compute-view/element-view/compute.ts +0 -324
  130. package/src/compute-view/element-view/memory/NodeGroup.ts +0 -31
  131. package/src/compute-view/element-view/memory/index.ts +0 -10
  132. package/src/compute-view/element-view/memory/memory.ts +0 -178
  133. package/src/compute-view/element-view/memory/stage-exclude.ts +0 -59
  134. package/src/compute-view/element-view/memory/stage-final.ts +0 -129
  135. package/src/compute-view/element-view/memory/stage-include.ts +0 -130
  136. package/src/compute-view/element-view/predicates/_utils.ts +0 -91
  137. package/src/compute-view/element-view/predicates/element-expand.ts +0 -29
  138. package/src/compute-view/element-view/predicates/element-kind-tag.ts +0 -27
  139. package/src/compute-view/element-view/predicates/element-ref.ts +0 -24
  140. package/src/compute-view/element-view/predicates/relation-direct.ts +0 -321
  141. package/src/compute-view/element-view/predicates/relation-in-out.ts +0 -64
  142. package/src/compute-view/element-view/predicates/relation-in.ts +0 -115
  143. package/src/compute-view/element-view/predicates/relation-out.ts +0 -119
  144. package/src/compute-view/element-view/predicates/wildcard.ts +0 -88
  145. package/src/compute-view/element-view/utils.ts +0 -65
  146. package/src/compute-view/index.ts +0 -4
  147. package/src/compute-view/memory/AbstractMemory.ts +0 -45
  148. package/src/compute-view/memory/AbstractStageExclude.ts +0 -215
  149. package/src/compute-view/memory/AbstractStageInclude.ts +0 -200
  150. package/src/compute-view/memory/_types.ts +0 -148
  151. package/src/compute-view/memory/index.ts +0 -5
  152. package/src/compute-view/memory/ops.ts +0 -43
  153. package/src/compute-view/relationships-view/_types.ts +0 -16
  154. package/src/compute-view/relationships-view/compute.ts +0 -159
  155. package/src/compute-view/relationships-view/index.ts +0 -3
  156. package/src/compute-view/relationships-view/layout.ts +0 -358
  157. package/src/compute-view/relationships-view/utils.ts +0 -73
  158. package/src/compute-view/utils/ancestorsOfNode.ts +0 -19
  159. package/src/compute-view/utils/applyCustomElementProperties.ts +0 -107
  160. package/src/compute-view/utils/applyCustomRelationProperties.ts +0 -58
  161. package/src/compute-view/utils/applyViewRuleStyles.ts +0 -73
  162. package/src/compute-view/utils/buildComputedNodes.ts +0 -166
  163. package/src/compute-view/utils/buildElementNotations.ts +0 -64
  164. package/src/compute-view/utils/elementExpressionToPredicate.ts +0 -50
  165. package/src/compute-view/utils/link-nodes-with-edges.ts +0 -56
  166. package/src/compute-view/utils/merge-props-from-relationships.ts +0 -161
  167. package/src/compute-view/utils/relationExpressionToPredicates.ts +0 -55
  168. package/src/compute-view/utils/resolve-extended-views.ts +0 -85
  169. package/src/compute-view/utils/resolve-global-rules.ts +0 -88
  170. package/src/compute-view/utils/topological-sort.ts +0 -256
  171. package/src/compute-view/utils/view-hash.ts +0 -45
  172. package/src/compute-view/utils/with-readable-edges.ts +0 -40
  173. package/src/index.ts +0 -32
  174. package/src/model/DeploymentElementModel.ts +0 -712
  175. package/src/model/DeploymentModel.ts +0 -393
  176. package/src/model/ElementModel.ts +0 -316
  177. package/src/model/LikeC4Model.ts +0 -882
  178. package/src/model/RelationModel.ts +0 -152
  179. package/src/model/connection/Connection.ts +0 -72
  180. package/src/model/connection/deployment/DeploymentConnectionModel.ts +0 -185
  181. package/src/model/connection/deployment/find.ts +0 -120
  182. package/src/model/connection/deployment/index.ts +0 -8
  183. package/src/model/connection/index.ts +0 -22
  184. package/src/model/connection/model/ConnectionModel.ts +0 -158
  185. package/src/model/connection/model/find.ts +0 -117
  186. package/src/model/connection/model/index.ts +0 -8
  187. package/src/model/connection/ops.ts +0 -276
  188. package/src/model/guards.ts +0 -77
  189. package/src/model/index.ts +0 -72
  190. package/src/model/types.ts +0 -67
  191. package/src/model/utils.ts +0 -66
  192. package/src/model/view/EdgeModel.ts +0 -121
  193. package/src/model/view/LikeC4ViewModel.ts +0 -361
  194. package/src/model/view/LikeC4ViewsFolder.ts +0 -151
  195. package/src/model/view/NodeModel.ts +0 -247
  196. package/src/theme/element.ts +0 -61
  197. package/src/theme/index.ts +0 -127
  198. package/src/theme/relationships.ts +0 -54
  199. package/src/types/RichText.ts +0 -205
  200. package/src/types/_aux.ts +0 -317
  201. package/src/types/_common.ts +0 -102
  202. package/src/types/const.ts +0 -34
  203. package/src/types/expression-model.ts +0 -294
  204. package/src/types/expression.ts +0 -313
  205. package/src/types/fqnRef.ts +0 -91
  206. package/src/types/geometry.ts +0 -159
  207. package/src/types/global.ts +0 -21
  208. package/src/types/index.ts +0 -44
  209. package/src/types/model-data.ts +0 -77
  210. package/src/types/model-deployment.ts +0 -78
  211. package/src/types/model-dump.ts +0 -79
  212. package/src/types/model-logical.ts +0 -126
  213. package/src/types/model-spec.ts +0 -88
  214. package/src/types/operators.ts +0 -156
  215. package/src/types/project.ts +0 -14
  216. package/src/types/scalar.ts +0 -162
  217. package/src/types/styles.ts +0 -122
  218. package/src/types/view-changes.ts +0 -32
  219. package/src/types/view-common.ts +0 -157
  220. package/src/types/view-computed.ts +0 -126
  221. package/src/types/view-layouted.ts +0 -94
  222. package/src/types/view-parsed.deployment.ts +0 -39
  223. package/src/types/view-parsed.dynamic.ts +0 -89
  224. package/src/types/view-parsed.element.ts +0 -65
  225. package/src/types/view.ts +0 -113
  226. package/src/utils/common-head.ts +0 -22
  227. package/src/utils/compare-natural.ts +0 -60
  228. package/src/utils/const.ts +0 -1
  229. package/src/utils/fqn.ts +0 -302
  230. package/src/utils/getOrCreate.ts +0 -8
  231. package/src/utils/guards.ts +0 -9
  232. package/src/utils/index.ts +0 -68
  233. package/src/utils/invariant.ts +0 -29
  234. package/src/utils/iterable/_types.ts +0 -5
  235. package/src/utils/iterable/filter.ts +0 -55
  236. package/src/utils/iterable/find.ts +0 -38
  237. package/src/utils/iterable/first.ts +0 -48
  238. package/src/utils/iterable/flat.ts +0 -17
  239. package/src/utils/iterable/head.ts +0 -22
  240. package/src/utils/iterable/index.ts +0 -15
  241. package/src/utils/iterable/map.ts +0 -40
  242. package/src/utils/iterable/reduce.ts +0 -24
  243. package/src/utils/iterable/some.ts +0 -36
  244. package/src/utils/iterable/to.ts +0 -19
  245. package/src/utils/iterable/unique.ts +0 -23
  246. package/src/utils/markdown/index.ts +0 -2
  247. package/src/utils/markdown/to-html.ts +0 -32
  248. package/src/utils/markdown/to-text.ts +0 -14
  249. package/src/utils/memoize-prop.ts +0 -30
  250. package/src/utils/mnemonist.ts +0 -9
  251. package/src/utils/object-hash.ts +0 -14
  252. package/src/utils/promises.ts +0 -24
  253. package/src/utils/relations.ts +0 -36
  254. package/src/utils/set.ts +0 -83
  255. package/src/utils/string-hash.ts +0 -16
@@ -1,712 +0,0 @@
1
- import { isEmpty, isTruthy, only, unique } from 'remeda'
2
- import type { SetRequired } from 'type-fest'
3
- import {
4
- type Any,
5
- type Color,
6
- type DeployedInstance,
7
- type DeploymentElement,
8
- type DeploymentElementStyle,
9
- type DeploymentNode,
10
- type DeploymentRelationship,
11
- type ElementShape as C4ElementShape,
12
- type IteratorLike,
13
- type Link,
14
- type RelationshipLineType,
15
- type RichTextOrEmpty,
16
- type scalar,
17
- DefaultElementShape,
18
- DefaultLineStyle,
19
- DefaultShapeSize,
20
- DefaultThemeColor,
21
- preferDescription,
22
- preferSummary,
23
- RichText,
24
- } from '../types'
25
- import * as aux from '../types/_aux'
26
- import { commonAncestor, hierarchyLevel, memoizeProp, nameFromFqn, nonNullable } from '../utils'
27
- import { difference, intersection, union } from '../utils/set'
28
- import type { LikeC4DeploymentModel } from './DeploymentModel'
29
- import type { ElementModel } from './ElementModel'
30
- import type { AnyRelationshipModel, RelationshipModel, RelationshipsIterator } from './RelationModel'
31
- import type { IncomingFilter, OutgoingFilter, WithMetadata, WithTags } from './types'
32
- import type { LikeC4ViewModel } from './view/LikeC4ViewModel'
33
-
34
- export type DeploymentElementsIterator<A extends Any> = IteratorLike<DeploymentElementModel<A>>
35
- export type DeployedInstancesIterator<A extends Any> = IteratorLike<DeployedInstanceModel<A>>
36
- export type DeploymentNodesIterator<A extends Any> = IteratorLike<DeploymentNodeModel<A>>
37
-
38
- export type DeploymentElementModel<A extends Any = Any> = DeploymentNodeModel<A> | DeployedInstanceModel<A>
39
-
40
- abstract class AbstractDeploymentElementModel<A extends Any> implements WithTags<A>, WithMetadata<A> {
41
- abstract readonly id: aux.DeploymentFqn<A>
42
- abstract readonly _literalId: aux.DeploymentId<A>
43
- abstract readonly parent: DeploymentNodeModel<A> | null
44
- abstract readonly title: string
45
- abstract readonly hierarchyLevel: number
46
-
47
- abstract readonly $model: LikeC4DeploymentModel<A>
48
- abstract readonly $node: DeploymentElement<A>
49
- abstract readonly tags: aux.Tags<A>
50
-
51
- get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color' | 'size'> {
52
- return {
53
- shape: DefaultElementShape,
54
- color: DefaultThemeColor,
55
- size: DefaultShapeSize,
56
- ...this.$node.style,
57
- }
58
- }
59
-
60
- get name(): string {
61
- return nameFromFqn(this.id)
62
- }
63
-
64
- get shape(): C4ElementShape {
65
- return this.$node.style?.shape ?? DefaultElementShape
66
- }
67
-
68
- get color(): Color {
69
- return this.$node.style?.color as Color ?? DefaultThemeColor
70
- }
71
-
72
- /**
73
- * Short description of the element.
74
- * Falls back to description if summary is not provided.
75
- */
76
- get summary(): RichTextOrEmpty {
77
- return RichText.memoize(this, 'summary', preferSummary(this.$node))
78
- }
79
-
80
- /**
81
- * Long description of the element.
82
- * Falls back to summary if description is not provided.
83
- */
84
- get description(): RichTextOrEmpty {
85
- return RichText.memoize(this, 'description', preferDescription(this.$node))
86
- }
87
-
88
- get technology(): string | null {
89
- return this.$node.technology ?? null
90
- }
91
-
92
- get links(): ReadonlyArray<Link> {
93
- return this.$node.links ?? []
94
- }
95
-
96
- /**
97
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
98
- * (from closest to root)
99
- */
100
- public ancestors(): DeploymentNodesIterator<A> {
101
- return this.$model.ancestors(this)
102
- }
103
-
104
- /**
105
- * Returns the common ancestor of this element and another element.
106
- */
107
- public commonAncestor(another: DeploymentElementModel<A>): DeploymentNodeModel<A> | null {
108
- const common = commonAncestor(this.id, another.id)
109
- return common ? this.$model.node(common) : null
110
- }
111
-
112
- /**
113
- * Get all sibling (i.e. same parent)
114
- */
115
- public siblings(): DeploymentElementsIterator<A> {
116
- return this.$model.siblings(this)
117
- }
118
-
119
- /**
120
- * Check if the element is a sibling of another element
121
- */
122
- public isSibling(other: DeploymentElementModel<A>): boolean {
123
- return this.parent === other.parent
124
- }
125
-
126
- /**
127
- * Resolve siblings of the element and its ancestors
128
- * (from closest to root)
129
- */
130
- public *ascendingSiblings(): DeploymentElementsIterator<A> {
131
- yield* this.siblings()
132
- for (const ancestor of this.ancestors()) {
133
- yield* ancestor.siblings()
134
- }
135
- return
136
- }
137
-
138
- /**
139
- * Resolve siblings of the element and its ancestors
140
- * (from root to closest)
141
- */
142
- public *descendingSiblings(): DeploymentElementsIterator<A> {
143
- for (const ancestor of [...this.ancestors()].reverse()) {
144
- yield* ancestor.siblings()
145
- }
146
- yield* this.siblings()
147
- return
148
- }
149
-
150
- public incoming(filter: IncomingFilter = 'all'): IteratorLike<DeploymentRelationModel<A>> {
151
- return this.$model.incoming(this, filter)
152
- }
153
- public outgoing(filter: OutgoingFilter = 'all'): IteratorLike<DeploymentRelationModel<A>> {
154
- return this.$model.outgoing(this, filter)
155
- }
156
-
157
- public *incomers(filter: IncomingFilter = 'all'): IteratorLike<DeploymentRelationEndpoint<A>> {
158
- const unique = new Set<aux.DeploymentFqn<A>>()
159
- for (const r of this.incoming(filter)) {
160
- if (unique.has(r.source.id)) {
161
- continue
162
- }
163
- unique.add(r.source.id)
164
- yield r.source
165
- }
166
- return
167
- }
168
- public *outgoers(filter: OutgoingFilter = 'all'): IteratorLike<DeploymentRelationEndpoint<A>> {
169
- const unique = new Set<aux.DeploymentFqn<A>>()
170
- for (const r of this.outgoing(filter)) {
171
- if (unique.has(r.target.id)) {
172
- continue
173
- }
174
- unique.add(r.target.id)
175
- yield r.target
176
- }
177
- return
178
- }
179
-
180
- /**
181
- * Iterate over all views that include this deployment element.
182
- */
183
- public *views(): IteratorLike<LikeC4ViewModel.DeploymentView<A>> {
184
- for (const view of this.$model.views()) {
185
- if (view._type !== 'deployment') {
186
- continue
187
- }
188
- if (view.includesDeployment(this.id)) {
189
- yield view
190
- }
191
- }
192
- }
193
-
194
- // type guard
195
- public isDeploymentNode(): this is DeploymentNodeModel<A> {
196
- return false
197
- }
198
- // type guard
199
- public isInstance(): this is DeployedInstanceModel<A> {
200
- return false
201
- }
202
-
203
- public abstract outgoingModelRelationships(): RelationshipsIterator<A>
204
- public abstract incomingModelRelationships(): RelationshipsIterator<A>
205
-
206
- public get allOutgoing(): RelationshipsAccum<A> {
207
- return memoizeProp(this, Symbol.for('allOutgoing'), () =>
208
- RelationshipsAccum.from(
209
- new Set(this.outgoingModelRelationships()),
210
- new Set(this.outgoing()),
211
- ))
212
- }
213
-
214
- public get allIncoming(): RelationshipsAccum<A> {
215
- return memoizeProp(this, Symbol.for('allIncoming'), () =>
216
- RelationshipsAccum.from(
217
- new Set(this.incomingModelRelationships()),
218
- new Set(this.incoming()),
219
- ))
220
- }
221
-
222
- public hasMetadata(): boolean {
223
- return !!this.$node.metadata && !isEmpty(this.$node.metadata)
224
- }
225
-
226
- public getMetadata(): aux.Metadata<A>
227
- public getMetadata(field: aux.MetadataKey<A>): string | undefined
228
- public getMetadata(field?: aux.MetadataKey<A>) {
229
- if (field) {
230
- return this.$node.metadata?.[field]
231
- }
232
- return this.$node.metadata ?? {}
233
- }
234
-
235
- /**
236
- * Checks if the deployment element has the given tag.
237
- */
238
- public isTagged(tag: aux.LooseTag<A>): boolean {
239
- return this.tags.includes(tag as aux.Tag<A>)
240
- }
241
- }
242
-
243
- export class DeploymentNodeModel<A extends Any = Any> extends AbstractDeploymentElementModel<A> {
244
- override id: aux.DeploymentFqn<A>
245
- override _literalId: aux.DeploymentId<A>
246
- override title: string
247
- override hierarchyLevel: number
248
-
249
- constructor(
250
- public readonly $model: LikeC4DeploymentModel<A>,
251
- public readonly $node: DeploymentNode<A>,
252
- ) {
253
- super()
254
- this.id = $node.id
255
- this._literalId = $node.id
256
- this.title = $node.title
257
- this.hierarchyLevel = hierarchyLevel($node.id)
258
- }
259
-
260
- get parent(): DeploymentNodeModel<A> | null {
261
- return this.$model.parent(this)
262
- }
263
-
264
- get kind(): aux.DeploymentKind<A> {
265
- return this.$node.kind
266
- }
267
-
268
- override get tags(): aux.Tags<A> {
269
- return memoizeProp(this, Symbol.for('tags'), () => {
270
- return unique([
271
- ...(this.$node.tags ?? []),
272
- ...(this.$model.$model.specification.deployments[this.kind]?.tags ?? []),
273
- ] as aux.Tags<A>)
274
- })
275
- }
276
-
277
- public children(): ReadonlySet<DeploymentElementModel<A>> {
278
- return this.$model.children(this)
279
- }
280
-
281
- public descendants(sort: 'asc' | 'desc' = 'desc'): DeploymentElementsIterator<A> {
282
- return this.$model.descendants(this, sort)
283
- }
284
-
285
- public override isDeploymentNode(): this is DeploymentNodeModel<A> {
286
- return true
287
- }
288
-
289
- /**
290
- * Iterate over all instances nested in this deployment node.
291
- */
292
- public *instances(): DeployedInstancesIterator<A> {
293
- for (const nested of this.descendants('desc')) {
294
- if (nested.isInstance()) {
295
- yield nested
296
- }
297
- }
298
- return
299
- }
300
-
301
- /**
302
- * Returns deployed instance inside this deployment node
303
- * if only there are no more instances
304
- */
305
- public onlyOneInstance(): DeployedInstanceModel<A> | null {
306
- const children = this.children()
307
- if (children.size !== 1) {
308
- return null
309
- }
310
- const child = only([...children])
311
- return child?.isInstance() ? child : null
312
- }
313
-
314
- /**
315
- * Cached result of relationships from instances
316
- */
317
- private _relationshipsFromInstances: {
318
- outgoing: ReadonlySet<RelationshipModel<A>>
319
- incoming: ReadonlySet<RelationshipModel<A>>
320
- } | null = null
321
-
322
- private relationshipsFromInstances() {
323
- if (this._relationshipsFromInstances) {
324
- return this._relationshipsFromInstances
325
- }
326
- const {
327
- outgoing,
328
- incoming,
329
- } = (this._relationshipsFromInstances = {
330
- outgoing: new Set<RelationshipModel<A>>(),
331
- incoming: new Set<RelationshipModel<A>>(),
332
- })
333
- for (const instance of this.instances()) {
334
- for (const r of instance.element.outgoing()) {
335
- outgoing.add(r)
336
- }
337
- for (const r of instance.element.incoming()) {
338
- incoming.add(r)
339
- }
340
- }
341
- return this._relationshipsFromInstances
342
- }
343
-
344
- /**
345
- * We return only relationships that are not already present in nested instances
346
- */
347
- public override outgoingModelRelationships(): RelationshipsIterator<A> {
348
- return this.relationshipsFromInstances().outgoing.values()
349
- }
350
-
351
- /**
352
- * We return only relationships that are not already present in nested instances
353
- */
354
- public override incomingModelRelationships(): RelationshipsIterator<A> {
355
- return this.relationshipsFromInstances().incoming.values()
356
- }
357
-
358
- /**
359
- * Returns an iterator of relationships between nested instances
360
- */
361
- public internalModelRelationships(): ReadonlySet<RelationshipModel<A>> {
362
- const {
363
- outgoing,
364
- incoming,
365
- } = this.relationshipsFromInstances()
366
- return intersection(incoming, outgoing)
367
- }
368
- }
369
-
370
- export class DeployedInstanceModel<A extends Any = Any> extends AbstractDeploymentElementModel<A> {
371
- override readonly id: aux.DeploymentFqn<A>
372
- override readonly _literalId: aux.DeploymentId<A>
373
- override readonly title: string
374
- override readonly hierarchyLevel: number
375
-
376
- constructor(
377
- public readonly $model: LikeC4DeploymentModel<A>,
378
- public readonly $instance: DeployedInstance<A>,
379
- public readonly element: ElementModel<A>,
380
- ) {
381
- super()
382
- this.id = $instance.id
383
- this._literalId = $instance.id
384
- this.title = $instance.title ?? element.title
385
- this.hierarchyLevel = hierarchyLevel($instance.id)
386
- }
387
-
388
- get $node(): DeployedInstance<A> {
389
- return this.$instance
390
- }
391
-
392
- get parent(): DeploymentNodeModel<A> {
393
- return nonNullable(this.$model.parent(this), `Parent of ${this.id} not found`)
394
- }
395
-
396
- override get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color' | 'size'> {
397
- const { icon, style } = this.element.$element
398
- return {
399
- shape: this.element.shape,
400
- color: this.element.color,
401
- size: DefaultShapeSize,
402
- ...icon && { icon },
403
- ...style,
404
- ...this.$instance.style,
405
- }
406
- }
407
-
408
- override get shape(): C4ElementShape {
409
- return this.$instance.style?.shape ?? this.element.shape
410
- }
411
-
412
- override get color(): Color {
413
- return this.$instance.style?.color as Color ?? this.element.color
414
- }
415
-
416
- override get tags(): aux.Tags<A> {
417
- return memoizeProp(this, Symbol.for('tags'), () => {
418
- return unique([
419
- ...(this.$instance.tags ?? []),
420
- ...this.element.tags,
421
- ] as aux.Tags<A>)
422
- })
423
- }
424
-
425
- get kind(): aux.ElementKind<A> {
426
- return this.element.kind
427
- }
428
-
429
- override get summary(): RichTextOrEmpty {
430
- return RichText.memoize(
431
- this,
432
- 'summary',
433
- preferSummary(this.$instance) ?? preferSummary(this.element.$element),
434
- )
435
- }
436
-
437
- override get description(): RichTextOrEmpty {
438
- return RichText.memoize(
439
- this,
440
- 'description',
441
- preferDescription(this.$instance) ?? preferDescription(this.element.$element),
442
- )
443
- }
444
-
445
- override get technology(): string | null {
446
- return this.$instance.technology ?? this.element.technology ?? null
447
- }
448
-
449
- override get links(): ReadonlyArray<Link> {
450
- return this.$instance.links ?? this.element.links
451
- }
452
-
453
- public override isInstance(): this is DeployedInstanceModel<A> {
454
- return true
455
- }
456
-
457
- public override outgoingModelRelationships(): RelationshipsIterator<A> {
458
- return this.element.outgoing()
459
- }
460
- public override incomingModelRelationships(): RelationshipsIterator<A> {
461
- return this.element.incoming()
462
- }
463
-
464
- /**
465
- * Iterate over all views that include this instance.
466
- * (Some views may include the parent deployment node instead of the instance.)
467
- */
468
- public override *views(): IteratorLike<LikeC4ViewModel.DeploymentView<A>> {
469
- for (const view of this.$model.views()) {
470
- if (view._type !== 'deployment') {
471
- continue
472
- }
473
- if (view.includesDeployment(this.id)) {
474
- yield view
475
- continue
476
- }
477
- // check if the view includes parent referecing this element
478
- if (
479
- view.includesDeployment(this.parent.id)
480
- && this.parent.onlyOneInstance()
481
- ) {
482
- yield view
483
- }
484
- }
485
- }
486
- }
487
-
488
- export class NestedElementOfDeployedInstanceModel<A extends Any = Any> {
489
- constructor(
490
- public readonly instance: DeployedInstanceModel<A>,
491
- public readonly element: ElementModel<A>,
492
- ) {
493
- }
494
-
495
- get id(): aux.DeploymentFqn<A> {
496
- return this.instance.id
497
- }
498
-
499
- get _literalId(): aux.DeploymentId<A> {
500
- return this.instance.id
501
- }
502
-
503
- get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color'> {
504
- const { icon, style } = this.element.$element
505
- return {
506
- shape: this.element.shape,
507
- color: this.element.color,
508
- ...icon && { icon },
509
- ...style,
510
- }
511
- }
512
-
513
- get shape(): C4ElementShape {
514
- return this.element.shape
515
- }
516
-
517
- get color(): Color {
518
- return this.element.color
519
- }
520
-
521
- get title(): string {
522
- return this.element.title
523
- }
524
-
525
- get summary(): RichTextOrEmpty {
526
- return this.element.summary
527
- }
528
-
529
- get description(): RichTextOrEmpty {
530
- return this.element.description
531
- }
532
-
533
- get technology(): string | null {
534
- return this.element.technology
535
- }
536
-
537
- public isDeploymentNode(): this is DeploymentNodeModel<A> {
538
- return false
539
- }
540
- public isInstance(): this is DeployedInstanceModel<A> {
541
- return false
542
- }
543
- }
544
-
545
- export type DeploymentRelationEndpoint<A extends Any = Any> =
546
- | DeploymentElementModel<A>
547
- | NestedElementOfDeployedInstanceModel<A>
548
-
549
- export class DeploymentRelationModel<A extends Any = Any> implements AnyRelationshipModel<A> {
550
- public boundary: DeploymentNodeModel<A> | null
551
- public source: DeploymentRelationEndpoint<A>
552
- public target: DeploymentRelationEndpoint<A>
553
-
554
- constructor(
555
- public readonly $model: LikeC4DeploymentModel<A>,
556
- public readonly $relationship: DeploymentRelationship<A>,
557
- ) {
558
- this.source = $model.deploymentRef($relationship.source)
559
- this.target = $model.deploymentRef($relationship.target)
560
- const parent = commonAncestor(this.source.id, this.target.id)
561
- this.boundary = parent ? this.$model.node(parent) : null
562
- }
563
- get id(): scalar.RelationId {
564
- return this.$relationship.id
565
- }
566
-
567
- get expression(): string {
568
- return `${this.source.id} -> ${this.target.id}`
569
- }
570
-
571
- get title(): string | null {
572
- if (!isTruthy(this.$relationship.title)) {
573
- return null
574
- }
575
- return this.$relationship.title
576
- }
577
-
578
- get technology(): string | null {
579
- return this.$relationship.technology ?? null
580
- }
581
-
582
- get description(): RichTextOrEmpty {
583
- return RichText.memoize(this, 'description', this.$relationship.description)
584
- }
585
-
586
- get tags(): aux.Tags<A> {
587
- return this.$relationship.tags ?? []
588
- }
589
-
590
- get kind(): aux.RelationKind<A> | null {
591
- return this.$relationship.kind ?? null
592
- }
593
-
594
- get navigateTo(): LikeC4ViewModel<A> | null {
595
- return this.$relationship.navigateTo ? this.$model.$model.view(this.$relationship.navigateTo) : null
596
- }
597
-
598
- get links(): ReadonlyArray<Link> {
599
- return this.$relationship.links ?? []
600
- }
601
-
602
- get color(): Color {
603
- return this.$relationship.color ?? DefaultThemeColor
604
- }
605
-
606
- get line(): RelationshipLineType {
607
- return this.$relationship.line ?? DefaultLineStyle
608
- }
609
-
610
- public *views(): IteratorLike<LikeC4ViewModel.DeploymentView<A>> {
611
- for (const view of this.$model.views()) {
612
- if (view.includesRelation(this.id)) {
613
- yield view
614
- }
615
- }
616
- return
617
- }
618
-
619
- public isDeploymentRelation(): this is DeploymentRelationModel<A> {
620
- return true
621
- }
622
-
623
- public isModelRelation(): this is RelationshipModel<A> {
624
- return false
625
- }
626
-
627
- public hasMetadata(): boolean {
628
- return !!this.$relationship.metadata && !isEmpty(this.$relationship.metadata)
629
- }
630
-
631
- public getMetadata(): aux.Metadata<A>
632
- public getMetadata(field: aux.MetadataKey<A>): string | undefined
633
- public getMetadata(field?: aux.MetadataKey<A>) {
634
- if (field) {
635
- return this.$relationship.metadata?.[field]
636
- }
637
- return this.$relationship.metadata ?? {}
638
- }
639
-
640
- /**
641
- * Checks if the relationship has the given tag.
642
- */
643
- public isTagged(tag: aux.LooseTag<A>): boolean {
644
- return this.tags.includes(tag as aux.Tag<A>)
645
- }
646
- }
647
-
648
- export class RelationshipsAccum<A extends Any = Any> {
649
- static empty<A extends Any>(): RelationshipsAccum<A> {
650
- return new RelationshipsAccum()
651
- }
652
- static from<A extends Any>(
653
- model: Iterable<RelationshipModel<A>> | undefined,
654
- deployment?: Iterable<DeploymentRelationModel<A>>,
655
- ): RelationshipsAccum<A> {
656
- return new RelationshipsAccum(
657
- new Set(model),
658
- new Set(deployment),
659
- )
660
- }
661
- /**
662
- * @param model relationships from logical model
663
- * @param deployment relationships from deployment model
664
- */
665
- constructor(
666
- public readonly model: ReadonlySet<RelationshipModel<A>> = new Set(),
667
- public readonly deployment: ReadonlySet<DeploymentRelationModel<A>> = new Set(),
668
- ) {
669
- }
670
-
671
- get isEmpty(): boolean {
672
- return this.model.size === 0 && this.deployment.size === 0
673
- }
674
-
675
- get nonEmpty(): boolean {
676
- return this.model.size > 0 || this.deployment.size > 0
677
- }
678
-
679
- get size(): number {
680
- return this.model.size + this.deployment.size
681
- }
682
-
683
- /**
684
- * Returns new Accum containing all the elements which are both in this and otherAccum
685
- */
686
- public intersect(otherAccum: RelationshipsAccum<A>): RelationshipsAccum<A> {
687
- return RelationshipsAccum.from(
688
- intersection(this.model, otherAccum.model),
689
- intersection(this.deployment, otherAccum.deployment),
690
- )
691
- }
692
-
693
- /**
694
- * Returns new Accum containing all the elements which are both in this and otherAccum
695
- */
696
- public difference(otherAccum: RelationshipsAccum<A>): RelationshipsAccum<A> {
697
- return RelationshipsAccum.from(
698
- difference(this.model, otherAccum.model),
699
- difference(this.deployment, otherAccum.deployment),
700
- )
701
- }
702
-
703
- /**
704
- * Returns new Accum containing all the elements from both
705
- */
706
- public union(otherAccum: RelationshipsAccum<A>): RelationshipsAccum<A> {
707
- return RelationshipsAccum.from(
708
- union(this.model, otherAccum.model),
709
- union(this.deployment, otherAccum.deployment),
710
- )
711
- }
712
- }