@likec4/core 1.19.1 → 1.19.2

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 (40) hide show
  1. package/dist/builder/index.d.mts +3 -3
  2. package/dist/builder/index.d.ts +3 -3
  3. package/dist/builder/index.js +2 -2
  4. package/dist/compute-view/index.d.mts +2 -2
  5. package/dist/compute-view/index.d.ts +2 -2
  6. package/dist/compute-view/index.js +3 -3
  7. package/dist/index.d.mts +2 -2
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +2 -2
  10. package/dist/model/index.d.mts +8 -3
  11. package/dist/model/index.d.ts +8 -3
  12. package/dist/model/index.js +1 -1
  13. package/dist/shared/{core.BZ9Msq7w.d.mts → core.2I-l5UtM.d.mts} +5 -1
  14. package/dist/shared/{core.CmYMqgha.d.mts → core.BL1oTk7-.d.mts} +13 -3
  15. package/dist/shared/{core.BIfgabEw.d.ts → core.CqXs9Frh.d.ts} +5 -1
  16. package/dist/shared/{core.C05RDLhi.d.ts → core.DyJ41fBO.d.ts} +13 -3
  17. package/dist/shared/{index.DafVOuVd.js → index.KOeaSlL8.js} +332 -208
  18. package/dist/shared/{view.CyZrG8BJ.js → view.DrmaOfjr.js} +3 -0
  19. package/dist/types/index.d.mts +2 -2
  20. package/dist/types/index.d.ts +2 -2
  21. package/dist/types/index.js +1 -1
  22. package/package.json +3 -3
  23. package/src/builder/Builder.view-common.ts +1 -0
  24. package/src/compute-view/deployment-view/__test__/fixture.ts +31 -3
  25. package/src/compute-view/deployment-view/_types.ts +2 -1
  26. package/src/compute-view/deployment-view/compute.ts +4 -36
  27. package/src/compute-view/deployment-view/predicates/index.ts +8 -0
  28. package/src/compute-view/deployment-view/predicates/relation-direct.ts +117 -88
  29. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +16 -8
  30. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +18 -12
  31. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +16 -9
  32. package/src/compute-view/deployment-view/predicates/relation-where.ts +18 -0
  33. package/src/compute-view/deployment-view/predicates/utils.ts +183 -0
  34. package/src/model/DeploymentElementModel.ts +14 -1
  35. package/src/model/RelationModel.ts +4 -0
  36. package/src/model/connection/deployment/DeploymentConnectionModel.ts +11 -1
  37. package/src/types/deployments.ts +1 -0
  38. package/src/types/expression-v2.ts +12 -0
  39. package/src/types/index.ts +1 -0
  40. package/src/types/operators.ts +5 -5
