@likec4/core 1.47.0 → 1.48.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 (181) hide show
  1. package/LICENSE +1 -1
  2. package/dist/_chunks/Builder.view-element.mjs +3284 -0
  3. package/dist/_chunks/LikeC4Model.d.mts +1287 -0
  4. package/dist/_chunks/LikeC4Styles.mjs +691 -0
  5. package/dist/_chunks/RichText.d.mts +84 -0
  6. package/dist/_chunks/RichText.mjs +148 -0
  7. package/dist/_chunks/_aux.d.mts +289 -0
  8. package/dist/_chunks/_aux.mjs +18 -0
  9. package/dist/_chunks/_types.d.mts +781 -0
  10. package/dist/_chunks/_types2.d.mts +38 -0
  11. package/dist/_chunks/assignTagColors.mjs +24 -0
  12. package/dist/_chunks/calcDriftsFromSnapshot.mjs +379 -0
  13. package/dist/_chunks/connection.mjs +0 -0
  14. package/dist/_chunks/const.d.mts +43 -0
  15. package/dist/_chunks/const.mjs +33 -0
  16. package/dist/_chunks/expression-model.d.mts +192 -0
  17. package/dist/_chunks/expression-model.mjs +103 -0
  18. package/dist/_chunks/expression.d.mts +347 -0
  19. package/dist/_chunks/expression.mjs +107 -0
  20. package/dist/_chunks/find.d.mts +82 -0
  21. package/dist/_chunks/find.mjs +646 -0
  22. package/dist/_chunks/find2.d.mts +78 -0
  23. package/dist/_chunks/find2.mjs +287 -0
  24. package/dist/_chunks/fqnRef.d.mts +58 -0
  25. package/dist/_chunks/fqnRef.mjs +41 -0
  26. package/dist/_chunks/geometry.mjs +335 -0
  27. package/dist/_chunks/index.d.mts +169 -0
  28. package/dist/_chunks/index2.d.mts +937 -0
  29. package/dist/_chunks/index3.d.mts +146 -0
  30. package/dist/_chunks/index4.d.mts +62 -0
  31. package/dist/_chunks/index5.d.mts +42 -0
  32. package/dist/_chunks/index6.d.mts +43 -0
  33. package/dist/{shared/core.OtRNdMxy.d.mts → _chunks/index7.d.mts} +113 -197
  34. package/dist/_chunks/index8.d.mts +144 -0
  35. package/dist/_chunks/invariant.mjs +18 -0
  36. package/dist/_chunks/iterable.mjs +146 -0
  37. package/dist/_chunks/libs/@mantine/colors-generator.mjs +3416 -0
  38. package/dist/_chunks/libs/@ungap/structured-clone.mjs +213 -0
  39. package/dist/_chunks/libs/bail.mjs +14 -0
  40. package/dist/_chunks/libs/ccount.mjs +25 -0
  41. package/dist/_chunks/libs/character-entities-html4.mjs +263 -0
  42. package/dist/_chunks/libs/character-entities-legacy.mjs +117 -0
  43. package/dist/_chunks/libs/character-entities.mjs +2136 -0
  44. package/dist/_chunks/libs/comma-separated-tokens.mjs +18 -0
  45. package/dist/_chunks/libs/decode-named-character-reference.mjs +21 -0
  46. package/dist/_chunks/libs/defu.mjs +42 -0
  47. package/dist/_chunks/libs/devlop.mjs +5 -0
  48. package/dist/_chunks/libs/escape-string-regexp.mjs +8 -0
  49. package/dist/_chunks/libs/extend.mjs +77 -0
  50. package/dist/_chunks/libs/graphology-dag.mjs +703 -0
  51. package/dist/_chunks/libs/graphology-types.d.mts +601 -0
  52. package/dist/_chunks/libs/graphology.d.mts +6 -0
  53. package/dist/_chunks/libs/graphology.mjs +4565 -0
  54. package/dist/_chunks/libs/hast-util-sanitize.mjs +863 -0
  55. package/dist/_chunks/libs/hast-util-to-html.mjs +2696 -0
  56. package/dist/_chunks/libs/is-plain-obj.mjs +9 -0
  57. package/dist/_chunks/libs/longest-streak.mjs +30 -0
  58. package/dist/_chunks/libs/markdown-table.mjs +290 -0
  59. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +653 -0
  60. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +8522 -0
  61. package/dist/_chunks/libs/mdast-util-gfm.mjs +2393 -0
  62. package/dist/_chunks/libs/mdast-util-to-hast.mjs +1803 -0
  63. package/dist/_chunks/libs/micromark-extension-gfm.mjs +2243 -0
  64. package/dist/_chunks/libs/mnemonist.d.mts +254 -0
  65. package/dist/_chunks/libs/mnemonist.mjs +1978 -0
  66. package/dist/_chunks/libs/natural-compare-lite.mjs +42 -0
  67. package/dist/_chunks/libs/rehype-sanitize.mjs +29 -0
  68. package/dist/_chunks/libs/rehype-stringify.mjs +34 -0
  69. package/dist/_chunks/libs/remark-gfm.mjs +36 -0
  70. package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +100 -0
  71. package/dist/_chunks/libs/remark-parse.mjs +39 -0
  72. package/dist/_chunks/libs/remark-rehype.mjs +171 -0
  73. package/dist/_chunks/libs/remeda.mjs +702 -0
  74. package/dist/_chunks/libs/trough.mjs +158 -0
  75. package/dist/_chunks/libs/unified.mjs +2212 -0
  76. package/dist/_chunks/mnemonist.d.mts +1 -0
  77. package/dist/_chunks/mnemonist.mjs +0 -0
  78. package/dist/_chunks/model.mjs +1898 -0
  79. package/dist/_chunks/model2.mjs +0 -0
  80. package/dist/_chunks/relationships-view.mjs +132 -0
  81. package/dist/_chunks/rolldown-runtime.mjs +42 -0
  82. package/dist/{shared/core.C_3y3eqV.d.mts → _chunks/scalar.d.mts} +13 -43
  83. package/dist/_chunks/scalar.mjs +84 -0
  84. package/dist/_chunks/utils.mjs +483 -0
  85. package/dist/builder/index.d.mts +11 -775
  86. package/dist/builder/index.mjs +631 -1022
  87. package/dist/compute-view/index.d.mts +85 -56
  88. package/dist/compute-view/index.mjs +247 -214
  89. package/dist/compute-view/relationships-view/index.d.mts +16 -51
  90. package/dist/compute-view/relationships-view/index.mjs +6 -184
  91. package/dist/geometry/index.d.mts +2 -109
  92. package/dist/geometry/index.mjs +2 -327
  93. package/dist/index.d.mts +18 -20
  94. package/dist/index.mjs +27 -18
  95. package/dist/model/connection/deployment/index.d.mts +12 -15
  96. package/dist/model/connection/deployment/index.mjs +9 -2
  97. package/dist/model/connection/index.d.mts +14 -75
  98. package/dist/model/connection/index.mjs +10 -3
  99. package/dist/model/connection/model/index.d.mts +12 -15
  100. package/dist/model/connection/model/index.mjs +8 -2
  101. package/dist/model/index.d.mts +15 -57
  102. package/dist/model/index.mjs +11 -4
  103. package/dist/styles/index.d.mts +9 -117
  104. package/dist/styles/index.mjs +26 -59
  105. package/dist/types/RichText.d.mts +3 -0
  106. package/dist/types/RichText.mjs +7 -0
  107. package/dist/types/_aux.d.mts +3 -4
  108. package/dist/types/_aux.mjs +2 -7
  109. package/dist/types/expression-model.d.mts +6 -190
  110. package/dist/types/expression-model.mjs +6 -108
  111. package/dist/types/expression.d.mts +5 -6
  112. package/dist/types/expression.mjs +6 -112
  113. package/dist/types/fqnRef.d.mts +4 -60
  114. package/dist/types/fqnRef.mjs +6 -44
  115. package/dist/types/index.d.mts +9 -47
  116. package/dist/types/index.mjs +14 -16
  117. package/dist/types/scalar.d.mts +2 -2
  118. package/dist/types/scalar.mjs +7 -4
  119. package/dist/utils/graphology/index.d.mts +2 -1864
  120. package/dist/utils/graphology/index.mjs +3 -1
  121. package/dist/utils/index.d.mts +11 -124
  122. package/dist/utils/index.mjs +16 -43
  123. package/dist/utils/iterable/index.d.mts +9 -132
  124. package/dist/utils/iterable/index.mjs +2 -61
  125. package/dist/utils/mnemonist.d.mts +2 -0
  126. package/dist/utils/mnemonist.mjs +12 -0
  127. package/package.json +17 -22
  128. package/compute-view/relationships/package.json +0 -4
  129. package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
  130. package/dist/shared/core.78IWAHAE.mjs +0 -332
  131. package/dist/shared/core.B85MJLTf.mjs +0 -5
  132. package/dist/shared/core.BFd1lU9R.mjs +0 -29
  133. package/dist/shared/core.BKlholso.mjs +0 -3
  134. package/dist/shared/core.BNN-3vPH.mjs +0 -1255
  135. package/dist/shared/core.BPGOjone.d.mts +0 -46
  136. package/dist/shared/core.BP_QHEXs.mjs +0 -785
  137. package/dist/shared/core.BbE4y-yl.mjs +0 -177
  138. package/dist/shared/core.Bdy3hhTc.mjs +0 -28382
  139. package/dist/shared/core.BfCKSW-g.d.mts +0 -1266
  140. package/dist/shared/core.BhNcrwzK.mjs +0 -7
  141. package/dist/shared/core.BkVA6gjl.mjs +0 -5
  142. package/dist/shared/core.BoYfZOBm.mjs +0 -3
  143. package/dist/shared/core.BsSXS-_R.mjs +0 -7
  144. package/dist/shared/core.C3JowhaZ.mjs +0 -32
  145. package/dist/shared/core.C4x8aaWa.mjs +0 -27
  146. package/dist/shared/core.CAgYpDtM.d.mts +0 -98
  147. package/dist/shared/core.CHf8VEa3.mjs +0 -1206
  148. package/dist/shared/core.CLSZtnFh.mjs +0 -69
  149. package/dist/shared/core.CbT8JVYL.mjs +0 -5
  150. package/dist/shared/core.CdNCAwq7.mjs +0 -176
  151. package/dist/shared/core.CmGY9blO.mjs +0 -6717
  152. package/dist/shared/core.CmPXpJ8l.mjs +0 -21
  153. package/dist/shared/core.Coi_LOUZ.mjs +0 -7
  154. package/dist/shared/core.CqAJJpK_.mjs +0 -3
  155. package/dist/shared/core.CywrQs86.d.mts +0 -31
  156. package/dist/shared/core.D00YbOhQ.d.mts +0 -300
  157. package/dist/shared/core.D0WZutNd.mjs +0 -94
  158. package/dist/shared/core.D4npX2q8.mjs +0 -18
  159. package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
  160. package/dist/shared/core.DC5IAaDT.d.mts +0 -334
  161. package/dist/shared/core.DE9qzhn8.d.mts +0 -83
  162. package/dist/shared/core.DGcIbsj4.mjs +0 -3946
  163. package/dist/shared/core.DH7TXqXf.mjs +0 -136
  164. package/dist/shared/core.DKhRkHRN.d.mts +0 -41
  165. package/dist/shared/core.DRJma0Ol.mjs +0 -22
  166. package/dist/shared/core.DU5SRqNF.mjs +0 -2209
  167. package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
  168. package/dist/shared/core.DbfO90vF.mjs +0 -434
  169. package/dist/shared/core.DcS-0zys.mjs +0 -10
  170. package/dist/shared/core.Dh119QSP.mjs +0 -4995
  171. package/dist/shared/core.DjcWextK.mjs +0 -1371
  172. package/dist/shared/core.Dojz4bvg.d.mts +0 -504
  173. package/dist/shared/core.FZ305VYd.mjs +0 -21
  174. package/dist/shared/core.RfnaEmgA.mjs +0 -7
  175. package/dist/shared/core.btEq3i3f.mjs +0 -300
  176. package/dist/shared/core.oSV6SRfk.mjs +0 -13
  177. package/dist/shared/core.om36dXXW.mjs +0 -41
  178. package/dist/shared/core.osFs8tU7.d.mts +0 -466
  179. package/dist/shared/core.q10OP9oJ.mjs +0 -5
  180. package/dist/shared/core.tpvDGvdC.d.mts +0 -87
  181. package/dist/shared/core.uFk_o9X6.mjs +0 -13
