@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
@@ -0,0 +1,363 @@
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,4 +1,4 @@
1
- import * as Expr from '../types/expression';
1
+ import { Expr } from '../types';
2
2
  import { ComputeCtx } from './compute-ctx';
3
3
  export declare const includeElementRef: (ctx: ComputeCtx, expr: Expr.ElementRefExpr) => ComputeCtx;
4
4
  export declare const excludeElementRef: (ctx: ComputeCtx, expr: Expr.ElementRefExpr) => ComputeCtx;