@@ -1,5 +1,5 @@
1
- import { O as x, P as s$1, Q as a$4, k as hierarchyLevel, o as isAncestor, f as commonAncestor, r as sortNaturalByFqn, m as m$3, c as commonHead, R as getDefaultExportFromCjs, S as requireForeach, T as requireIterator, U as u$7, N as objectHash, J as intersection, H as difference, L as union, M as stringHash, I as equals, x as isString, q as isDescendantOf, a as isSameHierarchy, C as isome, y as ifilter, B as isIterable, G as toSet, u as sortParentsFirst, F as toArray, D as DefaultMap, A as imap, i as i$9, V as d$6, p as parentFqn, W as n$5, g as compareByFqnHierarchically, w as isNonEmptyArray, d as compareNatural, n as nameFromFqn, t as t$6, l as l$7, X as hasIntersection, s as sortByFqnHierarchically, e as ancestorsFqn, E as iunique, z as iflat, v as getOrCreate } from './object_hash.CE_oF3I3.js';
2
- import { e as DefaultElementShape, d as DefaultThemeColor, a7 as o$9, q as isElementWhere, M as whereOperatorAsPredicate, z as isWildcard, l as isElementKindExpr, p as isElementTagExpr, n as n$4, r as isExpandedElementExpr, m as isElementRef, h as isCustomElement, a5 as isViewRuleStyle, a8 as y$1, Q as ComputedNode, E as ElementKind, N as DefaultArrowType, F as FqnExpr, a4 as isViewRulePredicate, R as RelationExpr, a0 as isViewRuleAutoLayout, a3 as isViewRuleGroup, a1 as isViewRuleGlobalPredicateRef, a2 as isViewRuleGlobalStyle, a6 as stepEdgeId, _ as isDynamicViewParallelSteps, P as DefaultRelationshipColor, O as DefaultLineStyle, u as isOutgoing$1, s as isIncoming$1, t as isInOut, v as isRelation, y as isRelationWhere, j as isCustomRelationExpr, x as isRelationPredicateExpr, b as isElementPredicateExpr, a as isElementView, Z as isDynamicView, Y as isDeploymentView, D as DeploymentElement, U as extractStep, $ as isStepEdgeId, c as isScopedElementView } from './view.CyZrG8BJ.js';
1
+ import { O as x, P as s$1, Q as a$4, k as hierarchyLevel, o as isAncestor, f as commonAncestor, r as sortNaturalByFqn, m as m$3, c as commonHead, R as getDefaultExportFromCjs, S as requireForeach, T as requireIterator, U as u$7, N as objectHash, J as intersection, H as difference, L as union, M as stringHash, I as equals, x as isString, q as isDescendantOf, a as isSameHierarchy, C as isome, y as ifilter, B as isIterable, G as toSet, u as sortParentsFirst, F as toArray, D as DefaultMap, A as imap, i as i$9, V as d$6, p as parentFqn, W as n$5, g as compareByFqnHierarchically, w as isNonEmptyArray, d as compareNatural, n as nameFromFqn, t as t$6, X as hasIntersection, l as l$7, s as sortByFqnHierarchically, e as ancestorsFqn, E as iunique, z as iflat, v as getOrCreate } from './object_hash.CE_oF3I3.js';
2
+ import { e as DefaultElementShape, d as DefaultThemeColor, a7 as o$9, q as isElementWhere, M as whereOperatorAsPredicate, z as isWildcard, l as isElementKindExpr, p as isElementTagExpr, n as n$4, r as isExpandedElementExpr, m as isElementRef, h as isCustomElement, a5 as isViewRuleStyle, a8 as y$1, Q as ComputedNode, E as ElementKind, N as DefaultArrowType, F as FqnExpr, R as RelationExpr, o as o$a, a4 as isViewRulePredicate, a0 as isViewRuleAutoLayout, a3 as isViewRuleGroup, a1 as isViewRuleGlobalPredicateRef, a2 as isViewRuleGlobalStyle, a6 as stepEdgeId, _ as isDynamicViewParallelSteps, P as DefaultRelationshipColor, O as DefaultLineStyle, u as isOutgoing$1, s as isIncoming$1, t as isInOut, v as isRelation, y as isRelationWhere, j as isCustomRelationExpr, x as isRelationPredicateExpr, b as isElementPredicateExpr, a as isElementView, Z as isDynamicView, Y as isDeploymentView, D as DeploymentElement, U as extractStep, $ as isStepEdgeId, c as isScopedElementView } from './view.DrmaOfjr.js';
3
3
  import { u as u$6, a as nonNullable, i as invariant, n as nonexhaustive } from './chunk-RAAYCPUM.M-JWF7SS.js';
4
4
 
5
5
  function r$3(...t){return u$6(Object.values,t)}