@@ -1,79 +1,108 @@
1
- import { A as Any, t as toComputed, d as AnyParsed, m as _stage } from '../shared/core.D00YbOhQ.mjs';
2
- import { f as LikeC4Model } from '../shared/core.BfCKSW-g.mjs';
3
- import { P as ParsedLikeC4ModelData, C as ComputedLikeC4ModelData, p as ParsedView, r as ComputedView, J as DiagramNode, K as DiagramEdge } from '../shared/core.osFs8tU7.mjs';
4
- import { H as BaseViewProperties, O as ComputedNode, P as ComputedEdge, B as ViewAutoLayout } from '../shared/core.Dojz4bvg.mjs';
5
- import { P as ProjectId } from '../shared/core.C_3y3eqV.mjs';
6
- import { B as BBox } from '../shared/core.BPGOjone.mjs';
7
- import { N as NonEmptyArray } from '../shared/core.DB0Ue5Wx.mjs';
8
- import 'type-fest';
9
- import '../shared/core.CAgYpDtM.mjs';
10
- import '../shared/core.DC5IAaDT.mjs';
11
- import '../types/fqnRef.mjs';
12
- import '../shared/core.CywrQs86.mjs';
13
- import '../types/expression-model.mjs';
1
+ import { ct as toComputed, ht as _type, mt as _stage, n as Any, o as AnyParsed, wt as NonEmptyArray } from "../_chunks/_aux.mjs";
2
+ import "../_chunks/scalar.mjs";
3
+ import "../_chunks/expression.mjs";
4
+ import "../_chunks/fqnRef.mjs";
5
+ import { t as ModelExpression } from "../_chunks/expression-model.mjs";
6
+ import { $t as AnyIncludePredicate, J as ComputedEdge, Qt as AnyExcludePredicate, X as ComputedNode, c as ComputedLikeC4ModelData, d as ParsedLikeC4ModelData, h as ParsedView, on as ViewAutoLayout, p as ComputedView, rn as BaseViewProperties } from "../_chunks/index2.mjs";
7
+ import "../_chunks/RichText.mjs";
8
+ import "../_chunks/index3.mjs";
9
+ import { n as LikeC4Model } from "../_chunks/LikeC4Model.mjs";
10
+ import { B as ViewPredicate } from "../_chunks/_types.mjs";
11
+ import "../_chunks/const.mjs";
12
+ import "../_chunks/find.mjs";
13
+ import "../_chunks/find2.mjs";
14
+ import "../_chunks/index4.mjs";
15
+ import "../_chunks/index5.mjs";
16
+ import { a as LayoutedProjectNode, i as LayoutedProjectEdge, n as ComputedProjectNode, o as LayoutedProjectsView, r as ComputedProjectsView, t as ComputedProjectEdge } from "../_chunks/_types2.mjs";
17
+ import { n as computeRelationshipsView, r as RelationshipsViewData, t as treeFromElements } from "../_chunks/index6.mjs";
14
18
 
