@likec4/core 0.31.0 → 0.33.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 +13 -2
- package/dist/colors.d.ts +82 -15
- package/dist/colors.js +116 -87
- package/dist/colors.mjs +112 -0
- package/dist/compute-view/EdgeBuilder.d.ts +0 -1
- package/dist/compute-view/EdgeBuilder.js +37 -34
- package/dist/compute-view/EdgeBuilder.mjs +31 -0
- package/dist/compute-view/compute-ctx.d.ts +0 -1
- package/dist/compute-view/compute-ctx.js +33 -24
- package/dist/compute-view/compute-ctx.mjs +42 -0
- package/dist/compute-view/compute-element-view.d.ts +2 -3
- package/dist/compute-view/compute-element-view.js +137 -469
- package/dist/compute-view/compute-element-view.mjs +145 -0
- package/dist/compute-view/compute-predicates.d.ts +16 -0
- package/dist/compute-view/compute-predicates.js +358 -0
- package/dist/compute-view/compute-predicates.mjs +324 -0
- package/dist/compute-view/compute.d.ts +8 -9
- package/dist/compute-view/compute.js +49 -39
- package/dist/compute-view/compute.mjs +39 -0
- package/dist/compute-view/index.d.ts +1 -1
- package/dist/compute-view/index.js +24 -2
- package/dist/compute-view/index.mjs +1 -0
- package/dist/compute-view/utils/anyPossibleRelations.d.ts +0 -1
- package/dist/compute-view/utils/anyPossibleRelations.js +17 -12
- package/dist/compute-view/utils/anyPossibleRelations.mjs +12 -0
- package/dist/compute-view/utils/applyViewRuleStyles.d.ts +3 -0
- package/dist/compute-view/utils/applyViewRuleStyles.js +59 -0
- package/dist/compute-view/utils/applyViewRuleStyles.mjs +50 -0
- package/dist/compute-view/utils/sortNodes.d.ts +0 -1
- package/dist/compute-view/utils/sortNodes.js +47 -40
- package/dist/compute-view/utils/sortNodes.mjs +40 -0
- package/dist/errors/_base.d.ts +0 -1
- package/dist/errors/_base.js +14 -11
- package/dist/errors/_base.mjs +4 -0
- package/dist/errors/index.d.ts +2 -1
- package/dist/errors/index.js +60 -4
- package/dist/errors/index.mjs +5 -0
- package/dist/errors/invariant.d.ts +0 -1
- package/dist/errors/invariant.js +16 -16
- package/dist/errors/invariant.mjs +8 -0
- package/dist/errors/model-index.d.ts +0 -1
- package/dist/errors/model-index.js +16 -14
- package/dist/errors/model-index.mjs +8 -0
- package/dist/errors/non-nullable.d.ts +2 -0
- package/dist/errors/non-nullable.js +16 -0
- package/dist/errors/non-nullable.mjs +8 -0
- package/dist/errors/nonexhaustive.d.ts +2 -0
- package/dist/errors/nonexhaustive.js +13 -0
- package/dist/errors/nonexhaustive.mjs +5 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +71 -7
- package/dist/index.mjs +6 -0
- package/dist/model-index/ModelIndex.d.ts +0 -1
- package/dist/model-index/ModelIndex.js +125 -124
- package/dist/model-index/ModelIndex.mjs +128 -0
- package/dist/model-index/index.d.ts +0 -1
- package/dist/model-index/index.js +13 -2
- package/dist/model-index/index.mjs +1 -0
- package/dist/types/_common.d.ts +2 -1
- package/dist/types/_common.js +1 -2
- package/dist/types/_common.mjs +0 -0
- package/dist/types/computed-view.d.ts +9 -7
- package/dist/types/computed-view.js +1 -2
- package/dist/types/computed-view.mjs +0 -0
- package/dist/types/diagram.d.ts +5 -2
- package/dist/types/diagram.js +1 -2
- package/dist/types/diagram.mjs +0 -0
- package/dist/types/element.d.ts +5 -8
- package/dist/types/element.js +13 -5
- package/dist/types/element.mjs +5 -0
- package/dist/types/expression.d.ts +0 -1
- package/dist/types/expression.js +45 -31
- package/dist/types/expression.mjs +30 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +48 -4
- package/dist/types/index.mjs +3 -0
- package/dist/types/model.d.ts +0 -1
- package/dist/types/model.js +1 -2
- package/dist/types/model.mjs +0 -0
- package/dist/types/opaque.d.ts +0 -1
- package/dist/types/opaque.js +1 -2
- package/dist/types/opaque.mjs +0 -0
- package/dist/types/relation.d.ts +0 -1
- package/dist/types/relation.js +1 -2
- package/dist/types/relation.mjs +0 -0
- package/dist/types/theme.d.ts +22 -0
- package/dist/types/theme.js +1 -0
- package/dist/types/theme.mjs +0 -0
- package/dist/types/view.d.ts +4 -3
- package/dist/types/view.js +15 -8
- package/dist/types/view.mjs +9 -0
- package/dist/utils/compute-node-levels.d.ts +0 -1
- package/dist/utils/compute-node-levels.js +45 -29
- package/dist/utils/compute-node-levels.mjs +31 -0
- package/dist/utils/fqn.d.ts +12 -7
- package/dist/utils/fqn.js +73 -76
- package/dist/utils/fqn.mjs +66 -0
- package/dist/utils/guards.d.ts +2 -3
- package/dist/utils/guards.js +19 -11
- package/dist/utils/guards.mjs +13 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +49 -5
- package/dist/utils/index.mjs +4 -0
- package/dist/utils/relations.d.ts +11 -7
- package/dist/utils/relations.js +56 -43
- package/dist/utils/relations.mjs +42 -0
- package/package.json +25 -49
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function isElementRef(expr) {
|
|
2
|
+
return "element" in expr && "isDescedants" in expr;
|
|
3
|
+
}
|
|
4
|
+
export function isWildcard(expr) {
|
|
5
|
+
return "wildcard" in expr;
|
|
6
|
+
}
|
|
7
|
+
export function isElementKindExpr(expr) {
|
|
8
|
+
return "elementKind" in expr && "isEqual" in expr;
|
|
9
|
+
}
|
|
10
|
+
export function isElementTagExpr(expr) {
|
|
11
|
+
return "elementTag" in expr && "isEqual" in expr;
|
|
12
|
+
}
|
|
13
|
+
export function isElement(expr) {
|
|
14
|
+
return isElementRef(expr) || isWildcard(expr) || isElementKindExpr(expr) || isElementTagExpr(expr);
|
|
15
|
+
}
|
|
16
|
+
export function isRelation(expr) {
|
|
17
|
+
return "source" in expr && "target" in expr;
|
|
18
|
+
}
|
|
19
|
+
export function isInOut(expr) {
|
|
20
|
+
return "inout" in expr;
|
|
21
|
+
}
|
|
22
|
+
export function isIncoming(expr) {
|
|
23
|
+
return "incoming" in expr;
|
|
24
|
+
}
|
|
25
|
+
export function isOutgoing(expr) {
|
|
26
|
+
return "outgoing" in expr;
|
|
27
|
+
}
|
|
28
|
+
export function isAnyRelation(expr) {
|
|
29
|
+
return isRelation(expr) || isInOut(expr) || isIncoming(expr) || isOutgoing(expr);
|
|
30
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { isViewRuleExpression, isViewRuleAutoLayout, isViewRuleStyle } from './v
|
|
|
3
3
|
export * as Expr from './expression';
|
|
4
4
|
export type * from './_common';
|
|
5
5
|
export type * from './opaque';
|
|
6
|
+
export type * from './theme';
|
|
6
7
|
export type * from './element';
|
|
7
8
|
export type * from './relation';
|
|
8
9
|
export type * from './model';
|
|
@@ -10,4 +11,3 @@ export type * from './view';
|
|
|
10
11
|
export type * from './expression';
|
|
11
12
|
export type * from './computed-view';
|
|
12
13
|
export type * from './diagram';
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/types/index.js
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AsFqn", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _element.AsFqn;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "DefaultElementShape", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _element.DefaultElementShape;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "DefaultThemeColor", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _element.DefaultThemeColor;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
exports.Expr = void 0;
|
|
25
|
+
Object.defineProperty(exports, "isViewRuleAutoLayout", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _view.isViewRuleAutoLayout;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "isViewRuleExpression", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _view.isViewRuleExpression;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "isViewRuleStyle", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _view.isViewRuleStyle;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
var _element = require("./element");
|
|
44
|
+
var _view = require("./view");
|
|
45
|
+
var _Expr = _interopRequireWildcard(require("./expression"));
|
|
46
|
+
exports.Expr = _Expr;
|
|
47
|
+
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); }
|
|
48
|
+
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; }
|
package/dist/types/model.d.ts
CHANGED
package/dist/types/model.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=model.js.map
|
|
1
|
+
"use strict";
|
|
File without changes
|
package/dist/types/opaque.d.ts
CHANGED
package/dist/types/opaque.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=opaque.js.map
|
|
1
|
+
"use strict";
|
|
File without changes
|
package/dist/types/relation.d.ts
CHANGED
package/dist/types/relation.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=relation.js.map
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type ThemeColor = 'amber' | 'blue' | 'gray' | 'slate' | 'green' | 'indigo' | 'muted' | 'primary' | 'red' | 'secondary' | 'sky';
|
|
2
|
+
export type HexColorLiteral = `#${string}`;
|
|
3
|
+
export type ColorLiteral = HexColorLiteral;
|
|
4
|
+
export interface ThemeColorValues {
|
|
5
|
+
fill: ColorLiteral;
|
|
6
|
+
stroke: ColorLiteral;
|
|
7
|
+
hiContrast: ColorLiteral;
|
|
8
|
+
loContrast: ColorLiteral;
|
|
9
|
+
}
|
|
10
|
+
export type ThemeColors = {
|
|
11
|
+
[key in ThemeColor]: ThemeColorValues;
|
|
12
|
+
};
|
|
13
|
+
export interface ThemeRelationColors {
|
|
14
|
+
lineColor: ColorLiteral;
|
|
15
|
+
labelColor: ColorLiteral;
|
|
16
|
+
}
|
|
17
|
+
export interface LikeC4Theme {
|
|
18
|
+
font: 'Helvetica';
|
|
19
|
+
shadow: ColorLiteral;
|
|
20
|
+
relation: ThemeRelationColors;
|
|
21
|
+
colors: ThemeColors;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
package/dist/types/view.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Opaque } from './opaque';
|
|
2
|
-
import type { ElementShape, Fqn, Tag
|
|
2
|
+
import type { ElementShape, Fqn, Tag } from './element';
|
|
3
3
|
import type { ElementExpression, Expression } from './expression';
|
|
4
|
-
import type { NonEmptyArray } from './_common';
|
|
4
|
+
import type { IconUrl, NonEmptyArray } from './_common';
|
|
5
|
+
import type { ThemeColor } from './theme';
|
|
5
6
|
export type ViewID = Opaque<string, 'ViewID'>;
|
|
6
7
|
export interface ViewRuleExpression {
|
|
7
8
|
isInclude: boolean;
|
|
@@ -13,6 +14,7 @@ export interface ViewRuleStyle {
|
|
|
13
14
|
style: {
|
|
14
15
|
color?: ThemeColor;
|
|
15
16
|
shape?: ElementShape;
|
|
17
|
+
icon?: IconUrl;
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
export declare function isViewRuleStyle(rule: ViewRule): rule is ViewRuleStyle;
|
|
@@ -30,4 +32,3 @@ export interface ElementView {
|
|
|
30
32
|
readonly links: NonEmptyArray<string> | null;
|
|
31
33
|
readonly rules: ViewRule[];
|
|
32
34
|
}
|
|
33
|
-
//# sourceMappingURL=view.d.ts.map
|
package/dist/types/view.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isViewRuleAutoLayout = isViewRuleAutoLayout;
|
|
7
|
+
exports.isViewRuleExpression = isViewRuleExpression;
|
|
8
|
+
exports.isViewRuleStyle = isViewRuleStyle;
|
|
9
|
+
function isViewRuleExpression(rule) {
|
|
10
|
+
return "exprs" in rule && "isInclude" in rule;
|
|
3
11
|
}
|
|
4
|
-
|
|
5
|
-
|
|
12
|
+
function isViewRuleStyle(rule) {
|
|
13
|
+
return "style" in rule && "targets" in rule;
|
|
6
14
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=view.js.map
|
|
15
|
+
function isViewRuleAutoLayout(rule) {
|
|
16
|
+
return "autoLayout" in rule;
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function isViewRuleExpression(rule) {
|
|
2
|
+
return "exprs" in rule && "isInclude" in rule;
|
|
3
|
+
}
|
|
4
|
+
export function isViewRuleStyle(rule) {
|
|
5
|
+
return "style" in rule && "targets" in rule;
|
|
6
|
+
}
|
|
7
|
+
export function isViewRuleAutoLayout(rule) {
|
|
8
|
+
return "autoLayout" in rule;
|
|
9
|
+
}
|
|
@@ -1,32 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.computeNodeLevels = void 0;
|
|
7
|
+
var _errors = require("../errors");
|
|
8
|
+
const computeNodeLevels = ({
|
|
9
|
+
nodes
|
|
10
|
+
}) => {
|
|
11
|
+
const nodeLevels = {};
|
|
12
|
+
const compute = (node, level) => {
|
|
13
|
+
let levels = nodeLevels[node.id];
|
|
14
|
+
if (levels) {
|
|
15
|
+
return levels;
|
|
16
|
+
}
|
|
17
|
+
if (node.children.length === 0) {
|
|
18
|
+
levels = {
|
|
19
|
+
level,
|
|
20
|
+
depth: 0
|
|
21
|
+
};
|
|
22
|
+
nodeLevels[node.id] = levels;
|
|
23
|
+
return levels;
|
|
24
|
+
}
|
|
25
|
+
let depth = 1;
|
|
26
|
+
for (const childId of node.children) {
|
|
27
|
+
const child = nodes.find(n => n.id === childId);
|
|
28
|
+
(0, _errors.invariant)(child, `Child ${childId} not found`);
|
|
29
|
+
const {
|
|
30
|
+
depth: childDepth
|
|
31
|
+
} = compute(child, level + 1);
|
|
32
|
+
depth = Math.max(childDepth + 1, depth);
|
|
33
|
+
}
|
|
34
|
+
levels = {
|
|
35
|
+
level,
|
|
36
|
+
depth
|
|
24
37
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
nodeLevels[node.id] = levels;
|
|
39
|
+
return levels;
|
|
40
|
+
};
|
|
41
|
+
for (const node of nodes) {
|
|
42
|
+
if (!node.parent) {
|
|
43
|
+
compute(node, 0);
|
|
29
44
|
}
|
|
30
|
-
|
|
45
|
+
}
|
|
46
|
+
return nodeLevels;
|
|
31
47
|
};
|
|
32
|
-
|
|
48
|
+
exports.computeNodeLevels = computeNodeLevels;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { invariant } from "../errors/index.mjs";
|
|
2
|
+
export const computeNodeLevels = ({ nodes }) => {
|
|
3
|
+
const nodeLevels = {};
|
|
4
|
+
const compute = (node, level) => {
|
|
5
|
+
let levels = nodeLevels[node.id];
|
|
6
|
+
if (levels) {
|
|
7
|
+
return levels;
|
|
8
|
+
}
|
|
9
|
+
if (node.children.length === 0) {
|
|
10
|
+
levels = { level, depth: 0 };
|
|
11
|
+
nodeLevels[node.id] = levels;
|
|
12
|
+
return levels;
|
|
13
|
+
}
|
|
14
|
+
let depth = 1;
|
|
15
|
+
for (const childId of node.children) {
|
|
16
|
+
const child = nodes.find((n) => n.id === childId);
|
|
17
|
+
invariant(child, `Child ${childId} not found`);
|
|
18
|
+
const { depth: childDepth } = compute(child, level + 1);
|
|
19
|
+
depth = Math.max(childDepth + 1, depth);
|
|
20
|
+
}
|
|
21
|
+
levels = { level, depth };
|
|
22
|
+
nodeLevels[node.id] = levels;
|
|
23
|
+
return levels;
|
|
24
|
+
};
|
|
25
|
+
for (const node of nodes) {
|
|
26
|
+
if (!node.parent) {
|
|
27
|
+
compute(node, 0);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return nodeLevels;
|
|
31
|
+
};
|
package/dist/utils/fqn.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { Element, Fqn } from '../types';
|
|
2
2
|
export declare function nameFromFqn(fqn: Fqn): string;
|
|
3
|
-
export declare function isAncestor
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare function isAncestor<E extends {
|
|
4
|
+
id: Fqn;
|
|
5
|
+
}>(...args: [ancestor: Fqn, another: Fqn] | [ancestor: E, another: E]): boolean;
|
|
6
|
+
export declare function isSameHierarchy<E extends {
|
|
7
|
+
id: Fqn;
|
|
8
|
+
}>(...args: [one: Fqn, another: Fqn] | [one: E, another: E]): boolean;
|
|
9
|
+
export declare function isDescendantOf<E extends {
|
|
10
|
+
id: Fqn;
|
|
11
|
+
}>(ancestors: E[]): (e: E) => boolean;
|
|
6
12
|
export declare function notDescendantOf(ancestors: Element[]): (e: Element) => boolean;
|
|
7
13
|
export declare function commonAncestor(first: Fqn, second: Fqn): Fqn | null;
|
|
8
14
|
export declare function parentFqn(fqn: Fqn): Fqn | null;
|
|
@@ -16,8 +22,7 @@ export declare function parentFqn(fqn: Fqn): Fqn | null;
|
|
|
16
22
|
* - Positive number if a is deeper than b.
|
|
17
23
|
* - Negative number if b is deeper than a.
|
|
18
24
|
*/
|
|
19
|
-
export declare
|
|
20
|
-
export declare
|
|
25
|
+
export declare function compareFqnHierarchically(a: string, b: string): number;
|
|
26
|
+
export declare function compareByFqnHierarchically<T extends {
|
|
21
27
|
id: Fqn;
|
|
22
|
-
}>(a: T, b: T)
|
|
23
|
-
//# sourceMappingURL=fqn.d.ts.map
|
|
28
|
+
}>(a: T, b: T): number;
|
package/dist/utils/fqn.js
CHANGED
|
@@ -1,83 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.commonAncestor = commonAncestor;
|
|
7
|
+
exports.compareByFqnHierarchically = compareByFqnHierarchically;
|
|
8
|
+
exports.compareFqnHierarchically = compareFqnHierarchically;
|
|
9
|
+
exports.isAncestor = isAncestor;
|
|
10
|
+
exports.isDescendantOf = isDescendantOf;
|
|
11
|
+
exports.isSameHierarchy = isSameHierarchy;
|
|
12
|
+
exports.nameFromFqn = nameFromFqn;
|
|
13
|
+
exports.notDescendantOf = notDescendantOf;
|
|
14
|
+
exports.parentFqn = parentFqn;
|
|
15
|
+
var _remeda = require("remeda");
|
|
16
|
+
var _guards = require("./guards");
|
|
17
|
+
function nameFromFqn(fqn) {
|
|
18
|
+
const lastDot = fqn.lastIndexOf(".");
|
|
19
|
+
if (lastDot > 0) {
|
|
20
|
+
return fqn.slice(lastDot + 1);
|
|
21
|
+
} else {
|
|
22
|
+
return fqn;
|
|
23
|
+
}
|
|
11
24
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
function isAncestor(...args) {
|
|
26
|
+
const ancestor = (0, _guards.isString)(args[0]) ? args[0] : args[0].id;
|
|
27
|
+
const another = (0, _guards.isString)(args[1]) ? args[1] : args[1].id;
|
|
28
|
+
return another.startsWith(ancestor + ".");
|
|
16
29
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
function isSameHierarchy(...args) {
|
|
31
|
+
const one = (0, _guards.isString)(args[0]) ? args[0] : args[0].id;
|
|
32
|
+
const another = (0, _guards.isString)(args[1]) ? args[1] : args[1].id;
|
|
33
|
+
return one === another || another.startsWith(one + ".") || one.startsWith(another + ".");
|
|
21
34
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(e) => isAncestor(a, e)
|
|
26
|
-
]);
|
|
27
|
-
return anyPass(predicates);
|
|
35
|
+
function isDescendantOf(ancestors) {
|
|
36
|
+
const predicates = ancestors.flatMap(a => [e => e.id === a.id, e => isAncestor(a, e)]);
|
|
37
|
+
return (0, _remeda.anyPass)(predicates);
|
|
28
38
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
function notDescendantOf(ancestors) {
|
|
40
|
+
const isDescendant = isDescendantOf(ancestors);
|
|
41
|
+
return e => !isDescendant(e);
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
const a = first.split('.');
|
|
43
|
-
const b = second.split('.');
|
|
44
|
-
let ancestor = null;
|
|
45
|
-
while (a.length > 1 && b.length > 1 && !!a[0] && a[0] === b[0]) {
|
|
46
|
-
ancestor = (ancestor ? `${ancestor}.${a[0]}` : a[0]);
|
|
47
|
-
a.shift();
|
|
48
|
-
b.shift();
|
|
49
|
-
}
|
|
50
|
-
return ancestor;
|
|
51
|
-
}
|
|
52
|
-
export function parentFqn(fqn) {
|
|
53
|
-
const lastDot = fqn.lastIndexOf('.');
|
|
54
|
-
if (lastDot > 0) {
|
|
55
|
-
return fqn.substring(0, lastDot);
|
|
56
|
-
}
|
|
43
|
+
function commonAncestor(first, second) {
|
|
44
|
+
const parentA = parentFqn(first);
|
|
45
|
+
const parentB = parentFqn(second);
|
|
46
|
+
if (parentA === parentB) {
|
|
47
|
+
return parentA;
|
|
48
|
+
}
|
|
49
|
+
if (!parentA || !parentB) {
|
|
57
50
|
return null;
|
|
51
|
+
}
|
|
52
|
+
const a = first.split(".");
|
|
53
|
+
const b = second.split(".");
|
|
54
|
+
let ancestor = null;
|
|
55
|
+
while (a.length > 1 && b.length > 1 && !!a[0] && a[0] === b[0]) {
|
|
56
|
+
ancestor = ancestor ? `${ancestor}.${a[0]}` : a[0];
|
|
57
|
+
a.shift();
|
|
58
|
+
b.shift();
|
|
59
|
+
}
|
|
60
|
+
return ancestor;
|
|
61
|
+
}
|
|
62
|
+
function parentFqn(fqn) {
|
|
63
|
+
const lastDot = fqn.lastIndexOf(".");
|
|
64
|
+
if (lastDot > 0) {
|
|
65
|
+
return fqn.substring(0, lastDot);
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
function compareFqnHierarchically(a, b) {
|
|
70
|
+
const depthA = a.split(".").length;
|
|
71
|
+
const depthB = b.split(".").length;
|
|
72
|
+
if (depthA === depthB) {
|
|
73
|
+
return 0;
|
|
74
|
+
} else {
|
|
75
|
+
return depthA - depthB;
|
|
76
|
+
}
|
|
58
77
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
* @param {string} a - The first fqn to compare.
|
|
64
|
-
* @param {string} b - The second fqn to compare.
|
|
65
|
-
* @returns {number} - 0 if the fqns have the same depth.
|
|
66
|
-
* - Positive number if a is deeper than b.
|
|
67
|
-
* - Negative number if b is deeper than a.
|
|
68
|
-
*/
|
|
69
|
-
export const compareFqnHierarchically = (a, b) => {
|
|
70
|
-
const depthA = a.split('.').length;
|
|
71
|
-
const depthB = b.split('.').length;
|
|
72
|
-
if (depthA === depthB) {
|
|
73
|
-
// return a.localeCompare(b)
|
|
74
|
-
return 0;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
return depthA - depthB;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
export const compareByFqnHierarchically = (a, b) => {
|
|
81
|
-
return compareFqnHierarchically(a.id, b.id);
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=fqn.js.map
|
|
78
|
+
function compareByFqnHierarchically(a, b) {
|
|
79
|
+
return compareFqnHierarchically(a.id, b.id);
|
|
80
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { anyPass } from "remeda";
|
|
2
|
+
import { isString } from "./guards.mjs";
|
|
3
|
+
export function nameFromFqn(fqn) {
|
|
4
|
+
const lastDot = fqn.lastIndexOf(".");
|
|
5
|
+
if (lastDot > 0) {
|
|
6
|
+
return fqn.slice(lastDot + 1);
|
|
7
|
+
} else {
|
|
8
|
+
return fqn;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function isAncestor(...args) {
|
|
12
|
+
const ancestor = isString(args[0]) ? args[0] : args[0].id;
|
|
13
|
+
const another = isString(args[1]) ? args[1] : args[1].id;
|
|
14
|
+
return another.startsWith(ancestor + ".");
|
|
15
|
+
}
|
|
16
|
+
export function isSameHierarchy(...args) {
|
|
17
|
+
const one = isString(args[0]) ? args[0] : args[0].id;
|
|
18
|
+
const another = isString(args[1]) ? args[1] : args[1].id;
|
|
19
|
+
return one === another || another.startsWith(one + ".") || one.startsWith(another + ".");
|
|
20
|
+
}
|
|
21
|
+
export function isDescendantOf(ancestors) {
|
|
22
|
+
const predicates = ancestors.flatMap((a) => [(e) => e.id === a.id, (e) => isAncestor(a, e)]);
|
|
23
|
+
return anyPass(predicates);
|
|
24
|
+
}
|
|
25
|
+
export function notDescendantOf(ancestors) {
|
|
26
|
+
const isDescendant = isDescendantOf(ancestors);
|
|
27
|
+
return (e) => !isDescendant(e);
|
|
28
|
+
}
|
|
29
|
+
export function commonAncestor(first, second) {
|
|
30
|
+
const parentA = parentFqn(first);
|
|
31
|
+
const parentB = parentFqn(second);
|
|
32
|
+
if (parentA === parentB) {
|
|
33
|
+
return parentA;
|
|
34
|
+
}
|
|
35
|
+
if (!parentA || !parentB) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const a = first.split(".");
|
|
39
|
+
const b = second.split(".");
|
|
40
|
+
let ancestor = null;
|
|
41
|
+
while (a.length > 1 && b.length > 1 && !!a[0] && a[0] === b[0]) {
|
|
42
|
+
ancestor = ancestor ? `${ancestor}.${a[0]}` : a[0];
|
|
43
|
+
a.shift();
|
|
44
|
+
b.shift();
|
|
45
|
+
}
|
|
46
|
+
return ancestor;
|
|
47
|
+
}
|
|
48
|
+
export function parentFqn(fqn) {
|
|
49
|
+
const lastDot = fqn.lastIndexOf(".");
|
|
50
|
+
if (lastDot > 0) {
|
|
51
|
+
return fqn.substring(0, lastDot);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
export function compareFqnHierarchically(a, b) {
|
|
56
|
+
const depthA = a.split(".").length;
|
|
57
|
+
const depthB = b.split(".").length;
|
|
58
|
+
if (depthA === depthB) {
|
|
59
|
+
return 0;
|
|
60
|
+
} else {
|
|
61
|
+
return depthA - depthB;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function compareByFqnHierarchically(a, b) {
|
|
65
|
+
return compareFqnHierarchically(a.id, b.id);
|
|
66
|
+
}
|
package/dist/utils/guards.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { NonEmptyArray } from
|
|
1
|
+
import type { NonEmptyArray } from '../types';
|
|
2
2
|
export declare function isString(value: unknown): value is string;
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function failUnexpected(arg: never): never;
|
|
4
4
|
export declare function ignoreNeverInRuntime(arg: never): void;
|
|
5
5
|
export declare function isNonEmptyArray<A>(arr: ArrayLike<A>): arr is NonEmptyArray<A>;
|
|
6
|
-
//# sourceMappingURL=guards.d.ts.map
|
package/dist/utils/guards.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.failUnexpected = failUnexpected;
|
|
7
|
+
exports.ignoreNeverInRuntime = ignoreNeverInRuntime;
|
|
8
|
+
exports.isNonEmptyArray = isNonEmptyArray;
|
|
9
|
+
exports.isString = isString;
|
|
10
|
+
var _nonexhaustive = require("../errors/nonexhaustive");
|
|
11
|
+
function isString(value) {
|
|
12
|
+
return typeof value === "string";
|
|
3
13
|
}
|
|
4
|
-
|
|
5
|
-
|
|
14
|
+
function failUnexpected(arg) {
|
|
15
|
+
throw new _nonexhaustive.NonExhaustiveError(`Unexpected value: ${JSON.stringify(arg)}`);
|
|
6
16
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// throw new Error(`Unexpected value: ${arg}`);
|
|
17
|
+
function ignoreNeverInRuntime(arg) {
|
|
18
|
+
console.warn(`Unexpected and ignored value: ${JSON.stringify(arg)}`);
|
|
10
19
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=guards.js.map
|
|
20
|
+
function isNonEmptyArray(arr) {
|
|
21
|
+
return arr.length > 0;
|
|
22
|
+
}
|