@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,158 +0,0 @@
1
- import { isNot } from 'remeda'
2
- import type { AnyAux, aux, Unknown } from '../../../types'
3
- import { invariant } from '../../../utils'
4
- import { customInspectSymbol } from '../../../utils/const'
5
- import { ifilter, isome } from '../../../utils/iterable'
6
- import { difference, equals, intersection, union } from '../../../utils/set'
7
- import { stringHash } from '../../../utils/string-hash'
8
- import type { ElementModel } from '../../ElementModel'
9
- import type { RelationshipModel } from '../../RelationModel'
10
- import type { Connection } from '../Connection'
11
- import { hasSameSourceTarget } from '../ops'
12
- import { findConnection } from './find'
13
-
14
- /**
15
- * Connection refers to any relationships between two elements,
16
- * both direct and implicit ones (between their nested elements).
17
- *
18
- * Merges relationships together to an single edge on the diagram.
19
- */
20
- export class ConnectionModel<A extends AnyAux = Unknown> implements Connection<ElementModel<A>, aux.EdgeId> {
21
- public readonly id: aux.EdgeId
22
-
23
- constructor(
24
- public readonly source: ElementModel<A>,
25
- public readonly target: ElementModel<A>,
26
- public readonly relations: ReadonlySet<RelationshipModel<A>> = new Set(),
27
- ) {
28
- this.id = stringHash(`model:${source.id}:${target.id}`) as aux.EdgeId
29
- }
30
-
31
- private _boundary: ElementModel<A> | null | undefined
32
- /**
33
- * Common ancestor of the source and target elements.
34
- * Represents the boundary of the connection.
35
- */
36
- get boundary(): ElementModel<A> | null {
37
- return this._boundary ??= this.source.commonAncestor(this.target)
38
- }
39
-
40
- /**
41
- * Human readable expression of the connection
42
- * Mostly used for testing and debugging
43
- */
44
- get expression(): string {
45
- return `${this.source.id} -> ${this.target.id}`
46
- }
47
-
48
- /**
49
- * Returns true if only includes relations between the source and target elements.
50
- */
51
- get isDirect(): boolean {
52
- return this.nonEmpty() && !this.isImplicit
53
- }
54
-
55
- /**
56
- * Returns true if includes relations between nested elements of the source and target elements.
57
- */
58
- get isImplicit(): boolean {
59
- return this.nonEmpty() && isome(this.relations, isNot(hasSameSourceTarget(this)))
60
- }
61
-
62
- get directRelations(): ReadonlySet<RelationshipModel<A>> {
63
- return new Set(ifilter(this.relations, hasSameSourceTarget(this)))
64
- }
65
-
66
- nonEmpty(): boolean {
67
- return this.relations.size > 0
68
- }
69
-
70
- mergeWith(other: ConnectionModel<A>) {
71
- invariant(this.source.id === other.source.id, 'Cannot merge connections with different sources')
72
- invariant(this.target.id === other.target.id, 'Cannot merge connections with different targets')
73
- return new ConnectionModel(
74
- this.source,
75
- this.target,
76
- union(this.relations, other.relations),
77
- )
78
- }
79
-
80
- difference(other: ConnectionModel<A>) {
81
- return new ConnectionModel(
82
- this.source,
83
- this.target,
84
- difference(this.relations, other.relations),
85
- )
86
- }
87
-
88
- intersect(other: ConnectionModel<A>) {
89
- invariant(other instanceof ConnectionModel, 'Cannot intersect connection with different type')
90
- return new ConnectionModel(
91
- this.source,
92
- this.target,
93
- intersection(this.relations, other.relations),
94
- )
95
- }
96
-
97
- equals(other: Connection): boolean {
98
- invariant(other instanceof ConnectionModel, 'Cannot merge connection with different type')
99
- const _other = other as ConnectionModel<A>
100
- return this.id === _other.id
101
- && this.source.id === _other.source.id
102
- && this.target.id === _other.target.id
103
- && equals(this.relations, _other.relations)
104
- }
105
-
106
- /**
107
- * Returns a new instance with the updated relations.
108
- *
109
- * @param relations - A readonly set of `RelationshipModel` instances representing the new relations.
110
- * @returns A new `ConnectionModel` instance with the updated relations.
111
- */
112
- update(relations: ReadonlySet<RelationshipModel<A>>): ConnectionModel<A> {
113
- return new ConnectionModel(
114
- this.source,
115
- this.target,
116
- relations,
117
- )
118
- }
119
-
120
- [customInspectSymbol](
121
- // @ts-ignore
122
- depth,
123
- // @ts-ignore
124
- inspectOptions,
125
- // @ts-ignore
126
- inspect,
127
- ) {
128
- const asString = this.toString()
129
-
130
- // Trick so that node displays the name of the constructor
131
- Object.defineProperty(asString, 'constructor', {
132
- value: ConnectionModel,
133
- enumerable: false,
134
- })
135
-
136
- return asString
137
- }
138
-
139
- toString() {
140
- return [
141
- this.expression,
142
- this.relations.size ? ' relations:' : ' relations: [ ]',
143
- ...[...this.relations].map(c => ' ' + c.expression),
144
- ].join('\n')
145
- }
146
-
147
- /**
148
- * Creates a new connection with reversed direction (target becomes source and vice versa)
149
- * @param search - When true, attempts to find an existing connection between the reversed nodes
150
- */
151
- reversed(search = false): ConnectionModel<A> {
152
- if (!search) {
153
- return new ConnectionModel(this.target, this.source)
154
- }
155
- const [found] = findConnection(this.target, this.source, 'directed')
156
- return found ?? new ConnectionModel(this.target, this.source, new Set())
157
- }
158
- }
@@ -1,117 +0,0 @@
1
- import type { AnyAux } from '../../../types'
2
- import { isSameHierarchy } from '../../../utils/fqn'
3
- import { intersection } from '../../../utils/set'
4
- import type { ElementModel } from '../../ElementModel'
5
- import { ConnectionModel } from './ConnectionModel'
6
-
7
- /**
8
- * Resolve connection from source to target
9
- *
10
- * @param direction - if 'both', also returns connection from target to source
11
- * @default `directed`
12
- */
13
- export function findConnection<A extends AnyAux>(
14
- source: ElementModel<A>,
15
- target: ElementModel<A>,
16
- direction: 'directed' | 'both' = 'directed',
17
- ):
18
- | [ConnectionModel<A>, ConnectionModel<A>]
19
- | [ConnectionModel<A>]
20
- | []
21
- {
22
- if (source === target) {
23
- return []
24
- }
25
- if (isSameHierarchy(source, target)) {
26
- return []
27
- }
28
-
29
- const directedIntersection = intersection(source.allOutgoing, target.allIncoming)
30
-
31
- const directed = directedIntersection.size > 0
32
- ? new ConnectionModel(
33
- source,
34
- target,
35
- directedIntersection,
36
- )
37
- : null
38
-
39
- if (direction === 'directed') {
40
- return directed ? [directed] : []
41
- }
42
-
43
- const reverseIntersection = intersection(source.allIncoming, target.allOutgoing)
44
- const reverse = reverseIntersection.size > 0
45
- ? new ConnectionModel(
46
- target,
47
- source,
48
- reverseIntersection,
49
- )
50
- : null
51
-
52
- if (directed && reverse) {
53
- return [directed, reverse]
54
- }
55
- if (directed) {
56
- return [directed]
57
- }
58
- if (reverse) {
59
- return [reverse]
60
- }
61
-
62
- return []
63
- }
64
-
65
- /**
66
- * Resolve all connections between element and others
67
- * @param direction - if 'directed', only look for outgoing connections from the element to others
68
- * @default `both`
69
- */
70
- export function findConnectionsBetween<M extends AnyAux>(
71
- element: ElementModel<M>,
72
- others: Iterable<ElementModel<M>>,
73
- direction: 'directed' | 'both' = 'both',
74
- ): readonly ConnectionModel<M>[] {
75
- if (element.allIncoming.size === 0 && element.allOutgoing.size === 0) {
76
- return []
77
- }
78
-
79
- // We separate resolved connection,
80
- // because we want return outgoing first
81
- const outgoing = [] as ConnectionModel<M>[]
82
- const incoming = [] as ConnectionModel<M>[]
83
- for (const _other of others) {
84
- if (element === _other) {
85
- continue
86
- }
87
- for (const found of findConnection(element, _other, direction)) {
88
- if (found.source === element) {
89
- outgoing.push(found)
90
- } else {
91
- incoming.push(found)
92
- }
93
- }
94
- }
95
- return [
96
- ...outgoing,
97
- ...incoming,
98
- ]
99
- }
100
-
101
- /**
102
- * Resolve all connections within a given set of elements
103
- */
104
- export function findConnectionsWithin<M extends AnyAux>(
105
- elements: Iterable<ElementModel<M>>,
106
- ): readonly ConnectionModel<M>[] {
107
- return [...elements].reduce((acc, el, index, array) => {
108
- // skip for last element
109
- if (index === array.length - 1) {
110
- return acc
111
- }
112
- acc.push(
113
- ...findConnectionsBetween(el, array.slice(index + 1), 'both'),
114
- )
115
- return acc
116
- }, [] as ConnectionModel<M>[])
117
- }
@@ -1,8 +0,0 @@
1
- export { Connection } from '../Connection'
2
- export { ConnectionModel } from './ConnectionModel'
3
-
4
- export {
5
- findConnection,
6
- findConnectionsBetween,
7
- findConnectionsWithin,
8
- } from './find'
@@ -1,276 +0,0 @@
1
- import { map, pipe } from 'remeda'
2
- import type { IterableContainer, ReorderedArray } from '../../types'
3
- import { isString } from '../../utils'
4
- import {
5
- isAncestor,
6
- isDescendantOf,
7
- sortNaturalByFqn,
8
- } from '../../utils/fqn'
9
- import type { Connection } from './Connection'
10
-
11
- /**
12
- * Check if connection is nested inside another connection
13
- * (i.e. between descendants)
14
- */
15
- export function isNestedConnection<T extends { id: string }>(
16
- parent: WithSourceTarget<NoInfer<T>>,
17
- ): (nested: WithSourceTarget<T>) => boolean
18
- export function isNestedConnection<T extends { id: string }>(
19
- nested: WithSourceTarget<T>,
20
- parent: WithSourceTarget<T>,
21
- ): boolean
22
- export function isNestedConnection<T extends { id: string }>(
23
- nested: WithSourceTarget<T>,
24
- parent?: WithSourceTarget<T>,
25
- ) {
26
- if (!parent) {
27
- const p = nested
28
- return (n: WithSourceTarget<T>) => isNestedConnection(n, p)
29
- }
30
- const isSameSource = nested.source === parent.source
31
- const isSameTarget = nested.target === parent.target
32
- if (isSameSource && isSameTarget) {
33
- return false
34
- }
35
- const isSourceNested = isAncestor(parent.source.id, nested.source.id)
36
- const isTargetNested = isAncestor(parent.target.id, nested.target.id)
37
- return (
38
- (isSourceNested && isTargetNested)
39
- || (isSameSource && isTargetNested)
40
- || (isSameTarget && isSourceNested)
41
- )
42
- }
43
-
44
- type ConnectionElemId = Connection<{ readonly id: string }, any>
45
-
46
- export function findDeepestNestedConnection<C extends ConnectionElemId>(
47
- connections: ReadonlyArray<C>,
48
- connection: C,
49
- ): C | null {
50
- let deepest = connection
51
- for (const c of connections) {
52
- if (isNestedConnection(c, deepest)) {
53
- deepest = c
54
- }
55
- }
56
- return deepest !== connection ? deepest : null
57
- }
58
-
59
- export function sortDeepestFirst<C extends ConnectionElemId>(
60
- connections: ReadonlyArray<C>,
61
- ): C[] {
62
- const sorted = [] as C[]
63
- const unsorted = connections.slice()
64
- let next
65
- while (next = unsorted.shift()) {
66
- let deepest
67
- while (deepest = findDeepestNestedConnection(unsorted, next)) {
68
- const index = unsorted.indexOf(deepest)
69
- sorted.push(unsorted.splice(index, 1)[0]!)
70
- }
71
- sorted.push(next)
72
- }
73
- return sorted
74
- }
75
-
76
- /**
77
- * To make {@link sortConnectionsByBoundaryHierarchy} work correctly we add '.' to boundary
78
- * Othwerwise connection without boundary will be considered same level as connection with top-level boundary
79
- */
80
- export function boundaryHierarchy<C extends WithBoundary>(conn: C): string {
81
- return conn.boundary?.id ? `.${conn.boundary.id}` : ''
82
- }
83
-
84
- type WithBoundary = {
85
- id: string
86
- boundary: null | { id: string }
87
- }
88
- export function sortConnectionsByBoundaryHierarchy(
89
- sort?: 'asc' | 'desc',
90
- ): <T extends WithBoundary, A extends IterableContainer<T>>(array: A) => ReorderedArray<A>
91
- export function sortConnectionsByBoundaryHierarchy<T extends WithBoundary, A extends IterableContainer<T>>(
92
- array: A,
93
- sort?: 'asc' | 'desc',
94
- ): ReorderedArray<A>
95
- export function sortConnectionsByBoundaryHierarchy<T extends WithBoundary, A extends IterableContainer<T>>(
96
- connections?: A | 'asc' | 'desc',
97
- sort?: 'asc' | 'desc',
98
- ) {
99
- if (!connections || isString(connections)) {
100
- const dir = connections ?? 'asc'
101
- return (arr: A) => _sortByBoundary(arr, dir)
102
- }
103
- return _sortByBoundary(connections, sort ?? 'asc')
104
- }
105
-
106
- function _sortByBoundary<C extends WithBoundary>(
107
- connections: ReadonlyArray<C>,
108
- order: 'asc' | 'desc',
109
- ): C[] {
110
- return pipe(
111
- connections,
112
- map(conn => ({
113
- id: boundaryHierarchy(conn),
114
- conn: conn,
115
- })),
116
- sortNaturalByFqn(order),
117
- map(p => p.conn),
118
- )
119
- }
120
-
121
- /**
122
- * Find connections that includes given connection (i.e between it's ancestors)
123
- */
124
- export function findAscendingConnections<C extends ConnectionElemId>(
125
- connections: ReadonlyArray<C>,
126
- connection: C,
127
- ): Array<C> {
128
- return connections.filter(c => isNestedConnection(connection, c))
129
- }
130
-
131
- /**
132
- * Find connections that given connection includes (i.e between it's descendants)
133
- */
134
- export function findDescendantConnections<C extends ConnectionElemId>(
135
- connections: ReadonlyArray<C>,
136
- connection: C,
137
- ): Array<C> {
138
- return connections.filter(isNestedConnection(connection))
139
- }
140
-
141
- export function mergeConnections<C extends IterableContainer<Connection<any, any>>>(
142
- connections: C,
143
- ): Array<C[number]> {
144
- const map = new Map<C[number]['id'], C[number]>()
145
- for (const conn of connections) {
146
- const existing = map.get(conn.id)
147
- if (existing) {
148
- map.set(conn.id, conn.mergeWith(existing))
149
- } else {
150
- map.set(conn.id, conn)
151
- }
152
- }
153
- return [...map.values()]
154
- }
155
-
156
- /**
157
- * Excludes the values existing in `other` array.
158
- * The output maintains the same order as the input.
159
- */
160
- export function differenceConnections<C extends Connection<any, any>>(
161
- source: Iterable<C>,
162
- exclude: Iterable<C>,
163
- ): C[] {
164
- const minus = new Map([...exclude].map(c => [c.id, c]))
165
- return [...source].reduce((acc, c) => {
166
- const other = minus.get(c.id)
167
- if (!other) {
168
- acc.push(c)
169
- return acc
170
- }
171
- const updated = c.difference(other) as C
172
- if (updated.nonEmpty()) {
173
- acc.push(updated)
174
- }
175
- return acc
176
- }, [] as C[])
177
- }
178
-
179
- type WithSourceTarget<T = unknown> = {
180
- source: T
181
- target: T
182
- }
183
-
184
- export function hasSameSourceTarget<T>(a: WithSourceTarget<NoInfer<T>>): (b: WithSourceTarget<T>) => boolean
185
- export function hasSameSourceTarget<T>(a: WithSourceTarget<T>, b: WithSourceTarget<T>): boolean
186
- export function hasSameSourceTarget(a: WithSourceTarget, b?: WithSourceTarget) {
187
- if (b) {
188
- return a.source === b.source && a.target === b.target
189
- }
190
- return (b: WithSourceTarget) => a.source === b.source && a.target === b.target
191
- }
192
-
193
- export function hasSameSource<T>(a: WithSourceTarget<NoInfer<T>>): (b: WithSourceTarget<T>) => boolean
194
- export function hasSameSource<T>(a: WithSourceTarget<T>, b: WithSourceTarget<T>): boolean
195
- export function hasSameSource(a: WithSourceTarget, b?: WithSourceTarget) {
196
- if (b) {
197
- return a.source === b.source
198
- }
199
- return (b: WithSourceTarget) => a.source === b.source
200
- }
201
-
202
- export function hasSameTarget<T>(a: WithSourceTarget<NoInfer<T>>): (b: WithSourceTarget<T>) => boolean
203
- export function hasSameTarget<T>(a: WithSourceTarget<T>, b: WithSourceTarget<T>): boolean
204
- export function hasSameTarget(a: WithSourceTarget, b?: WithSourceTarget) {
205
- if (b) {
206
- return a.target === b.target
207
- }
208
- return (b: WithSourceTarget) => a.target === b.target
209
- }
210
-
211
- type WithId<T> = {
212
- id: T
213
- }
214
- export function isOutgoing<T extends string>(source: WithId<NoInfer<T>>): (a: WithSourceTarget<WithId<T>>) => boolean
215
- export function isOutgoing<T extends string>(a: WithSourceTarget<WithId<T>>, source: WithId<T>): boolean
216
- export function isOutgoing<T extends string>(a: WithSourceTarget<WithId<T>> | WithId<T>, source?: WithId<T>) {
217
- if (!source) {
218
- const _source = a as WithId<T>
219
- return (b: WithSourceTarget<WithId<T>>) => isOutgoing(b, _source)
220
- }
221
- const at = a as WithSourceTarget<WithId<T>>
222
- return isDescendantOf(at.source, source) && !isDescendantOf(at.target, source)
223
- }
224
-
225
- export function isIncoming<T extends string>(target: WithId<NoInfer<T>>): (a: WithSourceTarget<WithId<T>>) => boolean
226
- export function isIncoming<T extends string>(a: WithSourceTarget<WithId<T>>, target: WithId<T>): boolean
227
- export function isIncoming<T extends string>(a: WithSourceTarget<WithId<T>> | WithId<T>, target?: WithId<T>) {
228
- if (!target) {
229
- const _target = a as WithId<T>
230
- return (b: WithSourceTarget<WithId<T>>) => isIncoming(b, _target)
231
- }
232
- const at = a as WithSourceTarget<WithId<T>>
233
- return isDescendantOf(at.target, target) && !isDescendantOf(at.source, target)
234
- }
235
-
236
- export function isAnyInOut<T extends string>(source: WithId<NoInfer<T>>): (a: WithSourceTarget<WithId<T>>) => boolean
237
- export function isAnyInOut<T extends string>(a: WithSourceTarget<WithId<T>>, source: WithId<T>): boolean
238
- export function isAnyInOut<T extends string>(a: WithSourceTarget<WithId<T>> | WithId<T>, source?: WithId<T>) {
239
- if (!source) {
240
- const _source = a as WithId<T>
241
- return (b: WithSourceTarget<WithId<T>>) => isAnyInOut(b, _source)
242
- }
243
- const at = a as WithSourceTarget<WithId<T>>
244
- return isDescendantOf(at.source, source) !== isDescendantOf(at.target, source)
245
- }
246
-
247
- export function isInside<T extends string>(source: WithId<NoInfer<T>>): (a: WithSourceTarget<WithId<T>>) => boolean
248
- export function isInside<T extends string>(a: WithSourceTarget<WithId<T>>, source: WithId<T>): boolean
249
- export function isInside<T extends string>(a: WithSourceTarget<WithId<T>> | WithId<T>, source?: WithId<T>) {
250
- if (!source) {
251
- const _source = a as WithId<T>
252
- return (b: WithSourceTarget<WithId<T>>) => isInside(b, _source)
253
- }
254
- const at = a as WithSourceTarget<WithId<T>>
255
- return isDescendantOf(at.source, source) && isDescendantOf(at.target, source)
256
- }
257
-
258
- // export function isIncoming<T>(target: NoInfer<T>): (a: WithSourceTarget<T>) => boolean
259
- // export function isIncoming<T>(a: WithSourceTarget<T>, target: T): boolean
260
- // export function isIncoming<T = unknown>(a: WithSourceTarget<T> | T, target?: T) {
261
- // if (target) {
262
- // return (a as WithSourceTarget<T>).target === target
263
- // }
264
- // const _target = a as T
265
- // return (b: WithSourceTarget) => b.target === _target
266
- // }
267
-
268
- // export function isAnyInOut<T>(source: NoInfer<T>): (a: WithSourceTarget<T>) => boolean
269
- // export function isAnyInOut<T>(a: WithSourceTarget<T>, source: T): boolean
270
- // export function isAnyInOut<T = unknown>(a: WithSourceTarget<T> | T, source?: T) {
271
- // if (source) {
272
- // return hasSameSource(a as WithSourceTarget<T>, source) || hasSameTarget(a as WithSourceTarget<T>, source)
273
- // }
274
- // const _source = a as T
275
- // return (b: WithSourceTarget) => hasSameSource(b, _source) || hasSameTarget(b, _source)
276
- // }
@@ -1,77 +0,0 @@
1
- import type { Any, AnyAux } from '../types'
2
- import {
3
- type DeploymentElementModel,
4
- DeployedInstanceModel,
5
- DeploymentNodeModel,
6
- DeploymentRelationModel,
7
- NestedElementOfDeployedInstanceModel,
8
- } from './DeploymentElementModel'
9
- import { ElementModel } from './ElementModel'
10
- import { type AnyRelationshipModel, RelationshipModel } from './RelationModel'
11
- import { EdgeModel } from './view/EdgeModel'
12
- import { LikeC4ViewModel } from './view/LikeC4ViewModel'
13
- import { NodeModel } from './view/NodeModel'
14
-
15
- type AnyModel<A extends AnyAux> =
16
- | DeploymentNodeModel<A>
17
- | DeployedInstanceModel<A>
18
- | DeploymentRelationModel<A>
19
- | AnyRelationshipModel<A>
20
- | NestedElementOfDeployedInstanceModel<A>
21
- | ElementModel<A>
22
- | RelationshipModel<A>
23
- | LikeC4ViewModel<A>
24
- | NodeModel<A>
25
- | EdgeModel<A>
26
-
27
- export function isDeploymentNodeModel<M extends AnyAux>(
28
- model: AnyModel<M>,
29
- ): model is DeploymentNodeModel<M> {
30
- return model instanceof DeploymentNodeModel
31
- }
32
-
33
- export function isDeployedInstanceModel<M extends AnyAux>(
34
- model: AnyModel<M>,
35
- ): model is DeployedInstanceModel<M> {
36
- return model instanceof DeployedInstanceModel
37
- }
38
-
39
- export function isDeploymentElementModel<M extends AnyAux>(model: AnyModel<M>): model is DeploymentElementModel<M> {
40
- return isDeploymentNodeModel(model) || isDeployedInstanceModel(model)
41
- }
42
-
43
- export function isNestedElementOfDeployedInstanceModel<M extends AnyAux>(
44
- model: AnyModel<M>,
45
- ): model is NestedElementOfDeployedInstanceModel<M> {
46
- return model instanceof NestedElementOfDeployedInstanceModel
47
- }
48
-
49
- export function isDeploymentRelationModel<M extends AnyAux>(
50
- x: AnyModel<M>,
51
- ): x is DeploymentRelationModel<M> {
52
- return x instanceof DeploymentRelationModel
53
- }
54
-
55
- export function isRelationModel<M extends AnyAux>(x: AnyModel<M>): x is RelationshipModel<M> {
56
- return x instanceof RelationshipModel
57
- }
58
- export {
59
- isRelationModel as isModelRelation,
60
- isRelationModel as isRelationshipModel,
61
- }
62
-
63
- export function isElementModel<M extends Any>(element: AnyModel<M>): element is ElementModel<M> {
64
- return element instanceof ElementModel
65
- }
66
-
67
- export function isLikeC4ViewModel<M extends Any>(view: AnyModel<M>): view is LikeC4ViewModel<M> {
68
- return view instanceof LikeC4ViewModel
69
- }
70
-
71
- export function isNodeModel<M extends Any>(node: AnyModel<M>): node is NodeModel<M> {
72
- return node instanceof NodeModel
73
- }
74
-
75
- export function isEdgeModel<M extends Any>(edge: AnyModel<M>): edge is EdgeModel<M> {
76
- return edge instanceof EdgeModel
77
- }