@likec4/core 1.46.4 → 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 -773
  86. package/dist/builder/index.mjs +631 -978
  87. package/dist/compute-view/index.d.mts +90 -27
  88. package/dist/compute-view/index.mjs +253 -83
  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 +18 -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.BPGOjone.d.mts +0 -46
  135. package/dist/shared/core.BYdtmqY5.mjs +0 -1255
  136. package/dist/shared/core.BZCgljZd.d.mts +0 -83
  137. package/dist/shared/core.BbE4y-yl.mjs +0 -177
  138. package/dist/shared/core.BhNcrwzK.mjs +0 -7
  139. package/dist/shared/core.BkVA6gjl.mjs +0 -5
  140. package/dist/shared/core.BoYfZOBm.mjs +0 -3
  141. package/dist/shared/core.BsSXS-_R.mjs +0 -7
  142. package/dist/shared/core.BspBF3SJ.mjs +0 -3944
  143. package/dist/shared/core.BvPm_-u3.d.mts +0 -334
  144. package/dist/shared/core.C-Jdx7xo.d.mts +0 -1263
  145. package/dist/shared/core.C3JowhaZ.mjs +0 -32
  146. package/dist/shared/core.C4x8aaWa.mjs +0 -27
  147. package/dist/shared/core.CBLX4mT8.mjs +0 -28411
  148. package/dist/shared/core.CLSZtnFh.mjs +0 -69
  149. package/dist/shared/core.CRhT4Iio.mjs +0 -785
  150. package/dist/shared/core.CbT8JVYL.mjs +0 -5
  151. package/dist/shared/core.CdNCAwq7.mjs +0 -176
  152. package/dist/shared/core.ClTP6-TN.d.mts +0 -87
  153. package/dist/shared/core.CmGY9blO.mjs +0 -6717
  154. package/dist/shared/core.CmPXpJ8l.mjs +0 -21
  155. package/dist/shared/core.Coi_LOUZ.mjs +0 -7
  156. package/dist/shared/core.CqAJJpK_.mjs +0 -3
  157. package/dist/shared/core.Ctj2S3bD.d.mts +0 -466
  158. package/dist/shared/core.CywrQs86.d.mts +0 -31
  159. package/dist/shared/core.D00YbOhQ.d.mts +0 -300
  160. package/dist/shared/core.D0WZutNd.mjs +0 -94
  161. package/dist/shared/core.D4npX2q8.mjs +0 -18
  162. package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
  163. package/dist/shared/core.DEK-BO3_.mjs +0 -1206
  164. package/dist/shared/core.DH7TXqXf.mjs +0 -136
  165. package/dist/shared/core.DRJma0Ol.mjs +0 -22
  166. package/dist/shared/core.DSalPD6v.mjs +0 -1352
  167. package/dist/shared/core.DVfPJPJj.mjs +0 -2200
  168. package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
  169. package/dist/shared/core.DbfO90vF.mjs +0 -434
  170. package/dist/shared/core.DcS-0zys.mjs +0 -10
  171. package/dist/shared/core.DeDCYTDR.d.mts +0 -98
  172. package/dist/shared/core.DpKY_3NF.d.mts +0 -504
  173. package/dist/shared/core.Dt0v3djy.d.mts +0 -41
  174. package/dist/shared/core.FZ305VYd.mjs +0 -21
  175. package/dist/shared/core.RfnaEmgA.mjs +0 -7
  176. package/dist/shared/core.oSV6SRfk.mjs +0 -13
  177. package/dist/shared/core.om36dXXW.mjs +0 -41
  178. package/dist/shared/core.q10OP9oJ.mjs +0 -5
  179. package/dist/shared/core.uFk_o9X6.mjs +0 -13
  180. package/dist/shared/core.xeuDd__E.mjs +0 -300
  181. package/dist/shared/core.xgoPk2RG.mjs +0 -4989
