@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,786 +1,9 @@
1
- import { u, o as o$1, b as invariant, c as isScopedElementView, D as DeploymentElement, d as DefaultThemeColor, e as DefaultElementShape } from './shared/core.k12s_keD.mjs';
2
- export { A as AsFqn, B as BorderStyles, H as ComputedNode, I as ComputedView, h as DeploymentElementExpression, j as DeploymentExpression, g as DeploymentRelationExpression, K as DiagramNode, E as ElementKind, k as ElementShapes, F as extractStep, J as getBBoxCenter, G as getParallelStepsPrefix, r as isAutoLayoutDirection, w as isDeploymentView, x as isDynamicView, v as isDynamicViewParallelSteps, y as isElementView, i as isExtendsElementView, C as isStepEdgeId, s as isViewRuleAutoLayout, m as isViewRuleGlobalPredicateRef, q as isViewRuleGlobalStyle, t as isViewRuleGroup, l as isViewRulePredicate, p as isViewRuleStyle, f as nonNullable, n as nonexhaustive, z as stepEdgeId } from './shared/core.k12s_keD.mjs';
3
- import { m, l, c as computeViews, b as i, g as i$1, h as d, j as l$1 } from './shared/core.BQ4AbfvB.mjs';
4
- export { n as commonHead, k as compareRelations, o as objectHash, s as stringHash } from './shared/core.BQ4AbfvB.mjs';
5
- import { t as t$1, p as parentFqn, i as isSameHierarchy, L as LikeC4Model, n as nameFromFqn } from './shared/core.BPyJvuMU.mjs';
6
- export { a as LikeC4DeploymentModel, b as LikeC4ViewModel, l as ancestorsFqn, k as commonAncestor, o as compareByFqnHierarchically, m as compareFqnHierarchically, c as compareNatural, A as difference, B as equals, v as getOrCreate, D as hasIntersection, h as hierarchyDepth, j as hierarchyDistance, z as intersection, e as isAncestor, f as isDescendantOf, x as isNonEmptyArray, w as isString, g as notDescendantOf, d as parentFqnPredicate, s as sortByFqnHierarchically, u as sortNaturalByFqn, q as sortParentsFirst, C as symmetricDifference, y as union } from './shared/core.BPyJvuMU.mjs';
7
- import { i as isElementPredicateExpr } from './shared/core.BBgiAAv1.mjs';
8
- export { y as DefaultArrowType, D as DefaultLineStyle, z as DefaultRelationshipColor, e as Expr, v as isAndOperator, c as isCustomElement, q as isCustomRelationExpr, h as isElement, f as isElementKindExpr, a as isElementRef, g as isElementTagExpr, j as isElementWhere, b as isExpandedElementExpr, l as isInOut, m as isIncoming, t as isKindEqual, u as isNotOperator, w as isOrOperator, n as isOutgoing, k as isRelation, o as isRelationExpression, r as isRelationPredicateExpr, p as isRelationWhere, s as isTagEqual, d as isWildcard, x as whereOperatorAsPredicate } from './shared/core.BBgiAAv1.mjs';
9
- import defu from 'defu';
10
- export { isThemeColor } from './types/index.mjs';
11
-
12
- function o(r,n){let e=Math.ceil(r),t=Math.floor(n);if(t<e)throw new RangeError(`randomInteger: The range [${r.toString()},${n.toString()}] contains no integer`);return Math.floor(Math.random()*(t-e+1)+e)}
13
-
14
- function t(n){return typeof n=="function"}
15
-
16
- function n(...r){return u(Object.fromEntries,r)}
17
-
18
- const DELAY = "LIKEC4_DELAY";
19
- function delay(...args) {
20
- let ms = 100;
21
- if (args.length === 2) {
22
- ms = o(args[0], args[1]);
23
- } else if (args.length === 1) {
24
- ms = args[0];
25
- }
26
- return new Promise((resolve) => {
27
- setTimeout(() => {
28
- resolve(DELAY);
29
- }, ms ?? 100);
30
- });
31
- }
32
-
33
- function parseWhere(where) {
34
- if (t$1(where)) {
35
- const op = where;
36
- switch (true) {
37
- case op.startsWith("tag is not #"):
38
- return {
39
- tag: {
40
- neq: op.replace("tag is not #", "")
41
- }
42
- };
43
- case op.startsWith("tag is #"):
44
- return {
45
- tag: {
46
- eq: op.replace("tag is #", "")
47
- }
48
- };
49
- case op.startsWith("kind is not "):
50
- return {
51
- kind: {
52
- neq: op.replace("kind is not ", "")
53
- }
54
- };
55
- case op.startsWith("kind is "):
56
- return {
57
- kind: {
58
- eq: op.replace("kind is ", "")
59
- }
60
- };
61
- default:
62
- throw new Error(`Unknown where operator: ${where}`);
63
- }
64
- }
65
- if (where.and) {
66
- return {
67
- and: m(where.and, parseWhere)
68
- };
69
- }
70
- if (where.or) {
71
- return {
72
- or: m(where.or, parseWhere)
73
- };
74
- }
75
- if (where.not) {
76
- return {
77
- not: parseWhere(where.not)
78
- };
79
- }
80
- throw new Error(`Unknown where operator: ${where}`);
81
- }
82
- function $include(...args) {
83
- return (b) => {
84
- let expr = b.$expr(args[0]);
85
- if (args.length === 2) {
86
- const condition = args[1].where ? parseWhere(args[1].where) : void 0;
87
- if (condition) {
88
- expr = {
89
- where: {
90
- expr,
91
- condition
92
- }
93
- };
94
- }
95
- const custom = args[1].with;
96
- if (custom) {
97
- const isElement = isElementPredicateExpr(expr);
98
- if (isElement) {
99
- expr = {
100
- custom: {
101
- ...custom,
102
- expr
103
- }
104
- };
105
- } else {
106
- expr = {
107
- customRelation: {
108
- ...custom,
109
- relation: expr
110
- }
111
- };
112
- }
113
- }
114
- }
115
- b.include(expr);
116
- return b;
117
- };
118
- }
119
- function $exclude(...args) {
120
- return (b) => {
121
- let expr = b.$expr(args[0]);
122
- if (args.length === 2 && args[1].where) {
123
- const condition = parseWhere(args[1].where);
124
- expr = {
125
- where: {
126
- expr,
127
- condition
128
- }
129
- };
130
- }
131
- b.exclude(expr);
132
- return b;
133
- };
134
- }
135
- const asTypedExpr = (expr) => {
136
- return expr;
137
- };
138
- function $expr(expr) {
139
- if (!t$1(expr)) {
140
- return expr;
141
- }
142
- if (expr === "*") {
143
- return asTypedExpr({ wildcard: true });
144
- }
145
- if (expr.startsWith("->")) {
146
- if (expr.endsWith("->")) {
147
- return asTypedExpr({
148
- inout: $expr(expr.replace(/->/g, "").trim())
149
- });
150
- }
151
- return asTypedExpr({
152
- incoming: $expr(expr.replace("-> ", ""))
153
- });
154
- }
155
- if (expr.endsWith(" ->")) {
156
- return asTypedExpr({
157
- outgoing: $expr(expr.replace(" ->", ""))
158
- });
159
- }
160
- if (expr.includes(" <-> ")) {
161
- const [source, target] = expr.split(" <-> ");
162
- return asTypedExpr({
163
- source: $expr(source),
164
- target: $expr(target),
165
- isBidirectional: true
166
- });
167
- }
168
- if (expr.includes(" -> ")) {
169
- const [source, target] = expr.split(" -> ");
170
- return asTypedExpr({
171
- source: $expr(source),
172
- target: $expr(target)
173
- });
174
- }
175
- if (expr.endsWith("._")) {
176
- return asTypedExpr({
177
- expanded: expr.replace("._", "")
178
- });
179
- }
180
- if (expr.endsWith(".*")) {
181
- return asTypedExpr({
182
- element: expr.replace(".*", ""),
183
- isChildren: true
184
- });
185
- }
186
- if (expr.endsWith(".**")) {
187
- return asTypedExpr({
188
- element: expr.replace(".**", ""),
189
- isDescendants: true
190
- });
191
- }
192
- return asTypedExpr({
193
- element: expr
194
- });
195
- }
196
- const asTypedDeploymentExpression = (expr) => {
197
- return expr;
198
- };
199
- function $deploymentExpr(expr) {
200
- if (!t$1(expr)) {
201
- return expr;
202
- }
203
- if (expr === "*") {
204
- return asTypedDeploymentExpression({ wildcard: true });
205
- }
206
- if (expr.startsWith("->")) {
207
- if (expr.endsWith("->")) {
208
- return asTypedDeploymentExpression({
209
- inout: $deploymentExpr(expr.replace(/->/g, "").trim())
210
- });
211
- }
212
- return asTypedDeploymentExpression({
213
- incoming: $deploymentExpr(expr.replace("-> ", ""))
214
- });
215
- }
216
- if (expr.endsWith(" ->")) {
217
- return asTypedDeploymentExpression({
218
- outgoing: $deploymentExpr(expr.replace(" ->", ""))
219
- });
220
- }
221
- if (expr.includes(" <-> ")) {
222
- const [source, target] = expr.split(" <-> ");
223
- return asTypedDeploymentExpression({
224
- source: $deploymentExpr(source),
225
- target: $deploymentExpr(target),
226
- isBidirectional: true
227
- });
228
- }
229
- if (expr.includes(" -> ")) {
230
- const [source, target] = expr.split(" -> ");
231
- return asTypedDeploymentExpression({
232
- source: $deploymentExpr(source),
233
- target: $deploymentExpr(target)
234
- });
235
- }
236
- if (expr.endsWith("._")) {
237
- return asTypedDeploymentExpression({
238
- ref: {
239
- id: expr.replace("._", "")
240
- },
241
- selector: "expanded"
242
- });
243
- }
244
- if (expr.endsWith(".**")) {
245
- return asTypedDeploymentExpression({
246
- ref: {
247
- id: expr.replace(".**", "")
248
- },
249
- selector: "descendants"
250
- });
251
- }
252
- if (expr.endsWith(".*")) {
253
- return asTypedDeploymentExpression({
254
- ref: {
255
- id: expr.replace(".*", "")
256
- },
257
- selector: "children"
258
- });
259
- }
260
- return asTypedDeploymentExpression({
261
- ref: {
262
- id: expr
263
- }
264
- });
265
- }
266
- function $style(element, { notation, ...style }) {
267
- return (b) => b.style({
268
- targets: (o$1(element) ? element : [element]).map((e) => b.$expr(e)),
269
- ...notation ? { notation } : {},
270
- style: {
271
- ...style
272
- }
273
- });
274
- }
275
- function $autoLayout(layout) {
276
- return (b) => b.autoLayout(layout);
277
- }
278
- function $rules(...rules) {
279
- return (b) => rules.reduce((b2, rule) => rule(b2), b);
280
- }
281
- function mkViewBuilder(view) {
282
- const viewBuilder = {
283
- $expr: view.__ === "deployment" ? $deploymentExpr : $expr,
284
- autoLayout(autoLayout) {
285
- view.rules.push({
286
- direction: autoLayout
287
- });
288
- return viewBuilder;
289
- },
290
- exclude(expr) {
291
- view.rules.push({
292
- exclude: [expr]
293
- });
294
- return viewBuilder;
295
- },
296
- include(expr) {
297
- view.rules.push({
298
- include: [expr]
299
- });
300
- return viewBuilder;
301
- },
302
- style(rule) {
303
- view.rules.push(rule);
304
- return viewBuilder;
305
- }
306
- // title(title: string) {
307
- // view.title = title
308
- // return viewBuilder
309
- // },
310
- // description(description: string) {
311
- // view.description = description
312
- // return viewBuilder
313
- // }
314
- };
315
- return viewBuilder;
316
- }
317
-
318
- function builder(spec, _elements = /* @__PURE__ */ new Map(), _relations = [], _views = /* @__PURE__ */ new Map(), _globals = {
319
- predicates: {},
320
- dynamicPredicates: {},
321
- styles: {}
322
- }, _deployments = /* @__PURE__ */ new Map(), _deploymentRelations = []) {
323
- const toLikeC4Specification = () => ({
324
- elements: {
325
- ...spec.elements
326
- },
327
- deployments: {
328
- ...spec.deployments
329
- },
330
- relationships: {
331
- ...spec.relationships
332
- },
333
- tags: spec.tags ?? []
334
- });
335
- const mapLinks = (links) => {
336
- if (!links || !i$1(links, 1)) {
337
- return null;
338
- }
339
- return m(links, (l) => typeof l === "string" ? { url: l } : l);
340
- };
341
- const self = {
342
- get Types() {
343
- throw new Error("Types are not available in runtime");
344
- },
345
- clone: () => {
346
- return builder(
347
- structuredClone(spec),
348
- structuredClone(_elements),
349
- structuredClone(_relations),
350
- structuredClone(_views),
351
- structuredClone(_globals),
352
- structuredClone(_deployments),
353
- structuredClone(_deploymentRelations)
354
- );
355
- },
356
- __model: () => ({
357
- addElement: (element) => {
358
- const parent = parentFqn(element.id);
359
- if (parent) {
360
- invariant(
361
- _elements.get(parent),
362
- `Parent element with id "${parent}" not found for element with id "${element.id}"`
363
- );
364
- }
365
- if (_elements.has(element.id)) {
366
- throw new Error(`Element with id "${element.id}" already exists`);
367
- }
368
- _elements.set(element.id, element);
369
- return self;
370
- },
371
- addRelation(relation) {
372
- const sourceEl = _elements.get(relation.source);
373
- invariant(sourceEl, `Element with id "${relation.source}" not found`);
374
- const targetEl = _elements.get(relation.target);
375
- invariant(targetEl, `Element with id "${relation.target}" not found`);
376
- invariant(
377
- !isSameHierarchy(sourceEl, targetEl),
378
- "Cannot create relationship between elements in the same hierarchy"
379
- );
380
- _relations.push({
381
- id: `rel${_relations.length + 1}`,
382
- ...relation
383
- });
384
- return self;
385
- },
386
- /**
387
- * Fully qualified name for nested elements
388
- */
389
- fqn(id) {
390
- return id;
391
- },
392
- addSourcelessRelation() {
393
- throw new Error("Can be called only in nested model");
394
- }
395
- }),
396
- __views: () => ({
397
- addView: (view) => {
398
- if (isScopedElementView(view)) {
399
- invariant(_elements.get(view.viewOf), `Invalid view ${view.id}, wlement with id "${view.viewOf}" not found`);
400
- }
401
- _views.set(view.id, view);
402
- return self;
403
- }
404
- }),
405
- __deployment: () => ({
406
- addDeployment: (node) => {
407
- if (_deployments.has(node.id)) {
408
- throw new Error(`Deployment with id "${node.id}" already exists`);
409
- }
410
- const parent = parentFqn(node.id);
411
- if (parent) {
412
- invariant(
413
- _deployments.get(parent),
414
- `Parent element with id "${parent}" not found for node with id "${node.id}"`
415
- );
416
- }
417
- if (DeploymentElement.isInstance(node)) {
418
- invariant(parent, "Instance must have parent");
419
- }
420
- _deployments.set(node.id, node);
421
- return self;
422
- },
423
- addDeploymentRelation: (relation) => {
424
- invariant(
425
- !isSameHierarchy(relation.source.id, relation.target.id),
426
- "Cannot create relationship between elements in the same hierarchy"
427
- );
428
- _deploymentRelations.push({
429
- id: `deploy_rel${_deploymentRelations.length + 1}`,
430
- ...relation
431
- });
432
- return self;
433
- },
434
- fqn: (id) => id
435
- }),
436
- build: () => ({
437
- specification: toLikeC4Specification(),
438
- elements: n(Array.from(_elements.entries())),
439
- relations: l(_relations, (r) => [r.id, r]),
440
- globals: structuredClone(_globals),
441
- deployments: {
442
- elements: n(Array.from(_deployments.entries())),
443
- relations: l(_deploymentRelations, (r) => [r.id, r])
444
- },
445
- views: n(Array.from(_views.entries()))
446
- }),
447
- buildComputedModel: () => {
448
- const parsed = self.build();
449
- const computed = computeViews(parsed);
450
- return LikeC4Model.create(computed);
451
- },
452
- helpers: () => ({
453
- model: {
454
- model: (...ops) => {
455
- return (b) => {
456
- const v = b.__model();
457
- for (const op of ops) {
458
- op(v);
459
- }
460
- return b;
461
- };
462
- },
463
- rel: (source, target, _props) => {
464
- return (b) => {
465
- const {
466
- title = "",
467
- links: _links = [],
468
- ...props
469
- } = defu(
470
- typeof _props === "string" ? { title: _props } : { ..._props },
471
- { title: null, links: null }
472
- );
473
- const links = mapLinks(_links);
474
- b.addRelation({
475
- source,
476
- target,
477
- title,
478
- ...links && { links },
479
- ...props
480
- });
481
- return b;
482
- };
483
- },
484
- relTo: (target, _props) => {
485
- return (b) => {
486
- const {
487
- title = "",
488
- links: _links = [],
489
- ...props
490
- } = defu(
491
- typeof _props === "string" ? { title: _props } : { ..._props },
492
- { title: null, links: null }
493
- );
494
- const links = mapLinks(_links);
495
- b.addSourcelessRelation({
496
- target,
497
- title,
498
- ...links && { links },
499
- ...props
500
- });
501
- return b;
502
- };
503
- },
504
- ...i(
505
- spec.elements,
506
- ({ style: specStyle, ...spec2 }, kind) => (id, _props) => {
507
- const add = (b) => {
508
- const {
509
- links: _links,
510
- icon: _icon,
511
- style,
512
- title,
513
- ...props
514
- } = typeof _props === "string" ? { title: _props } : { ..._props };
515
- const links = mapLinks(_links);
516
- const icon = _icon ?? specStyle?.icon;
517
- const _id = b.fqn(id);
518
- b.addElement({
519
- id: _id,
520
- kind,
521
- title: title ?? nameFromFqn(_id),
522
- description: null,
523
- technology: null,
524
- tags: null,
525
- color: specStyle?.color ?? DefaultThemeColor,
526
- shape: specStyle?.shape ?? DefaultElementShape,
527
- style: d({
528
- border: specStyle?.border,
529
- opacity: specStyle?.opacity,
530
- ...style
531
- }, l$1),
532
- links,
533
- ...icon && { icon },
534
- ...spec2,
535
- ...props
536
- });
537
- return b;
538
- };
539
- add.with = (...ops) => (b) => {
540
- add(b);
541
- const nestedBuilder = {
542
- ...b,
543
- fqn: (child) => `${b.fqn(id)}.${child}`,
544
- addSourcelessRelation: (relation) => {
545
- return b.addRelation({
546
- ...relation,
547
- source: b.fqn(id)
548
- });
549
- }
550
- };
551
- for (const op of ops) {
552
- op(nestedBuilder);
553
- }
554
- return b;
555
- };
556
- return add;
557
- }
558
- )
559
- },
560
- views: {
561
- views: (...ops) => {
562
- return (b) => {
563
- const v = b.__views();
564
- for (const op of ops) {
565
- op(v);
566
- }
567
- return b;
568
- };
569
- },
570
- view: (id, _props, builder2) => {
571
- if (t(_props)) {
572
- builder2 = _props;
573
- _props = {};
574
- }
575
- return (b) => {
576
- const {
577
- links: _links = [],
578
- title = null,
579
- ...props
580
- } = typeof _props === "string" ? { title: _props } : { ..._props };
581
- const links = mapLinks(_links);
582
- const view = {
583
- id,
584
- __: "element",
585
- title,
586
- description: null,
587
- tags: null,
588
- rules: [],
589
- links,
590
- customColorDefinitions: {},
591
- ...props
592
- };
593
- b.addView(view);
594
- if (builder2) {
595
- builder2(mkViewBuilder(view));
596
- }
597
- return b;
598
- };
599
- },
600
- viewOf: (id, viewOf, _props, builder2) => {
601
- if (t(_props)) {
602
- builder2 = _props;
603
- _props = {};
604
- }
605
- return (b) => {
606
- const {
607
- links: _links = [],
608
- title = null,
609
- ...props
610
- } = typeof _props === "string" ? { title: _props } : { ..._props };
611
- const links = mapLinks(_links);
612
- const view = {
613
- id,
614
- __: "element",
615
- viewOf,
616
- title,
617
- description: null,
618
- tags: null,
619
- rules: [],
620
- links,
621
- customColorDefinitions: {},
622
- ...props
623
- };
624
- b.addView(view);
625
- if (builder2) {
626
- builder2(mkViewBuilder(view));
627
- }
628
- return b;
629
- };
630
- },
631
- deploymentView: (id, _props, builder2) => {
632
- if (t(_props)) {
633
- builder2 = _props;
634
- _props = {};
635
- }
636
- return (b) => {
637
- const {
638
- links: _links = [],
639
- title = null,
640
- ...props
641
- } = typeof _props === "string" ? { title: _props } : { ..._props };
642
- const links = mapLinks(_links);
643
- const view = {
644
- id,
645
- __: "deployment",
646
- title,
647
- description: null,
648
- tags: null,
649
- rules: [],
650
- links,
651
- customColorDefinitions: {},
652
- ...props
653
- };
654
- b.addView(view);
655
- if (builder2) {
656
- builder2(mkViewBuilder(view));
657
- }
658
- return b;
659
- };
660
- },
661
- $autoLayout,
662
- $exclude,
663
- $include,
664
- $rules,
665
- $style
666
- },
667
- deployment: {
668
- deployment: (...ops) => {
669
- return (b) => {
670
- const v = b.__deployment();
671
- for (const op of ops) {
672
- op(v);
673
- }
674
- return b;
675
- };
676
- },
677
- instanceOf: (id, to, _props) => {
678
- return (b) => {
679
- const {
680
- links,
681
- title,
682
- ...props
683
- } = typeof _props === "string" ? { title: _props } : { ..._props };
684
- const _id = b.fqn(id);
685
- invariant(_elements.has(to), `Target element with id "${to}" not found`);
686
- b.addDeployment({
687
- id: _id,
688
- element: to,
689
- ...title && { title },
690
- ...links && { links: mapLinks(links) },
691
- ...props
692
- });
693
- return b;
694
- };
695
- },
696
- rel: (source, target, _props) => {
697
- return (b) => {
698
- const {
699
- title,
700
- links,
701
- ...props
702
- } = typeof _props === "string" ? { title: _props } : { ..._props };
703
- b.addDeploymentRelation({
704
- source: {
705
- id: source
706
- },
707
- target: {
708
- id: target
709
- },
710
- ...title && { title },
711
- ...links && { links: mapLinks(links) },
712
- ...props
713
- });
714
- return b;
715
- };
716
- },
717
- ...i(
718
- spec.deployments ?? {},
719
- ({ style: specStyle, ...spec2 }, kind) => (id, _props) => {
720
- const add = (b) => {
721
- const {
722
- links,
723
- icon: _icon,
724
- style,
725
- title,
726
- ...props
727
- } = typeof _props === "string" ? { title: _props } : { ..._props };
728
- const icon = _icon ?? specStyle?.icon;
729
- const _id = b.fqn(id);
730
- b.addDeployment({
731
- id: _id,
732
- kind,
733
- title: title ?? nameFromFqn(_id),
734
- description: null,
735
- technology: null,
736
- tags: null,
737
- color: specStyle?.color ?? DefaultThemeColor,
738
- shape: specStyle?.shape ?? DefaultElementShape,
739
- style: d({
740
- border: specStyle?.border,
741
- opacity: specStyle?.opacity,
742
- ...style
743
- }, l$1),
744
- ...links && { links: mapLinks(links) },
745
- ...icon && { icon },
746
- ...spec2,
747
- ...props
748
- });
749
- return b;
750
- };
751
- add.with = (...ops) => (b) => {
752
- add(b);
753
- const nestedBuilder = {
754
- ...b,
755
- fqn: (child) => `${b.fqn(id)}.${child}`
756
- };
757
- for (const op of ops) {
758
- op(nestedBuilder);
759
- }
760
- return b;
761
- };
762
- return add;
763
- }
764
- )
765
- }
766
- }),
767
- with: (...ops) => {
768
- return ops.reduce((b, op) => op(b), self).clone();
769
- }
770
- };
771
- return self;
772
- }
773
- var Builder;
774
- ((Builder2) => {
775
- function forSpecification(spec) {
776
- const b = builder(spec);
777
- return {
778
- ...b.helpers(),
779
- builder: b
780
- };
781
- }
782
- Builder2.forSpecification = forSpecification;
783
- })(Builder || (Builder = {}));
1
+ export { i as invariant, a as nonNullable, n as nonexhaustive } from './shared/chunk-RAAYCPUM.M-JWF7SS.js';
2
+ export { A as AsFqn, B as BorderStyles, Q as ComputedNode, S as ComputedView, N as DefaultArrowType, e as DefaultElementShape, O as DefaultLineStyle, P as DefaultRelationshipColor, d as DefaultThemeColor, D as DeploymentElement, T as DiagramNode, E as ElementKind, g as ElementShapes, f as Expr, C as ExpressionV2, F as FqnExpr, G as FqnRef, R as RelationExpr, U as extractStep, V as getBBoxCenter, W as getParallelStepsPrefix, H as isAndOperator, X as isAutoLayoutDirection, h as isCustomElement, j as isCustomRelationExpr, Y as isDeploymentView, Z as isDynamicView, _ as isDynamicViewParallelSteps, k as isElement, l as isElementKindExpr, b as isElementPredicateExpr, m as isElementRef, p as isElementTagExpr, a as isElementView, q as isElementWhere, r as isExpandedElementExpr, i as isExtendsElementView, t as isInOut, s as isIncoming, I as isKindEqual, J as isNotOperator, K as isOrOperator, u as isOutgoing, v as isRelation, w as isRelationExpression, x as isRelationPredicateExpr, y as isRelationWhere, c as isScopedElementView, $ as isStepEdgeId, L as isTagEqual, a0 as isViewRuleAutoLayout, a1 as isViewRuleGlobalPredicateRef, a2 as isViewRuleGlobalStyle, a3 as isViewRuleGroup, a4 as isViewRulePredicate, a5 as isViewRuleStyle, z as isWildcard, a6 as stepEdgeId, M as whereOperatorAsPredicate } from './shared/view.CyZrG8BJ.js';
3
+ export { b as LikeC4DeploymentModel, L as LikeC4Model, e as LikeC4ViewModel } from './shared/index.DafVOuVd.js';
4
+ export { isThemeColor } from './types/index.js';
5
+ export { D as DefaultMap, e as ancestorsFqn, f as commonAncestor, c as commonHead, g as compareByFqnHierarchically, h as compareFqnHierarchically, d as compareNatural, H as difference, I as equalsSet, v as getOrCreate, i as hasAtLeast, j as hierarchyDistance, k as hierarchyLevel, y as ifilter, z as iflat, A as imap, J as intersection, o as isAncestor, q as isDescendantOf, B as isIterable, w as isNonEmptyArray, a as isSameHierarchy, x as isString, C as isome, E as iunique, n as nameFromFqn, N as objectHash, p as parentFqn, s as sortByFqnHierarchically, r as sortNaturalByFqn, u as sortParentsFirst, M as stringHash, K as symmetricDifference, F as toArray, G as toSet, L as union } from './shared/object_hash.CE_oF3I3.js';
6
+ export { LinkedList, compareRelations, delay, ifind, ireduce } from './utils/index.js';
784
7
 
785
8
  const { min: min$4, max: max$4 } = Math;
786
9
 
@@ -4446,4 +3669,4 @@ function computeColorValues(color) {
4446
3669
  }
4447
3670
  }
4448
3671
 
4449
- export { Builder, DefaultElementShape, DefaultThemeColor, DeploymentElement, ElementColors, LikeC4Model, RelationshipColors, computeColorValues, defaultTheme, delay, i$1 as hasAtLeast, invariant, isElementPredicateExpr, isSameHierarchy, isScopedElementView, nameFromFqn, parentFqn };
3672
+ export { ElementColors, RelationshipColors, computeColorValues, defaultTheme };