@likec4/core 0.40.0 → 0.41.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/README.md +2 -6
- package/dist/cjs/colors/element.d.ts +68 -0
- package/dist/{esm/colors.js → cjs/colors/element.js} +9 -23
- package/dist/cjs/colors/index.d.ts +132 -0
- package/dist/cjs/colors/index.js +27 -0
- package/dist/cjs/colors/relationships.d.ts +57 -0
- package/dist/cjs/colors/relationships.js +76 -0
- package/dist/cjs/index.d.ts +0 -2
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/types/computed-view.d.ts +10 -7
- package/dist/cjs/types/diagram.d.ts +14 -5
- package/dist/cjs/types/expression.d.ts +1 -1
- package/dist/cjs/types/relation.d.ts +12 -0
- package/dist/cjs/types/relation.js +12 -1
- package/dist/cjs/types/theme.d.ts +12 -14
- package/dist/cjs/types/view.d.ts +7 -4
- package/dist/cjs/types/view.js +1 -1
- package/dist/cjs/utils/fqn.d.ts +6 -1
- package/dist/cjs/utils/fqn.js +17 -4
- package/dist/cjs/utils/guards.d.ts +1 -0
- package/dist/cjs/utils/guards.js +7 -0
- package/dist/cjs/utils/index.d.ts +0 -1
- package/dist/cjs/utils/index.js +0 -11
- package/dist/esm/colors/element.d.ts +68 -0
- package/dist/{cjs/colors.js → esm/colors/element.js} +1 -33
- package/dist/esm/colors/index.d.ts +132 -0
- package/dist/esm/colors/index.js +9 -0
- package/dist/esm/colors/relationships.d.ts +57 -0
- package/dist/esm/colors/relationships.js +64 -0
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.js +1 -3
- package/dist/esm/types/computed-view.d.ts +10 -7
- package/dist/esm/types/diagram.d.ts +14 -5
- package/dist/esm/types/expression.d.ts +1 -1
- package/dist/esm/types/relation.d.ts +12 -0
- package/dist/esm/types/relation.js +3 -0
- package/dist/esm/types/theme.d.ts +12 -14
- package/dist/esm/types/view.d.ts +7 -4
- package/dist/esm/types/view.js +1 -1
- package/dist/esm/utils/fqn.d.ts +6 -1
- package/dist/esm/utils/fqn.js +16 -4
- package/dist/esm/utils/guards.d.ts +1 -0
- package/dist/esm/utils/guards.js +1 -0
- package/dist/esm/utils/index.d.ts +0 -1
- package/dist/esm/utils/index.js +0 -1
- package/package.json +52 -55
- package/dist/cjs/colors.d.ts +0 -148
- package/dist/cjs/compute-view/EdgeBuilder.d.ts +0 -6
- package/dist/cjs/compute-view/EdgeBuilder.js +0 -37
- package/dist/cjs/compute-view/compute-ctx.d.ts +0 -20
- package/dist/cjs/compute-view/compute-ctx.js +0 -91
- package/dist/cjs/compute-view/compute-element-view.d.ts +0 -3
- package/dist/cjs/compute-view/compute-element-view.js +0 -100
- package/dist/cjs/compute-view/compute-predicates.d.ts +0 -16
- package/dist/cjs/compute-view/compute-predicates.js +0 -363
- package/dist/cjs/compute-view/compute.d.ts +0 -14
- package/dist/cjs/compute-view/compute.js +0 -46
- package/dist/cjs/compute-view/index.d.ts +0 -4
- package/dist/cjs/compute-view/index.js +0 -49
- package/dist/cjs/compute-view/resolve-extended-views.d.ts +0 -6
- package/dist/cjs/compute-view/resolve-extended-views.js +0 -53
- package/dist/cjs/compute-view/resolve-relative-paths.d.ts +0 -2
- package/dist/cjs/compute-view/resolve-relative-paths.js +0 -84
- package/dist/cjs/compute-view/utils/anyPossibleRelations.d.ts +0 -2
- package/dist/cjs/compute-view/utils/anyPossibleRelations.js +0 -18
- package/dist/cjs/compute-view/utils/applyViewRuleStyles.d.ts +0 -2
- package/dist/cjs/compute-view/utils/applyViewRuleStyles.js +0 -57
- package/dist/cjs/compute-view/utils/sortNodes.d.ts +0 -19
- package/dist/cjs/compute-view/utils/sortNodes.js +0 -47
- package/dist/cjs/model-index/ModelIndex.d.ts +0 -27
- package/dist/cjs/model-index/ModelIndex.js +0 -139
- package/dist/cjs/model-index/index.d.ts +0 -1
- package/dist/cjs/model-index/index.js +0 -13
- package/dist/cjs/utils/compute-node-levels.d.ts +0 -7
- package/dist/cjs/utils/compute-node-levels.js +0 -48
- package/dist/esm/colors.d.ts +0 -148
- package/dist/esm/compute-view/EdgeBuilder.d.ts +0 -6
- package/dist/esm/compute-view/EdgeBuilder.js +0 -30
- package/dist/esm/compute-view/compute-ctx.d.ts +0 -20
- package/dist/esm/compute-view/compute-ctx.js +0 -100
- package/dist/esm/compute-view/compute-element-view.d.ts +0 -3
- package/dist/esm/compute-view/compute-element-view.js +0 -98
- package/dist/esm/compute-view/compute-predicates.d.ts +0 -16
- package/dist/esm/compute-view/compute-predicates.js +0 -324
- package/dist/esm/compute-view/compute.d.ts +0 -14
- package/dist/esm/compute-view/compute.js +0 -36
- package/dist/esm/compute-view/index.d.ts +0 -4
- package/dist/esm/compute-view/index.js +0 -4
- package/dist/esm/compute-view/resolve-extended-views.d.ts +0 -6
- package/dist/esm/compute-view/resolve-extended-views.js +0 -41
- package/dist/esm/compute-view/resolve-relative-paths.d.ts +0 -2
- package/dist/esm/compute-view/resolve-relative-paths.js +0 -76
- package/dist/esm/compute-view/utils/anyPossibleRelations.d.ts +0 -2
- package/dist/esm/compute-view/utils/anyPossibleRelations.js +0 -12
- package/dist/esm/compute-view/utils/applyViewRuleStyles.d.ts +0 -2
- package/dist/esm/compute-view/utils/applyViewRuleStyles.js +0 -50
- package/dist/esm/compute-view/utils/sortNodes.d.ts +0 -19
- package/dist/esm/compute-view/utils/sortNodes.js +0 -37
- package/dist/esm/model-index/ModelIndex.d.ts +0 -27
- package/dist/esm/model-index/ModelIndex.js +0 -127
- package/dist/esm/model-index/index.d.ts +0 -1
- package/dist/esm/model-index/index.js +0 -1
- package/dist/esm/utils/compute-node-levels.d.ts +0 -7
- package/dist/esm/utils/compute-node-levels.js +0 -31
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { allPass, find } from "remeda";
|
|
2
|
-
import { nonNullable } from "../errors/index.js";
|
|
3
|
-
import {
|
|
4
|
-
DefaultElementShape,
|
|
5
|
-
DefaultThemeColor,
|
|
6
|
-
isViewRuleAutoLayout,
|
|
7
|
-
isViewRuleStyle
|
|
8
|
-
} from "../types/index.js";
|
|
9
|
-
import { compareByFqnHierarchically, isAncestor, isSameHierarchy, parentFqn } from "../utils/index.js";
|
|
10
|
-
import { EdgeBuilder } from "./EdgeBuilder.js";
|
|
11
|
-
import { ComputeCtx } from "./compute-ctx.js";
|
|
12
|
-
import { applyViewRuleStyles } from "./utils/applyViewRuleStyles.js";
|
|
13
|
-
import { sortNodes } from "./utils/sortNodes.js";
|
|
14
|
-
function reduceToMap(elementsIterator) {
|
|
15
|
-
return Array.from(elementsIterator).sort(compareByFqnHierarchically).reduce((map, { id, color, shape, ...el }) => {
|
|
16
|
-
let parent = parentFqn(id);
|
|
17
|
-
let level = 0;
|
|
18
|
-
while (parent) {
|
|
19
|
-
if (map.has(parent)) {
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
parent = parentFqn(parent);
|
|
23
|
-
}
|
|
24
|
-
if (parent) {
|
|
25
|
-
const parentNd = nonNullable(map.get(parent));
|
|
26
|
-
parentNd.children.push(id);
|
|
27
|
-
level = parentNd.level + 1;
|
|
28
|
-
}
|
|
29
|
-
const node = {
|
|
30
|
-
...el,
|
|
31
|
-
id,
|
|
32
|
-
parent,
|
|
33
|
-
level,
|
|
34
|
-
color: color ?? DefaultThemeColor,
|
|
35
|
-
shape: shape ?? DefaultElementShape,
|
|
36
|
-
children: [],
|
|
37
|
-
inEdges: [],
|
|
38
|
-
outEdges: []
|
|
39
|
-
};
|
|
40
|
-
map.set(id, node);
|
|
41
|
-
return map;
|
|
42
|
-
}, /* @__PURE__ */ new Map());
|
|
43
|
-
}
|
|
44
|
-
const keepOriginalSortFromView = (_nodes, ctx) => {
|
|
45
|
-
const nodes = [...ctx.allElements].flatMap((e) => _nodes.get(e.id) || []);
|
|
46
|
-
for (const node of nodes) {
|
|
47
|
-
node.children = nodes.flatMap((n) => n.parent === node.id ? n.id : []);
|
|
48
|
-
}
|
|
49
|
-
return nodes;
|
|
50
|
-
};
|
|
51
|
-
export function computeElementView(view, index) {
|
|
52
|
-
const ctx = ComputeCtx.create(view, index);
|
|
53
|
-
const leafsFirst = [...ctx.allElements].sort((a, b) => -1 * compareByFqnHierarchically(a, b));
|
|
54
|
-
const elementsWithRelations = /* @__PURE__ */ new Set();
|
|
55
|
-
const edgeBuilder = new EdgeBuilder();
|
|
56
|
-
const anscestorOf = (id) => (e) => e.id === id || isAncestor(e.id, id);
|
|
57
|
-
const sortedRelations = [...ctx.relations];
|
|
58
|
-
for (const rel of sortedRelations) {
|
|
59
|
-
const source = find(leafsFirst, anscestorOf(rel.source));
|
|
60
|
-
if (!source) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
const target = find(
|
|
64
|
-
leafsFirst,
|
|
65
|
-
allPass([anscestorOf(rel.target), (e) => !isSameHierarchy(e, source)])
|
|
66
|
-
);
|
|
67
|
-
if (!target) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
elementsWithRelations.add(source);
|
|
71
|
-
elementsWithRelations.add(target);
|
|
72
|
-
edgeBuilder.add(source.id, target.id, rel);
|
|
73
|
-
}
|
|
74
|
-
const nodesMap = reduceToMap(/* @__PURE__ */ new Set([...ctx.elements, ...elementsWithRelations]));
|
|
75
|
-
const edges = edgeBuilder.build().map((edge) => {
|
|
76
|
-
while (edge.parent) {
|
|
77
|
-
if (nodesMap.has(edge.parent)) {
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
edge.parent = parentFqn(edge.parent);
|
|
81
|
-
}
|
|
82
|
-
nonNullable(nodesMap.get(edge.source)).outEdges.push(edge.id);
|
|
83
|
-
nonNullable(nodesMap.get(edge.target)).inEdges.push(edge.id);
|
|
84
|
-
return edge;
|
|
85
|
-
});
|
|
86
|
-
const nodes = applyViewRuleStyles(
|
|
87
|
-
view.rules.filter(isViewRuleStyle),
|
|
88
|
-
sortNodes(keepOriginalSortFromView(nodesMap, ctx), edges)
|
|
89
|
-
// map(e => nodesMap.get(e.id)!, Array.from(elements))
|
|
90
|
-
);
|
|
91
|
-
const autoLayoutRule = view.rules.find(isViewRuleAutoLayout);
|
|
92
|
-
return {
|
|
93
|
-
...view,
|
|
94
|
-
autoLayout: autoLayoutRule?.autoLayout ?? "TB",
|
|
95
|
-
nodes,
|
|
96
|
-
edges
|
|
97
|
-
};
|
|
98
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Expr } from '../types';
|
|
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;
|
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
import { anyPass, both, either, isNil, uniq } from "rambdax";
|
|
2
|
-
import { Expr } from "../types/index.js";
|
|
3
|
-
import { Relations, commonAncestor, isAncestor, isSameHierarchy } 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) => {
|
|
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(isInside(expr.element), 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(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,14 +0,0 @@
|
|
|
1
|
-
import type { BaseError } from '../errors';
|
|
2
|
-
import type { ModelIndex } from '../model-index';
|
|
3
|
-
import { type ComputedView, type ElementView } from '../types';
|
|
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 declare function assignNavigateTo<R extends Iterable<ComputedView>>(views: R): R;
|
|
14
|
-
export {};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { find } from "rambdax";
|
|
2
|
-
import { normalizeError } from "../errors/index.js";
|
|
3
|
-
import { computeElementView } from "./compute-element-view.js";
|
|
4
|
-
export function computeView(view, index) {
|
|
5
|
-
try {
|
|
6
|
-
return {
|
|
7
|
-
isSuccess: true,
|
|
8
|
-
view: computeElementView(view, index)
|
|
9
|
-
};
|
|
10
|
-
} catch (e) {
|
|
11
|
-
return {
|
|
12
|
-
isSuccess: false,
|
|
13
|
-
error: normalizeError(e),
|
|
14
|
-
view: void 0
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export function assignNavigateTo(views) {
|
|
19
|
-
const allElementViews = /* @__PURE__ */ new Map();
|
|
20
|
-
for (const v of views) {
|
|
21
|
-
if (v.viewOf && !v.extends) {
|
|
22
|
-
const viewsOf = allElementViews.get(v.viewOf) ?? [];
|
|
23
|
-
viewsOf.push(v.id);
|
|
24
|
-
allElementViews.set(v.viewOf, viewsOf);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
for (const { id, nodes } of views) {
|
|
28
|
-
for (const node of nodes) {
|
|
29
|
-
const navigateTo = find((v) => v !== id, allElementViews.get(node.id) ?? []);
|
|
30
|
-
if (navigateTo) {
|
|
31
|
-
node.navigateTo = navigateTo;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return views;
|
|
36
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import graphlib from "@dagrejs/graphlib";
|
|
2
|
-
import { isExtendsElementView } from "../types/index.js";
|
|
3
|
-
const { Graph, alg } = graphlib;
|
|
4
|
-
export function resolveRulesExtendedViews(unresolvedViews) {
|
|
5
|
-
const g = new Graph({
|
|
6
|
-
directed: true,
|
|
7
|
-
multigraph: false,
|
|
8
|
-
compound: false
|
|
9
|
-
});
|
|
10
|
-
for (const view of Object.values(unresolvedViews)) {
|
|
11
|
-
g.setNode(view.id);
|
|
12
|
-
if (isExtendsElementView(view)) {
|
|
13
|
-
g.setEdge(view.id, view.extends);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const cycles = alg.findCycles(g);
|
|
17
|
-
if (cycles.length > 0) {
|
|
18
|
-
cycles.flat().forEach((id) => g.removeNode(id));
|
|
19
|
-
}
|
|
20
|
-
const ordered = alg.postorder(g, g.sources());
|
|
21
|
-
return ordered.reduce((acc, id) => {
|
|
22
|
-
const view = unresolvedViews[id];
|
|
23
|
-
if (!view) {
|
|
24
|
-
return acc;
|
|
25
|
-
}
|
|
26
|
-
if (isExtendsElementView(view)) {
|
|
27
|
-
const extendsFrom = acc[view.extends];
|
|
28
|
-
if (!extendsFrom) {
|
|
29
|
-
return acc;
|
|
30
|
-
}
|
|
31
|
-
return Object.assign(acc, {
|
|
32
|
-
[view.id]: {
|
|
33
|
-
...extendsFrom,
|
|
34
|
-
...view,
|
|
35
|
-
rules: [...extendsFrom.rules, ...view.rules]
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return Object.assign(acc, { [view.id]: view });
|
|
40
|
-
}, {});
|
|
41
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { uniq, zip } from "rambdax";
|
|
2
|
-
import { hasAtLeast } from "remeda";
|
|
3
|
-
import { invariant } from "../errors/index.js";
|
|
4
|
-
function commonAncestorPath(views, sep = "/") {
|
|
5
|
-
if (views.length <= 1)
|
|
6
|
-
return "";
|
|
7
|
-
const uniqURIs = uniq(views.flatMap(({ docUri }) => docUri ? [docUri] : []));
|
|
8
|
-
if (uniqURIs.length === 0)
|
|
9
|
-
return "";
|
|
10
|
-
if (uniqURIs.length === 1) {
|
|
11
|
-
invariant(hasAtLeast(uniqURIs, 1));
|
|
12
|
-
return new URL(uniqURIs[0]).pathname;
|
|
13
|
-
}
|
|
14
|
-
invariant(hasAtLeast(uniqURIs, 2), "Expected at least 2 unique URIs");
|
|
15
|
-
const [baseUri, ...tail] = uniqURIs;
|
|
16
|
-
const parts = new URL(baseUri).pathname.split(sep);
|
|
17
|
-
let endOfPrefix = parts.length;
|
|
18
|
-
for (const uri of tail) {
|
|
19
|
-
if (uri === baseUri) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
const compare = new URL(uri).pathname.split(sep);
|
|
23
|
-
for (let i = 0; i < endOfPrefix; i++) {
|
|
24
|
-
if (compare[i] !== parts[i]) {
|
|
25
|
-
endOfPrefix = i;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (endOfPrefix === 0)
|
|
29
|
-
return "";
|
|
30
|
-
}
|
|
31
|
-
const prefix = parts.slice(0, endOfPrefix).join(sep);
|
|
32
|
-
return prefix.endsWith(sep) ? prefix : prefix + sep;
|
|
33
|
-
}
|
|
34
|
-
export function resolveRelativePaths(views) {
|
|
35
|
-
const commonPrefix = commonAncestorPath(views);
|
|
36
|
-
return views.map((view) => {
|
|
37
|
-
if (!view.docUri) {
|
|
38
|
-
return {
|
|
39
|
-
...view,
|
|
40
|
-
parts: []
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
const path = new URL(view.docUri).pathname;
|
|
44
|
-
const parts = path.replace(commonPrefix, "").split("/");
|
|
45
|
-
parts.pop();
|
|
46
|
-
return {
|
|
47
|
-
...view,
|
|
48
|
-
parts
|
|
49
|
-
};
|
|
50
|
-
}).sort((a, b) => {
|
|
51
|
-
if (a.parts.length === b.parts.length) {
|
|
52
|
-
if (a.parts.length === 0) {
|
|
53
|
-
return 0;
|
|
54
|
-
}
|
|
55
|
-
if (a.parts.length === 1 && hasAtLeast(a.parts, 1) && hasAtLeast(b.parts, 1)) {
|
|
56
|
-
return a.parts[0].localeCompare(b.parts[0]);
|
|
57
|
-
}
|
|
58
|
-
for (const [_a, _b] of zip(a.parts, b.parts)) {
|
|
59
|
-
const compare = _a.localeCompare(_b);
|
|
60
|
-
if (compare !== 0) {
|
|
61
|
-
return compare;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return 0;
|
|
65
|
-
}
|
|
66
|
-
return a.parts.length - b.parts.length;
|
|
67
|
-
}).map(({ parts, ...view }) => {
|
|
68
|
-
if (view.docUri) {
|
|
69
|
-
return {
|
|
70
|
-
...view,
|
|
71
|
-
relativePath: parts.join("/")
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
return view;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { prop, uniqBy } from "rambdax";
|
|
2
|
-
import { compareByFqnHierarchically, isAncestor } from "../../utils/index.js";
|
|
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
|
-
}
|