@likec4/core 1.27.3 → 1.28.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 (71) hide show
  1. package/dist/builder/index.d.mts +6 -6
  2. package/dist/builder/index.mjs +23 -13
  3. package/dist/compute-view/index.d.mts +3 -3
  4. package/dist/compute-view/index.mjs +3 -3
  5. package/dist/compute-view/relationships-view/index.d.mts +3 -3
  6. package/dist/index.d.mts +6 -6
  7. package/dist/index.mjs +2 -2
  8. package/dist/model/index.d.mts +6 -6
  9. package/dist/model/index.mjs +1 -1
  10. package/dist/shared/{core.RjpTh3vE.mjs → core.Bjl6Kmc8.mjs} +260 -168
  11. package/dist/shared/{core.BpuZeqlX.d.mts → core.CZR9J1Qx.d.mts} +2 -2
  12. package/dist/shared/{core.Djro-kuQ.d.mts → core.CiFKryGW.d.mts} +7 -2
  13. package/dist/shared/{core.HKn0jlo_.d.mts → core.D2830qgg.d.mts} +1 -1
  14. package/dist/shared/{core.CFDwncxs.d.mts → core.DJvmfnEi.d.mts} +481 -186
  15. package/dist/shared/{core.BMep80lJ.mjs → core.DgfwjBtu.mjs} +198 -87
  16. package/dist/shared/core.SjLhMA7a.d.mts +62 -0
  17. package/dist/types/index.d.mts +4 -4
  18. package/dist/types/index.mjs +1 -1
  19. package/dist/utils/index.d.mts +2 -2
  20. package/package.json +6 -6
  21. package/src/builder/Builder.ts +1 -0
  22. package/src/builder/Builder.view-common.ts +10 -10
  23. package/src/builder/Builder.view-element.ts +26 -14
  24. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +23 -8
  25. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +9 -4
  26. package/src/compute-view/deployment-view/predicates/deploymentRefs-where.ts +18 -0
  27. package/src/compute-view/deployment-view/predicates/relation-direct.ts +6 -0
  28. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +3 -0
  29. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +3 -0
  30. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +3 -0
  31. package/src/compute-view/deployment-view/predicates/utils.ts +10 -3
  32. package/src/compute-view/deployment-view/utils.ts +7 -4
  33. package/src/compute-view/element-view/__test__/fixture.ts +72 -65
  34. package/src/compute-view/element-view/_types.ts +13 -9
  35. package/src/compute-view/element-view/compute.ts +27 -27
  36. package/src/compute-view/element-view/memory/NodeGroup.ts +4 -3
  37. package/src/compute-view/element-view/memory/memory.ts +3 -2
  38. package/src/compute-view/element-view/memory/stage-include.ts +2 -2
  39. package/src/compute-view/element-view/predicates/_utils.ts +25 -24
  40. package/src/compute-view/element-view/predicates/element-expand.ts +7 -10
  41. package/src/compute-view/element-view/predicates/element-kind-tag.ts +5 -3
  42. package/src/compute-view/element-view/predicates/element-ref.ts +7 -19
  43. package/src/compute-view/element-view/predicates/relation-direct.ts +15 -13
  44. package/src/compute-view/element-view/predicates/relation-in-out.ts +5 -6
  45. package/src/compute-view/element-view/predicates/relation-in.ts +36 -32
  46. package/src/compute-view/element-view/predicates/relation-out.ts +37 -33
  47. package/src/compute-view/element-view/predicates/wildcard.ts +2 -2
  48. package/src/compute-view/utils/applyCustomElementProperties.ts +9 -4
  49. package/src/compute-view/utils/applyCustomRelationProperties.ts +10 -7
  50. package/src/compute-view/utils/elementExpressionToPredicate.ts +27 -26
  51. package/src/compute-view/utils/link-nodes-with-edges.ts +1 -1
  52. package/src/compute-view/utils/relationExpressionToPredicates.ts +10 -17
  53. package/src/compute-view/utils/uniqueTags.ts +3 -3
  54. package/src/index.ts +0 -2
  55. package/src/model/ElementModel.ts +25 -6
  56. package/src/model/LikeC4Model.ts +44 -6
  57. package/src/model/RelationModel.ts +4 -2
  58. package/src/model/view/LikeC4ViewModel.ts +3 -2
  59. package/src/types/_common.ts +0 -4
  60. package/src/types/deployments.ts +3 -2
  61. package/src/types/element.ts +2 -10
  62. package/src/types/expression-v2-model.ts +314 -0
  63. package/src/types/expression-v2.ts +238 -30
  64. package/src/types/index.ts +15 -46
  65. package/src/types/model-data.ts +4 -1
  66. package/src/types/relation.ts +2 -1
  67. package/src/types/scalars.ts +39 -0
  68. package/src/types/view-changes.ts +2 -1
  69. package/src/types/view.ts +7 -8
  70. package/dist/shared/core.30yYKXcZ.d.mts +0 -186
  71. package/src/types/expression.ts +0 -207
@@ -1,4 +1,4 @@
1
- import { D as DefaultElementShape, c as DefaultThemeColor, h as DefaultShapeSize, U as DefaultRelationshipColor, T as DefaultLineStyle, ab as o$8, t as isElementWhere, Q as whereOperatorAsPredicate, G as isWildcard, q as isElementKindExpr, s as isElementTagExpr, n as n$4, u as isExpandedElementExpr, r as isElementRef, l as isCustomElement, a9 as isViewRuleStyle, ac as y$2, V as ComputedNode, E as ElementKind, S as DefaultArrowType, I as FqnExpr, R as RelationExpr, o as o$9, a8 as isViewRulePredicate, a4 as isViewRuleAutoLayout, a7 as isViewRuleGroup, a5 as isViewRuleGlobalPredicateRef, a6 as isViewRuleGlobalStyle, aa as stepEdgeId, a2 as isDynamicViewParallelSteps, x as isOutgoing$1, v as isIncoming$1, w as isInOut, y as isRelation, F as isRelationWhere, m as isCustomRelationExpr, C as isRelationPredicateExpr, b as isElementPredicateExpr, a as isElementView, a1 as isDynamicView, a0 as isDeploymentView, d as DeploymentElement, Y as extractStep, a3 as isStepEdgeId, e as isScopedElementView } from './core.BMep80lJ.mjs';
1
+ import { s as splitGlobalFqn, D as DefaultElementShape, b as DefaultThemeColor, g as DefaultShapeSize, Z as n$3, y as DefaultRelationshipColor, x as DefaultLineStyle, _ as o$8, M as ModelLayer, w as whereOperatorAsPredicate, n as n$4, X as isViewRuleStyle, $ as y$2, C as ComputedNode, E as ElementKind, v as DefaultArrowType, F as FqnExpr, R as RelationExpr, o as o$9, W as isViewRulePredicate, S as isViewRuleAutoLayout, V as isViewRuleGroup, T as isViewRuleGlobalPredicateRef, U as isViewRuleGlobalStyle, Y as stepEdgeId, P as isDynamicViewParallelSteps, a as isElementView, O as isDynamicView, N as isDeploymentView, c as DeploymentElement, I as extractStep, Q as isStepEdgeId, d as isScopedElementView, e as isGlobalFqn, G as GlobalFqn } from './core.DgfwjBtu.mjs';
2
2
  import { C, y as s$1, z as a$5, u as hierarchyLevel, a as isAncestor, m as commonAncestor, w as sortNaturalByFqn, j as getDefaultExportFromCjs, i as isDescendantOf, x as isString, g as isSameHierarchy, c as ifilter, t as toSet, s as sortParentsFirst, b as toArray, D as DefaultMap, d as imap, p as parentFqn, o as compareByFqnHierarchically, e as isNonEmptyArray, k as compareNatural, n as nameFromFqn, f as t$6, v as sortByFqnHierarchically, l as ancestorsFqn } from './core.CQXU9DF7.mjs';