@@ -1,45 +1,108 @@
1
- import { A as Any, t as toComputed, d as AnyParsed } from '../shared/core.D00YbOhQ.mjs';
2
- import { f as LikeC4Model } from '../shared/core.C-Jdx7xo.mjs';
3
- import { P as ParsedLikeC4ModelData, C as ComputedLikeC4ModelData, p as ParsedView, r as ComputedView } from '../shared/core.Ctj2S3bD.mjs';
4
- import 'type-fest';
5
- import '../shared/core.DB0Ue5Wx.mjs';
6
- import '../shared/core.C_3y3eqV.mjs';
7
- import '../shared/core.DeDCYTDR.mjs';
8
- import '../shared/core.BvPm_-u3.mjs';
9
- import '../types/fqnRef.mjs';
10
- import '../shared/core.DpKY_3NF.mjs';
11
- import '../types/expression-model.mjs';
12
- import '../shared/core.BPGOjone.mjs';
13
- import '../shared/core.CywrQs86.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
- export { type ComputeViewResult, computeLikeC4Model, computeParsedModelData, computeView, resolveRulesExtendedViews, unsafeComputeView, viewsWithReadableEdges, withReadableEdges };
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
60
+ /**
61
+ * Computes an overview of projects and their relationships
62
+ */
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;
75
+ }
76
+ /**
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.
84
+ */
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,92 +1,262 @@
1
- import { w as willCreateCycle, t as topologicalSortExports, a as t$2, n as n$1 } from '../shared/core.xgoPk2RG.mjs';
2
- export { c as computeLikeC4Model, b as computeParsedModelData, d as computeView, u as unsafeComputeView } from '../shared/core.xgoPk2RG.mjs';
3
- import { n } from '../shared/core.BhNcrwzK.mjs';
4
- import { t } from '../shared/core.DVfPJPJj.mjs';
5
- import { r as isExtendsElementView, p as isElementView } 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$3 } from '../shared/core.CbT8JVYL.mjs';
9
- import { t as t$1 } from '../shared/core.DSalPD6v.mjs';
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";
10
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
+ */
11
25
  function resolveRulesExtendedViews(unresolvedViews) {
12
- const g = new Graph({
13
- type: "directed"
14
- });
15
- const extendedViews = [];
16
- for (const view of t(unresolvedViews)) {
17
- g.addNode(view.id, { view });
18
- if (isExtendsElementView(view)) {
19
- extendedViews.push(view);
20
- }
21
- }
22
- if (extendedViews.length === 0) {
23
- return unresolvedViews;
24
- }
25
- for (const view of extendedViews) {
26
- if (!g.hasNode(view.extends)) {
27
- console.warn(`View "${view.id}" extends from "${view.extends}" which does not exist`);
28
- continue;
29
- }
30
- if (willCreateCycle(g, view.id, view.extends)) {
31
- console.warn(`View "${view.id}" extends from "${view.extends}" which creates a cycle`);
32
- continue;
33
- }
34
- g.addDirectedEdge(view.id, view.extends);
35
- }
36
- const sorted = topologicalSortExports.topologicalSort(g).reverse();
37
- return sorted.reduce((acc, id) => {
38
- const view = g.getNodeAttribute(id, "view");
39
- if (!isExtendsElementView(view)) {
40
- acc[view.id] = view;
41
- return acc;
42
- }
43
- const extendsFrom = acc[view.extends];
44
- if (!extendsFrom || !isElementView(extendsFrom)) {
45
- return acc;
46
- }
47
- const tags = n([
48
- ...extendsFrom.tags ?? [],
49
- ...view.tags ?? []
50
- ]);
51
- const links = [
52
- ...extendsFrom.links ?? [],
53
- ...view.links ?? []
54
- ];
55
- acc[view.id] = {
56
- ...extendsFrom,
57
- ...view,
58
- title: view.title ?? extendsFrom.title ?? null,
59
- description: view.description ?? extendsFrom.description ?? null,
60
- tags,
61
- links: isNonEmptyArray(links) ? links : null,
62
- rules: [...extendsFrom.rules, ...view.rules]
63
- };
64
- return acc;
65
- }, {});
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
+ }, {});
66
65
  }
67
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
+ */
68
73
  function withReadableEdges({ edges, nodes, ...view }, separator = ":") {
69
- const edgeids = t$2(edges, (e) => [e.id, `${e.source}${separator}${e.target}`]);
70
- return {
71
- ...view,
72
- edges: edges.map((e) => ({
73
- ...e,
74
- id: edgeids[e.id]
75
- })),
76
- nodes: nodes.map((n) => ({
77
- ...n,
78
- inEdges: t$3(n.inEdges, (e) => edgeids[e]),
79
- outEdges: t$3(n.outEdges, (e) => edgeids[e])
80
- })),
81
- nodeIds: nodes.map((n) => n.id),
82
- edgeIds: edges.map((e) => edgeids[e.id])
83
- };
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
+ };
84
89
  }
