@likec4/core 1.27.3 → 1.28.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/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.RjpTh3vE.mjs → core.Bjl6Kmc8.mjs} +260 -168
- 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/types/index.d.mts +4 -4
- package/dist/types/index.mjs +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/package.json +6 -6
- 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 +44 -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
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isString } from 'remeda'
|
|
2
2
|
import type { IsStringLiteral } from 'type-fest/source/is-literal'
|
|
3
|
-
import { type
|
|
3
|
+
import { type ExpressionV2 } from '../types/expression-v2'
|
|
4
|
+
import { type Fqn } from '../types/scalars'
|
|
4
5
|
import type { AnyTypes, Invalid, Types } from './_types'
|
|
5
6
|
import type { LikeC4ViewBuilder, ViewPredicate } from './Builder.view-common'
|
|
6
7
|
import type { ViewsBuilder } from './Builder.views'
|
|
7
8
|
|
|
8
|
-
export interface ElementViewBuilder<T extends AnyTypes> extends LikeC4ViewBuilder<T, T['Fqn'],
|
|
9
|
+
export interface ElementViewBuilder<T extends AnyTypes> extends LikeC4ViewBuilder<T, T['Fqn'], Types.ToExpression<T>> {
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export type ElementViewRulesBuilder<T extends AnyTypes> = (b: ElementViewBuilder<T>) => ElementViewBuilder<T>
|
|
@@ -125,13 +126,15 @@ export interface TypedAddViewOfHelper<A extends AnyTypes> {
|
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
// To hook types
|
|
128
|
-
const asTypedExpr = (expr:
|
|
129
|
-
return expr as
|
|
129
|
+
const asTypedExpr = (expr: ExpressionV2): ExpressionV2 => {
|
|
130
|
+
return expr as ExpressionV2
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
export function $expr<Types extends AnyTypes>(
|
|
133
|
+
export function $expr<Types extends AnyTypes>(
|
|
134
|
+
expr: ViewPredicate.Expression<Types> | ExpressionV2,
|
|
135
|
+
): ExpressionV2 {
|
|
133
136
|
if (!isString(expr)) {
|
|
134
|
-
return expr as
|
|
137
|
+
return expr as ExpressionV2
|
|
135
138
|
}
|
|
136
139
|
if (expr === '*') {
|
|
137
140
|
return asTypedExpr({ wildcard: true })
|
|
@@ -168,22 +171,31 @@ export function $expr<Types extends AnyTypes>(expr: ViewPredicate.Expression<Typ
|
|
|
168
171
|
}
|
|
169
172
|
if (expr.endsWith('._')) {
|
|
170
173
|
return asTypedExpr({
|
|
171
|
-
|
|
174
|
+
ref: {
|
|
175
|
+
model: expr.replace('._', '') as Fqn,
|
|
176
|
+
},
|
|
177
|
+
selector: 'expanded',
|
|
172
178
|
})
|
|
173
179
|
}
|
|
174
|
-
if (expr.endsWith('
|
|
180
|
+
if (expr.endsWith('.**')) {
|
|
175
181
|
return asTypedExpr({
|
|
176
|
-
|
|
177
|
-
|
|
182
|
+
ref: {
|
|
183
|
+
model: expr.replace('.**', '') as Fqn,
|
|
184
|
+
},
|
|
185
|
+
selector: 'descendants',
|
|
178
186
|
})
|
|
179
187
|
}
|
|
180
|
-
if (expr.endsWith('
|
|
188
|
+
if (expr.endsWith('.*')) {
|
|
181
189
|
return asTypedExpr({
|
|
182
|
-
|
|
183
|
-
|
|
190
|
+
ref: {
|
|
191
|
+
model: expr.replace('.*', '') as Fqn,
|
|
192
|
+
},
|
|
193
|
+
selector: 'children',
|
|
184
194
|
})
|
|
185
195
|
}
|
|
186
196
|
return asTypedExpr({
|
|
187
|
-
|
|
197
|
+
ref: {
|
|
198
|
+
model: expr as any as Fqn,
|
|
199
|
+
},
|
|
188
200
|
})
|
|
189
201
|
}
|
|
@@ -99,6 +99,7 @@ exports[`Builder (style1) > should build nested elements and relTo 1`] = `
|
|
|
99
99
|
"predicates": {},
|
|
100
100
|
"styles": {},
|
|
101
101
|
},
|
|
102
|
+
"imports": {},
|
|
102
103
|
"relations": {
|
|
103
104
|
"rel1": {
|
|
104
105
|
"id": "rel1",
|
|
@@ -192,6 +193,7 @@ exports[`Builder (style1) > should build view 1`] = `
|
|
|
192
193
|
"predicates": {},
|
|
193
194
|
"styles": {},
|
|
194
195
|
},
|
|
196
|
+
"imports": {},
|
|
195
197
|
"relations": {},
|
|
196
198
|
"specification": {
|
|
197
199
|
"deployments": {},
|
|
@@ -237,8 +239,10 @@ exports[`Builder (style1) > should build view 1`] = `
|
|
|
237
239
|
{
|
|
238
240
|
"include": [
|
|
239
241
|
{
|
|
240
|
-
"
|
|
241
|
-
|
|
242
|
+
"ref": {
|
|
243
|
+
"model": "c2",
|
|
244
|
+
},
|
|
245
|
+
"selector": "children",
|
|
242
246
|
},
|
|
243
247
|
],
|
|
244
248
|
},
|
|
@@ -256,7 +260,10 @@ exports[`Builder (style1) > should build view 1`] = `
|
|
|
256
260
|
{
|
|
257
261
|
"include": [
|
|
258
262
|
{
|
|
259
|
-
"
|
|
263
|
+
"ref": {
|
|
264
|
+
"model": "c3",
|
|
265
|
+
},
|
|
266
|
+
"selector": "expanded",
|
|
260
267
|
},
|
|
261
268
|
],
|
|
262
269
|
},
|
|
@@ -329,6 +336,7 @@ exports[`Builder (style1) > should build viewOf 1`] = `
|
|
|
329
336
|
"predicates": {},
|
|
330
337
|
"styles": {},
|
|
331
338
|
},
|
|
339
|
+
"imports": {},
|
|
332
340
|
"relations": {},
|
|
333
341
|
"specification": {
|
|
334
342
|
"deployments": {},
|
|
@@ -357,8 +365,10 @@ exports[`Builder (style1) > should build viewOf 1`] = `
|
|
|
357
365
|
"include": [
|
|
358
366
|
{
|
|
359
367
|
"inout": {
|
|
360
|
-
"
|
|
361
|
-
|
|
368
|
+
"ref": {
|
|
369
|
+
"model": "c2.c3",
|
|
370
|
+
},
|
|
371
|
+
"selector": "children",
|
|
362
372
|
},
|
|
363
373
|
},
|
|
364
374
|
],
|
|
@@ -367,11 +377,16 @@ exports[`Builder (style1) > should build viewOf 1`] = `
|
|
|
367
377
|
"exclude": [
|
|
368
378
|
{
|
|
369
379
|
"source": {
|
|
370
|
-
"
|
|
380
|
+
"ref": {
|
|
381
|
+
"model": "c1",
|
|
382
|
+
},
|
|
383
|
+
"selector": "expanded",
|
|
371
384
|
},
|
|
372
385
|
"target": {
|
|
373
|
-
"
|
|
374
|
-
|
|
386
|
+
"ref": {
|
|
387
|
+
"model": "c2.c3",
|
|
388
|
+
},
|
|
389
|
+
"selector": "children",
|
|
375
390
|
},
|
|
376
391
|
},
|
|
377
392
|
],
|
|
@@ -105,6 +105,7 @@ exports[`Builder (style 2) > should build 1`] = `
|
|
|
105
105
|
"predicates": {},
|
|
106
106
|
"styles": {},
|
|
107
107
|
},
|
|
108
|
+
"imports": {},
|
|
108
109
|
"relations": {},
|
|
109
110
|
"specification": {
|
|
110
111
|
"deployments": {
|
|
@@ -143,8 +144,10 @@ exports[`Builder (style 2) > should build 1`] = `
|
|
|
143
144
|
"wildcard": true,
|
|
144
145
|
},
|
|
145
146
|
"target": {
|
|
146
|
-
"
|
|
147
|
-
|
|
147
|
+
"ref": {
|
|
148
|
+
"model": "cloud",
|
|
149
|
+
},
|
|
150
|
+
"selector": "descendants",
|
|
148
151
|
},
|
|
149
152
|
},
|
|
150
153
|
],
|
|
@@ -185,8 +188,10 @@ exports[`Builder (style 2) > should build 1`] = `
|
|
|
185
188
|
{
|
|
186
189
|
"include": [
|
|
187
190
|
{
|
|
188
|
-
"
|
|
189
|
-
|
|
191
|
+
"ref": {
|
|
192
|
+
"model": "cloud",
|
|
193
|
+
},
|
|
194
|
+
"selector": "children",
|
|
190
195
|
},
|
|
191
196
|
],
|
|
192
197
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type FqnExpr, type RelationExpr, whereOperatorAsPredicate } from '../../../types'
|
|
2
|
+
import type { PredicateExecutor } from '../_types'
|
|
3
|
+
import type { StageExclude, StageInclude } from '../memory'
|
|
4
|
+
import { predicateToPatch } from './utils'
|
|
5
|
+
|
|
6
|
+
// relation matches the condition
|
|
7
|
+
export const WhereDeploymentRefPredicate: PredicateExecutor<FqnExpr.Where> = {
|
|
8
|
+
include: ({ expr, model, memory, stage }) => {
|
|
9
|
+
const where = whereOperatorAsPredicate(expr.where.condition)
|
|
10
|
+
|
|
11
|
+
return predicateToPatch('include', { expr: expr.where.expr, model, stage, memory, where }) as StageInclude
|
|
12
|
+
},
|
|
13
|
+
exclude: ({ expr, model, memory, stage }) => {
|
|
14
|
+
const where = whereOperatorAsPredicate(expr.where.condition)
|
|
15
|
+
|
|
16
|
+
return predicateToPatch('exclude', { expr: expr.where.expr, model, stage, memory, where }) as StageExclude
|
|
17
|
+
},
|
|
18
|
+
}
|
|
@@ -40,6 +40,12 @@ const resolveWildcard = (model: LikeC4DeploymentModel, nonWildcard: FqnExpr.Depl
|
|
|
40
40
|
|
|
41
41
|
export const DirectRelationPredicate: PredicateExecutor<RelationExpr.Direct> = {
|
|
42
42
|
include: ({ expr: { source, target, isBidirectional = false }, model, stage, where }) => {
|
|
43
|
+
if (FqnExpr.isElementTagExpr(source) || FqnExpr.isElementKindExpr(source)) {
|
|
44
|
+
throw new Error('element kind and tag expressions are not supported in include')
|
|
45
|
+
}
|
|
46
|
+
if (FqnExpr.isElementTagExpr(target) || FqnExpr.isElementKindExpr(target)) {
|
|
47
|
+
throw new Error('element kind and tag expressions are not supported in include')
|
|
48
|
+
}
|
|
43
49
|
invariant(!FqnExpr.isModelRef(source), 'Invalid source model ref in direct relation')
|
|
44
50
|
invariant(!FqnExpr.isModelRef(target), 'Invalid target model ref in direct relation')
|
|
45
51
|
const sourceIsWildcard = FqnExpr.isWildcard(source)
|
|
@@ -36,6 +36,9 @@ export const InOutRelationPredicate: PredicateExecutor<RelationExpr.InOut> = {
|
|
|
36
36
|
return stage
|
|
37
37
|
},
|
|
38
38
|
exclude: ({ expr, model, memory, stage, where }) => {
|
|
39
|
+
if (FqnExpr.isElementTagExpr(expr.inout) || FqnExpr.isElementKindExpr(expr.inout)) {
|
|
40
|
+
throw new Error('element kind and tag expressions are not supported in exclude')
|
|
41
|
+
}
|
|
39
42
|
// Exclude all connections that have model relationshps with the elements
|
|
40
43
|
if (FqnExpr.isModelRef(expr.inout)) {
|
|
41
44
|
const elements = resolveModelElements(model, expr.inout)
|
|
@@ -38,6 +38,9 @@ export const IncomingRelationPredicate: PredicateExecutor<RelationExpr.Incoming>
|
|
|
38
38
|
return stage
|
|
39
39
|
},
|
|
40
40
|
exclude: ({ expr, model, memory, stage, where }) => {
|
|
41
|
+
if (FqnExpr.isElementTagExpr(expr.incoming) || FqnExpr.isElementKindExpr(expr.incoming)) {
|
|
42
|
+
throw new Error('element kind and tag expressions are not supported in exclude')
|
|
43
|
+
}
|
|
41
44
|
// Exclude all connections that have model relationshps with the elements
|
|
42
45
|
if (FqnExpr.isModelRef(expr.incoming)) {
|
|
43
46
|
const excludedRelations = resolveAllImcomingRelations(model, expr.incoming)
|
|
@@ -39,6 +39,9 @@ export const OutgoingRelationPredicate: PredicateExecutor<RelationExpr.Outgoing>
|
|
|
39
39
|
return stage
|
|
40
40
|
},
|
|
41
41
|
exclude: ({ expr, model, memory, stage, where }) => {
|
|
42
|
+
if (FqnExpr.isElementTagExpr(expr.outgoing) || FqnExpr.isElementKindExpr(expr.outgoing)) {
|
|
43
|
+
throw new Error('element kind and tag expressions are not supported in exclude')
|
|
44
|
+
}
|
|
42
45
|
// Exclude all connections that have model relationshps with the elements
|
|
43
46
|
if (FqnExpr.isModelRef(expr.outgoing)) {
|
|
44
47
|
const excludedRelations = resolveAllOutgoingRelations(model, expr.outgoing)
|
|
@@ -15,6 +15,7 @@ import { hasIntersection, intersection } from '../../../utils/set'
|
|
|
15
15
|
import type { ExcludePredicateCtx, PredicateCtx } from '../_types'
|
|
16
16
|
import type { StageExclude, StageInclude } from '../memory'
|
|
17
17
|
import { DeploymentRefPredicate } from './deploymentRefs'
|
|
18
|
+
import { WhereDeploymentRefPredicate } from './deploymentRefs-where'
|
|
18
19
|
import { DirectRelationPredicate } from './relation-direct'
|
|
19
20
|
import { InOutRelationPredicate } from './relation-in-out'
|
|
20
21
|
import { IncomingRelationPredicate } from './relation-incoming'
|
|
@@ -30,14 +31,22 @@ export function predicateToPatch(
|
|
|
30
31
|
{ expr, where, ...ctx }: PredicateCtx,
|
|
31
32
|
): StageExclude | StageInclude | undefined {
|
|
32
33
|
switch (true) {
|
|
34
|
+
case FqnExpr.isElementTagExpr(expr):
|
|
35
|
+
case FqnExpr.isElementKindExpr(expr):
|
|
36
|
+
throw new Error('element kind and tag expressions are not supported in deployment view rules')
|
|
37
|
+
case RelationExpr.isCustom(expr):
|
|
38
|
+
case FqnExpr.isCustom(expr):
|
|
33
39
|
case FqnExpr.isModelRef(expr):
|
|
34
40
|
// Ignore model refs in deployment view
|
|
35
41
|
return undefined
|
|
42
|
+
case FqnExpr.isWhere(expr):
|
|
43
|
+
return WhereDeploymentRefPredicate[op]({ ...ctx, expr, where } as any)
|
|
44
|
+
case RelationExpr.isWhere(expr):
|
|
45
|
+
return WhereRelationPredicate[op]({ ...ctx, expr, where } as any)
|
|
36
46
|
case FqnExpr.isDeploymentRef(expr):
|
|
37
47
|
return DeploymentRefPredicate[op]({ ...ctx, expr, where } as any)
|
|
38
48
|
case FqnExpr.isWildcard(expr):
|
|
39
49
|
return WildcardPredicate[op]({ ...ctx, expr, where } as any)
|
|
40
|
-
|
|
41
50
|
case RelationExpr.isDirect(expr):
|
|
42
51
|
return DirectRelationPredicate[op]({ ...ctx, expr, where } as any)
|
|
43
52
|
case RelationExpr.isInOut(expr):
|
|
@@ -46,8 +55,6 @@ export function predicateToPatch(
|
|
|
46
55
|
return OutgoingRelationPredicate[op]({ ...ctx, expr, where } as any)
|
|
47
56
|
case RelationExpr.isIncoming(expr):
|
|
48
57
|
return IncomingRelationPredicate[op]({ ...ctx, expr, where } as any)
|
|
49
|
-
case RelationExpr.isWhere(expr):
|
|
50
|
-
return WhereRelationPredicate[op]({ ...ctx, expr, where } as any)
|
|
51
58
|
default:
|
|
52
59
|
nonexhaustive(expr)
|
|
53
60
|
}
|
|
@@ -7,18 +7,18 @@ import type { AnyAux } from '../../model/types'
|
|
|
7
7
|
import {
|
|
8
8
|
type ComputedEdge,
|
|
9
9
|
type ComputedNode,
|
|
10
|
-
DefaultArrowType,
|
|
11
10
|
type DeploymentNodeKind,
|
|
12
11
|
type DeploymentViewRule,
|
|
13
12
|
type Fqn,
|
|
14
|
-
FqnExpr,
|
|
15
|
-
isViewRuleStyle,
|
|
16
13
|
type NonEmptyArray,
|
|
17
14
|
type Tag,
|
|
15
|
+
DefaultArrowType,
|
|
16
|
+
FqnExpr,
|
|
17
|
+
isViewRuleStyle,
|
|
18
18
|
} from '../../types'
|
|
19
19
|
import { nameFromFqn, parentFqn } from '../../utils'
|
|
20
20
|
import { applyViewRuleStyle } from '../utils/applyViewRuleStyles'
|
|
21
|
-
import {
|
|
21
|
+
import { type ComputedNodeSource, buildComputedNodes } from '../utils/buildComputedNodes'
|
|
22
22
|
import { mergePropsFromRelationships } from '../utils/merge-props-from-relationships'
|
|
23
23
|
import { uniqueTags } from '../utils/uniqueTags'
|
|
24
24
|
import type { Elem, Memory } from './_types'
|
|
@@ -67,6 +67,9 @@ export function deploymentExpressionToPredicate<T extends { id: string; modelRef
|
|
|
67
67
|
if (FqnExpr.isWildcard(target)) {
|
|
68
68
|
return () => true
|
|
69
69
|
}
|
|
70
|
+
if (FqnExpr.isElementTagExpr(target) || FqnExpr.isElementKindExpr(target)) {
|
|
71
|
+
throw new Error('element kind and tag expressions are not supported in deployment view rules')
|
|
72
|
+
}
|
|
70
73
|
if (FqnExpr.isDeploymentRef(target)) {
|
|
71
74
|
const fqn = target.ref.deployment
|
|
72
75
|
if (target.selector === 'expanded') {
|
|
@@ -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
|
}
|