@likec4/core 0.33.1 → 0.35.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 +63 -25
- 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,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.anyPossibleRelations = anyPossibleRelations;
|
|
7
|
-
var _rambdax = require("rambdax");
|
|
8
|
-
var _fqn = require("../../utils/fqn");
|
|
9
|
-
function* anyPossibleRelations(elements) {
|
|
10
|
-
const uniqElements = (0, _rambdax.uniqBy)((0, _rambdax.prop)("id"), elements).sort(_fqn.compareByFqnHierarchically).reverse();
|
|
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();
|
|
11
5
|
for (const source of uniqElements) {
|
|
12
6
|
for (const target of uniqElements) {
|
|
13
|
-
if (source !== target && !
|
|
7
|
+
if (source !== target && !isAncestor(source, target) && !isAncestor(target, source)) {
|
|
14
8
|
yield [source, target];
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.applyViewRuleStyles = applyViewRuleStyles;
|
|
7
|
+
var _rambdax = require("rambdax");
|
|
8
|
+
var _remeda = require("remeda");
|
|
9
|
+
var _errors = require("../../errors/index.cjs");
|
|
10
|
+
var _types = require("../../types/index.cjs");
|
|
11
|
+
function applyViewRuleStyles(rules, _nodes) {
|
|
12
|
+
if (rules.length === 0) {
|
|
13
|
+
return _nodes;
|
|
14
|
+
}
|
|
15
|
+
const nodes = (0, _rambdax.clone)(_nodes);
|
|
16
|
+
for (const rule of rules) {
|
|
17
|
+
const predicates = [];
|
|
18
|
+
if (!rule.style.color && !rule.style.shape) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
for (const target of rule.targets) {
|
|
22
|
+
if (_types.Expr.isWildcard(target)) {
|
|
23
|
+
predicates.push(() => true);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
if (_types.Expr.isElementKindExpr(target)) {
|
|
27
|
+
predicates.push(target.isEqual ? n => n.kind === target.elementKind : n => n.kind !== target.elementKind);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (_types.Expr.isElementTagExpr(target)) {
|
|
31
|
+
predicates.push(target.isEqual ? ({
|
|
32
|
+
tags
|
|
33
|
+
}) => !!tags && tags.includes(target.elementTag) : ({
|
|
34
|
+
tags
|
|
35
|
+
}) => (0, _rambdax.isNil)(tags) || !tags.includes(target.elementTag));
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (_types.Expr.isElementRef(target)) {
|
|
39
|
+
const {
|
|
40
|
+
element,
|
|
41
|
+
isDescedants
|
|
42
|
+
} = target;
|
|
43
|
+
predicates.push(isDescedants ? n => n.id.startsWith(element + ".") : n => n.id === element);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
(0, _errors.nonexhaustive)(target);
|
|
47
|
+
}
|
|
48
|
+
(0, _rambdax.filter)((0, _rambdax.anyPass)(predicates), nodes).forEach(n => {
|
|
49
|
+
n.shape = rule.style.shape ?? n.shape;
|
|
50
|
+
n.color = rule.style.color ?? n.color;
|
|
51
|
+
if (_remeda.isDefined.strict(rule.style.icon)) {
|
|
52
|
+
n.icon = rule.style.icon;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return nodes;
|
|
57
|
+
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type ViewRuleStyle } from '../../types/view';
|
|
1
|
+
import type { ComputedNode, ViewRuleStyle } from '../../types';
|
|
3
2
|
export declare function applyViewRuleStyles(rules: ViewRuleStyle[], _nodes: ComputedNode[]): ComputedNode[];
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.applyViewRuleStyles = applyViewRuleStyles;
|
|
7
|
-
var _rambdax = require("rambdax");
|
|
8
|
-
var _remeda = require("remeda");
|
|
9
|
-
var Expr = _interopRequireWildcard(require("../../types/expression"));
|
|
10
|
-
var _errors = require("../../errors");
|
|
11
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
function applyViewRuleStyles(rules, _nodes) {
|
|
1
|
+
import { anyPass, clone, filter, isNil } from "rambdax";
|
|
2
|
+
import { isDefined } from "remeda";
|
|
3
|
+
import { nonexhaustive } from "../../errors/index.js";
|
|
4
|
+
import { Expr } from "../../types/index.js";
|
|
5
|
+
export function applyViewRuleStyles(rules, _nodes) {
|
|
14
6
|
if (rules.length === 0) {
|
|
15
7
|
return _nodes;
|
|
16
8
|
}
|
|
17
|
-
const nodes =
|
|
9
|
+
const nodes = clone(_nodes);
|
|
18
10
|
for (const rule of rules) {
|
|
19
11
|
const predicates = [];
|
|
20
12
|
if (!rule.style.color && !rule.style.shape) {
|
|
@@ -26,34 +18,33 @@ function applyViewRuleStyles(rules, _nodes) {
|
|
|
26
18
|
break;
|
|
27
19
|
}
|
|
28
20
|
if (Expr.isElementKindExpr(target)) {
|
|
29
|
-
predicates.push(
|
|
21
|
+
predicates.push(
|
|
22
|
+
target.isEqual ? (n) => n.kind === target.elementKind : (n) => n.kind !== target.elementKind
|
|
23
|
+
);
|
|
30
24
|
continue;
|
|
31
25
|
}
|
|
32
26
|
if (Expr.isElementTagExpr(target)) {
|
|
33
|
-
predicates.push(
|
|
34
|
-
tags
|
|
35
|
-
|
|
36
|
-
tags
|
|
37
|
-
}) => (0, _rambdax.isNil)(tags) || !tags.includes(target.elementTag));
|
|
27
|
+
predicates.push(
|
|
28
|
+
target.isEqual ? ({ tags }) => !!tags && tags.includes(target.elementTag) : ({ tags }) => isNil(tags) || !tags.includes(target.elementTag)
|
|
29
|
+
);
|
|
38
30
|
continue;
|
|
39
31
|
}
|
|
40
32
|
if (Expr.isElementRef(target)) {
|
|
41
|
-
const {
|
|
42
|
-
|
|
43
|
-
isDescedants
|
|
44
|
-
|
|
45
|
-
predicates.push(isDescedants ? n => n.id.startsWith(element + ".") : n => n.id === element);
|
|
33
|
+
const { element, isDescedants } = target;
|
|
34
|
+
predicates.push(
|
|
35
|
+
isDescedants ? (n) => n.id.startsWith(element + ".") : (n) => n.id === element
|
|
36
|
+
);
|
|
46
37
|
continue;
|
|
47
38
|
}
|
|
48
|
-
|
|
39
|
+
nonexhaustive(target);
|
|
49
40
|
}
|
|
50
|
-
|
|
41
|
+
filter(anyPass(predicates), nodes).forEach((n) => {
|
|
51
42
|
n.shape = rule.style.shape ?? n.shape;
|
|
52
43
|
n.color = rule.style.color ?? n.color;
|
|
53
|
-
if (
|
|
44
|
+
if (isDefined.strict(rule.style.icon)) {
|
|
54
45
|
n.icon = rule.style.icon;
|
|
55
46
|
}
|
|
56
47
|
});
|
|
57
48
|
}
|
|
58
49
|
return nodes;
|
|
59
|
-
}
|
|
50
|
+
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sortNodes = sortNodes;
|
|
7
|
+
var _utils = require("../../utils/index.cjs");
|
|
8
|
+
var _graphlib = _interopRequireDefault(require("@dagrejs/graphlib"));
|
|
9
|
+
var _errors = require("../../errors/index.cjs");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const {
|
|
12
|
+
Graph,
|
|
13
|
+
alg
|
|
14
|
+
} = _graphlib.default;
|
|
15
|
+
function sortNodes(_nodes, edges) {
|
|
6
16
|
const g = new Graph({
|
|
7
17
|
compound: true,
|
|
8
18
|
directed: true,
|
|
@@ -18,7 +28,7 @@ export function sortNodes(_nodes, edges) {
|
|
|
18
28
|
const source = _nodes.get(edge.source);
|
|
19
29
|
let target = _nodes.get(edge.target);
|
|
20
30
|
while (source && target) {
|
|
21
|
-
if (!isSameHierarchy(source, target) && !g.hasEdge(source.id, target.id)) {
|
|
31
|
+
if (!(0, _utils.isSameHierarchy)(source, target) && !g.hasEdge(source.id, target.id)) {
|
|
22
32
|
g.setEdge(source.id, target.id);
|
|
23
33
|
if (!alg.isAcyclic(g)) {
|
|
24
34
|
g.removeEdge(source.id, target.id);
|
|
@@ -32,9 +42,9 @@ export function sortNodes(_nodes, edges) {
|
|
|
32
42
|
}
|
|
33
43
|
}
|
|
34
44
|
const sorted = alg.topsort(g);
|
|
35
|
-
const nodes = sorted.map(
|
|
45
|
+
const nodes = sorted.map(id => (0, _errors.nonNullable)(_nodes.get(id)));
|
|
36
46
|
for (const node of nodes) {
|
|
37
|
-
node.children = nodes.flatMap(
|
|
47
|
+
node.children = nodes.flatMap(n => n.parent === node.id ? n.id : []);
|
|
38
48
|
}
|
|
39
49
|
return nodes;
|
|
40
|
-
}
|
|
50
|
+
}
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.sortNodes = sortNodes;
|
|
7
|
-
var _utils = require("../../utils");
|
|
8
|
-
var _graphlib = _interopRequireDefault(require("@dagrejs/graphlib"));
|
|
9
|
-
var _errors = require("../../errors");
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
const {
|
|
12
|
-
Graph,
|
|
13
|
-
alg
|
|
14
|
-
} = _graphlib.default;
|
|
15
|
-
function sortNodes(_nodes, edges) {
|
|
1
|
+
import { isSameHierarchy } from "../../utils/index.js";
|
|
2
|
+
import pkg from "@dagrejs/graphlib";
|
|
3
|
+
import { nonNullable } from "../../errors/index.js";
|
|
4
|
+
const { Graph, alg } = pkg;
|
|
5
|
+
export function sortNodes(_nodes, edges) {
|
|
16
6
|
const g = new Graph({
|
|
17
7
|
compound: true,
|
|
18
8
|
directed: true,
|
|
@@ -28,7 +18,7 @@ function sortNodes(_nodes, edges) {
|
|
|
28
18
|
const source = _nodes.get(edge.source);
|
|
29
19
|
let target = _nodes.get(edge.target);
|
|
30
20
|
while (source && target) {
|
|
31
|
-
if (!
|
|
21
|
+
if (!isSameHierarchy(source, target) && !g.hasEdge(source.id, target.id)) {
|
|
32
22
|
g.setEdge(source.id, target.id);
|
|
33
23
|
if (!alg.isAcyclic(g)) {
|
|
34
24
|
g.removeEdge(source.id, target.id);
|
|
@@ -42,9 +32,9 @@ function sortNodes(_nodes, edges) {
|
|
|
42
32
|
}
|
|
43
33
|
}
|
|
44
34
|
const sorted = alg.topsort(g);
|
|
45
|
-
const nodes = sorted.map(id =>
|
|
35
|
+
const nodes = sorted.map((id) => nonNullable(_nodes.get(id)));
|
|
46
36
|
for (const node of nodes) {
|
|
47
|
-
node.children = nodes.flatMap(n => n.parent === node.id ? n.id : []);
|
|
37
|
+
node.children = nodes.flatMap((n) => n.parent === node.id ? n.id : []);
|
|
48
38
|
}
|
|
49
39
|
return nodes;
|
|
50
|
-
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnknownError = exports.RelationRefError = exports.BaseError = void 0;
|
|
7
|
+
exports.normalizeError = normalizeError;
|
|
8
|
+
exports.serializeError = serializeError;
|
|
9
|
+
exports.throwNormalizedError = throwNormalizedError;
|
|
10
|
+
var _tsCustomError = require("ts-custom-error");
|
|
11
|
+
var _safeStableStringify = _interopRequireDefault(require("safe-stable-stringify"));
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
class BaseError extends _tsCustomError.CustomError {
|
|
14
|
+
constructor(message, options) {
|
|
15
|
+
super(message, options);
|
|
16
|
+
Object.defineProperty(this, "name", {
|
|
17
|
+
value: "BaseError"
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.BaseError = BaseError;
|
|
22
|
+
class UnknownError extends BaseError {
|
|
23
|
+
constructor(message, options) {
|
|
24
|
+
super(message, options);
|
|
25
|
+
Object.defineProperty(this, "name", {
|
|
26
|
+
value: "UnknownError"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.UnknownError = UnknownError;
|
|
31
|
+
class RelationRefError extends BaseError {
|
|
32
|
+
constructor(message, options) {
|
|
33
|
+
super(message, options);
|
|
34
|
+
Object.defineProperty(this, "name", {
|
|
35
|
+
value: "RelationRefError"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.RelationRefError = RelationRefError;
|
|
40
|
+
function normalizeError(e) {
|
|
41
|
+
if (e instanceof BaseError) {
|
|
42
|
+
return e;
|
|
43
|
+
}
|
|
44
|
+
if (e instanceof Error) {
|
|
45
|
+
return new UnknownError(e.message, {
|
|
46
|
+
cause: e
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const message = typeof e === "string" ? e : (0, _safeStableStringify.default)(e);
|
|
50
|
+
return new UnknownError(message);
|
|
51
|
+
}
|
|
52
|
+
function serializeError(e) {
|
|
53
|
+
const error = normalizeError(e);
|
|
54
|
+
return {
|
|
55
|
+
name: error.name,
|
|
56
|
+
message: error.stack ? error.stack : `${error.name}: ${error.message}`,
|
|
57
|
+
error
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function throwNormalizedError(e) {
|
|
61
|
+
throw normalizeError(e);
|
|
62
|
+
}
|
package/dist/errors/_base.d.ts
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
+
import { CustomError } from 'ts-custom-error';
|
|
2
|
+
export interface BaseErrorOptions {
|
|
3
|
+
cause?: unknown;
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* Base class for all errors in the LikeC4 library.
|
|
3
7
|
*/
|
|
4
|
-
export declare
|
|
8
|
+
export declare class BaseError extends CustomError {
|
|
9
|
+
constructor(message: string, options?: BaseErrorOptions);
|
|
10
|
+
}
|
|
5
11
|
/**
|
|
6
12
|
* Unknown error, mosly probably a bug, unhandled case or coming from a third-party library.
|
|
7
13
|
*/
|
|
8
|
-
export declare
|
|
9
|
-
|
|
14
|
+
export declare class UnknownError extends BaseError {
|
|
15
|
+
constructor(message: string, options?: BaseErrorOptions);
|
|
16
|
+
}
|
|
17
|
+
export declare class RelationRefError extends BaseError {
|
|
18
|
+
constructor(message: string, options?: BaseErrorOptions);
|
|
19
|
+
}
|
|
20
|
+
export declare function normalizeError(e: unknown): BaseError;
|
|
21
|
+
export declare function serializeError(e: unknown): {
|
|
22
|
+
name: string;
|
|
23
|
+
message: string;
|
|
24
|
+
error: BaseError;
|
|
25
|
+
};
|
|
26
|
+
export declare function throwNormalizedError(e: unknown): never;
|
package/dist/errors/_base.js
CHANGED
|
@@ -1,14 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { CustomError } from "ts-custom-error";
|
|
2
|
+
import stringify from "safe-stable-stringify";
|
|
3
|
+
export class BaseError extends CustomError {
|
|
4
|
+
constructor(message, options) {
|
|
5
|
+
super(message, options);
|
|
6
|
+
Object.defineProperty(this, "name", { value: "BaseError" });
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class UnknownError extends BaseError {
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
Object.defineProperty(this, "name", { value: "UnknownError" });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class RelationRefError extends BaseError {
|
|
16
|
+
constructor(message, options) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
Object.defineProperty(this, "name", { value: "RelationRefError" });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function normalizeError(e) {
|
|
22
|
+
if (e instanceof BaseError) {
|
|
23
|
+
return e;
|
|
24
|
+
}
|
|
25
|
+
if (e instanceof Error) {
|
|
26
|
+
return new UnknownError(e.message, { cause: e });
|
|
27
|
+
}
|
|
28
|
+
const message = typeof e === "string" ? e : stringify(e);
|
|
29
|
+
return new UnknownError(message);
|
|
30
|
+
}
|
|
31
|
+
export function serializeError(e) {
|
|
32
|
+
const error = normalizeError(e);
|
|
33
|
+
return {
|
|
34
|
+
name: error.name,
|
|
35
|
+
message: error.stack ? error.stack : `${error.name}: ${error.message}`,
|
|
36
|
+
error
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function throwNormalizedError(e) {
|
|
40
|
+
throw normalizeError(e);
|
|
41
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _base = require("./_base.cjs");
|
|
7
|
+
Object.keys(_base).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _base[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _base[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _invariant = require("./invariant.cjs");
|
|
18
|
+
Object.keys(_invariant).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _invariant[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _invariant[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _nonNullable = require("./non-nullable.cjs");
|
|
29
|
+
Object.keys(_nonNullable).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _nonNullable[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _nonNullable[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _nonexhaustive = require("./nonexhaustive.cjs");
|
|
40
|
+
Object.keys(_nonexhaustive).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _nonexhaustive[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _nonexhaustive[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _modelIndex = require("./model-index.cjs");
|
|
51
|
+
Object.keys(_modelIndex).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _modelIndex[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _modelIndex[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
package/dist/errors/index.js
CHANGED
|
@@ -1,60 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _base = require("./_base");
|
|
7
|
-
Object.keys(_base).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _base[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _base[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _invariant = require("./invariant");
|
|
18
|
-
Object.keys(_invariant).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _invariant[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _invariant[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _nonNullable = require("./non-nullable");
|
|
29
|
-
Object.keys(_nonNullable).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _nonNullable[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _nonNullable[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _nonexhaustive = require("./nonexhaustive");
|
|
40
|
-
Object.keys(_nonexhaustive).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _nonexhaustive[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _nonexhaustive[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
var _modelIndex = require("./model-index");
|
|
51
|
-
Object.keys(_modelIndex).forEach(function (key) {
|
|
52
|
-
if (key === "default" || key === "__esModule") return;
|
|
53
|
-
if (key in exports && exports[key] === _modelIndex[key]) return;
|
|
54
|
-
Object.defineProperty(exports, key, {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _modelIndex[key];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
1
|
+
export * from "./_base.js";
|
|
2
|
+
export * from "./invariant.js";
|
|
3
|
+
export * from "./non-nullable.js";
|
|
4
|
+
export * from "./nonexhaustive.js";
|
|
5
|
+
export * from "./model-index.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InvariantError = void 0;
|
|
7
|
+
exports.invariant = invariant;
|
|
8
|
+
var _base = require("./_base.cjs");
|
|
9
|
+
class InvariantError extends _base.BaseError {
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
Object.defineProperty(this, "name", {
|
|
13
|
+
value: "InvariantError"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.InvariantError = InvariantError;
|
|
18
|
+
function invariant(condition, message) {
|
|
19
|
+
if (condition) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
throw new InvariantError(message ?? "Invariant failed");
|
|
23
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { BaseErrorOptions } from './_base';
|
|
2
|
+
import { BaseError } from './_base';
|
|
3
|
+
export declare class InvariantError extends BaseError {
|
|
4
|
+
constructor(message: string, options?: BaseErrorOptions);
|
|
5
|
+
}
|
|
2
6
|
export declare function invariant(condition: any, message?: string): asserts condition;
|
package/dist/errors/invariant.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const InvariantError = _base.BaseError.subclass("InvariantError");
|
|
10
|
-
exports.InvariantError = InvariantError;
|
|
11
|
-
function invariant(condition, message) {
|
|
1
|
+
import { BaseError } from "./_base.js";
|
|
2
|
+
export class InvariantError extends BaseError {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
Object.defineProperty(this, "name", { value: "InvariantError" });
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function invariant(condition, message) {
|
|
12
9
|
if (condition) {
|
|
13
10
|
return;
|
|
14
11
|
}
|
|
15
12
|
throw new InvariantError(message ?? "Invariant failed");
|
|
16
|
-
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InvalidModelError = void 0;
|
|
7
|
+
exports.ensureModel = ensureModel;
|
|
8
|
+
var _base = require("./_base.cjs");
|
|
9
|
+
class InvalidModelError extends _base.BaseError {
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
Object.defineProperty(this, "name", {
|
|
13
|
+
value: "InvalidModelError"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.InvalidModelError = InvalidModelError;
|
|
18
|
+
function ensureModel(condition, message) {
|
|
19
|
+
if (condition) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
throw new InvalidModelError(message ?? "ModelIndex Invariant failed");
|
|
23
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { BaseErrorOptions } from './_base';
|
|
2
|
+
import { BaseError } from './_base';
|
|
3
|
+
export declare class InvalidModelError extends BaseError {
|
|
4
|
+
constructor(message: string, options?: BaseErrorOptions);
|
|
5
|
+
}
|
|
2
6
|
export declare function ensureModel(condition: any, message?: string): asserts condition;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const InvalidModelError = _base.BaseError.subclass("InvalidModelError");
|
|
10
|
-
exports.InvalidModelError = InvalidModelError;
|
|
11
|
-
function ensureModel(condition, message) {
|
|
1
|
+
import { BaseError } from "./_base.js";
|
|
2
|
+
export class InvalidModelError extends BaseError {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
Object.defineProperty(this, "name", { value: "InvalidModelError" });
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function ensureModel(condition, message) {
|
|
12
9
|
if (condition) {
|
|
13
10
|
return;
|
|
14
11
|
}
|
|
15
12
|
throw new InvalidModelError(message ?? "ModelIndex Invariant failed");
|
|
16
|
-
}
|
|
13
|
+
}
|