@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,682 +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
- RichText,
22
- } from '../types'
23
- import * as aux from '../types/_aux'
24
- import { commonAncestor, hierarchyLevel, memoizeProp, nameFromFqn, nonNullable } from '../utils'
25
- import { difference, intersection, union } from '../utils/set'
26
- import type { LikeC4DeploymentModel } from './DeploymentModel'
27
- import type { ElementModel } from './ElementModel'
28
- import type { AnyRelationshipModel, RelationshipModel, RelationshipsIterator } from './RelationModel'
29
- import type { IncomingFilter, OutgoingFilter, WithMetadata, WithTags } from './types'
30
- import type { LikeC4ViewModel } from './view/LikeC4ViewModel'
31
-
32
- export type DeploymentElementsIterator<A extends Any> = IteratorLike<DeploymentElementModel<A>>
33
- export type DeployedInstancesIterator<A extends Any> = IteratorLike<DeployedInstanceModel<A>>
34
- export type DeploymentNodesIterator<A extends Any> = IteratorLike<DeploymentNodeModel<A>>
35
-
36
- export type DeploymentElementModel<A extends Any = Any> = DeploymentNodeModel<A> | DeployedInstanceModel<A>
37
-
38
- abstract class AbstractDeploymentElementModel<A extends Any> implements WithTags<A>, WithMetadata<A> {
39
- abstract readonly id: aux.DeploymentFqn<A>
40
- abstract readonly _literalId: aux.DeploymentId<A>
41
- abstract readonly parent: DeploymentNodeModel<A> | null
42
- abstract readonly title: string
43
- abstract readonly hierarchyLevel: number
44
-
45
- abstract readonly $model: LikeC4DeploymentModel<A>
46
- abstract readonly $node: DeploymentElement<A>
47
- abstract readonly tags: aux.Tags<A>
48
-
49
- get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color' | 'size'> {
50
- return {
51
- shape: DefaultElementShape,
52
- color: DefaultThemeColor,
53
- size: DefaultShapeSize,
54
- ...this.$node.style,
55
- }
56
- }
57
-
58
- get name(): string {
59
- return nameFromFqn(this.id)
60
- }
61
-
62
- get shape(): C4ElementShape {
63
- return this.$node.style?.shape ?? DefaultElementShape
64
- }
65
-
66
- get color(): Color {
67
- return this.$node.style?.color as Color ?? DefaultThemeColor
68
- }
69
-
70
- get description(): RichTextOrEmpty {
71
- return RichText.memoize(this, this.$node.description)
72
- }
73
-
74
- get technology(): string | null {
75
- return this.$node.technology ?? null
76
- }
77
-
78
- get links(): ReadonlyArray<Link> {
79
- return this.$node.links ?? []
80
- }
81
-
82
- /**
83
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
84
- * (from closest to root)
85
- */
86
- public ancestors(): DeploymentNodesIterator<A> {
87
- return this.$model.ancestors(this)
88
- }
89
-
90
- /**
91
- * Returns the common ancestor of this element and another element.
92
- */
93
- public commonAncestor(another: DeploymentElementModel<A>): DeploymentNodeModel<A> | null {
94
- const common = commonAncestor(this.id, another.id)
95
- return common ? this.$model.node(common) : null
96
- }
97
-
98
- /**
99
- * Get all sibling (i.e. same parent)
100
- */
101
- public siblings(): DeploymentElementsIterator<A> {
102
- return this.$model.siblings(this)
103
- }
104
-
105
- /**
106
- * Check if the element is a sibling of another element
107
- */
108
- public isSibling(other: DeploymentElementModel<A>): boolean {
109
- return this.parent === other.parent
110
- }
111
-
112
- /**
113
- * Resolve siblings of the element and its ancestors
114
- * (from closest to root)
115
- */
116
- public *ascendingSiblings(): DeploymentElementsIterator<A> {
117
- yield* this.siblings()
118
- for (const ancestor of this.ancestors()) {
119
- yield* ancestor.siblings()
120
- }
121
- return
122
- }
123
-
124
- /**
125
- * Resolve siblings of the element and its ancestors
126
- * (from root to closest)
127
- */
128
- public *descendingSiblings(): DeploymentElementsIterator<A> {
129
- for (const ancestor of [...this.ancestors()].reverse()) {
130
- yield* ancestor.siblings()
131
- }
132
- yield* this.siblings()
133
- return
134
- }
135
-
136
- public incoming(filter: IncomingFilter = 'all'): IteratorLike<DeploymentRelationModel<A>> {
137
- return this.$model.incoming(this, filter)
138
- }
139
- public outgoing(filter: OutgoingFilter = 'all'): IteratorLike<DeploymentRelationModel<A>> {
140
- return this.$model.outgoing(this, filter)
141
- }
142
-
143
- public *incomers(filter: IncomingFilter = 'all'): IteratorLike<DeploymentRelationEndpoint<A>> {
144
- const unique = new Set<aux.DeploymentFqn<A>>()
145
- for (const r of this.incoming(filter)) {
146
- if (unique.has(r.source.id)) {
147
- continue
148
- }
149
- unique.add(r.source.id)
150
- yield r.source
151
- }
152
- return
153
- }
154
- public *outgoers(filter: OutgoingFilter = 'all'): IteratorLike<DeploymentRelationEndpoint<A>> {
155
- const unique = new Set<aux.DeploymentFqn<A>>()
156
- for (const r of this.outgoing(filter)) {
157
- if (unique.has(r.target.id)) {
158
- continue
159
- }
160
- unique.add(r.target.id)
161
- yield r.target
162
- }
163
- return
164
- }
165
-
166
- /**
167
- * Iterate over all views that include this deployment element.
168
- */
169
- public *views(): IteratorLike<LikeC4ViewModel.DeploymentView<A>> {
170
- for (const view of this.$model.views()) {
171
- if (view._type !== 'deployment') {
172
- continue
173
- }
174
- if (view.includesDeployment(this.id)) {
175
- yield view
176
- }
177
- }
178
- }
179
-
180
- // type guard
181
- public isDeploymentNode(): this is DeploymentNodeModel<A> {
182
- return false
183
- }
184
- // type guard
185
- public isInstance(): this is DeployedInstanceModel<A> {
186
- return false
187
- }
188
-
189
- public abstract outgoingModelRelationships(): RelationshipsIterator<A>
190
- public abstract incomingModelRelationships(): RelationshipsIterator<A>
191
-
192
- public get allOutgoing(): RelationshipsAccum<A> {
193
- return memoizeProp(this, Symbol.for('allOutgoing'), () =>
194
- RelationshipsAccum.from(
195
- new Set(this.outgoingModelRelationships()),
196
- new Set(this.outgoing()),
197
- ))
198
- }
199
-
200
- public get allIncoming(): RelationshipsAccum<A> {
201
- return memoizeProp(this, Symbol.for('allIncoming'), () =>
202
- RelationshipsAccum.from(
203
- new Set(this.incomingModelRelationships()),
204
- new Set(this.incoming()),
205
- ))
206
- }
207
-
208
- public hasMetadata(): boolean {
209
- return !!this.$node.metadata && !isEmpty(this.$node.metadata)
210
- }
211
-
212
- public getMetadata(): aux.Metadata<A>
213
- public getMetadata(field: aux.MetadataKey<A>): string | undefined
214
- public getMetadata(field?: aux.MetadataKey<A>) {
215
- if (field) {
216
- return this.$node.metadata?.[field]
217
- }
218
- return this.$node.metadata ?? {}
219
- }
220
-
221
- /**
222
- * Checks if the deployment element has the given tag.
223
- */
224
- public isTagged(tag: aux.LooseTag<A>): boolean {
225
- return this.tags.includes(tag as aux.Tag<A>)
226
- }
227
- }
228
-
229
- export class DeploymentNodeModel<A extends Any = Any> extends AbstractDeploymentElementModel<A> {
230
- override id: aux.DeploymentFqn<A>
231
- override _literalId: aux.DeploymentId<A>
232
- override title: string
233
- override hierarchyLevel: number
234
-
235
- constructor(
236
- public readonly $model: LikeC4DeploymentModel<A>,
237
- public readonly $node: DeploymentNode<A>,
238
- ) {
239
- super()
240
- this.id = $node.id
241
- this._literalId = $node.id
242
- this.title = $node.title
243
- this.hierarchyLevel = hierarchyLevel($node.id)
244
- }
245
-
246
- get parent(): DeploymentNodeModel<A> | null {
247
- return this.$model.parent(this)
248
- }
249
-
250
- get kind(): aux.DeploymentKind<A> {
251
- return this.$node.kind
252
- }
253
-
254
- override get tags(): aux.Tags<A> {
255
- return memoizeProp(this, Symbol.for('tags'), () => {
256
- return unique([
257
- ...(this.$node.tags ?? []),
258
- ...(this.$model.$model.specification.deployments[this.kind]?.tags ?? []),
259
- ] as aux.Tags<A>)
260
- })
261
- }
262
-
263
- public children(): ReadonlySet<DeploymentElementModel<A>> {
264
- return this.$model.children(this)
265
- }
266
-
267
- public descendants(sort: 'asc' | 'desc' = 'desc'): DeploymentElementsIterator<A> {
268
- return this.$model.descendants(this, sort)
269
- }
270
-
271
- public override isDeploymentNode(): this is DeploymentNodeModel<A> {
272
- return true
273
- }
274
-
275
- /**
276
- * Iterate over all instances nested in this deployment node.
277
- */
278
- public *instances(): DeployedInstancesIterator<A> {
279
- for (const nested of this.descendants('desc')) {
280
- if (nested.isInstance()) {
281
- yield nested
282
- }
283
- }
284
- return
285
- }
286
-
287
- /**
288
- * Returns deployed instance inside this deployment node
289
- * if only there are no more instances
290
- */
291
- public onlyOneInstance(): DeployedInstanceModel<A> | null {
292
- const children = this.children()
293
- if (children.size !== 1) {
294
- return null
295
- }
296
- const child = only([...children])
297
- return child?.isInstance() ? child : null
298
- }
299
-
300
- /**
301
- * Cached result of relationships from instances
302
- */
303
- private _relationshipsFromInstances: {
304
- outgoing: ReadonlySet<RelationshipModel<A>>
305
- incoming: ReadonlySet<RelationshipModel<A>>
306
- } | null = null
307
-
308
- private relationshipsFromInstances() {
309
- if (this._relationshipsFromInstances) {
310
- return this._relationshipsFromInstances
311
- }
312
- const {
313
- outgoing,
314
- incoming,
315
- } = (this._relationshipsFromInstances = {
316
- outgoing: new Set<RelationshipModel<A>>(),
317
- incoming: new Set<RelationshipModel<A>>(),
318
- })
319
- for (const instance of this.instances()) {
320
- for (const r of instance.element.outgoing()) {
321
- outgoing.add(r)
322
- }
323
- for (const r of instance.element.incoming()) {
324
- incoming.add(r)
325
- }
326
- }
327
- return this._relationshipsFromInstances
328
- }
329
-
330
- /**
331
- * We return only relationships that are not already present in nested instances
332
- */
333
- public override outgoingModelRelationships(): RelationshipsIterator<A> {
334
- return this.relationshipsFromInstances().outgoing.values()
335
- }
336
-
337
- /**
338
- * We return only relationships that are not already present in nested instances
339
- */
340
- public override incomingModelRelationships(): RelationshipsIterator<A> {
341
- return this.relationshipsFromInstances().incoming.values()
342
- }
343
-
344
- /**
345
- * Returns an iterator of relationships between nested instances
346
- */
347
- public internalModelRelationships(): ReadonlySet<RelationshipModel<A>> {
348
- const {
349
- outgoing,
350
- incoming,
351
- } = this.relationshipsFromInstances()
352
- return intersection(incoming, outgoing)
353
- }
354
- }
355
-
356
- export class DeployedInstanceModel<A extends Any = Any> extends AbstractDeploymentElementModel<A> {
357
- override readonly id: aux.DeploymentFqn<A>
358
- override readonly _literalId: aux.DeploymentId<A>
359
- override readonly title: string
360
- override readonly hierarchyLevel: number
361
-
362
- constructor(
363
- public readonly $model: LikeC4DeploymentModel<A>,
364
- public readonly $instance: DeployedInstance<A>,
365
- public readonly element: ElementModel<A>,
366
- ) {
367
- super()
368
- this.id = $instance.id
369
- this._literalId = $instance.id
370
- this.title = $instance.title ?? element.title
371
- this.hierarchyLevel = hierarchyLevel($instance.id)
372
- }
373
-
374
- get $node(): DeployedInstance<A> {
375
- return this.$instance
376
- }
377
-
378
- get parent(): DeploymentNodeModel<A> {
379
- return nonNullable(this.$model.parent(this), `Parent of ${this.id} not found`)
380
- }
381
-
382
- override get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color' | 'size'> {
383
- const { icon, style } = this.element.$element
384
- return {
385
- shape: this.element.shape,
386
- color: this.element.color,
387
- size: DefaultShapeSize,
388
- ...icon && { icon },
389
- ...style,
390
- ...this.$instance.style,
391
- }
392
- }
393
-
394
- override get shape(): C4ElementShape {
395
- return this.$instance.style?.shape ?? this.element.shape
396
- }
397
-
398
- override get color(): Color {
399
- return this.$instance.style?.color as Color ?? this.element.color
400
- }
401
-
402
- override get tags(): aux.Tags<A> {
403
- return memoizeProp(this, Symbol.for('tags'), () => {
404
- return unique([
405
- ...(this.$instance.tags ?? []),
406
- ...this.element.tags,
407
- ] as aux.Tags<A>)
408
- })
409
- }
410
-
411
- get kind(): aux.ElementKind<A> {
412
- return this.element.kind
413
- }
414
-
415
- override get description(): RichTextOrEmpty {
416
- return RichText.memoize(this, this.$instance.description ?? this.element.$element.description)
417
- }
418
-
419
- override get technology(): string | null {
420
- return this.$instance.technology ?? this.element.technology ?? null
421
- }
422
-
423
- override get links(): ReadonlyArray<Link> {
424
- return this.$instance.links ?? this.element.links
425
- }
426
-
427
- public override isInstance(): this is DeployedInstanceModel<A> {
428
- return true
429
- }
430
-
431
- public override outgoingModelRelationships(): RelationshipsIterator<A> {
432
- return this.element.outgoing()
433
- }
434
- public override incomingModelRelationships(): RelationshipsIterator<A> {
435
- return this.element.incoming()
436
- }
437
-
438
- /**
439
- * Iterate over all views that include this instance.
440
- * (Some views may include the parent deployment node instead of the instance.)
441
- */
442
- public override *views(): IteratorLike<LikeC4ViewModel.DeploymentView<A>> {
443
- for (const view of this.$model.views()) {
444
- if (view._type !== 'deployment') {
445
- continue
446
- }
447
- if (view.includesDeployment(this.id)) {
448
- yield view
449
- continue
450
- }
451
- // check if the view includes parent referecing this element
452
- if (
453
- view.includesDeployment(this.parent.id)
454
- && this.parent.onlyOneInstance()
455
- ) {
456
- yield view
457
- }
458
- }
459
- }
460
- }
461
-
462
- export class NestedElementOfDeployedInstanceModel<A extends Any = Any> {
463
- constructor(
464
- public readonly instance: DeployedInstanceModel<A>,
465
- public readonly element: ElementModel<A>,
466
- ) {
467
- }
468
-
469
- get id(): aux.DeploymentFqn<A> {
470
- return this.instance.id
471
- }
472
-
473
- get _literalId(): aux.DeploymentId<A> {
474
- return this.instance.id
475
- }
476
-
477
- get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color'> {
478
- const { icon, style } = this.element.$element
479
- return {
480
- shape: this.element.shape,
481
- color: this.element.color,
482
- ...icon && { icon },
483
- ...style,
484
- }
485
- }
486
-
487
- get shape(): C4ElementShape {
488
- return this.element.shape
489
- }
490
-
491
- get color(): Color {
492
- return this.element.color
493
- }
494
-
495
- get title(): string {
496
- return this.element.title
497
- }
498
-
499
- get description(): RichTextOrEmpty {
500
- return this.element.description
501
- }
502
-
503
- get technology(): string | null {
504
- return this.element.technology
505
- }
506
-
507
- public isDeploymentNode(): this is DeploymentNodeModel<A> {
508
- return false
509
- }
510
- public isInstance(): this is DeployedInstanceModel<A> {
511
- return false
512
- }
513
- }
514
-
515
- export type DeploymentRelationEndpoint<A extends Any = Any> =
516
- | DeploymentElementModel<A>
517
- | NestedElementOfDeployedInstanceModel<A>
518
-
519
- export class DeploymentRelationModel<A extends Any = Any> implements AnyRelationshipModel<A> {
520
- public boundary: DeploymentNodeModel<A> | null
521
- public source: DeploymentRelationEndpoint<A>
522
- public target: DeploymentRelationEndpoint<A>
523
-
524
- constructor(
525
- public readonly $model: LikeC4DeploymentModel<A>,
526
- public readonly $relationship: DeploymentRelationship<A>,
527
- ) {
528
- this.source = $model.deploymentRef($relationship.source)
529
- this.target = $model.deploymentRef($relationship.target)
530
- const parent = commonAncestor(this.source.id, this.target.id)
531
- this.boundary = parent ? this.$model.node(parent) : null
532
- }
533
- get id(): scalar.RelationId {
534
- return this.$relationship.id
535
- }
536
-
537
- get expression(): string {
538
- return `${this.source.id} -> ${this.target.id}`
539
- }
540
-
541
- get title(): string | null {
542
- if (!isTruthy(this.$relationship.title)) {
543
- return null
544
- }
545
- return this.$relationship.title
546
- }
547
-
548
- get technology(): string | null {
549
- return this.$relationship.technology ?? null
550
- }
551
-
552
- get description(): RichTextOrEmpty {
553
- return RichText.memoize(this, this.$relationship.description)
554
- }
555
-
556
- get tags(): aux.Tags<A> {
557
- return this.$relationship.tags ?? []
558
- }
559
-
560
- get kind(): aux.RelationKind<A> | null {
561
- return this.$relationship.kind ?? null
562
- }
563
-
564
- get navigateTo(): LikeC4ViewModel<A> | null {
565
- return this.$relationship.navigateTo ? this.$model.$model.view(this.$relationship.navigateTo) : null
566
- }
567
-
568
- get links(): ReadonlyArray<Link> {
569
- return this.$relationship.links ?? []
570
- }
571
-
572
- get color(): Color {
573
- return this.$relationship.color ?? DefaultThemeColor
574
- }
575
-
576
- get line(): RelationshipLineType {
577
- return this.$relationship.line ?? DefaultLineStyle
578
- }
579
-
580
- public *views(): IteratorLike<LikeC4ViewModel.DeploymentView<A>> {
581
- for (const view of this.$model.views()) {
582
- if (view.includesRelation(this.id)) {
583
- yield view
584
- }
585
- }
586
- return
587
- }
588
-
589
- public isDeploymentRelation(): this is DeploymentRelationModel<A> {
590
- return true
591
- }
592
-
593
- public isModelRelation(): this is RelationshipModel<A> {
594
- return false
595
- }
596
-
597
- public hasMetadata(): boolean {
598
- return !!this.$relationship.metadata && !isEmpty(this.$relationship.metadata)
599
- }
600
-
601
- public getMetadata(): aux.Metadata<A>
602
- public getMetadata(field: aux.MetadataKey<A>): string | undefined
603
- public getMetadata(field?: aux.MetadataKey<A>) {
604
- if (field) {
605
- return this.$relationship.metadata?.[field]
606
- }
607
- return this.$relationship.metadata ?? {}
608
- }
609
-
610
- /**
611
- * Checks if the relationship has the given tag.
612
- */
613
- public isTagged(tag: aux.LooseTag<A>): boolean {
614
- return this.tags.includes(tag as aux.Tag<A>)
615
- }
616
- }
617
-
618
- export class RelationshipsAccum<A extends Any = Any> {
619
- static empty<A extends Any>(): RelationshipsAccum<A> {
620
- return new RelationshipsAccum()
621
- }
622
- static from<A extends Any>(
623
- model: Iterable<RelationshipModel<A>> | undefined,
624
- deployment?: Iterable<DeploymentRelationModel<A>>,
625
- ): RelationshipsAccum<A> {
626
- return new RelationshipsAccum(
627
- new Set(model),
628
- new Set(deployment),
629
- )
630
- }
631
- /**
632
- * @param model relationships from logical model
633
- * @param deployment relationships from deployment model
634
- */
635
- constructor(
636
- public readonly model: ReadonlySet<RelationshipModel<A>> = new Set(),
637
- public readonly deployment: ReadonlySet<DeploymentRelationModel<A>> = new Set(),
638
- ) {
639
- }
640
-
641
- get isEmpty(): boolean {
642
- return this.model.size === 0 && this.deployment.size === 0
643
- }
644
-
645
- get nonEmpty(): boolean {
646
- return this.model.size > 0 || this.deployment.size > 0
647
- }
648
-
649
- get size(): number {
650
- return this.model.size + this.deployment.size
651
- }
652
-
653
- /**
654
- * Returns new Accum containing all the elements which are both in this and otherAccum
655
- */
656
- public intersect(otherAccum: RelationshipsAccum<A>): RelationshipsAccum<A> {
657
- return RelationshipsAccum.from(
658
- intersection(this.model, otherAccum.model),
659
- intersection(this.deployment, otherAccum.deployment),
660
- )
661
- }
662
-
663
- /**
664
- * Returns new Accum containing all the elements which are both in this and otherAccum
665
- */
666
- public difference(otherAccum: RelationshipsAccum<A>): RelationshipsAccum<A> {
667
- return RelationshipsAccum.from(
668
- difference(this.model, otherAccum.model),
669
- difference(this.deployment, otherAccum.deployment),
670
- )
671
- }
672
-
673
- /**
674
- * Returns new Accum containing all the elements from both
675
- */
676
- public union(otherAccum: RelationshipsAccum<A>): RelationshipsAccum<A> {
677
- return RelationshipsAccum.from(
678
- union(this.model, otherAccum.model),
679
- union(this.deployment, otherAccum.deployment),
680
- )
681
- }
682
- }