@likec4/core 0.37.1 → 0.41.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 (147) hide show
  1. package/README.md +2 -6
  2. package/dist/cjs/colors/element.d.ts +68 -0
  3. package/dist/{colors.js → cjs/colors/element.js} +24 -46
  4. package/dist/cjs/colors/index.d.ts +132 -0
  5. package/dist/cjs/colors/index.js +27 -0
  6. package/dist/cjs/colors/relationships.d.ts +57 -0
  7. package/dist/cjs/colors/relationships.js +76 -0
  8. package/dist/cjs/errors/index.d.ts +45 -0
  9. package/dist/cjs/errors/index.js +137 -0
  10. package/dist/{index.d.ts → cjs/index.d.ts} +3 -5
  11. package/dist/{index.cjs → cjs/index.js} +16 -38
  12. package/dist/{types → cjs/types}/computed-view.d.ts +11 -7
  13. package/dist/{types → cjs/types}/diagram.d.ts +15 -11
  14. package/dist/{types → cjs/types}/expression.d.ts +1 -1
  15. package/dist/{types/index.cjs → cjs/types/index.js} +10 -10
  16. package/dist/cjs/types/relation.d.ts +22 -0
  17. package/dist/cjs/types/relation.js +12 -0
  18. package/dist/{types → cjs/types}/theme.d.ts +10 -6
  19. package/dist/{types → cjs/types}/view.d.ts +22 -4
  20. package/dist/{types/view.cjs → cjs/types/view.js} +1 -1
  21. package/dist/{utils → cjs/utils}/fqn.d.ts +6 -1
  22. package/dist/{utils/fqn.cjs → cjs/utils/fqn.js} +18 -5
  23. package/dist/{utils → cjs/utils}/guards.d.ts +1 -2
  24. package/dist/cjs/utils/guards.js +20 -0
  25. package/dist/{utils → cjs/utils}/index.d.ts +0 -1
  26. package/dist/{utils/index.cjs → cjs/utils/index.js} +3 -14
  27. package/dist/{utils/relations.cjs → cjs/utils/relations.js} +1 -1
  28. package/dist/esm/colors/element.d.ts +68 -0
  29. package/dist/esm/colors/element.js +82 -0
  30. package/dist/esm/colors/index.d.ts +132 -0
  31. package/dist/esm/colors/index.js +9 -0
  32. package/dist/esm/colors/relationships.d.ts +57 -0
  33. package/dist/esm/colors/relationships.js +64 -0
  34. package/dist/esm/errors/index.d.ts +45 -0
  35. package/dist/esm/errors/index.js +97 -0
  36. package/dist/esm/index.d.ts +6 -0
  37. package/dist/esm/index.js +4 -0
  38. package/dist/esm/types/_common.d.ts +3 -0
  39. package/dist/esm/types/computed-view.d.ts +44 -0
  40. package/dist/esm/types/diagram.d.ts +41 -0
  41. package/dist/esm/types/element.d.ts +29 -0
  42. package/dist/esm/types/expression.d.ts +56 -0
  43. package/dist/esm/types/index.d.ts +11 -0
  44. package/dist/esm/types/model.d.ts +14 -0
  45. package/dist/esm/types/opaque.d.ts +102 -0
  46. package/dist/esm/types/relation.d.ts +22 -0
  47. package/dist/esm/types/relation.js +3 -0
  48. package/dist/esm/types/theme.d.ts +26 -0
  49. package/dist/esm/types/view.d.ts +61 -0
  50. package/dist/{types → esm/types}/view.js +1 -1
  51. package/dist/esm/utils/fqn.d.ts +33 -0
  52. package/dist/{utils → esm/utils}/fqn.js +16 -4
  53. package/dist/esm/utils/guards.d.ts +4 -0
  54. package/dist/esm/utils/guards.js +7 -0
  55. package/dist/esm/utils/index.d.ts +3 -0
  56. package/dist/{utils → esm/utils}/index.js +0 -1
  57. package/dist/esm/utils/relations.d.ts +25 -0
  58. package/package.json +44 -61
  59. package/dist/colors.cjs +0 -124
  60. package/dist/colors.d.ts +0 -148
  61. package/dist/compute-view/EdgeBuilder.cjs +0 -37
  62. package/dist/compute-view/EdgeBuilder.d.ts +0 -6
  63. package/dist/compute-view/EdgeBuilder.js +0 -30
  64. package/dist/compute-view/compute-ctx.cjs +0 -89
  65. package/dist/compute-view/compute-ctx.d.ts +0 -19
  66. package/dist/compute-view/compute-ctx.js +0 -98
  67. package/dist/compute-view/compute-element-view.cjs +0 -91
  68. package/dist/compute-view/compute-element-view.d.ts +0 -3
  69. package/dist/compute-view/compute-element-view.js +0 -86
  70. package/dist/compute-view/compute-predicates.cjs +0 -363
  71. package/dist/compute-view/compute-predicates.d.ts +0 -16
  72. package/dist/compute-view/compute-predicates.js +0 -324
  73. package/dist/compute-view/compute.cjs +0 -46
  74. package/dist/compute-view/compute.d.ts +0 -14
  75. package/dist/compute-view/compute.js +0 -36
  76. package/dist/compute-view/index.cjs +0 -38
  77. package/dist/compute-view/index.d.ts +0 -3
  78. package/dist/compute-view/index.js +0 -3
  79. package/dist/compute-view/resolve-extended-views.cjs +0 -50
  80. package/dist/compute-view/resolve-extended-views.d.ts +0 -6
  81. package/dist/compute-view/resolve-extended-views.js +0 -38
  82. package/dist/compute-view/utils/anyPossibleRelations.cjs +0 -18
  83. package/dist/compute-view/utils/anyPossibleRelations.d.ts +0 -2
  84. package/dist/compute-view/utils/anyPossibleRelations.js +0 -12
  85. package/dist/compute-view/utils/applyViewRuleStyles.cjs +0 -57
  86. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +0 -2
  87. package/dist/compute-view/utils/applyViewRuleStyles.js +0 -50
  88. package/dist/compute-view/utils/sortNodes.cjs +0 -50
  89. package/dist/compute-view/utils/sortNodes.d.ts +0 -2
  90. package/dist/compute-view/utils/sortNodes.js +0 -40
  91. package/dist/errors/_base.cjs +0 -62
  92. package/dist/errors/_base.d.ts +0 -26
  93. package/dist/errors/_base.js +0 -41
  94. package/dist/errors/index.cjs +0 -60
  95. package/dist/errors/index.d.ts +0 -5
  96. package/dist/errors/index.js +0 -5
  97. package/dist/errors/invariant.cjs +0 -23
  98. package/dist/errors/invariant.d.ts +0 -6
  99. package/dist/errors/invariant.js +0 -13
  100. package/dist/errors/model-index.cjs +0 -23
  101. package/dist/errors/model-index.d.ts +0 -6
  102. package/dist/errors/model-index.js +0 -13
  103. package/dist/errors/non-nullable.cjs +0 -23
  104. package/dist/errors/non-nullable.d.ts +0 -6
  105. package/dist/errors/non-nullable.js +0 -13
  106. package/dist/errors/nonexhaustive.cjs +0 -23
  107. package/dist/errors/nonexhaustive.d.ts +0 -6
  108. package/dist/errors/nonexhaustive.js +0 -12
  109. package/dist/index.js +0 -6
  110. package/dist/model-index/ModelIndex.cjs +0 -140
  111. package/dist/model-index/ModelIndex.d.ts +0 -27
  112. package/dist/model-index/ModelIndex.js +0 -128
  113. package/dist/model-index/index.cjs +0 -13
  114. package/dist/model-index/index.d.ts +0 -1
  115. package/dist/model-index/index.js +0 -1
  116. package/dist/types/relation.d.ts +0 -10
  117. package/dist/types/relation.js +0 -0
  118. package/dist/types/theme.cjs +0 -1
  119. package/dist/utils/compute-node-levels.cjs +0 -48
  120. package/dist/utils/compute-node-levels.d.ts +0 -7
  121. package/dist/utils/compute-node-levels.js +0 -31
  122. package/dist/utils/guards.cjs +0 -22
  123. package/dist/utils/guards.js +0 -13
  124. /package/dist/{types → cjs/types}/_common.d.ts +0 -0
  125. /package/dist/{types/_common.cjs → cjs/types/_common.js} +0 -0
  126. /package/dist/{types/computed-view.cjs → cjs/types/computed-view.js} +0 -0
  127. /package/dist/{types/diagram.cjs → cjs/types/diagram.js} +0 -0
  128. /package/dist/{types → cjs/types}/element.d.ts +0 -0
  129. /package/dist/{types/element.cjs → cjs/types/element.js} +0 -0
  130. /package/dist/{types/expression.cjs → cjs/types/expression.js} +0 -0
  131. /package/dist/{types → cjs/types}/index.d.ts +0 -0
  132. /package/dist/{types → cjs/types}/model.d.ts +0 -0
  133. /package/dist/{types/model.cjs → cjs/types/model.js} +0 -0
  134. /package/dist/{types → cjs/types}/opaque.d.ts +0 -0
  135. /package/dist/{types/opaque.cjs → cjs/types/opaque.js} +0 -0
  136. /package/dist/{types/relation.cjs → cjs/types/theme.js} +0 -0
  137. /package/dist/{utils → cjs/utils}/relations.d.ts +0 -0
  138. /package/dist/{types → esm/types}/_common.js +0 -0
  139. /package/dist/{types → esm/types}/computed-view.js +0 -0
  140. /package/dist/{types → esm/types}/diagram.js +0 -0
  141. /package/dist/{types → esm/types}/element.js +0 -0
  142. /package/dist/{types → esm/types}/expression.js +0 -0
  143. /package/dist/{types → esm/types}/index.js +0 -0
  144. /package/dist/{types → esm/types}/model.js +0 -0
  145. /package/dist/{types → esm/types}/opaque.js +0 -0
  146. /package/dist/{types → esm/types}/theme.js +0 -0
  147. /package/dist/{utils → esm/utils}/relations.js +0 -0
