@likec4/core 0.33.1 → 0.34.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 (120) hide show
  1. package/dist/{colors.mjs → colors.cjs} +15 -3
  2. package/dist/colors.js +3 -15
  3. package/dist/compute-view/EdgeBuilder.cjs +37 -0
  4. package/dist/compute-view/EdgeBuilder.d.ts +1 -2
  5. package/dist/compute-view/EdgeBuilder.js +10 -18
  6. package/dist/compute-view/compute-ctx.cjs +35 -0
  7. package/dist/compute-view/compute-ctx.js +21 -14
  8. package/dist/compute-view/compute-element-view.cjs +135 -0
  9. package/dist/compute-view/compute-element-view.js +70 -62
  10. package/dist/compute-view/compute-predicates.cjs +363 -0
  11. package/dist/compute-view/compute-predicates.d.ts +1 -1
  12. package/dist/compute-view/compute-predicates.js +81 -115
  13. package/dist/compute-view/compute.cjs +60 -0
  14. package/dist/compute-view/compute.d.ts +13 -4
  15. package/dist/compute-view/compute.js +24 -31
  16. package/dist/compute-view/index.cjs +27 -0
  17. package/dist/compute-view/index.d.ts +2 -3
  18. package/dist/compute-view/index.js +2 -24
  19. package/dist/compute-view/utils/anyPossibleRelations.cjs +18 -0
  20. package/dist/compute-view/utils/anyPossibleRelations.js +6 -12
  21. package/dist/compute-view/utils/applyViewRuleStyles.cjs +57 -0
  22. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +1 -2
  23. package/dist/compute-view/utils/applyViewRuleStyles.js +20 -29
  24. package/dist/compute-view/utils/{sortNodes.mjs → sortNodes.cjs} +19 -9
  25. package/dist/compute-view/utils/sortNodes.js +9 -19
  26. package/dist/errors/_base.cjs +62 -0
  27. package/dist/errors/_base.d.ts +20 -3
  28. package/dist/errors/_base.js +41 -14
  29. package/dist/errors/index.cjs +60 -0
  30. package/dist/errors/index.js +5 -60
  31. package/dist/errors/invariant.cjs +23 -0
  32. package/dist/errors/invariant.d.ts +5 -1
  33. package/dist/errors/invariant.js +9 -12
  34. package/dist/errors/model-index.cjs +23 -0
  35. package/dist/errors/model-index.d.ts +5 -1
  36. package/dist/errors/model-index.js +9 -12
  37. package/dist/errors/non-nullable.cjs +23 -0
  38. package/dist/errors/non-nullable.d.ts +5 -1
  39. package/dist/errors/non-nullable.js +11 -14
  40. package/dist/errors/nonexhaustive.cjs +23 -0
  41. package/dist/errors/nonexhaustive.d.ts +6 -2
  42. package/dist/errors/nonexhaustive.js +12 -13
  43. package/dist/index.cjs +71 -0
  44. package/dist/index.d.ts +2 -5
  45. package/dist/index.js +6 -71
  46. package/dist/model-index/{ModelIndex.mjs → ModelIndex.cjs} +35 -23
  47. package/dist/model-index/ModelIndex.js +23 -35
  48. package/dist/model-index/index.cjs +13 -0
  49. package/dist/model-index/index.js +1 -13
  50. package/dist/types/_common.cjs +1 -0
  51. package/dist/types/_common.js +0 -1
  52. package/dist/types/computed-view.cjs +1 -0
  53. package/dist/types/computed-view.js +0 -1
  54. package/dist/types/diagram.cjs +1 -0
  55. package/dist/types/diagram.js +0 -1
  56. package/dist/types/element.cjs +14 -0
  57. package/dist/types/element.js +3 -12
  58. package/dist/types/expression.cjs +45 -0
  59. package/dist/types/expression.js +11 -26
  60. package/dist/types/index.cjs +132 -0
  61. package/dist/types/index.d.ts +10 -12
  62. package/dist/types/index.js +11 -48
  63. package/dist/types/model.cjs +1 -0
  64. package/dist/types/model.d.ts +1 -1
  65. package/dist/types/model.js +0 -1
  66. package/dist/types/opaque.cjs +1 -0
  67. package/dist/types/opaque.d.ts +1 -1
  68. package/dist/types/opaque.js +0 -1
  69. package/dist/types/relation.cjs +1 -0
  70. package/dist/types/relation.js +0 -1
  71. package/dist/types/theme.cjs +1 -0
  72. package/dist/types/theme.js +0 -1
  73. package/dist/types/view.cjs +17 -0
  74. package/dist/types/view.js +4 -12
  75. package/dist/utils/compute-node-levels.cjs +48 -0
  76. package/dist/utils/compute-node-levels.d.ts +2 -2
  77. package/dist/utils/compute-node-levels.js +7 -24
  78. package/dist/utils/fqn.cjs +80 -0
  79. package/dist/utils/fqn.js +19 -33
  80. package/dist/utils/guards.cjs +22 -0
  81. package/dist/utils/guards.js +7 -16
  82. package/dist/utils/index.cjs +49 -0
  83. package/dist/utils/index.d.ts +1 -1
  84. package/dist/utils/index.js +4 -49
  85. package/dist/utils/relations.cjs +59 -0
  86. package/dist/utils/relations.d.ts +14 -12
  87. package/dist/utils/relations.js +28 -33
  88. package/package.json +58 -21
  89. package/dist/compute-view/EdgeBuilder.mjs +0 -31
  90. package/dist/compute-view/compute-ctx.mjs +0 -42
  91. package/dist/compute-view/compute-element-view.mjs +0 -145
  92. package/dist/compute-view/compute-predicates.mjs +0 -324
  93. package/dist/compute-view/compute.mjs +0 -39
  94. package/dist/compute-view/index.mjs +0 -1
  95. package/dist/compute-view/utils/anyPossibleRelations.mjs +0 -12
  96. package/dist/compute-view/utils/applyViewRuleStyles.mjs +0 -50
  97. package/dist/errors/_base.mjs +0 -4
  98. package/dist/errors/index.mjs +0 -5
  99. package/dist/errors/invariant.mjs +0 -8
  100. package/dist/errors/model-index.mjs +0 -8
  101. package/dist/errors/non-nullable.mjs +0 -8
  102. package/dist/errors/nonexhaustive.mjs +0 -5
  103. package/dist/index.mjs +0 -6
  104. package/dist/model-index/index.mjs +0 -1
  105. package/dist/types/_common.mjs +0 -0
  106. package/dist/types/computed-view.mjs +0 -0
  107. package/dist/types/diagram.mjs +0 -0
  108. package/dist/types/element.mjs +0 -5
  109. package/dist/types/expression.mjs +0 -30
  110. package/dist/types/index.mjs +0 -3
  111. package/dist/types/model.mjs +0 -0
  112. package/dist/types/opaque.mjs +0 -0
  113. package/dist/types/relation.mjs +0 -0
  114. package/dist/types/theme.mjs +0 -0
  115. package/dist/types/view.mjs +0 -9
  116. package/dist/utils/compute-node-levels.mjs +0 -31
  117. package/dist/utils/fqn.mjs +0 -66
  118. package/dist/utils/guards.mjs +0 -13
  119. package/dist/utils/index.mjs +0 -4
  120. package/dist/utils/relations.mjs +0 -42
