@likec4/core 1.18.0 → 1.19.1

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 (177) hide show
  1. package/LICENSE +1 -1
  2. package/dist/builder/index.d.mts +502 -0
  3. package/dist/builder/index.d.ts +502 -0
  4. package/dist/builder/index.js +871 -0
  5. package/dist/compute-view/index.d.mts +9 -78
  6. package/dist/compute-view/index.d.ts +9 -78
  7. package/dist/compute-view/index.js +78 -0
  8. package/dist/index.d.mts +9 -730
  9. package/dist/index.d.ts +9 -730
  10. package/dist/{index.mjs → index.js} +7 -784
  11. package/dist/model/index.d.mts +218 -606
  12. package/dist/model/index.d.ts +218 -606
  13. package/dist/model/index.js +1 -0
  14. package/dist/shared/chunk-RAAYCPUM.M-JWF7SS.js +21 -0
  15. package/dist/shared/core.BIfgabEw.d.ts +719 -0
  16. package/dist/shared/core.BZ9Msq7w.d.mts +719 -0
  17. package/dist/shared/{core.DMYY7C8s.d.mts → core.C05RDLhi.d.ts} +179 -230
  18. package/dist/shared/{core.DMYY7C8s.d.ts → core.CmYMqgha.d.mts} +179 -230
  19. package/dist/shared/core.D6-fWbM3.d.ts +127 -0
  20. package/dist/shared/core.D74xkKkG.d.mts +148 -0
  21. package/dist/shared/core.D74xkKkG.d.ts +148 -0
  22. package/dist/shared/core.sLaWHBjR.d.mts +127 -0
  23. package/dist/shared/index.DafVOuVd.js +7443 -0
  24. package/dist/shared/object_hash.CE_oF3I3.js +1222 -0
  25. package/dist/shared/view.CyZrG8BJ.js +354 -0
  26. package/dist/types/index.d.mts +4 -2
  27. package/dist/types/index.d.ts +4 -2
  28. package/dist/types/index.js +20 -0
  29. package/dist/utils/index.d.mts +419 -0
  30. package/dist/utils/index.d.ts +419 -0
  31. package/dist/utils/index.js +347 -0
  32. package/package.json +47 -33
  33. package/src/builder/Builder-style1.test-d.ts +190 -0
  34. package/src/builder/Builder-style2.test-d.ts +175 -0
  35. package/src/builder/Builder.deployment.ts +25 -20
  36. package/src/builder/Builder.deploymentModel.ts +80 -55
  37. package/src/builder/Builder.element.ts +2 -0
  38. package/src/builder/Builder.model.ts +57 -43
  39. package/src/builder/Builder.ts +412 -431
  40. package/src/builder/Builder.view-common.ts +234 -0
  41. package/src/builder/Builder.view-deployment.ts +135 -0
  42. package/src/builder/Builder.view-element.ts +189 -0
  43. package/src/builder/Builder.views.ts +109 -33
  44. package/src/builder/Builder.with.ts +475 -0
  45. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +374 -0
  46. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +183 -0
  47. package/src/builder/__snapshots__/Builder.spec.ts.snap +374 -0
  48. package/src/builder/_types.ts +28 -5
  49. package/src/builder/index.ts +10 -4
  50. package/src/colors/index.ts +2 -2
  51. package/src/compute-view/compute-view.ts +45 -54
  52. package/src/compute-view/deployment-view/__test__/TestHelper.ts +236 -0
  53. package/src/compute-view/deployment-view/__test__/fixture.ts +50 -62
  54. package/src/compute-view/deployment-view/_types.ts +26 -18
  55. package/src/compute-view/deployment-view/clean-connections.ts +173 -164
  56. package/src/compute-view/deployment-view/compute.ts +51 -37
  57. package/src/compute-view/deployment-view/memory/index.ts +9 -0
  58. package/src/compute-view/deployment-view/memory/memory.ts +97 -0
  59. package/src/compute-view/deployment-view/predicates/elements.ts +144 -0
  60. package/src/compute-view/deployment-view/predicates/relation-direct.ts +183 -76
  61. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +38 -20
  62. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +72 -23
  63. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +61 -22
  64. package/src/compute-view/deployment-view/predicates/wildcard.ts +15 -15
  65. package/src/compute-view/deployment-view/stages/stage-exclude.ts +5 -0
  66. package/src/compute-view/deployment-view/stages/stage-final.ts +245 -0
  67. package/src/compute-view/deployment-view/stages/stage-include.ts +95 -0
  68. package/src/compute-view/deployment-view/utils.ts +95 -31
  69. package/src/compute-view/dynamic-view/__test__/fixture.ts +4 -4
  70. package/src/compute-view/dynamic-view/compute.ts +59 -45
  71. package/src/compute-view/element-view/__test__/TestHelper.ts +258 -0
  72. package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +64 -62
  73. package/src/compute-view/element-view/__test__/fixture.ts +147 -117
  74. package/src/compute-view/element-view/_types.ts +48 -0
  75. package/src/compute-view/element-view/clean-connections.ts +113 -0
  76. package/src/compute-view/element-view/compute.ts +264 -683
  77. package/src/compute-view/element-view/memory/NodeGroup.ts +31 -0
  78. package/src/compute-view/element-view/memory/index.ts +10 -0
  79. package/src/compute-view/element-view/memory/memory.ts +177 -0
  80. package/src/compute-view/element-view/memory/stage-exclude.ts +59 -0
  81. package/src/compute-view/element-view/memory/stage-final.ts +129 -0
  82. package/src/compute-view/element-view/memory/stage-include.ts +128 -0
  83. package/src/compute-view/element-view/predicates/_utils.ts +86 -0
  84. package/src/compute-view/element-view/predicates/element-expand.ts +33 -0
  85. package/src/compute-view/element-view/predicates/element-kind-tag.ts +26 -0
  86. package/src/compute-view/element-view/predicates/element-ref.ts +37 -0
  87. package/src/compute-view/element-view/predicates/relation-direct.ts +309 -0
  88. package/src/compute-view/element-view/predicates/relation-in-out.ts +66 -0
  89. package/src/compute-view/element-view/predicates/relation-in.ts +118 -0
  90. package/src/compute-view/element-view/predicates/relation-out.ts +116 -0
  91. package/src/compute-view/element-view/predicates/wildcard.ts +88 -0
  92. package/src/compute-view/element-view/utils.ts +59 -0
  93. package/src/compute-view/index.ts +3 -4
  94. package/src/compute-view/memory/AbstractMemory.ts +45 -0
  95. package/src/compute-view/memory/AbstractStageExclude.ts +216 -0
  96. package/src/compute-view/memory/AbstractStageInclude.ts +200 -0
  97. package/src/compute-view/memory/_types.ts +147 -0
  98. package/src/compute-view/memory/index.ts +5 -0
  99. package/src/compute-view/memory/ops.ts +43 -0
  100. package/src/compute-view/utils/buildComputedNodes.ts +4 -4
  101. package/src/compute-view/utils/elementExpressionToPredicate.ts +1 -3
  102. package/src/compute-view/utils/link-nodes-with-edges.ts +3 -7
  103. package/src/compute-view/utils/{derive-edge-props-from-relationships.ts → merge-props-from-relationships.ts} +54 -23
  104. package/src/compute-view/utils/relationExpressionToPredicates.ts +2 -2
  105. package/src/compute-view/utils/resolve-extended-views.ts +44 -40
  106. package/src/compute-view/utils/resolve-global-rules.ts +6 -6
  107. package/src/compute-view/utils/topological-sort.ts +167 -71
  108. package/src/compute-view/utils/with-readable-edges.ts +14 -9
  109. package/src/index.ts +22 -16
  110. package/src/model/DeploymentElementModel.ts +150 -85
  111. package/src/model/DeploymentModel.ts +27 -21
  112. package/src/model/ElementModel.ts +51 -25
  113. package/src/model/LikeC4Model.test-d.ts +4 -3
  114. package/src/model/LikeC4Model.ts +98 -42
  115. package/src/model/RelationModel.ts +5 -4
  116. package/src/model/__test__/fixture.ts +5 -9
  117. package/src/model/connection/Connection.ts +72 -0
  118. package/src/model/connection/deployment/DeploymentConnectionModel.ts +178 -0
  119. package/src/model/connection/{deployment.ts → deployment/find.ts} +14 -18
  120. package/src/model/connection/deployment/index.ts +8 -0
  121. package/src/model/connection/index.ts +22 -0
  122. package/src/model/connection/model/ConnectionModel.ts +157 -0
  123. package/src/model/connection/{model.ts → model/find.ts} +43 -49
  124. package/src/model/connection/model/index.ts +8 -0
  125. package/src/model/connection/ops.ts +274 -0
  126. package/src/model/guards.ts +9 -0
  127. package/src/model/index.ts +45 -3
  128. package/src/model/types.ts +35 -18
  129. package/src/model/view/EdgeModel.ts +6 -6
  130. package/src/model/view/LikeC4ViewModel.ts +14 -8
  131. package/src/model/view/NodeModel.ts +6 -5
  132. package/src/types/_common.ts +53 -1
  133. package/src/types/deployments.ts +88 -156
  134. package/src/types/element.ts +2 -2
  135. package/src/types/expression-v2.ts +172 -0
  136. package/src/types/expression.ts +9 -5
  137. package/src/types/global.ts +3 -3
  138. package/src/types/index.ts +220 -13
  139. package/src/types/model.ts +28 -24
  140. package/src/types/operators.ts +1 -1
  141. package/src/types/relation.ts +14 -10
  142. package/src/types/theme.ts +0 -1
  143. package/src/types/view.ts +20 -18
  144. package/src/utils/const.ts +1 -0
  145. package/src/utils/fqn.ts +140 -49
  146. package/src/utils/getOrCreate.ts +1 -1
  147. package/src/utils/index.ts +75 -9
  148. package/src/utils/iterable/_types.ts +5 -0
  149. package/src/utils/iterable/filter.ts +55 -0
  150. package/src/utils/iterable/find.ts +36 -0
  151. package/src/utils/iterable/flat.ts +17 -0
  152. package/src/utils/iterable/index.ts +13 -0
  153. package/src/utils/iterable/map.ts +40 -0
  154. package/src/utils/iterable/reduce.ts +24 -0
  155. package/src/utils/iterable/some.ts +36 -0
  156. package/src/utils/iterable/to.ts +19 -0
  157. package/src/utils/iterable/unique.ts +29 -0
  158. package/src/utils/relations.ts +3 -64
  159. package/src/utils/set.ts +11 -9
  160. package/src/utils/string-hash.ts +1 -1
  161. package/dist/compute-view/index.mjs +0 -79
  162. package/dist/model/index.mjs +0 -2
  163. package/dist/shared/core.BBgiAAv1.mjs +0 -144
  164. package/dist/shared/core.BPyJvuMU.mjs +0 -2420
  165. package/dist/shared/core.BQ4AbfvB.mjs +0 -9228
  166. package/dist/shared/core.k12s_keD.mjs +0 -203
  167. package/dist/types/index.mjs +0 -21
  168. package/src/builder/Builder.test-d.ts +0 -124
  169. package/src/builder/Builder.view.ts +0 -543
  170. package/src/compute-view/LikeC4ModelGraph.ts +0 -330
  171. package/src/compute-view/deployment-view/Memory.ts +0 -108
  172. package/src/compute-view/deployment-view/Stage.ts +0 -145
  173. package/src/compute-view/deployment-view/predicates/deployment-ref.ts +0 -146
  174. package/src/compute-view/element-view/predicates.ts +0 -517
  175. package/src/compute-view/utils/sortNodes.ts +0 -101
  176. package/src/model/connection/ConnectionModel.ts +0 -94
  177. package/src/model/connection/DeploymentConnectionModel.ts +0 -99
