@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.
Files changed (107) hide show
  1. package/README.md +13 -2
  2. package/dist/colors.d.ts +82 -15
  3. package/dist/colors.js +116 -87
  4. package/dist/colors.mjs +112 -0
  5. package/dist/compute-view/EdgeBuilder.d.ts +0 -1
  6. package/dist/compute-view/EdgeBuilder.js +37 -34
  7. package/dist/compute-view/EdgeBuilder.mjs +31 -0
  8. package/dist/compute-view/compute-ctx.d.ts +0 -1
  9. package/dist/compute-view/compute-ctx.js +33 -24
  10. package/dist/compute-view/compute-ctx.mjs +42 -0
  11. package/dist/compute-view/compute-element-view.d.ts +2 -3
  12. package/dist/compute-view/compute-element-view.js +137 -469
  13. package/dist/compute-view/compute-element-view.mjs +145 -0
  14. package/dist/compute-view/compute-predicates.d.ts +16 -0
  15. package/dist/compute-view/compute-predicates.js +358 -0
  16. package/dist/compute-view/compute-predicates.mjs +324 -0
  17. package/dist/compute-view/compute.d.ts +8 -9
  18. package/dist/compute-view/compute.js +49 -39
  19. package/dist/compute-view/compute.mjs +39 -0
  20. package/dist/compute-view/index.d.ts +1 -1
  21. package/dist/compute-view/index.js +24 -2
  22. package/dist/compute-view/index.mjs +1 -0
  23. package/dist/compute-view/utils/anyPossibleRelations.d.ts +0 -1
  24. package/dist/compute-view/utils/anyPossibleRelations.js +17 -12
  25. package/dist/compute-view/utils/anyPossibleRelations.mjs +12 -0
  26. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +3 -0
  27. package/dist/compute-view/utils/applyViewRuleStyles.js +59 -0
  28. package/dist/compute-view/utils/applyViewRuleStyles.mjs +50 -0
  29. package/dist/compute-view/utils/sortNodes.d.ts +0 -1
  30. package/dist/compute-view/utils/sortNodes.js +47 -40
  31. package/dist/compute-view/utils/sortNodes.mjs +40 -0
  32. package/dist/errors/_base.d.ts +0 -1
  33. package/dist/errors/_base.js +14 -11
  34. package/dist/errors/_base.mjs +4 -0
  35. package/dist/errors/index.d.ts +2 -1
  36. package/dist/errors/index.js +60 -4
  37. package/dist/errors/index.mjs +5 -0
  38. package/dist/errors/invariant.d.ts +0 -1
  39. package/dist/errors/invariant.js +16 -16
  40. package/dist/errors/invariant.mjs +8 -0
  41. package/dist/errors/model-index.d.ts +0 -1
  42. package/dist/errors/model-index.js +16 -14
  43. package/dist/errors/model-index.mjs +8 -0
  44. package/dist/errors/non-nullable.d.ts +2 -0
  45. package/dist/errors/non-nullable.js +16 -0
  46. package/dist/errors/non-nullable.mjs +8 -0
  47. package/dist/errors/nonexhaustive.d.ts +2 -0
  48. package/dist/errors/nonexhaustive.js +13 -0
  49. package/dist/errors/nonexhaustive.mjs +5 -0
  50. package/dist/index.d.ts +6 -3
  51. package/dist/index.js +71 -7
  52. package/dist/index.mjs +6 -0
  53. package/dist/model-index/ModelIndex.d.ts +0 -1
  54. package/dist/model-index/ModelIndex.js +125 -124
  55. package/dist/model-index/ModelIndex.mjs +128 -0
  56. package/dist/model-index/index.d.ts +0 -1
  57. package/dist/model-index/index.js +13 -2
  58. package/dist/model-index/index.mjs +1 -0
  59. package/dist/types/_common.d.ts +2 -1
  60. package/dist/types/_common.js +1 -2
  61. package/dist/types/_common.mjs +0 -0
  62. package/dist/types/computed-view.d.ts +9 -7
  63. package/dist/types/computed-view.js +1 -2
  64. package/dist/types/computed-view.mjs +0 -0
  65. package/dist/types/diagram.d.ts +5 -2
  66. package/dist/types/diagram.js +1 -2
  67. package/dist/types/diagram.mjs +0 -0
  68. package/dist/types/element.d.ts +5 -8
  69. package/dist/types/element.js +13 -5
  70. package/dist/types/element.mjs +5 -0
  71. package/dist/types/expression.d.ts +0 -1
  72. package/dist/types/expression.js +45 -31
  73. package/dist/types/expression.mjs +30 -0
  74. package/dist/types/index.d.ts +1 -1
  75. package/dist/types/index.js +48 -4
  76. package/dist/types/index.mjs +3 -0
  77. package/dist/types/model.d.ts +0 -1
  78. package/dist/types/model.js +1 -2
  79. package/dist/types/model.mjs +0 -0
  80. package/dist/types/opaque.d.ts +0 -1
  81. package/dist/types/opaque.js +1 -2
  82. package/dist/types/opaque.mjs +0 -0
  83. package/dist/types/relation.d.ts +0 -1
  84. package/dist/types/relation.js +1 -2
  85. package/dist/types/relation.mjs +0 -0
  86. package/dist/types/theme.d.ts +22 -0
  87. package/dist/types/theme.js +1 -0
  88. package/dist/types/theme.mjs +0 -0
  89. package/dist/types/view.d.ts +4 -3
  90. package/dist/types/view.js +15 -8
  91. package/dist/types/view.mjs +9 -0
  92. package/dist/utils/compute-node-levels.d.ts +0 -1
  93. package/dist/utils/compute-node-levels.js +45 -29
  94. package/dist/utils/compute-node-levels.mjs +31 -0
  95. package/dist/utils/fqn.d.ts +12 -7
  96. package/dist/utils/fqn.js +73 -76
  97. package/dist/utils/fqn.mjs +66 -0
  98. package/dist/utils/guards.d.ts +2 -3
  99. package/dist/utils/guards.js +19 -11
  100. package/dist/utils/guards.mjs +13 -0
  101. package/dist/utils/index.d.ts +0 -1
  102. package/dist/utils/index.js +49 -5
  103. package/dist/utils/index.mjs +4 -0
  104. package/dist/utils/relations.d.ts +11 -7
  105. package/dist/utils/relations.js +56 -43
  106. package/dist/utils/relations.mjs +42 -0
  107. 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