@@ -1,363 +0,0 @@
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 _types = require("../types/index.cjs");
9
- var _utils = require("../utils/index.cjs");
10
- var _computeCtx = require("./compute-ctx.cjs");
11
- const {
12
- isAnyInOut,
13
- isBetween,
14
- isIncoming,
15
- isInside,
16
- isOutgoing,
17
- isAnyBetween
18
- } = _utils.Relations;
19
- const includeElementRef = (ctx, expr) => {
20
- const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
21
- const filters = [];
22
- if (expr.isDescedants) {
23
- elements.forEach(child => {
24
- filters.push((0, _rambdax.both)(isInside(expr.element), isAnyInOut(child.id)));
25
- });
26
- }
27
- const ctxElements = (0, _rambdax.uniq)([...ctx.elements, ...ctx.implicits]);
28
- const excludeImplicits = [];
29
- for (const el of elements) {
30
- if (ctx.root && ctx.root !== el.id && !(0, _utils.isAncestor)(el.id, ctx.root)) {
31
- excludeImplicits.push(...[...ctx.implicits].filter(impl => (0, _utils.isAncestor)(el.id, impl.id)));
32
- }
33
- for (const ctxEl of ctxElements) {
34
- if (!(0, _utils.isSameHierarchy)(el, ctxEl)) {
35
- filters.push(isAnyBetween(el.id, ctxEl.id));
36
- }
37
- }
38
- }
39
- const relations = filters.length ? ctx.index.filterRelations((0, _rambdax.anyPass)(filters)) : [];
40
- if (excludeImplicits.length == 0) {
41
- return ctx.include({
42
- elements,
43
- relations
44
- });
45
- }
46
- return ctx.include({
47
- elements,
48
- relations
49
- }).exclude({
50
- implicits: excludeImplicits
51
- });
52
- };
53
- exports.includeElementRef = includeElementRef;
54
- const excludeElementRef = (ctx, expr) => {
55
- const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
56
- const elementsIds = elements.map(e => e.id);
57
- const relations = [...ctx.relations].filter(r => elementsIds.includes(r.source) || elementsIds.includes(r.target));
58
- return ctx.exclude({
59
- elements,
60
- relations
61
- });
62
- };
63
- exports.excludeElementRef = excludeElementRef;
64
- const asElementPredicate = expr => {
65
- if (expr.isEqual) {
66
- if (_types.Expr.isElementKindExpr(expr)) {
67
- return e => e.kind === expr.elementKind;
68
- } else {
69
- return ({
70
- tags
71
- }) => !!tags && tags.includes(expr.elementTag);
72
- }
73
- } else {
74
- if (_types.Expr.isElementKindExpr(expr)) {
75
- return e => e.kind !== expr.elementKind;
76
- } else {
77
- return ({
78
- tags
79
- }) => (0, _rambdax.isNil)(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
80
- }
81
- }
82
- };
83
- const includeElementKindOrTag = (ctx, expr) => {
84
- const elements = ctx.index.elements.filter(asElementPredicate(expr));
85
- return elements.reduce((accCtx, el) => includeElementRef(accCtx, {
86
- element: el.id,
87
- isDescedants: false
88
- }), ctx);
89
- };
90
- exports.includeElementKindOrTag = includeElementKindOrTag;
91
- const excludeElementKindOrTag = (ctx, expr) => {
92
- const predicate = asElementPredicate(expr);
93
- const elements = [...ctx.elements].filter(predicate);
94
- const implicits = [...ctx.implicits].filter(predicate);
95
- return ctx.exclude({
96
- elements,
97
- implicits
98
- });
99
- };
100
- exports.excludeElementKindOrTag = excludeElementKindOrTag;
101
- const includeWildcardRef = (ctx, _expr) => {
102
- const {
103
- root
104
- } = ctx;
105
- if (root) {
106
- const elements = [ctx.index.find(root), ...ctx.index.children(root)];
107
- const allImplicits = [...ctx.index.siblings(root), ...ctx.index.ancestors(root).flatMap(a => [...ctx.index.siblings(a.id)])];
108
- const inOut = ctx.index.filterRelations(isAnyInOut(root));
109
- const implicits = [];
110
- for (const implicit of allImplicits) {
111
- if (inOut.some(isAnyInOut(implicit.id))) {
112
- implicits.push(implicit);
113
- }
114
- }
115
- return ctx.include({
116
- elements,
117
- relations: [...ctx.index.filterRelations(isInside(root)), ...inOut],
118
- implicits
119
- });
120
- } else {
121
- const elements = ctx.index.rootElements();
122
- if (elements.length <= 1) {
123
- return new _computeCtx.ComputeCtx(ctx.index, ctx.root, new Set(elements));
124
- }
125
- const relations = ctx.index.filterRelations(rel => (0, _rambdax.isNil)((0, _utils.commonAncestor)(rel.source, rel.target)));
126
- return ctx.include({
127
- elements,
128
- relations
129
- });
130
- }
131
- };
132
- exports.includeWildcardRef = includeWildcardRef;
133
- const excludeWildcardRef = (ctx, _expr) => {
134
- const {
135
- root
136
- } = ctx;
137
- if (root) {
138
- const relations = [...ctx.relations].filter((0, _rambdax.either)(isInside(root), isAnyInOut(root)));
139
- return ctx.exclude({
140
- elements: [...ctx.elements].filter(e => e.id === root || (0, _utils.isAncestor)(root, e.id)),
141
- relations,
142
- implicits: [...ctx.implicits].filter(e => relations.some(isAnyInOut(e.id)))
143
- });
144
- } else {
145
- return new _computeCtx.ComputeCtx(ctx.index, ctx.root);
146
- }
147
- };
148
- exports.excludeWildcardRef = excludeWildcardRef;
149
- const resolveElements = (ctx, expr) => {
150
- if (_types.Expr.isWildcard(expr)) {
151
- if (ctx.root) {
152
- return [ctx.index.find(ctx.root)];
153
- } else {
154
- return ctx.index.rootElements();
155
- }
156
- }
157
- if (_types.Expr.isElementKindExpr(expr)) {
158
- return ctx.index.elements.filter(el => {
159
- if (expr.isEqual) {
160
- return el.kind === expr.elementKind;
161
- }
162
- return el.kind !== expr.elementKind;
163
- });
164
- }
165
- if (_types.Expr.isElementTagExpr(expr)) {
166
- return ctx.index.elements.filter(el => {
167
- const tags = el.tags;
168
- if (expr.isEqual) {
169
- return !!tags && tags.includes(expr.elementTag);
170
- }
171
- return (0, _rambdax.isNil)(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
172
- });
173
- }
174
- if (expr.isDescedants) {
175
- return ctx.index.children(expr.element);
176
- } else {
177
- return [ctx.index.find(expr.element)];
178
- }
179
- };
180
- const includeIncomingExpr = (ctx, expr) => {
181
- if (_types.Expr.isWildcard(expr.incoming) && !ctx.root) {
182
- return ctx;
183
- }
184
- const elements = resolveElements(ctx, expr.incoming);
185
- if (elements.length === 0) {
186
- return ctx;
187
- }
188
- let allrelations = ctx.index.relations;
189
- if (_types.Expr.isElementRef(expr.incoming)) {
190
- allrelations = allrelations.filter(isIncoming(expr.incoming.element));
191
- }
192
- const implicits = [];
193
- const relations = [];
194
- for (const el of elements) {
195
- const elRelations = allrelations.filter(isIncoming(el.id));
196
- if (elRelations.length > 0) {
197
- relations.push(...elRelations);
198
- implicits.push(el);
199
- }
200
- }
201
- return ctx.include({
202
- relations,
203
- implicits
204
- });
205
- };
206
- exports.includeIncomingExpr = includeIncomingExpr;
207
- const excludeIncomingExpr = (ctx, expr) => {
208
- if (_types.Expr.isWildcard(expr.incoming) && !ctx.root) {
209
- return ctx;
210
- }
211
- const elements = resolveElements(ctx, expr.incoming);
212
- if (elements.length === 0) {
213
- return ctx;
214
- }
215
- const isIncomings = (0, _rambdax.anyPass)(elements.map(el => isIncoming(el.id)));
216
- const excluded = [...ctx.relations].filter(isIncomings);
217
- if (excluded.length > 0) {
218
- return ctx.exclude({
219
- relations: excluded
220
- });
221
- }
222
- return ctx;
223
- };
224
- exports.excludeIncomingExpr = excludeIncomingExpr;
225
- const includeOutgoingExpr = (ctx, expr) => {
226
- if (_types.Expr.isWildcard(expr.outgoing) && !ctx.root) {
227
- return ctx;
228
- }
229
- const elements = resolveElements(ctx, expr.outgoing);
230
- if (elements.length === 0) {
231
- return ctx;
232
- }
233
- let allrelations = ctx.index.relations;
234
- if (_types.Expr.isElementRef(expr.outgoing)) {
235
- allrelations = allrelations.filter(isOutgoing(expr.outgoing.element));
236
- }
237
- const implicits = [];
238
- const relations = [];
239
- for (const el of elements) {
240
- const elRelations = allrelations.filter(isOutgoing(el.id));
241
- if (elRelations.length > 0) {
242
- relations.push(...elRelations);
243
- implicits.push(el);
244
- }
245
- }
246
- return ctx.include({
247
- relations,
248
- implicits
249
- });
250
- };
251
- exports.includeOutgoingExpr = includeOutgoingExpr;
252
- const excludeOutgoingExpr = (ctx, expr) => {
253
- if (_types.Expr.isWildcard(expr.outgoing) && !ctx.root) {
254
- return ctx;
255
- }
256
- const elements = resolveElements(ctx, expr.outgoing);
257
- if (elements.length === 0) {
258
- return ctx;
259
- }
260
- const isOutgoings = (0, _rambdax.anyPass)(elements.map(el => isOutgoing(el.id)));
261
- const excluded = [...ctx.relations].filter(isOutgoings);
262
- if (excluded.length > 0) {
263
- return ctx.exclude({
264
- relations: excluded
265
- });
266
- }
267
- return ctx;
268
- };
269
- exports.excludeOutgoingExpr = excludeOutgoingExpr;
270
- const includeInOutExpr = (ctx, expr) => {
271
- if (_types.Expr.isWildcard(expr.inout) && !ctx.root) {
272
- return ctx;
273
- }
274
- const targets = resolveElements(ctx, expr.inout);
275
- if (targets.length === 0) {
276
- return ctx;
277
- }
278
- let allrelations = ctx.index.relations;
279
- if (_types.Expr.isElementRef(expr.inout)) {
280
- allrelations = allrelations.filter(isAnyInOut(expr.inout.element));
281
- }
282
- const implicits = [];
283
- const relations = [];
284
- for (const target of targets) {
285
- const foundRelations = allrelations.filter(isAnyInOut(target.id));
286
- if (foundRelations.length > 0) {
287
- relations.push(...foundRelations);
288
- implicits.push(target);
289
- }
290
- }
291
- return ctx.include({
292
- relations,
293
- implicits
294
- });
295
- };
296
- exports.includeInOutExpr = includeInOutExpr;
297
- const excludeInOutExpr = (ctx, expr) => {
298
- if (_types.Expr.isWildcard(expr.inout) && !ctx.root) {
299
- return ctx;
300
- }
301
- const targets = resolveElements(ctx, expr.inout);
302
- if (targets.length === 0) {
303
- return ctx;
304
- }
305
- const excluded = [...ctx.relations].filter((0, _rambdax.anyPass)(targets.map(t => isAnyInOut(t.id))));
306
- if (excluded.length > 0) {
307
- return ctx.exclude({
308
- relations: excluded
309
- });
310
- }
311
- return ctx;
312
- };
313
- exports.excludeInOutExpr = excludeInOutExpr;
314
- const includeRelationExpr = (ctx, expr) => {
315
- const sources = resolveElements(ctx, expr.source);
316
- const targets = resolveElements(ctx, expr.target);
317
- if (sources.length === 0 || targets.length === 0) {
318
- return ctx;
319
- }
320
- const implicits = [];
321
- const relations = [];
322
- for (const source of sources) {
323
- for (const target of targets) {
324
- if ((0, _utils.isSameHierarchy)(source, target)) {
325
- continue;
326
- }
327
- const foundRelations = ctx.index.filterRelations(isBetween(source.id, target.id));
328
- if (foundRelations.length > 0) {
329
- relations.push(...foundRelations);
330
- implicits.push(source, target);
331
- }
332
- }
333
- }
334
- return ctx.include({
335
- relations,
336
- implicits
337
- });
338
- };
339
- exports.includeRelationExpr = includeRelationExpr;
340
- const excludeRelationExpr = (ctx, expr) => {
341
- const sources = resolveElements(ctx, expr.source);
342
- const targets = resolveElements(ctx, expr.target);
343
- const filters = [];
344
- for (const source of sources) {
345
- for (const target of targets) {
346
- if ((0, _utils.isSameHierarchy)(source, target)) {
347
- continue;
348
- }
349
- filters.push(isBetween(source.id, target.id));
350
- }
351
- }
352
- if (filters.length == 0) {
353
- return ctx;
354
- }
355
- const excluded = [...ctx.relations].filter((0, _rambdax.anyPass)(filters));
356
- if (excluded.length == 0) {
357
- return ctx;
358
- }
359
- return ctx.exclude({
360
- relations: excluded
361
- });
362
- };
363
- exports.excludeRelationExpr = excludeRelationExpr;
@@ -1,16 +0,0 @@
1
- import { Expr } from '../types';
2
- import { ComputeCtx } from './compute-ctx';
3
- export declare const includeElementRef: (ctx: ComputeCtx, expr: Expr.ElementRefExpr) => ComputeCtx;
4
- export declare const excludeElementRef: (ctx: ComputeCtx, expr: Expr.ElementRefExpr) => ComputeCtx;
5
- export declare const includeElementKindOrTag: (ctx: ComputeCtx, expr: Expr.ElementKindExpr | Expr.ElementTagExpr) => ComputeCtx;
6
- export declare const excludeElementKindOrTag: (ctx: ComputeCtx, expr: Expr.ElementKindExpr | Expr.ElementTagExpr) => ComputeCtx;
7
- export declare const includeWildcardRef: (ctx: ComputeCtx, _expr: Expr.WildcardExpr) => ComputeCtx;
8
- export declare const excludeWildcardRef: (ctx: ComputeCtx, _expr: Expr.WildcardExpr) => ComputeCtx;
9
- export declare const includeIncomingExpr: (ctx: ComputeCtx, expr: Expr.IncomingExpr) => ComputeCtx;
10
- export declare const excludeIncomingExpr: (ctx: ComputeCtx, expr: Expr.IncomingExpr) => ComputeCtx;
11
- export declare const includeOutgoingExpr: (ctx: ComputeCtx, expr: Expr.OutgoingExpr) => ComputeCtx;
12
- export declare const excludeOutgoingExpr: (ctx: ComputeCtx, expr: Expr.OutgoingExpr) => ComputeCtx;
13
- export declare const includeInOutExpr: (ctx: ComputeCtx, expr: Expr.InOutExpr) => ComputeCtx;
14
- export declare const excludeInOutExpr: (ctx: ComputeCtx, expr: Expr.InOutExpr) => ComputeCtx;
15
- export declare const includeRelationExpr: (ctx: ComputeCtx, expr: Expr.RelationExpr) => ComputeCtx;
16
- export declare const excludeRelationExpr: (ctx: ComputeCtx, expr: Expr.RelationExpr) => ComputeCtx;
@@ -1,324 +0,0 @@
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) => {
7
- const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
8
- const filters = [];
9
- if (expr.isDescedants) {
10
- elements.forEach((child) => {
11
- filters.push(both(isInside(expr.element), isAnyInOut(child.id)));
12
- });
13
- }
14
- const ctxElements = uniq([...ctx.elements, ...ctx.implicits]);
15
- const excludeImplicits = [];
16
- for (const el of elements) {
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)));
19
- }
20
- for (const ctxEl of ctxElements) {
21
- if (!isSameHierarchy(el, ctxEl)) {
22
- filters.push(isAnyBetween(el.id, ctxEl.id));
23
- }
24
- }
25
- }
26
- const relations = filters.length ? ctx.index.filterRelations(anyPass(filters)) : [];
27
- if (excludeImplicits.length == 0) {
28
- return ctx.include({ elements, relations });
29
- }
30
- return ctx.include({ elements, relations }).exclude({ implicits: excludeImplicits });
31
- };
32
- export const excludeElementRef = (ctx, expr) => {
33
- const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
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 });
39
- };
40
- const asElementPredicate = (expr) => {
41
- if (expr.isEqual) {
42
- if (Expr.isElementKindExpr(expr)) {
43
- return (e) => e.kind === expr.elementKind;
44
- } else {
45
- return ({ tags }) => !!tags && tags.includes(expr.elementTag);
46
- }
47
- } else {
48
- if (Expr.isElementKindExpr(expr)) {
49
- return (e) => e.kind !== expr.elementKind;
50
- } else {
51
- return ({ tags }) => isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
52
- }
53
- }
54
- };
55
- export const includeElementKindOrTag = (ctx, expr) => {
56
- const elements = ctx.index.elements.filter(asElementPredicate(expr));
57
- return elements.reduce(
58
- (accCtx, el) => includeElementRef(accCtx, {
59
- element: el.id,
60
- isDescedants: false
61
- }),
62
- ctx
63
- );
64
- };
65
- export const excludeElementKindOrTag = (ctx, expr) => {
66
- const predicate = asElementPredicate(expr);
67
- const elements = [...ctx.elements].filter(predicate);
68
- const implicits = [...ctx.implicits].filter(predicate);
69
- return ctx.exclude({ elements, implicits });
70
- };
71
- export const includeWildcardRef = (ctx, _expr) => {
72
- const { root } = ctx;
73
- if (root) {
74
- const elements = [ctx.index.find(root), ...ctx.index.children(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));
80
- const implicits = [];
81
- for (const implicit of allImplicits) {
82
- if (inOut.some(isAnyInOut(implicit.id))) {
83
- implicits.push(implicit);
84
- }
85
- }
86
- return ctx.include({
87
- elements,
88
- relations: [...ctx.index.filterRelations(isInside(root)), ...inOut],
89
- implicits
90
- });
91
- } else {
92
- const elements = ctx.index.rootElements();
93
- if (elements.length <= 1) {
94
- return new ComputeCtx(ctx.index, ctx.root, new Set(elements));
95
- }
96
- const relations = ctx.index.filterRelations(
97
- (rel) => isNil(commonAncestor(rel.source, rel.target))
98
- );
99
- return ctx.include({
100
- elements,
101
- relations
102
- });
103
- }
104
- };
105
- export const excludeWildcardRef = (ctx, _expr) => {
106
- const { root } = ctx;
107
- if (root) {
108
- const relations = [...ctx.relations].filter(either(isInside(root), isAnyInOut(root)));
109
- return ctx.exclude({
110
- elements: [...ctx.elements].filter((e) => e.id === root || isAncestor(root, e.id)),
111
- relations,
112
- implicits: [...ctx.implicits].filter((e) => relations.some(isAnyInOut(e.id)))
113
- });
114
- } else {
115
- return new ComputeCtx(ctx.index, ctx.root);
116
- }
117
- };
118
- const resolveElements = (ctx, expr) => {
119
- if (Expr.isWildcard(expr)) {
120
- if (ctx.root) {
121
- return [ctx.index.find(ctx.root)];
122
- } else {
123
- return ctx.index.rootElements();
124
- }
125
- }
126
- if (Expr.isElementKindExpr(expr)) {
127
- return ctx.index.elements.filter((el) => {
128
- if (expr.isEqual) {
129
- return el.kind === expr.elementKind;
130
- }
131
- return el.kind !== expr.elementKind;
132
- });
133
- }
134
- if (Expr.isElementTagExpr(expr)) {
135
- return ctx.index.elements.filter((el) => {
136
- const tags = el.tags;
137
- if (expr.isEqual) {
138
- return !!tags && tags.includes(expr.elementTag);
139
- }
140
- return isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
141
- });
142
- }
143
- if (expr.isDescedants) {
144
- return ctx.index.children(expr.element);
145
- } else {
146
- return [ctx.index.find(expr.element)];
147
- }
148
- };
149
- export const includeIncomingExpr = (ctx, expr) => {
150
- if (Expr.isWildcard(expr.incoming) && !ctx.root) {
151
- return ctx;
152
- }
153
- const elements = resolveElements(ctx, expr.incoming);
154
- if (elements.length === 0) {
155
- return ctx;
156
- }
157
- let allrelations = ctx.index.relations;
158
- if (Expr.isElementRef(expr.incoming)) {
159
- allrelations = allrelations.filter(isIncoming(expr.incoming.element));
160
- }
161
- const implicits = [];
162
- const relations = [];
163
- for (const el of elements) {
164
- const elRelations = allrelations.filter(isIncoming(el.id));
165
- if (elRelations.length > 0) {
166
- relations.push(...elRelations);
167
- implicits.push(el);
168
- }
169
- }
170
- return ctx.include({
171
- relations,
172
- implicits
173
- });
174
- };
175
- export const excludeIncomingExpr = (ctx, expr) => {
176
- if (Expr.isWildcard(expr.incoming) && !ctx.root) {
177
- return ctx;
178
- }
179
- const elements = resolveElements(ctx, expr.incoming);
180
- if (elements.length === 0) {
181
- return ctx;
182
- }
183
- const isIncomings = anyPass(elements.map((el) => isIncoming(el.id)));
184
- const excluded = [...ctx.relations].filter(isIncomings);
185
- if (excluded.length > 0) {
186
- return ctx.exclude({
187
- relations: excluded
188
- });
189
- }
190
- return ctx;
191
- };
192
- export const includeOutgoingExpr = (ctx, expr) => {
193
- if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
194
- return ctx;
195
- }
196
- const elements = resolveElements(ctx, expr.outgoing);
197
- if (elements.length === 0) {
198
- return ctx;
199
- }
200
- let allrelations = ctx.index.relations;
201
- if (Expr.isElementRef(expr.outgoing)) {
202
- allrelations = allrelations.filter(isOutgoing(expr.outgoing.element));
203
- }
204
- const implicits = [];
205
- const relations = [];
206
- for (const el of elements) {
207
- const elRelations = allrelations.filter(isOutgoing(el.id));
208
- if (elRelations.length > 0) {
209
- relations.push(...elRelations);
210
- implicits.push(el);
211
- }
212
- }
213
- return ctx.include({
214
- relations,
215
- implicits
216
- });
217
- };
218
- export const excludeOutgoingExpr = (ctx, expr) => {
219
- if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
220
- return ctx;
221
- }
222
- const elements = resolveElements(ctx, expr.outgoing);
223
- if (elements.length === 0) {
224
- return ctx;
225
- }
226
- const isOutgoings = anyPass(elements.map((el) => isOutgoing(el.id)));
227
- const excluded = [...ctx.relations].filter(isOutgoings);
228
- if (excluded.length > 0) {
229
- return ctx.exclude({
230
- relations: excluded
231
- });
232
- }
233
- return ctx;
234
- };
235
- export const includeInOutExpr = (ctx, expr) => {
236
- if (Expr.isWildcard(expr.inout) && !ctx.root) {
237
- return ctx;
238
- }
239
- const targets = resolveElements(ctx, expr.inout);
240
- if (targets.length === 0) {
241
- return ctx;
242
- }
243
- let allrelations = ctx.index.relations;
244
- if (Expr.isElementRef(expr.inout)) {
245
- allrelations = allrelations.filter(isAnyInOut(expr.inout.element));
246
- }
247
- const implicits = [];
248
- const relations = [];
249
- for (const target of targets) {
250
- const foundRelations = allrelations.filter(isAnyInOut(target.id));
251
- if (foundRelations.length > 0) {
252
- relations.push(...foundRelations);
253
- implicits.push(target);
254
- }
255
- }
256
- return ctx.include({
257
- relations,
258
- implicits
259
- });
260
- };
261
- export const excludeInOutExpr = (ctx, expr) => {
262
- if (Expr.isWildcard(expr.inout) && !ctx.root) {
263
- return ctx;
264
- }
265
- const targets = resolveElements(ctx, expr.inout);
266
- if (targets.length === 0) {
267
- return ctx;
268
- }
269
- const excluded = [...ctx.relations].filter(anyPass(targets.map((t) => isAnyInOut(t.id))));
270
- if (excluded.length > 0) {
271
- return ctx.exclude({
272
- relations: excluded
273
- });
274
- }
275
- return ctx;
276
- };
277
- export const includeRelationExpr = (ctx, expr) => {
278
- const sources = resolveElements(ctx, expr.source);
279
- const targets = resolveElements(ctx, expr.target);
280
- if (sources.length === 0 || targets.length === 0) {
281
- return ctx;
282
- }
283
- const implicits = [];
284
- const relations = [];
285
- for (const source of sources) {
286
- for (const target of targets) {
287
- if (isSameHierarchy(source, target)) {
288
- continue;
289
- }
290
- const foundRelations = ctx.index.filterRelations(isBetween(source.id, target.id));
291
- if (foundRelations.length > 0) {
292
- relations.push(...foundRelations);
293
- implicits.push(source, target);
294
- }
295
- }
296
- }
297
- return ctx.include({
298
- relations,
299
- implicits
300
- });
301
- };
302
- export const excludeRelationExpr = (ctx, expr) => {
303
- const sources = resolveElements(ctx, expr.source);
304
- const targets = resolveElements(ctx, expr.target);
305
- const filters = [];
306
- for (const source of sources) {
307
- for (const target of targets) {
308
- if (isSameHierarchy(source, target)) {
309
- continue;
310
- }
311
- filters.push(isBetween(source.id, target.id));
312
- }
313
- }
314
- if (filters.length == 0) {
315
- return ctx;
316
- }
317
- const excluded = [...ctx.relations].filter(anyPass(filters));
318
- if (excluded.length == 0) {
319
- return ctx;
320
- }
321
- return ctx.exclude({
322
- relations: excluded
323
- });
324
- };