@likec4/core 1.27.3 → 1.28.1
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/dist/builder/index.d.mts +6 -6
- package/dist/builder/index.mjs +23 -13
- package/dist/compute-view/index.d.mts +3 -3
- package/dist/compute-view/index.mjs +3 -3
- package/dist/compute-view/relationships-view/index.d.mts +3 -3
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +2 -2
- package/dist/model/index.d.mts +6 -6
- package/dist/model/index.mjs +1 -1
- package/dist/shared/{core.BpuZeqlX.d.mts → core.CZR9J1Qx.d.mts} +2 -2
- package/dist/shared/{core.Djro-kuQ.d.mts → core.CiFKryGW.d.mts} +7 -2
- package/dist/shared/{core.HKn0jlo_.d.mts → core.D2830qgg.d.mts} +1 -1
- package/dist/shared/{core.CFDwncxs.d.mts → core.DJvmfnEi.d.mts} +481 -186
- package/dist/shared/{core.BMep80lJ.mjs → core.DgfwjBtu.mjs} +198 -87
- package/dist/shared/core.SjLhMA7a.d.mts +62 -0
- package/dist/shared/{core.RjpTh3vE.mjs → core.w6BcP9z5.mjs} +263 -168
- package/dist/types/index.d.mts +4 -4
- package/dist/types/index.mjs +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/package.json +7 -7
- package/src/builder/Builder.ts +1 -0
- package/src/builder/Builder.view-common.ts +10 -10
- package/src/builder/Builder.view-element.ts +26 -14
- package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +23 -8
- package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +9 -4
- package/src/compute-view/deployment-view/predicates/deploymentRefs-where.ts +18 -0
- package/src/compute-view/deployment-view/predicates/relation-direct.ts +6 -0
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +3 -0
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +3 -0
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +3 -0
- package/src/compute-view/deployment-view/predicates/utils.ts +10 -3
- package/src/compute-view/deployment-view/utils.ts +7 -4
- package/src/compute-view/element-view/__test__/fixture.ts +72 -65
- package/src/compute-view/element-view/_types.ts +13 -9
- package/src/compute-view/element-view/compute.ts +27 -27
- package/src/compute-view/element-view/memory/NodeGroup.ts +4 -3
- package/src/compute-view/element-view/memory/memory.ts +3 -2
- package/src/compute-view/element-view/memory/stage-include.ts +2 -2
- package/src/compute-view/element-view/predicates/_utils.ts +25 -24
- package/src/compute-view/element-view/predicates/element-expand.ts +7 -10
- package/src/compute-view/element-view/predicates/element-kind-tag.ts +5 -3
- package/src/compute-view/element-view/predicates/element-ref.ts +7 -19
- package/src/compute-view/element-view/predicates/relation-direct.ts +15 -13
- package/src/compute-view/element-view/predicates/relation-in-out.ts +5 -6
- package/src/compute-view/element-view/predicates/relation-in.ts +36 -32
- package/src/compute-view/element-view/predicates/relation-out.ts +37 -33
- package/src/compute-view/element-view/predicates/wildcard.ts +2 -2
- package/src/compute-view/utils/applyCustomElementProperties.ts +9 -4
- package/src/compute-view/utils/applyCustomRelationProperties.ts +10 -7
- package/src/compute-view/utils/elementExpressionToPredicate.ts +27 -26
- package/src/compute-view/utils/link-nodes-with-edges.ts +1 -1
- package/src/compute-view/utils/relationExpressionToPredicates.ts +10 -17
- package/src/compute-view/utils/uniqueTags.ts +3 -3
- package/src/index.ts +0 -2
- package/src/model/ElementModel.ts +25 -6
- package/src/model/LikeC4Model.ts +47 -6
- package/src/model/RelationModel.ts +4 -2
- package/src/model/view/LikeC4ViewModel.ts +3 -2
- package/src/types/_common.ts +0 -4
- package/src/types/deployments.ts +3 -2
- package/src/types/element.ts +2 -10
- package/src/types/expression-v2-model.ts +314 -0
- package/src/types/expression-v2.ts +238 -30
- package/src/types/index.ts +15 -46
- package/src/types/model-data.ts +4 -1
- package/src/types/relation.ts +2 -1
- package/src/types/scalars.ts +39 -0
- package/src/types/view-changes.ts +2 -1
- package/src/types/view.ts +7 -8
- package/dist/shared/core.30yYKXcZ.d.mts +0 -186
- package/src/types/expression.ts +0 -207
|
@@ -4,28 +4,19 @@ import {
|
|
|
4
4
|
type BorderStyle,
|
|
5
5
|
type Color,
|
|
6
6
|
type ComputedView,
|
|
7
|
-
type CustomElementExpr as C4CustomElementExpr,
|
|
8
|
-
type CustomRelationExpr as C4CustomRelationExpr,
|
|
9
7
|
type Element,
|
|
10
|
-
type ElementExpression as C4ElementExpression,
|
|
11
8
|
type ElementKind,
|
|
12
9
|
type ElementShape,
|
|
13
|
-
type ElementWhereExpr,
|
|
14
|
-
type Expression as C4Expression,
|
|
15
10
|
type Fqn,
|
|
16
11
|
type GlobalPredicateId,
|
|
17
12
|
type GlobalStyleID,
|
|
18
13
|
type IconUrl,
|
|
19
|
-
type IncomingExpr as C4IncomingExpr,
|
|
20
|
-
type InOutExpr as C4InOutExpr,
|
|
21
14
|
type KindEqual,
|
|
22
15
|
type ModelRelation,
|
|
23
16
|
type NonEmptyArray,
|
|
24
|
-
type OutgoingExpr as C4OutgoingExpr,
|
|
25
17
|
type RelationId,
|
|
26
18
|
type RelationshipArrowType,
|
|
27
19
|
type RelationshipLineType,
|
|
28
|
-
type RelationWhereExpr,
|
|
29
20
|
type Tag,
|
|
30
21
|
type TagEqual,
|
|
31
22
|
type ViewId,
|
|
@@ -36,12 +27,8 @@ import {
|
|
|
36
27
|
type ViewRulePredicate,
|
|
37
28
|
type ViewRuleStyle,
|
|
38
29
|
type WhereOperator,
|
|
39
|
-
|
|
40
|
-
isElementWhere,
|
|
41
|
-
isRelationExpression,
|
|
42
|
-
isRelationWhere,
|
|
30
|
+
ModelLayer,
|
|
43
31
|
} from '../../../types'
|
|
44
|
-
import { type DirectRelationExpr as C4RelationExpr } from '../../../types/expression'
|
|
45
32
|
import type { Participant } from '../../../types/operators'
|
|
46
33
|
import { withReadableEdges } from '../../utils/with-readable-edges'
|
|
47
34
|
import { computeElementView } from '../compute'
|
|
@@ -365,6 +352,7 @@ const fakeParsedModel = {
|
|
|
365
352
|
relations: {},
|
|
366
353
|
},
|
|
367
354
|
views: {},
|
|
355
|
+
imports: {},
|
|
368
356
|
globals: {
|
|
369
357
|
predicates: {
|
|
370
358
|
'remove_tag_old': [
|
|
@@ -441,19 +429,8 @@ export type Expression =
|
|
|
441
429
|
|
|
442
430
|
export function $custom(
|
|
443
431
|
expr: ElementRefExpr,
|
|
444
|
-
props:
|
|
445
|
-
|
|
446
|
-
description?: string
|
|
447
|
-
technology?: string
|
|
448
|
-
shape?: ElementShape
|
|
449
|
-
color?: Color
|
|
450
|
-
border?: BorderStyle
|
|
451
|
-
icon?: string
|
|
452
|
-
opacity?: number
|
|
453
|
-
navigateTo?: string
|
|
454
|
-
multiple?: boolean
|
|
455
|
-
},
|
|
456
|
-
): C4CustomElementExpr {
|
|
432
|
+
props: Omit<ModelLayer.FqnExpr.Custom['custom'], 'expr'>,
|
|
433
|
+
): ModelLayer.FqnExpr.Custom {
|
|
457
434
|
return {
|
|
458
435
|
custom: {
|
|
459
436
|
expr: $expr(expr) as any,
|
|
@@ -463,21 +440,33 @@ export function $custom(
|
|
|
463
440
|
}
|
|
464
441
|
|
|
465
442
|
export function $customRelation(
|
|
466
|
-
relation:
|
|
467
|
-
props: Omit<
|
|
468
|
-
):
|
|
443
|
+
relation: ModelLayer.RelationExprOrWhere,
|
|
444
|
+
props: Omit<ModelLayer.RelationExpr.Custom['customRelation'], 'expr'>,
|
|
445
|
+
): ModelLayer.RelationExpr.Custom {
|
|
469
446
|
return {
|
|
470
447
|
customRelation: {
|
|
471
|
-
|
|
448
|
+
expr: $expr(relation) as any,
|
|
472
449
|
...props,
|
|
473
450
|
},
|
|
474
451
|
}
|
|
475
452
|
}
|
|
476
453
|
|
|
477
454
|
export function $where(
|
|
478
|
-
expr: Expression
|
|
455
|
+
expr: Expression,
|
|
479
456
|
operator: WhereOperator<TestTag, string>,
|
|
480
|
-
):
|
|
457
|
+
): ModelLayer.Expression.Where
|
|
458
|
+
export function $where(
|
|
459
|
+
expr: ModelLayer.RelationExpr,
|
|
460
|
+
operator: WhereOperator<TestTag, string>,
|
|
461
|
+
): ModelLayer.RelationExpr.Where
|
|
462
|
+
export function $where(
|
|
463
|
+
expr: ModelLayer.FqnExpr,
|
|
464
|
+
operator: WhereOperator<TestTag, string>,
|
|
465
|
+
): ModelLayer.FqnExpr.Where
|
|
466
|
+
export function $where(
|
|
467
|
+
expr: Expression | ModelLayer.Expression,
|
|
468
|
+
operator: WhereOperator<TestTag, string>,
|
|
469
|
+
): ModelLayer.Expression {
|
|
481
470
|
return {
|
|
482
471
|
where: {
|
|
483
472
|
expr: $expr(expr) as any,
|
|
@@ -497,38 +486,38 @@ export function $participant(
|
|
|
497
486
|
}
|
|
498
487
|
|
|
499
488
|
export function $inout(
|
|
500
|
-
expr: InOutExpr |
|
|
501
|
-
):
|
|
489
|
+
expr: InOutExpr | ModelLayer.FqnExpr,
|
|
490
|
+
): ModelLayer.RelationExpr.InOut {
|
|
502
491
|
const innerExpression = !isString(expr)
|
|
503
|
-
? expr as
|
|
504
|
-
: $expr(expr.replace(/->/g, '').trim() as
|
|
492
|
+
? expr as ModelLayer.FqnExpr
|
|
493
|
+
: $expr(expr.replace(/->/g, '').trim() as any)
|
|
505
494
|
|
|
506
495
|
return { inout: innerExpression }
|
|
507
496
|
}
|
|
508
497
|
|
|
509
498
|
export function $incoming(
|
|
510
|
-
expr: IncomingExpr |
|
|
511
|
-
):
|
|
499
|
+
expr: IncomingExpr | ModelLayer.FqnExpr,
|
|
500
|
+
): ModelLayer.RelationExpr.Incoming {
|
|
512
501
|
const innerExpression = !isString(expr)
|
|
513
|
-
? expr as
|
|
514
|
-
: $expr(expr.replace('-> ', '') as
|
|
502
|
+
? expr as ModelLayer.FqnExpr
|
|
503
|
+
: $expr(expr.replace('-> ', '') as any)
|
|
515
504
|
|
|
516
505
|
return { incoming: innerExpression }
|
|
517
506
|
}
|
|
518
507
|
|
|
519
508
|
export function $outgoing(
|
|
520
|
-
expr: OutgoingExpr |
|
|
521
|
-
):
|
|
509
|
+
expr: OutgoingExpr | ModelLayer.FqnExpr,
|
|
510
|
+
): ModelLayer.RelationExpr.Outgoing {
|
|
522
511
|
const innerExpression = !isString(expr)
|
|
523
|
-
? expr as
|
|
524
|
-
: $expr(expr.replace(' ->', '') as
|
|
512
|
+
? expr as ModelLayer.FqnExpr
|
|
513
|
+
: $expr(expr.replace(' ->', '') as any)
|
|
525
514
|
|
|
526
515
|
return { outgoing: innerExpression }
|
|
527
516
|
}
|
|
528
517
|
|
|
529
518
|
export function $relation(
|
|
530
519
|
expr: RelationExpr,
|
|
531
|
-
):
|
|
520
|
+
): ModelLayer.RelationExpr {
|
|
532
521
|
const [source, target] = expr.split(/ -> | <-> /)
|
|
533
522
|
const isBidirectional = expr.includes(' <-> ')
|
|
534
523
|
|
|
@@ -539,9 +528,9 @@ export function $relation(
|
|
|
539
528
|
}
|
|
540
529
|
}
|
|
541
530
|
|
|
542
|
-
export function $expr(expr: Expression |
|
|
531
|
+
export function $expr(expr: Expression | ModelLayer.Expression): ModelLayer.Expression {
|
|
543
532
|
if (!isString(expr)) {
|
|
544
|
-
return expr as
|
|
533
|
+
return expr as ModelLayer.Expression
|
|
545
534
|
}
|
|
546
535
|
if (expr === '*') {
|
|
547
536
|
return { wildcard: true }
|
|
@@ -557,23 +546,32 @@ export function $expr(expr: Expression | C4Expression): C4Expression {
|
|
|
557
546
|
}
|
|
558
547
|
if (expr.endsWith('._')) {
|
|
559
548
|
return {
|
|
560
|
-
|
|
549
|
+
ref: {
|
|
550
|
+
model: expr.replace('._', '') as Fqn,
|
|
551
|
+
},
|
|
552
|
+
selector: 'expanded',
|
|
561
553
|
}
|
|
562
554
|
}
|
|
563
555
|
if (expr.endsWith('.*')) {
|
|
564
556
|
return {
|
|
565
|
-
|
|
566
|
-
|
|
557
|
+
ref: {
|
|
558
|
+
model: expr.replace('.*', '') as Fqn,
|
|
559
|
+
},
|
|
560
|
+
selector: 'children',
|
|
567
561
|
}
|
|
568
562
|
}
|
|
569
563
|
if (expr.endsWith('.**')) {
|
|
570
564
|
return {
|
|
571
|
-
|
|
572
|
-
|
|
565
|
+
ref: {
|
|
566
|
+
model: expr.replace('.**', '') as Fqn,
|
|
567
|
+
},
|
|
568
|
+
selector: 'descendants',
|
|
573
569
|
}
|
|
574
570
|
}
|
|
575
571
|
return {
|
|
576
|
-
|
|
572
|
+
ref: {
|
|
573
|
+
model: expr as Fqn,
|
|
574
|
+
},
|
|
577
575
|
}
|
|
578
576
|
}
|
|
579
577
|
|
|
@@ -590,27 +588,33 @@ type CustomProps = {
|
|
|
590
588
|
opacity?: number
|
|
591
589
|
navigateTo?: string
|
|
592
590
|
multiple?: boolean
|
|
593
|
-
} & Omit<
|
|
591
|
+
} & Omit<ModelLayer.RelationExpr.Custom['customRelation'], 'expr' | 'navigateTo'>
|
|
594
592
|
}
|
|
595
|
-
export function $include(
|
|
596
|
-
|
|
593
|
+
export function $include(
|
|
594
|
+
expr: Expression | ModelLayer.Expression,
|
|
595
|
+
props?: CustomProps,
|
|
596
|
+
): ViewRulePredicate {
|
|
597
|
+
let _expr = props?.where ? $where(expr as any, props.where) : $expr(expr)
|
|
597
598
|
_expr = props?.with ? $with(_expr, props.with) : _expr
|
|
598
599
|
return {
|
|
599
600
|
include: [_expr],
|
|
600
601
|
}
|
|
601
602
|
}
|
|
602
|
-
export function $with(
|
|
603
|
-
|
|
603
|
+
export function $with(
|
|
604
|
+
expr: ModelLayer.Expression,
|
|
605
|
+
props?: CustomProps['with'],
|
|
606
|
+
): ModelLayer.RelationExpr.Custom | ModelLayer.FqnExpr.Custom {
|
|
607
|
+
if (ModelLayer.RelationExpr.is(expr) || ModelLayer.RelationExpr.isWhere(expr)) {
|
|
604
608
|
return {
|
|
605
609
|
customRelation: {
|
|
606
|
-
|
|
610
|
+
expr,
|
|
607
611
|
...props as any,
|
|
608
612
|
},
|
|
609
613
|
}
|
|
610
|
-
} else if (
|
|
614
|
+
} else if (ModelLayer.FqnExpr.is(expr) || ModelLayer.FqnExpr.isWhere(expr)) {
|
|
611
615
|
return {
|
|
612
616
|
custom: {
|
|
613
|
-
expr
|
|
617
|
+
expr,
|
|
614
618
|
...props as any,
|
|
615
619
|
},
|
|
616
620
|
}
|
|
@@ -618,8 +622,11 @@ export function $with(expr: C4Expression, props?: CustomProps['with']): C4Custom
|
|
|
618
622
|
|
|
619
623
|
throw 'Unsupported type of internal expression'
|
|
620
624
|
}
|
|
621
|
-
export function $exclude(
|
|
622
|
-
|
|
625
|
+
export function $exclude(
|
|
626
|
+
expr: Expression | ModelLayer.Expression,
|
|
627
|
+
where?: WhereOperator<TestTag, string>,
|
|
628
|
+
): ViewRulePredicate {
|
|
629
|
+
let _expr = where ? $where(expr as any, where) : $expr(expr)
|
|
623
630
|
return {
|
|
624
631
|
exclude: [_expr],
|
|
625
632
|
}
|
|
@@ -633,7 +640,7 @@ export function $group(groupRules: ViewRuleGroup['groupRules']): ViewRuleGroup {
|
|
|
633
640
|
|
|
634
641
|
export function $style(element: ElementRefExpr, style: ViewRuleStyle['style']): ViewRuleStyle {
|
|
635
642
|
return {
|
|
636
|
-
targets: [$expr(element) as
|
|
643
|
+
targets: [$expr(element) as ModelLayer.FqnExpr],
|
|
637
644
|
style: Object.assign({}, style),
|
|
638
645
|
}
|
|
639
646
|
}
|
|
@@ -2,7 +2,7 @@ import { type LikeC4Model } from '../../model'
|
|
|
2
2
|
import type { ConnectionModel } from '../../model/connection/model'
|
|
3
3
|
import type { RelationshipModel } from '../../model/RelationModel'
|
|
4
4
|
import type { AnyAux } from '../../model/types'
|
|
5
|
-
import type {
|
|
5
|
+
import type { ModelLayer } from '../../types/expression-v2-model'
|
|
6
6
|
|
|
7
7
|
import type { Ctx, Memory, Stage, StageExclude, StageInclude } from './memory'
|
|
8
8
|
|
|
@@ -21,28 +21,32 @@ export { Memory } from './memory'
|
|
|
21
21
|
|
|
22
22
|
export type Connections = ReadonlyArray<ConnectionModel<AnyAux>>
|
|
23
23
|
|
|
24
|
-
export interface PredicateCtx<Expr extends Expression = Expression> {
|
|
24
|
+
export interface PredicateCtx<Expr extends ModelLayer.Expression = ModelLayer.Expression> {
|
|
25
25
|
expr: Expr
|
|
26
26
|
stage: Stage
|
|
27
27
|
// View scope
|
|
28
28
|
scope: Elem | null
|
|
29
29
|
model: LikeC4Model<AnyAux>
|
|
30
30
|
memory: Memory
|
|
31
|
-
where: Expr extends
|
|
32
|
-
: Expr extends
|
|
31
|
+
where: Expr extends ModelLayer.RelationExpr ? RelationshipWhere
|
|
32
|
+
: Expr extends ModelLayer.FqnExpr ? ElementWhere
|
|
33
33
|
: never
|
|
34
|
-
filterWhere: Expr extends
|
|
35
|
-
: Expr extends
|
|
34
|
+
filterWhere: Expr extends ModelLayer.RelationExpr ? ConnectionWhereFilter
|
|
35
|
+
: Expr extends ModelLayer.FqnExpr ? ElementWhereFilter
|
|
36
36
|
: never
|
|
37
37
|
}
|
|
38
|
-
export interface IncludePredicateCtx<Expr extends Expression = Expression>
|
|
38
|
+
export interface IncludePredicateCtx<Expr extends ModelLayer.Expression = ModelLayer.Expression>
|
|
39
|
+
extends PredicateCtx<Expr>
|
|
40
|
+
{
|
|
39
41
|
stage: StageInclude
|
|
40
42
|
}
|
|
41
|
-
export interface ExcludePredicateCtx<Expr extends Expression = Expression>
|
|
43
|
+
export interface ExcludePredicateCtx<Expr extends ModelLayer.Expression = ModelLayer.Expression>
|
|
44
|
+
extends PredicateCtx<Expr>
|
|
45
|
+
{
|
|
42
46
|
stage: StageExclude
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
export interface PredicateExecutor<Expr extends Expression> {
|
|
49
|
+
export interface PredicateExecutor<Expr extends ModelLayer.Expression = ModelLayer.Expression> {
|
|
46
50
|
include(ctx: IncludePredicateCtx<Expr>): StageInclude | undefined
|
|
47
51
|
exclude(ctx: ExcludePredicateCtx<Expr>): StageExclude | undefined
|
|
48
52
|
}
|
|
@@ -7,14 +7,12 @@ import type { RelationshipModel } from '../../model/RelationModel'
|
|
|
7
7
|
import type { AnyAux } from '../../model/types'
|
|
8
8
|
import type {
|
|
9
9
|
ComputedElementView,
|
|
10
|
-
ElementPredicateExpression,
|
|
11
10
|
ElementView,
|
|
12
11
|
NodeId,
|
|
13
|
-
RelationPredicateExpression,
|
|
14
12
|
ViewRule,
|
|
15
13
|
} from '../../types'
|
|
16
14
|
import { isViewRuleAutoLayout, isViewRuleGroup, isViewRulePredicate, whereOperatorAsPredicate } from '../../types'
|
|
17
|
-
import
|
|
15
|
+
import { ModelLayer } from '../../types/expression-v2-model'
|
|
18
16
|
import { sortParentsFirst } from '../../utils'
|
|
19
17
|
import { DefaultMap } from '../../utils/mnemonist'
|
|
20
18
|
import { applyCustomElementProperties } from '../utils/applyCustomElementProperties'
|
|
@@ -41,52 +39,54 @@ import { buildNodes, NoFilter, NoWhere, toComputedEdges } from './utils'
|
|
|
41
39
|
|
|
42
40
|
function processElementPredicate(
|
|
43
41
|
// ...args:
|
|
44
|
-
// | [expr:
|
|
45
|
-
// | [expr:
|
|
46
|
-
expr:
|
|
42
|
+
// | [expr: ModelLayer.AnyFqnExpr, op: 'include', IncludePredicateCtx<ModelLayer.AnyFqnExpr>]
|
|
43
|
+
// | [expr: ModelLayer.AnyFqnExpr, op: 'exclude', ExcludePredicateCtx<ModelLayer.AnyFqnExpr>]
|
|
44
|
+
expr: ModelLayer.AnyFqnExpr,
|
|
47
45
|
op: 'include' | 'exclude',
|
|
48
|
-
ctx: Omit<PredicateCtx<
|
|
46
|
+
ctx: Omit<PredicateCtx<ModelLayer.AnyFqnExpr>, 'expr'>,
|
|
49
47
|
): Stage {
|
|
50
48
|
switch (true) {
|
|
51
|
-
case
|
|
49
|
+
case ModelLayer.FqnExpr.isCustom(expr): {
|
|
52
50
|
if (op === 'include') {
|
|
53
51
|
return processElementPredicate(expr.custom.expr, op, ctx)
|
|
54
52
|
}
|
|
55
53
|
return ctx.stage
|
|
56
54
|
}
|
|
57
|
-
case
|
|
55
|
+
case ModelLayer.FqnExpr.isWhere(expr): {
|
|
58
56
|
const where = whereOperatorAsPredicate(expr.where.condition)
|
|
59
57
|
const filterWhere = filter<Elem>(where)
|
|
60
58
|
return processElementPredicate(expr.where.expr, op, { ...ctx, where, filterWhere } as any)
|
|
61
59
|
}
|
|
62
|
-
case
|
|
60
|
+
case ModelLayer.FqnExpr.isModelRef(expr) && expr.selector === 'expanded': {
|
|
63
61
|
return ExpandedElementPredicate[op]({ ...ctx, expr } as any) ?? ctx.stage
|
|
64
62
|
}
|
|
65
|
-
case
|
|
66
|
-
return ElementRefPredicate[op]({ ...ctx, expr } as any) ?? ctx.stage
|
|
67
|
-
}
|
|
68
|
-
case Expr.isWildcard(expr):
|
|
63
|
+
case ModelLayer.FqnExpr.isWildcard(expr): {
|
|
69
64
|
return WildcardPredicate[op]({ ...ctx, expr } as any) ?? ctx.stage
|
|
70
|
-
|
|
71
|
-
case
|
|
65
|
+
}
|
|
66
|
+
case ModelLayer.FqnExpr.isElementKindExpr(expr):
|
|
67
|
+
case ModelLayer.FqnExpr.isElementTagExpr(expr): {
|
|
72
68
|
return ElementKindOrTagPredicate[op]({ ...ctx, expr } as any) ?? ctx.stage
|
|
69
|
+
}
|
|
70
|
+
case ModelLayer.FqnExpr.isModelRef(expr): {
|
|
71
|
+
return ElementRefPredicate[op]({ ...ctx, expr } as any) ?? ctx.stage
|
|
72
|
+
}
|
|
73
73
|
default:
|
|
74
74
|
nonexhaustive(expr)
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
function processRelationtPredicate(
|
|
78
|
-
expr:
|
|
78
|
+
expr: ModelLayer.AnyRelationExpr,
|
|
79
79
|
op: 'include' | 'exclude',
|
|
80
|
-
ctx: Omit<PredicateCtx<
|
|
80
|
+
ctx: Omit<PredicateCtx<ModelLayer.AnyRelationExpr>, 'expr'>,
|
|
81
81
|
): Stage {
|
|
82
82
|
switch (true) {
|
|
83
|
-
case
|
|
83
|
+
case ModelLayer.RelationExpr.isCustom(expr): {
|
|
84
84
|
if (op === 'include') {
|
|
85
|
-
return processRelationtPredicate(expr.customRelation.
|
|
85
|
+
return processRelationtPredicate(expr.customRelation.expr, op, ctx)
|
|
86
86
|
}
|
|
87
87
|
return ctx.stage
|
|
88
88
|
}
|
|
89
|
-
case
|
|
89
|
+
case ModelLayer.RelationExpr.isWhere(expr): {
|
|
90
90
|
const where = whereOperatorAsPredicate(expr.where.condition)
|
|
91
91
|
const filterRelations = (relations: ReadonlySet<RelationshipModel>) => {
|
|
92
92
|
return new Set(filter([...relations], where))
|
|
@@ -104,16 +104,16 @@ function processRelationtPredicate(
|
|
|
104
104
|
filterWhere,
|
|
105
105
|
})
|
|
106
106
|
}
|
|
107
|
-
case
|
|
107
|
+
case ModelLayer.RelationExpr.isInOut(expr): {
|
|
108
108
|
return InOutRelationPredicate[op]({ ...ctx, expr } as any) ?? ctx.stage
|
|
109
109
|
}
|
|
110
|
-
case
|
|
110
|
+
case ModelLayer.RelationExpr.isDirect(expr): {
|
|
111
111
|
return DirectRelationExprPredicate[op]({ ...ctx, expr } as any) ?? ctx.stage
|
|
112
112
|
}
|
|
113
|
-
case
|
|
113
|
+
case ModelLayer.RelationExpr.isOutgoing(expr): {
|
|
114
114
|
return OutgoingExprPredicate[op]({ ...ctx, expr } as any) ?? ctx.stage
|
|
115
115
|
}
|
|
116
|
-
case
|
|
116
|
+
case ModelLayer.RelationExpr.isIncoming(expr): {
|
|
117
117
|
return IncomingExprPredicate[op]({ ...ctx, expr } as any) ?? ctx.stage
|
|
118
118
|
}
|
|
119
119
|
default:
|
|
@@ -146,14 +146,14 @@ export function processPredicates<M extends AnyAux>(
|
|
|
146
146
|
for (const expr of exprs) {
|
|
147
147
|
let stage = op === 'include' ? memory.stageInclude(expr) : memory.stageExclude(expr)
|
|
148
148
|
switch (true) {
|
|
149
|
-
case
|
|
149
|
+
case ModelLayer.isAnyFqnExpr(expr):
|
|
150
150
|
stage = processElementPredicate(expr, op, {
|
|
151
151
|
...ctx,
|
|
152
152
|
stage,
|
|
153
153
|
memory,
|
|
154
154
|
} as any) ?? stage
|
|
155
155
|
break
|
|
156
|
-
case
|
|
156
|
+
case ModelLayer.isAnyRelationExpr(expr):
|
|
157
157
|
stage = processRelationtPredicate(expr, op, {
|
|
158
158
|
...ctx,
|
|
159
159
|
stage,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ElementKind
|
|
1
|
+
import { ElementKind } from '../../../types/element'
|
|
2
|
+
import { type NodeId, type ViewRuleGroup } from '../../../types/view'
|
|
2
3
|
import type { Elem } from '../_types'
|
|
3
4
|
|
|
4
5
|
export class NodesGroup {
|
|
@@ -8,7 +9,7 @@ export class NodesGroup {
|
|
|
8
9
|
public readonly id: NodeId,
|
|
9
10
|
public readonly viewRule: ViewRuleGroup,
|
|
10
11
|
public readonly parent: NodeId | null = null,
|
|
11
|
-
public readonly elements: ReadonlySet<Elem> = new Set<Elem>()
|
|
12
|
+
public readonly elements: ReadonlySet<Elem> = new Set<Elem>(),
|
|
12
13
|
) {
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -21,7 +22,7 @@ export class NodesGroup {
|
|
|
21
22
|
this.id,
|
|
22
23
|
this.viewRule,
|
|
23
24
|
this.parent,
|
|
24
|
-
elements
|
|
25
|
+
elements,
|
|
25
26
|
)
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { nonNullable } from '../../../errors'
|
|
2
2
|
import type { ConnectionModel } from '../../../model/connection'
|
|
3
3
|
import type { ElementModel } from '../../../model/ElementModel'
|
|
4
|
-
import type {
|
|
4
|
+
import type { ModelLayer } from '../../../types/expression-v2-model'
|
|
5
|
+
import type { NodeId, ViewRuleGroup } from '../../../types/view'
|
|
5
6
|
import { Stack } from '../../../utils/mnemonist'
|
|
6
7
|
import { type ComputeCtx, type CtxElement, type MutableState, type StageExpression, AbstractMemory } from '../../memory'
|
|
7
8
|
import { NodesGroup } from './NodeGroup'
|
|
@@ -15,7 +16,7 @@ export interface Ctx extends
|
|
|
15
16
|
Memory<Ctx>,
|
|
16
17
|
StageInclude<Ctx>,
|
|
17
18
|
StageExclude,
|
|
18
|
-
Expression
|
|
19
|
+
ModelLayer.Expression
|
|
19
20
|
>
|
|
20
21
|
{
|
|
21
22
|
MutableState: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dropWhile, forEach, pipe, take, zip } from 'remeda'
|
|
2
|
-
import { Expr } from '../../..'
|
|
3
2
|
import { findConnection, findConnectionsBetween } from '../../../model/connection/model'
|
|
3
|
+
import { ModelLayer } from '../../../types/expression-v2-model'
|
|
4
4
|
import { difference, isAncestor, isIterable } from '../../../utils'
|
|
5
5
|
import { toArray } from '../../../utils/iterable'
|
|
6
6
|
import { type CtxConnection, type StageExpression, AbstractStageInclude } from '../../memory'
|
|
@@ -62,7 +62,7 @@ export class StageInclude<C extends Ctx = Ctx> extends AbstractStageInclude<C> {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
protected override processConnections(connections: CtxConnection<Ctx>[]) {
|
|
65
|
-
if (
|
|
65
|
+
if (ModelLayer.isAnyRelationExpr(this.expression)) {
|
|
66
66
|
return connections
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { anyPass } from 'remeda'
|
|
2
2
|
import { nonexhaustive } from '../../../errors'
|
|
3
|
-
import type { LikeC4Model } from '../../../model'
|
|
4
|
-
import
|
|
3
|
+
import type { LikeC4Model } from '../../../model/LikeC4Model'
|
|
4
|
+
import { ModelLayer } from '../../../types/expression-v2-model'
|
|
5
5
|
import { isDescendantOf } from '../../../utils/fqn'
|
|
6
6
|
import { ifilter, toArray } from '../../../utils/iterable'
|
|
7
7
|
import type { Elem, Memory, PredicateCtx } from '../_types'
|
|
@@ -10,33 +10,34 @@ import type { Elem, Memory, PredicateCtx } from '../_types'
|
|
|
10
10
|
* Resolve elements from the model based on the given expression
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export function resolveElements(model: LikeC4Model, expr:
|
|
13
|
+
export function resolveElements(model: LikeC4Model, expr: ModelLayer.FqnExpr.NonWildcard): Elem[] {
|
|
14
14
|
switch (true) {
|
|
15
|
-
case
|
|
16
|
-
|
|
15
|
+
case ModelLayer.FqnExpr.isElementKindExpr(expr): {
|
|
16
|
+
return [...ifilter(model.elements(), el => {
|
|
17
|
+
return expr.isEqual === (el.kind === expr.elementKind)
|
|
18
|
+
})]
|
|
19
|
+
}
|
|
20
|
+
case ModelLayer.FqnExpr.isElementTagExpr(expr): {
|
|
21
|
+
return [...ifilter(model.elements(), el => {
|
|
22
|
+
return expr.isEqual === el.tags.includes(expr.elementTag)
|
|
23
|
+
})]
|
|
24
|
+
}
|
|
25
|
+
case expr.selector === 'expanded': {
|
|
26
|
+
const element = model.element(ModelLayer.FqnRef.toFqn(expr.ref))
|
|
17
27
|
return [
|
|
18
28
|
element,
|
|
19
29
|
...element.children(),
|
|
20
30
|
]
|
|
21
31
|
}
|
|
22
|
-
case
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
children = toArray(element.children())
|
|
27
|
-
} else if (expr.isDescendants) {
|
|
28
|
-
children = toArray(element.descendants())
|
|
29
|
-
}
|
|
32
|
+
case expr.selector === 'children':
|
|
33
|
+
case expr.selector === 'descendants': {
|
|
34
|
+
const element = model.element(ModelLayer.FqnRef.toFqn(expr.ref))
|
|
35
|
+
let children = expr.selector === 'children' ? toArray(element.children()) : toArray(element.descendants())
|
|
30
36
|
return children && children.length > 0 ? children : [element]
|
|
31
37
|
}
|
|
32
|
-
case
|
|
33
|
-
return [
|
|
34
|
-
|
|
35
|
-
})]
|
|
36
|
-
case Expr.isElementTagExpr(expr):
|
|
37
|
-
return [...ifilter(model.elements(), el => {
|
|
38
|
-
return expr.isEqual === el.tags.includes(expr.elementTag)
|
|
39
|
-
})]
|
|
38
|
+
case ModelLayer.FqnExpr.isModelRef(expr): {
|
|
39
|
+
return [model.element(ModelLayer.FqnRef.toFqn(expr.ref))]
|
|
40
|
+
}
|
|
40
41
|
default:
|
|
41
42
|
nonexhaustive(expr)
|
|
42
43
|
}
|
|
@@ -69,15 +70,15 @@ export function includeDescendantsFromMemory(elements: Elem[], memory: Memory):
|
|
|
69
70
|
* Combination of `resolveElements` and `includeDescendantsFromMemory`
|
|
70
71
|
*/
|
|
71
72
|
export function resolveAndIncludeFromMemory(
|
|
72
|
-
nonWildcard:
|
|
73
|
+
nonWildcard: ModelLayer.FqnExpr.NonWildcard,
|
|
73
74
|
{ memory, model }: Pick<PredicateCtx, 'model' | 'memory'>,
|
|
74
75
|
): Elem[] {
|
|
75
76
|
const resolved = resolveElements(model, nonWildcard)
|
|
76
77
|
// We include from memory only if the expression is:
|
|
77
78
|
// - expanded element
|
|
78
79
|
// - element reference with or with children (but not descendants - they are already included)
|
|
79
|
-
if (
|
|
80
|
-
if (nonWildcard.
|
|
80
|
+
if (ModelLayer.FqnExpr.isModelRef(nonWildcard)) {
|
|
81
|
+
if (nonWildcard.selector === 'descendants') {
|
|
81
82
|
return resolved
|
|
82
83
|
}
|
|
83
84
|
return includeDescendantsFromMemory(resolved, memory)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { findConnectionsWithin } from '../../../model/connection/model'
|
|
2
|
-
import
|
|
2
|
+
import { ModelLayer } from '../../../types/expression-v2-model'
|
|
3
3
|
import type { Elem, PredicateExecutor } from '../_types'
|
|
4
|
+
import { resolveElements } from './_utils'
|
|
4
5
|
|
|
5
|
-
export const ExpandedElementPredicate: PredicateExecutor<
|
|
6
|
+
export const ExpandedElementPredicate: PredicateExecutor<ModelLayer.FqnExpr.ModelRef> = {
|
|
6
7
|
include: ({ expr, model, stage, where }) => {
|
|
7
|
-
const parent = model.element(expr.
|
|
8
|
+
const parent = model.element(ModelLayer.FqnRef.toFqn(expr.ref))
|
|
8
9
|
if (where(parent)) {
|
|
9
10
|
stage.addExplicit(parent)
|
|
10
11
|
stage.connectWithExisting(parent)
|
|
@@ -21,13 +22,9 @@ export const ExpandedElementPredicate: PredicateExecutor<Expr.ExpandedElementExp
|
|
|
21
22
|
stage.addConnections(findConnectionsWithin(expanded))
|
|
22
23
|
return stage
|
|
23
24
|
},
|
|
24
|
-
exclude: ({ expr, model, stage,
|
|
25
|
-
const
|
|
26
|
-
const elements = [
|
|
27
|
-
parent,
|
|
28
|
-
...parent.children()
|
|
29
|
-
].filter(where)
|
|
25
|
+
exclude: ({ expr, model, stage, filterWhere }) => {
|
|
26
|
+
const elements = filterWhere(resolveElements(model, expr))
|
|
30
27
|
stage.exclude(elements)
|
|
31
28
|
return stage
|
|
32
|
-
}
|
|
29
|
+
},
|
|
33
30
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { findConnectionsWithin } from '../../../model/connection/model'
|
|
2
|
-
import
|
|
2
|
+
import type { ModelLayer } from '../../../types/expression-v2-model'
|
|
3
3
|
import type { PredicateExecutor } from '../_types'
|
|
4
4
|
import { resolveElements } from './_utils'
|
|
5
5
|
|
|
6
|
-
export const ElementKindOrTagPredicate: PredicateExecutor<
|
|
6
|
+
export const ElementKindOrTagPredicate: PredicateExecutor<
|
|
7
|
+
ModelLayer.FqnExpr.ElementKindExpr | ModelLayer.FqnExpr.ElementTagExpr
|
|
8
|
+
> = {
|
|
7
9
|
include: ({ expr, model, stage, filterWhere }) => {
|
|
8
10
|
const elements = filterWhere(resolveElements(model, expr))
|
|
9
11
|
if (elements.length === 0) {
|
|
@@ -22,5 +24,5 @@ export const ElementKindOrTagPredicate: PredicateExecutor<Expr.ElementKindExpr |
|
|
|
22
24
|
stage.exclude(elements)
|
|
23
25
|
|
|
24
26
|
return stage
|
|
25
|
-
}
|
|
27
|
+
},
|
|
26
28
|
}
|