@likec4/core 1.31.0 → 1.32.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.
- package/README.md +407 -5
- package/dist/builder/index.d.mts +221 -42
- package/dist/builder/index.mjs +118 -65
- package/dist/compute-view/index.d.mts +23 -7
- package/dist/compute-view/index.mjs +11 -6
- package/dist/compute-view/relationships-view/index.d.mts +9 -7
- package/dist/compute-view/relationships-view/index.mjs +3 -2
- package/dist/index.d.mts +10 -14
- package/dist/index.mjs +9 -6
- package/dist/model/index.d.mts +173 -19
- package/dist/model/index.mjs +6 -1
- package/dist/shared/core.BaYE_r29.d.mts +258 -0
- package/dist/shared/core.Bk7wEZFG.mjs +276 -0
- package/dist/shared/core.BrCnZFTn.mjs +32 -0
- package/dist/shared/core.BuO4ncfY.d.mts +146 -0
- package/dist/shared/{core.Bq753SYD.mjs → core.CBpKAlhj.mjs} +2012 -4422
- package/dist/shared/core.CCWXGc6G.d.mts +920 -0
- package/dist/shared/core.CUYDgv2-.mjs +214 -0
- package/dist/shared/{core.Cu-UdkSl.mjs → core.CpXlRyE5.mjs} +7 -494
- package/dist/shared/{core.C-YXI-43.mjs → core.Cy9smucx.mjs} +3 -1
- package/dist/shared/core.CywrQs86.d.mts +31 -0
- package/dist/shared/core.DoK86JEe.mjs +518 -0
- package/dist/shared/core.Dpq3P3YJ.d.mts +1265 -0
- package/dist/shared/{core.D2830qgg.d.mts → core.Pf5I9o0e.d.mts} +1 -1
- package/dist/shared/core.cbA9VZ02.mjs +2681 -0
- package/dist/shared/{core.CQXU9DF7.mjs → core.rmvsy0n3.mjs} +23 -32
- package/dist/types/aux.d.mts +3 -0
- package/dist/types/aux.mjs +1 -0
- package/dist/types/index.d.mts +7 -45
- package/dist/types/index.mjs +130 -3
- package/dist/utils/index.d.mts +221 -53
- package/dist/utils/index.mjs +14 -10
- package/package.json +15 -7
- package/src/builder/Builder.deploymentModel.ts +82 -18
- package/src/builder/Builder.element.ts +40 -20
- package/src/builder/Builder.model.ts +66 -17
- package/src/builder/Builder.ts +168 -76
- package/src/builder/Builder.view-common.ts +35 -17
- package/src/builder/Builder.view-deployment.ts +25 -25
- package/src/builder/Builder.view-element.ts +13 -12
- package/src/builder/Builder.views.ts +12 -7
- package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +62 -34
- package/src/builder/__snapshots__/Builder-style2.compute-model.json5 +319 -0
- package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +45 -24
- package/src/builder/_types.ts +34 -27
- package/src/compute-view/compute-view.ts +31 -34
- package/src/compute-view/deployment-view/__test__/TestHelper.ts +27 -14
- package/src/compute-view/deployment-view/__test__/fixture.ts +15 -13
- package/src/compute-view/deployment-view/_types.ts +10 -10
- package/src/compute-view/deployment-view/clean-connections.ts +5 -7
- package/src/compute-view/deployment-view/compute.ts +16 -13
- package/src/compute-view/deployment-view/memory/memory.ts +5 -6
- package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +4 -5
- package/src/compute-view/deployment-view/predicates/relation-direct.ts +25 -50
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +5 -7
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +7 -11
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +7 -10
- package/src/compute-view/deployment-view/predicates/utils.ts +37 -31
- package/src/compute-view/deployment-view/predicates/wildcard.ts +3 -2
- package/src/compute-view/deployment-view/stages/stage-final.ts +2 -2
- package/src/compute-view/deployment-view/stages/stage-include.ts +1 -1
- package/src/compute-view/deployment-view/utils.ts +79 -72
- package/src/compute-view/dynamic-view/__test__/fixture.ts +20 -11
- package/src/compute-view/dynamic-view/compute.ts +60 -53
- package/src/compute-view/element-view/__test__/TestHelper.ts +53 -29
- package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +26 -26
- package/src/compute-view/element-view/__test__/fixture.ts +134 -83
- package/src/compute-view/element-view/_types.ts +14 -19
- package/src/compute-view/element-view/clean-connections.ts +12 -8
- package/src/compute-view/element-view/compute.ts +61 -51
- package/src/compute-view/element-view/memory/NodeGroup.ts +8 -9
- package/src/compute-view/element-view/memory/memory.ts +22 -22
- package/src/compute-view/element-view/memory/stage-include.ts +5 -3
- package/src/compute-view/element-view/predicates/_utils.ts +18 -14
- package/src/compute-view/element-view/predicates/element-expand.ts +4 -5
- package/src/compute-view/element-view/predicates/element-kind-tag.ts +3 -4
- package/src/compute-view/element-view/predicates/element-ref.ts +3 -4
- package/src/compute-view/element-view/predicates/relation-direct.ts +16 -12
- package/src/compute-view/element-view/predicates/relation-in-out.ts +7 -8
- package/src/compute-view/element-view/predicates/relation-in.ts +19 -26
- package/src/compute-view/element-view/predicates/relation-out.ts +20 -21
- package/src/compute-view/element-view/predicates/wildcard.ts +3 -3
- package/src/compute-view/element-view/utils.ts +25 -23
- package/src/compute-view/index.ts +1 -1
- package/src/compute-view/memory/AbstractStageExclude.ts +3 -4
- package/src/compute-view/memory/AbstractStageInclude.ts +1 -1
- package/src/compute-view/memory/_types.ts +3 -2
- package/src/compute-view/relationships-view/_types.ts +3 -4
- package/src/compute-view/relationships-view/compute.ts +8 -11
- package/src/compute-view/relationships-view/layout.ts +6 -6
- package/src/compute-view/relationships-view/utils.ts +4 -4
- package/src/compute-view/utils/ancestorsOfNode.ts +7 -7
- package/src/compute-view/utils/applyCustomElementProperties.ts +16 -8
- package/src/compute-view/utils/applyCustomRelationProperties.ts +19 -9
- package/src/compute-view/utils/applyViewRuleStyles.ts +18 -10
- package/src/compute-view/utils/buildComputedNodes.ts +40 -40
- package/src/compute-view/utils/buildElementNotations.ts +14 -14
- package/src/compute-view/utils/elementExpressionToPredicate.ts +14 -15
- package/src/compute-view/utils/link-nodes-with-edges.ts +6 -4
- package/src/compute-view/utils/merge-props-from-relationships.ts +52 -20
- package/src/compute-view/utils/relationExpressionToPredicates.ts +19 -19
- package/src/compute-view/utils/resolve-extended-views.ts +8 -7
- package/src/compute-view/utils/resolve-global-rules.ts +31 -26
- package/src/compute-view/utils/topological-sort.ts +14 -14
- package/src/compute-view/utils/view-hash.ts +2 -2
- package/src/compute-view/utils/with-readable-edges.ts +9 -5
- package/src/index.ts +0 -32
- package/src/model/DeploymentElementModel.ts +171 -144
- package/src/model/DeploymentModel.ts +88 -65
- package/src/model/ElementModel.ts +85 -74
- package/src/model/LikeC4Model.ts +430 -241
- package/src/model/RelationModel.ts +63 -29
- package/src/model/__test__/fixture.ts +50 -36
- package/src/model/connection/Connection.ts +2 -2
- package/src/model/connection/deployment/DeploymentConnectionModel.ts +21 -24
- package/src/model/connection/deployment/find.ts +1 -1
- package/src/model/connection/model/ConnectionModel.ts +21 -20
- package/src/model/connection/model/find.ts +7 -7
- package/src/model/connection/ops.ts +6 -6
- package/src/model/guards.ts +66 -14
- package/src/model/index.ts +20 -7
- package/src/model/types.ts +41 -97
- package/src/model/view/EdgeModel.ts +47 -41
- package/src/model/view/LikeC4ViewModel.ts +130 -80
- package/src/model/view/NodeModel.ts +102 -96
- package/src/theme/element.ts +1 -1
- package/src/theme/index.ts +9 -9
- package/src/theme/relationships.ts +1 -1
- package/src/types/_common.ts +21 -15
- package/src/types/aux.ts +285 -0
- package/src/types/const.ts +34 -0
- package/src/types/expression-model.ts +292 -0
- package/src/types/expression.ts +311 -0
- package/src/types/fqnRef.ts +88 -0
- package/src/types/geometry.ts +131 -0
- package/src/types/global.ts +10 -8
- package/src/types/index.ts +39 -201
- package/src/types/model-data.ts +52 -84
- package/src/types/model-deployment.ts +87 -0
- package/src/types/model-dump.ts +72 -0
- package/src/types/model-logical.ts +111 -0
- package/src/types/model-spec.ts +81 -0
- package/src/types/operators.ts +51 -52
- package/src/types/scalar.ts +114 -0
- package/src/types/styles.ts +123 -0
- package/src/types/view-changes.ts +4 -5
- package/src/types/view-common.ts +157 -0
- package/src/types/view-computed.ts +113 -0
- package/src/types/view-layouted.ts +82 -0
- package/src/types/view-parsed.deployment.ts +40 -0
- package/src/types/view-parsed.dynamic.ts +78 -0
- package/src/types/view-parsed.element.ts +65 -0
- package/src/types/view.ts +122 -542
- package/src/utils/compare-natural.ts +43 -1
- package/src/utils/getOrCreate.ts +0 -34
- package/src/utils/index.ts +7 -12
- package/src/utils/iterable/filter.ts +1 -1
- package/src/utils/iterable/find.ts +3 -1
- package/src/utils/iterable/head.ts +22 -0
- package/src/utils/iterable/index.ts +1 -0
- package/src/utils/iterable/map.ts +1 -1
- package/src/utils/iterable/reduce.ts +1 -1
- package/src/utils/iterable/some.ts +1 -1
- package/src/utils/memoize-prop.ts +30 -0
- package/src/utils/object-hash.ts +1 -1
- package/src/utils/relations.ts +14 -11
- package/src/utils/string-hash.ts +1 -1
- package/dist/shared/core.CQDU11hR.d.mts +0 -753
- package/dist/shared/core.DJvmfnEi.d.mts +0 -1153
- package/dist/shared/core.DgfwjBtu.mjs +0 -495
- package/dist/shared/core.Dx7siloV.d.mts +0 -146
- package/dist/shared/core.SjLhMA7a.d.mts +0 -62
- package/src/builder/__snapshots__/Builder.spec.ts.snap +0 -374
- package/src/compute-view/element-view/predicates.ts +0 -520
- package/src/compute-view/utils/uniqueTags.ts +0 -21
- package/src/types/deployments.ts +0 -170
- package/src/types/element.ts +0 -109
- package/src/types/expression-v2-model.ts +0 -314
- package/src/types/expression-v2.ts +0 -392
- package/src/types/overview-graph.ts +0 -43
- package/src/types/relation.ts +0 -61
- package/src/types/scalars.ts +0 -39
- package/src/types/theme.ts +0 -82
- package/src/types/view-notation.ts +0 -9
- package/src/utils/graphlib.ts +0 -10
- /package/src/{errors/index.ts → utils/invariant.ts} +0 -0
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
import { indexBy, isString, map, prop } from 'remeda'
|
|
2
2
|
import { LikeC4Model } from '../../../model'
|
|
3
3
|
import {
|
|
4
|
+
type Aux,
|
|
5
|
+
type aux,
|
|
4
6
|
type BorderStyle,
|
|
5
7
|
type Color,
|
|
6
|
-
type
|
|
8
|
+
type ComputedElementView,
|
|
7
9
|
type Element,
|
|
8
|
-
type ElementKind,
|
|
9
10
|
type ElementShape,
|
|
11
|
+
type ElementViewPredicate,
|
|
12
|
+
type ElementViewPredicate as ViewRulePredicate,
|
|
13
|
+
type ElementViewRule,
|
|
14
|
+
type ElementViewRule as ViewRule,
|
|
15
|
+
type ElementViewRuleGroup as ViewRuleGroup,
|
|
16
|
+
type ElementViewRuleStyle as ViewRuleStyle,
|
|
10
17
|
type Fqn,
|
|
11
18
|
type GlobalPredicateId,
|
|
12
19
|
type GlobalStyleID,
|
|
13
20
|
type IconUrl,
|
|
14
21
|
type KindEqual,
|
|
22
|
+
type ModelExpression,
|
|
15
23
|
type ModelRelation,
|
|
16
24
|
type NonEmptyArray,
|
|
25
|
+
type ParsedElementView,
|
|
17
26
|
type RelationId,
|
|
18
27
|
type RelationshipArrowType,
|
|
19
28
|
type RelationshipLineType,
|
|
20
|
-
type
|
|
29
|
+
type scalar,
|
|
30
|
+
type SpecAux,
|
|
21
31
|
type TagEqual,
|
|
22
|
-
type ViewId,
|
|
23
|
-
type ViewRule,
|
|
24
32
|
type ViewRuleGlobalPredicateRef,
|
|
25
33
|
type ViewRuleGlobalStyle,
|
|
26
|
-
type ViewRuleGroup,
|
|
27
|
-
type ViewRulePredicate,
|
|
28
|
-
type ViewRuleStyle,
|
|
29
34
|
type WhereOperator,
|
|
30
|
-
|
|
35
|
+
ModelFqnExpr,
|
|
36
|
+
ModelRelationExpr,
|
|
31
37
|
} from '../../../types'
|
|
32
38
|
import type { Participant } from '../../../types/operators'
|
|
33
39
|
import { withReadableEdges } from '../../utils/with-readable-edges'
|
|
@@ -127,12 +133,12 @@ const el = ({
|
|
|
127
133
|
kind: string
|
|
128
134
|
tags?: NonEmptyArray<TestTag>
|
|
129
135
|
}): Element => ({
|
|
130
|
-
id: id as Fqn,
|
|
131
|
-
kind: kind as ElementKind,
|
|
136
|
+
id: id as scalar.Fqn,
|
|
137
|
+
kind: kind as scalar.ElementKind,
|
|
132
138
|
title: title ?? id,
|
|
133
139
|
description: null,
|
|
134
140
|
technology: null,
|
|
135
|
-
tags: tags as NonEmptyArray<Tag> ?? null,
|
|
141
|
+
tags: tags as NonEmptyArray<scalar.Tag> ?? null,
|
|
136
142
|
links: null,
|
|
137
143
|
style: {
|
|
138
144
|
...style,
|
|
@@ -239,8 +245,12 @@ const rel = <Source extends FakeElementIds, Target extends FakeElementIds>({
|
|
|
239
245
|
({
|
|
240
246
|
id: `${source}:${target}` as RelationId,
|
|
241
247
|
title: title ?? '',
|
|
242
|
-
source:
|
|
243
|
-
|
|
248
|
+
source: {
|
|
249
|
+
model: source as Fqn,
|
|
250
|
+
},
|
|
251
|
+
target: {
|
|
252
|
+
model: target as Fqn,
|
|
253
|
+
},
|
|
244
254
|
...(props as any),
|
|
245
255
|
}) as Omit<ModelRelation, 'id'> & { id: `${Source}:${Target}` }
|
|
246
256
|
|
|
@@ -325,7 +335,7 @@ export const fakeRelations = [
|
|
|
325
335
|
export const globalStyles = {
|
|
326
336
|
'mute_old': [{
|
|
327
337
|
targets: [$expr({
|
|
328
|
-
elementTag: 'old'
|
|
338
|
+
elementTag: 'old',
|
|
329
339
|
isEqual: true,
|
|
330
340
|
})],
|
|
331
341
|
style: {
|
|
@@ -334,7 +344,7 @@ export const globalStyles = {
|
|
|
334
344
|
}],
|
|
335
345
|
'red_next': [{
|
|
336
346
|
targets: [$expr({
|
|
337
|
-
elementTag: 'next'
|
|
347
|
+
elementTag: 'next',
|
|
338
348
|
isEqual: true,
|
|
339
349
|
})],
|
|
340
350
|
style: {
|
|
@@ -345,6 +355,27 @@ export const globalStyles = {
|
|
|
345
355
|
|
|
346
356
|
export type FakeRelationIds = (typeof fakeRelations)[number]['id']
|
|
347
357
|
const fakeParsedModel = {
|
|
358
|
+
_stage: 'computed' as const,
|
|
359
|
+
specification: {
|
|
360
|
+
elements: {
|
|
361
|
+
actor: {},
|
|
362
|
+
system: {},
|
|
363
|
+
container: {},
|
|
364
|
+
component: {},
|
|
365
|
+
},
|
|
366
|
+
relationships: {
|
|
367
|
+
graphlql: {},
|
|
368
|
+
},
|
|
369
|
+
deployments: {},
|
|
370
|
+
tags: {
|
|
371
|
+
old: {},
|
|
372
|
+
next: {},
|
|
373
|
+
aws: {},
|
|
374
|
+
storage: {},
|
|
375
|
+
communication: {},
|
|
376
|
+
legacy: {},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
348
379
|
elements: fakeElements,
|
|
349
380
|
relations: indexBy(fakeRelations, r => r.id),
|
|
350
381
|
deployments: {
|
|
@@ -381,23 +412,39 @@ const fakeParsedModel = {
|
|
|
381
412
|
},
|
|
382
413
|
}),
|
|
383
414
|
],
|
|
384
|
-
}
|
|
415
|
+
} as Record<string, NonEmptyArray<ElementViewPredicate<$Aux>>>,
|
|
385
416
|
dynamicPredicates: {},
|
|
386
417
|
styles: globalStyles,
|
|
387
418
|
},
|
|
388
419
|
} as const
|
|
389
420
|
export const fakeModel = LikeC4Model.fromDump(fakeParsedModel)
|
|
390
421
|
|
|
422
|
+
// export type $Aux = typeof fakeModel.Aux
|
|
423
|
+
export type $Aux = Aux<
|
|
424
|
+
'computed',
|
|
425
|
+
FakeElementIds,
|
|
426
|
+
never,
|
|
427
|
+
'index',
|
|
428
|
+
never,
|
|
429
|
+
SpecAux<
|
|
430
|
+
'actor' | 'system' | 'container' | 'component',
|
|
431
|
+
never,
|
|
432
|
+
'graphlql',
|
|
433
|
+
TestTag,
|
|
434
|
+
never
|
|
435
|
+
>
|
|
436
|
+
>
|
|
437
|
+
|
|
391
438
|
const emptyView = {
|
|
392
|
-
|
|
393
|
-
|
|
439
|
+
_stage: 'parsed' as const,
|
|
440
|
+
_type: 'element' as const,
|
|
441
|
+
id: 'index' as scalar.ViewId<'index'>,
|
|
394
442
|
title: null,
|
|
395
443
|
description: null,
|
|
396
444
|
tags: null,
|
|
397
445
|
links: null,
|
|
398
|
-
customColorDefinitions: {},
|
|
399
446
|
rules: [],
|
|
400
|
-
}
|
|
447
|
+
} satisfies ParsedElementView<$Aux>
|
|
401
448
|
|
|
402
449
|
export const includeWildcard = {
|
|
403
450
|
include: [
|
|
@@ -429,8 +476,8 @@ export type Expression =
|
|
|
429
476
|
|
|
430
477
|
export function $custom(
|
|
431
478
|
expr: ElementRefExpr,
|
|
432
|
-
props: Omit<
|
|
433
|
-
):
|
|
479
|
+
props: Omit<ModelFqnExpr.Custom<$Aux>['custom'], 'expr'>,
|
|
480
|
+
): ModelFqnExpr.Custom<$Aux> {
|
|
434
481
|
return {
|
|
435
482
|
custom: {
|
|
436
483
|
expr: $expr(expr) as any,
|
|
@@ -440,9 +487,9 @@ export function $custom(
|
|
|
440
487
|
}
|
|
441
488
|
|
|
442
489
|
export function $customRelation(
|
|
443
|
-
relation:
|
|
444
|
-
props: Omit<
|
|
445
|
-
):
|
|
490
|
+
relation: ModelRelationExpr.OrWhere<$Aux>,
|
|
491
|
+
props: Omit<ModelRelationExpr.Custom<$Aux>['customRelation'], 'expr'>,
|
|
492
|
+
): ModelRelationExpr.Custom<$Aux> {
|
|
446
493
|
return {
|
|
447
494
|
customRelation: {
|
|
448
495
|
expr: $expr(relation) as any,
|
|
@@ -453,20 +500,20 @@ export function $customRelation(
|
|
|
453
500
|
|
|
454
501
|
export function $where(
|
|
455
502
|
expr: Expression,
|
|
456
|
-
operator: WhereOperator
|
|
457
|
-
):
|
|
503
|
+
operator: WhereOperator<$Aux>,
|
|
504
|
+
): ModelExpression.Where<$Aux>
|
|
458
505
|
export function $where(
|
|
459
|
-
expr:
|
|
460
|
-
operator: WhereOperator
|
|
461
|
-
):
|
|
506
|
+
expr: ModelRelationExpr<$Aux>,
|
|
507
|
+
operator: WhereOperator<$Aux>,
|
|
508
|
+
): ModelRelationExpr.Where<$Aux>
|
|
462
509
|
export function $where(
|
|
463
|
-
expr:
|
|
464
|
-
operator: WhereOperator
|
|
465
|
-
):
|
|
510
|
+
expr: ModelFqnExpr<$Aux>,
|
|
511
|
+
operator: WhereOperator<$Aux>,
|
|
512
|
+
): ModelFqnExpr.Where<$Aux>
|
|
466
513
|
export function $where(
|
|
467
|
-
expr: Expression |
|
|
468
|
-
operator: WhereOperator
|
|
469
|
-
):
|
|
514
|
+
expr: Expression | ModelExpression<$Aux>,
|
|
515
|
+
operator: WhereOperator<$Aux>,
|
|
516
|
+
): ModelExpression.Where<$Aux> {
|
|
470
517
|
return {
|
|
471
518
|
where: {
|
|
472
519
|
expr: $expr(expr) as any,
|
|
@@ -477,8 +524,8 @@ export function $where(
|
|
|
477
524
|
|
|
478
525
|
export function $participant(
|
|
479
526
|
participant: Participant,
|
|
480
|
-
operator: TagEqual
|
|
481
|
-
): WhereOperator
|
|
527
|
+
operator: TagEqual<$Aux> | KindEqual<$Aux>,
|
|
528
|
+
): WhereOperator<$Aux> {
|
|
482
529
|
return {
|
|
483
530
|
participant,
|
|
484
531
|
operator,
|
|
@@ -486,38 +533,38 @@ export function $participant(
|
|
|
486
533
|
}
|
|
487
534
|
|
|
488
535
|
export function $inout(
|
|
489
|
-
expr: InOutExpr |
|
|
490
|
-
):
|
|
536
|
+
expr: InOutExpr | ModelFqnExpr<$Aux>,
|
|
537
|
+
): ModelRelationExpr.InOut<$Aux> {
|
|
491
538
|
const innerExpression = !isString(expr)
|
|
492
|
-
? expr
|
|
539
|
+
? expr
|
|
493
540
|
: $expr(expr.replace(/->/g, '').trim() as any)
|
|
494
541
|
|
|
495
|
-
return { inout: innerExpression }
|
|
542
|
+
return { inout: innerExpression as any }
|
|
496
543
|
}
|
|
497
544
|
|
|
498
545
|
export function $incoming(
|
|
499
|
-
expr: IncomingExpr |
|
|
500
|
-
):
|
|
546
|
+
expr: IncomingExpr | ModelFqnExpr<$Aux>,
|
|
547
|
+
): ModelRelationExpr.Incoming<$Aux> {
|
|
501
548
|
const innerExpression = !isString(expr)
|
|
502
|
-
? expr
|
|
549
|
+
? expr
|
|
503
550
|
: $expr(expr.replace('-> ', '') as any)
|
|
504
551
|
|
|
505
|
-
return { incoming: innerExpression }
|
|
552
|
+
return { incoming: innerExpression as any }
|
|
506
553
|
}
|
|
507
554
|
|
|
508
555
|
export function $outgoing(
|
|
509
|
-
expr: OutgoingExpr |
|
|
510
|
-
):
|
|
556
|
+
expr: OutgoingExpr | ModelFqnExpr<$Aux>,
|
|
557
|
+
): ModelRelationExpr.Outgoing<$Aux> {
|
|
511
558
|
const innerExpression = !isString(expr)
|
|
512
|
-
? expr as
|
|
559
|
+
? expr as ModelFqnExpr
|
|
513
560
|
: $expr(expr.replace(' ->', '') as any)
|
|
514
561
|
|
|
515
|
-
return { outgoing: innerExpression }
|
|
562
|
+
return { outgoing: innerExpression as any }
|
|
516
563
|
}
|
|
517
564
|
|
|
518
565
|
export function $relation(
|
|
519
566
|
expr: RelationExpr,
|
|
520
|
-
):
|
|
567
|
+
): ModelRelationExpr.Direct<$Aux> {
|
|
521
568
|
const [source, target] = expr.split(/ -> | <-> /)
|
|
522
569
|
const isBidirectional = expr.includes(' <-> ')
|
|
523
570
|
|
|
@@ -528,9 +575,9 @@ export function $relation(
|
|
|
528
575
|
}
|
|
529
576
|
}
|
|
530
577
|
|
|
531
|
-
export function $expr(expr: Expression |
|
|
578
|
+
export function $expr(expr: Expression | ModelExpression<$Aux>): ModelExpression<$Aux> {
|
|
532
579
|
if (!isString(expr)) {
|
|
533
|
-
return expr as
|
|
580
|
+
return expr as ModelExpression<$Aux>
|
|
534
581
|
}
|
|
535
582
|
if (expr === '*') {
|
|
536
583
|
return { wildcard: true }
|
|
@@ -547,7 +594,7 @@ export function $expr(expr: Expression | ModelLayer.Expression): ModelLayer.Expr
|
|
|
547
594
|
if (expr.endsWith('._')) {
|
|
548
595
|
return {
|
|
549
596
|
ref: {
|
|
550
|
-
model: expr.replace('._', '') as Fqn
|
|
597
|
+
model: expr.replace('._', '') as aux.Fqn<$Aux>,
|
|
551
598
|
},
|
|
552
599
|
selector: 'expanded',
|
|
553
600
|
}
|
|
@@ -555,7 +602,7 @@ export function $expr(expr: Expression | ModelLayer.Expression): ModelLayer.Expr
|
|
|
555
602
|
if (expr.endsWith('.*')) {
|
|
556
603
|
return {
|
|
557
604
|
ref: {
|
|
558
|
-
model: expr.replace('.*', '') as Fqn
|
|
605
|
+
model: expr.replace('.*', '') as aux.Fqn<$Aux>,
|
|
559
606
|
},
|
|
560
607
|
selector: 'children',
|
|
561
608
|
}
|
|
@@ -563,20 +610,20 @@ export function $expr(expr: Expression | ModelLayer.Expression): ModelLayer.Expr
|
|
|
563
610
|
if (expr.endsWith('.**')) {
|
|
564
611
|
return {
|
|
565
612
|
ref: {
|
|
566
|
-
model: expr.replace('.**', '') as Fqn
|
|
613
|
+
model: expr.replace('.**', '') as aux.Fqn<$Aux>,
|
|
567
614
|
},
|
|
568
615
|
selector: 'descendants',
|
|
569
616
|
}
|
|
570
617
|
}
|
|
571
618
|
return {
|
|
572
619
|
ref: {
|
|
573
|
-
model: expr as Fqn
|
|
620
|
+
model: expr as aux.Fqn<$Aux>,
|
|
574
621
|
},
|
|
575
622
|
}
|
|
576
623
|
}
|
|
577
624
|
|
|
578
625
|
type CustomProps = {
|
|
579
|
-
where?: WhereOperator
|
|
626
|
+
where?: WhereOperator<$Aux>
|
|
580
627
|
with?: {
|
|
581
628
|
title?: string
|
|
582
629
|
description?: string
|
|
@@ -588,30 +635,30 @@ type CustomProps = {
|
|
|
588
635
|
opacity?: number
|
|
589
636
|
navigateTo?: string
|
|
590
637
|
multiple?: boolean
|
|
591
|
-
} & Omit<
|
|
638
|
+
} & Omit<ModelRelationExpr.Custom<$Aux>['customRelation'], 'expr' | 'navigateTo'>
|
|
592
639
|
}
|
|
593
640
|
export function $include(
|
|
594
|
-
expr: Expression |
|
|
641
|
+
expr: Expression | ModelExpression<$Aux>,
|
|
595
642
|
props?: CustomProps,
|
|
596
|
-
):
|
|
597
|
-
let _expr = props?.where ? $where(expr as any, props.where) : $expr(expr)
|
|
643
|
+
): ElementViewPredicate<$Aux> {
|
|
644
|
+
let _expr = props?.where ? $where(expr as any, props.where as any) : $expr(expr)
|
|
598
645
|
_expr = props?.with ? $with(_expr, props.with) : _expr
|
|
599
646
|
return {
|
|
600
647
|
include: [_expr],
|
|
601
648
|
}
|
|
602
649
|
}
|
|
603
650
|
export function $with(
|
|
604
|
-
expr:
|
|
651
|
+
expr: ModelExpression<$Aux>,
|
|
605
652
|
props?: CustomProps['with'],
|
|
606
|
-
):
|
|
607
|
-
if (
|
|
653
|
+
): ModelRelationExpr.Custom<$Aux> | ModelFqnExpr.Custom<$Aux> {
|
|
654
|
+
if (ModelRelationExpr.is(expr) || ModelRelationExpr.isWhere(expr)) {
|
|
608
655
|
return {
|
|
609
656
|
customRelation: {
|
|
610
657
|
expr,
|
|
611
658
|
...props as any,
|
|
612
659
|
},
|
|
613
660
|
}
|
|
614
|
-
} else if (
|
|
661
|
+
} else if (ModelFqnExpr.is(expr) || ModelFqnExpr.isWhere(expr)) {
|
|
615
662
|
return {
|
|
616
663
|
custom: {
|
|
617
664
|
expr,
|
|
@@ -623,24 +670,24 @@ export function $with(
|
|
|
623
670
|
throw 'Unsupported type of internal expression'
|
|
624
671
|
}
|
|
625
672
|
export function $exclude(
|
|
626
|
-
expr: Expression |
|
|
627
|
-
where?: WhereOperator
|
|
628
|
-
): ViewRulePredicate {
|
|
673
|
+
expr: Expression | ModelExpression<$Aux>,
|
|
674
|
+
where?: WhereOperator<$Aux>,
|
|
675
|
+
): ViewRulePredicate<$Aux> {
|
|
629
676
|
let _expr = where ? $where(expr as any, where) : $expr(expr)
|
|
630
677
|
return {
|
|
631
678
|
exclude: [_expr],
|
|
632
679
|
}
|
|
633
680
|
}
|
|
634
|
-
export function $group(groupRules: ViewRuleGroup['groupRules']): ViewRuleGroup {
|
|
681
|
+
export function $group(groupRules: ViewRuleGroup<$Aux>['groupRules']): ViewRuleGroup<$Aux> {
|
|
635
682
|
return {
|
|
636
683
|
title: null,
|
|
637
684
|
groupRules,
|
|
638
685
|
}
|
|
639
686
|
}
|
|
640
687
|
|
|
641
|
-
export function $style(element: ElementRefExpr, style: ViewRuleStyle['style']): ViewRuleStyle {
|
|
688
|
+
export function $style(element: ElementRefExpr, style: ViewRuleStyle<$Aux>['style']): ViewRuleStyle<$Aux> {
|
|
642
689
|
return {
|
|
643
|
-
targets: [$expr(element) as
|
|
690
|
+
targets: [$expr(element) as ModelFqnExpr<$Aux>],
|
|
644
691
|
style: Object.assign({}, style),
|
|
645
692
|
}
|
|
646
693
|
}
|
|
@@ -665,25 +712,29 @@ export function $global(expr: GlobalExpr): ViewRuleGlobalStyle | ViewRuleGlobalP
|
|
|
665
712
|
}
|
|
666
713
|
|
|
667
714
|
export function computeView(
|
|
668
|
-
...args: [FakeElementIds,
|
|
669
|
-
|
|
670
|
-
|
|
715
|
+
...args: [FakeElementIds, ElementViewRule<$Aux> | ElementViewRule<$Aux>[]] | [
|
|
716
|
+
ElementViewRule<$Aux> | ElementViewRule<$Aux>[],
|
|
717
|
+
]
|
|
718
|
+
): ComputedElementView<$Aux> & {
|
|
719
|
+
nodeIds: string[]
|
|
720
|
+
edgeIds: string[]
|
|
721
|
+
} {
|
|
722
|
+
let result: ComputedElementView<$Aux>
|
|
671
723
|
if (args.length === 1) {
|
|
672
|
-
result = computeElementView(
|
|
673
|
-
fakeModel
|
|
724
|
+
result = computeElementView<$Aux>(
|
|
725
|
+
fakeModel as unknown as LikeC4Model<$Aux>,
|
|
674
726
|
{
|
|
675
727
|
...emptyView,
|
|
676
|
-
rules: [args[0]].flat(),
|
|
728
|
+
rules: [args[0]].flat() as ElementViewRule<$Aux>[],
|
|
677
729
|
},
|
|
678
730
|
)
|
|
679
731
|
} else {
|
|
680
732
|
result = computeElementView(
|
|
681
|
-
fakeModel
|
|
733
|
+
fakeModel as unknown as LikeC4Model<$Aux>,
|
|
682
734
|
{
|
|
683
735
|
...emptyView,
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
rules: [args[1]].flat(),
|
|
736
|
+
viewOf: args[0] as aux.Fqn<$Aux>,
|
|
737
|
+
rules: [args[1]].flat() as ElementViewRule<$Aux>[],
|
|
687
738
|
},
|
|
688
739
|
)
|
|
689
740
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type LikeC4Model } from '../../model'
|
|
2
|
-
import type { ConnectionModel } from '../../model
|
|
3
|
-
import type { RelationshipModel } from '../../model
|
|
4
|
-
import type {
|
|
5
|
-
import type { ModelLayer } from '../../types/expression-v2-model'
|
|
2
|
+
import type { ConnectionModel } from '../../model'
|
|
3
|
+
import type { RelationshipModel } from '../../model'
|
|
4
|
+
import type { ModelExpression, ModelFqnExpr, ModelRelationExpr } from '../../types'
|
|
6
5
|
|
|
7
6
|
import type { Ctx, Memory, Stage, StageExclude, StageInclude } from './memory'
|
|
8
7
|
|
|
@@ -14,39 +13,35 @@ export type Connection = Ctx['Connection']
|
|
|
14
13
|
export type ElementWhere = Where<Elem>
|
|
15
14
|
export type ElementWhereFilter = (elements: readonly Elem[]) => Elem[]
|
|
16
15
|
export type ConnectionWhere = Where<Connection>
|
|
17
|
-
export type RelationshipWhere = Where<RelationshipModel
|
|
16
|
+
export type RelationshipWhere = Where<RelationshipModel<any>>
|
|
18
17
|
export type ConnectionWhereFilter = (connections: readonly Connection[]) => Connection[]
|
|
19
18
|
|
|
20
19
|
export { Memory } from './memory'
|
|
21
20
|
|
|
22
|
-
export type Connections = ReadonlyArray<ConnectionModel<
|
|
21
|
+
export type Connections = ReadonlyArray<ConnectionModel<any>>
|
|
23
22
|
|
|
24
|
-
export interface PredicateCtx<Expr
|
|
23
|
+
export interface PredicateCtx<Expr = ModelExpression<any>> {
|
|
25
24
|
expr: Expr
|
|
26
25
|
stage: Stage
|
|
27
26
|
// View scope
|
|
28
27
|
scope: Elem | null
|
|
29
|
-
model: LikeC4Model<
|
|
28
|
+
model: LikeC4Model<any>
|
|
30
29
|
memory: Memory
|
|
31
|
-
where: Expr extends
|
|
32
|
-
: Expr extends
|
|
30
|
+
where: Expr extends ModelRelationExpr<any> ? RelationshipWhere
|
|
31
|
+
: Expr extends ModelFqnExpr<any> ? ElementWhere
|
|
33
32
|
: never
|
|
34
|
-
filterWhere: Expr extends
|
|
35
|
-
: Expr extends
|
|
33
|
+
filterWhere: Expr extends ModelRelationExpr<any> ? ConnectionWhereFilter
|
|
34
|
+
: Expr extends ModelFqnExpr<any> ? ElementWhereFilter
|
|
36
35
|
: never
|
|
37
36
|
}
|
|
38
|
-
export interface IncludePredicateCtx<Expr
|
|
39
|
-
extends PredicateCtx<Expr>
|
|
40
|
-
{
|
|
37
|
+
export interface IncludePredicateCtx<Expr = ModelExpression<any>> extends PredicateCtx<Expr> {
|
|
41
38
|
stage: StageInclude
|
|
42
39
|
}
|
|
43
|
-
export interface ExcludePredicateCtx<Expr
|
|
44
|
-
extends PredicateCtx<Expr>
|
|
45
|
-
{
|
|
40
|
+
export interface ExcludePredicateCtx<Expr = ModelExpression<any>> extends PredicateCtx<Expr> {
|
|
46
41
|
stage: StageExclude
|
|
47
42
|
}
|
|
48
43
|
|
|
49
|
-
export interface PredicateExecutor<Expr
|
|
44
|
+
export interface PredicateExecutor<Expr = ModelExpression<any>> {
|
|
50
45
|
include(ctx: IncludePredicateCtx<Expr>): StageInclude | undefined
|
|
51
46
|
exclude(ctx: ExcludePredicateCtx<Expr>): StageExclude | undefined
|
|
52
47
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { allPass, anyPass, pipe, prop, reduce } from 'remeda'
|
|
2
|
-
import {
|
|
2
|
+
import type { RelationshipModel } from '../../model'
|
|
3
3
|
import {
|
|
4
|
+
Connection,
|
|
5
|
+
ConnectionModel,
|
|
4
6
|
differenceConnections,
|
|
5
7
|
findDeepestNestedConnection,
|
|
6
8
|
findDescendantConnections,
|
|
@@ -8,8 +10,8 @@ import {
|
|
|
8
10
|
isIncoming,
|
|
9
11
|
isOutgoing,
|
|
10
12
|
mergeConnections,
|
|
11
|
-
} from '../../model
|
|
12
|
-
import type {
|
|
13
|
+
} from '../../model'
|
|
14
|
+
import type { AnyAux } from '../../types'
|
|
13
15
|
import { intersection, union } from '../../utils'
|
|
14
16
|
import { ifilter, toSet } from '../../utils/iterable'
|
|
15
17
|
|
|
@@ -36,7 +38,9 @@ function isInOutToDescendant(id: string): (c: ConnectionModel) => boolean {
|
|
|
36
38
|
])
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
export function findRedundantConnections
|
|
41
|
+
export function findRedundantConnections<A extends AnyAux>(
|
|
42
|
+
connections: Iterable<ConnectionModel<A>>,
|
|
43
|
+
): Array<ConnectionModel<A>> {
|
|
40
44
|
return pipe(
|
|
41
45
|
[...connections],
|
|
42
46
|
mergeConnections,
|
|
@@ -92,7 +96,7 @@ export function findRedundantConnections(connections: Iterable<ConnectionModel>)
|
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
return reducedConnections
|
|
95
|
-
}, [] as ConnectionModel[]),
|
|
99
|
+
}, [] as ConnectionModel<A>[]),
|
|
96
100
|
)
|
|
97
101
|
}
|
|
98
102
|
|
|
@@ -103,9 +107,9 @@ export function findRedundantConnections(connections: Iterable<ConnectionModel>)
|
|
|
103
107
|
* @returns New connection without redundant relationships
|
|
104
108
|
* Connection may be empty if all relationships are redundant, in this case it should be removed
|
|
105
109
|
*/
|
|
106
|
-
export function cleanRedundantRelationships(
|
|
107
|
-
connections: Iterable<ConnectionModel
|
|
108
|
-
): Array<ConnectionModel
|
|
110
|
+
export function cleanRedundantRelationships<A extends AnyAux>(
|
|
111
|
+
connections: Iterable<ConnectionModel<A>>,
|
|
112
|
+
): Array<ConnectionModel<A>> {
|
|
109
113
|
return differenceConnections(
|
|
110
114
|
connections,
|
|
111
115
|
findRedundantConnections(connections),
|