@likec4/core 0.36.0 → 0.37.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/compute-view/compute-ctx.cjs +54 -0
- package/dist/compute-view/compute-ctx.d.ts +3 -1
- package/dist/compute-view/compute-ctx.js +69 -13
- package/dist/compute-view/compute-element-view.cjs +1 -45
- package/dist/compute-view/compute-element-view.d.ts +1 -1
- package/dist/compute-view/compute-element-view.js +3 -64
- package/dist/compute-view/compute.cjs +9 -23
- package/dist/compute-view/compute.d.ts +3 -14
- package/dist/compute-view/compute.js +8 -18
- package/dist/compute-view/index.cjs +11 -0
- package/dist/compute-view/index.d.ts +1 -0
- package/dist/compute-view/index.js +1 -0
- package/dist/compute-view/resolve-extended-views.cjs +50 -0
- package/dist/compute-view/resolve-extended-views.d.ts +6 -0
- package/dist/compute-view/resolve-extended-views.js +38 -0
- package/dist/errors/non-nullable.cjs +2 -2
- package/dist/errors/non-nullable.d.ts +1 -1
- package/dist/errors/non-nullable.js +2 -2
- package/dist/types/computed-view.d.ts +4 -2
- package/dist/types/model.d.ts +8 -3
- package/dist/types/view.cjs +8 -0
- package/dist/types/view.d.ts +10 -1
- package/dist/types/view.js +6 -0
- package/dist/utils/relations.cjs +1 -2
- package/dist/utils/relations.js +1 -2
- package/package.json +1 -1
|
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ComputeCtx = void 0;
|
|
7
7
|
var _rambdax = require("rambdax");
|
|
8
|
+
var _types = require("../types/index.cjs");
|
|
9
|
+
var _computePredicates = require("./compute-predicates.cjs");
|
|
10
|
+
var _errors = require("../errors/index.cjs");
|
|
8
11
|
class ComputeCtx {
|
|
9
12
|
constructor(index, root, elements = /* @__PURE__ */new Set(), relations = /* @__PURE__ */new Set(), implicits = /* @__PURE__ */new Set()) {
|
|
10
13
|
this.index = index;
|
|
@@ -31,5 +34,56 @@ class ComputeCtx {
|
|
|
31
34
|
}
|
|
32
35
|
return new ComputeCtx(this.index, this.root, elements ? new Set((0, _rambdax.difference)([...this.elements], elements)) : this.elements, relations ? new Set((0, _rambdax.difference)([...this.relations], relations)) : this.relations, newImplicits);
|
|
33
36
|
}
|
|
37
|
+
processViewRules(viewRules) {
|
|
38
|
+
let ctx = this;
|
|
39
|
+
for (const {
|
|
40
|
+
isInclude,
|
|
41
|
+
exprs
|
|
42
|
+
} of viewRules) {
|
|
43
|
+
for (const expr of exprs) {
|
|
44
|
+
if (_types.Expr.isElementKindExpr(expr) || _types.Expr.isElementTagExpr(expr)) {
|
|
45
|
+
ctx = isInclude ? (0, _computePredicates.includeElementKindOrTag)(ctx, expr) : (0, _computePredicates.excludeElementKindOrTag)(ctx, expr);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (_types.Expr.isElementRef(expr)) {
|
|
49
|
+
ctx = isInclude ? (0, _computePredicates.includeElementRef)(ctx, expr) : (0, _computePredicates.excludeElementRef)(ctx, expr);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (_types.Expr.isWildcard(expr)) {
|
|
53
|
+
ctx = isInclude ? (0, _computePredicates.includeWildcardRef)(ctx, expr) : (0, _computePredicates.excludeWildcardRef)(ctx, expr);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (_types.Expr.isIncoming(expr)) {
|
|
57
|
+
ctx = isInclude ? (0, _computePredicates.includeIncomingExpr)(ctx, expr) : (0, _computePredicates.excludeIncomingExpr)(ctx, expr);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (_types.Expr.isOutgoing(expr)) {
|
|
61
|
+
ctx = isInclude ? (0, _computePredicates.includeOutgoingExpr)(ctx, expr) : (0, _computePredicates.excludeOutgoingExpr)(ctx, expr);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (_types.Expr.isInOut(expr)) {
|
|
65
|
+
ctx = isInclude ? (0, _computePredicates.includeInOutExpr)(ctx, expr) : (0, _computePredicates.excludeInOutExpr)(ctx, expr);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (_types.Expr.isRelation(expr)) {
|
|
69
|
+
ctx = isInclude ? (0, _computePredicates.includeRelationExpr)(ctx, expr) : (0, _computePredicates.excludeRelationExpr)(ctx, expr);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
(0, _errors.nonexhaustive)(expr);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return ctx;
|
|
76
|
+
}
|
|
77
|
+
static create(view, index) {
|
|
78
|
+
const rootElement = (0, _types.isStrictElementView)(view) ? view.viewOf : null;
|
|
79
|
+
let ctx = new ComputeCtx(index, rootElement);
|
|
80
|
+
const rulesInclude = view.rules.filter(_types.isViewRuleExpression);
|
|
81
|
+
if (rootElement && rulesInclude.length == 0) {
|
|
82
|
+
ctx = ctx.include({
|
|
83
|
+
elements: [index.find(rootElement)]
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return ctx.processViewRules(rulesInclude);
|
|
87
|
+
}
|
|
34
88
|
}
|
|
35
89
|
exports.ComputeCtx = ComputeCtx;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModelIndex } from '../model-index';
|
|
2
|
-
import type { Fqn, Element, Relation } from '../types';
|
|
2
|
+
import type { Fqn, Element, Relation, ViewRuleExpression, ElementView } from '../types';
|
|
3
3
|
export type ComputeCtxPatch = {
|
|
4
4
|
elements?: Element[];
|
|
5
5
|
relations?: Relation[];
|
|
@@ -14,4 +14,6 @@ export declare class ComputeCtx {
|
|
|
14
14
|
constructor(index: ModelIndex, root: Fqn | null, elements?: Set<Element>, relations?: Set<Relation>, implicits?: Set<Element>);
|
|
15
15
|
include({ elements, relations, implicits }: ComputeCtxPatch): ComputeCtx;
|
|
16
16
|
exclude({ elements, relations, implicits }: ComputeCtxPatch): ComputeCtx;
|
|
17
|
+
processViewRules(viewRules: ViewRuleExpression[]): ComputeCtx;
|
|
18
|
+
static create(view: ElementView, index: ModelIndex): ComputeCtx;
|
|
17
19
|
}
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { difference } from "rambdax";
|
|
2
|
+
import { Expr, isStrictElementView, isViewRuleExpression } from "../types/index.js";
|
|
3
|
+
import {
|
|
4
|
+
excludeElementKindOrTag,
|
|
5
|
+
excludeElementRef,
|
|
6
|
+
excludeInOutExpr,
|
|
7
|
+
excludeIncomingExpr,
|
|
8
|
+
excludeOutgoingExpr,
|
|
9
|
+
excludeRelationExpr,
|
|
10
|
+
excludeWildcardRef,
|
|
11
|
+
includeElementKindOrTag,
|
|
12
|
+
includeElementRef,
|
|
13
|
+
includeInOutExpr,
|
|
14
|
+
includeIncomingExpr,
|
|
15
|
+
includeOutgoingExpr,
|
|
16
|
+
includeRelationExpr,
|
|
17
|
+
includeWildcardRef
|
|
18
|
+
} from "./compute-predicates.js";
|
|
19
|
+
import { nonexhaustive } from "../errors/index.js";
|
|
2
20
|
export class ComputeCtx {
|
|
3
21
|
constructor(index, root, elements = /* @__PURE__ */ new Set(), relations = /* @__PURE__ */ new Set(), implicits = /* @__PURE__ */ new Set()) {
|
|
4
22
|
this.index = index;
|
|
@@ -7,11 +25,7 @@ export class ComputeCtx {
|
|
|
7
25
|
this.relations = relations;
|
|
8
26
|
this.implicits = implicits;
|
|
9
27
|
}
|
|
10
|
-
include({
|
|
11
|
-
elements,
|
|
12
|
-
relations,
|
|
13
|
-
implicits
|
|
14
|
-
}) {
|
|
28
|
+
include({ elements, relations, implicits }) {
|
|
15
29
|
return new ComputeCtx(
|
|
16
30
|
this.index,
|
|
17
31
|
this.root,
|
|
@@ -20,16 +34,10 @@ export class ComputeCtx {
|
|
|
20
34
|
implicits ? /* @__PURE__ */ new Set([...this.implicits, ...implicits]) : this.implicits
|
|
21
35
|
);
|
|
22
36
|
}
|
|
23
|
-
exclude({
|
|
24
|
-
elements,
|
|
25
|
-
relations,
|
|
26
|
-
implicits
|
|
27
|
-
}) {
|
|
37
|
+
exclude({ elements, relations, implicits }) {
|
|
28
38
|
let newImplicits = implicits ? new Set(difference([...this.implicits], implicits)) : this.implicits;
|
|
29
39
|
if (elements) {
|
|
30
|
-
newImplicits = new Set(
|
|
31
|
-
difference([...newImplicits], elements)
|
|
32
|
-
);
|
|
40
|
+
newImplicits = new Set(difference([...newImplicits], elements));
|
|
33
41
|
}
|
|
34
42
|
return new ComputeCtx(
|
|
35
43
|
this.index,
|
|
@@ -39,4 +47,52 @@ export class ComputeCtx {
|
|
|
39
47
|
newImplicits
|
|
40
48
|
);
|
|
41
49
|
}
|
|
50
|
+
processViewRules(viewRules) {
|
|
51
|
+
let ctx = this;
|
|
52
|
+
for (const { isInclude, exprs } of viewRules) {
|
|
53
|
+
for (const expr of exprs) {
|
|
54
|
+
if (Expr.isElementKindExpr(expr) || Expr.isElementTagExpr(expr)) {
|
|
55
|
+
ctx = isInclude ? includeElementKindOrTag(ctx, expr) : excludeElementKindOrTag(ctx, expr);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (Expr.isElementRef(expr)) {
|
|
59
|
+
ctx = isInclude ? includeElementRef(ctx, expr) : excludeElementRef(ctx, expr);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (Expr.isWildcard(expr)) {
|
|
63
|
+
ctx = isInclude ? includeWildcardRef(ctx, expr) : excludeWildcardRef(ctx, expr);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (Expr.isIncoming(expr)) {
|
|
67
|
+
ctx = isInclude ? includeIncomingExpr(ctx, expr) : excludeIncomingExpr(ctx, expr);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (Expr.isOutgoing(expr)) {
|
|
71
|
+
ctx = isInclude ? includeOutgoingExpr(ctx, expr) : excludeOutgoingExpr(ctx, expr);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (Expr.isInOut(expr)) {
|
|
75
|
+
ctx = isInclude ? includeInOutExpr(ctx, expr) : excludeInOutExpr(ctx, expr);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (Expr.isRelation(expr)) {
|
|
79
|
+
ctx = isInclude ? includeRelationExpr(ctx, expr) : excludeRelationExpr(ctx, expr);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
nonexhaustive(expr);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return ctx;
|
|
86
|
+
}
|
|
87
|
+
static create(view, index) {
|
|
88
|
+
const rootElement = isStrictElementView(view) ? view.viewOf : null;
|
|
89
|
+
let ctx = new ComputeCtx(index, rootElement);
|
|
90
|
+
const rulesInclude = view.rules.filter(isViewRuleExpression);
|
|
91
|
+
if (rootElement && rulesInclude.length == 0) {
|
|
92
|
+
ctx = ctx.include({
|
|
93
|
+
elements: [index.find(rootElement)]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return ctx.processViewRules(rulesInclude);
|
|
97
|
+
}
|
|
42
98
|
}
|
|
@@ -10,7 +10,6 @@ var _types = require("../types/index.cjs");
|
|
|
10
10
|
var _utils = require("../utils/index.cjs");
|
|
11
11
|
var _EdgeBuilder = require("./EdgeBuilder.cjs");
|
|
12
12
|
var _computeCtx = require("./compute-ctx.cjs");
|
|
13
|
-
var _computePredicates = require("./compute-predicates.cjs");
|
|
14
13
|
var _applyViewRuleStyles = require("./utils/applyViewRuleStyles.cjs");
|
|
15
14
|
var _sortNodes = require("./utils/sortNodes.cjs");
|
|
16
15
|
function reduceToMap(elementsIterator) {
|
|
@@ -46,50 +45,7 @@ function reduceToMap(elementsIterator) {
|
|
|
46
45
|
}, /* @__PURE__ */new Map());
|
|
47
46
|
}
|
|
48
47
|
function computeElementView(view, index) {
|
|
49
|
-
const
|
|
50
|
-
let ctx = new _computeCtx.ComputeCtx(index, rootElement);
|
|
51
|
-
const rulesInclude = view.rules.filter(_types.isViewRuleExpression);
|
|
52
|
-
if (rootElement && rulesInclude.length == 0) {
|
|
53
|
-
ctx = ctx.include({
|
|
54
|
-
elements: [index.find(rootElement)]
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
for (const {
|
|
58
|
-
isInclude,
|
|
59
|
-
exprs
|
|
60
|
-
} of rulesInclude) {
|
|
61
|
-
for (const expr of exprs) {
|
|
62
|
-
if (_types.Expr.isElementKindExpr(expr) || _types.Expr.isElementTagExpr(expr)) {
|
|
63
|
-
ctx = isInclude ? (0, _computePredicates.includeElementKindOrTag)(ctx, expr) : (0, _computePredicates.excludeElementKindOrTag)(ctx, expr);
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (_types.Expr.isElementRef(expr)) {
|
|
67
|
-
ctx = isInclude ? (0, _computePredicates.includeElementRef)(ctx, expr) : (0, _computePredicates.excludeElementRef)(ctx, expr);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (_types.Expr.isWildcard(expr)) {
|
|
71
|
-
ctx = isInclude ? (0, _computePredicates.includeWildcardRef)(ctx, expr) : (0, _computePredicates.excludeWildcardRef)(ctx, expr);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (_types.Expr.isIncoming(expr)) {
|
|
75
|
-
ctx = isInclude ? (0, _computePredicates.includeIncomingExpr)(ctx, expr) : (0, _computePredicates.excludeIncomingExpr)(ctx, expr);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (_types.Expr.isOutgoing(expr)) {
|
|
79
|
-
ctx = isInclude ? (0, _computePredicates.includeOutgoingExpr)(ctx, expr) : (0, _computePredicates.excludeOutgoingExpr)(ctx, expr);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (_types.Expr.isInOut(expr)) {
|
|
83
|
-
ctx = isInclude ? (0, _computePredicates.includeInOutExpr)(ctx, expr) : (0, _computePredicates.excludeInOutExpr)(ctx, expr);
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (_types.Expr.isRelation(expr)) {
|
|
87
|
-
ctx = isInclude ? (0, _computePredicates.includeRelationExpr)(ctx, expr) : (0, _computePredicates.excludeRelationExpr)(ctx, expr);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
(0, _errors.nonexhaustive)(expr);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
48
|
+
const ctx = _computeCtx.ComputeCtx.create(view, index);
|
|
93
49
|
const allElements = [...ctx.elements, ...ctx.implicits].sort(_utils.compareByFqnHierarchically).reverse();
|
|
94
50
|
const elementsWithRelations = /* @__PURE__ */new Set();
|
|
95
51
|
const edgeBuilder = new _EdgeBuilder.EdgeBuilder();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ModelIndex } from '../model-index';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ComputedView, type ElementView } from '../types';
|
|
3
3
|
export declare function computeElementView(view: ElementView, index: ModelIndex): ComputedView;
|
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
import { allPass, find } from "remeda";
|
|
2
|
-
import { nonNullable
|
|
2
|
+
import { nonNullable } from "../errors/index.js";
|
|
3
3
|
import {
|
|
4
4
|
DefaultElementShape,
|
|
5
5
|
DefaultThemeColor,
|
|
6
|
-
Expr,
|
|
7
6
|
isViewRuleAutoLayout,
|
|
8
|
-
isViewRuleExpression,
|
|
9
7
|
isViewRuleStyle
|
|
10
8
|
} from "../types/index.js";
|
|
11
9
|
import { compareByFqnHierarchically, isAncestor, isSameHierarchy, parentFqn } from "../utils/index.js";
|
|
12
10
|
import { EdgeBuilder } from "./EdgeBuilder.js";
|
|
13
11
|
import { ComputeCtx } from "./compute-ctx.js";
|
|
14
|
-
import {
|
|
15
|
-
excludeElementKindOrTag,
|
|
16
|
-
excludeElementRef,
|
|
17
|
-
excludeInOutExpr,
|
|
18
|
-
excludeIncomingExpr,
|
|
19
|
-
excludeOutgoingExpr,
|
|
20
|
-
excludeRelationExpr,
|
|
21
|
-
excludeWildcardRef,
|
|
22
|
-
includeElementKindOrTag,
|
|
23
|
-
includeElementRef,
|
|
24
|
-
includeInOutExpr,
|
|
25
|
-
includeIncomingExpr,
|
|
26
|
-
includeOutgoingExpr,
|
|
27
|
-
includeRelationExpr,
|
|
28
|
-
includeWildcardRef
|
|
29
|
-
} from "./compute-predicates.js";
|
|
30
12
|
import { applyViewRuleStyles } from "./utils/applyViewRuleStyles.js";
|
|
31
13
|
import { sortNodes } from "./utils/sortNodes.js";
|
|
32
14
|
function reduceToMap(elementsIterator) {
|
|
@@ -57,47 +39,7 @@ function reduceToMap(elementsIterator) {
|
|
|
57
39
|
}, /* @__PURE__ */ new Map());
|
|
58
40
|
}
|
|
59
41
|
export function computeElementView(view, index) {
|
|
60
|
-
const
|
|
61
|
-
let ctx = new ComputeCtx(index, rootElement);
|
|
62
|
-
const rulesInclude = view.rules.filter(isViewRuleExpression);
|
|
63
|
-
if (rootElement && rulesInclude.length == 0) {
|
|
64
|
-
ctx = ctx.include({
|
|
65
|
-
elements: [index.find(rootElement)]
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
for (const { isInclude, exprs } of rulesInclude) {
|
|
69
|
-
for (const expr of exprs) {
|
|
70
|
-
if (Expr.isElementKindExpr(expr) || Expr.isElementTagExpr(expr)) {
|
|
71
|
-
ctx = isInclude ? includeElementKindOrTag(ctx, expr) : excludeElementKindOrTag(ctx, expr);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (Expr.isElementRef(expr)) {
|
|
75
|
-
ctx = isInclude ? includeElementRef(ctx, expr) : excludeElementRef(ctx, expr);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (Expr.isWildcard(expr)) {
|
|
79
|
-
ctx = isInclude ? includeWildcardRef(ctx, expr) : excludeWildcardRef(ctx, expr);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (Expr.isIncoming(expr)) {
|
|
83
|
-
ctx = isInclude ? includeIncomingExpr(ctx, expr) : excludeIncomingExpr(ctx, expr);
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (Expr.isOutgoing(expr)) {
|
|
87
|
-
ctx = isInclude ? includeOutgoingExpr(ctx, expr) : excludeOutgoingExpr(ctx, expr);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (Expr.isInOut(expr)) {
|
|
91
|
-
ctx = isInclude ? includeInOutExpr(ctx, expr) : excludeInOutExpr(ctx, expr);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (Expr.isRelation(expr)) {
|
|
95
|
-
ctx = isInclude ? includeRelationExpr(ctx, expr) : excludeRelationExpr(ctx, expr);
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
nonexhaustive(expr);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
42
|
+
const ctx = ComputeCtx.create(view, index);
|
|
101
43
|
const allElements = [...ctx.elements, ...ctx.implicits].sort(compareByFqnHierarchically).reverse();
|
|
102
44
|
const elementsWithRelations = /* @__PURE__ */ new Set();
|
|
103
45
|
const edgeBuilder = new EdgeBuilder();
|
|
@@ -108,10 +50,7 @@ export function computeElementView(view, index) {
|
|
|
108
50
|
if (!source) {
|
|
109
51
|
continue;
|
|
110
52
|
}
|
|
111
|
-
const target = find(
|
|
112
|
-
allElements,
|
|
113
|
-
allPass([anscestorOf(rel.target), (e) => !isSameHierarchy(e, source)])
|
|
114
|
-
);
|
|
53
|
+
const target = find(allElements, allPass([anscestorOf(rel.target), (e) => !isSameHierarchy(e, source)]));
|
|
115
54
|
if (!target) {
|
|
116
55
|
continue;
|
|
117
56
|
}
|
|
@@ -5,11 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.assignNavigateTo = assignNavigateTo;
|
|
7
7
|
exports.computeView = computeView;
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var _modelIndex = require("../model-index/index.cjs");
|
|
8
|
+
var _rambdax = require("rambdax");
|
|
9
|
+
var _errors = require("../errors/index.cjs");
|
|
11
10
|
var _computeElementView = require("./compute-element-view.cjs");
|
|
12
|
-
var _ = require("../index.cjs");
|
|
13
11
|
function computeView(view, index) {
|
|
14
12
|
try {
|
|
15
13
|
return {
|
|
@@ -19,30 +17,18 @@ function computeView(view, index) {
|
|
|
19
17
|
} catch (e) {
|
|
20
18
|
return {
|
|
21
19
|
isSuccess: false,
|
|
22
|
-
error: (0,
|
|
20
|
+
error: (0, _errors.normalizeError)(e),
|
|
23
21
|
view: void 0
|
|
24
22
|
};
|
|
25
23
|
}
|
|
26
24
|
}
|
|
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
25
|
function assignNavigateTo(views) {
|
|
37
26
|
const allElementViews = /* @__PURE__ */new Map();
|
|
38
|
-
for (const {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const viewsOf = allElementViews.get(viewOf) ?? [];
|
|
44
|
-
viewsOf.push(id);
|
|
45
|
-
allElementViews.set(viewOf, viewsOf);
|
|
27
|
+
for (const v of views) {
|
|
28
|
+
if (v.viewOf && !v.extends) {
|
|
29
|
+
const viewsOf = allElementViews.get(v.viewOf) ?? [];
|
|
30
|
+
viewsOf.push(v.id);
|
|
31
|
+
allElementViews.set(v.viewOf, viewsOf);
|
|
46
32
|
}
|
|
47
33
|
}
|
|
48
34
|
for (const {
|
|
@@ -50,7 +36,7 @@ function assignNavigateTo(views) {
|
|
|
50
36
|
nodes
|
|
51
37
|
} of views) {
|
|
52
38
|
for (const node of nodes) {
|
|
53
|
-
const navigateTo = (0,
|
|
39
|
+
const navigateTo = (0, _rambdax.find)(v => v !== id, allElementViews.get(node.id) ?? []);
|
|
54
40
|
if (navigateTo) {
|
|
55
41
|
node.navigateTo = navigateTo;
|
|
56
42
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import { type
|
|
1
|
+
import type { BaseError } from '../errors';
|
|
2
|
+
import type { ModelIndex } from '../model-index';
|
|
3
|
+
import { type ComputedView, type ElementView } from '../types';
|
|
4
4
|
type ComputeViewResult = {
|
|
5
5
|
isSuccess: true;
|
|
6
6
|
view: ComputedView;
|
|
@@ -10,16 +10,5 @@ type ComputeViewResult = {
|
|
|
10
10
|
view: undefined;
|
|
11
11
|
};
|
|
12
12
|
export declare function computeView(view: ElementView, index: ModelIndex): ComputeViewResult;
|
|
13
|
-
export type CmpInputModel = {
|
|
14
|
-
elements: Record<Fqn, Element>;
|
|
15
|
-
relations: Record<RelationID, Relation>;
|
|
16
|
-
views: ElementView[];
|
|
17
|
-
};
|
|
18
|
-
export type CmpOutputModel = {
|
|
19
|
-
elements: Record<Fqn, Element>;
|
|
20
|
-
relations: Record<RelationID, Relation>;
|
|
21
|
-
views: Record<ViewID, ComputedView>;
|
|
22
|
-
};
|
|
23
|
-
export declare function computeViews(model: CmpInputModel): CmpOutputModel;
|
|
24
13
|
export declare function assignNavigateTo<R extends Iterable<ComputedView>>(views: R): R;
|
|
25
14
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { find } from "rambdax";
|
|
2
|
+
import { normalizeError } from "../errors/index.js";
|
|
3
3
|
import { computeElementView } from "./compute-element-view.js";
|
|
4
|
-
import { normalizeError } from "../index.js";
|
|
5
4
|
export function computeView(view, index) {
|
|
6
5
|
try {
|
|
7
6
|
return {
|
|
@@ -16,27 +15,18 @@ export function computeView(view, index) {
|
|
|
16
15
|
};
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
export function computeViews(model) {
|
|
20
|
-
const index = ModelIndex.from(model);
|
|
21
|
-
const computedViews = compact(map(model.views, (view) => computeView(view, index).view));
|
|
22
|
-
return {
|
|
23
|
-
elements: model.elements,
|
|
24
|
-
relations: model.relations,
|
|
25
|
-
views: mapToObj(computedViews, (view) => [view.id, view])
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
18
|
export function assignNavigateTo(views) {
|
|
29
19
|
const allElementViews = /* @__PURE__ */ new Map();
|
|
30
|
-
for (const
|
|
31
|
-
if (viewOf) {
|
|
32
|
-
const viewsOf = allElementViews.get(viewOf) ?? [];
|
|
33
|
-
viewsOf.push(id);
|
|
34
|
-
allElementViews.set(viewOf, viewsOf);
|
|
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);
|
|
35
25
|
}
|
|
36
26
|
}
|
|
37
27
|
for (const { id, nodes } of views) {
|
|
38
28
|
for (const node of nodes) {
|
|
39
|
-
const navigateTo = find(allElementViews.get(node.id) ?? []
|
|
29
|
+
const navigateTo = find((v) => v !== id, allElementViews.get(node.id) ?? []);
|
|
40
30
|
if (navigateTo) {
|
|
41
31
|
node.navigateTo = navigateTo;
|
|
42
32
|
}
|
|
@@ -14,6 +14,17 @@ Object.keys(_compute).forEach(function (key) {
|
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
+
var _resolveExtendedViews = require("./resolve-extended-views.cjs");
|
|
18
|
+
Object.keys(_resolveExtendedViews).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _resolveExtendedViews[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _resolveExtendedViews[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
17
28
|
var _EdgeBuilder = require("./EdgeBuilder.cjs");
|
|
18
29
|
Object.keys(_EdgeBuilder).forEach(function (key) {
|
|
19
30
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveRulesExtendedViews = resolveRulesExtendedViews;
|
|
7
|
+
var _graphlib = _interopRequireDefault(require("@dagrejs/graphlib"));
|
|
8
|
+
var _errors = require("../errors/index.cjs");
|
|
9
|
+
var _types = require("../types/index.cjs");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const {
|
|
12
|
+
Graph,
|
|
13
|
+
alg
|
|
14
|
+
} = _graphlib.default;
|
|
15
|
+
function resolveRulesExtendedViews(unresolvedViews) {
|
|
16
|
+
const g = new Graph({
|
|
17
|
+
directed: true,
|
|
18
|
+
multigraph: false,
|
|
19
|
+
compound: false
|
|
20
|
+
});
|
|
21
|
+
for (const view of Object.values(unresolvedViews)) {
|
|
22
|
+
if (!(0, _types.isExtendsElementView)(view)) {
|
|
23
|
+
g.setNode(view.id);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (unresolvedViews[view.extends]) {
|
|
27
|
+
g.setEdge(view.extends, view.id);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!alg.isAcyclic(g)) {
|
|
31
|
+
alg.findCycles(g).flat().map(id => g.removeNode(id));
|
|
32
|
+
}
|
|
33
|
+
return alg.topsort(g).reduce((acc, id) => {
|
|
34
|
+
const view = (0, _errors.nonNullable)(unresolvedViews[id], `Cannot find view ${id}`);
|
|
35
|
+
if ((0, _types.isExtendsElementView)(view)) {
|
|
36
|
+
const extendsFrom = acc[view.extends];
|
|
37
|
+
(0, _errors.invariant)(extendsFrom, `Cannot find base view '${view.extends}' for '${view.id}'`);
|
|
38
|
+
return Object.assign(acc, {
|
|
39
|
+
[view.id]: {
|
|
40
|
+
...extendsFrom,
|
|
41
|
+
...view,
|
|
42
|
+
rules: [...extendsFrom.rules, ...view.rules]
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return Object.assign(acc, {
|
|
47
|
+
[view.id]: view
|
|
48
|
+
});
|
|
49
|
+
}, {});
|
|
50
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import pkg from "@dagrejs/graphlib";
|
|
2
|
+
import { invariant, nonNullable } from "../errors/index.js";
|
|
3
|
+
import { isExtendsElementView } from "../types/index.js";
|
|
4
|
+
const { Graph, alg } = pkg;
|
|
5
|
+
export function resolveRulesExtendedViews(unresolvedViews) {
|
|
6
|
+
const g = new Graph({
|
|
7
|
+
directed: true,
|
|
8
|
+
multigraph: false,
|
|
9
|
+
compound: false
|
|
10
|
+
});
|
|
11
|
+
for (const view of Object.values(unresolvedViews)) {
|
|
12
|
+
if (!isExtendsElementView(view)) {
|
|
13
|
+
g.setNode(view.id);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (unresolvedViews[view.extends]) {
|
|
17
|
+
g.setEdge(view.extends, view.id);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!alg.isAcyclic(g)) {
|
|
21
|
+
alg.findCycles(g).flat().map((id) => g.removeNode(id));
|
|
22
|
+
}
|
|
23
|
+
return alg.topsort(g).reduce((acc, id) => {
|
|
24
|
+
const view = nonNullable(unresolvedViews[id], `Cannot find view ${id}`);
|
|
25
|
+
if (isExtendsElementView(view)) {
|
|
26
|
+
const extendsFrom = acc[view.extends];
|
|
27
|
+
invariant(extendsFrom, `Cannot find base view '${view.extends}' for '${view.id}'`);
|
|
28
|
+
return Object.assign(acc, {
|
|
29
|
+
[view.id]: {
|
|
30
|
+
...extendsFrom,
|
|
31
|
+
...view,
|
|
32
|
+
rules: [...extendsFrom.rules, ...view.rules]
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return Object.assign(acc, { [view.id]: view });
|
|
37
|
+
}, {});
|
|
38
|
+
}
|
|
@@ -15,9 +15,9 @@ class NullableError extends _base.BaseError {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.NullableError = NullableError;
|
|
18
|
-
function nonNullable(value) {
|
|
18
|
+
function nonNullable(value, message) {
|
|
19
19
|
if (typeof value === "undefined" || value == null) {
|
|
20
|
-
throw new NullableError(`Expected defined value, but received ${value}`);
|
|
20
|
+
throw new NullableError(message ?? `Expected defined value, but received ${value}`);
|
|
21
21
|
}
|
|
22
22
|
return value;
|
|
23
23
|
}
|
|
@@ -3,4 +3,4 @@ import { BaseError } from './_base';
|
|
|
3
3
|
export declare class NullableError extends BaseError {
|
|
4
4
|
constructor(message: string, options?: BaseErrorOptions);
|
|
5
5
|
}
|
|
6
|
-
export declare function nonNullable<T>(value: T):
|
|
6
|
+
export declare function nonNullable<T>(value: T, message?: string): T & {};
|
|
@@ -5,9 +5,9 @@ export class NullableError extends BaseError {
|
|
|
5
5
|
Object.defineProperty(this, "name", { value: "UnexpectedNullableError" });
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
export function nonNullable(value) {
|
|
8
|
+
export function nonNullable(value, message) {
|
|
9
9
|
if (typeof value === "undefined" || value == null) {
|
|
10
|
-
throw new NullableError(`Expected defined value, but received ${value}`);
|
|
10
|
+
throw new NullableError(message ?? `Expected defined value, but received ${value}`);
|
|
11
11
|
}
|
|
12
12
|
return value;
|
|
13
13
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Opaque } from './opaque';
|
|
2
2
|
import type { ElementKind, ElementShape, Fqn, Tag } from './element';
|
|
3
3
|
import type { RelationID } from './relation';
|
|
4
|
-
import type {
|
|
4
|
+
import type { BasicElementView, ViewID, ViewRuleAutoLayout } from './view';
|
|
5
5
|
import type { IconUrl, NonEmptyArray } from './_common';
|
|
6
6
|
import type { ThemeColor } from './theme';
|
|
7
7
|
export type NodeId = Fqn;
|
|
@@ -31,7 +31,9 @@ export interface ComputedEdge {
|
|
|
31
31
|
label: string | null;
|
|
32
32
|
relations: RelationID[];
|
|
33
33
|
}
|
|
34
|
-
export interface ComputedView extends
|
|
34
|
+
export interface ComputedView extends BasicElementView {
|
|
35
|
+
viewOf?: Fqn;
|
|
36
|
+
extends?: ViewID;
|
|
35
37
|
autoLayout: ViewRuleAutoLayout['autoLayout'];
|
|
36
38
|
nodes: ComputedNode[];
|
|
37
39
|
edges: ComputedEdge[];
|
package/dist/types/model.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type { Fqn, Element } from './element';
|
|
2
|
-
import type { RelationID, Relation } from './relation';
|
|
3
|
-
import type { ViewID } from './view';
|
|
4
1
|
import type { ComputedView } from './computed-view';
|
|
2
|
+
import type { Element, Fqn } from './element';
|
|
3
|
+
import type { Relation, RelationID } from './relation';
|
|
4
|
+
import type { ElementView, ViewID } from './view';
|
|
5
|
+
export interface LikeC4RawModel {
|
|
6
|
+
elements: Record<Fqn, Element>;
|
|
7
|
+
relations: Record<RelationID, Relation>;
|
|
8
|
+
views: Record<ViewID, ElementView>;
|
|
9
|
+
}
|
|
5
10
|
export interface LikeC4Model {
|
|
6
11
|
elements: Record<Fqn, Element>;
|
|
7
12
|
relations: Record<RelationID, Relation>;
|
package/dist/types/view.cjs
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.isExtendsElementView = isExtendsElementView;
|
|
7
|
+
exports.isStrictElementView = isStrictElementView;
|
|
6
8
|
exports.isViewRuleAutoLayout = isViewRuleAutoLayout;
|
|
7
9
|
exports.isViewRuleExpression = isViewRuleExpression;
|
|
8
10
|
exports.isViewRuleStyle = isViewRuleStyle;
|
|
@@ -14,4 +16,10 @@ function isViewRuleStyle(rule) {
|
|
|
14
16
|
}
|
|
15
17
|
function isViewRuleAutoLayout(rule) {
|
|
16
18
|
return "autoLayout" in rule;
|
|
19
|
+
}
|
|
20
|
+
function isStrictElementView(view) {
|
|
21
|
+
return "viewOf" in view;
|
|
22
|
+
}
|
|
23
|
+
function isExtendsElementView(view) {
|
|
24
|
+
return "extends" in view;
|
|
17
25
|
}
|
package/dist/types/view.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface ViewRuleAutoLayout {
|
|
|
23
23
|
}
|
|
24
24
|
export declare function isViewRuleAutoLayout(rule: ViewRule): rule is ViewRuleAutoLayout;
|
|
25
25
|
export type ViewRule = ViewRuleExpression | ViewRuleStyle | ViewRuleAutoLayout;
|
|
26
|
-
export interface
|
|
26
|
+
export interface BasicElementView {
|
|
27
27
|
readonly id: ViewID;
|
|
28
28
|
readonly viewOf?: Fqn;
|
|
29
29
|
readonly title: string | null;
|
|
@@ -32,3 +32,12 @@ export interface ElementView {
|
|
|
32
32
|
readonly links: NonEmptyArray<string> | null;
|
|
33
33
|
readonly rules: ViewRule[];
|
|
34
34
|
}
|
|
35
|
+
export interface StrictElementView extends BasicElementView {
|
|
36
|
+
readonly viewOf: Fqn;
|
|
37
|
+
}
|
|
38
|
+
export declare function isStrictElementView(view: ElementView): view is StrictElementView;
|
|
39
|
+
export interface ExtendsElementView extends BasicElementView {
|
|
40
|
+
readonly extends: ViewID;
|
|
41
|
+
}
|
|
42
|
+
export declare function isExtendsElementView(view: ElementView): view is ExtendsElementView;
|
|
43
|
+
export type ElementView = StrictElementView | ExtendsElementView | BasicElementView;
|
package/dist/types/view.js
CHANGED
|
@@ -7,3 +7,9 @@ export function isViewRuleStyle(rule) {
|
|
|
7
7
|
export function isViewRuleAutoLayout(rule) {
|
|
8
8
|
return "autoLayout" in rule;
|
|
9
9
|
}
|
|
10
|
+
export function isStrictElementView(view) {
|
|
11
|
+
return "viewOf" in view;
|
|
12
|
+
}
|
|
13
|
+
export function isExtendsElementView(view) {
|
|
14
|
+
return "extends" in view;
|
|
15
|
+
}
|
package/dist/utils/relations.cjs
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.compareRelations = exports.Relations = void 0;
|
|
7
|
-
var _remeda = require("remeda");
|
|
8
7
|
var _fqn = require("./fqn.cjs");
|
|
9
8
|
var _rambdax = require("rambdax");
|
|
10
9
|
const compareRelations = (a, b) => {
|
|
@@ -25,7 +24,7 @@ const isBetween = (source, target) => {
|
|
|
25
24
|
};
|
|
26
25
|
};
|
|
27
26
|
const isAnyBetween = (source, target) => {
|
|
28
|
-
return (0,
|
|
27
|
+
return (0, _rambdax.either)(isBetween(source, target), isBetween(target, source));
|
|
29
28
|
};
|
|
30
29
|
const isIncoming = target => {
|
|
31
30
|
const targetPrefix = target + ".";
|
package/dist/utils/relations.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { anyPass } from "remeda";
|
|
2
1
|
import { compareFqnHierarchically, isAncestor } from "./fqn.js";
|
|
3
2
|
import { either } from "rambdax";
|
|
4
3
|
export const compareRelations = (a, b) => {
|
|
@@ -18,7 +17,7 @@ const isBetween = (source, target) => {
|
|
|
18
17
|
};
|
|
19
18
|
};
|
|
20
19
|
const isAnyBetween = (source, target) => {
|
|
21
|
-
return
|
|
20
|
+
return either(isBetween(source, target), isBetween(target, source));
|
|
22
21
|
};
|
|
23
22
|
const isIncoming = (target) => {
|
|
24
23
|
const targetPrefix = target + ".";
|