@likec4/core 1.32.1 → 1.33.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 (101) hide show
  1. package/dist/builder/index.d.mts +10 -6
  2. package/dist/builder/index.mjs +45 -13
  3. package/dist/compute-view/index.d.mts +6 -4
  4. package/dist/compute-view/index.mjs +33 -10
  5. package/dist/compute-view/relationships-view/index.d.mts +6 -4
  6. package/dist/compute-view/relationships-view/index.mjs +6 -3
  7. package/dist/index.d.mts +9 -138
  8. package/dist/index.mjs +31 -3712
  9. package/dist/model/connection/deployment/index.d.mts +10 -0
  10. package/dist/model/connection/deployment/index.mjs +18 -0
  11. package/dist/model/connection/index.d.mts +70 -0
  12. package/dist/model/connection/index.mjs +23 -0
  13. package/dist/model/connection/model/index.d.mts +10 -0
  14. package/dist/model/connection/model/index.mjs +11 -0
  15. package/dist/model/index.d.mts +14 -256
  16. package/dist/model/index.mjs +27 -5
  17. package/dist/shared/{core.DXzRBkuI.d.mts → core.1pNeDdRk.d.mts} +92 -81
  18. package/dist/shared/{core.BuO4ncfY.d.mts → core.668kXpZq.d.mts} +42 -52
  19. package/dist/shared/core.8KM0D6va.mjs +33 -0
  20. package/dist/shared/core.B0oEIXqd.mjs +47 -0
  21. package/dist/shared/core.BH9nN-_I.mjs +22 -0
  22. package/dist/shared/core.BMCb0wJI.mjs +177 -0
  23. package/dist/shared/core.BTnf14gD.mjs +331 -0
  24. package/dist/shared/core.BgvIuGGU.mjs +3 -0
  25. package/dist/shared/core.BoyJPEen.mjs +21 -0
  26. package/dist/shared/{core.CUYDgv2-.mjs → core.Br7Fab9l.mjs} +12 -15
  27. package/dist/shared/{core.BrCnZFTn.mjs → core.Btl47GOn.mjs} +3 -3
  28. package/dist/shared/core.ByrmCl9I.mjs +5 -0
  29. package/dist/shared/core.C80Z37Eu.mjs +29 -0
  30. package/dist/shared/{core.Pf5I9o0e.d.mts → core.CF82MWyh.d.mts} +1 -1
  31. package/dist/shared/{core.rmvsy0n3.mjs → core.C_C-3c1S.mjs} +5 -198
  32. package/dist/shared/core.CeQbbp7K.d.mts +41 -0
  33. package/dist/shared/{core.DoK86JEe.mjs → core.CpwrZi3D.mjs} +2 -73
  34. package/dist/shared/{core.CpXlRyE5.mjs → core.CtKXPqN_.mjs} +5 -36
  35. package/dist/shared/core.CxGKeL-L.mjs +144 -0
  36. package/dist/shared/core.CzdwsPmY.d.mts +69 -0
  37. package/dist/shared/{core.Cy9smucx.mjs → core.D4npX2q8.mjs} +1 -3
  38. package/dist/shared/core.D56nCp7e.mjs +168 -0
  39. package/dist/shared/core.D5qVzkws.mjs +724 -0
  40. package/dist/shared/core.DDAPzd3T.d.mts +87 -0
  41. package/dist/shared/{core.CBpKAlhj.mjs → core.DDynPqbh.mjs} +96 -56
  42. package/dist/shared/{core.Bk7wEZFG.mjs → core.DXRAwwDB.mjs} +3 -2
  43. package/dist/shared/core.DcS-0zys.mjs +10 -0
  44. package/dist/shared/{core.BaYE_r29.d.mts → core.De___iBS.d.mts} +4 -3
  45. package/dist/shared/core.DsMrjY2q.mjs +34 -0
  46. package/dist/shared/core.DuSLYTG6.d.mts +57 -0
  47. package/dist/shared/core.Dy-F3xRP.d.mts +83 -0
  48. package/dist/shared/{core.znRaUX_A.d.mts → core.OLInHaJx.d.mts} +48 -41
  49. package/dist/shared/core.XptQjhMA.mjs +1295 -0
  50. package/dist/shared/{core.cbA9VZ02.mjs → core.hoq9W4rW.mjs} +28 -1073
  51. package/dist/shared/core.zLlww-07.mjs +3 -0
  52. package/dist/theme/index.d.mts +134 -0
  53. package/dist/theme/index.mjs +3709 -0
  54. package/dist/types/aux.d.mts +3 -2
  55. package/dist/types/index.d.mts +9 -5
  56. package/dist/types/index.mjs +17 -146
  57. package/dist/utils/index.d.mts +16 -100
  58. package/dist/utils/index.mjs +25 -1312
  59. package/dist/utils/iterable/index.d.mts +100 -0
  60. package/dist/utils/iterable/index.mjs +24 -0
  61. package/package.json +26 -10
  62. package/src/builder/Builder.ts +13 -4
  63. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +0 -13
  64. package/src/builder/__snapshots__/Builder-style2.compute-model.json5 +2 -6
  65. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +0 -7
  66. package/src/builder/_types.ts +6 -2
  67. package/src/compute-view/deployment-view/__test__/fixture.ts +15 -5
  68. package/src/compute-view/deployment-view/utils.ts +13 -13
  69. package/src/compute-view/dynamic-view/compute.ts +2 -1
  70. package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +2 -2
  71. package/src/compute-view/relationships-view/layout.ts +1 -1
  72. package/src/compute-view/utils/applyCustomElementProperties.ts +8 -0
  73. package/src/compute-view/utils/applyCustomRelationProperties.ts +2 -0
  74. package/src/compute-view/utils/buildComputedNodes.ts +4 -3
  75. package/src/compute-view/utils/merge-props-from-relationships.ts +6 -5
  76. package/src/compute-view/utils/view-hash.ts +24 -3
  77. package/src/model/DeploymentElementModel.ts +22 -18
  78. package/src/model/ElementModel.ts +14 -10
  79. package/src/model/RelationModel.ts +21 -21
  80. package/src/model/index.ts +4 -0
  81. package/src/model/types.ts +11 -0
  82. package/src/model/view/EdgeModel.ts +6 -5
  83. package/src/model/view/LikeC4ViewModel.ts +10 -4
  84. package/src/model/view/NodeModel.ts +6 -4
  85. package/src/theme/index.ts +12 -5
  86. package/src/types/RichText.ts +200 -0
  87. package/src/types/aux.ts +1 -1
  88. package/src/types/index.ts +2 -0
  89. package/src/types/model-deployment.ts +4 -3
  90. package/src/types/model-logical.ts +3 -3
  91. package/src/types/scalar.ts +47 -2
  92. package/src/types/view-common.ts +1 -1
  93. package/src/types/view-computed.ts +2 -4
  94. package/src/types/view-layouted.ts +9 -0
  95. package/src/types/view-parsed.deployment.ts +0 -1
  96. package/src/types/view.ts +0 -27
  97. package/src/utils/index.ts +5 -10
  98. package/src/utils/markdown/index.ts +2 -0
  99. package/src/utils/markdown/to-html.ts +32 -0
  100. package/src/utils/markdown/to-text.ts +14 -0
  101. package/src/utils/promises.ts +4 -0
