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