@@ -1538,6 +1538,9 @@ class AbstractDeploymentElementModel {
1538
1538
  get tags() {
1539
1539
  return this.$node.tags ?? [];
1540
1540
  }
1541
+ get kind() {
1542
+ return this.$node.kind ?? null;
1543
+ }
1541
1544
  get description() {
1542
1545
  return this.$node.description ?? null;
1543
1546
  }
@@ -1797,6 +1800,9 @@ class DeployedInstanceModel extends AbstractDeploymentElementModel {
1797
1800
  get tags() {
1798
1801
  return this.$instance.tags ?? [];
1799
1802
  }
1803
+ get kind() {
1804
+ return this.$instance.kind ?? null;
1805
+ }
1800
1806
  get description() {
1801
1807
  return this.$instance.description ?? this.element.description;
1802
1808
  }
@@ -1912,6 +1918,9 @@ class DeploymentRelationModel {
1912
1918
  get tags() {
1913
1919
  return this.$relationship.tags ?? [];
1914
1920
  }
1921
+ get kind() {
1922
+ return this.$relationship.kind ?? null;
1923
+ }
1915
1924
  get navigateTo() {
1916
1925
  return this.$relationship.navigateTo ? this.$model.$model.view(this.$relationship.navigateTo) : null;
1917
1926
  }
@@ -2053,11 +2062,10 @@ class DeploymentConnectionModel {
2053
2062
  yield* this.relations.model;
2054
2063
  yield* this.relations.deployment;
2055
2064
  }
2056
- /**
2057
- * Merge with another connection, if it has the same source and target.
2058
- * Returns new connection with union of relationships.
2059
- */
2060
2065
  mergeWith(other) {
2066
+ if (Array.isArray(other)) {
2067
+ return other.reduce((acc, o) => acc.mergeWith(o), this);
2068
+ }
2061
2069
  invariant(this.source.id === other.source.id, "Cannot merge connections with different sources");
2062
2070
  invariant(this.target.id === other.target.id, "Cannot merge connections with different targets");
2063
2071
  return new DeploymentConnectionModel(
@@ -3736,103 +3744,283 @@ function findConnectedElements(stage) {
3736
3744
  );
3737
3745
  }
3738
3746
 
3739
- const IncomingRelationPredicate = {
3740
- include: ({ expr, model, memory, stage }) => {
3741
- const sources = [...memory.elements];
3742
- if (FqnExpr.isWildcard(expr.incoming)) {
3743
- for (const source of sources) {
3744
- if (source.allOutgoing.isEmpty) {
3747
+ const OutgoingRelationPredicate = {
3748
+ include: ({ expr, model, memory, stage, where }) => {
3749
+ const targets = [...memory.elements];
3750
+ if (FqnExpr.isWildcard(expr.outgoing)) {
3751
+ for (const target of targets) {
3752
+ if (target.allIncoming.isEmpty) {
3745
3753
  continue;
3746
3754
  }
3747
- const targets2 = [...resolveAscendingSiblings(source)];
3748
- stage.addConnections(findConnectionsBetween(source, targets2, "directed"));
3755
+ for (const source of resolveAscendingSiblings(target)) {
3756
+ const toInclude = applyPredicate(findConnection(source, target, "directed"), where);
3757
+ stage.addConnections(toInclude);
3758
+ }
3749
3759
  }
3750
3760
  return stage;
3751
3761
  }
3752
- invariant(FqnExpr.isDeploymentRef(expr.incoming), "Only deployment refs are supported in include");
3753
- const targets = resolveElements$1(model, expr.incoming);
3762
+ invariant(FqnExpr.isDeploymentRef(expr.outgoing), "Only deployment refs are supported in include");
3763
+ const sources = resolveElements$1(model, expr.outgoing);
3754
3764
  for (const source of sources) {
3755
- stage.addConnections(findConnectionsBetween(source, targets, "directed"));
3765
+ const toInclude = applyPredicate(findConnectionsBetween(source, targets, "directed"), where);
3766
+ stage.addConnections(toInclude);
3756
3767
  }
3757
3768
  return stage;
3758
3769
  },
3759
- exclude: ({ expr, model, memory, stage }) => {
3760
- if (FqnExpr.isModelRef(expr.incoming)) {
3761
- const excludedRelations = resolveAllImcomingRelations(model, expr.incoming);
3762
- return excludeModelRelations(excludedRelations, { stage, memory });
3770
+ exclude: ({ expr, model, memory, stage, where }) => {
3771
+ if (FqnExpr.isModelRef(expr.outgoing)) {
3772
+ const excludedRelations = resolveAllOutgoingRelations(model, expr.outgoing);
3773
+ return excludeModelRelations(excludedRelations, { stage, memory }, where);
3763
3774
  }
3764
- if (FqnExpr.isWildcard(expr.incoming)) {
3775
+ if (FqnExpr.isWildcard(expr.outgoing)) {
3765
3776
  return stage;
3766
3777
  }
3767
- const isIncoming = filterIncomingConnections(resolveElements$1(model, expr.incoming));
3768
- const toExclude = memory.connections.filter(isIncoming);
3778
+ const isOutgoing = filterOutgoingConnections(resolveElements$1(model, expr.outgoing));
3779
+ const toExclude = x(
3780
+ memory.connections,
3781
+ T(isOutgoing),
3782
+ applyPredicate(where)
3783
+ );
3769
3784
  stage.excludeConnections(toExclude);
3770
3785
  return stage;
3771
3786
  }
3772
3787
  };
3773
- function filterIncomingConnections(targets) {
3788
+ function filterOutgoingConnections(sources) {
3774
3789
  return y$1(
3775
- targets.map((target) => {
3776
- const satisfies = (el) => el === target || isAncestor(target, el);
3790
+ sources.map((source) => {
3791
+ const satisfies = (el) => el === source || isAncestor(source, el);
3777
3792
  return (connection) => {
3778
- return !satisfies(connection.source) && satisfies(connection.target);
3793
+ return satisfies(connection.source) && !satisfies(connection.target);
3779
3794
  };
3780
3795
  })
3781
3796
  );
3782
3797
  }
3783
- function resolveAllImcomingRelations(model, moodelRef) {
3798
+ function resolveAllOutgoingRelations(model, moodelRef) {
3784
3799
  const targets = resolveModelElements(model, moodelRef);
3785
- return new Set(targets.flatMap((e) => [...e.allIncoming]));
3800
+ return new Set(targets.flatMap((e) => [...e.allOutgoing]));
3786
3801
  }
3787
3802
 
3788
- const OutgoingRelationPredicate = {
3803
+ const InOutRelationPredicate$1 = {
3804
+ include: ({ expr, model, memory, stage, where }) => {
3805
+ const sources = [...memory.elements];
3806
+ if (FqnExpr.isWildcard(expr.inout)) {
3807
+ for (const source of sources) {
3808
+ const targets2 = [...resolveAscendingSiblings(source)];
3809
+ const toInclude = matchConnections$1(findConnectionsBetween(source, targets2, "both"), where);
3810
+ stage.addConnections(toInclude);
3811
+ }
3812
+ return stage;
3813
+ }
3814
+ invariant(FqnExpr.isDeploymentRef(expr.inout), "Only deployment refs are supported in include");
3815
+ const targets = resolveElements$1(model, expr.inout);
3816
+ for (const source of sources) {
3817
+ const toInclude = matchConnections$1(findConnectionsBetween(source, targets, "both"), where);
3818
+ stage.addConnections(toInclude);
3819
+ }
3820
+ return stage;
3821
+ },
3822
+ exclude: ({ expr, model, memory, stage, where }) => {
3823
+ if (FqnExpr.isModelRef(expr.inout)) {
3824
+ const elements2 = resolveModelElements(model, expr.inout);
3825
+ if (elements2.length === 0) {
3826
+ return stage;
3827
+ }
3828
+ const excludedRelations = union(
3829
+ /* @__PURE__ */ new Set(),
3830
+ ...elements2.flatMap((e) => [e.allIncoming, e.allOutgoing])
3831
+ );
3832
+ return excludeModelRelations(excludedRelations, { stage, memory }, where);
3833
+ }
3834
+ if (FqnExpr.isWildcard(expr.inout)) {
3835
+ return stage;
3836
+ }
3837
+ const elements = resolveElements$1(model, expr.inout);
3838
+ const isIncoming = filterIncomingConnections(elements);
3839
+ const isOutgoing = filterOutgoingConnections(elements);
3840
+ const toExclude = x(
3841
+ memory.connections,
3842
+ T((c) => isIncoming(c) !== isOutgoing(c)),
3843
+ applyPredicate(where)
3844
+ );
3845
+ stage.excludeConnections(toExclude);
3846
+ return stage;
3847
+ }
3848
+ };
3849
+
3850
+ const WhereRelationPredicate = {
3789
3851
  include: ({ expr, model, memory, stage }) => {
3790
- const targets = [...memory.elements];
3791
- if (FqnExpr.isWildcard(expr.outgoing)) {
3792
- for (const target of targets) {
3793
- if (target.allIncoming.isEmpty) {
3852
+ const where = whereOperatorAsPredicate(expr.where.condition);
3853
+ return predicateToPatch("include", { expr: expr.where.expr, model, stage, memory, where });
3854
+ },
3855
+ exclude: ({ expr, model, memory, stage }) => {
3856
+ const where = whereOperatorAsPredicate(expr.where.condition);
3857
+ return predicateToPatch("exclude", { expr: expr.where.expr, model, stage, memory, where });
3858
+ }
3859
+ };
3860
+
3861
+ const WildcardPredicate$1 = {
3862
+ include: ({ model, stage }) => {
3863
+ const children = [];
3864
+ const rootElements = [...model.roots()].map((root) => {
3865
+ if (!root.onlyOneInstance()) {
3866
+ children.push(...root.children());
3867
+ }
3868
+ return root;
3869
+ });
3870
+ stage.addExplicit(rootElements);
3871
+ if (children.length > 1) {
3872
+ stage.addConnections(findConnectionsWithin([
3873
+ ...rootElements,
3874
+ ...children
3875
+ ]));
3876
+ }
3877
+ return stage;
3878
+ },
3879
+ exclude: ({ stage, memory }) => {
3880
+ stage.exclude(memory.elements);
3881
+ return stage;
3882
+ }
3883
+ };
3884
+
3885
+ function predicateToPatch(op, { expr, where, ...ctx }) {
3886
+ switch (true) {
3887
+ case FqnExpr.isModelRef(expr):
3888
+ return void 0;
3889
+ case FqnExpr.isDeploymentRef(expr):
3890
+ return DeploymentRefPredicate[op]({ ...ctx, expr, where });
3891
+ case FqnExpr.isWildcard(expr):
3892
+ return WildcardPredicate$1[op]({ ...ctx, expr, where });
3893
+ case RelationExpr.isDirect(expr):
3894
+ return DirectRelationPredicate[op]({ ...ctx, expr, where });
3895
+ case RelationExpr.isInOut(expr):
3896
+ return InOutRelationPredicate$1[op]({ ...ctx, expr, where });
3897
+ case RelationExpr.isOutgoing(expr):
3898
+ return OutgoingRelationPredicate[op]({ ...ctx, expr, where });
3899
+ case RelationExpr.isIncoming(expr):
3900
+ return IncomingRelationPredicate[op]({ ...ctx, expr, where });
3901
+ case RelationExpr.isWhere(expr):
3902
+ return WhereRelationPredicate[op]({ ...ctx, expr, where });
3903
+ default:
3904
+ nonexhaustive(expr);
3905
+ }
3906
+ }
3907
+ function excludeModelRelations(relationsToExclude, { stage, memory }, where, filterConnections = () => true) {
3908
+ if (relationsToExclude.size === 0) {
3909
+ return stage;
3910
+ }
3911
+ const toExclude = x(
3912
+ memory.connections,
3913
+ T((c) => filterConnections(c)),
3914
+ // Find connections that have at least one relation in common with the excluded relations
3915
+ T((c) => hasIntersection(c.relations.model, relationsToExclude)),
3916
+ m$3(
3917
+ (c) => c.update({
3918
+ deployment: null,
3919
+ model: intersection(c.relations.model, relationsToExclude)
3920
+ })
3921
+ ),
3922
+ applyPredicate(where),
3923
+ T((c) => c.nonEmpty())
3924
+ );
3925
+ if (toExclude.length === 0) {
3926
+ return stage;
3927
+ }
3928
+ return stage.excludeConnections(toExclude);
3929
+ }
3930
+ function matchConnection$1(c, where) {
3931
+ return applyPredicate(c, where).nonEmpty();
3932
+ }
3933
+ function applyPredicate(...args) {
3934
+ if (args.length === 1) {
3935
+ return (x) => applyPredicate(x, args[0]);
3936
+ }
3937
+ const [c, where] = args;
3938
+ if (where === null) {
3939
+ return c;
3940
+ }
3941
+ if (o$a(c)) {
3942
+ return c.map((x) => applyPredicate(x, where)).filter((x) => x.nonEmpty());
3943
+ }
3944
+ const map2 = toFilterableRelation$1(c.source, c.target);
3945
+ return c.update({
3946
+ model: new Set([...c.relations.model.values()].filter((r) => where(map2(r)))),
3947
+ deployment: new Set([...c.relations.deployment.values()].filter((r) => where(map2(r))))
3948
+ });
3949
+ }
3950
+ function matchConnections$1(connections, where) {
3951
+ if (!where) {
3952
+ return connections;
3953
+ }
3954
+ return x(
3955
+ connections,
3956
+ T((c) => matchConnection$1(c, where))
3957
+ );
3958
+ }
3959
+ function elementToFilterable$1(element) {
3960
+ return i$7(element, ["tags", "kind"]);
3961
+ }
3962
+ function toFilterableRelation$1(source, target) {
3963
+ return (relation) => ({
3964
+ tags: relation.tags,
3965
+ kind: relation.kind,
3966
+ source: elementToFilterable$1(source),
3967
+ target: elementToFilterable$1(target)
3968
+ });
3969
+ }
3970
+
3971
+ const IncomingRelationPredicate = {
3972
+ include: ({ expr, model, memory, stage, where }) => {
3973
+ const sources = [...memory.elements];
3974
+ if (FqnExpr.isWildcard(expr.incoming)) {
3975
+ for (const source of sources) {
3976
+ if (source.allOutgoing.isEmpty) {
3794
3977
  continue;
3795
3978
  }
3796
- for (const source of resolveAscendingSiblings(target)) {
3797
- stage.addConnections(findConnection(source, target, "directed"));
3798
- }
3979
+ const targets2 = [...resolveAscendingSiblings(source)];
3980
+ const toInclude = applyPredicate(findConnectionsBetween(source, targets2, "directed"), where);
3981
+ stage.addConnections(toInclude);
3799
3982
  }
3800
3983
  return stage;
3801
3984
  }
3802
- invariant(FqnExpr.isDeploymentRef(expr.outgoing), "Only deployment refs are supported in include");
3803
- const sources = resolveElements$1(model, expr.outgoing);
3985
+ invariant(FqnExpr.isDeploymentRef(expr.incoming), "Only deployment refs are supported in include");
3986
+ const targets = resolveElements$1(model, expr.incoming);
3804
3987
  for (const source of sources) {
3805
- stage.addConnections(findConnectionsBetween(source, targets, "directed"));
3988
+ const toInclude = applyPredicate(findConnectionsBetween(source, targets, "directed"), where);
3989
+ stage.addConnections(toInclude);
3806
3990
  }
3807
3991
  return stage;
3808
3992
  },
3809
- exclude: ({ expr, model, memory, stage }) => {
3810
- if (FqnExpr.isModelRef(expr.outgoing)) {
3811
- const excludedRelations = resolveAllOutgoingRelations(model, expr.outgoing);
3812
- return excludeModelRelations(excludedRelations, { stage, memory });
3993
+ exclude: ({ expr, model, memory, stage, where }) => {
3994
+ if (FqnExpr.isModelRef(expr.incoming)) {
3995
+ const excludedRelations = resolveAllImcomingRelations(model, expr.incoming);
3996
+ return excludeModelRelations(excludedRelations, { stage, memory }, where);
3813
3997
  }
3814
- if (FqnExpr.isWildcard(expr.outgoing)) {
3998
+ if (FqnExpr.isWildcard(expr.incoming)) {
3815
3999
  return stage;
3816
4000
  }
3817
- const isOutgoing = filterOutgoingConnections(resolveElements$1(model, expr.outgoing));
3818
- const toExclude = memory.connections.filter(isOutgoing);
4001
+ const isIncoming = filterIncomingConnections(resolveElements$1(model, expr.incoming));
4002
+ const toExclude = x(
4003
+ memory.connections,
4004
+ T(isIncoming),
4005
+ applyPredicate(where)
4006
+ );
3819
4007
  stage.excludeConnections(toExclude);
3820
4008
  return stage;
3821
4009
  }
3822
4010
  };
3823
- function filterOutgoingConnections(sources) {
4011
+ function filterIncomingConnections(targets) {
3824
4012
  return y$1(
3825
- sources.map((source) => {
3826
- const satisfies = (el) => el === source || isAncestor(source, el);
4013
+ targets.map((target) => {
4014
+ const satisfies = (el) => el === target || isAncestor(target, el);
3827
4015
  return (connection) => {
3828
- return satisfies(connection.source) && !satisfies(connection.target);
4016
+ return !satisfies(connection.source) && satisfies(connection.target);
3829
4017
  };
3830
4018
  })
3831
4019
  );
3832
4020
  }
3833
- function resolveAllOutgoingRelations(model, moodelRef) {
4021
+ function resolveAllImcomingRelations(model, moodelRef) {
3834
4022
  const targets = resolveModelElements(model, moodelRef);
3835
- return new Set(targets.flatMap((e) => [...e.allOutgoing]));
4023
+ return new Set(targets.flatMap((e) => [...e.allIncoming]));
3836
4024
  }
3837
4025
 
3838
4026
  const resolveAscendingSiblings = (element) => {
@@ -3843,7 +4031,7 @@ const resolveAscendingSiblings = (element) => {
3843
4031
  return siblings;
3844
4032
  };
3845
4033
  const DirectRelationPredicate = {
3846
- include: ({ expr: { source, target, isBidirectional = false }, model, stage }) => {
4034
+ include: ({ expr: { source, target, isBidirectional = false }, model, stage, where }) => {
3847
4035
  invariant(!FqnExpr.isModelRef(source), "Invalid source model ref in direct relation");
3848
4036
  invariant(!FqnExpr.isModelRef(target), "Invalid target model ref in direct relation");
3849
4037
  const sourceIsWildcard = FqnExpr.isWildcard(source);
@@ -3898,7 +4086,7 @@ const DirectRelationPredicate = {
3898
4086
  const isTarget = filterIncomingConnections(targets);
3899
4087
  connections = x(
3900
4088
  sources,
3901
- u$1((s) => findConnectionsBetween(s, targets, dir)),
4089
+ u$1((s) => matchConnections(findConnectionsBetween(s, targets, dir), where)),
3902
4090
  T((c) => isSource(c) && isTarget(c))
3903
4091
  );
3904
4092
  }
@@ -3912,72 +4100,64 @@ const DirectRelationPredicate = {
3912
4100
  }
3913
4101
  return stage;
3914
4102
  },
3915
- exclude: ({ expr, model, memory, stage }) => {
3916
- if (FqnExpr.isWildcard(expr.source) && FqnExpr.isWildcard(expr.target)) {
3917
- stage.excludeConnections(memory.connections);
3918
- return stage;
3919
- }
3920
- if (FqnExpr.isModelRef(expr.source) && FqnExpr.isModelRef(expr.target)) {
3921
- const toExclude2 = resolveRelationsBetweenModelElements({
3922
- source: expr.source,
3923
- target: expr.target,
3924
- expr,
3925
- model
3926
- });
3927
- return excludeModelRelations(toExclude2, { stage, memory });
3928
- }
3929
- if (FqnExpr.isModelRef(expr.source)) {
3930
- if (FqnExpr.isWildcard(expr.target)) {
3931
- const toExclude2 = resolveAllOutgoingRelations(model, expr.source);
3932
- return excludeModelRelations(toExclude2, { stage, memory });
3933
- }
3934
- const allOutgoing = resolveAllOutgoingRelations(model, expr.source);
3935
- const isTarget2 = deploymentExpressionToPredicate(expr.target);
3936
- return excludeModelRelations(
3937
- allOutgoing,
3938
- { stage, memory },
3939
- (c) => isTarget2(c.target)
3940
- );
3941
- }
3942
- if (FqnExpr.isModelRef(expr.target)) {
3943
- const toExclude2 = resolveAllImcomingRelations(model, expr.target);
3944
- const isSource2 = deploymentExpressionToPredicate(expr.source);
3945
- return excludeModelRelations(
3946
- toExclude2,
3947
- { stage, memory },
3948
- (c) => isSource2(c.source)
3949
- );
3950
- }
3951
- const isSource = deploymentExpressionToPredicate(expr.source);
4103
+ exclude: ({ expr, model, memory, stage, where }) => {
3952
4104
  const isTarget = deploymentExpressionToPredicate(expr.target);
3953
- const satisfies = (connection) => {
3954
- return isSource(connection.source) && isTarget(connection.target) || expr.isBidirectional && isSource(connection.target) && isTarget(connection.source);
3955
- };
3956
- const toExclude = memory.connections.filter(satisfies);
3957
- stage.excludeConnections(toExclude);
3958
- return stage;
4105
+ const isSource = deploymentExpressionToPredicate(expr.source);
4106
+ let modelRelationsToExclude;
4107
+ switch (true) {
4108
+ // * -> *
4109
+ case (FqnExpr.isWildcard(expr.source) && FqnExpr.isWildcard(expr.target)):
4110
+ stage.excludeConnections(matchConnections(memory.connections, where));
4111
+ return stage;
4112
+ // model -> model
4113
+ case (FqnExpr.isModelRef(expr.source) && FqnExpr.isModelRef(expr.target)):
4114
+ modelRelationsToExclude = resolveRelationsBetweenModelElements({
4115
+ source: expr.source,
4116
+ target: expr.target,
4117
+ expr,
4118
+ model
4119
+ });
4120
+ return excludeModelRelations(modelRelationsToExclude, { stage, memory }, where);
4121
+ // model -> *
4122
+ case (FqnExpr.isModelRef(expr.source) && FqnExpr.isWildcard(expr.target)):
4123
+ modelRelationsToExclude = resolveAllOutgoingRelations(model, expr.source);
4124
+ return excludeModelRelations(modelRelationsToExclude, { stage, memory }, where);
4125
+ // model -> deployment
4126
+ case FqnExpr.isModelRef(expr.source):
4127
+ modelRelationsToExclude = resolveAllOutgoingRelations(model, expr.source);
4128
+ return excludeModelRelations(
4129
+ modelRelationsToExclude,
4130
+ { stage, memory },
4131
+ where,
4132
+ (c) => isTarget(c.target)
4133
+ );
4134
+ // deployment -> model
4135
+ case FqnExpr.isModelRef(expr.target):
4136
+ modelRelationsToExclude = resolveAllImcomingRelations(model, expr.target);
4137
+ return excludeModelRelations(
4138
+ modelRelationsToExclude,
4139
+ { stage, memory },
4140
+ where,
4141
+ (c) => isSource(c.source)
4142
+ );
4143
+ // deployment -> deployment
4144
+ default:
4145
+ const satisfies = (connection) => {
4146
+ return isSource(connection.source) && isTarget(connection.target) || expr.isBidirectional === true && isSource(connection.target) && isTarget(connection.source);
4147
+ };
4148
+ const deploymentRelationsToExclude = x(
4149
+ memory.connections,
4150
+ T(satisfies),
4151
+ applyPredicate(where)
4152
+ );
4153
+ if (deploymentRelationsToExclude.length === 0) {
4154
+ return stage;
4155
+ }
4156
+ stage.excludeConnections(deploymentRelationsToExclude);
4157
+ return stage;
4158
+ }
3959
4159
  }
3960
4160
  };
3961
- function excludeModelRelations(relationsToExclude, { stage, memory }, filterConnections = () => true) {
3962
- if (relationsToExclude.size === 0) {
3963
- return stage;
3964
- }
3965
- const toExclude = x(
3966
- memory.connections,
3967
- // Find connections that have at least one relation in common with the excluded relations
3968
- T((c) => filterConnections(c) && hasIntersection(c.relations.model, relationsToExclude)),
3969
- m$3(
3970
- (c) => c.update({
3971
- deployment: null,
3972
- model: intersection(c.relations.model, relationsToExclude)
3973
- })
3974
- )
3975
- );
3976
- if (toExclude.length === 0) {
3977
- return stage;
3978
- }
3979
- return stage.excludeConnections(toExclude);
3980
- }
3981
4161
  function resolveRelationsBetweenModelElements({
3982
4162
  source,
3983
4163
  target,
@@ -3993,71 +4173,35 @@ function resolveRelationsBetweenModelElements({
3993
4173
  }
3994
4174
  return new Set(modelConnections.flatMap((c) => [...c.relations]));
3995
4175
  }
3996
-
3997
- const InOutRelationPredicate$1 = {
3998
- include: ({ expr, model, memory, stage }) => {
3999
- const sources = [...memory.elements];
4000
- if (FqnExpr.isWildcard(expr.inout)) {
4001
- for (const source of sources) {
4002
- const targets2 = [...resolveAscendingSiblings(source)];
4003
- stage.addConnections(findConnectionsBetween(source, targets2, "both"));
4004
- }
4005
- return stage;
4006
- }
4007
- invariant(FqnExpr.isDeploymentRef(expr.inout), "Only deployment refs are supported in include");
4008
- const targets = resolveElements$1(model, expr.inout);
4009
- for (const source of sources) {
4010
- stage.addConnections(findConnectionsBetween(source, targets, "both"));
4011
- }
4012
- return stage;
4013
- },
4014
- exclude: ({ expr, model, memory, stage }) => {
4015
- if (FqnExpr.isModelRef(expr.inout)) {
4016
- const elements2 = resolveModelElements(model, expr.inout);
4017
- if (elements2.length === 0) {
4018
- return stage;
4019
- }
4020
- const excludedRelations = union(
4021
- /* @__PURE__ */ new Set(),
4022
- ...elements2.flatMap((e) => [e.allIncoming, e.allOutgoing])
4023
- );
4024
- return excludeModelRelations(excludedRelations, { stage, memory });
4025
- }
4026
- if (FqnExpr.isWildcard(expr.inout)) {
4027
- return stage;
4028
- }
4029
- const elements = resolveElements$1(model, expr.inout);
4030
- const isIncoming = filterIncomingConnections(elements);
4031
- const isOutgoing = filterOutgoingConnections(elements);
4032
- const toExclude = memory.connections.filter((c) => isIncoming(c) !== isOutgoing(c));
4033
- stage.excludeConnections(toExclude);
4034
- return stage;
4176
+ function elementToFilterable(element) {
4177
+ return i$7(element, ["tags", "kind"]);
4178
+ }
4179
+ function toFilterableRelation(source, target) {
4180
+ return (relation) => ({
4181
+ tags: relation.tags,
4182
+ kind: relation.kind,
4183
+ source: elementToFilterable(source),
4184
+ target: elementToFilterable(target)
4185
+ });
4186
+ }
4187
+ function matchConnection(c, where) {
4188
+ if (!where) {
4189
+ return true;
4035
4190
  }
4036
- };
4037
-
4038
- const WildcardPredicate$1 = {
4039
- include: ({ model, stage }) => {
4040
- const children = [];
4041
- const rootElements = [...model.roots()].map((root) => {
4042
- if (!root.onlyOneInstance()) {
4043
- children.push(...root.children());
4044
- }
4045
- return root;
4046
- });
4047
- stage.addExplicit(rootElements);
4048
- if (children.length > 1) {
4049
- stage.addConnections(findConnectionsWithin([
4050
- ...rootElements,
4051
- ...children
4052
- ]));
4053
- }
4054
- return stage;
4055
- },
4056
- exclude: ({ stage, memory }) => {
4057
- stage.exclude(memory.elements);
4058
- return stage;
4191
+ return [
4192
+ ...Array.from(c.relations.deployment.values()).map(toFilterableRelation(c.source, c.target)),
4193
+ ...Array.from(c.relations.model.values()).map(toFilterableRelation(c.source, c.target))
4194
+ ].filter(where).length > 0;
4195
+ }
4196
+ function matchConnections(connections, where) {
4197
+ if (!where) {
4198
+ return connections;
4059
4199
  }
4060
- };
4200
+ return x(
4201
+ connections,
4202
+ T((c) => matchConnection(c, where))
4203
+ );
4204
+ }
4061
4205
 
4062
4206
  let StageFinal$1 = class StageFinal {
4063
4207
  constructor(memory) {
@@ -4235,31 +4379,8 @@ function processPredicates$1(model, rules) {
4235
4379
  const exprs = rule.include ?? rule.exclude;
4236
4380
  for (const expr of exprs) {
4237
4381
  let stage = op === "include" ? memory.stageInclude(expr) : memory.stageExclude(expr);
4238
- const ctx = { model, stage, memory };
4239
- switch (true) {
4240
- case FqnExpr.isModelRef(expr):
4241
- break;
4242
- case FqnExpr.isDeploymentRef(expr):
4243
- stage = DeploymentRefPredicate[op]({ ...ctx, expr }) ?? stage;
4244
- break;
4245
- case FqnExpr.isWildcard(expr):
4246
- stage = WildcardPredicate$1[op]({ ...ctx, expr }) ?? stage;
4247
- break;
4248
- case RelationExpr.isDirect(expr):
4249
- stage = DirectRelationPredicate[op]({ ...ctx, expr }) ?? stage;
4250
- break;
4251
- case RelationExpr.isInOut(expr):
4252
- stage = InOutRelationPredicate$1[op]({ ...ctx, expr }) ?? stage;
4253
- break;
4254
- case RelationExpr.isOutgoing(expr):
4255
- stage = OutgoingRelationPredicate[op]({ ...ctx, expr }) ?? stage;
4256
- break;
4257
- case RelationExpr.isIncoming(expr):
4258
- stage = IncomingRelationPredicate[op]({ ...ctx, expr }) ?? stage;
4259
- break;
4260
- default:
4261
- nonexhaustive(expr);
4262
- }
4382
+ const ctx = { expr, model, stage, memory, where: null };
4383
+ stage = predicateToPatch(op, ctx) ?? stage;
4263
4384
  memory = stage.commit();
4264
4385
  }
4265
4386
  }
@@ -4273,7 +4394,7 @@ function computeDeploymentView(likec4model, {
4273
4394
  // exclude rules
4274
4395
  ...view
4275
4396
  }) {
4276
- let memory = processPredicates$1(likec4model.deployment, rules);
4397
+ const memory = processPredicates$1(likec4model.deployment, rules);
4277
4398
  const nodesMap = buildNodes$1(memory);
4278
4399
  const computedEdges = toComputedEdges$1(memory.connections);
4279
4400
  linkNodesWithEdges(nodesMap, computedEdges);
@@ -6718,6 +6839,9 @@ class RelationshipModel {
6718
6839
  get tags() {
6719
6840
  return this.$relationship.tags ?? [];
6720
6841
  }
6842
+ get kind() {
6843
+ return this.$relationship.kind ?? null;
6844
+ }
6721
6845
  get links() {
6722
6846
  return this.$relationship.links ?? [];
6723
6847
  }