@likec4/core 0.33.0 → 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,146 +1,120 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.includeWildcardRef = exports.includeRelationExpr = exports.includeOutgoingExpr = exports.includeIncomingExpr = exports.includeInOutExpr = exports.includeElementRef = exports.includeElementKindOrTag = exports.excludeWildcardRef = exports.excludeRelationExpr = exports.excludeOutgoingExpr = exports.excludeIncomingExpr = exports.excludeInOutExpr = exports.excludeElementRef = exports.excludeElementKindOrTag = void 0;
7
- var _rambdax = require("rambdax");
8
- var Expr = _interopRequireWildcard(require("../types/expression"));
9
- var _utils = require("../utils");
10
- var _relations = require("../utils/relations");
11
- var _computeCtx = require("./compute-ctx");
12
- 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); }
13
- 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; }
14
- const includeElementRef = (ctx, expr) => {
1
+ import { anyPass, both, either, isNil, uniq } from "rambdax";
2
+ import { Expr } from "../types/index.js";
3
+ import { commonAncestor, isAncestor, isSameHierarchy, Relations } from "../utils/index.js";
4
+ import { ComputeCtx } from "./compute-ctx.js";
5
+ const { isAnyInOut, isBetween, isIncoming, isInside, isOutgoing, isAnyBetween } = Relations;
6
+ export const includeElementRef = (ctx, expr) => {
15
7
  const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
16
8
  const filters = [];
17
9
  if (expr.isDescedants) {
18
- elements.forEach(child => {
19
- filters.push((0, _rambdax.both)(_utils.Relations.isInside(expr.element), _utils.Relations.isAnyInOut(child.id)));
10
+ elements.forEach((child) => {
11
+ filters.push(both(isInside(expr.element), isAnyInOut(child.id)));
20
12
  });
21
13
  }
22
- const ctxElements = (0, _rambdax.uniq)([...ctx.elements, ...ctx.implicits]);
14
+ const ctxElements = uniq([...ctx.elements, ...ctx.implicits]);
23
15
  const excludeImplicits = [];
24
16
  for (const el of elements) {
25
- if (ctx.root && ctx.root !== el.id && !(0, _utils.isAncestor)(el.id, ctx.root)) {
26
- excludeImplicits.push(...[...ctx.implicits].filter(impl => (0, _utils.isAncestor)(el.id, impl.id)));
17
+ if (ctx.root && ctx.root !== el.id && !isAncestor(el.id, ctx.root)) {
18
+ excludeImplicits.push(...[...ctx.implicits].filter((impl) => isAncestor(el.id, impl.id)));
27
19
  }
28
20
  for (const ctxEl of ctxElements) {
29
- if (!(0, _utils.isSameHierarchy)(el, ctxEl)) {
30
- filters.push(_utils.Relations.isAnyBetween(el.id, ctxEl.id));
21
+ if (!isSameHierarchy(el, ctxEl)) {
22
+ filters.push(isAnyBetween(el.id, ctxEl.id));
31
23
  }
32
24
  }
33
25
  }
34
- const relations = filters.length ? ctx.index.filterRelations((0, _rambdax.anyPass)(filters)) : [];
26
+ const relations = filters.length ? ctx.index.filterRelations(anyPass(filters)) : [];
35
27
  if (excludeImplicits.length == 0) {
36
- return ctx.include({
37
- elements,
38
- relations
39
- });
28
+ return ctx.include({ elements, relations });
40
29
  }
41
- return ctx.include({
42
- elements,
43
- relations
44
- }).exclude({
45
- implicits: excludeImplicits
46
- });
30
+ return ctx.include({ elements, relations }).exclude({ implicits: excludeImplicits });
47
31
  };
48
- exports.includeElementRef = includeElementRef;
49
- const excludeElementRef = (ctx, expr) => {
32
+ export const excludeElementRef = (ctx, expr) => {
50
33
  const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
51
- const elementsIds = elements.map(e => e.id);
52
- const relations = [...ctx.relations].filter(r => elementsIds.includes(r.source) || elementsIds.includes(r.target));
53
- return ctx.exclude({
54
- elements,
55
- relations
56
- });
34
+ const elementsIds = elements.map((e) => e.id);
35
+ const relations = [...ctx.relations].filter(
36
+ (r) => elementsIds.includes(r.source) || elementsIds.includes(r.target)
37
+ );
38
+ return ctx.exclude({ elements, relations });
57
39
  };
58
- exports.excludeElementRef = excludeElementRef;
59
- const asElementPredicate = expr => {
40
+ const asElementPredicate = (expr) => {
60
41
  if (expr.isEqual) {
61
42
  if (Expr.isElementKindExpr(expr)) {
62
- return e => e.kind === expr.elementKind;
43
+ return (e) => e.kind === expr.elementKind;
63
44
  } else {
64
- return ({
65
- tags
66
- }) => !!tags && tags.includes(expr.elementTag);
45
+ return ({ tags }) => !!tags && tags.includes(expr.elementTag);
67
46
  }
68
47
  } else {
69
48
  if (Expr.isElementKindExpr(expr)) {
70
- return e => e.kind !== expr.elementKind;
49
+ return (e) => e.kind !== expr.elementKind;
71
50
  } else {
72
- return ({
73
- tags
74
- }) => (0, _rambdax.isNil)(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
51
+ return ({ tags }) => isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
75
52
  }
76
53
  }
77
54
  };
78
- const includeElementKindOrTag = (ctx, expr) => {
55
+ export const includeElementKindOrTag = (ctx, expr) => {
79
56
  const elements = ctx.index.elements.filter(asElementPredicate(expr));
80
- return elements.reduce((accCtx, el) => includeElementRef(accCtx, {
81
- element: el.id,
82
- isDescedants: false
83
- }), ctx);
57
+ return elements.reduce(
58
+ (accCtx, el) => includeElementRef(accCtx, {
59
+ element: el.id,
60
+ isDescedants: false
61
+ }),
62
+ ctx
63
+ );
84
64
  };
85
- exports.includeElementKindOrTag = includeElementKindOrTag;
86
- const excludeElementKindOrTag = (ctx, expr) => {
65
+ export const excludeElementKindOrTag = (ctx, expr) => {
87
66
  const predicate = asElementPredicate(expr);
88
67
  const elements = [...ctx.elements].filter(predicate);
89
68
  const implicits = [...ctx.implicits].filter(predicate);
90
- return ctx.exclude({
91
- elements,
92
- implicits
93
- });
69
+ return ctx.exclude({ elements, implicits });
94
70
  };
95
- exports.excludeElementKindOrTag = excludeElementKindOrTag;
96
- const includeWildcardRef = (ctx, _expr) => {
97
- const {
98
- root
99
- } = ctx;
71
+ export const includeWildcardRef = (ctx, _expr) => {
72
+ const { root } = ctx;
100
73
  if (root) {
101
74
  const elements = [ctx.index.find(root), ...ctx.index.children(root)];
102
- const allImplicits = [...ctx.index.siblings(root), ...ctx.index.ancestors(root).flatMap(a => [...ctx.index.siblings(a.id)])];
103
- const inOut = ctx.index.filterRelations((0, _relations.isAnyInOut)(root));
75
+ const allImplicits = [
76
+ ...ctx.index.siblings(root),
77
+ ...ctx.index.ancestors(root).flatMap((a) => [...ctx.index.siblings(a.id)])
78
+ ];
79
+ const inOut = ctx.index.filterRelations(isAnyInOut(root));
104
80
  const implicits = [];
105
81
  for (const implicit of allImplicits) {
106
- if (inOut.some((0, _relations.isAnyInOut)(implicit.id))) {
82
+ if (inOut.some(isAnyInOut(implicit.id))) {
107
83
  implicits.push(implicit);
108
84
  }
109
85
  }
110
86
  return ctx.include({
111
87
  elements,
112
- relations: [...ctx.index.filterRelations((0, _relations.isInside)(root)), ...inOut],
88
+ relations: [...ctx.index.filterRelations(isInside(root)), ...inOut],
113
89
  implicits
114
90
  });
115
91
  } else {
116
92
  const elements = ctx.index.rootElements();
117
93
  if (elements.length <= 1) {
118
- return new _computeCtx.ComputeCtx(ctx.index, ctx.root, new Set(elements));
94
+ return new ComputeCtx(ctx.index, ctx.root, new Set(elements));
119
95
  }
120
- const relations = ctx.index.filterRelations(rel => (0, _rambdax.isNil)((0, _utils.commonAncestor)(rel.source, rel.target)));
96
+ const relations = ctx.index.filterRelations(
97
+ (rel) => isNil(commonAncestor(rel.source, rel.target))
98
+ );
121
99
  return ctx.include({
122
100
  elements,
123
101
  relations
124
102
  });
125
103
  }
126
104
  };
127
- exports.includeWildcardRef = includeWildcardRef;
128
- const excludeWildcardRef = (ctx, _expr) => {
129
- const {
130
- root
131
- } = ctx;
105
+ export const excludeWildcardRef = (ctx, _expr) => {
106
+ const { root } = ctx;
132
107
  if (root) {
133
- const relations = [...ctx.relations].filter((0, _rambdax.either)((0, _relations.isInside)(root), (0, _relations.isAnyInOut)(root)));
108
+ const relations = [...ctx.relations].filter(either(isInside(root), isAnyInOut(root)));
134
109
  return ctx.exclude({
135
- elements: [...ctx.elements].filter(e => e.id === root || (0, _utils.isAncestor)(root, e.id)),
110
+ elements: [...ctx.elements].filter((e) => e.id === root || isAncestor(root, e.id)),
136
111
  relations,
137
- implicits: [...ctx.implicits].filter(e => relations.some((0, _relations.isAnyInOut)(e.id)))
112
+ implicits: [...ctx.implicits].filter((e) => relations.some(isAnyInOut(e.id)))
138
113
  });
139
114
  } else {
140
- return new _computeCtx.ComputeCtx(ctx.index, ctx.root);
115
+ return new ComputeCtx(ctx.index, ctx.root);
141
116
  }
142
117
  };
143
- exports.excludeWildcardRef = excludeWildcardRef;
144
118
  const resolveElements = (ctx, expr) => {
145
119
  if (Expr.isWildcard(expr)) {
146
120
  if (ctx.root) {
@@ -150,7 +124,7 @@ const resolveElements = (ctx, expr) => {
150
124
  }
151
125
  }
152
126
  if (Expr.isElementKindExpr(expr)) {
153
- return ctx.index.elements.filter(el => {
127
+ return ctx.index.elements.filter((el) => {
154
128
  if (expr.isEqual) {
155
129
  return el.kind === expr.elementKind;
156
130
  }
@@ -158,12 +132,12 @@ const resolveElements = (ctx, expr) => {
158
132
  });
159
133
  }
160
134
  if (Expr.isElementTagExpr(expr)) {
161
- return ctx.index.elements.filter(el => {
135
+ return ctx.index.elements.filter((el) => {
162
136
  const tags = el.tags;
163
137
  if (expr.isEqual) {
164
138
  return !!tags && tags.includes(expr.elementTag);
165
139
  }
166
- return (0, _rambdax.isNil)(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
140
+ return isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
167
141
  });
168
142
  }
169
143
  if (expr.isDescedants) {
@@ -172,7 +146,7 @@ const resolveElements = (ctx, expr) => {
172
146
  return [ctx.index.find(expr.element)];
173
147
  }
174
148
  };
175
- const includeIncomingExpr = (ctx, expr) => {
149
+ export const includeIncomingExpr = (ctx, expr) => {
176
150
  if (Expr.isWildcard(expr.incoming) && !ctx.root) {
177
151
  return ctx;
178
152
  }
@@ -182,12 +156,12 @@ const includeIncomingExpr = (ctx, expr) => {
182
156
  }
183
157
  let allrelations = ctx.index.relations;
184
158
  if (Expr.isElementRef(expr.incoming)) {
185
- allrelations = allrelations.filter((0, _relations.isIncoming)(expr.incoming.element));
159
+ allrelations = allrelations.filter(isIncoming(expr.incoming.element));
186
160
  }
187
161
  const implicits = [];
188
162
  const relations = [];
189
163
  for (const el of elements) {
190
- const elRelations = allrelations.filter((0, _relations.isIncoming)(el.id));
164
+ const elRelations = allrelations.filter(isIncoming(el.id));
191
165
  if (elRelations.length > 0) {
192
166
  relations.push(...elRelations);
193
167
  implicits.push(el);
@@ -198,8 +172,7 @@ const includeIncomingExpr = (ctx, expr) => {
198
172
  implicits
199
173
  });
200
174
  };
201
- exports.includeIncomingExpr = includeIncomingExpr;
202
- const excludeIncomingExpr = (ctx, expr) => {
175
+ export const excludeIncomingExpr = (ctx, expr) => {
203
176
  if (Expr.isWildcard(expr.incoming) && !ctx.root) {
204
177
  return ctx;
205
178
  }
@@ -207,7 +180,7 @@ const excludeIncomingExpr = (ctx, expr) => {
207
180
  if (elements.length === 0) {
208
181
  return ctx;
209
182
  }
210
- const isIncomings = (0, _rambdax.anyPass)(elements.map(el => (0, _relations.isIncoming)(el.id)));
183
+ const isIncomings = anyPass(elements.map((el) => isIncoming(el.id)));
211
184
  const excluded = [...ctx.relations].filter(isIncomings);
212
185
  if (excluded.length > 0) {
213
186
  return ctx.exclude({
@@ -216,8 +189,7 @@ const excludeIncomingExpr = (ctx, expr) => {
216
189
  }
217
190
  return ctx;
218
191
  };
219
- exports.excludeIncomingExpr = excludeIncomingExpr;
220
- const includeOutgoingExpr = (ctx, expr) => {
192
+ export const includeOutgoingExpr = (ctx, expr) => {
221
193
  if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
222
194
  return ctx;
223
195
  }
@@ -227,12 +199,12 @@ const includeOutgoingExpr = (ctx, expr) => {
227
199
  }
228
200
  let allrelations = ctx.index.relations;
229
201
  if (Expr.isElementRef(expr.outgoing)) {
230
- allrelations = allrelations.filter((0, _relations.isOutgoing)(expr.outgoing.element));
202
+ allrelations = allrelations.filter(isOutgoing(expr.outgoing.element));
231
203
  }
232
204
  const implicits = [];
233
205
  const relations = [];
234
206
  for (const el of elements) {
235
- const elRelations = allrelations.filter((0, _relations.isOutgoing)(el.id));
207
+ const elRelations = allrelations.filter(isOutgoing(el.id));
236
208
  if (elRelations.length > 0) {
237
209
  relations.push(...elRelations);
238
210
  implicits.push(el);
@@ -243,8 +215,7 @@ const includeOutgoingExpr = (ctx, expr) => {
243
215
  implicits
244
216
  });
245
217
  };
246
- exports.includeOutgoingExpr = includeOutgoingExpr;
247
- const excludeOutgoingExpr = (ctx, expr) => {
218
+ export const excludeOutgoingExpr = (ctx, expr) => {
248
219
  if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
249
220
  return ctx;
250
221
  }
@@ -252,7 +223,7 @@ const excludeOutgoingExpr = (ctx, expr) => {
252
223
  if (elements.length === 0) {
253
224
  return ctx;
254
225
  }
255
- const isOutgoings = (0, _rambdax.anyPass)(elements.map(el => (0, _relations.isOutgoing)(el.id)));
226
+ const isOutgoings = anyPass(elements.map((el) => isOutgoing(el.id)));
256
227
  const excluded = [...ctx.relations].filter(isOutgoings);
257
228
  if (excluded.length > 0) {
258
229
  return ctx.exclude({
@@ -261,8 +232,7 @@ const excludeOutgoingExpr = (ctx, expr) => {
261
232
  }
262
233
  return ctx;
263
234
  };
264
- exports.excludeOutgoingExpr = excludeOutgoingExpr;
265
- const includeInOutExpr = (ctx, expr) => {
235
+ export const includeInOutExpr = (ctx, expr) => {
266
236
  if (Expr.isWildcard(expr.inout) && !ctx.root) {
267
237
  return ctx;
268
238
  }
@@ -272,12 +242,12 @@ const includeInOutExpr = (ctx, expr) => {
272
242
  }
273
243
  let allrelations = ctx.index.relations;
274
244
  if (Expr.isElementRef(expr.inout)) {
275
- allrelations = allrelations.filter((0, _relations.isAnyInOut)(expr.inout.element));
245
+ allrelations = allrelations.filter(isAnyInOut(expr.inout.element));
276
246
  }
277
247
  const implicits = [];
278
248
  const relations = [];
279
249
  for (const target of targets) {
280
- const foundRelations = allrelations.filter((0, _relations.isAnyInOut)(target.id));
250
+ const foundRelations = allrelations.filter(isAnyInOut(target.id));
281
251
  if (foundRelations.length > 0) {
282
252
  relations.push(...foundRelations);
283
253
  implicits.push(target);
@@ -288,8 +258,7 @@ const includeInOutExpr = (ctx, expr) => {
288
258
  implicits
289
259
  });
290
260
  };
291
- exports.includeInOutExpr = includeInOutExpr;
292
- const excludeInOutExpr = (ctx, expr) => {
261
+ export const excludeInOutExpr = (ctx, expr) => {
293
262
  if (Expr.isWildcard(expr.inout) && !ctx.root) {
294
263
  return ctx;
295
264
  }
@@ -297,7 +266,7 @@ const excludeInOutExpr = (ctx, expr) => {
297
266
  if (targets.length === 0) {
298
267
  return ctx;
299
268
  }
300
- const excluded = [...ctx.relations].filter((0, _rambdax.anyPass)(targets.map(t => (0, _relations.isAnyInOut)(t.id))));
269
+ const excluded = [...ctx.relations].filter(anyPass(targets.map((t) => isAnyInOut(t.id))));
301
270
  if (excluded.length > 0) {
302
271
  return ctx.exclude({
303
272
  relations: excluded
@@ -305,8 +274,7 @@ const excludeInOutExpr = (ctx, expr) => {
305
274
  }
306
275
  return ctx;
307
276
  };
308
- exports.excludeInOutExpr = excludeInOutExpr;
309
- const includeRelationExpr = (ctx, expr) => {
277
+ export const includeRelationExpr = (ctx, expr) => {
310
278
  const sources = resolveElements(ctx, expr.source);
311
279
  const targets = resolveElements(ctx, expr.target);
312
280
  if (sources.length === 0 || targets.length === 0) {
@@ -316,10 +284,10 @@ const includeRelationExpr = (ctx, expr) => {
316
284
  const relations = [];
317
285
  for (const source of sources) {
318
286
  for (const target of targets) {
319
- if ((0, _utils.isSameHierarchy)(source, target)) {
287
+ if (isSameHierarchy(source, target)) {
320
288
  continue;
321
289
  }
322
- const foundRelations = ctx.index.filterRelations((0, _relations.isBetween)(source.id, target.id));
290
+ const foundRelations = ctx.index.filterRelations(isBetween(source.id, target.id));
323
291
  if (foundRelations.length > 0) {
324
292
  relations.push(...foundRelations);
325
293
  implicits.push(source, target);
@@ -331,23 +299,22 @@ const includeRelationExpr = (ctx, expr) => {
331
299
  implicits
332
300
  });
333
301
  };
334
- exports.includeRelationExpr = includeRelationExpr;
335
- const excludeRelationExpr = (ctx, expr) => {
302
+ export const excludeRelationExpr = (ctx, expr) => {
336
303
  const sources = resolveElements(ctx, expr.source);
337
304
  const targets = resolveElements(ctx, expr.target);
338
305
  const filters = [];
339
306
  for (const source of sources) {
340
307
  for (const target of targets) {
341
- if ((0, _utils.isSameHierarchy)(source, target)) {
308
+ if (isSameHierarchy(source, target)) {
342
309
  continue;
343
310
  }
344
- filters.push((0, _relations.isBetween)(source.id, target.id));
311
+ filters.push(isBetween(source.id, target.id));
345
312
  }
346
313
  }
347
314
  if (filters.length == 0) {
348
315
  return ctx;
349
316
  }
350
- const excluded = [...ctx.relations].filter((0, _rambdax.anyPass)(filters));
317
+ const excluded = [...ctx.relations].filter(anyPass(filters));
351
318
  if (excluded.length == 0) {
352
319
  return ctx;
353
320
  }
@@ -355,4 +322,3 @@ const excludeRelationExpr = (ctx, expr) => {
355
322
  relations: excluded
356
323
  });
357
324
  };
358
- exports.excludeRelationExpr = excludeRelationExpr;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assignNavigateTo = assignNavigateTo;
7
+ exports.computeView = computeView;
8
+ exports.computeViews = computeViews;
9
+ var _remeda = require("remeda");
10
+ var _modelIndex = require("../model-index/index.cjs");
11
+ var _computeElementView = require("./compute-element-view.cjs");
12
+ var _ = require("../index.cjs");
13
+ function computeView(view, index) {
14
+ try {
15
+ return {
16
+ isSuccess: true,
17
+ view: (0, _computeElementView.computeElementView)(view, index)
18
+ };
19
+ } catch (e) {
20
+ return {
21
+ isSuccess: false,
22
+ error: (0, _.normalizeError)(e),
23
+ view: void 0
24
+ };
25
+ }
26
+ }
27
+ function computeViews(model) {
28
+ const index = _modelIndex.ModelIndex.from(model);
29
+ const computedViews = (0, _remeda.compact)((0, _remeda.map)(model.views, view => computeView(view, index).view));
30
+ return {
31
+ elements: model.elements,
32
+ relations: model.relations,
33
+ views: (0, _remeda.mapToObj)(computedViews, view => [view.id, view])
34
+ };
35
+ }
36
+ function assignNavigateTo(views) {
37
+ const allElementViews = /* @__PURE__ */new Map();
38
+ for (const {
39
+ id,
40
+ viewOf
41
+ } of views) {
42
+ if (viewOf) {
43
+ const viewsOf = allElementViews.get(viewOf) ?? [];
44
+ viewsOf.push(id);
45
+ allElementViews.set(viewOf, viewsOf);
46
+ }
47
+ }
48
+ for (const {
49
+ id,
50
+ nodes
51
+ } of views) {
52
+ for (const node of nodes) {
53
+ const navigateTo = (0, _remeda.find)(allElementViews.get(node.id) ?? [], v => v !== id);
54
+ if (navigateTo) {
55
+ node.navigateTo = navigateTo;
56
+ }
57
+ }
58
+ }
59
+ return views;
60
+ }
@@ -1,16 +1,25 @@
1
1
  import { ModelIndex } from '../model-index';
2
2
  import type { ComputedView, Element, ElementView, Fqn, Relation, RelationID, ViewID } from '../types';
3
- export declare function computeView<V extends ElementView>(view: V, index: ModelIndex): ComputedView | null;
4
- type InputModel = {
3
+ import { type BaseError } from '..';
4
+ type ComputeViewResult = {
5
+ isSuccess: true;
6
+ view: ComputedView;
7
+ } | {
8
+ isSuccess: false;
9
+ error: BaseError;
10
+ view: undefined;
11
+ };
12
+ export declare function computeView(view: ElementView, index: ModelIndex): ComputeViewResult;
13
+ export type CmpInputModel = {
5
14
  elements: Record<Fqn, Element>;
6
15
  relations: Record<RelationID, Relation>;
7
16
  views: ElementView[];
8
17
  };
9
- type OutputModel = {
18
+ export type CmpOutputModel = {
10
19
  elements: Record<Fqn, Element>;
11
20
  relations: Record<RelationID, Relation>;
12
21
  views: Record<ViewID, ComputedView>;
13
22
  };
14
- export declare function computeViews(model: InputModel): OutputModel;
23
+ export declare function computeViews(model: CmpInputModel): CmpOutputModel;
15
24
  export declare function assignNavigateTo<R extends Iterable<ComputedView>>(views: R): R;
16
25
  export {};
@@ -1,53 +1,46 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.assignNavigateTo = assignNavigateTo;
7
- exports.computeView = computeView;
8
- exports.computeViews = computeViews;
9
- var _remeda = require("remeda");
10
- var _modelIndex = require("../model-index");
11
- var _computeElementView = require("./compute-element-view");
12
- function computeView(view, index) {
1
+ import { compact, find, map, mapToObj } from "remeda";
2
+ import { ModelIndex } from "../model-index/index.js";
3
+ import { computeElementView } from "./compute-element-view.js";
4
+ import { normalizeError } from "../index.js";
5
+ export function computeView(view, index) {
13
6
  try {
14
- return (0, _computeElementView.computeElementView)(view, index);
7
+ return {
8
+ isSuccess: true,
9
+ view: computeElementView(view, index)
10
+ };
15
11
  } catch (e) {
16
- console.error(e);
17
- return null;
12
+ return {
13
+ isSuccess: false,
14
+ error: normalizeError(e),
15
+ view: void 0
16
+ };
18
17
  }
19
18
  }
20
- function computeViews(model) {
21
- const index = _modelIndex.ModelIndex.from(model);
22
- const computedViews = (0, _remeda.compact)((0, _remeda.map)(model.views, view => computeView(view, index)));
19
+ export function computeViews(model) {
20
+ const index = ModelIndex.from(model);
21
+ const computedViews = compact(map(model.views, (view) => computeView(view, index).view));
23
22
  return {
24
23
  elements: model.elements,
25
24
  relations: model.relations,
26
- views: (0, _remeda.mapToObj)(computedViews, view => [view.id, view])
25
+ views: mapToObj(computedViews, (view) => [view.id, view])
27
26
  };
28
27
  }
29
- function assignNavigateTo(views) {
30
- const allElementViews = /* @__PURE__ */new Map();
31
- for (const {
32
- id,
33
- viewOf
34
- } of views) {
28
+ export function assignNavigateTo(views) {
29
+ const allElementViews = /* @__PURE__ */ new Map();
30
+ for (const { id, viewOf } of views) {
35
31
  if (viewOf) {
36
32
  const viewsOf = allElementViews.get(viewOf) ?? [];
37
33
  viewsOf.push(id);
38
34
  allElementViews.set(viewOf, viewsOf);
39
35
  }
40
36
  }
41
- for (const {
42
- id,
43
- nodes
44
- } of views) {
37
+ for (const { id, nodes } of views) {
45
38
  for (const node of nodes) {
46
- const navigateTo = (0, _remeda.find)(allElementViews.get(node.id) ?? [], v => v !== id);
39
+ const navigateTo = find(allElementViews.get(node.id) ?? [], (v) => v !== id);
47
40
  if (navigateTo) {
48
41
  node.navigateTo = navigateTo;
49
42
  }
50
43
  }
51
44
  }
52
45
  return views;
53
- }
46
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _compute = require("./compute.cjs");
7
+ Object.keys(_compute).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _compute[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _compute[key];
14
+ }
15
+ });
16
+ });
17
+ var _EdgeBuilder = require("./EdgeBuilder.cjs");
18
+ Object.keys(_EdgeBuilder).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _EdgeBuilder[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _EdgeBuilder[key];
25
+ }
26
+ });
27
+ });
@@ -1,3 +1,2 @@
1
- export { computeView, computeViews, assignNavigateTo } from './compute';
2
- export type * from '../types/view';
3
- export type * from '../types/computed-view';
1
+ export * from './compute';
2
+ export * from './EdgeBuilder';
@@ -1,24 +1,2 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "assignNavigateTo", {
7
- enumerable: true,
8
- get: function () {
9
- return _compute.assignNavigateTo;
10
- }
11
- });
12
- Object.defineProperty(exports, "computeView", {
13
- enumerable: true,
14
- get: function () {
15
- return _compute.computeView;
16
- }
17
- });
18
- Object.defineProperty(exports, "computeViews", {
19
- enumerable: true,
20
- get: function () {
21
- return _compute.computeViews;
22
- }
23
- });
24
- var _compute = require("./compute");
1
+ export * from "./compute.js";
2
+ export * from "./EdgeBuilder.js";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.anyPossibleRelations = anyPossibleRelations;
7
+ var _rambdax = require("rambdax");
8
+ var _utils = require("../../utils/index.cjs");
9
+ function* anyPossibleRelations(elements) {
10
+ const uniqElements = (0, _rambdax.uniqBy)((0, _rambdax.prop)("id"), elements).sort(_utils.compareByFqnHierarchically).reverse();
11
+ for (const source of uniqElements) {
12
+ for (const target of uniqElements) {
13
+ if (source !== target && !(0, _utils.isAncestor)(source, target) && !(0, _utils.isAncestor)(target, source)) {
14
+ yield [source, target];
15
+ }
16
+ }
17
+ }
18
+ }