@@ -1,642 +1,254 @@
1
- import { IsLiteral, LiteralUnion, Simplify, SetRequired } from 'type-fest';
2
- import { F as Fqn, b3 as ViewId, b as RelationId, bE as NodeId, bF as EdgeId, aD as AnyLikeC4Model, K as KeysOf, aE as LayoutedLikeC4Model, bY as DiagramView, a as ComputedView, aC as ParsedLikeC4ModelDump, R as Relation, Y as Tag, _ as Link, E as Element, O as ElementKind, f as ElementShape, aX as ThemeColor, t as DeploymentNodeKind, g as Color, bS as ComputedDynamicView, bH as StepEdgeId, bR as ComputedElementView, bT as ComputedDeploymentView, x as DeploymentRef, v as DeploymentNode, w as DeployedInstance, u as PhysicalElementStyle, k as DeploymentRelation } from '../shared/core.DMYY7C8s.mjs';
1
+ import { E as ElementModel, D as DeploymentElementModel, A as AnyAux, f as DeploymentNodeModel, g as DeployedInstanceModel, R as RelationshipsAccum, h as RelationshipModel, i as DeploymentRelationModel } from '../shared/core.BZ9Msq7w.mjs';
2
+ export { b as Aux, j as EdgeModel, L as LikeC4DeploymentModel, d as LikeC4Model, e as LikeC4ViewModel, N as NodeModel } from '../shared/core.BZ9Msq7w.mjs';
3
+ import { F as Fqn, a as IteratorLike } from '../shared/core.D74xkKkG.mjs';
4
+ import { I as IterableContainer, R as ReorderedArray } from '../shared/core.sLaWHBjR.mjs';
5
+ import 'type-fest';
6
+ import '../shared/core.CmYMqgha.mjs';
3
7
 