19
+ //#region src/compute-view/compute-view.d.ts
15
20
  type ComputeViewResult<V> = {
16
- isSuccess: true;
17
- error?: undefined;
18
- view: V;
21
+ isSuccess: true;
22
+ error?: undefined;
23
+ view: V;
19
24
  } | {
20
- isSuccess: false;
21
- error: Error;
22
- view: undefined;
25
+ isSuccess: false;
26
+ error: Error;
27
+ view: undefined;
23
28
  };
24
29
  declare function unsafeComputeView<A extends Any>(viewsource: ParsedView<A>, likec4model: LikeC4Model<any>): ComputedView<A>;
25
30
  declare function computeView<A extends Any>(viewsource: ParsedView<A>, likec4model: LikeC4Model<A>): ComputeViewResult<ComputedView<A>>;
26
31
  declare function computeParsedModelData<A extends AnyParsed, B extends toComputed<A> = toComputed<A>>(parsed: ParsedLikeC4ModelData<A>): ComputedLikeC4ModelData<B>;
27
32
  declare function computeLikeC4Model<A extends Any, B extends toComputed<A> = toComputed<A>>(parsed: ParsedLikeC4ModelData<A>): LikeC4Model<B>;
28
-
33
+ //#endregion
34
+ //#region src/compute-view/utils/resolve-extended-views.d.ts
29
35
  /**
30
36
  * Resolve rules of extended views
31
37
  * (Removes invalid views)
32
38
  */