+ }
@@ -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
@@ -1,4 +1,48 @@
1
- export { AsFqn, DefaultThemeColor, DefaultElementShape } from './element';
2
- export { isViewRuleExpression, isViewRuleAutoLayout, isViewRuleStyle } from './view';
3
- export * as Expr from './expression';
4
- //# sourceMappingURL=index.js.map
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; }
@@ -0,0 +1,3 @@
1
+ export { AsFqn, DefaultThemeColor, DefaultElementShape } from "./element.mjs";
2
+ export { isViewRuleExpression, isViewRuleAutoLayout, isViewRuleStyle } from "./view.mjs";
3
+ export * as Expr from "./expression.mjs";
@@ -7,4 +7,3 @@ export interface LikeC4Model {
7
7
  relations: Record<RelationID, Relation>;
8
8
  views: Record<ViewID, ComputedView>;
9
9
  }
10
- //# sourceMappingURL=model.d.ts.map
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=model.js.map
1
+ "use strict";
File without changes
@@ -100,4 +100,3 @@ type WontWork = UnwrapOpaque<string>;
100
100
  */
101
101
  export type UnwrapOpaque<OpaqueType extends Tagged<unknown>> = OpaqueType extends Opaque<infer Type, OpaqueType[typeof tag]> ? Type : OpaqueType;
102
102
  export {};
103
- //# sourceMappingURL=opaque.d.ts.map
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=opaque.js.map
1
+ "use strict";
File without changes
@@ -8,4 +8,3 @@ export interface Relation {
8
8
  readonly title: string;
9
9
  readonly tags?: Tag[];
10
10
  }
11
- //# sourceMappingURL=relation.d.ts.map
@@ -1,2 +1 @@
1
- export {};
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
@@ -1,7 +1,8 @@
1
1
  import type { Opaque } from './opaque';