3
3
  import { u as u$6 } from './core.DbRvwARP.mjs';
4
4
  import { n as nonNullable, i as invariant, a as nonexhaustive } from './core.C-YXI-43.mjs';
@@ -18,7 +18,7 @@ var T$1={asc:(r,n)=>r>n,desc:(r,n)=>r<n};function s(r,n){let[e,...o]=n;if(!m$2(e
18
18
 
19
19
  function m$1(...r){return u$6(o$6,r)}function o$6(r,t){let e=[...r];return e.sort(t),e}
20
20
 
21
- function a$3(...r){return s(n$3,r)}var n$3=(r,t)=>[...r].sort(t);
21
+ function a$3(...r){return s(n$2,r)}var n$2=(r,t)=>[...r].sort(t);
22
22
 
23
23
  function l$5(...e){return u$6(u$3,e)}var u$3=(e,a,n)=>e.reduce(a,n);
24
24
 
@@ -40,8 +40,6 @@ function t$2(...n){return u$6(o$4,n)}var o$4=n=>n.length===1?n[0]:void 0;
40
40
 
41
41
  function i$3(...e){return u$6(o$3,e)}function o$3(e,r){let a={};for(let[n,u]of Object.entries(e)){let l=r(u,n,e);a[n]=l;}return a}
42
42
 
43
- function n$2(e){return !!e}
44
-
45
43
  function a$2(...e){return u$6(n$1,e)}var n$1=e=>e.at(-1);
46
44
 
47
45
  function l$3(...n){return u$6(d,n)}function d(n,o){let e={};for(let[a,t]of n.entries()){let[y,u]=o(t,a,n);e[y]=u;}return e}
@@ -78,11 +76,22 @@ class ElementModel {
78
76
  this.$element = $element;
79
77
  this.id = this.$element.id;
80
78
  this._literalId = this.$element.id;
81
- this.hierarchyLevel = hierarchyLevel(this.id);
79
+ const [projectId, fqn] = splitGlobalFqn(this.id);
80
+ if (projectId) {
81
+ this.imported = {
82
+ from: projectId,
83
+ fqn
84
+ };
85
+ this.hierarchyLevel = hierarchyLevel(fqn);
86
+ } else {
87
+ this.imported = null;
88
+ this.hierarchyLevel = hierarchyLevel(this.id);
89
+ }
82
90
  }
83
91
  id;
84
92
  _literalId;
85
93
  hierarchyLevel;
94
+ imported;
86
95
  get parent() {
87
96
  return this.$model.parent(this);
88
97
  }
@@ -251,7 +260,7 @@ class ElementModel {
251
260
  * @returns true if the element is deployed
252
261
  */
253
262
  isDeployed() {
254
- return n$2(this.deployments().next().value);
263
+ return n$3(this.deployments().next().value);
255
264
  }
256
265
  deployments() {
257
266
  return this.$model.deployment.instancesOf(this);
@@ -1466,7 +1475,7 @@ function calcViewLayoutHash(view) {
1466
1475
  nodes: C(
1467
1476
  view.nodes,
1468
1477
  m$3(i$6(["id", "title", "description", "technology", "shape", "icon", "children"])),
1469
- l$3(({ id, icon, ...node }) => [id, { ...node, icon: n$2(icon) ? "Y" : "N" }])
1478
+ l$3(({ id, icon, ...node }) => [id, { ...node, icon: n$3(icon) ? "Y" : "N" }])
1470
1479
  ),
1471
1480
  edges: C(
1472
1481
  view.edges,
@@ -3156,29 +3165,39 @@ let Memory$1 = class Memory extends AbstractMemory {
3156
3165
  };
3157
3166
 
3158
3167
  function elementExprToPredicate(target) {
3159
- if (isElementWhere(target)) {
3168
+ if (ModelLayer.FqnExpr.isCustom(target)) {
3169
+ return elementExprToPredicate(target.custom.expr);
3170
+ }
3171
+ if (ModelLayer.FqnExpr.isWhere(target)) {
3160
3172
  const predicate = elementExprToPredicate(target.where.expr);
3161
3173
  const where = whereOperatorAsPredicate(target.where.condition);
3162
3174
  return (n) => predicate(n) && where(n);
3163
3175
  }
3164
- if (isWildcard(target)) {
3165
- return () => true;
3166
- }
3167
- if (isElementKindExpr(target)) {
3176
+ if (ModelLayer.FqnExpr.isElementKindExpr(target)) {
3168
3177
  return target.isEqual ? (n) => n.kind === target.elementKind : (n) => n.kind !== target.elementKind;
3169
3178
  }
3170
- if (isElementTagExpr(target)) {
3179
+ if (ModelLayer.FqnExpr.isElementTagExpr(target)) {
3171
3180
  return target.isEqual ? ({ tags }) => !!tags && tags.includes(target.elementTag) : ({ tags }) => n$4(tags) || !tags.includes(target.elementTag);
3172
3181
  }
3173
- if (isExpandedElementExpr(target)) {
3174
- return (n) => n.id === target.expanded || parentFqn(n.id) === target.expanded;
3175
- }
3176
- if (isElementRef(target)) {
3177
- const { element, isChildren, isDescendants } = target;
3178
- return isChildren || isDescendants ? (n) => n.id.startsWith(element + ".") : (n) => n.id === element;
3182
+ if (ModelLayer.FqnExpr.isWildcard(target)) {
3183
+ return () => true;
3179
3184
  }
3180
- if (isCustomElement(target)) {
3181
- return elementExprToPredicate(target.custom.expr);
3185
+ if (ModelLayer.FqnExpr.isModelRef(target)) {
3186
+ const fqn = ModelLayer.FqnRef.toFqn(target.ref);
3187
+ if (target.selector === "expanded") {
3188
+ return (n) => {
3189
+ return n.id === fqn || parentFqn(n.id) === fqn;
3190
+ };
3191
+ }
3192
+ if (target.selector === "descendants" || target.selector === "children") {
3193
+ const fqnWithDot = fqn + ".";
3194
+ return (n) => {
3195
+ return n.id.startsWith(fqnWithDot);
3196
+ };
3197
+ }
3198
+ return (n) => {
3199
+ return n.id === fqn;
3200
+ };
3182
3201
  }
3183
3202
  nonexhaustive(target);
3184
3203
  }
@@ -3379,31 +3398,31 @@ function mergePropsFromRelationships(relations, prefer) {
3379
3398
  relations,
3380
3399
  l$5(
3381
3400
  (acc, r) => {
3382
- if (n$2(r.title) && !acc.title.includes(r.title)) {
3401
+ if (n$3(r.title) && !acc.title.includes(r.title)) {
3383
3402
  acc.title.push(r.title);
3384
3403
  }
3385
- if (n$2(r.description) && !acc.description.includes(r.description)) {
3404
+ if (n$3(r.description) && !acc.description.includes(r.description)) {
3386
3405
  acc.description.push(r.description);
3387
3406
  }
3388
- if (n$2(r.technology) && !acc.technology.includes(r.technology)) {
3407
+ if (n$3(r.technology) && !acc.technology.includes(r.technology)) {
3389
3408
  acc.technology.push(r.technology);
3390
3409
  }
3391
- if (n$2(r.kind) && !acc.kind.includes(r.kind)) {
3410
+ if (n$3(r.kind) && !acc.kind.includes(r.kind)) {
3392
3411
  acc.kind.push(r.kind);
3393
3412
  }
3394
- if (n$2(r.color) && !acc.color.includes(r.color)) {
3413
+ if (n$3(r.color) && !acc.color.includes(r.color)) {
3395
3414
  acc.color.push(r.color);
3396
3415
  }
3397
- if (n$2(r.line) && !acc.line.includes(r.line)) {
3416
+ if (n$3(r.line) && !acc.line.includes(r.line)) {
3398
3417
  acc.line.push(r.line);
3399
3418
  }
3400
- if (n$2(r.head) && !acc.head.includes(r.head)) {
3419
+ if (n$3(r.head) && !acc.head.includes(r.head)) {
3401
3420
  acc.head.push(r.head);
3402
3421
  }
3403
- if (n$2(r.tail) && !acc.tail.includes(r.tail)) {
3422
+ if (n$3(r.tail) && !acc.tail.includes(r.tail)) {
3404
3423
  acc.tail.push(r.tail);
3405
3424
  }
3406
- if (n$2(r.navigateTo) && !acc.navigateTo.includes(r.navigateTo)) {
3425
+ if (n$3(r.navigateTo) && !acc.navigateTo.includes(r.navigateTo)) {
3407
3426
  acc.navigateTo.push(r.navigateTo);
3408
3427
  }
3409
3428
  if (r.tags) {
@@ -3447,12 +3466,12 @@ function mergePropsFromRelationships(relations, prefer) {
3447
3466
  ...isNonEmptyArray(allprops.links) && { links: allprops.links },
3448
3467
  ...isNonEmptyArray(tags) && { tags }
3449
3468
  },
3450
- n$2
3469
+ n$3
3451
3470
  );
3452
3471
  if (prefer) {
3453
3472
  return {
3454
3473
  ...merged,
3455
- ...d$2(pickRelationshipProps(prefer), n$2)
3474
+ ...d$2(pickRelationshipProps(prefer), n$3)
3456
3475
  };
3457
3476
  }
3458
3477
  return merged;
@@ -3500,6 +3519,9 @@ function deploymentExpressionToPredicate(target) {
3500
3519
  if (FqnExpr.isWildcard(target)) {
3501
3520
  return () => true;
3502
3521
  }
3522
+ if (FqnExpr.isElementTagExpr(target) || FqnExpr.isElementKindExpr(target)) {
3523
+ throw new Error("element kind and tag expressions are not supported in deployment view rules");
3524
+ }
3503
3525
  if (FqnExpr.isDeploymentRef(target)) {
3504
3526
  const fqn = target.ref.deployment;
3505
3527
  if (target.selector === "expanded") {
@@ -3694,6 +3716,17 @@ function isDeploymentElementModel(x) {
3694
3716
  return x instanceof DeploymentNodeModel || x instanceof DeployedInstanceModel;
3695
3717
  }
3696
3718
 
3719
+ const WhereDeploymentRefPredicate = {
3720
+ include: ({ expr, model, memory, stage }) => {
3721
+ const where = whereOperatorAsPredicate(expr.where.condition);
3722
+ return predicateToPatch("include", { expr: expr.where.expr, model, stage, memory, where });
3723
+ },
3724
+ exclude: ({ expr, model, memory, stage }) => {
3725
+ const where = whereOperatorAsPredicate(expr.where.condition);
3726
+ return predicateToPatch("exclude", { expr: expr.where.expr, model, stage, memory, where });
3727
+ }
3728
+ };
3729
+
3697
3730
  const IncomingRelationPredicate = {
3698
3731
  include: ({ expr, model, memory, stage, where }) => {
3699
3732
  const sources = [...memory.elements];
@@ -3717,6 +3750,9 @@ const IncomingRelationPredicate = {
3717
3750
  return stage;
3718
3751
  },
3719
3752
  exclude: ({ expr, model, memory, stage, where }) => {
3753
+ if (FqnExpr.isElementTagExpr(expr.incoming) || FqnExpr.isElementKindExpr(expr.incoming)) {
3754
+ throw new Error("element kind and tag expressions are not supported in exclude");
3755
+ }
3720
3756
  if (FqnExpr.isModelRef(expr.incoming)) {
3721
3757
  const excludedRelations = resolveAllImcomingRelations(model, expr.incoming);
3722
3758
  return excludeModelRelations(excludedRelations, { stage, memory }, where);
@@ -3773,6 +3809,9 @@ const OutgoingRelationPredicate = {
3773
3809
  return stage;
3774
3810
  },
3775
3811
  exclude: ({ expr, model, memory, stage, where }) => {
3812
+ if (FqnExpr.isElementTagExpr(expr.outgoing) || FqnExpr.isElementKindExpr(expr.outgoing)) {
3813
+ throw new Error("element kind and tag expressions are not supported in exclude");
3814
+ }
3776
3815
  if (FqnExpr.isModelRef(expr.outgoing)) {
3777
3816
  const excludedRelations = resolveAllOutgoingRelations(model, expr.outgoing);
3778
3817
  return excludeModelRelations(excludedRelations, { stage, memory }, where);
@@ -3814,6 +3853,12 @@ const resolveAscendingSiblings = (element) => {
3814
3853
  };
3815
3854
  const DirectRelationPredicate = {
3816
3855
  include: ({ expr: { source, target, isBidirectional = false }, model, stage, where }) => {
3856
+ if (FqnExpr.isElementTagExpr(source) || FqnExpr.isElementKindExpr(source)) {
3857
+ throw new Error("element kind and tag expressions are not supported in include");
3858
+ }
3859
+ if (FqnExpr.isElementTagExpr(target) || FqnExpr.isElementKindExpr(target)) {
3860
+ throw new Error("element kind and tag expressions are not supported in include");
3861
+ }
3817
3862
  invariant(!FqnExpr.isModelRef(source), "Invalid source model ref in direct relation");
3818
3863
  invariant(!FqnExpr.isModelRef(target), "Invalid target model ref in direct relation");
3819
3864
  const sourceIsWildcard = FqnExpr.isWildcard(source);
@@ -3991,6 +4036,9 @@ const InOutRelationPredicate$1 = {
3991
4036
  return stage;
3992
4037
  },
3993
4038
  exclude: ({ expr, model, memory, stage, where }) => {
4039
+ if (FqnExpr.isElementTagExpr(expr.inout) || FqnExpr.isElementKindExpr(expr.inout)) {
4040
+ throw new Error("element kind and tag expressions are not supported in exclude");
4041
+ }
3994
4042
  if (FqnExpr.isModelRef(expr.inout)) {
3995
4043
  const elements2 = resolveModelElements(model, expr.inout);
3996
4044
  if (elements2.length === 0) {
@@ -4063,8 +4111,17 @@ const WildcardPredicate$1 = {
4063
4111
 
4064
4112
  function predicateToPatch(op, { expr, where, ...ctx }) {
4065
4113
  switch (true) {
4114
+ case FqnExpr.isElementTagExpr(expr):
4115
+ case FqnExpr.isElementKindExpr(expr):
4116
+ throw new Error("element kind and tag expressions are not supported in deployment view rules");
4117
+ case RelationExpr.isCustom(expr):
4118
+ case FqnExpr.isCustom(expr):
4066
4119
  case FqnExpr.isModelRef(expr):
4067
4120
  return void 0;
4121
+ case FqnExpr.isWhere(expr):
4122
+ return WhereDeploymentRefPredicate[op]({ ...ctx, expr, where });
4123
+ case RelationExpr.isWhere(expr):
4124
+ return WhereRelationPredicate[op]({ ...ctx, expr, where });
4068
4125
  case FqnExpr.isDeploymentRef(expr):
4069
4126
  return DeploymentRefPredicate[op]({ ...ctx, expr, where });
4070
4127
  case FqnExpr.isWildcard(expr):
@@ -4077,8 +4134,6 @@ function predicateToPatch(op, { expr, where, ...ctx }) {
4077
4134
  return OutgoingRelationPredicate[op]({ ...ctx, expr, where });
4078
4135
  case RelationExpr.isIncoming(expr):
4079
4136
  return IncomingRelationPredicate[op]({ ...ctx, expr, where });
4080
- case RelationExpr.isWhere(expr):
4081
- return WhereRelationPredicate[op]({ ...ctx, expr, where });
4082
4137
  default:
4083
4138
  nonexhaustive(expr);
4084
4139
  }
@@ -4527,7 +4582,7 @@ function flattenGroupRules(guard) {
4527
4582
  };
4528
4583
  }
4529
4584
  function applyCustomElementProperties(_rules, _nodes) {
4530
- const rules = _rules.flatMap(flattenGroupRules(isCustomElement));
4585
+ const rules = _rules.flatMap(flattenGroupRules(ModelLayer.FqnExpr.isCustom));
4531
4586
  if (rules.length === 0) {
4532
4587
  return _nodes;
4533
4588
  }
@@ -4662,7 +4717,7 @@ class DynamicViewCompute {
4662
4717
  color,
4663
4718
  line
4664
4719
  } = this.findRelations(source, target);
4665
- const navigateTo = n$2(stepNavigateTo) && stepNavigateTo !== this.view.id ? stepNavigateTo : derivedNavigateTo;
4720
+ const navigateTo = n$3(stepNavigateTo) && stepNavigateTo !== this.view.id ? stepNavigateTo : derivedNavigateTo;
4666
4721
  this.steps.push({
4667
4722
  id,
4668
4723
  ...step,
@@ -4799,7 +4854,7 @@ class DynamicViewCompute {
4799
4854
  const alltags = C(
4800
4855
  relationships,
4801
4856
  u$1((r) => r.tags),
4802
- T(n$2),
4857
+ T(n$3),
4803
4858
  i$8()
4804
4859
  );
4805
4860
  const tags = i$9(alltags, 1) ? alltags : null;
@@ -4809,7 +4864,7 @@ class DynamicViewCompute {
4809
4864
  const navigateTo = relationNavigateTo && relationNavigateTo !== this.view.id ? relationNavigateTo : C(
4810
4865
  relationships,
4811
4866
  m$3((r) => r.$relationship.navigateTo),
4812
- T(n$2),
4867
+ T(n$3),
4813
4868
  T((v) => v !== this.view.id),
4814
4869
  i$8(),
4815
4870
  t$2()
@@ -4817,9 +4872,9 @@ class DynamicViewCompute {
4817
4872
  const commonProperties = C(
4818
4873
  relationships,
4819
4874
  l$5((acc, { title, $relationship: r }) => {
4820
- n$2(title) && acc.title.add(title);
4821
- n$2(r.color) && acc.color.add(r.color);
4822
- n$2(r.line) && acc.line.add(r.line);
4875
+ n$3(title) && acc.title.add(title);
4876
+ n$3(r.color) && acc.color.add(r.color);
4877
+ n$3(r.line) && acc.line.add(r.line);
4823
4878
  return acc;
4824
4879
  }, {
4825
4880
  color: /* @__PURE__ */ new Set(),
@@ -4843,7 +4898,10 @@ function computeDynamicView(model, view) {
4843
4898
 
4844
4899
  function relationExpressionToPredicates(expr) {
4845
4900
  switch (true) {
4846
- case isRelationWhere(expr): {
4901
+ case ModelLayer.RelationExpr.isCustom(expr): {
4902
+ return relationExpressionToPredicates(expr.customRelation.expr);
4903
+ }
4904
+ case ModelLayer.RelationExpr.isWhere(expr): {
4847
4905
  const predicate = relationExpressionToPredicates(expr.where.expr);
4848
4906
  const where = whereOperatorAsPredicate(expr.where.condition);
4849
4907
  return (e) => predicate(e) && where({
@@ -4853,22 +4911,22 @@ function relationExpressionToPredicates(expr) {
4853
4911
  ...e.kind && { kind: e.kind }
4854
4912
  });
4855
4913
  }
4856
- case isRelation(expr): {
4914
+ case ModelLayer.RelationExpr.isDirect(expr): {
4857
4915
  const isSource = elementExprToPredicate(expr.source);
4858
4916
  const isTarget = elementExprToPredicate(expr.target);
4859
4917
  return (edge) => {
4860
4918
  return isSource(edge.source) && isTarget(edge.target) || !!expr.isBidirectional && isSource(edge.target) && isTarget(edge.source);
4861
4919
  };
4862
4920
  }
4863
- case isInOut(expr): {
4864
- const isInOut2 = elementExprToPredicate(expr.inout);
4865
- return (edge) => isInOut2(edge.source) || isInOut2(edge.target);
4921
+ case ModelLayer.RelationExpr.isInOut(expr): {
4922
+ const isInOut = elementExprToPredicate(expr.inout);
4923
+ return (edge) => isInOut(edge.source) || isInOut(edge.target);
4866
4924
  }
4867
- case isIncoming$1(expr): {
4925
+ case ModelLayer.RelationExpr.isIncoming(expr): {
4868
4926
  const isTarget = elementExprToPredicate(expr.incoming);
4869
4927
  return (edge) => isTarget(edge.target);
4870
4928
  }
4871
- case isOutgoing$1(expr): {
4929
+ case ModelLayer.RelationExpr.isOutgoing(expr): {
4872
4930
  const isSource = elementExprToPredicate(expr.outgoing);
4873
4931
  return (edge) => isSource(edge.source);
4874
4932
  }
@@ -4878,16 +4936,20 @@ function relationExpressionToPredicates(expr) {
4878
4936
  }
4879
4937
 
4880
4938
  function applyCustomRelationProperties(_rules, nodes, _edges) {
4881
- const rules = _rules.flatMap(flattenGroupRules(isCustomRelationExpr));
4939
+ const rules = _rules.flatMap(flattenGroupRules(ModelLayer.RelationExpr.isCustom));
4882
4940
  const edges = Array.from(_edges);
4883
4941
  if (rules.length === 0 || edges.length === 0) {
4884
4942
  return edges;
4885
4943
  }
4886
4944
  for (const {
4887
- customRelation: { relation, title, ...customprops }
4945
+ customRelation: {
4946
+ expr,
4947
+ title,
4948
+ ...customprops
4949
+ }
4888
4950
  } of rules) {
4889
4951
  const props = d$1(customprops, n$4);
4890
- const satisfies = relationExpressionToPredicates(relation);
4952
+ const satisfies = relationExpressionToPredicates(expr);
4891
4953
  edges.forEach((edge, i) => {
4892
4954
  const source = nodes.find((n) => n.id === edge.source);
4893
4955
  const target = nodes.find((n) => n.id === edge.target);
@@ -5027,7 +5089,7 @@ class StageInclude extends AbstractStageInclude {
5027
5089
  }
5028
5090
  }
5029
5091
  processConnections(connections) {
5030
- if (isRelationPredicateExpr(this.expression)) {
5092
+ if (ModelLayer.isAnyRelationExpr(this.expression)) {
5031
5093
  return connections;
5032
5094
  }
5033
5095
  C(
@@ -5322,62 +5384,34 @@ class StageFinal {
5322
5384
  }
5323
5385
  }
5324
5386
 
5325
- const ExpandedElementPredicate = {
5326
- include: ({ expr, model, stage, where }) => {
5327
- const parent = model.element(expr.expanded);
5328
- if (where(parent)) {
5329
- stage.addExplicit(parent);
5330
- stage.connectWithExisting(parent);
5331
- }
5332
- const children = [...parent.children()].filter(where);
5333
- const expanded = [];
5334
- for (const child of children) {
5335
- stage.addImplicit(child);
5336
- if (stage.connectWithExisting(child)) {
5337
- expanded.push(child);
5338
- }
5339
- }
5340
- stage.addConnections(findConnectionsWithin$1(expanded));
5341
- return stage;
5342
- },
5343
- exclude: ({ expr, model, stage, where }) => {
5344
- const parent = model.element(expr.expanded);
5345
- const elements = [
5346
- parent,
5347
- ...parent.children()
5348
- ].filter(where);
5349
- stage.exclude(elements);
5350
- return stage;
5351
- }
5352
- };
5353
-
5354
5387
  function resolveElements(model, expr) {
5355
5388
  switch (true) {
5356
- case isExpandedElementExpr(expr): {
5357
- const element = model.element(expr.expanded);
5389
+ case ModelLayer.FqnExpr.isElementKindExpr(expr): {
5390
+ return [...ifilter(model.elements(), (el) => {
5391
+ return expr.isEqual === (el.kind === expr.elementKind);
5392
+ })];
5393
+ }
5394
+ case ModelLayer.FqnExpr.isElementTagExpr(expr): {
5395
+ return [...ifilter(model.elements(), (el) => {
5396
+ return expr.isEqual === el.tags.includes(expr.elementTag);
5397
+ })];
5398
+ }
5399
+ case expr.selector === "expanded": {
5400
+ const element = model.element(ModelLayer.FqnRef.toFqn(expr.ref));
5358
5401
  return [
5359
5402
  element,
5360
5403
  ...element.children()
5361
5404
  ];
5362
5405
  }
5363
- case isElementRef(expr): {
5364
- const element = model.element(expr.element);
5365
- let children;
5366
- if (expr.isChildren) {
5367
- children = toArray(element.children());
5368
- } else if (expr.isDescendants) {
5369
- children = toArray(element.descendants());
5370
- }
5406
+ case expr.selector === "children":
5407
+ case expr.selector === "descendants": {
5408
+ const element = model.element(ModelLayer.FqnRef.toFqn(expr.ref));
5409
+ let children = expr.selector === "children" ? toArray(element.children()) : toArray(element.descendants());
5371
5410
  return children && children.length > 0 ? children : [element];
5372
5411
  }
5373
- case isElementKindExpr(expr):
5374
- return [...ifilter(model.elements(), (el) => {
5375
- return expr.isEqual === (el.kind === expr.elementKind);
5376
- })];
5377
- case isElementTagExpr(expr):
5378
- return [...ifilter(model.elements(), (el) => {
5379
- return expr.isEqual === el.tags.includes(expr.elementTag);
5380
- })];
5412
+ case ModelLayer.FqnExpr.isModelRef(expr): {
5413
+ return [model.element(ModelLayer.FqnRef.toFqn(expr.ref))];
5414
+ }
5381
5415
  default:
5382
5416
  nonexhaustive(expr);
5383
5417
  }
@@ -5400,8 +5434,8 @@ function includeDescendantsFromMemory(elements, memory) {
5400
5434
  }
5401
5435
  function resolveAndIncludeFromMemory(nonWildcard, { memory, model }) {
5402
5436
  const resolved = resolveElements(model, nonWildcard);
5403
- if (isExpandedElementExpr(nonWildcard) || isElementRef(nonWildcard)) {
5404
- if (nonWildcard.isDescendants === true) {
5437
+ if (ModelLayer.FqnExpr.isModelRef(nonWildcard)) {
5438
+ if (nonWildcard.selector === "descendants") {
5405
5439
  return resolved;
5406
5440
  }
5407
5441
  return includeDescendantsFromMemory(resolved, memory);
@@ -5409,6 +5443,31 @@ function resolveAndIncludeFromMemory(nonWildcard, { memory, model }) {
5409
5443
  return resolved;
5410
5444
  }
5411
5445
 
5446
+ const ExpandedElementPredicate = {
5447
+ include: ({ expr, model, stage, where }) => {
5448
+ const parent = model.element(ModelLayer.FqnRef.toFqn(expr.ref));
5449
+ if (where(parent)) {
5450
+ stage.addExplicit(parent);
5451
+ stage.connectWithExisting(parent);
5452
+ }
5453
+ const children = [...parent.children()].filter(where);
5454
+ const expanded = [];
5455
+ for (const child of children) {
5456
+ stage.addImplicit(child);
5457
+ if (stage.connectWithExisting(child)) {
5458
+ expanded.push(child);
5459
+ }
5460
+ }
5461
+ stage.addConnections(findConnectionsWithin$1(expanded));
5462
+ return stage;
5463
+ },
5464
+ exclude: ({ expr, model, stage, filterWhere }) => {
5465
+ const elements = filterWhere(resolveElements(model, expr));
5466
+ stage.exclude(elements);
5467
+ return stage;
5468
+ }
5469
+ };
5470
+
5412
5471
  const ElementKindOrTagPredicate = {
5413
5472
  include: ({ expr, model, stage, filterWhere }) => {
5414
5473
  const elements = filterWhere(resolveElements(model, expr));
@@ -5427,19 +5486,9 @@ const ElementKindOrTagPredicate = {
5427
5486
  }
5428
5487
  };
5429
5488
 
5430
- function applyElementSelector(elem, expr) {
5431
- let children;
5432
- if (expr.isChildren) {
5433
- children = [...elem.children()];
5434
- } else if (expr.isDescendants) {
5435
- children = [...elem.descendants()];
5436
- }
5437
- return children && children.length > 0 ? children : [elem];
5438
- }
5439
5489
  const ElementRefPredicate = {
5440
- include: ({ expr, model, stage, where }) => {
5441
- const element = model.element(expr.element);
5442
- const elements = applyElementSelector(element, expr).filter(where);
5490
+ include: ({ expr, model, stage, filterWhere }) => {
5491
+ const elements = filterWhere(resolveElements(model, expr));
5443
5492
  if (elements.length === 0) {
5444
5493
  return;
5445
5494
  }
@@ -5449,8 +5498,7 @@ const ElementRefPredicate = {
5449
5498
  return stage;
5450
5499
  },
5451
5500
  exclude: ({ expr, model, stage, filterWhere }) => {
5452
- const element = model.element(expr.element);
5453
- const elements = filterWhere(applyElementSelector(element, expr));
5501
+ const elements = filterWhere(resolveElements(model, expr));
5454
5502
  stage.exclude(elements);
5455
5503
  return stage;
5456
5504
  }
@@ -5500,6 +5548,7 @@ function buildNodes(memory) {
5500
5548
  return buildComputedNodes([...memory.final].map(toNodeSource), memory.groups);
5501
5549
  }
5502
5550
 
5551
+ const isWildcard = ModelLayer.FqnExpr.isWildcard;
5503
5552
  const DirectRelationExprPredicate = {
5504
5553
  include: ({ expr: { source, target, isBidirectional = false }, memory, model, stage, where, filterWhere }) => {
5505
5554
  const sourceIsWildcard = isWildcard(source);
@@ -5750,8 +5799,8 @@ function resolveWildcard(nonWildcard, { memory, model }) {
5750
5799
  if (!i$9(sources, 1)) {
5751
5800
  return [[], []];
5752
5801
  }
5753
- if (isExpandedElementExpr(nonWildcard) || isElementRef(nonWildcard)) {
5754
- const parent = model.element(nonWildcard.element ?? nonWildcard.expanded);
5802
+ if (ModelLayer.FqnExpr.isModelRef(nonWildcard)) {
5803
+ const parent = model.element(ModelLayer.FqnRef.toFqn(nonWildcard.ref));
5755
5804
  const targets2 = toArray(parent.ascendingSiblings());
5756
5805
  return [
5757
5806
  includeDescendantsFromMemory(sources, memory),
@@ -5773,7 +5822,7 @@ const IncomingExprPredicate = {
5773
5822
  include: ({ expr, scope, model, memory, stage, filterWhere }) => {
5774
5823
  const target = expr.incoming;
5775
5824
  const connections = [];
5776
- if (isWildcard(target)) {
5825
+ if (ModelLayer.FqnExpr.isWildcard(target)) {
5777
5826
  if (!scope) {
5778
5827
  return;
5779
5828
  }
@@ -5814,7 +5863,7 @@ const IncomingExprPredicate = {
5814
5863
  },
5815
5864
  exclude: ({ expr: { incoming }, model, scope, stage, where }) => {
5816
5865
  const excluded = [];
5817
- if (isWildcard(incoming)) {
5866
+ if (ModelLayer.FqnExpr.isWildcard(incoming)) {
5818
5867
  if (!scope) {
5819
5868
  return;
5820
5869
  }
@@ -5831,34 +5880,38 @@ const IncomingExprPredicate = {
5831
5880
  };
5832
5881
  function incomingConnectionPredicate(model, expr) {
5833
5882
  switch (true) {
5834
- case isElementKindExpr(expr):
5835
- case isElementTagExpr(expr): {
5883
+ case ModelLayer.FqnExpr.isElementKindExpr(expr):
5884
+ case ModelLayer.FqnExpr.isElementTagExpr(expr): {
5836
5885
  const isElement = elementExprToPredicate(expr);
5837
5886
  return (connection) => isElement(connection.target);
5838
5887
  }
5839
- case (isElementRef(expr) && expr.isChildren): {
5888
+ case (ModelLayer.FqnExpr.isModelRef(expr) && expr.selector === "children"): {
5889
+ const fqn = ModelLayer.FqnRef.toFqn(expr.ref);
5840
5890
  return y$2(
5841
- [...model.children(expr.element)].map(
5891
+ [...model.children(fqn)].map(
5842
5892
  (el) => Connection.isIncoming(el.id)
5843
5893
  )
5844
5894
  );
5845
5895
  }
5846
- case (isElementRef(expr) && expr.isDescendants): {
5896
+ case (ModelLayer.FqnExpr.isModelRef(expr) && expr.selector === "descendants"): {
5897
+ const fqn = ModelLayer.FqnRef.toFqn(expr.ref);
5847
5898
  return y$2([
5848
- Connection.isInside(expr.element),
5849
- ...[...model.children(expr.element)].map(
5899
+ Connection.isInside(fqn),
5900
+ ...[...model.children(fqn)].map(
5850
5901
  (el) => Connection.isIncoming(el.id)
5851
5902
  )
5852
5903
  ]);
5853
5904
  }
5854
- case isExpandedElementExpr(expr): {
5905
+ case (ModelLayer.FqnExpr.isModelRef(expr) && expr.selector === "expanded"): {
5906
+ const fqn = ModelLayer.FqnRef.toFqn(expr.ref);
5855
5907
  return y$2([
5856
- Connection.isIncoming(expr.expanded),
5857
- Connection.isInside(expr.expanded)
5908
+ Connection.isIncoming(fqn),
5909
+ Connection.isInside(fqn)
5858
5910
  ]);
5859
5911
  }
5860
- case isElementRef(expr): {
5861
- return Connection.isIncoming(expr.element);
5912
+ case ModelLayer.FqnExpr.isModelRef(expr): {
5913
+ const fqn = ModelLayer.FqnRef.toFqn(expr.ref);
5914
+ return Connection.isIncoming(fqn);
5862
5915
  }
5863
5916
  default:
5864
5917
  nonexhaustive(expr);
@@ -5868,7 +5921,7 @@ function incomingConnectionPredicate(model, expr) {
5868
5921
  const InOutRelationPredicate = {
5869
5922
  include: ({ expr: { inout }, scope, model, memory, stage, filterWhere }) => {
5870
5923
  const connections = [];
5871
- if (isWildcard(inout)) {
5924
+ if (ModelLayer.FqnExpr.isWildcard(inout)) {
5872
5925
  if (!scope) {
5873
5926
  return;
5874
5927
  }
@@ -5902,7 +5955,7 @@ const InOutRelationPredicate = {
5902
5955
  },
5903
5956
  exclude: ({ expr: { inout }, model, scope, stage, where }) => {
5904
5957
  const excluded = [];
5905
- if (isWildcard(inout)) {
5958
+ if (ModelLayer.FqnExpr.isWildcard(inout)) {
5906
5959
  if (!scope) {
5907
5960
  return;
5908
5961
  }
@@ -5923,7 +5976,7 @@ const OutgoingExprPredicate = {
5923
5976
  include: ({ expr, scope, model, memory, stage, filterWhere }) => {
5924
5977
  const target = expr.outgoing;
5925
5978
  const connections = [];
5926
- if (isWildcard(target)) {
5979
+ if (ModelLayer.FqnExpr.isWildcard(target)) {
5927
5980
  if (!scope) {
5928
5981
  return;
5929
5982
  }
@@ -5962,7 +6015,7 @@ const OutgoingExprPredicate = {
5962
6015
  },
5963
6016
  exclude: ({ expr: { outgoing }, model, scope, stage, where }) => {
5964
6017
  const excluded = [];
5965
- if (isWildcard(outgoing)) {
6018
+ if (ModelLayer.FqnExpr.isWildcard(outgoing)) {
5966
6019
  if (!scope) {
5967
6020
  return;
5968
6021
  }
@@ -5981,34 +6034,38 @@ const OutgoingExprPredicate = {
5981
6034
  };
5982
6035
  function outgoingConnectionPredicate(model, expr) {
5983
6036
  switch (true) {
5984
- case isElementKindExpr(expr):
5985
- case isElementTagExpr(expr): {
6037
+ case ModelLayer.FqnExpr.isElementKindExpr(expr):
6038
+ case ModelLayer.FqnExpr.isElementTagExpr(expr): {
5986
6039
  const isElement = elementExprToPredicate(expr);
5987
6040
  return (connection) => isElement(connection.source);
5988
6041
  }
5989
- case (isElementRef(expr) && expr.isChildren): {
6042
+ case (ModelLayer.FqnExpr.isModelRef(expr) && expr.selector === "children"): {
6043
+ const fqn = ModelLayer.FqnRef.toFqn(expr.ref);
5990
6044
  return y$2(
5991
- [...model.children(expr.element)].map(
6045
+ [...model.children(fqn)].map(
5992
6046
  (el) => Connection.isOutgoing(el.id)
5993
6047
  )
5994
6048
  );
5995
6049
  }
5996
- case (isElementRef(expr) && expr.isDescendants): {
6050
+ case (ModelLayer.FqnExpr.isModelRef(expr) && expr.selector === "descendants"): {
6051
+ const fqn = ModelLayer.FqnRef.toFqn(expr.ref);
5997
6052
  return y$2([
5998
- Connection.isInside(expr.element),
5999
- ...[...model.children(expr.element)].map(
6053
+ Connection.isInside(fqn),
6054
+ ...[...model.children(fqn)].map(
6000
6055
  (el) => Connection.isOutgoing(el.id)
6001
6056
  )
6002
6057
  ]);
6003
6058
  }
6004
- case isExpandedElementExpr(expr): {
6059
+ case (ModelLayer.FqnExpr.isModelRef(expr) && expr.selector === "expanded"): {
6060
+ const fqn = ModelLayer.FqnRef.toFqn(expr.ref);
6005
6061
  return y$2([
6006
- Connection.isOutgoing(expr.expanded),
6007
- Connection.isInside(expr.expanded)
6062
+ Connection.isOutgoing(fqn),
6063
+ Connection.isInside(fqn)
6008
6064
  ]);
6009
6065
  }
6010
- case isElementRef(expr): {
6011
- return Connection.isOutgoing(expr.element);
6066
+ case ModelLayer.FqnExpr.isModelRef(expr): {
6067
+ const fqn = ModelLayer.FqnRef.toFqn(expr.ref);
6068
+ return Connection.isOutgoing(fqn);
6012
6069
  }
6013
6070
  default:
6014
6071
  nonexhaustive(expr);
@@ -6083,41 +6140,43 @@ const WildcardPredicate = {
6083
6140
 
6084
6141
  function processElementPredicate(expr, op, ctx) {
6085
6142
  switch (true) {
6086
- case isCustomElement(expr): {
6143
+ case ModelLayer.FqnExpr.isCustom(expr): {
6087
6144
  if (op === "include") {
6088
6145
  return processElementPredicate(expr.custom.expr, op, ctx);
6089
6146
  }
6090
6147
  return ctx.stage;
6091
6148
  }
6092
- case isElementWhere(expr): {
6149
+ case ModelLayer.FqnExpr.isWhere(expr): {
6093
6150
  const where = whereOperatorAsPredicate(expr.where.condition);
6094
6151
  const filterWhere = T(where);
6095
6152
  return processElementPredicate(expr.where.expr, op, { ...ctx, where, filterWhere });
6096
6153
  }
6097
- case isExpandedElementExpr(expr): {
6154
+ case (ModelLayer.FqnExpr.isModelRef(expr) && expr.selector === "expanded"): {
6098
6155
  return ExpandedElementPredicate[op]({ ...ctx, expr }) ?? ctx.stage;
6099
6156
  }
6100
- case isElementRef(expr): {
6101
- return ElementRefPredicate[op]({ ...ctx, expr }) ?? ctx.stage;
6102
- }
6103
- case isWildcard(expr):
6157
+ case ModelLayer.FqnExpr.isWildcard(expr): {
6104
6158
  return WildcardPredicate[op]({ ...ctx, expr }) ?? ctx.stage;
6105
- case isElementKindExpr(expr):
6106
- case isElementTagExpr(expr):
6159
+ }
6160
+ case ModelLayer.FqnExpr.isElementKindExpr(expr):
6161
+ case ModelLayer.FqnExpr.isElementTagExpr(expr): {
6107
6162
  return ElementKindOrTagPredicate[op]({ ...ctx, expr }) ?? ctx.stage;
6163
+ }
6164
+ case ModelLayer.FqnExpr.isModelRef(expr): {
6165
+ return ElementRefPredicate[op]({ ...ctx, expr }) ?? ctx.stage;
6166
+ }
6108
6167
  default:
6109
6168
  nonexhaustive(expr);
6110
6169
  }
6111
6170
  }
6112
6171
  function processRelationtPredicate(expr, op, ctx) {
6113
6172
  switch (true) {
6114
- case isCustomRelationExpr(expr): {
6173
+ case ModelLayer.RelationExpr.isCustom(expr): {
6115
6174
  if (op === "include") {
6116
- return processRelationtPredicate(expr.customRelation.relation, op, ctx);
6175
+ return processRelationtPredicate(expr.customRelation.expr, op, ctx);
6117
6176
  }
6118
6177
  return ctx.stage;
6119
6178
  }
6120
- case isRelationWhere(expr): {
6179
+ case ModelLayer.RelationExpr.isWhere(expr): {
6121
6180
  const where = whereOperatorAsPredicate(expr.where.condition);
6122
6181
  const filterRelations = (relations) => {
6123
6182
  return new Set(T([...relations], where));
@@ -6135,16 +6194,16 @@ function processRelationtPredicate(expr, op, ctx) {
6135
6194
  filterWhere
6136
6195
  });
6137
6196
  }
6138
- case isInOut(expr): {
6197
+ case ModelLayer.RelationExpr.isInOut(expr): {
6139
6198
  return InOutRelationPredicate[op]({ ...ctx, expr }) ?? ctx.stage;
6140
6199
  }
6141
- case isRelation(expr): {
6200
+ case ModelLayer.RelationExpr.isDirect(expr): {
6142
6201
  return DirectRelationExprPredicate[op]({ ...ctx, expr }) ?? ctx.stage;
6143
6202
  }
6144
- case isOutgoing$1(expr): {
6203
+ case ModelLayer.RelationExpr.isOutgoing(expr): {
6145
6204
  return OutgoingExprPredicate[op]({ ...ctx, expr }) ?? ctx.stage;
6146
6205
  }
6147
- case isIncoming$1(expr): {
6206
+ case ModelLayer.RelationExpr.isIncoming(expr): {
6148
6207
  return IncomingExprPredicate[op]({ ...ctx, expr }) ?? ctx.stage;
6149
6208
  }
6150
6209
  default:
@@ -6172,14 +6231,14 @@ function processPredicates(model, memory, rules) {
6172
6231
  for (const expr of exprs) {
6173
6232
  let stage = op === "include" ? memory.stageInclude(expr) : memory.stageExclude(expr);
6174
6233
  switch (true) {
6175
- case isElementPredicateExpr(expr):
6234
+ case ModelLayer.isAnyFqnExpr(expr):
6176
6235
  stage = processElementPredicate(expr, op, {
6177
6236
  ...ctx,
6178
6237
  stage,
6179
6238
  memory
6180
6239
  }) ?? stage;
6181
6240
  break;
6182
- case isRelationPredicateExpr(expr):
6241
+ case ModelLayer.isAnyRelationExpr(expr):
6183
6242
  stage = processRelationtPredicate(expr, op, {
6184
6243
  ...ctx,
6185
6244
  stage,
@@ -7146,6 +7205,11 @@ class LikeC4Model {
7146
7205
  this.#allTags.get(tag).add(el);
7147
7206
  }
7148
7207
  }
7208
+ for (const [projectId, elements] of t$1($model.imports)) {
7209
+ for (const element of sortParentsFirst(elements)) {
7210
+ this.addImportedElement(projectId, element);
7211
+ }
7212
+ }
7149
7213
  for (const relation of r$3($model.relations)) {
7150
7214
  const el = this.addRelation(relation);
7151
7215
  for (const tag of el.tags) {
@@ -7410,7 +7474,7 @@ class LikeC4Model {
7410
7474
  if (this.#elements.has(element.id)) {
7411
7475
  throw new Error(`Element ${element.id} already exists`);
7412
7476
  }
7413
- const el = new ElementModel(this, Object.freeze(structuredClone(element)));
7477
+ const el = new ElementModel(this, Object.freeze(element));
7414
7478
  this.#elements.set(el.id, el);
7415
7479
  const parentId = parentFqn(el.id);
7416
7480
  if (parentId) {
@@ -7422,13 +7486,39 @@ class LikeC4Model {
7422
7486
  }
7423
7487
  return el;
7424
7488
  }
7489
+ addImportedElement(projectId, element) {
7490
+ invariant(!isGlobalFqn(element.id), `Imported element already has global FQN`);
7491
+ const id = GlobalFqn(projectId, element.id);
7492
+ if (this.#elements.has(id)) {
7493
+ throw new Error(`Element ${id} already exists`);
7494
+ }
7495
+ const el = new ElementModel(
7496
+ this,
7497
+ Object.freeze({
7498
+ ...element,
7499
+ id
7500
+ })
7501
+ );
7502
+ this.#elements.set(el.id, el);
7503
+ let parentId = parentFqn(el.id);
7504
+ while (parentId) {
7505
+ if (parentId.includes(".") && this.#elements.has(parentId)) {
7506
+ this.#parents.set(el.id, this.element(parentId));
7507
+ this.#children.get(parentId).add(el);
7508
+ return el;
7509
+ }
7510
+ parentId = parentFqn(parentId);
7511
+ }
7512
+ this.#rootElements.add(el);
7513
+ return el;
7514
+ }
7425
7515
  addRelation(relation) {
7426
7516
  if (this.#relations.has(relation.id)) {
7427
7517
  throw new Error(`Relation ${relation.id} already exists`);
7428
7518
  }
7429
7519
  const rel = new RelationshipModel(
7430
7520
  this,
7431
- Object.freeze(structuredClone(relation))
7521
+ Object.freeze(relation)
7432
7522
  );
7433
7523
  const { source, target } = rel;
7434
7524
  this.#relations.set(rel.id, rel);
@@ -7457,6 +7547,7 @@ class LikeC4Model {
7457
7547
  }
7458
7548
  ((LikeC4Model2) => {
7459
7549
  LikeC4Model2.EMPTY = LikeC4Model2.create({
7550
+ projectId: "default",
7460
7551
  specification: {
7461
7552
  elements: {},
7462
7553
  relationships: {},
@@ -7474,7 +7565,8 @@ class LikeC4Model {
7474
7565
  },
7475
7566
  elements: {},
7476
7567
  relations: {},
7477
- views: {}
7568
+ views: {},
7569
+ imports: {}
7478
7570
  });
7479
7571
  })(LikeC4Model || (LikeC4Model = {}));
7480
7572