@likec4/core 0.32.0 → 0.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 (106) hide show
  1. package/dist/colors.d.ts +76 -9
  2. package/dist/colors.js +116 -93
  3. package/dist/colors.mjs +112 -0
  4. package/dist/compute-view/EdgeBuilder.d.ts +0 -1
  5. package/dist/compute-view/EdgeBuilder.js +37 -34
  6. package/dist/compute-view/EdgeBuilder.mjs +31 -0
  7. package/dist/compute-view/compute-ctx.d.ts +0 -1
  8. package/dist/compute-view/compute-ctx.js +33 -24
  9. package/dist/compute-view/compute-ctx.mjs +42 -0
  10. package/dist/compute-view/compute-element-view.d.ts +2 -3
  11. package/dist/compute-view/compute-element-view.js +137 -525
  12. package/dist/compute-view/compute-element-view.mjs +145 -0
  13. package/dist/compute-view/compute-predicates.d.ts +16 -0
  14. package/dist/compute-view/compute-predicates.js +358 -0
  15. package/dist/compute-view/compute-predicates.mjs +324 -0
  16. package/dist/compute-view/compute.d.ts +8 -9
  17. package/dist/compute-view/compute.js +49 -39
  18. package/dist/compute-view/compute.mjs +39 -0
  19. package/dist/compute-view/index.d.ts +1 -1
  20. package/dist/compute-view/index.js +24 -2
  21. package/dist/compute-view/index.mjs +1 -0
  22. package/dist/compute-view/utils/anyPossibleRelations.d.ts +0 -1
  23. package/dist/compute-view/utils/anyPossibleRelations.js +17 -12
  24. package/dist/compute-view/utils/anyPossibleRelations.mjs +12 -0
  25. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +3 -0
  26. package/dist/compute-view/utils/applyViewRuleStyles.js +59 -0
  27. package/dist/compute-view/utils/applyViewRuleStyles.mjs +50 -0
  28. package/dist/compute-view/utils/sortNodes.d.ts +0 -1
  29. package/dist/compute-view/utils/sortNodes.js +47 -42
  30. package/dist/compute-view/utils/sortNodes.mjs +40 -0
  31. package/dist/errors/_base.d.ts +0 -1
  32. package/dist/errors/_base.js +14 -11
  33. package/dist/errors/_base.mjs +4 -0
  34. package/dist/errors/index.d.ts +1 -1
  35. package/dist/errors/index.js +60 -5
  36. package/dist/errors/index.mjs +5 -0
  37. package/dist/errors/invariant.d.ts +0 -2
  38. package/dist/errors/invariant.js +16 -21
  39. package/dist/errors/invariant.mjs +8 -0
  40. package/dist/errors/model-index.d.ts +0 -1
  41. package/dist/errors/model-index.js +16 -14
  42. package/dist/errors/model-index.mjs +8 -0
  43. package/dist/errors/non-nullable.d.ts +2 -0
  44. package/dist/errors/non-nullable.js +16 -0
  45. package/dist/errors/non-nullable.mjs +8 -0
  46. package/dist/errors/nonexhaustive.d.ts +0 -1
  47. package/dist/errors/nonexhaustive.js +13 -6
  48. package/dist/errors/nonexhaustive.mjs +5 -0
  49. package/dist/index.d.ts +6 -3
  50. package/dist/index.js +71 -7
  51. package/dist/index.mjs +6 -0
  52. package/dist/model-index/ModelIndex.d.ts +0 -1
  53. package/dist/model-index/ModelIndex.js +125 -122
  54. package/dist/model-index/ModelIndex.mjs +128 -0
  55. package/dist/model-index/index.d.ts +0 -1
  56. package/dist/model-index/index.js +13 -2
  57. package/dist/model-index/index.mjs +1 -0
  58. package/dist/types/_common.d.ts +0 -1
  59. package/dist/types/_common.js +1 -2
  60. package/dist/types/_common.mjs +0 -0
  61. package/dist/types/computed-view.d.ts +7 -6
  62. package/dist/types/computed-view.js +1 -2
  63. package/dist/types/computed-view.mjs +0 -0
  64. package/dist/types/diagram.d.ts +5 -2
  65. package/dist/types/diagram.js +1 -2
  66. package/dist/types/diagram.mjs +0 -0
  67. package/dist/types/element.d.ts +3 -7
  68. package/dist/types/element.js +13 -5
  69. package/dist/types/element.mjs +5 -0
  70. package/dist/types/expression.d.ts +0 -1
  71. package/dist/types/expression.js +45 -31
  72. package/dist/types/expression.mjs +30 -0
  73. package/dist/types/index.d.ts +1 -1
  74. package/dist/types/index.js +48 -4
  75. package/dist/types/index.mjs +3 -0
  76. package/dist/types/model.d.ts +0 -1
  77. package/dist/types/model.js +1 -2
  78. package/dist/types/model.mjs +0 -0
  79. package/dist/types/opaque.d.ts +0 -1
  80. package/dist/types/opaque.js +1 -2
  81. package/dist/types/opaque.mjs +0 -0
  82. package/dist/types/relation.d.ts +0 -1
  83. package/dist/types/relation.js +1 -2
  84. package/dist/types/relation.mjs +0 -0
  85. package/dist/types/theme.d.ts +22 -0
  86. package/dist/types/theme.js +1 -0
  87. package/dist/types/theme.mjs +0 -0
  88. package/dist/types/view.d.ts +2 -2
  89. package/dist/types/view.js +15 -8
  90. package/dist/types/view.mjs +9 -0
  91. package/dist/utils/compute-node-levels.d.ts +0 -1
  92. package/dist/utils/compute-node-levels.js +45 -29
  93. package/dist/utils/compute-node-levels.mjs +31 -0
  94. package/dist/utils/fqn.d.ts +0 -1
  95. package/dist/utils/fqn.js +71 -71
  96. package/dist/utils/fqn.mjs +66 -0
  97. package/dist/utils/guards.d.ts +0 -1
  98. package/dist/utils/guards.js +19 -12
  99. package/dist/utils/guards.mjs +13 -0
  100. package/dist/utils/index.d.ts +0 -1
  101. package/dist/utils/index.js +49 -5
  102. package/dist/utils/index.mjs +4 -0
  103. package/dist/utils/relations.d.ts +0 -1
  104. package/dist/utils/relations.js +56 -49
  105. package/dist/utils/relations.mjs +42 -0
  106. package/package.json +20 -55
