@likec4/core 0.33.0 → 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,324 +0,0 @@
|
|
|
1
|
-
import { anyPass, both, either, isNil, uniq } from "rambdax";
|
|
2
|
-
import * as Expr from "../types/expression.mjs";
|
|
3
|
-
import { Relations, commonAncestor, isAncestor, isSameHierarchy } from "../utils/index.mjs";
|
|
4
|
-
import { isAnyInOut, isBetween, isIncoming, isInside, isOutgoing } from "../utils/relations.mjs";
|
|
5
|
-
import { ComputeCtx } from "./compute-ctx.mjs";
|
|
6
|
-
export const includeElementRef = (ctx, expr) => {
|
|
7
|
-
const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
|
|
8
|
-
const filters = [];
|
|
9
|
-
if (expr.isDescedants) {
|
|
10
|
-
elements.forEach((child) => {
|
|
11
|
-
filters.push(both(Relations.isInside(expr.element), Relations.isAnyInOut(child.id)));
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
const ctxElements = uniq([...ctx.elements, ...ctx.implicits]);
|
|
15
|
-
const excludeImplicits = [];
|
|
16
|
-
for (const el of elements) {
|
|
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)));
|
|
19
|
-
}
|
|
20
|
-
for (const ctxEl of ctxElements) {
|
|
21
|
-
if (!isSameHierarchy(el, ctxEl)) {
|
|
22
|
-
filters.push(Relations.isAnyBetween(el.id, ctxEl.id));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const relations = filters.length ? ctx.index.filterRelations(anyPass(filters)) : [];
|
|
27
|
-
if (excludeImplicits.length == 0) {
|
|
28
|
-
return ctx.include({ elements, relations });
|
|
29
|
-
}
|
|
30
|
-
return ctx.include({ elements, relations }).exclude({ implicits: excludeImplicits });
|
|
31
|
-
};
|
|
32
|
-
export const excludeElementRef = (ctx, expr) => {
|
|
33
|
-
const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
|
|
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 });
|
|
39
|
-
};
|
|
40
|
-
const asElementPredicate = (expr) => {
|
|
41
|
-
if (expr.isEqual) {
|
|
42
|
-
if (Expr.isElementKindExpr(expr)) {
|
|
43
|
-
return (e) => e.kind === expr.elementKind;
|
|
44
|
-
} else {
|
|
45
|
-
return ({ tags }) => !!tags && tags.includes(expr.elementTag);
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
if (Expr.isElementKindExpr(expr)) {
|
|
49
|
-
return (e) => e.kind !== expr.elementKind;
|
|
50
|
-
} else {
|
|
51
|
-
return ({ tags }) => isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
export const includeElementKindOrTag = (ctx, expr) => {
|
|
56
|
-
const elements = ctx.index.elements.filter(asElementPredicate(expr));
|
|
57
|
-
return elements.reduce(
|
|
58
|
-
(accCtx, el) => includeElementRef(accCtx, {
|
|
59
|
-
element: el.id,
|
|
60
|
-
isDescedants: false
|
|
61
|
-
}),
|
|
62
|
-
ctx
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
export const excludeElementKindOrTag = (ctx, expr) => {
|
|
66
|
-
const predicate = asElementPredicate(expr);
|
|
67
|
-
const elements = [...ctx.elements].filter(predicate);
|
|
68
|
-
const implicits = [...ctx.implicits].filter(predicate);
|
|
69
|
-
return ctx.exclude({ elements, implicits });
|
|
70
|
-
};
|
|
71
|
-
export const includeWildcardRef = (ctx, _expr) => {
|
|
72
|
-
const { root } = ctx;
|
|
73
|
-
if (root) {
|
|
74
|
-
const elements = [ctx.index.find(root), ...ctx.index.children(root)];
|
|
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));
|
|
80
|
-
const implicits = [];
|
|
81
|
-
for (const implicit of allImplicits) {
|
|
82
|
-
if (inOut.some(isAnyInOut(implicit.id))) {
|
|
83
|
-
implicits.push(implicit);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return ctx.include({
|
|
87
|
-
elements,
|
|
88
|
-
relations: [...ctx.index.filterRelations(isInside(root)), ...inOut],
|
|
89
|
-
implicits
|
|
90
|
-
});
|
|
91
|
-
} else {
|
|
92
|
-
const elements = ctx.index.rootElements();
|
|
93
|
-
if (elements.length <= 1) {
|
|
94
|
-
return new ComputeCtx(ctx.index, ctx.root, new Set(elements));
|
|
95
|
-
}
|
|
96
|
-
const relations = ctx.index.filterRelations(
|
|
97
|
-
(rel) => isNil(commonAncestor(rel.source, rel.target))
|
|
98
|
-
);
|
|
99
|
-
return ctx.include({
|
|
100
|
-
elements,
|
|
101
|
-
relations
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
export const excludeWildcardRef = (ctx, _expr) => {
|
|
106
|
-
const { root } = ctx;
|
|
107
|
-
if (root) {
|
|
108
|
-
const relations = [...ctx.relations].filter(either(isInside(root), isAnyInOut(root)));
|
|
109
|
-
return ctx.exclude({
|
|
110
|
-
elements: [...ctx.elements].filter((e) => e.id === root || isAncestor(root, e.id)),
|
|
111
|
-
relations,
|
|
112
|
-
implicits: [...ctx.implicits].filter((e) => relations.some(isAnyInOut(e.id)))
|
|
113
|
-
});
|
|
114
|
-
} else {
|
|
115
|
-
return new ComputeCtx(ctx.index, ctx.root);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
const resolveElements = (ctx, expr) => {
|
|
119
|
-
if (Expr.isWildcard(expr)) {
|
|
120
|
-
if (ctx.root) {
|
|
121
|
-
return [ctx.index.find(ctx.root)];
|
|
122
|
-
} else {
|
|
123
|
-
return ctx.index.rootElements();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (Expr.isElementKindExpr(expr)) {
|
|
127
|
-
return ctx.index.elements.filter((el) => {
|
|
128
|
-
if (expr.isEqual) {
|
|
129
|
-
return el.kind === expr.elementKind;
|
|
130
|
-
}
|
|
131
|
-
return el.kind !== expr.elementKind;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
if (Expr.isElementTagExpr(expr)) {
|
|
135
|
-
return ctx.index.elements.filter((el) => {
|
|
136
|
-
const tags = el.tags;
|
|
137
|
-
if (expr.isEqual) {
|
|
138
|
-
return !!tags && tags.includes(expr.elementTag);
|
|
139
|
-
}
|
|
140
|
-
return isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
if (expr.isDescedants) {
|
|
144
|
-
return ctx.index.children(expr.element);
|
|
145
|
-
} else {
|
|
146
|
-
return [ctx.index.find(expr.element)];
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
export const includeIncomingExpr = (ctx, expr) => {
|
|
150
|
-
if (Expr.isWildcard(expr.incoming) && !ctx.root) {
|
|
151
|
-
return ctx;
|
|
152
|
-
}
|
|
153
|
-
const elements = resolveElements(ctx, expr.incoming);
|
|
154
|
-
if (elements.length === 0) {
|
|
155
|
-
return ctx;
|
|
156
|
-
}
|
|
157
|
-
let allrelations = ctx.index.relations;
|
|
158
|
-
if (Expr.isElementRef(expr.incoming)) {
|
|
159
|
-
allrelations = allrelations.filter(isIncoming(expr.incoming.element));
|
|
160
|
-
}
|
|
161
|
-
const implicits = [];
|
|
162
|
-
const relations = [];
|
|
163
|
-
for (const el of elements) {
|
|
164
|
-
const elRelations = allrelations.filter(isIncoming(el.id));
|
|
165
|
-
if (elRelations.length > 0) {
|
|
166
|
-
relations.push(...elRelations);
|
|
167
|
-
implicits.push(el);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return ctx.include({
|
|
171
|
-
relations,
|
|
172
|
-
implicits
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
export const excludeIncomingExpr = (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
|
-
const isIncomings = anyPass(elements.map((el) => isIncoming(el.id)));
|
|
184
|
-
const excluded = [...ctx.relations].filter(isIncomings);
|
|
185
|
-
if (excluded.length > 0) {
|
|
186
|
-
return ctx.exclude({
|
|
187
|
-
relations: excluded
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
return ctx;
|
|
191
|
-
};
|
|
192
|
-
export const includeOutgoingExpr = (ctx, expr) => {
|
|
193
|
-
if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
|
|
194
|
-
return ctx;
|
|
195
|
-
}
|
|
196
|
-
const elements = resolveElements(ctx, expr.outgoing);
|
|
197
|
-
if (elements.length === 0) {
|
|
198
|
-
return ctx;
|
|
199
|
-
}
|
|
200
|
-
let allrelations = ctx.index.relations;
|
|
201
|
-
if (Expr.isElementRef(expr.outgoing)) {
|
|
202
|
-
allrelations = allrelations.filter(isOutgoing(expr.outgoing.element));
|
|
203
|
-
}
|
|
204
|
-
const implicits = [];
|
|
205
|
-
const relations = [];
|
|
206
|
-
for (const el of elements) {
|
|
207
|
-
const elRelations = allrelations.filter(isOutgoing(el.id));
|
|
208
|
-
if (elRelations.length > 0) {
|
|
209
|
-
relations.push(...elRelations);
|
|
210
|
-
implicits.push(el);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return ctx.include({
|
|
214
|
-
relations,
|
|
215
|
-
implicits
|
|
216
|
-
});
|
|
217
|
-
};
|
|
218
|
-
export const excludeOutgoingExpr = (ctx, expr) => {
|
|
219
|
-
if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
|
|
220
|
-
return ctx;
|
|
221
|
-
}
|
|
222
|
-
const elements = resolveElements(ctx, expr.outgoing);
|
|
223
|
-
if (elements.length === 0) {
|
|
224
|
-
return ctx;
|
|
225
|
-
}
|
|
226
|
-
const isOutgoings = anyPass(elements.map((el) => isOutgoing(el.id)));
|
|
227
|
-
const excluded = [...ctx.relations].filter(isOutgoings);
|
|
228
|
-
if (excluded.length > 0) {
|
|
229
|
-
return ctx.exclude({
|
|
230
|
-
relations: excluded
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
return ctx;
|
|
234
|
-
};
|
|
235
|
-
export const includeInOutExpr = (ctx, expr) => {
|
|
236
|
-
if (Expr.isWildcard(expr.inout) && !ctx.root) {
|
|
237
|
-
return ctx;
|
|
238
|
-
}
|
|
239
|
-
const targets = resolveElements(ctx, expr.inout);
|
|
240
|
-
if (targets.length === 0) {
|
|
241
|
-
return ctx;
|
|
242
|
-
}
|
|
243
|
-
let allrelations = ctx.index.relations;
|
|
244
|
-
if (Expr.isElementRef(expr.inout)) {
|
|
245
|
-
allrelations = allrelations.filter(isAnyInOut(expr.inout.element));
|
|
246
|
-
}
|
|
247
|
-
const implicits = [];
|
|
248
|
-
const relations = [];
|
|
249
|
-
for (const target of targets) {
|
|
250
|
-
const foundRelations = allrelations.filter(isAnyInOut(target.id));
|
|
251
|
-
if (foundRelations.length > 0) {
|
|
252
|
-
relations.push(...foundRelations);
|
|
253
|
-
implicits.push(target);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return ctx.include({
|
|
257
|
-
relations,
|
|
258
|
-
implicits
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
export const excludeInOutExpr = (ctx, expr) => {
|
|
262
|
-
if (Expr.isWildcard(expr.inout) && !ctx.root) {
|
|
263
|
-
return ctx;
|
|
264
|
-
}
|
|
265
|
-
const targets = resolveElements(ctx, expr.inout);
|
|
266
|
-
if (targets.length === 0) {
|
|
267
|
-
return ctx;
|
|
268
|
-
}
|
|
269
|
-
const excluded = [...ctx.relations].filter(anyPass(targets.map((t) => isAnyInOut(t.id))));
|
|
270
|
-
if (excluded.length > 0) {
|
|
271
|
-
return ctx.exclude({
|
|
272
|
-
relations: excluded
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
return ctx;
|
|
276
|
-
};
|
|
277
|
-
export const includeRelationExpr = (ctx, expr) => {
|
|
278
|
-
const sources = resolveElements(ctx, expr.source);
|
|
279
|
-
const targets = resolveElements(ctx, expr.target);
|
|
280
|
-
if (sources.length === 0 || targets.length === 0) {
|
|
281
|
-
return ctx;
|
|
282
|
-
}
|
|
283
|
-
const implicits = [];
|
|
284
|
-
const relations = [];
|
|
285
|
-
for (const source of sources) {
|
|
286
|
-
for (const target of targets) {
|
|
287
|
-
if (isSameHierarchy(source, target)) {
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
const foundRelations = ctx.index.filterRelations(isBetween(source.id, target.id));
|
|
291
|
-
if (foundRelations.length > 0) {
|
|
292
|
-
relations.push(...foundRelations);
|
|
293
|
-
implicits.push(source, target);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return ctx.include({
|
|
298
|
-
relations,
|
|
299
|
-
implicits
|
|
300
|
-
});
|
|
301
|
-
};
|
|
302
|
-
export const excludeRelationExpr = (ctx, expr) => {
|
|
303
|
-
const sources = resolveElements(ctx, expr.source);
|
|
304
|
-
const targets = resolveElements(ctx, expr.target);
|
|
305
|
-
const filters = [];
|
|
306
|
-
for (const source of sources) {
|
|
307
|
-
for (const target of targets) {
|
|
308
|
-
if (isSameHierarchy(source, target)) {
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
filters.push(isBetween(source.id, target.id));
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
if (filters.length == 0) {
|
|
315
|
-
return ctx;
|
|
316
|
-
}
|
|
317
|
-
const excluded = [...ctx.relations].filter(anyPass(filters));
|
|
318
|
-
if (excluded.length == 0) {
|
|
319
|
-
return ctx;
|
|
320
|
-
}
|
|
321
|
-
return ctx.exclude({
|
|
322
|
-
relations: excluded
|
|
323
|
-
});
|
|
324
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { compact, find, map, mapToObj } from "remeda";
|
|
2
|
-
import { ModelIndex } from "../model-index/index.mjs";
|
|
3
|
-
import { computeElementView } from "./compute-element-view.mjs";
|
|
4
|
-
export function computeView(view, index) {
|
|
5
|
-
try {
|
|
6
|
-
return computeElementView(view, index);
|
|
7
|
-
} catch (e) {
|
|
8
|
-
console.error(e);
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export function computeViews(model) {
|
|
13
|
-
const index = ModelIndex.from(model);
|
|
14
|
-
const computedViews = compact(map(model.views, (view) => computeView(view, index)));
|
|
15
|
-
return {
|
|
16
|
-
elements: model.elements,
|
|
17
|
-
relations: model.relations,
|
|
18
|
-
views: mapToObj(computedViews, (view) => [view.id, view])
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export function assignNavigateTo(views) {
|
|
22
|
-
const allElementViews = /* @__PURE__ */ new Map();
|
|
23
|
-
for (const { id, viewOf } of views) {
|
|
24
|
-
if (viewOf) {
|
|
25
|
-
const viewsOf = allElementViews.get(viewOf) ?? [];
|
|
26
|
-
viewsOf.push(id);
|
|
27
|
-
allElementViews.set(viewOf, viewsOf);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
for (const { id, nodes } of views) {
|
|
31
|
-
for (const node of nodes) {
|
|
32
|
-
const navigateTo = find(allElementViews.get(node.id) ?? [], (v) => v !== id);
|
|
33
|
-
if (navigateTo) {
|
|
34
|
-
node.navigateTo = navigateTo;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return views;
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { computeView, computeViews, assignNavigateTo } from "./compute.mjs";
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { prop, uniqBy } from "rambdax";
|
|
2
|
-
import { compareByFqnHierarchically, isAncestor } from "../../utils/fqn.mjs";
|
|
3
|
-
export function* anyPossibleRelations(elements) {
|
|
4
|
-
const uniqElements = uniqBy(prop("id"), elements).sort(compareByFqnHierarchically).reverse();
|
|
5
|
-
for (const source of uniqElements) {
|
|
6
|
-
for (const target of uniqElements) {
|
|
7
|
-
if (source !== target && !isAncestor(source, target) && !isAncestor(target, source)) {
|
|
8
|
-
yield [source, target];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { anyPass, filter, clone, isNil } from "rambdax";
|
|
2
|
-
import { isDefined } from "remeda";
|
|
3
|
-
import * as Expr from "../../types/expression.mjs";
|
|
4
|
-
import { nonexhaustive } from "../../errors/index.mjs";
|
|
5
|
-
export function applyViewRuleStyles(rules, _nodes) {
|
|
6
|
-
if (rules.length === 0) {
|
|
7
|
-
return _nodes;
|
|
8
|
-
}
|
|
9
|
-
const nodes = clone(_nodes);
|
|
10
|
-
for (const rule of rules) {
|
|
11
|
-
const predicates = [];
|
|
12
|
-
if (!rule.style.color && !rule.style.shape) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
for (const target of rule.targets) {
|
|
16
|
-
if (Expr.isWildcard(target)) {
|
|
17
|
-
predicates.push(() => true);
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
if (Expr.isElementKindExpr(target)) {
|
|
21
|
-
predicates.push(
|
|
22
|
-
target.isEqual ? (n) => n.kind === target.elementKind : (n) => n.kind !== target.elementKind
|
|
23
|
-
);
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (Expr.isElementTagExpr(target)) {
|
|
27
|
-
predicates.push(
|
|
28
|
-
target.isEqual ? ({ tags }) => !!tags && tags.includes(target.elementTag) : ({ tags }) => isNil(tags) || !tags.includes(target.elementTag)
|
|
29
|
-
);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
if (Expr.isElementRef(target)) {
|
|
33
|
-
const { element, isDescedants } = target;
|
|
34
|
-
predicates.push(
|
|
35
|
-
isDescedants ? (n) => n.id.startsWith(element + ".") : (n) => n.id === element
|
|
36
|
-
);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
nonexhaustive(target);
|
|
40
|
-
}
|
|
41
|
-
filter(anyPass(predicates), nodes).forEach((n) => {
|
|
42
|
-
n.shape = rule.style.shape ?? n.shape;
|
|
43
|
-
n.color = rule.style.color ?? n.color;
|
|
44
|
-
if (isDefined.strict(rule.style.icon)) {
|
|
45
|
-
n.icon = rule.style.icon;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return nodes;
|
|
50
|
-
}
|
package/dist/errors/_base.mjs
DELETED
package/dist/errors/index.mjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BaseError } from "./_base.mjs";
|
|
2
|
-
export const InvalidModelError = BaseError.subclass("InvalidModelError");
|
|
3
|
-
export function ensureModel(condition, message) {
|
|
4
|
-
if (condition) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
throw new InvalidModelError(message ?? "ModelIndex Invariant failed");
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BaseError } from "./_base.mjs";
|
|
2
|
-
export const UnexpectedNullableError = BaseError.subclass("UnexpectedNullableError");
|
|
3
|
-
export function nonNullable(value) {
|
|
4
|
-
if (value == null) {
|
|
5
|
-
throw new UnexpectedNullableError("Expected value to not be null or undefined");
|
|
6
|
-
}
|
|
7
|
-
return value;
|
|
8
|
-
}
|
package/dist/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as ModelIndex } from "./ModelIndex.mjs";
|
package/dist/types/_common.mjs
DELETED
|
File without changes
|
|
File without changes
|
package/dist/types/diagram.mjs
DELETED
|
File without changes
|
package/dist/types/element.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export function isElementRef(expr) {
|
|
2
|
-
return "element" in expr && "isDescedants" in expr;
|
|
3
|
-
}
|
|
4
|
-
export function isWildcard(expr) {
|
|
5
|
-
return "wildcard" in expr;
|
|
6
|
-
}
|
|
7
|
-
export function isElementKindExpr(expr) {
|
|
8
|
-
return "elementKind" in expr && "isEqual" in expr;
|
|
9
|
-
}
|
|
10
|
-
export function isElementTagExpr(expr) {
|
|
11
|
-
return "elementTag" in expr && "isEqual" in expr;
|
|
12
|
-
}
|
|
13
|
-
export function isElement(expr) {
|
|
14
|
-
return isElementRef(expr) || isWildcard(expr) || isElementKindExpr(expr) || isElementTagExpr(expr);
|
|
15
|
-
}
|
|
16
|
-
export function isRelation(expr) {
|
|
17
|
-
return "source" in expr && "target" in expr;
|
|
18
|
-
}
|
|
19
|
-
export function isInOut(expr) {
|
|
20
|
-
return "inout" in expr;
|
|
21
|
-
}
|
|
22
|
-
export function isIncoming(expr) {
|
|
23
|
-
return "incoming" in expr;
|
|
24
|
-
}
|
|
25
|
-
export function isOutgoing(expr) {
|
|
26
|
-
return "outgoing" in expr;
|
|
27
|
-
}
|
|
28
|
-
export function isAnyRelation(expr) {
|
|
29
|
-
return isRelation(expr) || isInOut(expr) || isIncoming(expr) || isOutgoing(expr);
|
|
30
|
-
}
|
package/dist/types/index.mjs
DELETED
package/dist/types/model.mjs
DELETED
|
File without changes
|
package/dist/types/opaque.mjs
DELETED
|
File without changes
|
package/dist/types/relation.mjs
DELETED
|
File without changes
|
package/dist/types/theme.mjs
DELETED
|
File without changes
|
package/dist/types/view.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export function isViewRuleExpression(rule) {
|
|
2
|
-
return "exprs" in rule && "isInclude" in rule;
|
|
3
|
-
}
|
|
4
|
-
export function isViewRuleStyle(rule) {
|
|
5
|
-
return "style" in rule && "targets" in rule;
|
|
6
|
-
}
|
|
7
|
-
export function isViewRuleAutoLayout(rule) {
|
|
8
|
-
return "autoLayout" in rule;
|
|
9
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { invariant } from "../errors/index.mjs";
|
|
2
|
-
export const computeNodeLevels = ({ nodes }) => {
|
|
3
|
-
const nodeLevels = {};
|
|
4
|
-
const compute = (node, level) => {
|
|
5
|
-
let levels = nodeLevels[node.id];
|
|
6
|
-
if (levels) {
|
|
7
|
-
return levels;
|
|
8
|
-
}
|
|
9
|
-
if (node.children.length === 0) {
|
|
10
|
-
levels = { level, depth: 0 };
|
|
11
|
-
nodeLevels[node.id] = levels;
|
|
12
|
-
return levels;
|
|
13
|
-
}
|
|
14
|
-
let depth = 1;
|
|
15
|
-
for (const childId of node.children) {
|
|
16
|
-
const child = nodes.find((n) => n.id === childId);
|
|
17
|
-
invariant(child, `Child ${childId} not found`);
|
|
18
|
-
const { depth: childDepth } = compute(child, level + 1);
|
|
19
|
-
depth = Math.max(childDepth + 1, depth);
|
|
20
|
-
}
|
|
21
|
-
levels = { level, depth };
|
|
22
|
-
nodeLevels[node.id] = levels;
|
|
23
|
-
return levels;
|
|
24
|
-
};
|
|
25
|
-
for (const node of nodes) {
|
|
26
|
-
if (!node.parent) {
|
|
27
|
-
compute(node, 0);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return nodeLevels;
|
|
31
|
-
};
|
package/dist/utils/fqn.mjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { anyPass } from "remeda";
|
|
2
|
-
import { isString } from "./guards.mjs";
|
|
3
|
-
export function nameFromFqn(fqn) {
|
|
4
|
-
const lastDot = fqn.lastIndexOf(".");
|
|
5
|
-
if (lastDot > 0) {
|
|
6
|
-
return fqn.slice(lastDot + 1);
|
|
7
|
-
} else {
|
|
8
|
-
return fqn;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export function isAncestor(...args) {
|
|
12
|
-
const ancestor = isString(args[0]) ? args[0] : args[0].id;
|
|
13
|
-
const another = isString(args[1]) ? args[1] : args[1].id;
|
|
14
|
-
return another.startsWith(ancestor + ".");
|
|
15
|
-
}
|
|
16
|
-
export function isSameHierarchy(...args) {
|
|
17
|
-
const one = isString(args[0]) ? args[0] : args[0].id;
|
|
18
|
-
const another = isString(args[1]) ? args[1] : args[1].id;
|
|
19
|
-
return one === another || another.startsWith(one + ".") || one.startsWith(another + ".");
|
|
20
|
-
}
|
|
21
|
-
export function isDescendantOf(ancestors) {
|
|
22
|
-
const predicates = ancestors.flatMap((a) => [(e) => e.id === a.id, (e) => isAncestor(a, e)]);
|
|
23
|
-
return anyPass(predicates);
|
|
24
|
-
}
|
|
25
|
-
export function notDescendantOf(ancestors) {
|
|
26
|
-
const isDescendant = isDescendantOf(ancestors);
|
|
27
|
-
return (e) => !isDescendant(e);
|
|
28
|
-
}
|
|
29
|
-
export function commonAncestor(first, second) {
|
|
30
|
-
const parentA = parentFqn(first);
|
|
31
|
-
const parentB = parentFqn(second);
|
|
32
|
-
if (parentA === parentB) {
|
|
33
|
-
return parentA;
|
|
34
|
-
}
|
|
35
|
-
if (!parentA || !parentB) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
const a = first.split(".");
|
|
39
|
-
const b = second.split(".");
|
|
40
|
-
let ancestor = null;
|
|
41
|
-
while (a.length > 1 && b.length > 1 && !!a[0] && a[0] === b[0]) {
|
|
42
|
-
ancestor = ancestor ? `${ancestor}.${a[0]}` : a[0];
|
|
43
|
-
a.shift();
|
|
44
|
-
b.shift();
|
|
45
|
-
}
|
|
46
|
-
return ancestor;
|
|
47
|
-
}
|
|
48
|
-
export function parentFqn(fqn) {
|
|
49
|
-
const lastDot = fqn.lastIndexOf(".");
|
|
50
|
-
if (lastDot > 0) {
|
|
51
|
-
return fqn.substring(0, lastDot);
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
export function compareFqnHierarchically(a, b) {
|
|
56
|
-
const depthA = a.split(".").length;
|
|
57
|
-
const depthB = b.split(".").length;
|
|
58
|
-
if (depthA === depthB) {
|
|
59
|
-
return 0;
|
|
60
|
-
} else {
|
|
61
|
-
return depthA - depthB;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export function compareByFqnHierarchically(a, b) {
|
|
65
|
-
return compareFqnHierarchically(a.id, b.id);
|
|
66
|
-
}
|
package/dist/utils/guards.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { NonExhaustiveError } from "../errors/nonexhaustive.mjs";
|
|
2
|
-
export function isString(value) {
|
|
3
|
-
return typeof value === "string";
|
|
4
|
-
}
|
|
5
|
-
export function failUnexpected(arg) {
|
|
6
|
-
throw new NonExhaustiveError(`Unexpected value: ${JSON.stringify(arg)}`);
|
|
7
|
-
}
|
|
8
|
-
export function ignoreNeverInRuntime(arg) {
|
|
9
|
-
console.warn(`Unexpected and ignored value: ${JSON.stringify(arg)}`);
|
|
10
|
-
}
|
|
11
|
-
export function isNonEmptyArray(arr) {
|
|
12
|
-
return arr.length > 0;
|
|
13
|
-
}
|
package/dist/utils/index.mjs
DELETED