@@ -1,45 +1,30 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isAnyRelation = isAnyRelation;
7
- exports.isElement = isElement;
8
- exports.isElementKindExpr = isElementKindExpr;
9
- exports.isElementRef = isElementRef;
10
- exports.isElementTagExpr = isElementTagExpr;
11
- exports.isInOut = isInOut;
12
- exports.isIncoming = isIncoming;
13
- exports.isOutgoing = isOutgoing;
14
- exports.isRelation = isRelation;
15
- exports.isWildcard = isWildcard;
16
- function isElementRef(expr) {
1
+ export function isElementRef(expr) {
17
2
  return "element" in expr && "isDescedants" in expr;
18
3
  }
19
- function isWildcard(expr) {
4
+ export function isWildcard(expr) {
20
5
  return "wildcard" in expr;
21
6
  }
22
- function isElementKindExpr(expr) {
7
+ export function isElementKindExpr(expr) {
23
8
  return "elementKind" in expr && "isEqual" in expr;
24
9
  }
25
- function isElementTagExpr(expr) {
10
+ export function isElementTagExpr(expr) {
26
11
  return "elementTag" in expr && "isEqual" in expr;
27
12
  }
28
- function isElement(expr) {
13
+ export function isElement(expr) {
29
14
  return isElementRef(expr) || isWildcard(expr) || isElementKindExpr(expr) || isElementTagExpr(expr);
30
15
  }
31
- function isRelation(expr) {
16
+ export function isRelation(expr) {
32
17
  return "source" in expr && "target" in expr;
33
18
  }
34
- function isInOut(expr) {
19
+ export function isInOut(expr) {
35
20
  return "inout" in expr;
36
21
  }
37
- function isIncoming(expr) {
22
+ export function isIncoming(expr) {
38
23
  return "incoming" in expr;
39
24
  }
40
- function isOutgoing(expr) {
25
+ export function isOutgoing(expr) {
41
26
  return "outgoing" in expr;
42
27
  }
43
- function isAnyRelation(expr) {
28
+ export function isAnyRelation(expr) {
44
29
  return isRelation(expr) || isInOut(expr) || isIncoming(expr) || isOutgoing(expr);
45
- }
30
+ }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ Expr: true
8
+ };
9
+ exports.Expr = void 0;
10
+ var _opaque = require("./opaque.cjs");
11
+ Object.keys(_opaque).forEach(function (key) {
12
+ if (key === "default" || key === "__esModule") return;
13
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
14
+ if (key in exports && exports[key] === _opaque[key]) return;
15
+ Object.defineProperty(exports, key, {
16
+ enumerable: true,
17
+ get: function () {
18
+ return _opaque[key];
19
+ }
20
+ });
21
+ });
22
+ var _common = require("./_common.cjs");
23
+ Object.keys(_common).forEach(function (key) {
24
+ if (key === "default" || key === "__esModule") return;
25
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
26
+ if (key in exports && exports[key] === _common[key]) return;
27
+ Object.defineProperty(exports, key, {
28
+ enumerable: true,
29
+ get: function () {
30
+ return _common[key];
31
+ }
32
+ });
33
+ });
34
+ var _theme = require("./theme.cjs");
35
+ Object.keys(_theme).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
38
+ if (key in exports && exports[key] === _theme[key]) return;
39
+ Object.defineProperty(exports, key, {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _theme[key];
43
+ }
44
+ });
45
+ });
46
+ var _element = require("./element.cjs");
47
+ Object.keys(_element).forEach(function (key) {
48
+ if (key === "default" || key === "__esModule") return;
49
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
50
+ if (key in exports && exports[key] === _element[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _element[key];
55
+ }
56
+ });
57
+ });
58
+ var _relation = require("./relation.cjs");
59
+ Object.keys(_relation).forEach(function (key) {
60
+ if (key === "default" || key === "__esModule") return;
61
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
62
+ if (key in exports && exports[key] === _relation[key]) return;
63
+ Object.defineProperty(exports, key, {
64
+ enumerable: true,
65
+ get: function () {
66
+ return _relation[key];
67
+ }
68
+ });
69
+ });
70
+ var _model = require("./model.cjs");
71
+ Object.keys(_model).forEach(function (key) {
72
+ if (key === "default" || key === "__esModule") return;
73
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
74
+ if (key in exports && exports[key] === _model[key]) return;
75
+ Object.defineProperty(exports, key, {
76
+ enumerable: true,
77
+ get: function () {
78
+ return _model[key];
79
+ }
80
+ });
81
+ });
82
+ var _view = require("./view.cjs");
83
+ Object.keys(_view).forEach(function (key) {
84
+ if (key === "default" || key === "__esModule") return;
85
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
86
+ if (key in exports && exports[key] === _view[key]) return;
87
+ Object.defineProperty(exports, key, {
88
+ enumerable: true,
89
+ get: function () {
90
+ return _view[key];
91
+ }
92
+ });
93
+ });
94
+ var _Expr = _interopRequireWildcard(require("./expression.cjs"));
95
+ exports.Expr = _Expr;
96
+ Object.keys(_Expr).forEach(function (key) {
97
+ if (key === "default" || key === "__esModule") return;
98
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
99
+ if (key in exports && exports[key] === _Expr[key]) return;
100
+ Object.defineProperty(exports, key, {
101
+ enumerable: true,
102
+ get: function () {
103
+ return _Expr[key];
104
+ }
105
+ });
106
+ });
107
+ var _computedView = require("./computed-view.cjs");
108
+ Object.keys(_computedView).forEach(function (key) {
109
+ if (key === "default" || key === "__esModule") return;
110
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
111
+ if (key in exports && exports[key] === _computedView[key]) return;
112
+ Object.defineProperty(exports, key, {
113
+ enumerable: true,
114
+ get: function () {
115
+ return _computedView[key];
116
+ }
117
+ });
118
+ });
119
+ var _diagram = require("./diagram.cjs");
120
+ Object.keys(_diagram).forEach(function (key) {
121
+ if (key === "default" || key === "__esModule") return;
122
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
123
+ if (key in exports && exports[key] === _diagram[key]) return;
124
+ Object.defineProperty(exports, key, {
125
+ enumerable: true,
126
+ get: function () {
127
+ return _diagram[key];
128
+ }
129
+ });
130
+ });
131
+ 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); }
132
+ 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; }
@@ -1,13 +1,11 @@
1
- export { AsFqn, DefaultThemeColor, DefaultElementShape } from './element';
2
- export { isViewRuleExpression, isViewRuleAutoLayout, isViewRuleStyle } from './view';
1
+ export * from './opaque';
2
+ export * from './_common';
3
+ export * from './theme';
4
+ export * from './element';
5
+ export * from './relation';
6
+ export * from './model';
7
+ export * from './view';
8
+ export * from './expression';
9
+ export * from './computed-view';
10
+ export * from './diagram';
3
11
  export * as Expr from './expression';
4
- export type * from './_common';
5
- export type * from './opaque';
6
- export type * from './theme';
7
- export type * from './element';
8
- export type * from './relation';
9
- export type * from './model';
10
- export type * from './view';
11
- export type * from './expression';
12
- export type * from './computed-view';
13
- export type * from './diagram';
@@ -1,48 +1,11 @@
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; }
1
+ export * from "./opaque.js";
2
+ export * from "./_common.js";
3
+ export * from "./theme.js";
4
+ export * from "./element.js";
5
+ export * from "./relation.js";
6
+ export * from "./model.js";
7
+ export * from "./view.js";
8
+ export * from "./expression.js";
9
+ export * from "./computed-view.js";
10
+ export * from "./diagram.js";
11
+ export * as Expr from "./expression.js";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,7 +1,7 @@
1
1
  import type { Fqn, Element } from './element';
