Skip to content

Commit a110cf7

Browse files
committed
Добавлены опции group.by и group.except
1 parent 770f4f8 commit a110cf7

5 files changed

Lines changed: 70 additions & 32 deletions

File tree

src/new_links_format/README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ links:
2626
- orders.gateway
2727
title: Передача заказа
2828
```
29+
30+
Также улучшена поддержка контекстов, добавлены свойства group.by и group.except. С помощью этих свойств можно несколько компонентов низкого уровня объеденить в один компонент более выского. Очень хорошо может помочь при рендеринге больших схем. В примере ниже компоненты orders.db, orders.backend будут отображены на схеме как один компонент orders. Внутри этого компонента отдельно будет отрисован компонент orders.gateway, т.к. он был исключен из группировки с помощью свойства except.
31+
32+
```yaml
33+
contexts:
34+
L2:
35+
title: L2 уровень
36+
location: L2
37+
components:
38+
- customer.*
39+
- payments.*
40+
- front.*
41+
group:
42+
by:
43+
- orders
44+
except:
45+
- orders.gateway
46+
47+
```
2948
Обязательными являются только параметры from/to. Новый параметр via позволяет отметить шлюзы, через которые работает связь между компонентами.
3049

3150
# Особенности
@@ -34,12 +53,13 @@ links:
3453
3. В SELF контексте компонента будут отображены все связи, которые у него существуют. Неважно при этом где они описаны. Также будут показаны связи, которые проходят через шлюзы.
3554
4. Все связи всплывают наверх, если вы используете модель DDD, при всплытии также происходит группировка.
3655
5. Работает ТОЛЬКО с plantUML представлением.
37-
6. Корректно работает в случае указания элемнтов разного уровня на контекстной диаграмме. При этом прозводительность упадет.
56+
6. Реализована возможнсть упрощать схему с помощью объединения компонентов низкого уровня в один компонент уровнем выше.
57+
7. Корректно работает в случае указания элемнтов разного уровня на контекстной диаграмме. При этом прозводительность упадет.
3858

3959
# Подключение:
4060
1. Заменить файлы, находящиеся в папке metamodel/dochub/entities/contexts на файлы в соотвествующей папке из примера.
4161
2. Использовать converter.json, которые сделает первичную конвертацию из формата старых ссылок в новый формат.
4262
3. Подключить файлы entities/links.yaml и datasets/links.yaml в архитектуру
43-
4. Добавить полученные данные в свойство "links:"
63+
4. Подключить файл с новыми данными.
4464
5. Старые связи можно не удалять
4565

src/new_links_format/converter.jsonata

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
}
1818
)
1919
);
20-
$links{from & "-" & to:{
20+
{"links": $links{from & "-" & to:{
2121
"from": from,
2222
"to": to,
2323
"title": title,
2424
"contract": contract
25-
}}
25+
}}}
2626
)

src/new_links_format/example.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,18 @@ contexts:
132132
title: L2 уровень
133133
location: L2
134134
components:
135-
- "*.*" # Отбираем все компоненты второго уровня
135+
- customer.*
136+
- payments.*
137+
- front.*
138+
group:
139+
by:
140+
- orders
141+
except:
142+
- orders.gateway
136143
L1:
137144
title: L1 уровень
138145
location: L1
139146
components:
140147
- front
141148
- auth
142-
- orders
143149
- payments

src/new_links_format/metamodel/dochub/entities/contexts/base.yaml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ entities:
126126
? [$params.componentId]
127127
/* Если нет берем все компоненты указанные в контексте */
128128
: $context.components;
129-
129+
130130
/* Если в контексте переопределена функция получения компонентов, используем ее*/
131131
$r := $context.api.fetchComponents ? (
132132
$eval($context.api.fetchComponents, $params)
@@ -158,29 +158,16 @@ entities:
158158
))^($);
159159
)
160160
161-
oldFormToNew: >
162-
(
163-
$.components.$spread().(
164-
$from := $keys();
165-
$l := *.$;
166-
$l.links.(
167-
$f := direction = "<--" or direction = "<-" or direction = "<---" or direction = "<-----" ? id : $from;
168-
$t := $f = id ? $from : id;
169-
{"from": $f, "to":$t, "contract":$.contract, "title": $.title, "direction": "-->"}
170-
)
171-
)
172-
)
173-
174161
# Генерирует список отображаемых связей
175162
# Входящие параметры:
176163
# components - список компонентов в формате fetchComponents
177164
# links - список ссылок
178165
# required - список компонентов, явно добавленных в контекст
179166
fetchComponentsFromLinks: >
180167
(
181-
$requiredComponents := required;
182-
$components := components;
183-
$links := links;
168+
$requiredComponents := $.required;
169+
$components := $.components;
170+
$links := $.links;
184171
$neededComponents := $distinct($append($links.from, $links.to) ~> $append($requiredComponents.$keys()));
185172
$neededComponents.(
186173
$id := $;
@@ -189,8 +176,9 @@ entities:
189176
"entity": entity,
190177
"aspects": aspects
191178
}};
192-
)
179+
);
193180
)
181+
# нужно сделать правило, которые бы выводило ссылки с отствующим from или to, чтобы разбирать причины появления таких ссылок
194182
fetchLinks: >
195183
(
196184
$manifest := manifest;
@@ -213,7 +201,7 @@ entities:
213201
"title": *.title,
214202
"via": *.via,
215203
"contract": *.contract
216-
};
204+
}[from != ""];
217205
218206
$c := $components.$spread().$keys().{"key":$};
219207
@@ -306,14 +294,35 @@ entities:
306294
"contract": $contract,
307295
"title": $title
308296
}
309-
)][from != to];
297+
)];
298+
299+
$groupExternal := $.groups;
300+
$except := $.exceptGroups;
301+
302+
$s := $distinct($mainRes.(
303+
[to, from]
304+
));
305+
$grouped := $groupExternal.(
306+
$e := $;
307+
$s.(
308+
$r := $contains($, $e) and $not($ in $except);
309+
$r ? {"group": $e, "element":$, "is":$r}
310+
)
311+
);
312+
313+
$result := $mainRes.(
314+
$data := $;
315+
$from := $grouped[element = $data.from] ? $grouped[element = $data.from].group : $data.from;
316+
$to := $grouped[element = $data.to] ? $grouped[element = $data.to].group : $data.to;
317+
$merge([$data, {"from": $from, "to":$to}])
318+
);
310319
311320
$getMatched := function($array){(
312321
$v1 := ($array)[0];
313322
$sv1 := $split($v1, ".");
314323
$cnt := $count($sv1);
315324
$rf := $array;
316-
325+
317326
$rfr := $sv1#$i.(
318327
$matcher := $join($split($v1, ".", $cnt-$i),".");
319328
$res := $count([$filter($rf, function($v){
@@ -331,7 +340,7 @@ entities:
331340
$q;
332341
)};
333342
334-
$r:=$mainRes{from & "-" & to: (
343+
$r:=$result{from & "-" & to: (
335344
$lFrom := $getMatched(realFrom);
336345
$lTo := $getMatched(realTo);
337346
$values := $count(from);
@@ -340,7 +349,7 @@ entities:
340349
$to := (to)[0];
341350
$title := $values > 1 ? (
342351
$r:=$domainLevel ? $split($to,".", $domainLevel) ~> $join(".") : ($services[$to in list])[0];
343-
(fromServiceName)[0] & " -> " & ($lookup($components, $r).title)[0] & " (" & $cnt & ")"
352+
($lFrom != "" ? (fromServiceName)[0] : "*") & " -> " & ($lookup($components, $r).title)[0] & " (" & $cnt & ")"
344353
) : title;
345354
{
346355
"from":(from)[0],

src/new_links_format/metamodel/dochub/entities/contexts/plantuml.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ entities:
2020
$manifest := manifest;
2121
2222
$stopBracketsCount := function($a, $b) {$a = 0 ? "}\n" : $a & "}\n"};
23-
23+
2424
$join($map($areas, function($domain, $index) {(
2525
$result := "";
2626
$component := $lookup($components, $domain);
@@ -158,6 +158,8 @@ entities:
158158
$manifest := _source ? _source : $;
159159
160160
$isExtraLinks := $not($string($context."extra-links") = "false");
161+
$groups := [$context.group.by];
162+
$exceptGroups := [$context.group.except];
161163
162164
/* Получаем коллекцию дефолтных вспомогательных функций */
163165
$defFunctions := $manifest.entities.contexts.api;
@@ -185,7 +187,9 @@ entities:
185187
$links := $eval($context.api.fetchLinks ? $context.api.fetchLinks : $defFunctions.fetchLinks, {
186188
"manifest": $manifest,
187189
"extraLinks": $isExtraLinks,
188-
"components": $components
190+
"components": $components,
191+
"groups": $groups,
192+
"exceptGroups": $exceptGroups
189193
});
190194
191195
$components := $eval($defFunctions.fetchComponentsFromLinks, {
@@ -206,7 +210,6 @@ entities:
206210
"components": $components
207211
});
208212
209-
210213
/* Генерируем код связей */
211214
$linksCode := $eval($defFunctions.makePumlComponentsLinks, {
212215
"links": $links

0 commit comments

Comments
 (0)