@@ -0,0 +1,724 @@
1
+ import { c as customInspectSymbol } from './core.C80Z37Eu.mjs';
2
+ import { a as intersection, d as difference, u as union, b as stringHash, e as equals } from './core.CpwrZi3D.mjs';
3
+ import { C, t as s, g as hierarchyLevel, d as commonAncestor, k as isSameHierarchy } from './core.C_C-3c1S.mjs';
4
+ import { u } from './core.DbRvwARP.mjs';
5
+ import { b as DefaultShapeSize, R as RichText, n as n$1, D as DefaultThemeColor, e as DefaultLineStyle, a as DefaultElementShape } from './core.D56nCp7e.mjs';
6
+ import { a as nonNullable, i as invariant } from './core.D4npX2q8.mjs';
7
+ import { m as memoizeProp } from './core.B0oEIXqd.mjs';
8
+
9
+ function y(t,i){let a=i.length-t.length;if(a===1){let[n,...r]=i;return C(n,{lazy:t,lazyArgs:r})}if(a===0){let n={lazy:t,lazyArgs:i};return Object.assign(e=>C(e,n),n)}throw new Error("Wrong number of arguments")}
10
+
11
+ function i(...e){return y(a,e)}function a(){let e=new Set;return t=>e.has(t)?s:(e.add(t),{done:false,hasNext:true,next:t})}
12
+
13
+ function t(...n){return u(o,n)}var o=n=>n.length===1?n[0]:void 0;
14
+
15
+ function n(e){return e===void 0?true:typeof e=="string"||Array.isArray(e)?e.length===0:Object.keys(e).length===0}
16
+
17
+ class AbstractDeploymentElementModel {
18
+ get style() {
19
+ return {
20
+ shape: DefaultElementShape,
21
+ color: DefaultThemeColor,
22
+ size: DefaultShapeSize,
23
+ ...this.$node.style
24
+ };
25
+ }
26
+ get shape() {
27
+ return this.$node.style?.shape ?? DefaultElementShape;
28
+ }
29
+ get color() {
30
+ return this.$node.style?.color ?? DefaultThemeColor;
31
+ }
32
+ get description() {
33
+ return RichText.memoize(this, this.$node.description);
34
+ }
35
+ get technology() {
36
+ return this.$node.technology ?? null;
37
+ }
38
+ get links() {
39
+ return this.$node.links ?? [];
40
+ }
41
+ /**
42
+ * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
43
+ * (from closest to root)
44
+ */
45
+ ancestors() {
46
+ return this.$model.ancestors(this);
47
+ }
48
+ /**
49
+ * Returns the common ancestor of this element and another element.
50
+ */
51
+ commonAncestor(another) {
52
+ const common = commonAncestor(this.id, another.id);
53
+ return common ? this.$model.node(common) : null;
54
+ }
55
+ /**
56
+ * Get all sibling (i.e. same parent)
57
+ */
58
+ siblings() {
59
+ return this.$model.siblings(this);
60
+ }
61
+ /**
62
+ * Check if the element is a sibling of another element
63
+ */
64
+ isSibling(other) {
65
+ return this.parent === other.parent;
66
+ }
67
+ /**
68
+ * Resolve siblings of the element and its ancestors
69
+ * (from closest to root)
70
+ */
71
+ *ascendingSiblings() {
72
+ yield* this.siblings();
73
+ for (const ancestor of this.ancestors()) {
74
+ yield* ancestor.siblings();
75
+ }
76
+ return;
77
+ }
78
+ /**
79
+ * Resolve siblings of the element and its ancestors
80
+ * (from root to closest)
81
+ */
82
+ *descendingSiblings() {
83
+ for (const ancestor of [...this.ancestors()].reverse()) {
84
+ yield* ancestor.siblings();
85
+ }
86
+ yield* this.siblings();
87
+ return;
88
+ }
89
+ incoming(filter = "all") {
90
+ return this.$model.incoming(this, filter);
91
+ }
92
+ outgoing(filter = "all") {
93
+ return this.$model.outgoing(this, filter);
94
+ }
95
+ *incomers(filter = "all") {
96
+ const unique2 = /* @__PURE__ */ new Set();
97
+ for (const r of this.incoming(filter)) {
98
+ if (unique2.has(r.source.id)) {
99
+ continue;
100
+ }
101
+ unique2.add(r.source.id);
102
+ yield r.source;
103
+ }
104
+ return;
105
+ }
106
+ *outgoers(filter = "all") {
107
+ const unique2 = /* @__PURE__ */ new Set();
108
+ for (const r of this.outgoing(filter)) {
109
+ if (unique2.has(r.target.id)) {
110
+ continue;
111
+ }
112
+ unique2.add(r.target.id);
113
+ yield r.target;
114
+ }
115
+ return;
116
+ }
117
+ /**
118
+ * Iterate over all views that include this deployment element.
119
+ */
120
+ *views() {
121
+ for (const view of this.$model.views()) {
122
+ if (view._type !== "deployment") {
123
+ continue;
124
+ }
125
+ if (view.includesDeployment(this.id)) {
126
+ yield view;
127
+ }
128
+ }
129
+ }
130
+ // type guard
131
+ isDeploymentNode() {
132
+ return false;
133
+ }
134
+ // type guard
135
+ isInstance() {
136
+ return false;
137
+ }
138
+ get allOutgoing() {
139
+ return memoizeProp(this, Symbol.for("allOutgoing"), () => RelationshipsAccum.from(
140
+ new Set(this.outgoingModelRelationships()),
141
+ new Set(this.outgoing())
142
+ ));
143
+ }
144
+ get allIncoming() {
145
+ return memoizeProp(this, Symbol.for("allIncoming"), () => RelationshipsAccum.from(
146
+ new Set(this.incomingModelRelationships()),
147
+ new Set(this.incoming())
148
+ ));
149
+ }
150
+ hasMetadata() {
151
+ return !!this.$node.metadata && !n(this.$node.metadata);
152
+ }
153
+ getMetadata(field) {
154
+ if (field) {
155
+ return this.$node.metadata?.[field];
156
+ }
157
+ return this.$node.metadata ?? {};
158
+ }
159
+ /**
160
+ * Checks if the deployment element has the given tag.
161
+ */
162
+ isTagged(tag) {
163
+ return this.tags.includes(tag);
164
+ }
165
+ }
166
+ class DeploymentNodeModel extends AbstractDeploymentElementModel {
167
+ constructor($model, $node) {
168
+ super();
169
+ this.$model = $model;
170
+ this.$node = $node;
171
+ this.id = $node.id;
172
+ this._literalId = $node.id;
173
+ this.title = $node.title;
174
+ this.hierarchyLevel = hierarchyLevel($node.id);
175
+ }
176
+ id;
177
+ _literalId;
178
+ title;
179
+ hierarchyLevel;
180
+ get parent() {
181
+ return this.$model.parent(this);
182
+ }
183
+ get kind() {
184
+ return this.$node.kind;
185
+ }
186
+ get tags() {
187
+ return memoizeProp(this, Symbol.for("tags"), () => {
188
+ return i([
189
+ ...this.$node.tags ?? [],
190
+ ...this.$model.$model.specification.deployments[this.kind]?.tags ?? []
191
+ ]);
192
+ });
193
+ }
194
+ children() {
195
+ return this.$model.children(this);
196
+ }
197
+ descendants(sort = "desc") {
198
+ return this.$model.descendants(this, sort);
199
+ }
200
+ isDeploymentNode() {
201
+ return true;
202
+ }
203
+ /**
204
+ * Iterate over all instances nested in this deployment node.
205
+ */
206
+ *instances() {
207
+ for (const nested of this.descendants("desc")) {
208
+ if (nested.isInstance()) {
209
+ yield nested;
210
+ }
211
+ }
212
+ return;
213
+ }
214
+ /**
215
+ * Returns deployed instance inside this deployment node
216
+ * if only there are no more instances
217
+ */
218
+ onlyOneInstance() {
219
+ const children = this.children();
220
+ if (children.size !== 1) {
221
+ return null;
222
+ }
223
+ const child = t([...children]);
224
+ return child?.isInstance() ? child : null;
225
+ }
226
+ /**
227
+ * Cached result of relationships from instances
228
+ */
229
+ _relationshipsFromInstances = null;
230
+ relationshipsFromInstances() {
231
+ if (this._relationshipsFromInstances) {
232
+ return this._relationshipsFromInstances;
233
+ }
234
+ const {
235
+ outgoing,
236
+ incoming
237
+ } = this._relationshipsFromInstances = {
238
+ outgoing: /* @__PURE__ */ new Set(),
239
+ incoming: /* @__PURE__ */ new Set()
240
+ };
241
+ for (const instance of this.instances()) {
242
+ for (const r of instance.element.outgoing()) {
243
+ outgoing.add(r);
244
+ }
245
+ for (const r of instance.element.incoming()) {
246
+ incoming.add(r);
247
+ }
248
+ }
249
+ return this._relationshipsFromInstances;
250
+ }
251
+ /**
252
+ * We return only relationships that are not already present in nested instances
253
+ */
254
+ outgoingModelRelationships() {
255
+ return this.relationshipsFromInstances().outgoing.values();
256
+ }
257
+ /**
258
+ * We return only relationships that are not already present in nested instances
259
+ */
260
+ incomingModelRelationships() {
261
+ return this.relationshipsFromInstances().incoming.values();
262
+ }
263
+ /**
264
+ * Returns an iterator of relationships between nested instances
265
+ */
266
+ internalModelRelationships() {
267
+ const {
268
+ outgoing,
269
+ incoming
270
+ } = this.relationshipsFromInstances();
271
+ return intersection(incoming, outgoing);
272
+ }
273
+ }
274
+ class DeployedInstanceModel extends AbstractDeploymentElementModel {
275
+ constructor($model, $instance, element) {
276
+ super();
277
+ this.$model = $model;
278
+ this.$instance = $instance;
279
+ this.element = element;
280
+ this.id = $instance.id;
281
+ this._literalId = $instance.id;
282
+ this.title = $instance.title ?? element.title;
283
+ this.hierarchyLevel = hierarchyLevel($instance.id);
284
+ }
285
+ id;
286
+ _literalId;
287
+ title;
288
+ hierarchyLevel;
289
+ get $node() {
290
+ return this.$instance;
291
+ }
292
+ get parent() {
293
+ return nonNullable(this.$model.parent(this), `Parent of ${this.id} not found`);
294
+ }
295
+ get style() {
296
+ const { icon, style } = this.element.$element;
297
+ return {
298
+ shape: this.element.shape,
299
+ color: this.element.color,
300
+ size: DefaultShapeSize,
301
+ ...icon && { icon },
302
+ ...style,
303
+ ...this.$instance.style
304
+ };
305
+ }
306
+ get shape() {
307
+ return this.$instance.style?.shape ?? this.element.shape;
308
+ }
309
+ get color() {
310
+ return this.$instance.style?.color ?? this.element.color;
311
+ }
312
+ get tags() {
313
+ return memoizeProp(this, Symbol.for("tags"), () => {
314
+ return i([
315
+ ...this.$instance.tags ?? [],
316
+ ...this.element.tags
317
+ ]);
318
+ });
319
+ }
320
+ get kind() {
321
+ return this.element.kind;
322
+ }
323
+ get description() {
324
+ return RichText.memoize(this, this.$instance.description ?? this.element.$element.description);
325
+ }
326
+ get technology() {
327
+ return this.$instance.technology ?? this.element.technology ?? null;
328
+ }
329
+ get links() {
330
+ return this.$instance.links ?? this.element.links;
331
+ }
332
+ isInstance() {
333
+ return true;
334
+ }
335
+ outgoingModelRelationships() {
336
+ return this.element.outgoing();
337
+ }
338
+ incomingModelRelationships() {
339
+ return this.element.incoming();
340
+ }
341
+ /**
342
+ * Iterate over all views that include this instance.
343
+ * (Some views may include the parent deployment node instead of the instance.)
344
+ */
345
+ *views() {
346
+ for (const view of this.$model.views()) {
347
+ if (view._type !== "deployment") {
348
+ continue;
349
+ }
350
+ if (view.includesDeployment(this.id)) {
351
+ yield view;
352
+ continue;
353
+ }
354
+ if (view.includesDeployment(this.parent.id) && this.parent.onlyOneInstance()) {
355
+ yield view;
356
+ }
357
+ }
358
+ }
359
+ }
360
+ class NestedElementOfDeployedInstanceModel {
361
+ constructor(instance, element) {
362
+ this.instance = instance;
363
+ this.element = element;
364
+ }
365
+ get id() {
366
+ return this.instance.id;
367
+ }
368
+ get _literalId() {
369
+ return this.instance.id;
370
+ }
371
+ get style() {
372
+ const { icon, style } = this.element.$element;
373
+ return {
374
+ shape: this.element.shape,
375
+ color: this.element.color,
376
+ ...icon && { icon },
377
+ ...style
378
+ };
379
+ }
380
+ get shape() {
381
+ return this.element.shape;
382
+ }
383
+ get color() {
384
+ return this.element.color;
385
+ }
386
+ get title() {
387
+ return this.element.title;
388
+ }
389
+ get description() {
390
+ return this.element.description;
391
+ }
392
+ get technology() {
393
+ return this.element.technology;
394
+ }
395
+ isDeploymentNode() {
396
+ return false;
397
+ }
398
+ isInstance() {
399
+ return false;
400
+ }
401
+ }
402
+ class DeploymentRelationModel {
403
+ constructor($model, $relationship) {
404
+ this.$model = $model;
405
+ this.$relationship = $relationship;
406
+ this.source = $model.deploymentRef($relationship.source);
407
+ this.target = $model.deploymentRef($relationship.target);
408
+ const parent = commonAncestor(this.source.id, this.target.id);
409
+ this.boundary = parent ? this.$model.node(parent) : null;
410
+ }
411
+ boundary;
412
+ source;
413
+ target;
414
+ get id() {
415
+ return this.$relationship.id;
416
+ }
417
+ get expression() {
418
+ return `${this.source.id} -> ${this.target.id}`;
419
+ }
420
+ get title() {
421
+ if (!n$1(this.$relationship.title)) {
422
+ return null;
423
+ }
424
+ return this.$relationship.title;
425
+ }
426
+ get technology() {
427
+ return this.$relationship.technology ?? null;
428
+ }
429
+ get description() {
430
+ return RichText.memoize(this, this.$relationship.description);
431
+ }
432
+ get tags() {
433
+ return this.$relationship.tags ?? [];
434
+ }
435
+ get kind() {
436
+ return this.$relationship.kind ?? null;
437
+ }
438
+ get navigateTo() {
439
+ return this.$relationship.navigateTo ? this.$model.$model.view(this.$relationship.navigateTo) : null;
440
+ }
441
+ get links() {
442
+ return this.$relationship.links ?? [];
443
+ }
444
+ get color() {
445
+ return this.$relationship.color ?? DefaultThemeColor;
446
+ }
447
+ get line() {
448
+ return this.$relationship.line ?? DefaultLineStyle;
449
+ }
450
+ *views() {
451
+ for (const view of this.$model.views()) {
452
+ if (view.includesRelation(this.id)) {
453
+ yield view;
454
+ }
455
+ }
456
+ return;
457
+ }
458
+ isDeploymentRelation() {
459
+ return true;
460
+ }
461
+ isModelRelation() {
462
+ return false;
463
+ }
464
+ hasMetadata() {
465
+ return !!this.$relationship.metadata && !n(this.$relationship.metadata);
466
+ }
467
+ getMetadata(field) {
468
+ if (field) {
469
+ return this.$relationship.metadata?.[field];
470
+ }
471
+ return this.$relationship.metadata ?? {};
472
+ }
473
+ /**
474
+ * Checks if the relationship has the given tag.
475
+ */
476
+ isTagged(tag) {
477
+ return this.tags.includes(tag);
478
+ }
479
+ }
480
+ class RelationshipsAccum {
481
+ /**
482
+ * @param model relationships from logical model
483
+ * @param deployment relationships from deployment model
484
+ */
485
+ constructor(model = /* @__PURE__ */ new Set(), deployment = /* @__PURE__ */ new Set()) {
486
+ this.model = model;
487
+ this.deployment = deployment;
488
+ }
489
+ static empty() {
490
+ return new RelationshipsAccum();
491
+ }
492
+ static from(model, deployment) {
493
+ return new RelationshipsAccum(
494
+ new Set(model),
495
+ new Set(deployment)
496
+ );
497
+ }
498
+ get isEmpty() {
499
+ return this.model.size === 0 && this.deployment.size === 0;
500
+ }
501
+ get nonEmpty() {
502
+ return this.model.size > 0 || this.deployment.size > 0;
503
+ }
504
+ get size() {
505
+ return this.model.size + this.deployment.size;
506
+ }
507
+ /**
508
+ * Returns new Accum containing all the elements which are both in this and otherAccum
509
+ */
510
+ intersect(otherAccum) {
511
+ return RelationshipsAccum.from(
512
+ intersection(this.model, otherAccum.model),
513
+ intersection(this.deployment, otherAccum.deployment)
514
+ );
515
+ }
516
+ /**
517
+ * Returns new Accum containing all the elements which are both in this and otherAccum
518
+ */
519
+ difference(otherAccum) {
520
+ return RelationshipsAccum.from(
521
+ difference(this.model, otherAccum.model),
522
+ difference(this.deployment, otherAccum.deployment)
523
+ );
524
+ }
525
+ /**
526
+ * Returns new Accum containing all the elements from both
527
+ */
528
+ union(otherAccum) {
529
+ return RelationshipsAccum.from(
530
+ union(this.model, otherAccum.model),
531
+ union(this.deployment, otherAccum.deployment)
532
+ );
533
+ }
534
+ }
535
+
536
+ class DeploymentConnectionModel {
537
+ constructor(source, target, relations) {
538
+ this.source = source;
539
+ this.target = target;
540
+ this.relations = relations;
541
+ this.id = stringHash(`deployment:${source.id}:${target.id}`);
542
+ }
543
+ id;
544
+ /**
545
+ * Human readable expression of the connection
546
+ * Mostly used for testing and debugging
547
+ */
548
+ get expression() {
549
+ return `${this.source.id} -> ${this.target.id}`;
550
+ }
551
+ _boundary;
552
+ /**
553
+ * Common ancestor of the source and target elements.
554
+ * Represents the boundary of the connection.
555
+ */
556
+ get boundary() {
557
+ this._boundary ??= this.source.commonAncestor(this.target);
558
+ return this._boundary;
559
+ }
560
+ nonEmpty() {
561
+ return this.relations.nonEmpty;
562
+ }
563
+ [customInspectSymbol](depth, inspectOptions, inspect) {
564
+ const asString = this.toString();
565
+ Object.defineProperty(asString, "constructor", {
566
+ value: DeploymentConnectionModel,
567
+ enumerable: false
568
+ });
569
+ return asString;
570
+ }
571
+ toString() {
572
+ const model = [...this.relations.model].map((c) => " " + c.expression);
573
+ if (model.length) {
574
+ model.unshift(" model:");
575
+ } else {
576
+ model.unshift(" model: []");
577
+ }
578
+ const deployment = [...this.relations.deployment].map((c) => " " + c.expression);
579
+ if (deployment.length) {
580
+ deployment.unshift(" deployment:");
581
+ } else {
582
+ deployment.unshift(" deployment: []");
583
+ }
584
+ return [
585
+ this.expression,
586
+ ...model,
587
+ ...deployment
588
+ ].join("\n");
589
+ }
590
+ /**
591
+ * Check if connection contains deployment relation,
592
+ * that is directly connected to source or target.
593
+ */
594
+ hasDirectDeploymentRelation() {
595
+ for (const relation of this.relations.deployment) {
596
+ if (relation.source.id === this.source.id || relation.target.id === this.target.id) {
597
+ return true;
598
+ }
599
+ }
600
+ return false;
601
+ }
602
+ *values() {
603
+ yield* this.relations.model;
604
+ yield* this.relations.deployment;
605
+ }
606
+ mergeWith(other) {
607
+ if (Array.isArray(other)) {
608
+ return other.reduce((acc, o) => acc.mergeWith(o), this);
609
+ }
610
+ invariant(this.source.id === other.source.id, "Cannot merge connections with different sources");
611
+ invariant(this.target.id === other.target.id, "Cannot merge connections with different targets");
612
+ return new DeploymentConnectionModel(
613
+ this.source,
614
+ this.target,
615
+ this.relations.union(other.relations)
616
+ );
617
+ }
618
+ difference(other) {
619
+ return new DeploymentConnectionModel(
620
+ this.source,
621
+ this.target,
622
+ this.relations.difference(other.relations)
623
+ );
624
+ }
625
+ intersect(other) {
626
+ return new DeploymentConnectionModel(
627
+ this.source,
628
+ this.target,
629
+ this.relations.intersect(other.relations)
630
+ );
631
+ }
632
+ equals(other) {
633
+ invariant(other instanceof DeploymentConnectionModel, "Other should ne DeploymentConnectionModel");
634
+ return this.id === other.id && this.source.id === other.source.id && this.target.id === other.target.id && equals(this.relations.model, other.relations.model) && equals(this.relations.deployment, other.relations.deployment);
635
+ }
636
+ /**
637
+ * Creates a clone of the current `DeploymentConnectionModel` instance with optional overrides.
638
+ * if `null` is provided in overrides, the corresponding relation set will be empty.
639
+ */
640
+ update(overrides) {
641
+ if (overrides) {
642
+ overrides = {
643
+ model: this.relations.model,
644
+ deployment: this.relations.deployment,
645
+ ...overrides
646
+ };
647
+ }
648
+ return new DeploymentConnectionModel(
649
+ this.source,
650
+ this.target,
651
+ overrides ? new RelationshipsAccum(
652
+ overrides.model ?? /* @__PURE__ */ new Set(),
653
+ overrides.deployment ?? /* @__PURE__ */ new Set()
654
+ ) : this.relations
655
+ );
656
+ }
657
+ }
658
+
659
+ function findConnection(source, target, direction = "directed") {
660
+ if (source === target) {
661
+ return [];
662
+ }
663
+ if (isSameHierarchy(source, target)) {
664
+ return [];
665
+ }
666
+ const directedIntersection = source.allOutgoing.intersect(target.allIncoming);
667
+ const directed = directedIntersection.nonEmpty ? [
668
+ new DeploymentConnectionModel(
669
+ source,
670
+ target,
671
+ directedIntersection
672
+ )
673
+ ] : [];
674
+ if (direction === "directed") {
675
+ return directed;
676
+ }
677
+ return [
678
+ ...directed,
679
+ ...findConnection(target, source, "directed")
680
+ ];
681
+ }
682
+ function findConnectionsBetween(element, others, direction = "both") {
683
+ if (element.allIncoming.isEmpty && element.allOutgoing.isEmpty) {
684
+ return [];
685
+ }
686
+ const outgoing = [];
687
+ const incoming = [];
688
+ for (const _other of others) {
689
+ if (element === _other) {
690
+ continue;
691
+ }
692
+ for (const found of findConnection(element, _other, direction)) {
693
+ if (found.source === element) {
694
+ outgoing.push(found);
695
+ } else {
696
+ incoming.push(found);
697
+ }
698
+ }
699
+ }
700
+ return [
701
+ ...outgoing,
702
+ ...incoming
703
+ ];
704
+ }
705
+ function findConnectionsWithin(elements) {
706
+ return [...elements].reduce((acc, el, index, array) => {
707
+ if (index === array.length - 1) {
708
+ return acc;
709
+ }
710
+ acc.push(
711
+ ...findConnectionsBetween(el, array.slice(index + 1), "both")
712
+ );
713
+ return acc;
714
+ }, []);
715
+ }
716
+
717
+ const deploymentConnection = {
718
+ __proto__: null,
719
+ findConnection: findConnection,
720
+ findConnectionsBetween: findConnectionsBetween,
721
+ findConnectionsWithin: findConnectionsWithin
722
+ };
723
+
724
+ export { DeploymentConnectionModel as D, NestedElementOfDeployedInstanceModel as N, RelationshipsAccum as R, findConnectionsBetween as a, findConnectionsWithin as b, DeployedInstanceModel as c, deploymentConnection as d, DeploymentNodeModel as e, findConnection as f, DeploymentRelationModel as g, i, n, t };