33
39
  declare function resolveRulesExtendedViews<A extends Any, V extends Record<any, ParsedView<A>>>(unresolvedViews: V): V;
34
-
40
+ //#endregion
41
+ //#region src/compute-view/utils/with-readable-edges.d.ts
35
42
  /**
36
43
  * Convert hashed edge ids to human-readable
37
44
  * Mostly for testing purposes
38
45
  */
39
- declare function withReadableEdges<V extends ComputedView<any>>({ edges, nodes, ...view }: V, separator?: string): V & {
40
- nodeIds: string[];
41
- edgeIds: string[];
46
+ declare function withReadableEdges<V extends ComputedView<any>>({
47
+ edges,
48
+ nodes,
49
+ ...view
50
+ }: V, separator?: string): V & {
51
+ nodeIds: string[];
52
+ edgeIds: string[];
42
53
  };
43
- declare function viewsWithReadableEdges<A extends Any>({ views, ...model }: ComputedLikeC4ModelData<A>): ComputedLikeC4ModelData<A>;
44
-
45
- interface ComputedProjectNode extends ComputedNode {
46
- readonly projectId: ProjectId;
47
- }
48
- interface ComputedProjectEdge extends ComputedEdge {
49
- readonly projectId: ProjectId;
50
- }
51
- interface LayoutedProjectNode extends DiagramNode {
52
- readonly projectId: ProjectId;
53
- }
54
- interface LayoutedProjectEdge extends DiagramEdge {
55
- readonly projectId: ProjectId;
56
- }
54
+ declare function viewsWithReadableEdges<A extends Any>({
55
+ views,
56
+ ...model
57
+ }: ComputedLikeC4ModelData<A>): ComputedLikeC4ModelData<A>;
58
+ //#endregion
59
+ //#region src/compute-view/projects-view/compute.d.ts
57
60
  /**
58
- * An overview of projects and their relationships, presented as a graph with nodes and edges.
59
- * Even though it has same structure as other likec4 views, it is not mixed with them, as it represents a different kind.
61
+ * Computes an overview of projects and their relationships
60
62
  */
61
- interface ComputedProjectsView extends BaseViewProperties<any> {
62
- readonly [_stage]: 'computed';
63
- readonly nodes: ReadonlyArray<ComputedProjectNode>;
64
- readonly edges: ReadonlyArray<ComputedProjectEdge>;
65
- readonly autoLayout: ViewAutoLayout;
66
- }
67
- interface LayoutedProjectsView extends BaseViewProperties<any> {
68
- readonly [_stage]: 'layouted';
69
- readonly nodes: ReadonlyArray<LayoutedProjectNode>;
70
- readonly edges: ReadonlyArray<LayoutedProjectEdge>;
71
- readonly bounds: BBox;
63
+ declare function computeProjectsView(likec4models: NonEmptyArray<LikeC4Model>): ComputedProjectsView;
64
+ //#endregion
65
+ //#region src/compute-view/adhoc-view/compute.d.ts
66
+ interface AdhocViewIncludePredicate<A extends Any> extends AnyIncludePredicate<ModelExpression<A>> {}
67
+ interface AdhocViewExcludePredicate<A extends Any> extends AnyExcludePredicate<ModelExpression<A>> {}
68
+ type AdhocViewPredicate<A extends Any = Any> = AdhocViewIncludePredicate<A> | AdhocViewExcludePredicate<A>;
69
+ interface ComputedAdhocView extends BaseViewProperties<Any> {
70
+ readonly [_type]: 'adhoc';
71
+ readonly [_stage]: 'computed';
72
+ readonly nodes: ReadonlyArray<ComputedNode>;
73
+ readonly edges: ReadonlyArray<ComputedEdge>;
74
+ readonly autoLayout: ViewAutoLayout;
72
75
  }
73
-
74
76
  /**
75
- * Computes an overview of projects and their relationships
77
+ * Computes an adhoc view based on the given predicates.
78
+ * Adhoc views are not defined in the model, but computed on demand.
79
+ * Available for logical model only.
80
+ *
81
+ * @param predicates accepts the same predicates as element view.
82
+ * @param likec4model The LikeC4 model to compute view.
83
+ * @returns The computed adhoc view.
76
84
  */
77
- declare function computeProjectsView(likec4models: NonEmptyArray<LikeC4Model>): ComputedProjectsView;
78
-
79
- export { type ComputeViewResult, type ComputedProjectEdge, type ComputedProjectNode, type ComputedProjectsView, type LayoutedProjectEdge, type LayoutedProjectNode, type LayoutedProjectsView, computeLikeC4Model, computeParsedModelData, computeProjectsView, computeView, resolveRulesExtendedViews, unsafeComputeView, viewsWithReadableEdges, withReadableEdges };
85
+ declare function computeAdhocView<A extends Any>(likec4model: LikeC4Model<A>, predicates: AdhocViewPredicate<NoInfer<A>>[]): ComputedAdhocView;
86
+ //#endregion
87
+ //#region src/compute-view/adhoc-view/builder.d.ts
88
+ /**
89
+ * Allows you to define type-safe adhoc views using types from the model.
90
+ */
91
+ declare class AdhocView<A extends Any> {
92
+ #private;
93
+ private readonly model;
94
+ /**
95
+ * Creates a new adhoc view builder.
96
+ */
97
+ static use<A extends Any>(model: LikeC4Model<A>): AdhocView<A>;
98
+ private constructor();
99
+ /**
100
+ * Used to cache the type of the predicates.
101
+ */
102
+ readonly Expr: ViewPredicate.AllExpression<ViewPredicate.ElementExpr<A['ElementId']>>;
103
+ include(...predicates: this['Expr'][]): this;
104
+ exclude(...predicates: this['Expr'][]): this;
105
+ compute(): ComputedAdhocView;
106
+ }
107
+ //#endregion
108
+ export { AdhocView, type AdhocViewExcludePredicate, type AdhocViewIncludePredicate, type AdhocViewPredicate, type ComputeViewResult, type ComputedAdhocView, ComputedProjectEdge, ComputedProjectNode, ComputedProjectsView, LayoutedProjectEdge, LayoutedProjectNode, LayoutedProjectsView, type RelationshipsViewData, computeAdhocView, computeLikeC4Model, computeParsedModelData, computeProjectsView, computeRelationshipsView, computeView, resolveRulesExtendedViews, treeFromElements, unsafeComputeView, viewsWithReadableEdges, withReadableEdges };
@@ -1,229 +1,262 @@
1
- import { w as willCreateCycle, t as topologicalSortExports, a as t$4, n as n$1, b as t$9, l as linkNodesWithEdges, c as topologicalSort } from '../shared/core.Dh119QSP.mjs';
2
- export { d as computeLikeC4Model, e as computeParsedModelData, f as computeView, u as unsafeComputeView } from '../shared/core.Dh119QSP.mjs';
3
- import { n } from '../shared/core.BhNcrwzK.mjs';
4
- import { t as t$2 } from '../shared/core.DU5SRqNF.mjs';
5
- import { r as isExtendsElementView, p as isElementView, _ as _stage } from '../shared/core.DH7TXqXf.mjs';
6
- import { G as Graph } from '../shared/core.CmGY9blO.mjs';
7
- import { c as isNonEmptyArray } from '../shared/core.CdNCAwq7.mjs';
8
- import { t as t$5 } from '../shared/core.CbT8JVYL.mjs';
9
- import { t as t$3, b as t$8 } from '../shared/core.DjcWextK.mjs';
10
- import { t as t$1, a as t$7 } from '../shared/core.BsSXS-_R.mjs';
11
- import { t as t$6, e as e$1 } from '../shared/core.Coi_LOUZ.mjs';
12
- import { e } from '../shared/core.BP_QHEXs.mjs';
13
- import { D as DefaultMap } from '../shared/core.BbE4y-yl.mjs';
14
- import { a as nonNullable, i as invariant } from '../shared/core.D4npX2q8.mjs';
15
- import { s as stringHash } from '../shared/core.oSV6SRfk.mjs';
16
- import { preferSummary } from '../types/_aux.mjs';
17
- import { a as GlobalFqn, P as ProjectId } from '../shared/core.D0WZutNd.mjs';
18
-
19
- function t(...t){return t$1(Object.keys,t)}
1
+ import { r as __toESM } from "../_chunks/rolldown-runtime.mjs";
2
+ import { C as t$1, E as t$4, G as t$7, I as e, S as t$3, Y as t$5, Z as t$6, i as n, m as e$1, r as t, w as t$2, x as n$1, y as t$8 } from "../_chunks/libs/remeda.mjs";
3
+ import { N as _stage, P as _type, _ as isExtendsElementView, g as isElementView } from "../_chunks/LikeC4Styles.mjs";
4
+ import "../_chunks/libs/natural-compare-lite.mjs";
5
+ import { N as isNonEmptyArray, r as stringHash } from "../_chunks/utils.mjs";
6
+ import { n as nonNullable, t as invariant } from "../_chunks/invariant.mjs";
7
+ import "../_chunks/libs/@mantine/colors-generator.mjs";
8
+ import { n as require_topological_sort, t as require_will_create_cycle } from "../_chunks/libs/graphology-dag.mjs";
9
+ import { n as import_default_map } from "../_chunks/libs/mnemonist.mjs";
10
+ import "../_chunks/libs/defu.mjs";
11
+ import "../_chunks/libs/extend.mjs";
12
+ import { n as preferSummary } from "../_chunks/_aux.mjs";
13
+ import { c as ProjectId, d as ViewId, i as GlobalFqn } from "../_chunks/scalar.mjs";
14
+ import { a as unsafeComputeView, c as linkNodesWithEdges, i as computeView, n as computeLikeC4Model, o as computeElementView, r as computeParsedModelData, s as topologicalSort$1, t as $expr } from "../_chunks/Builder.view-element.mjs";
15
+ import { t as Graph } from "../_chunks/libs/graphology.mjs";
16
+ import { n as treeFromElements, t as computeRelationshipsView } from "../_chunks/relationships-view.mjs";
20
17
 
18
+ //#region src/compute-view/utils/resolve-extended-views.ts
19
+ var import_topological_sort = require_topological_sort();
20
+ var import_will_create_cycle = /* @__PURE__ */ __toESM(require_will_create_cycle(), 1);
21
+ /**
22
+ * Resolve rules of extended views
23
+ * (Removes invalid views)
24
+ */
21
25
  function resolveRulesExtendedViews(unresolvedViews) {
22
- const g = new Graph({
23
- type: "directed"
24
- });
25
- const extendedViews = [];
26
- for (const view of t$2(unresolvedViews)) {
27
- g.addNode(view.id, { view });
28
- if (isExtendsElementView(view)) {
29
- extendedViews.push(view);
30
- }
31
- }
32
- if (extendedViews.length === 0) {
33
- return unresolvedViews;
34
- }
35
- for (const view of extendedViews) {
36
- if (!g.hasNode(view.extends)) {
37
- console.warn(`View "${view.id}" extends from "${view.extends}" which does not exist`);
38
- continue;
39
- }
40
- if (willCreateCycle(g, view.id, view.extends)) {
41
- console.warn(`View "${view.id}" extends from "${view.extends}" which creates a cycle`);
42
- continue;
43
- }
44
- g.addDirectedEdge(view.id, view.extends);
45
- }
46
- const sorted = topologicalSortExports.topologicalSort(g).reverse();
47
- return sorted.reduce((acc, id) => {
48
- const view = g.getNodeAttribute(id, "view");
49
- if (!isExtendsElementView(view)) {
50
- acc[view.id] = view;
51
- return acc;
52
- }
53
- const extendsFrom = acc[view.extends];
54
- if (!extendsFrom || !isElementView(extendsFrom)) {
55
- return acc;
56
- }
57
- const tags = n([
58
- ...extendsFrom.tags ?? [],
59
- ...view.tags ?? []
60
- ]);
61
- const links = [
62
- ...extendsFrom.links ?? [],
63
- ...view.links ?? []
64
- ];
65
- acc[view.id] = {
66
- ...extendsFrom,
67
- ...view,
68
- title: view.title ?? extendsFrom.title ?? null,
69
- description: view.description ?? extendsFrom.description ?? null,
70
- tags,
71
- links: isNonEmptyArray(links) ? links : null,
72
- rules: [...extendsFrom.rules, ...view.rules]
73
- };
74
- return acc;
75
- }, {});
26
+ const g = new Graph({ type: "directed" });
27
+ const extendedViews = [];
28
+ for (const view of t(unresolvedViews)) {
29
+ g.addNode(view.id, { view });
30
+ if (isExtendsElementView(view)) extendedViews.push(view);
31
+ }
32
+ if (extendedViews.length === 0) return unresolvedViews;
33
+ for (const view of extendedViews) {
34
+ if (!g.hasNode(view.extends)) {
35
+ console.warn(`View "${view.id}" extends from "${view.extends}" which does not exist`);
36
+ continue;
37
+ }
38
+ if ((0, import_will_create_cycle.default)(g, view.id, view.extends)) {
39
+ console.warn(`View "${view.id}" extends from "${view.extends}" which creates a cycle`);
40
+ continue;
41
+ }
42
+ g.addDirectedEdge(view.id, view.extends);
43
+ }
44
+ return (0, import_topological_sort.topologicalSort)(g).reverse().reduce((acc, id) => {
45
+ const view = g.getNodeAttribute(id, "view");
46
+ if (!isExtendsElementView(view)) {
47
+ acc[view.id] = view;
48
+ return acc;
49
+ }
50
+ const extendsFrom = acc[view.extends];
51
+ if (!extendsFrom || !isElementView(extendsFrom)) return acc;
52
+ const tags = n([...extendsFrom.tags ?? [], ...view.tags ?? []]);
53
+ const links = [...extendsFrom.links ?? [], ...view.links ?? []];
54
+ acc[view.id] = {
55
+ ...extendsFrom,
56
+ ...view,
57
+ title: view.title ?? extendsFrom.title ?? null,
58
+ description: view.description ?? extendsFrom.description ?? null,
59
+ tags,
60
+ links: isNonEmptyArray(links) ? links : null,
61
+ rules: [...extendsFrom.rules, ...view.rules]
62
+ };
63
+ return acc;
64
+ }, {});
76
65
  }
77
66
 
67
+ //#endregion
68
+ //#region src/compute-view/utils/with-readable-edges.ts
69
+ /**
70
+ * Convert hashed edge ids to human-readable
71
+ * Mostly for testing purposes
72
+ */
78
73
  function withReadableEdges({ edges, nodes, ...view }, separator = ":") {
79
- const edgeids = t$4(edges, (e) => [e.id, `${e.source}${separator}${e.target}`]);
80
- return {
81
- ...view,
82
- edges: edges.map((e) => ({
83
- ...e,
84
- id: edgeids[e.id]
85
- })),
86
- nodes: nodes.map((n) => ({
87
- ...n,
88
- inEdges: t$5(n.inEdges, (e) => edgeids[e]),
89
- outEdges: t$5(n.outEdges, (e) => edgeids[e])
90
- })),
91
- nodeIds: nodes.map((n) => n.id),
92
- edgeIds: edges.map((e) => edgeids[e.id])
93
- };
74
+ const edgeids = t$1(edges, (e) => [e.id, `${e.source}${separator}${e.target}`]);
75
+ return {
76
+ ...view,
77
+ edges: edges.map((e) => ({
78
+ ...e,
79
+ id: edgeids[e.id]
80
+ })),
81
+ nodes: nodes.map((n) => ({
82
+ ...n,
83
+ inEdges: t$2(n.inEdges, (e) => edgeids[e]),
84
+ outEdges: t$2(n.outEdges, (e) => edgeids[e])
85
+ })),
86
+ nodeIds: nodes.map((n) => n.id),
87
+ edgeIds: edges.map((e) => edgeids[e.id])
88
+ };
94
89
  }
95
90
  function viewsWithReadableEdges({ views, ...model }) {
96
- return {
97
- ...model,
98
- views: t$3(views, (v) => n$1(withReadableEdges(v), ["nodeIds", "edgeIds"]))
99
- };
91
+ return {
92
+ ...model,
93
+ views: t$3(views, (v) => n$1(withReadableEdges(v), ["nodeIds", "edgeIds"]))
94
+ };
100
95
  }
101
96
 
102
- const keysCount = (object) => t(object).length;
97
+ //#endregion
98
+ //#region src/compute-view/projects-view/compute.ts
99
+ const keysCount = (object) => t$4(object).length;
103
100
  const nodeId = (projectId) => stringHash(projectId);
101
+ /**
102
+ * Computes an overview of projects and their relationships
103
+ */
104
104
  function computeProjectsView(likec4models) {
105
- const nodesMap = buildNodesForEachModel(likec4models);
106
- const key = (from, to) => `${from}->${to}`;
107
- const relationships = new DefaultMap((key2) => {
108
- const [from, to] = key2.split("->");
109
- return {
110
- from,
111
- to,
112
- relationships: /* @__PURE__ */ new Set()
113
- };
114
- });
115
- const relationshipsFromTo = (from, to) => relationships.get(key(from, to)).relationships;
116
- const processImportedElement = (model, importedElement) => {
117
- const projectId = importedElement.projectId;
118
- invariant(projectId !== model.projectId, "Imported element must have a different project id");
119
- const incoming = relationshipsFromTo(model.projectId, projectId);
120
- for (const rel of importedElement.incoming("direct")) {
121
- if (rel.source.projectId === model.projectId) {
122
- incoming.add(rel);
123
- }
124
- }
125
- const outgoing = relationshipsFromTo(projectId, model.projectId);
126
- for (const rel of importedElement.outgoing("direct")) {
127
- if (rel.target.projectId === model.projectId) {
128
- outgoing.add(rel);
129
- }
130
- }
131
- };
132
- for (const model of likec4models) {
133
- if (e(model.$data.imports)) {
134
- continue;
135
- }
136
- for (const [projectId, imported] of t$6(model.$data.imports)) {
137
- for (const importedElement of imported) {
138
- const fqn = GlobalFqn(projectId, importedElement.id);
139
- processImportedElement(
140
- model,
141
- nonNullable(
142
- model.findElement(fqn),
143
- `Element ${importedElement.id} from project ${projectId} not found in model ${model.projectId}`
144
- )
145
- );
146
- }
147
- }
148
- }
149
- const edges = Array.from(relationships.entries()).filter(([_, { relationships: relationships2 }]) => relationships2.size > 0).map(([key2, { from, to, relationships: relationshipsSet }]) => {
150
- const relationships2 = [...relationshipsSet];
151
- invariant(t$7(relationships2, 1), "Relationships set must have at least one relationship");
152
- const edge = {
153
- id: stringHash(key2),
154
- source: nodeId(from),
155
- target: nodeId(to),
156
- projectId: from,
157
- relations: t$5(relationships2, e$1("id")),
158
- label: null,
159
- color: "gray",
160
- parent: null,
161
- line: "solid",
162
- tags: n(t$8(relationships2, e$1("tags")))
163
- };
164
- const onlyOne = t$9(relationships2);
165
- if (onlyOne) {
166
- edge.label = onlyOne.title;
167
- edge.description = preferSummary(onlyOne.$relationship) ?? null;
168
- edge.technology = onlyOne.technology;
169
- edge.color = onlyOne.color;
170
- edge.line = onlyOne.line;
171
- if (onlyOne.kind) {
172
- edge.kind = onlyOne.kind;
173
- }
174
- if (onlyOne.$relationship.navigateTo) {
175
- edge.navigateTo = onlyOne.$relationship.navigateTo;
176
- }
177
- }
178
- return edge;
179
- });
180
- linkNodesWithEdges(nodesMap, edges);
181
- const sorted = topologicalSort({
182
- nodes: nodesMap,
183
- edges
184
- });
185
- return {
186
- id: "projects-view",
187
- [_stage]: "computed",
188
- title: "Projects",
189
- description: {
190
- txt: "Overview of all projects and their relationships"
191
- },
192
- autoLayout: {
193
- direction: "TB"
194
- },
195
- ...sorted
196
- };
105
+ const nodesMap = buildNodesForEachModel(likec4models);
106
+ const key = (from, to) => `${from}->${to}`;
107
+ const relationships = new import_default_map.default((key) => {
108
+ const [from, to] = key.split("->");
109
+ return {
110
+ from,
111
+ to,
112
+ relationships: /* @__PURE__ */ new Set()
113
+ };
114
+ });
115
+ const relationshipsFromTo = (from, to) => relationships.get(key(from, to)).relationships;
116
+ const processImportedElement = (model, importedElement) => {
117
+ const projectId = importedElement.projectId;
118
+ invariant(projectId !== model.projectId, "Imported element must have a different project id");
119
+ const incoming = relationshipsFromTo(model.projectId, projectId);
120
+ for (const rel of importedElement.incoming("direct")) if (rel.source.projectId === model.projectId) incoming.add(rel);
121
+ const outgoing = relationshipsFromTo(projectId, model.projectId);
122
+ for (const rel of importedElement.outgoing("direct")) if (rel.target.projectId === model.projectId) outgoing.add(rel);
123
+ };
124
+ for (const model of likec4models) {
125
+ if (e(model.$data.imports)) continue;
126
+ for (const [projectId, imported] of t$5(model.$data.imports)) for (const importedElement of imported) {
127
+ const fqn = GlobalFqn(projectId, importedElement.id);
128
+ processImportedElement(model, nonNullable(model.findElement(fqn), `Element ${importedElement.id} from project ${projectId} not found in model ${model.projectId}`));
129
+ }
130
+ }
131
+ const edges = Array.from(relationships.entries()).filter(([_, { relationships }]) => relationships.size > 0).map(([key, { from, to, relationships: relationshipsSet }]) => {
132
+ const relationships = [...relationshipsSet];
133
+ invariant(t$6(relationships, 1), "Relationships set must have at least one relationship");
134
+ const edge = {
135
+ id: stringHash(key),
136
+ source: nodeId(from),
137
+ target: nodeId(to),
138
+ projectId: from,
139
+ relations: t$2(relationships, e$1("id")),
140
+ label: null,
141
+ color: "gray",
142
+ parent: null,
143
+ line: "solid",
144
+ tags: n(t$7(relationships, e$1("tags")))
145
+ };
146
+ const onlyOne = t$8(relationships);
147
+ if (onlyOne) {
148
+ edge.label = onlyOne.title;
149
+ edge.description = /* @__PURE__ */ preferSummary(onlyOne.$relationship) ?? null;
150
+ edge.technology = onlyOne.technology;
151
+ edge.color = onlyOne.color;
152
+ edge.line = onlyOne.line;
153
+ if (onlyOne.kind) edge.kind = onlyOne.kind;
154
+ if (onlyOne.$relationship.navigateTo) edge.navigateTo = onlyOne.$relationship.navigateTo;
155
+ }
156
+ return edge;
157
+ });
158
+ linkNodesWithEdges(nodesMap, edges);
159
+ const sorted = topologicalSort$1({
160
+ nodes: nodesMap,
161
+ edges
162
+ });
163
+ return {
164
+ id: "projects-view",
165
+ [_type]: "projects",
166
+ [_stage]: "computed",
167
+ title: "Projects",
168
+ description: { txt: "Overview of all projects and their relationships" },
169
+ autoLayout: { direction: "TB" },
170
+ ...sorted
171
+ };
197
172
  }
198
173
  function buildNodesForEachModel(likec4models) {
199
- const nodesMap = /* @__PURE__ */ new Map();
200
- for (const model of likec4models) {
201
- const projectId = ProjectId(model.projectId);
202
- const node = {
203
- id: nodeId(projectId),
204
- kind: "@project",
205
- parent: null,
206
- projectId,
207
- title: model.project.title ?? model.project.id,
208
- description: {
209
- txt: [
210
- `Elements: ${keysCount(model.$data.elements)}`,
211
- `Relationships: ${keysCount(model.$data.relations)}`,
212
- `Views: ${keysCount(model.$data.views)}`
213
- ].join("\n")
214
- },
215
- shape: "rectangle",
216
- children: [],
217
- inEdges: [],
218
- outEdges: [],
219
- color: "primary",
220
- level: 0,
221
- style: {},
222
- tags: []
223
- };
224
- nodesMap.set(node.id, node);
225
- }
226
- return nodesMap;
174
+ const nodesMap = /* @__PURE__ */ new Map();
175
+ for (const model of likec4models) {
176
+ const projectId = ProjectId(model.projectId);
177
+ const node = {
178
+ id: nodeId(projectId),
179
+ kind: "@project",
180
+ parent: null,
181
+ projectId,
182
+ title: model.project.title ?? model.project.id,
183
+ description: { txt: [
184
+ `Elements: ${keysCount(model.$data.elements)}`,
185
+ `Relationships: ${keysCount(model.$data.relations)}`,
186
+ `Views: ${keysCount(model.$data.views)}`
187
+ ].join("\n") },
188
+ shape: "rectangle",
189
+ children: [],
190
+ inEdges: [],
191
+ outEdges: [],
192
+ color: "primary",
193
+ level: 0,
194
+ style: {},
195
+ tags: []
196
+ };
197
+ nodesMap.set(node.id, node);
198
+ }
199
+ return nodesMap;
200
+ }
201
+
202
+ //#endregion
203
+ //#region src/compute-view/adhoc-view/compute.ts
204
+ /**
205
+ * Computes an adhoc view based on the given predicates.
206
+ * Adhoc views are not defined in the model, but computed on demand.
207
+ * Available for logical model only.
208
+ *
209
+ * @param predicates accepts the same predicates as element view.
210
+ * @param likec4model The LikeC4 model to compute view.
211
+ * @returns The computed adhoc view.
212
+ */
213
+ function computeAdhocView(likec4model, predicates) {
214
+ return {
215
+ ...computeElementView(likec4model, {
216
+ id: ViewId("adhoc"),
217
+ _stage: "parsed",
218
+ _type: "element",
219
+ rules: predicates,
220
+ title: null,
221
+ description: null
222
+ }),
223
+ _type: "adhoc",
224
+ _stage: "computed"
225
+ };
227
226
  }
228
227
 
229
- export { computeProjectsView, resolveRulesExtendedViews, viewsWithReadableEdges, withReadableEdges };
228
+ //#endregion
229
+ //#region src/compute-view/adhoc-view/builder.ts
230
+ /**
231
+ * Allows you to define type-safe adhoc views using types from the model.
232
+ */
233
+ var AdhocView = class AdhocView {
234
+ /**
235
+ * Creates a new adhoc view builder.
236
+ */
237
+ static use(model) {
238
+ return new AdhocView(model);
239
+ }
240
+ #predicates = [];
241
+ constructor(model) {
242
+ this.model = model;
243
+ }
244
+ /**
245
+ * Used to cache the type of the predicates.
246
+ */
247
+ Expr;
248
+ include(...predicates) {
249
+ this.#predicates.push({ include: predicates.map((predicate) => $expr(predicate)) });
250
+ return this;
251
+ }
252
+ exclude(...predicates) {
253
+ this.#predicates.push({ exclude: predicates.map((predicate) => $expr(predicate)) });
254
+ return this;
255
+ }
256
+ compute() {
257
+ return computeAdhocView(this.model, this.#predicates);
258
+ }
259
+ };
260
+
261
+ //#endregion
262
+ export { AdhocView, computeAdhocView, computeLikeC4Model, computeParsedModelData, computeProjectsView, computeRelationshipsView, computeView, resolveRulesExtendedViews, treeFromElements, unsafeComputeView, viewsWithReadableEdges, withReadableEdges };