2
- import type { ElementShape, Fqn, Tag, ThemeColor } from './element';
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
@@ -1,10 +1,17 @@
1
- export function isViewRuleExpression(rule) {
2
- return 'exprs' in rule && 'isInclude' in rule;
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
- export function isViewRuleStyle(rule) {
5
- return 'style' in rule && 'targets' in rule;
12
+ function isViewRuleStyle(rule) {
13
+ return "style" in rule && "targets" in rule;
6
14
  }
7
- export function isViewRuleAutoLayout(rule) {
8
- return 'autoLayout' in rule;
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
+ }
@@ -5,4 +5,3 @@ type NodeLevelDepth = {
5
5
  };
6
6
  export declare const computeNodeLevels: ({ nodes }: ComputedView) => Record<import("..").Fqn, NodeLevelDepth>;
7
7
  export {};
8
- //# sourceMappingURL=compute-node-levels.d.ts.map
@@ -1,32 +1,48 @@
1
- import { invariant } from '../errors';
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;
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
- for (const node of nodes) {
26
- if (!node.parent) {
27
- compute(node, 0);
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
- return nodeLevels;
45
+ }
46
+ return nodeLevels;
31
47
  };
32
- //# sourceMappingURL=compute-node-levels.js.map
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
+ };
@@ -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(...args: [ancestor: Fqn, another: Fqn] | [ancestor: Element, another: Element]): boolean;
4
- export declare function isSameHierarchy(...args: [one: Fqn, another: Fqn] | [one: Element, another: Element]): boolean;
5
- export declare function isDescendantOf(ancestors: Element[]): (e: Element) => boolean;
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 const compareFqnHierarchically: (a: string, b: string) => number;
20
- export declare const compareByFqnHierarchically: <T extends {
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) => number;
23
- //# sourceMappingURL=fqn.d.ts.map
28
+ }>(a: T, b: T): number;
package/dist/utils/fqn.js CHANGED
@@ -1,83 +1,80 @@
1
- import { anyPass } from 'remeda';
2
- import { isString } from './guards';
3
- export function nameFromFqn(fqn) {
4
- const lastDot = fqn.lastIndexOf('.');
5
- if (lastDot > 0) {
6
- return fqn.slice(lastDot + 1);
7
- }
8
- else {
9
- return fqn;
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
- export function isAncestor(...args) {
13
- const ancestor = isString(args[0]) ? args[0] : args[0].id;
14
- const another = isString(args[1]) ? args[1] : args[1].id;
15
- return another.startsWith(ancestor + '.');
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
- export function isSameHierarchy(...args) {
18
- const one = isString(args[0]) ? args[0] : args[0].id;
19
- const another = isString(args[1]) ? args[1] : args[1].id;
20
- return one === another || another.startsWith(one + '.') || one.startsWith(another + '.');
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
- export function isDescendantOf(ancestors) {
23
- const predicates = ancestors.flatMap(a => [
24
- (e) => e.id === a.id,
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
- export function notDescendantOf(ancestors) {
30
- const isDescendant = isDescendantOf(ancestors);
31
- return (e) => !isDescendant(e);
39
+ function notDescendantOf(ancestors) {
40
+ const isDescendant = isDescendantOf(ancestors);
41
+ return e => !isDescendant(e);
32
42
  }
33
- export function commonAncestor(first, second) {
34
- const parentA = parentFqn(first);
35
- const parentB = parentFqn(second);
36
- if (parentA === parentB) {
37
- return parentA;
38
- }
39
- if (!parentA || !parentB) {
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
- * Compares two fully qualified names (fqns) hierarchically based on their depth.
61
- * From parent nodes to leaves
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
+ }
@@ -1,6 +1,5 @@
1
- import type { NonEmptyArray } from "../types";
1
+ import type { NonEmptyArray } from '../types';
2
2
  export declare function isString(value: unknown): value is string;
3
- export declare function failExpectedNever(arg: never): never;
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
@@ -1,14 +1,22 @@
1
- export function isString(value) {
2
- return typeof value === 'string';
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
- export function failExpectedNever(arg) {
5
- throw new Error(`Unexpected value: ${JSON.stringify(arg)}`);
14
+ function failUnexpected(arg) {
15
+ throw new _nonexhaustive.NonExhaustiveError(`Unexpected value: ${JSON.stringify(arg)}`);
6
16
  }
7
- export function ignoreNeverInRuntime(arg) {
8
- console.warn(`Unexpected and ignored value: ${JSON.stringify(arg)}`);
9
- // throw new Error(`Unexpected value: ${arg}`);
17
+ function ignoreNeverInRuntime(arg) {
18
+ console.warn(`Unexpected and ignored value: ${JSON.stringify(arg)}`);
10
19
  }
11
- export function isNonEmptyArray(arr) {
12
- return arr.length > 0;
13
- }
14
- //# sourceMappingURL=guards.js.map
20
+ function isNonEmptyArray(arr) {
21
+ return arr.length > 0;
22
+ }