@@ -0,0 +1,145 @@
1
+ import { allPass, find } from "remeda";
2
+ import { nonNullable, nonexhaustive } from "../errors/index.mjs";
3
+ import {
4
+ DefaultElementShape,
5
+ DefaultThemeColor
6
+ } from "../types/index.mjs";
7
+ import * as Expr from "../types/expression.mjs";
8
+ import { isViewRuleAutoLayout, isViewRuleExpression, isViewRuleStyle } from "../types/view.mjs";
9
+ import { compareByFqnHierarchically, isAncestor, isSameHierarchy, parentFqn } from "../utils/index.mjs";
10
+ import { EdgeBuilder } from "./EdgeBuilder.mjs";
11
+ import { ComputeCtx } from "./compute-ctx.mjs";
12
+ import {
13
+ excludeElementKindOrTag,
14
+ excludeElementRef,
15
+ excludeInOutExpr,
16
+ excludeIncomingExpr,
17
+ excludeOutgoingExpr,
18
+ excludeRelationExpr,
19
+ excludeWildcardRef,
20
+ includeElementKindOrTag,
21
+ includeElementRef,
22
+ includeInOutExpr,
23
+ includeIncomingExpr,
24
+ includeOutgoingExpr,
25
+ includeRelationExpr,
26
+ includeWildcardRef
27
+ } from "./compute-predicates.mjs";
28
+ import { applyViewRuleStyles } from "./utils/applyViewRuleStyles.mjs";
29
+ import { sortNodes } from "./utils/sortNodes.mjs";
30
+ function reduceToMap(elementsIterator) {
31
+ return Array.from(elementsIterator).sort(compareByFqnHierarchically).reduce((map, { id, color, shape, ...el }) => {
32
+ let parent = parentFqn(id);
33
+ while (parent) {
34
+ if (map.has(parent)) {
35
+ break;
36
+ }
37
+ parent = parentFqn(parent);
38
+ }
39
+ if (parent) {
40
+ const parentNd = nonNullable(map.get(parent));
41
+ parentNd.children.push(id);
42
+ }
43
+ const node = {
44
+ ...el,
45
+ id,
46
+ parent,
47
+ color: color ?? DefaultThemeColor,
48
+ shape: shape ?? DefaultElementShape,
49
+ children: [],
50
+ inEdges: [],
51
+ outEdges: []
52
+ };
53
+ map.set(id, node);
54
+ return map;
55
+ }, /* @__PURE__ */ new Map());
56
+ }
57
+ export function computeElementView(view, index) {
58
+ const rootElement = view.viewOf ?? null;
59
+ let ctx = new ComputeCtx(index, rootElement);
60
+ const rulesInclude = view.rules.filter(isViewRuleExpression);
61
+ if (rootElement && rulesInclude.length == 0) {
62
+ ctx = ctx.include({
63
+ elements: [index.find(rootElement)]
64
+ });
65
+ }
66
+ for (const { isInclude, exprs } of rulesInclude) {
67
+ for (const expr of exprs) {
68
+ if (Expr.isElementKindExpr(expr) || Expr.isElementTagExpr(expr)) {
69
+ ctx = isInclude ? includeElementKindOrTag(ctx, expr) : excludeElementKindOrTag(ctx, expr);
70
+ continue;
71
+ }
72
+ if (Expr.isElementRef(expr)) {
73
+ ctx = isInclude ? includeElementRef(ctx, expr) : excludeElementRef(ctx, expr);
74
+ continue;
75
+ }
76
+ if (Expr.isWildcard(expr)) {
77
+ ctx = isInclude ? includeWildcardRef(ctx, expr) : excludeWildcardRef(ctx, expr);
78
+ continue;
79
+ }
80
+ if (Expr.isIncoming(expr)) {
81
+ ctx = isInclude ? includeIncomingExpr(ctx, expr) : excludeIncomingExpr(ctx, expr);
82
+ continue;
83
+ }
84
+ if (Expr.isOutgoing(expr)) {
85
+ ctx = isInclude ? includeOutgoingExpr(ctx, expr) : excludeOutgoingExpr(ctx, expr);
86
+ continue;
87
+ }
88
+ if (Expr.isInOut(expr)) {
89
+ ctx = isInclude ? includeInOutExpr(ctx, expr) : excludeInOutExpr(ctx, expr);
90
+ continue;
91
+ }
92
+ if (Expr.isRelation(expr)) {
93
+ ctx = isInclude ? includeRelationExpr(ctx, expr) : excludeRelationExpr(ctx, expr);
94
+ continue;
95
+ }
96
+ nonexhaustive(expr);
97
+ }
98
+ }
99
+ const allElements = [...ctx.elements, ...ctx.implicits].sort(compareByFqnHierarchically).reverse();
100
+ const elementsWithRelations = /* @__PURE__ */ new Set();
101
+ const edgeBuilder = new EdgeBuilder();
102
+ const anscestorOf = (id) => (e) => e.id === id || isAncestor(e.id, id);
103
+ const sortedRelations = [...ctx.relations];
104
+ for (const rel of sortedRelations) {
105
+ const source = find(allElements, anscestorOf(rel.source));
106
+ if (!source) {
107
+ continue;
108
+ }
109
+ const target = find(
110
+ allElements,
111
+ allPass([anscestorOf(rel.target), (e) => !isSameHierarchy(e, source)])
112
+ );
113
+ if (!target) {
114
+ continue;
115
+ }
116
+ elementsWithRelations.add(source);
117
+ elementsWithRelations.add(target);
118
+ edgeBuilder.add(source.id, target.id, rel);
119
+ }
120
+ const elements = /* @__PURE__ */ new Set([...ctx.elements, ...elementsWithRelations]);
121
+ const nodesMap = reduceToMap(elements);
122
+ const edges = edgeBuilder.build().map((edge) => {
123
+ while (edge.parent) {
124
+ if (nodesMap.has(edge.parent)) {
125
+ break;
126
+ }
127
+ edge.parent = parentFqn(edge.parent);
128
+ }
129
+ nonNullable(nodesMap.get(edge.source)).outEdges.push(edge.id);
130
+ nonNullable(nodesMap.get(edge.target)).inEdges.push(edge.id);
131
+ return edge;
132
+ });
133
+ const nodes = applyViewRuleStyles(
134
+ view.rules.filter(isViewRuleStyle),
135
+ sortNodes(nodesMap, edges)
136
+ // map(e => nodesMap.get(e.id)!, Array.from(elements))
137
+ );
138
+ const autoLayoutRule = view.rules.find(isViewRuleAutoLayout);
139
+ return {
140
+ ...view,
141
+ autoLayout: autoLayoutRule?.autoLayout ?? "TB",
142
+ nodes,
143
+ edges
144
+ };
145
+ }
@@ -0,0 +1,16 @@
1
+ import * as Expr from '../types/expression';
2
+ import { ComputeCtx } from './compute-ctx';
3
+ export declare const includeElementRef: (ctx: ComputeCtx, expr: Expr.ElementRefExpr) => ComputeCtx;
4
+ export declare const excludeElementRef: (ctx: ComputeCtx, expr: Expr.ElementRefExpr) => ComputeCtx;
5
+ export declare const includeElementKindOrTag: (ctx: ComputeCtx, expr: Expr.ElementKindExpr | Expr.ElementTagExpr) => ComputeCtx;
6
+ export declare const excludeElementKindOrTag: (ctx: ComputeCtx, expr: Expr.ElementKindExpr | Expr.ElementTagExpr) => ComputeCtx;
7
+ export declare const includeWildcardRef: (ctx: ComputeCtx, _expr: Expr.WildcardExpr) => ComputeCtx;
8
+ export declare const excludeWildcardRef: (ctx: ComputeCtx, _expr: Expr.WildcardExpr) => ComputeCtx;
9
+ export declare const includeIncomingExpr: (ctx: ComputeCtx, expr: Expr.IncomingExpr) => ComputeCtx;
10
+ export declare const excludeIncomingExpr: (ctx: ComputeCtx, expr: Expr.IncomingExpr) => ComputeCtx;
11
+ export declare const includeOutgoingExpr: (ctx: ComputeCtx, expr: Expr.OutgoingExpr) => ComputeCtx;
12
+ export declare const excludeOutgoingExpr: (ctx: ComputeCtx, expr: Expr.OutgoingExpr) => ComputeCtx;
13
+ export declare const includeInOutExpr: (ctx: ComputeCtx, expr: Expr.InOutExpr) => ComputeCtx;
14
+ export declare const excludeInOutExpr: (ctx: ComputeCtx, expr: Expr.InOutExpr) => ComputeCtx;
15
+ export declare const includeRelationExpr: (ctx: ComputeCtx, expr: Expr.RelationExpr) => ComputeCtx;
16
+ export declare const excludeRelationExpr: (ctx: ComputeCtx, expr: Expr.RelationExpr) => ComputeCtx;
@@ -0,0 +1,358 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.includeWildcardRef = exports.includeRelationExpr = exports.includeOutgoingExpr = exports.includeIncomingExpr = exports.includeInOutExpr = exports.includeElementRef = exports.includeElementKindOrTag = exports.excludeWildcardRef = exports.excludeRelationExpr = exports.excludeOutgoingExpr = exports.excludeIncomingExpr = exports.excludeInOutExpr = exports.excludeElementRef = exports.excludeElementKindOrTag = void 0;
7
+ var _rambdax = require("rambdax");
8
+ var Expr = _interopRequireWildcard(require("../types/expression"));
9
+ var _utils = require("../utils");
10
+ var _relations = require("../utils/relations");
11
+ var _computeCtx = require("./compute-ctx");
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+ const includeElementRef = (ctx, expr) => {
15
+ const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
16
+ const filters = [];
17
+ if (expr.isDescedants) {
18
+ elements.forEach(child => {
19
+ filters.push((0, _rambdax.both)(_utils.Relations.isInside(expr.element), _utils.Relations.isAnyInOut(child.id)));
20
+ });
21
+ }
22
+ const ctxElements = (0, _rambdax.uniq)([...ctx.elements, ...ctx.implicits]);
23
+ const excludeImplicits = [];
24
+ for (const el of elements) {
25
+ if (ctx.root && ctx.root !== el.id && !(0, _utils.isAncestor)(el.id, ctx.root)) {
26
+ excludeImplicits.push(...[...ctx.implicits].filter(impl => (0, _utils.isAncestor)(el.id, impl.id)));
27
+ }
28
+ for (const ctxEl of ctxElements) {
29
+ if (!(0, _utils.isSameHierarchy)(el, ctxEl)) {
30
+ filters.push(_utils.Relations.isAnyBetween(el.id, ctxEl.id));
31
+ }
32
+ }
33
+ }
34
+ const relations = filters.length ? ctx.index.filterRelations((0, _rambdax.anyPass)(filters)) : [];
35
+ if (excludeImplicits.length == 0) {
36
+ return ctx.include({
37
+ elements,
38
+ relations
39
+ });
40
+ }
41
+ return ctx.include({
42
+ elements,
43
+ relations
44
+ }).exclude({
45
+ implicits: excludeImplicits
46
+ });
47
+ };
48
+ exports.includeElementRef = includeElementRef;
49
+ const excludeElementRef = (ctx, expr) => {
50
+ const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
51
+ const elementsIds = elements.map(e => e.id);
52
+ const relations = [...ctx.relations].filter(r => elementsIds.includes(r.source) || elementsIds.includes(r.target));
53
+ return ctx.exclude({
54
+ elements,
55
+ relations
56
+ });
57
+ };
58
+ exports.excludeElementRef = excludeElementRef;
59
+ const asElementPredicate = expr => {
60
+ if (expr.isEqual) {
61
+ if (Expr.isElementKindExpr(expr)) {
62
+ return e => e.kind === expr.elementKind;
63
+ } else {
64
+ return ({
65
+ tags
66
+ }) => !!tags && tags.includes(expr.elementTag);
67
+ }
68
+ } else {
69
+ if (Expr.isElementKindExpr(expr)) {
70
+ return e => e.kind !== expr.elementKind;
71
+ } else {
72
+ return ({
73
+ tags
74
+ }) => (0, _rambdax.isNil)(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
75
+ }
76
+ }
77
+ };
78
+ const includeElementKindOrTag = (ctx, expr) => {
79
+ const elements = ctx.index.elements.filter(asElementPredicate(expr));
80
+ return elements.reduce((accCtx, el) => includeElementRef(accCtx, {
81
+ element: el.id,
82
+ isDescedants: false
83
+ }), ctx);
84
+ };
85
+ exports.includeElementKindOrTag = includeElementKindOrTag;
86
+ const excludeElementKindOrTag = (ctx, expr) => {
87
+ const predicate = asElementPredicate(expr);
88
+ const elements = [...ctx.elements].filter(predicate);
89
+ const implicits = [...ctx.implicits].filter(predicate);
90
+ return ctx.exclude({
91
+ elements,
92
+ implicits
93
+ });
94
+ };
95
+ exports.excludeElementKindOrTag = excludeElementKindOrTag;
96
+ const includeWildcardRef = (ctx, _expr) => {
97
+ const {
98
+ root
99
+ } = ctx;
100
+ if (root) {
101
+ const elements = [ctx.index.find(root), ...ctx.index.children(root)];
102
+ const allImplicits = [...ctx.index.siblings(root), ...ctx.index.ancestors(root).flatMap(a => [...ctx.index.siblings(a.id)])];
103
+ const inOut = ctx.index.filterRelations((0, _relations.isAnyInOut)(root));
104
+ const implicits = [];
105
+ for (const implicit of allImplicits) {
106
+ if (inOut.some((0, _relations.isAnyInOut)(implicit.id))) {
107
+ implicits.push(implicit);
108
+ }
109
+ }
110
+ return ctx.include({
111
+ elements,
112
+ relations: [...ctx.index.filterRelations((0, _relations.isInside)(root)), ...inOut],
113
+ implicits
114
+ });
115
+ } else {
116
+ const elements = ctx.index.rootElements();
117
+ if (elements.length <= 1) {
118
+ return new _computeCtx.ComputeCtx(ctx.index, ctx.root, new Set(elements));
119
+ }
120
+ const relations = ctx.index.filterRelations(rel => (0, _rambdax.isNil)((0, _utils.commonAncestor)(rel.source, rel.target)));
121
+ return ctx.include({
122
+ elements,
123
+ relations
124
+ });
125
+ }
126
+ };
127
+ exports.includeWildcardRef = includeWildcardRef;
128
+ const excludeWildcardRef = (ctx, _expr) => {
129
+ const {
130
+ root
131
+ } = ctx;
132
+ if (root) {
133
+ const relations = [...ctx.relations].filter((0, _rambdax.either)((0, _relations.isInside)(root), (0, _relations.isAnyInOut)(root)));
134
+ return ctx.exclude({
135
+ elements: [...ctx.elements].filter(e => e.id === root || (0, _utils.isAncestor)(root, e.id)),
136
+ relations,
137
+ implicits: [...ctx.implicits].filter(e => relations.some((0, _relations.isAnyInOut)(e.id)))
138
+ });
139
+ } else {
140
+ return new _computeCtx.ComputeCtx(ctx.index, ctx.root);
141
+ }
142
+ };
143
+ exports.excludeWildcardRef = excludeWildcardRef;
144
+ const resolveElements = (ctx, expr) => {
145
+ if (Expr.isWildcard(expr)) {
146
+ if (ctx.root) {
147
+ return [ctx.index.find(ctx.root)];
148
+ } else {
149
+ return ctx.index.rootElements();
150
+ }
151
+ }
152
+ if (Expr.isElementKindExpr(expr)) {
153
+ return ctx.index.elements.filter(el => {
154
+ if (expr.isEqual) {
155
+ return el.kind === expr.elementKind;
156
+ }
157
+ return el.kind !== expr.elementKind;
158
+ });
159
+ }
160
+ if (Expr.isElementTagExpr(expr)) {
161
+ return ctx.index.elements.filter(el => {
162
+ const tags = el.tags;
163
+ if (expr.isEqual) {
164
+ return !!tags && tags.includes(expr.elementTag);
165
+ }
166
+ return (0, _rambdax.isNil)(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
167
+ });
168
+ }
169
+ if (expr.isDescedants) {
170
+ return ctx.index.children(expr.element);
171
+ } else {
172
+ return [ctx.index.find(expr.element)];
173
+ }
174
+ };
175
+ const includeIncomingExpr = (ctx, expr) => {
176
+ if (Expr.isWildcard(expr.incoming) && !ctx.root) {
177
+ return ctx;
178
+ }
179
+ const elements = resolveElements(ctx, expr.incoming);
180
+ if (elements.length === 0) {
181
+ return ctx;
182
+ }
183
+ let allrelations = ctx.index.relations;
184
+ if (Expr.isElementRef(expr.incoming)) {
185
+ allrelations = allrelations.filter((0, _relations.isIncoming)(expr.incoming.element));
186
+ }
187
+ const implicits = [];
188
+ const relations = [];
189
+ for (const el of elements) {
190
+ const elRelations = allrelations.filter((0, _relations.isIncoming)(el.id));
191
+ if (elRelations.length > 0) {
192
+ relations.push(...elRelations);
193
+ implicits.push(el);
194
+ }
195
+ }
196
+ return ctx.include({
197
+ relations,
198
+ implicits
199
+ });
200
+ };
201
+ exports.includeIncomingExpr = includeIncomingExpr;
202
+ const excludeIncomingExpr = (ctx, expr) => {
203
+ if (Expr.isWildcard(expr.incoming) && !ctx.root) {
204
+ return ctx;
205
+ }
206
+ const elements = resolveElements(ctx, expr.incoming);
207
+ if (elements.length === 0) {
208
+ return ctx;
209
+ }
210
+ const isIncomings = (0, _rambdax.anyPass)(elements.map(el => (0, _relations.isIncoming)(el.id)));
211
+ const excluded = [...ctx.relations].filter(isIncomings);
212
+ if (excluded.length > 0) {
213
+ return ctx.exclude({
214
+ relations: excluded
215
+ });
216
+ }
217
+ return ctx;
218
+ };
219
+ exports.excludeIncomingExpr = excludeIncomingExpr;
220
+ const includeOutgoingExpr = (ctx, expr) => {
221
+ if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
222
+ return ctx;
223
+ }
224
+ const elements = resolveElements(ctx, expr.outgoing);
225
+ if (elements.length === 0) {
226
+ return ctx;
227
+ }
228
+ let allrelations = ctx.index.relations;
229
+ if (Expr.isElementRef(expr.outgoing)) {
230
+ allrelations = allrelations.filter((0, _relations.isOutgoing)(expr.outgoing.element));
231
+ }
232
+ const implicits = [];
233
+ const relations = [];
234
+ for (const el of elements) {
235
+ const elRelations = allrelations.filter((0, _relations.isOutgoing)(el.id));
236
+ if (elRelations.length > 0) {
237
+ relations.push(...elRelations);
238
+ implicits.push(el);
239
+ }
240
+ }
241
+ return ctx.include({
242
+ relations,
243
+ implicits
244
+ });
245
+ };
246
+ exports.includeOutgoingExpr = includeOutgoingExpr;
247
+ const excludeOutgoingExpr = (ctx, expr) => {
248
+ if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
249
+ return ctx;
250
+ }
251
+ const elements = resolveElements(ctx, expr.outgoing);
252
+ if (elements.length === 0) {
253
+ return ctx;
254
+ }
255
+ const isOutgoings = (0, _rambdax.anyPass)(elements.map(el => (0, _relations.isOutgoing)(el.id)));
256
+ const excluded = [...ctx.relations].filter(isOutgoings);
257
+ if (excluded.length > 0) {
258
+ return ctx.exclude({
259
+ relations: excluded
260
+ });
261
+ }
262
+ return ctx;
263
+ };
264
+ exports.excludeOutgoingExpr = excludeOutgoingExpr;
265
+ const includeInOutExpr = (ctx, expr) => {
266
+ if (Expr.isWildcard(expr.inout) && !ctx.root) {
267
+ return ctx;
268
+ }
269
+ const targets = resolveElements(ctx, expr.inout);
270
+ if (targets.length === 0) {
271
+ return ctx;
272
+ }
273
+ let allrelations = ctx.index.relations;
274
+ if (Expr.isElementRef(expr.inout)) {
275
+ allrelations = allrelations.filter((0, _relations.isAnyInOut)(expr.inout.element));
276
+ }
277
+ const implicits = [];
278
+ const relations = [];
279
+ for (const target of targets) {
280
+ const foundRelations = allrelations.filter((0, _relations.isAnyInOut)(target.id));
281
+ if (foundRelations.length > 0) {
282
+ relations.push(...foundRelations);
283
+ implicits.push(target);
284
+ }
285
+ }
286
+ return ctx.include({
287
+ relations,
288
+ implicits
289
+ });
290
+ };
291
+ exports.includeInOutExpr = includeInOutExpr;
292
+ const excludeInOutExpr = (ctx, expr) => {
293
+ if (Expr.isWildcard(expr.inout) && !ctx.root) {
294
+ return ctx;
295
+ }
296
+ const targets = resolveElements(ctx, expr.inout);
297
+ if (targets.length === 0) {
298
+ return ctx;
299
+ }
300
+ const excluded = [...ctx.relations].filter((0, _rambdax.anyPass)(targets.map(t => (0, _relations.isAnyInOut)(t.id))));
301
+ if (excluded.length > 0) {
302
+ return ctx.exclude({
303
+ relations: excluded
304
+ });
305
+ }
306
+ return ctx;
307
+ };
308
+ exports.excludeInOutExpr = excludeInOutExpr;
309
+ const includeRelationExpr = (ctx, expr) => {
310
+ const sources = resolveElements(ctx, expr.source);
311
+ const targets = resolveElements(ctx, expr.target);
312
+ if (sources.length === 0 || targets.length === 0) {
313
+ return ctx;
314
+ }
315
+ const implicits = [];
316
+ const relations = [];
317
+ for (const source of sources) {
318
+ for (const target of targets) {
319
+ if ((0, _utils.isSameHierarchy)(source, target)) {
320
+ continue;
321
+ }
322
+ const foundRelations = ctx.index.filterRelations((0, _relations.isBetween)(source.id, target.id));
323
+ if (foundRelations.length > 0) {
324
+ relations.push(...foundRelations);
325
+ implicits.push(source, target);
326
+ }
327
+ }
328
+ }
329
+ return ctx.include({
330
+ relations,
331
+ implicits
332
+ });
333
+ };
334
+ exports.includeRelationExpr = includeRelationExpr;
335
+ const excludeRelationExpr = (ctx, expr) => {
336
+ const sources = resolveElements(ctx, expr.source);
337
+ const targets = resolveElements(ctx, expr.target);
338
+ const filters = [];
339
+ for (const source of sources) {
340
+ for (const target of targets) {
341
+ if ((0, _utils.isSameHierarchy)(source, target)) {
342
+ continue;
343
+ }
344
+ filters.push((0, _relations.isBetween)(source.id, target.id));
345
+ }
346
+ }
347
+ if (filters.length == 0) {
348
+ return ctx;
349
+ }
350
+ const excluded = [...ctx.relations].filter((0, _rambdax.anyPass)(filters));
351
+ if (excluded.length == 0) {
352
+ return ctx;
353
+ }
354
+ return ctx.exclude({
355
+ relations: excluded
356
+ });
357
+ };
358
+ exports.excludeRelationExpr = excludeRelationExpr;