85
90
  function viewsWithReadableEdges({ views, ...model }) {
86
- return {
87
- ...model,
88
- views: t$1(views, (v) => n$1(withReadableEdges(v), ["nodeIds", "edgeIds"]))
89
- };
91
+ return {
92
+ ...model,
93
+ views: t$3(views, (v) => n$1(withReadableEdges(v), ["nodeIds", "edgeIds"]))
94
+ };
90
95
  }
91
96
 
92
- export { resolveRulesExtendedViews, viewsWithReadableEdges, withReadableEdges };
97
+ //#endregion
98
+ //#region src/compute-view/projects-view/compute.ts
99
+ const keysCount = (object) => t$4(object).length;
100
+ const nodeId = (projectId) => stringHash(projectId);
101
+ /**
102
+ * Computes an overview of projects and their relationships
103
+ */
104
+ function computeProjectsView(likec4models) {
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
+ };
172
+ }
173
+ function buildNodesForEachModel(likec4models) {
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
+ };
226
+ }
227
+
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 };
@@ -1,51 +1,16 @@
1
- import { A as Any, U as Unknown, a as ElementId, V as ViewId } from '../../shared/core.D00YbOhQ.mjs';
2
- import { E as ElementModel, R as RelationshipModel, f as LikeC4Model } from '../../shared/core.C-Jdx7xo.mjs';
3
- import 'type-fest';
4
- import '../../shared/core.DB0Ue5Wx.mjs';
5
- import '../../shared/core.C_3y3eqV.mjs';
6
- import '../../shared/core.DeDCYTDR.mjs';
7
- import '../../shared/core.BvPm_-u3.mjs';
8
- import '../../types/fqnRef.mjs';
9
- import '../../shared/core.DpKY_3NF.mjs';
10
- import '../../types/expression-model.mjs';
11
- import '../../shared/core.BPGOjone.mjs';
12
- import '../../shared/core.CywrQs86.mjs';
13
- import '../../shared/core.Ctj2S3bD.mjs';
14
-
15
- type RelationshipsViewData<M extends Any = Unknown> = {
16
- incomers: ReadonlySet<ElementModel<M>>;
17
- incoming: ReadonlySet<RelationshipModel<M>>;
18
- subjects: ReadonlySet<ElementModel<M>>;
19
- outgoing: ReadonlySet<RelationshipModel<M>>;
20
- outgoers: ReadonlySet<ElementModel<M>>;
21
- };
22
-
23
- declare function computeRelationshipsView<M extends Any>(subjectId: ElementId<M>, likec4model: LikeC4Model<M>, scopeViewId: ViewId<M> | null, scope?: 'global' | 'view'): RelationshipsViewData<M>;
24
-
25
- declare function treeFromElements<M extends Any>(elements: Iterable<ElementModel<M>>): {
26
- sorted: readonly ElementModel<M>[];
27
- byId: (id: ElementId<M>) => ElementModel<M>;
28
- root: ReadonlySet<ElementModel<M>>;
29
- parent: (el: ElementModel<M>) => ElementModel<M> | null;
30
- children: (el: ElementModel<M>) => ReadonlyArray<ElementModel<M>>;
31
- /**
32
- * Flattens the tree structure by removing redundant hierarchy levels.
33
- * @example
34
- * A
35
- * └── B
36
- * ├── C
37
- * │ └── D
38
- * │ └── E
39
- * └── F
40
- * └── G
41
- * becomes
42
- * A
43
- * ├── C
44
- * │ └── E
45
- * └── F
46
- * └── G
47
- */
48
- flatten: () => Set<ElementModel<M>>;
49
- };
50
-
51
- export { type RelationshipsViewData, computeRelationshipsView, treeFromElements };
1
+ import "../../_chunks/_aux.mjs";
2
+ import "../../_chunks/scalar.mjs";
3
+ import "../../_chunks/expression.mjs";
4
+ import "../../_chunks/fqnRef.mjs";
5
+ import "../../_chunks/expression-model.mjs";
6
+ import "../../_chunks/index2.mjs";
7
+ import "../../_chunks/RichText.mjs";
8
+ import "../../_chunks/index3.mjs";
9
+ import "../../_chunks/LikeC4Model.mjs";
10
+ import "../../_chunks/const.mjs";
11
+ import "../../_chunks/find.mjs";
12
+ import "../../_chunks/find2.mjs";
13
+ import "../../_chunks/index4.mjs";
14
+ import "../../_chunks/index5.mjs";
15
+ import { n as computeRelationshipsView, r as RelationshipsViewData, t as treeFromElements } from "../../_chunks/index6.mjs";
16
+ export { RelationshipsViewData, computeRelationshipsView, treeFromElements };