4
- type IncomingFilter = 'all' | 'direct' | 'to-descendants';
5
- type OutgoingFilter = 'all' | 'direct' | 'from-descendants';
6
- type IteratorLike<T> = IteratorObject<T, BuiltinIteratorReturn>;
7
- type WithId<Id> = {
8
- id: Id;
9
- };
10
- type WithViews<Id extends string, ViewType> = {
11
- views: Record<Id, ViewType>;
12
- };
13
- type AnyAux = Aux<string, string, string, any>;
14
- /**
15
- * Auxilary type to keep track
16
- */
17
- interface Aux<Element extends string, Deployment extends string, Views extends string, ViewType> {
18
- Fqn: IsLiteral<Element> extends true ? Fqn<Element> : Fqn;
19
- Element: Element;
20
- ElementOrFqn: Element | WithId<this['Fqn']>;
21
- DeploymentFqn: IsLiteral<Deployment> extends true ? Fqn<Deployment> : Fqn;
22
- Deployment: Deployment;
23
- DeploymentOrFqn: Deployment | WithId<this['DeploymentFqn']>;
24
- ViewId: IsLiteral<Views> extends true ? ViewId<Views> : ViewId;
25
- ViewIdLiteral: Views;
26
- ViewType: ViewType;
27
- RelationId: RelationId;
28
- NodeId: NodeId;
29
- NodeIdLiteral: string;
30
- EdgeId: EdgeId;
31
- EdgeIdLiteral: string;
32
- NodeOrId: LiteralUnion<this['NodeIdLiteral'], string> | WithId<this['NodeId']>;
33
- EdgeOrId: LiteralUnion<this['EdgeIdLiteral'], string> | WithId<this['EdgeId']>;
34
- Model: Simplify<Omit<AnyLikeC4Model, 'views'> & WithViews<this['ViewId'], ViewType>>;
35
- }
36
- declare namespace Aux {
37
- type FromModel<M> = M extends AnyLikeC4Model ? Aux<KeysOf<M['elements']>, KeysOf<M['deployments']['elements']>, KeysOf<M['views']>, M extends LayoutedLikeC4Model ? DiagramView<ViewId<KeysOf<M['views']>>, string> : ComputedView<ViewId<KeysOf<M['views']>>, string>> : never;
38
- type FromDump<M> = M extends ParsedLikeC4ModelDump ? Aux<KeysOf<M['elements']>, KeysOf<M['deployments']['elements']>, KeysOf<M['views']>, DiagramView<ViewId<KeysOf<M['views']>>, string>> : never;
39
- }
40
-
41
- type RelationshipsIterator<M extends AnyAux> = IteratorLike<RelationshipModel<M>>;
42
- declare class RelationshipModel<M extends AnyAux> {
43
- readonly model: LikeC4Model<M>;
44
- readonly $relationship: Relation;
45
- readonly source: ElementModel<M>;
46
- readonly target: ElementModel<M>;
8
+ interface Connection<Elem = ElementModel | DeploymentElementModel, Id = string> {
9
+ readonly id: Id;
10
+ readonly source: Elem;
11
+ readonly target: Elem;
47
12
  /**
48
13
  * Common ancestor of the source and target elements.
49
- * Represents the boundary of the Relation.
50
- */
51
- readonly boundary: ElementModel<M> | null;
52
- constructor(model: LikeC4Model<M>, $relationship: Relation);
53
- get id(): M['RelationId'];
54
- get expression(): string;
55
- get title(): string | null;
56
- get technology(): string | null;
57
- get description(): string | null;
58
- get navigateTo(): LikeC4ViewModel<M> | null;
59
- get tags(): ReadonlyArray<Tag>;
60
- get links(): ReadonlyArray<Link>;
61
- /**
62
- * Iterate over all views that include this relationship.
63
- */
64
- views(): ViewsIterator<M>;
65
- }
66
-
67
- type ElementsIterator<M extends AnyAux> = IteratorLike<ElementModel<M>>;
68
- declare class ElementModel<M extends AnyAux> {
69
- readonly model: LikeC4Model<M>;
70
- readonly $element: Element;
71
- constructor(model: LikeC4Model<M>, $element: Element);
72
- get id(): M['Fqn'];
73
- get kind(): ElementKind;
74
- get shape(): ElementShape;
75
- get color(): ThemeColor;
76
- get tags(): ReadonlyArray<Tag>;
77
- get title(): string;
78
- get description(): string | null;
79
- get technology(): string | null;
80
- get links(): ReadonlyArray<Link>;
81
- get parent(): ElementModel<M> | null;
82
- get defaultView(): LikeC4ViewModel<M> | null;
83
- /**
84
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
85
- * (from closest to root)
86
- */
87
- ancestors(): ElementsIterator<M>;
88
- /**
89
- * Returns the common ancestor of this element and another element.
90
- */
91
- commonAncestor(another: ElementModel<M>): ElementModel<M> | null;
92
- children(): ReadonlySet<ElementModel<M>>;
93
- /**
94
- * Get all descendant elements (i.e. children, children’s children, etc.)
95
- */
96
- descendants(): ElementsIterator<M>;
97
- /**
98
- * Get all sibling (i.e. same parent)
99
- */
100
- siblings(): ElementsIterator<M>;
101
- /**
102
- * Resolve siblings of the element and its ancestors
103
- * (from closest to root)
104
- */
105
- ascendingSiblings(): ElementsIterator<M>;
106
- incoming(filter?: IncomingFilter): RelationshipsIterator<M>;
107
- incomers(filter?: IncomingFilter): ElementsIterator<M>;
108
- outgoing(filter?: OutgoingFilter): RelationshipsIterator<M>;
109
- outgoers(filter?: OutgoingFilter): ElementsIterator<M>;
110
- protected cachedOutgoing: Set<RelationshipModel<M>> | null;
111
- protected cachedIncoming: Set<RelationshipModel<M>> | null;
112
- get allOutgoing(): ReadonlySet<RelationshipModel<M>>;
113
- get allIncoming(): ReadonlySet<RelationshipModel<M>>;
114
- /**
115
- * Iterate over all views that include this element.
116
- */
117
- views(): ViewsIterator<M>;
118
- /**
119
- * Iterate over all views that scope this element.
120
- * It is possible that element is not included in the view.
121
- */
122
- scopedViews(): ViewsIterator<M>;
123
- /**
124
- * @returns true if the element is deployed
125
- */
126
- isDeployed(): boolean;
127
- deployments(): DeployedInstancesIterator<M>;
128
- }
129
-
130
- type NodesIterator<M extends AnyAux, V extends ComputedView | DiagramView> = IteratorLike<NodeModel<M, V>>;
131
- declare namespace NodeModel {
132
- interface WithParent<M extends AnyAux, V extends ComputedView | DiagramView> extends NodeModel<M, V> {
133
- parent: NodeModel<M, V>;
134
- }
135
- interface WithElement<M extends AnyAux, V extends ComputedView | DiagramView> extends NodeModel<M, V> {
136
- kind: ElementKind;
137
- element: ElementModel<M>;
138
- }
139
- interface WithDeploymentElement<M extends AnyAux, V extends ComputedView | DiagramView> extends NodeModel<M, V> {
140
- kind: DeploymentNodeKind;
141
- deployment: DeploymentElementModel<M>;
142
- }
143
- interface WithDeployedInstance<M extends AnyAux, V extends ComputedView | DiagramView> extends NodeModel<M, V> {
144
- kind: 'instance';
145
- element: ElementModel<M>;
146
- deployment: DeployedInstanceModel<M>;
147
- }
148
- interface IsGroup<M extends AnyAux, V extends ComputedView | DiagramView> extends NodeModel<M, V> {
149
- kind: typeof ElementKind.Group;
150
- element: null;
151
- deployment: null;
152
- }
153
- }
154
- declare class NodeModel<M extends AnyAux, V extends ComputedView | DiagramView = M['ViewType']> {
155
- readonly $view: LikeC4ViewModel<M, V>;
156
- readonly $node: V['nodes'][number];
157
- constructor($view: LikeC4ViewModel<M, V>, $node: V['nodes'][number]);
158
- get id(): NodeId;
159
- get title(): string;
160
- get kind(): ElementKind | DeploymentNodeKind | typeof ElementKind.Group | 'instance';
161
- get description(): string | null;
162
- get technology(): string | null;
163
- get parent(): NodeModel<M, V> | null;
164
- get element(): ElementModel<M> | null;
165
- get deployment(): DeploymentElementModel<M> | null;
166
- get shape(): ElementShape;
167
- get color(): Color;
168
- get tags(): ReadonlyArray<Tag>;
169
- get links(): ReadonlyArray<Link>;
170
- get navigateTo(): LikeC4ViewModel<M> | null;
171
- /**
172
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
173
- * (from closest to root)
174
- */
175
- ancestors(): NodesIterator<M, V>;
176
- children(): NodesIterator<M, V>;
177
- sublings(): NodesIterator<M, V>;
178
- incoming(filter?: IncomingFilter): EdgesIterator<M, V>;
179
- incomers(filter?: IncomingFilter): NodesIterator<M, V>;
180
- outgoing(filter?: OutgoingFilter): EdgesIterator<M, V>;
181
- outgoers(filter?: OutgoingFilter): NodesIterator<M, V>;
182
- isDiagramNode(): this is NodeModel<M, DiagramView>;
183
- hasChildren(): boolean;
184
- hasParent(): this is NodeModel.WithParent<M, V>;
185
- /**
186
- * Check if this node references to logical model element.
187
- */
188
- hasElement(): this is NodeModel.WithElement<M, V>;
189
- /**
190
- * Check if this node references to deployment element (Node or Instance).
191
- */
192
- hasDeployment(): this is NodeModel.WithDeploymentElement<M, V>;
193
- /**
194
- * Check if this node references to deployed instance
195
- * Deployed instance always references to element and deployment element.
196
- */
197
- hasDeployedInstance(): this is NodeModel.WithDeployedInstance<M, V>;
198
- isGroup(): this is NodeModel.IsGroup<M, V>;
14
+ * Represents the boundary of the connection.
15
+ */
16
+ readonly boundary: Elem | null;
17
+ /**
18
+ * Human readable expression of the connection
19
+ * Mostly used for testing and debugging
20
+ */
21
+ readonly expression: string;
22
+ mergeWith(this: Connection<Elem, Id>, other: typeof this): typeof this;
23
+ nonEmpty(): boolean;
24
+ difference(this: Connection<Elem, Id>, other: typeof this): typeof this;
25
+ intersect(this: Connection<Elem, Id>, other: typeof this): typeof this;
26
+ equals(other: Connection): boolean;
27
+ }
28
+ declare namespace Connection {
29
+ type ConnectionPredicate = <C extends Connection<{
30
+ id: string;
31
+ }, any>>(connection: C) => boolean;
32
+ type ElementId = Fqn | string;
33
+ export const isInside: (fqn: ElementId) => ConnectionPredicate;
34
+ export const isDirectedBetween: (source: ElementId, target: ElementId) => ConnectionPredicate;
35
+ export const isAnyBetween: (source: ElementId, target: ElementId) => ConnectionPredicate;
36
+ export const isIncoming: (target: ElementId) => ConnectionPredicate;
37
+ export const isOutgoing: (source: ElementId) => ConnectionPredicate;
38
+ export const isAnyInOut: (source: ElementId) => ConnectionPredicate;
39
+ export { };
199
40
  }
200
41
 
201
- type EdgesIterator<M extends AnyAux, V extends ComputedView | DiagramView> = IteratorLike<EdgeModel<M, V>>;
202
- declare class EdgeModel<M extends AnyAux, V extends ComputedView | DiagramView = M['ViewType']> {
203
- readonly view: LikeC4ViewModel<M, V>;
204
- readonly $edge: V['edges'][number];
205
- readonly source: NodeModel<M, V>;
206
- readonly target: NodeModel<M, V>;
207
- constructor(view: LikeC4ViewModel<M, V>, $edge: V['edges'][number], source: NodeModel<M, V>, target: NodeModel<M, V>);
208
- get id(): M['EdgeId'];
209
- get parent(): NodeModel<M, V> | null;
210
- get label(): string | null;
211
- get description(): string | null;
212
- get technology(): string | null;
213
- hasParent(): this is EdgeModel.WithParent<M, V>;
214
- get tags(): ReadonlyArray<Tag>;
215
- get stepNumber(): number | null;
216
- get navigateTo(): LikeC4ViewModel<M> | null;
217
- isStep(): this is EdgeModel.StepEdge<M, ComputedDynamicView>;
218
- relationships(type: 'model'): IteratorLike<RelationshipModel<M>>;
219
- relationships(type: 'deployment'): IteratorLike<DeploymentRelationModel<M>>;
220
- relationships(type?: 'model' | 'deployment'): IteratorLike<LikeC4Model.AnyRelation<M>>;
221
- includesRelation(rel: M['RelationId']): boolean;
222
- }
223
- declare namespace EdgeModel {
224
- interface StepEdge<M extends AnyAux, V extends ComputedView | DiagramView> extends EdgeModel<M, V> {
225
- id: StepEdgeId;
226
- stepNumber: number;
227
- }
228
- interface WithParent<M extends AnyAux, V extends ComputedView | DiagramView> extends EdgeModel<M, V> {
229
- parent: NodeModel<M, V>;
230
- }
231
- }
42
+ declare const customInspectSymbol: unique symbol;
232
43
 
233
- type ViewsIterator<M extends AnyAux> = IteratorLike<LikeC4ViewModel<M>>;
234
- declare class LikeC4ViewModel<M extends AnyAux, V extends ComputedView | DiagramView = M['ViewType']> {
235
- #private;
236
- readonly $model: LikeC4Model<M>;
237
- readonly $view: V;
238
- constructor($model: LikeC4Model<M>, $view: V);
239
- get __(): NonNullable<M['ViewType']['__']>;
240
- get id(): M['ViewId'];
241
- get title(): string | null;
242
- get tags(): ReadonlyArray<Tag>;
243
- get links(): ReadonlyArray<Link>;
244
- get viewOf(): ElementModel<M> | null;
245
- /**
246
- * All tags from nodes and edges.
247
- */
248
- get includedTags(): ReadonlyArray<Tag>;
249
- roots(): NodesIterator<M, V>;
250
- /**
251
- * Iterate over all nodes that have children.
252
- */
253
- compounds(): NodesIterator<M, V>;
254
- /**
255
- * Get node by id.
256
- * @throws Error if node is not found.
257
- */
258
- node(node: M['NodeOrId']): NodeModel<M, V>;
259
- /**
260
- * Find node by id.
261
- */
262
- findNode(node: M['NodeOrId']): NodeModel<M, V> | null;
263
- /**
264
- * Iterate over all nodes.
265
- */
266
- nodes(): NodesIterator<M, V>;
267
- /**
268
- * Find edge by id.
269
- * @param edge Edge or id
270
- * @returns EdgeModel
271
- */
272
- edge(edge: M['EdgeOrId']): EdgeModel<M, V>;
273
- findEdge(edge: M['EdgeOrId']): EdgeModel<M, V> | null;
274
- /**
275
- * Iterate over all edges.
276
- */
277
- edges(): EdgesIterator<M, V>;
278
- /**
279
- * Iterate over all edges.
280
- */
281
- edgesWithRelation(relation: M['RelationId']): EdgesIterator<M, V>;
282
- /**
283
- * Nodes that have references to elements from logical model.
284
- */
285
- elements(): IteratorLike<NodeModel.WithElement<M, V>>;
286
- includesElement(elementId: M['Element']): boolean;
287
- includesDeployment(deploymentId: M['Deployment']): boolean;
288
- includesRelation(relationId: M['RelationId']): boolean;
289
- /**
290
- * Below are type guards.
291
- */
292
- isComputed(): this is LikeC4ViewModel<M, ComputedView>;
293
- isDiagram(): this is LikeC4ViewModel<M, DiagramView>;
294
- isElementView(): this is LikeC4ViewModel<M, ComputedElementView>;
295
- isDeploymentView(): this is LikeC4ViewModel<M, ComputedDeploymentView>;
296
- isDynamicView(): this is LikeC4ViewModel<M, ComputedDynamicView>;
297
- }
298
-
299
- declare class LikeC4DeploymentModel<M extends AnyAux = AnyAux> {
300
- #private;
301
- readonly $model: LikeC4Model<M>;
302
- readonly $deployments: AnyLikeC4Model['deployments'];
303
- constructor($model: LikeC4Model<M>, $deployments: AnyLikeC4Model['deployments']);
304
- element(el: M['DeploymentOrFqn']): DeploymentElementModel<M>;
305
- findElement(el: M['Deployment']): DeploymentElementModel<M> | null;
306
- node(el: M['DeploymentOrFqn']): DeploymentNodeModel<M>;
307
- findNode(el: M['Deployment']): DeploymentNodeModel<M> | null;
308
- instance(el: M['DeploymentOrFqn']): DeployedInstanceModel<M>;
309
- findInstance(el: M['Deployment']): DeployedInstanceModel<M> | null;
310
- /**
311
- * Returns the root elements of the model.
312
- */
313
- roots(): DeploymentNodesIterator<M>;
314
- /**
315
- * Returns all elements in the model.
316
- */
317
- elements(): DeploymentElementsIterator<M>;
318
- /**
319
- * Returns all elements in the model.
320
- */
321
- nodes(): DeploymentNodesIterator<M>;
322
- instances(): DeployedInstancesIterator<M>;
323
- /**
324
- * Iterate over all instances of the given logical element.
325
- */
326
- instancesOf(element: M['ElementOrFqn']): DeployedInstancesIterator<M>;
327
- deploymentRef(ref: DeploymentRef): DeploymentElementModel<M> | NestedElementOfDeployedInstanceModel<M>;
328
- /**
329
- * Returns all relationships in the model.
330
- */
331
- relationships(): IteratorLike<DeploymentRelationModel<M>>;
332
- /**
333
- * Returns a specific relationship by its ID.
334
- */
335
- relationship(id: M['RelationId']): DeploymentRelationModel<M>;
336
- findRelationship(id: LiteralUnion<M['RelationId'], string>): DeploymentRelationModel<M> | null;
337
- /**
338
- * Returns all deployment views in the model.
339
- */
340
- views(): IteratorLike<LikeC4ViewModel<M, ComputedDeploymentView>>;
341
- /**
342
- * Returns the parent element of given element.
343
- * @see ancestors
344
- */
345
- parent(element: M['DeploymentOrFqn']): DeploymentNodeModel<M> | null;
346
- /**
347
- * Get all children of the element (only direct children),
348
- * @see descendants
349
- */
350
- children(element: M['DeploymentOrFqn']): ReadonlySet<DeploymentElementModel<M>>;
44
+ /**
45
+ * Connection is ephemeral entity, result of a resolving relationships between source and target.
46
+ * Includes direct relationships and/or between their nested elements.
47
+ */
48
+ declare class DeploymentConnectionModel<M extends AnyAux = AnyAux> implements Connection<DeploymentElementModel<M>, M['EdgeId']> {
49
+ readonly source: DeploymentNodeModel<M> | DeployedInstanceModel<M>;
50
+ readonly target: DeploymentNodeModel<M> | DeployedInstanceModel<M>;
51
+ readonly relations: RelationshipsAccum<M>;
52
+ constructor(source: DeploymentNodeModel<M> | DeployedInstanceModel<M>, target: DeploymentNodeModel<M> | DeployedInstanceModel<M>, relations: RelationshipsAccum<M>);
53
+ readonly id: M['EdgeId'];
351
54
  /**
352
- * Get all sibling (i.e. same parent)
55
+ * Human readable expression of the connection
56
+ * Mostly used for testing and debugging
353
57
  */
354
- siblings(element: M['DeploymentOrFqn']): DeploymentElementsIterator<M>;
58
+ get expression(): string;
59
+ private _boundary;
355
60
  /**
356
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
357
- * (from closest to root)
61
+ * Common ancestor of the source and target elements.
62
+ * Represents the boundary of the connection.
358
63
  */
359
- ancestors(element: M['DeploymentOrFqn']): DeploymentNodesIterator<M>;
64
+ get boundary(): DeploymentNodeModel<M> | null;
65
+ nonEmpty(): boolean;
66
+ [customInspectSymbol](depth: any, inspectOptions: any, inspect: any): string;
67
+ toString(): string;
360
68
  /**
361
- * Get all descendant elements (i.e. children, children’s children, etc.)
69
+ * Check if connection contains deployment relation,
70
+ * that is directly connected to source or target.
362
71
  */
363
- descendants(element: M['DeploymentOrFqn']): DeploymentElementsIterator<M>;
72
+ hasDirectDeploymentRelation(): boolean;
73
+ values(): IteratorLike<RelationshipModel<M> | DeploymentRelationModel<M>>;
364
74
  /**
365
- * Incoming relationships to the element and its descendants
366
- * @see incomers
75
+ * Merge with another connection, if it has the same source and target.
76
+ * Returns new connection with union of relationships.
367
77
  */
368
- incoming(element: M['DeploymentOrFqn'], filter?: IncomingFilter): IteratorLike<DeploymentRelationModel<M>>;
78
+ mergeWith(other: DeploymentConnectionModel<M>): DeploymentConnectionModel<M>;
79
+ difference(other: DeploymentConnectionModel<M>): DeploymentConnectionModel<M>;
80
+ intersect(other: DeploymentConnectionModel<M>): DeploymentConnectionModel<M>;
81
+ equals(other: Connection): boolean;
369
82
  /**
370
- * Outgoing relationships from the element and its descendants
371
- * @see outgoers
83
+ * Creates a clone of the current `DeploymentConnectionModel` instance with optional overrides.
84
+ * if `null` is provided in overrides, the corresponding relation set will be empty.
372
85
  */
373
- outgoing(element: M['DeploymentOrFqn'], filter?: OutgoingFilter): IteratorLike<DeploymentRelationModel<M>>;
374
- private addElement;
375
- private addRelation;
86
+ update(overrides?: {
87
+ model?: ReadonlySet<RelationshipModel<M>> | null;
88
+ deployment?: ReadonlySet<DeploymentRelationModel<M>> | null;
89
+ }): DeploymentConnectionModel<M>;
376
90
  }
377
91
 
378
- type DeploymentElementsIterator<M extends AnyAux> = IteratorLike<DeploymentElementModel<M>>;
379
- type DeployedInstancesIterator<M extends AnyAux> = IteratorLike<DeployedInstanceModel<M>>;
380
- type DeploymentNodesIterator<M extends AnyAux> = IteratorLike<DeploymentNodeModel<M>>;
381
- declare abstract class DeploymentElementModel<M extends AnyAux = AnyAux> {
382
- abstract readonly $model: LikeC4DeploymentModel<M>;
383
- abstract readonly $node: DeploymentNode | DeployedInstance;
384
- get id(): M['DeploymentFqn'];
385
- get style(): SetRequired<PhysicalElementStyle, 'shape' | 'color'>;
386
- get shape(): ElementShape;
387
- get color(): ThemeColor;
388
- get tags(): ReadonlyArray<Tag>;
389
- get title(): string;
390
- get description(): string | null;
391
- get technology(): string | null;
392
- get parent(): DeploymentNodeModel<M> | null;
393
- get links(): ReadonlyArray<Link>;
394
- /**
395
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
396
- * (from closest to root)
397
- */
398
- ancestors(): DeploymentNodesIterator<M>;
399
- /**
400
- * Returns the common ancestor of this element and another element.
401
- */
402
- commonAncestor(another: DeploymentElementModel<M>): DeploymentNodeModel<M> | null;
403
- /**
404
- * Get all sibling (i.e. same parent)
405
- */
406
- siblings(): DeploymentElementsIterator<M>;
407
- /**
408
- * Check if the element is a sibling of another element
409
- */
410
- isSibling(other: DeploymentElementModel<M>): boolean;
411
- /**
412
- * Resolve siblings of the element and its ancestors
413
- * (from closest to root)
414
- */
415
- ascendingSiblings(): DeploymentElementsIterator<M>;
416
- incoming(filter?: IncomingFilter): IteratorLike<DeploymentRelationModel<M>>;
417
- outgoing(filter?: OutgoingFilter): IteratorLike<DeploymentRelationModel<M>>;
418
- incomers(filter?: IncomingFilter): IteratorLike<DeploymentRelationEndpoint<M>>;
419
- outgoers(filter?: OutgoingFilter): IteratorLike<DeploymentRelationEndpoint<M>>;
420
- /**
421
- * Iterate over all views that include this deployment element.
422
- */
423
- views(): IteratorLike<LikeC4ViewModel<M, ComputedDeploymentView>>;
424
- isDeploymentNode(): this is DeploymentNodeModel<M>;
425
- isInstance(): this is DeployedInstanceModel<M>;
426
- abstract outgoingFromModel(): RelationshipsIterator<M>;
427
- abstract incomingFromModel(): RelationshipsIterator<M>;
428
- protected cachedOutgoing: RelationshipsAccum<M> | null;
429
- protected cachedIncoming: RelationshipsAccum<M> | null;
430
- get allOutgoing(): RelationshipsAccum<M>;
431
- get allIncoming(): RelationshipsAccum<M>;
432
- }
433
- declare class DeploymentNodeModel<M extends AnyAux = AnyAux> extends DeploymentElementModel<M> {
434
- readonly $model: LikeC4DeploymentModel<M>;
435
- readonly $node: DeploymentNode;
436
- constructor($model: LikeC4DeploymentModel<M>, $node: DeploymentNode);
437
- get kind(): DeploymentNodeKind;
438
- children(): ReadonlySet<DeploymentElementModel<M>>;
439
- descendants(): DeploymentElementsIterator<M>;
440
- isDeploymentNode(): this is DeploymentNodeModel<M>;
441
- /**
442
- * Iterate over all instances nested in this deployment node.
443
- */
444
- instances(): DeployedInstancesIterator<M>;
445
- /**
446
- * Returns deployed instance inside this deployment node
447
- * if only there are no more instances
448
- */
449
- onlyOneInstance(): DeployedInstanceModel<M> | null;
450
- /**
451
- * Cached result of relationships from instances
452
- */
453
- private _relationshipsFromInstances;
454
- private relationshipsFromInstances;
92
+ /**
93
+ * Connection refers to any relationships between two elements,
94
+ * both direct and implicit ones (between their nested elements).
95
+ *
96
+ * Merges relationships together to an single edge on the diagram.
97
+ */
98
+ declare class ConnectionModel<M extends AnyAux = AnyAux> implements Connection<ElementModel<M>, M['EdgeId']> {
99
+ readonly source: ElementModel<M>;
100
+ readonly target: ElementModel<M>;
101
+ readonly relations: ReadonlySet<RelationshipModel<M>>;
102
+ readonly id: M['EdgeId'];
103
+ constructor(source: ElementModel<M>, target: ElementModel<M>, relations?: ReadonlySet<RelationshipModel<M>>);
104
+ private _boundary;
455
105
  /**
456
- * We return only relationships that are not already present in nested instances
106
+ * Common ancestor of the source and target elements.
107
+ * Represents the boundary of the connection.
457
108
  */
458
- outgoingFromModel(): RelationshipsIterator<M>;
109
+ get boundary(): ElementModel<M> | null;
459
110
  /**
460
- * We return only relationships that are not already present in nested instances
111
+ * Human readable expression of the connection
112
+ * Mostly used for testing and debugging
461
113
  */
462
- incomingFromModel(): RelationshipsIterator<M>;
463
- }
464
- declare class DeployedInstanceModel<M extends AnyAux = AnyAux> extends DeploymentElementModel<M> {
465
- readonly $model: LikeC4DeploymentModel<M>;
466
- readonly $instance: DeployedInstance;
467
- readonly $element: ElementModel<M>;
468
- constructor($model: LikeC4DeploymentModel<M>, $instance: DeployedInstance, $element: ElementModel<M>);
469
- get parent(): DeploymentNodeModel<M>;
470
- get $node(): DeployedInstance;
471
- get style(): SetRequired<PhysicalElementStyle, 'shape' | 'color'>;
472
- get shape(): ElementShape;
473
- get color(): ThemeColor;
474
- get tags(): ReadonlyArray<Tag>;
475
- get title(): string;
476
- get description(): string | null;
477
- get technology(): string | null;
478
- get links(): ReadonlyArray<Link>;
479
- isInstance(): this is DeployedInstanceModel<M>;
480
- outgoingFromModel(): RelationshipsIterator<M>;
481
- incomingFromModel(): RelationshipsIterator<M>;
482
- }
483
- declare class NestedElementOfDeployedInstanceModel<M extends AnyAux> {
484
- readonly instance: DeployedInstanceModel<M>;
485
- readonly element: ElementModel<M>;
486
- constructor(instance: DeployedInstanceModel<M>, element: ElementModel<M>);
487
- get id(): M['DeploymentFqn'];
488
- get style(): SetRequired<PhysicalElementStyle, 'shape' | 'color'>;
489
- get shape(): ElementShape;
490
- get color(): ThemeColor;
491
- get title(): string;
492
- get description(): string | null;
493
- get technology(): string | null;
494
- isDeploymentNode(): this is DeploymentNodeModel<M>;
495
- isInstance(): this is DeployedInstanceModel<M>;
496
- }
497
- type DeploymentRelationEndpoint<M extends AnyAux> = DeploymentElementModel<M> | NestedElementOfDeployedInstanceModel<M>;
498
- declare class DeploymentRelationModel<M extends AnyAux> {
499
- readonly $model: LikeC4DeploymentModel<M>;
500
- readonly $relationship: DeploymentRelation;
501
- boundary: DeploymentNodeModel<M> | null;
502
- source: DeploymentRelationEndpoint<M>;
503
- target: DeploymentRelationEndpoint<M>;
504
- constructor($model: LikeC4DeploymentModel<M>, $relationship: DeploymentRelation);
505
- get id(): M['RelationId'];
506
114
  get expression(): string;
507
- get title(): string | null;
508
- get technology(): string | null;
509
- get description(): string | null;
510
- get tags(): ReadonlyArray<Tag>;
511
- get navigateTo(): LikeC4ViewModel<M> | null;
512
- get links(): ReadonlyArray<Link>;
513
- views(): IteratorLike<LikeC4ViewModel<M, ComputedDeploymentView>>;
514
- }
515
- declare class RelationshipsAccum<M extends AnyAux> {
516
- readonly model: ReadonlySet<RelationshipModel<M>>;
517
- readonly deployment: ReadonlySet<DeploymentRelationModel<M>>;
518
115
  /**
519
- * @param model relationships from logical model
520
- * @param deployment relationships from deployment model
116
+ * Returns true if only includes relations between the source and target elements.
521
117
  */
522
- constructor(model: ReadonlySet<RelationshipModel<M>>, deployment: ReadonlySet<DeploymentRelationModel<M>>);
523
- get isEmpty(): boolean;
524
- get nonEmpty(): boolean;
525
- get size(): number;
118
+ get isDirect(): boolean;
526
119
  /**
527
- * Returns new Accum containing all the elements which are both in this and otherAccum
120
+ * Returns true if includes relations between nested elements of the source and target elements.
528
121
  */
529
- intersect(otherAccum: RelationshipsAccum<M>): RelationshipsAccum<M>;
122
+ get isImplicit(): boolean;
123
+ get directRelations(): ReadonlySet<RelationshipModel<M>>;
124
+ nonEmpty(): boolean;
125
+ mergeWith(other: ConnectionModel<M>): ConnectionModel<M>;
126
+ difference(other: ConnectionModel<M>): ConnectionModel<M>;
127
+ intersect(other: ConnectionModel<M>): ConnectionModel<M>;
128
+ equals(other: Connection): boolean;
530
129
  /**
531
- * Returns new Accum containing all the elements which are both in this and otherAccum
130
+ * Returns a new instance with the updated relations.
131
+ *
132
+ * @param relations - A readonly set of `RelationshipModel` instances representing the new relations.
133
+ * @returns A new `ConnectionModel` instance with the updated relations.
532
134
  */
533
- difference(otherAccum: RelationshipsAccum<M>): RelationshipsAccum<M>;
135
+ update(relations: ReadonlySet<RelationshipModel<M>>): ConnectionModel<M>;
136
+ [customInspectSymbol](depth: any, inspectOptions: any, inspect: any): string;
137
+ toString(): string;
534
138
  /**
535
- * Returns new Accum containing all the elements from both
139
+ * Creates a new connection with reversed direction (target becomes source and vice versa)
140
+ * @param search - When true, attempts to find an existing connection between the reversed nodes
536
141
  */
537
- union(otherAccum: RelationshipsAccum<M>): RelationshipsAccum<M>;
142
+ reversed(search?: boolean): ConnectionModel<M>;
538
143
  }
539
144
 
540
- declare class LikeC4Model<M extends AnyAux = LikeC4Model.Any> {
541
- #private;
542
- readonly $model: M['Model'];
543
- /**
544
- * Only available in compile time
545
- */
546
- readonly Aux: M;
547
- readonly deployment: LikeC4DeploymentModel<M>;
548
- static create<const M extends AnyLikeC4Model>(model: M): LikeC4Model<Aux.FromModel<M>>;
549
- /**
550
- * This method is supposed to be used only in dumps
551
- */
552
- static fromDump<const M extends ParsedLikeC4ModelDump>(dump: M): LikeC4Model<Aux.FromDump<M>>;
553
- private constructor();
554
- get type(): 'computed' | 'layouted';
555
- element(el: M['ElementOrFqn']): ElementModel<M>;
556
- findElement(el: LiteralUnion<M['Element'], string>): ElementModel<M> | null;
557
- /**
558
- * Returns the root elements of the model.
559
- */
560
- roots(): ElementsIterator<M>;
561
- /**
562
- * Returns all elements in the model.
563
- */
564
- elements(): ElementsIterator<M>;
565
- /**
566
- * Returns all relationships in the model.
567
- */
568
- relationships(): RelationshipsIterator<M>;
569
- /**
570
- * Returns a specific relationship by its ID.
571
- * If the relationship is not found in the model, it will be searched in the deployment model.
572
- * Search can be limited to the model or deployment model only.
573
- */
574
- relationship(id: M['RelationId'], type: 'model'): RelationshipModel<M>;
575
- relationship(id: M['RelationId'], type: 'deployment'): DeploymentRelationModel<M>;
576
- relationship(id: M['RelationId'], type?: 'model' | 'deployment'): RelationshipModel<M> | DeploymentRelationModel<M>;
577
- findRelationship(id: LiteralUnion<M['RelationId'], string>, type: 'model'): RelationshipModel<M> | null;
578
- findRelationship(id: LiteralUnion<M['RelationId'], string>, type: 'deployment'): DeploymentRelationModel<M> | null;
579
- findRelationship(id: LiteralUnion<M['RelationId'], string>, type?: 'model' | 'deployment'): RelationshipModel<M> | DeploymentRelationModel<M> | null;
580
- /**
581
- * Returns all views in the model.
582
- */
583
- views(): MapIterator<LikeC4ViewModel<M, M["ViewType"]>>;
584
- /**
585
- * Returns a specific view by its ID.
586
- */
587
- view(viewId: M['ViewIdLiteral']): LikeC4ViewModel<M>;
588
- findView(viewId: LiteralUnion<M['ViewId'], string>): LikeC4ViewModel<M>;
589
- /**
590
- * Returns the parent element of given element.
591
- * @see ancestors
592
- */
593
- parent(element: M['ElementOrFqn']): ElementModel<M> | null;
594
- /**
595
- * Get all children of the element (only direct children),
596
- * @see descendants
597
- */
598
- children(element: M['ElementOrFqn']): ReadonlySet<ElementModel<M>>;
599
- /**
600
- * Get all sibling (i.e. same parent)
601
- */
602
- siblings(element: M['ElementOrFqn']): ElementsIterator<M>;
603
- /**
604
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
605
- * (from closest to root)
606
- */
607
- ancestors(element: M['ElementOrFqn']): ElementsIterator<M>;
608
- /**
609
- * Get all descendant elements (i.e. children, children’s children, etc.)
610
- */
611
- descendants(element: M['ElementOrFqn']): ElementsIterator<M>;
612
- /**
613
- * Incoming relationships to the element and its descendants
614
- * @see incomers
615
- */
616
- incoming(element: M['ElementOrFqn'], filter?: IncomingFilter): RelationshipsIterator<M>;
617
- /**
618
- * Outgoing relationships from the element and its descendants
619
- * @see outgoers
620
- */
621
- outgoing(element: M['ElementOrFqn'], filter?: OutgoingFilter): RelationshipsIterator<M>;
622
- private addElement;
623
- private addRelation;
145
+ /**
146
+ * Check if connection is nested inside another connection
147
+ * (i.e. between descendants)
148
+ */
149
+ declare function isNestedConnection<T extends {
150
+ id: string;
151
+ }>(parent: WithSourceTarget<NoInfer<T>>): (nested: WithSourceTarget<T>) => boolean;
152
+ declare function isNestedConnection<T extends {
153
+ id: string;
154
+ }>(nested: WithSourceTarget<T>, parent: WithSourceTarget<T>): boolean;
155
+ type ConnectionElemId = Connection<{
156
+ readonly id: string;
157
+ }, any>;
158
+ declare function findDeepestNestedConnection<C extends ConnectionElemId>(connections: ReadonlyArray<C>, connection: C): C | null;
159
+ declare function sortDeepestFirst<C extends ConnectionElemId>(connections: ReadonlyArray<C>): C[];
160
+ type WithBoundary = {
161
+ boundary: null | {
162
+ id: string;
163
+ };
164
+ };
165
+ declare function sortConnectionsByBoundaryHierarchy(sort?: 'asc' | 'desc'): <T extends WithBoundary, A extends IterableContainer<T>>(array: A) => ReorderedArray<A>;
166
+ declare function sortConnectionsByBoundaryHierarchy<T extends WithBoundary, A extends IterableContainer<T>>(array: A, sort?: 'asc' | 'desc'): ReorderedArray<A>;
167
+ /**
168
+ * Find connections that includes given connection (i.e between it's ancestors)
169
+ */
170
+ declare function findAscendingConnections<C extends ConnectionElemId>(connections: ReadonlyArray<C>, connection: C): Array<C>;
171
+ /**
172
+ * Find connections that includes given connection (i.e between it's descendants)
173
+ */
174
+ declare function findDescendantConnections<C extends ConnectionElemId>(connections: ReadonlyArray<C>, connection: C): Array<C>;
175
+ declare function mergeConnections<C extends Connection>(connections: ReadonlyArray<C>): C[];
176
+ /**
177
+ * Excludes the values existing in `other` array.
178
+ * The output maintains the same order as the input.
179
+ */
180
+ declare function differenceConnections<C extends Connection>(source: Iterable<C>, exclude: Iterable<C>): C[];
181
+ type WithSourceTarget<T = unknown> = {
182
+ source: T;
183
+ target: T;
184
+ };
185
+ declare function hasSameSourceTarget<T>(a: WithSourceTarget<NoInfer<T>>): (b: WithSourceTarget<T>) => boolean;
186
+ declare function hasSameSourceTarget<T>(a: WithSourceTarget<T>, b: WithSourceTarget<T>): boolean;
187
+ declare function hasSameSource<T>(a: WithSourceTarget<NoInfer<T>>): (b: WithSourceTarget<T>) => boolean;
188
+ declare function hasSameSource<T>(a: WithSourceTarget<T>, b: WithSourceTarget<T>): boolean;
189
+ declare function hasSameTarget<T>(a: WithSourceTarget<NoInfer<T>>): (b: WithSourceTarget<T>) => boolean;
190
+ declare function hasSameTarget<T>(a: WithSourceTarget<T>, b: WithSourceTarget<T>): boolean;
191
+ type WithId<T> = {
192
+ id: T;
193
+ };
194
+ declare function isOutgoing<T extends string>(source: WithId<NoInfer<T>>): (a: WithSourceTarget<WithId<T>>) => boolean;
195
+ declare function isOutgoing<T extends string>(a: WithSourceTarget<WithId<T>>, source: WithId<T>): boolean;
196
+ declare function isIncoming<T extends string>(target: WithId<NoInfer<T>>): (a: WithSourceTarget<WithId<T>>) => boolean;
197
+ declare function isIncoming<T extends string>(a: WithSourceTarget<WithId<T>>, target: WithId<T>): boolean;
198
+ declare function isAnyInOut<T extends string>(source: WithId<NoInfer<T>>): (a: WithSourceTarget<WithId<T>>) => boolean;
199
+ declare function isAnyInOut<T extends string>(a: WithSourceTarget<WithId<T>>, source: WithId<T>): boolean;
200
+
201
+ /**
202
+ * Resolve connection from source to target
203
+ * If direction is `both`, also look for reverse connection
204
+ *
205
+ * @default direction directed
206
+ */
207
+ declare function findConnection$1<M extends AnyAux>(source: DeploymentElementModel<M>, target: DeploymentElementModel<NoInfer<M>>, direction: 'directed'): readonly [DeploymentConnectionModel<M>] | readonly [];
208
+ declare function findConnection$1<M extends AnyAux>(source: DeploymentElementModel<M>, target: DeploymentElementModel<NoInfer<M>>, direction: 'both'): readonly [DeploymentConnectionModel<M>, DeploymentConnectionModel<M>] | readonly [DeploymentConnectionModel<M>] | readonly [];
209
+ declare function findConnection$1<M extends AnyAux>(source: DeploymentElementModel<M>, target: DeploymentElementModel<NoInfer<M>>, direction?: 'directed' | 'both'): readonly [DeploymentConnectionModel<M>, DeploymentConnectionModel<M>] | readonly [DeploymentConnectionModel<M>] | readonly [];
210
+ /**
211
+ * Resolve all connections between element and others
212
+ * By default, look for both directions.
213
+ *
214
+ * @default direction both
215
+ */
216
+ declare function findConnectionsBetween$1<M extends AnyAux>(element: DeploymentElementModel<M>, others: Iterable<DeploymentElementModel<NoInfer<M>>>, direction?: 'directed' | 'both'): readonly DeploymentConnectionModel<M>[];
217
+ /**
218
+ * Resolve all connections within a given set of elements
219
+ */
220
+ declare function findConnectionsWithin$1<M extends AnyAux>(elements: Iterable<DeploymentElementModel<M>>): readonly DeploymentConnectionModel<M>[];
221
+
222
+ declare namespace find$1 {
223
+ export { findConnection$1 as findConnection, findConnectionsBetween$1 as findConnectionsBetween, findConnectionsWithin$1 as findConnectionsWithin };
624
224
  }
625
- declare namespace LikeC4Model {
626
- type Any = Aux<string, string, string, ComputedView | DiagramView>;
627
- type Element<M extends AnyAux = Any> = ElementModel<M>;
628
- type Relation<M extends AnyAux = Any> = RelationshipModel<M>;
629
- type AnyRelation<M extends AnyAux = Any> = RelationshipModel<M> | DeploymentRelationModel<M>;
630
- type View<M extends AnyAux = Any, V extends ComputedView | DiagramView = M['ViewType']> = LikeC4ViewModel<M, V>;
631
- type Node<M extends AnyAux = Any, V extends ComputedView | DiagramView = M['ViewType']> = NodeModel<M, V>;
632
- type Edge<M extends AnyAux = Any, V extends ComputedView | DiagramView = M['ViewType']> = EdgeModel<M, V>;
633
- type DeploymentModel<M extends AnyAux = AnyAux> = LikeC4DeploymentModel<M>;
634
- type Deployment<M extends AnyAux = AnyAux> = DeploymentElementModel<M>;
635
- type DeploymentNode<M extends AnyAux = AnyAux> = DeploymentNodeModel<M>;
636
- type DeployedInstance<M extends AnyAux = AnyAux> = DeployedInstanceModel<M>;
637
- type Typed<Elements extends string = string, Deployments extends string = string, Views extends string = string, ViewType = DiagramView<Views> | ComputedView<Views>> = Aux<Elements, Deployments, Views, ViewType>;
638
- type Computed<Elements extends string = string, Deployments extends string = string, Views extends string = string> = LikeC4Model<Typed<Elements, Deployments, Views, ComputedView<Views>>>;
639
- type Layouted<Elements extends string = string, Deployments extends string = string, Views extends string = string> = LikeC4Model<Typed<Elements, Deployments, Views, DiagramView<Views>>>;
225
+
226
+ /**
227
+ * Resolve connection from source to target
228
+ *
229
+ * @param direction - if 'both', also returns connection from target to source
230
+ * @default `directed`
231
+ */
232
+ declare function findConnection<M extends AnyAux>(source: ElementModel<M>, target: ElementModel<M>, direction?: 'directed' | 'both'): [ConnectionModel<M>, ConnectionModel<M>] | [ConnectionModel<M>] | [];
233
+ /**
234
+ * Resolve all connections between element and others
235
+ * @param direction - if 'directed', only look for outgoing connections from the element to others
236
+ * @default `both`
237
+ */
238
+ declare function findConnectionsBetween<M extends AnyAux>(element: ElementModel<M>, others: Iterable<ElementModel<NoInfer<M>>>, direction?: 'directed' | 'both'): readonly ConnectionModel<M>[];
239
+ /**
240
+ * Resolve all connections within a given set of elements
241
+ */
242
+ declare function findConnectionsWithin<M extends AnyAux>(elements: Iterable<ElementModel<M>>): readonly ConnectionModel<M>[];
243
+
244
+ declare const find_findConnection: typeof findConnection;
245
+ declare const find_findConnectionsBetween: typeof findConnectionsBetween;
246
+ declare const find_findConnectionsWithin: typeof findConnectionsWithin;
247
+ declare namespace find {
248
+ export { find_findConnection as findConnection, find_findConnectionsBetween as findConnectionsBetween, find_findConnectionsWithin as findConnectionsWithin };
640
249
  }
641
250
 
642
- export { LikeC4DeploymentModel, LikeC4Model, Aux as LikeC4ModelAux, LikeC4ViewModel };
251
+ declare function isDeploymentNode(model: DeploymentElementModel): model is DeploymentNodeModel;
252
+ declare function isDeployedInstance(model: DeploymentElementModel): model is DeployedInstanceModel;
253
+
254
+ export { AnyAux, Connection, ConnectionModel, DeployedInstanceModel, DeploymentConnectionModel, DeploymentElementModel, DeploymentNodeModel, DeploymentRelationModel, ElementModel, RelationshipModel, find$1 as deploymentConnection, differenceConnections, findAscendingConnections, findDeepestNestedConnection, findDescendantConnections, hasSameSource, hasSameSourceTarget, hasSameTarget, isAnyInOut, isDeployedInstance, isDeploymentNode, isIncoming, isNestedConnection, isOutgoing, mergeConnections, find as modelConnection, sortConnectionsByBoundaryHierarchy, sortDeepestFirst };