2
2
  import type { RelationID, Relation } from './relation';
3
3
  import type { ViewID } from './view';
4
- import type { ComputedView } from '../compute-view';
4
+ import type { ComputedView } from './computed-view';
5
5
  export interface LikeC4Model {
6
6
  elements: Record<Fqn, Element>;
7
7
  relations: Record<RelationID, Relation>;
@@ -1 +0,0 @@
1
- "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,5 +1,5 @@
1
1
  declare const tag: unique symbol;
2
- declare type Tagged<Token> = {
2
+ type Tagged<Token> = {
3
3
  readonly [tag]: Token;
4
4
  };
5
5
  /**
@@ -1 +0,0 @@
1
- "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1 +0,0 @@
1
- "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1 +0,0 @@
1
- "use strict";
@@ -0,0 +1,17 @@
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;
11
+ }
12
+ function isViewRuleStyle(rule) {
13
+ return "style" in rule && "targets" in rule;
14
+ }
15
+ function isViewRuleAutoLayout(rule) {
16
+ return "autoLayout" in rule;
17
+ }
@@ -1,17 +1,9 @@
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) {
1
+ export function isViewRuleExpression(rule) {
10
2
  return "exprs" in rule && "isInclude" in rule;
11
3
  }
12
- function isViewRuleStyle(rule) {
4
+ export function isViewRuleStyle(rule) {
13
5
  return "style" in rule && "targets" in rule;
14
6
  }
15
- function isViewRuleAutoLayout(rule) {
7
+ export function isViewRuleAutoLayout(rule) {
16
8
  return "autoLayout" in rule;
17
- }
9
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.computeNodeLevels = void 0;
7
+ var _errors = require("../errors/index.cjs");
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
37
+ };
38
+ nodeLevels[node.id] = levels;
39
+ return levels;
40
+ };
41
+ for (const node of nodes) {
42
+ if (!node.parent) {
43
+ compute(node, 0);
44
+ }
45
+ }
46
+ return nodeLevels;
47
+ };
48
+ exports.computeNodeLevels = computeNodeLevels;
@@ -1,7 +1,7 @@
1
- import type { ComputedView } from '../types/computed-view';
1
+ import type { ComputedView } from '../types';
2
2
  type NodeLevelDepth = {
3
3
  level: number;
4
4
  depth: number;
5
5
  };
6
- export declare const computeNodeLevels: ({ nodes }: ComputedView) => Record<import("..").Fqn, NodeLevelDepth>;
6
+ export declare const computeNodeLevels: ({ nodes }: ComputedView) => Record<import("../types").Fqn, NodeLevelDepth>;
7
7
  export {};
@@ -1,13 +1,5 @@
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
- }) => {
1
+ import { invariant } from "../errors/index.js";
2
+ export const computeNodeLevels = ({ nodes }) => {
11
3
  const nodeLevels = {};
12
4
  const compute = (node, level) => {
13
5
  let levels = nodeLevels[node.id];
@@ -15,26 +7,18 @@ const computeNodeLevels = ({
15
7
  return levels;
16
8
  }
17
9
  if (node.children.length === 0) {
18
- levels = {
19
- level,
20
- depth: 0
21
- };
10
+ levels = { level, depth: 0 };
22
11
  nodeLevels[node.id] = levels;
23
12
  return levels;
24
13
  }
25
14
  let depth = 1;
26
15
  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);
16
+ const child = nodes.find((n) => n.id === childId);
17
+ invariant(child, `Child ${childId} not found`);
18
+ const { depth: childDepth } = compute(child, level + 1);
32
19
  depth = Math.max(childDepth + 1, depth);
33
20
  }
34
- levels = {
35
- level,
36
- depth
37
- };
21
+ levels = { level, depth };
38
22
  nodeLevels[node.id] = levels;
39
23
  return levels;
40
24
  };
@@ -45,4 +29,3 @@ const computeNodeLevels = ({
45
29
  }
46
30
  return nodeLevels;
47
31
  };
48
- exports.computeNodeLevels = computeNodeLevels;
@@ -0,0 +1,80 @@
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.cjs");
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
+ }
24
+ }
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 + ".");
29
+ }
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 + ".");
34
+ }
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);
38
+ }
39
+ function notDescendantOf(ancestors) {
40
+ const isDescendant = isDescendantOf(ancestors);
41
+ return e => !isDescendant(e);
42
+ }
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) {
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
+ }
77
+ }
78
+ function compareByFqnHierarchically(a, b) {
79
+ return compareFqnHierarchically(a.id, b.id);
80
+ }
package/dist/utils/fqn.js CHANGED
@@ -1,20 +1,6 @@
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) {
1
+ import { anyPass } from "remeda";
2
+ import { isString } from "./guards.js";
3
+ export function nameFromFqn(fqn) {
18
4
  const lastDot = fqn.lastIndexOf(".");
19
5
  if (lastDot > 0) {
20
6
  return fqn.slice(lastDot + 1);
@@ -22,25 +8,25 @@ function nameFromFqn(fqn) {
22
8
  return fqn;
23
9
  }
24
10
  }
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;
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;
28
14
  return another.startsWith(ancestor + ".");
29
15
  }
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;
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;
33
19
  return one === another || another.startsWith(one + ".") || one.startsWith(another + ".");
34
20
  }
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);
21
+ export function isDescendantOf(ancestors) {
22
+ const predicates = ancestors.flatMap((a) => [(e) => e.id === a.id, (e) => isAncestor(a, e)]);
23
+ return anyPass(predicates);
38
24
  }
39
- function notDescendantOf(ancestors) {
25
+ export function notDescendantOf(ancestors) {
40
26
  const isDescendant = isDescendantOf(ancestors);
41
- return e => !isDescendant(e);
27
+ return (e) => !isDescendant(e);
42
28
  }
43
- function commonAncestor(first, second) {
29
+ export function commonAncestor(first, second) {
44
30
  const parentA = parentFqn(first);
45
31
  const parentB = parentFqn(second);
46
32
  if (parentA === parentB) {
@@ -59,14 +45,14 @@ function commonAncestor(first, second) {
59
45
  }
60
46
  return ancestor;
61
47
  }
62
- function parentFqn(fqn) {
48
+ export function parentFqn(fqn) {
63
49
  const lastDot = fqn.lastIndexOf(".");
64
50
  if (lastDot > 0) {
65
51
  return fqn.substring(0, lastDot);
66
52
  }
67
53
  return null;
68
54
  }
69
- function compareFqnHierarchically(a, b) {
55
+ export function compareFqnHierarchically(a, b) {
70
56
  const depthA = a.split(".").length;
71
57
  const depthB = b.split(".").length;
72
58
  if (depthA === depthB) {
@@ -75,6 +61,6 @@ function compareFqnHierarchically(a, b) {
75
61
  return depthA - depthB;
76
62
  }
77
63
  }
78
- function compareByFqnHierarchically(a, b) {
64
+ export function compareByFqnHierarchically(a, b) {
79
65
  return compareFqnHierarchically(a.id, b.id);
80
- }
66
+ }
@@ -0,0 +1,22 @@
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 _errors = require("../errors/index.cjs");
11
+ function isString(value) {
12
+ return typeof value === "string";
13
+ }
14
+ function failUnexpected(arg) {
15
+ throw new _errors.NonExhaustiveError(`Unexpected value: ${JSON.stringify(arg)}`);
16
+ }
17
+ function ignoreNeverInRuntime(arg) {
18
+ console.warn(`Unexpected and ignored value: ${JSON.stringify(arg)}`);
19
+ }
20
+ function isNonEmptyArray(arr) {
21
+ return arr.length > 0;
22
+ }