@likec4/core 1.27.2 → 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.
Files changed (71) hide show
  1. package/dist/builder/index.d.mts +6 -6
  2. package/dist/builder/index.mjs +23 -13
  3. package/dist/compute-view/index.d.mts +3 -3
  4. package/dist/compute-view/index.mjs +3 -3
  5. package/dist/compute-view/relationships-view/index.d.mts +3 -3
  6. package/dist/index.d.mts +6 -6
  7. package/dist/index.mjs +2 -2
  8. package/dist/model/index.d.mts +6 -6
  9. package/dist/model/index.mjs +1 -1
  10. package/dist/shared/{core.RjpTh3vE.mjs → core.Bjl6Kmc8.mjs} +260 -168
  11. package/dist/shared/{core.C9JdFlAd.d.mts → core.CZR9J1Qx.d.mts} +2 -2
  12. package/dist/shared/{core.C7IN6igU.d.mts → core.CiFKryGW.d.mts} +7 -2
  13. package/dist/shared/{core.HKn0jlo_.d.mts → core.D2830qgg.d.mts} +1 -1
  14. package/dist/shared/{core.z6g06scf.d.mts → core.DJvmfnEi.d.mts} +484 -189
  15. package/dist/shared/{core.BMep80lJ.mjs → core.DgfwjBtu.mjs} +198 -87
  16. package/dist/shared/core.SjLhMA7a.d.mts +62 -0
  17. package/dist/types/index.d.mts +4 -4
  18. package/dist/types/index.mjs +1 -1
  19. package/dist/utils/index.d.mts +2 -2
  20. package/package.json +6 -6
  21. package/src/builder/Builder.ts +1 -0
  22. package/src/builder/Builder.view-common.ts +10 -10
  23. package/src/builder/Builder.view-element.ts +26 -14
  24. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +23 -8
  25. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +9 -4
  26. package/src/compute-view/deployment-view/predicates/deploymentRefs-where.ts +18 -0
  27. package/src/compute-view/deployment-view/predicates/relation-direct.ts +6 -0
  28. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +3 -0
  29. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +3 -0
  30. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +3 -0
  31. package/src/compute-view/deployment-view/predicates/utils.ts +10 -3
  32. package/src/compute-view/deployment-view/utils.ts +7 -4
  33. package/src/compute-view/element-view/__test__/fixture.ts +72 -65
  34. package/src/compute-view/element-view/_types.ts +13 -9
  35. package/src/compute-view/element-view/compute.ts +27 -27
  36. package/src/compute-view/element-view/memory/NodeGroup.ts +4 -3
  37. package/src/compute-view/element-view/memory/memory.ts +3 -2
  38. package/src/compute-view/element-view/memory/stage-include.ts +2 -2
  39. package/src/compute-view/element-view/predicates/_utils.ts +25 -24
  40. package/src/compute-view/element-view/predicates/element-expand.ts +7 -10
  41. package/src/compute-view/element-view/predicates/element-kind-tag.ts +5 -3
  42. package/src/compute-view/element-view/predicates/element-ref.ts +7 -19
  43. package/src/compute-view/element-view/predicates/relation-direct.ts +15 -13
  44. package/src/compute-view/element-view/predicates/relation-in-out.ts +5 -6
  45. package/src/compute-view/element-view/predicates/relation-in.ts +36 -32
  46. package/src/compute-view/element-view/predicates/relation-out.ts +37 -33
  47. package/src/compute-view/element-view/predicates/wildcard.ts +2 -2
  48. package/src/compute-view/utils/applyCustomElementProperties.ts +9 -4
  49. package/src/compute-view/utils/applyCustomRelationProperties.ts +10 -7
  50. package/src/compute-view/utils/elementExpressionToPredicate.ts +27 -26
  51. package/src/compute-view/utils/link-nodes-with-edges.ts +1 -1
  52. package/src/compute-view/utils/relationExpressionToPredicates.ts +10 -17
  53. package/src/compute-view/utils/uniqueTags.ts +3 -3
  54. package/src/index.ts +0 -2
  55. package/src/model/ElementModel.ts +25 -6
  56. package/src/model/LikeC4Model.ts +44 -6
  57. package/src/model/RelationModel.ts +4 -2
  58. package/src/model/view/LikeC4ViewModel.ts +3 -2
  59. package/src/types/_common.ts +0 -4
  60. package/src/types/deployments.ts +3 -2
  61. package/src/types/element.ts +2 -10
  62. package/src/types/expression-v2-model.ts +314 -0
  63. package/src/types/expression-v2.ts +238 -30
  64. package/src/types/index.ts +15 -46
  65. package/src/types/model-data.ts +4 -1
  66. package/src/types/relation.ts +2 -1
  67. package/src/types/scalars.ts +39 -0
  68. package/src/types/view-changes.ts +2 -1
  69. package/src/types/view.ts +10 -11
  70. package/dist/shared/core.30yYKXcZ.d.mts +0 -186
  71. 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 Expression as C4Expression, type Fqn } from '../types'
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'], C4Expression> {
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: C4Expression): C4Expression => {
129
- return expr as C4Expression
129
+ const asTypedExpr = (expr: ExpressionV2): ExpressionV2 => {
130
+ return expr as ExpressionV2
130
131
  }
131
132
 
132
- export function $expr<Types extends AnyTypes>(expr: ViewPredicate.Expression<Types> | C4Expression): C4Expression {
133
+ export function $expr<Types extends AnyTypes>(
134
+ expr: ViewPredicate.Expression<Types> | ExpressionV2,
135
+ ): ExpressionV2 {
133
136
  if (!isString(expr)) {
134
- return expr as C4Expression
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
- expanded: expr.replace('._', '') as Fqn,
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
- element: expr.replace('.*', '') as Fqn,
177
- isChildren: true,
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
- element: expr.replace('.**', '') as Fqn,
183
- isDescendants: true,
190
+ ref: {
191
+ model: expr.replace('.*', '') as Fqn,
192
+ },
193
+ selector: 'children',
184
194
  })
185
195
  }
186
196
  return asTypedExpr({
187
- element: expr as any as Fqn,
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
- "element": "c2",
241
- "isChildren": true,
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
- "expanded": "c3",
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
- "element": "c2.c3",
361
- "isChildren": true,
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
- "expanded": "c1",
380
+ "ref": {
381
+ "model": "c1",
382
+ },
383
+ "selector": "expanded",
371
384
  },
372
385
  "target": {
373
- "element": "c2.c3",
374
- "isChildren": true,
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
- "element": "cloud",
147
- "isDescendants": true,
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
- "element": "cloud",
189
- "isChildren": true,
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 { buildComputedNodes, type ComputedNodeSource } from '../utils/buildComputedNodes'
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
- isElementRef,
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
- title?: string
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: RelationExpr,
467
- props: Omit<C4CustomRelationExpr['customRelation'], 'relation'>,
468
- ): C4CustomRelationExpr {
443
+ relation: ModelLayer.RelationExprOrWhere,
444
+ props: Omit<ModelLayer.RelationExpr.Custom['customRelation'], 'expr'>,
445
+ ): ModelLayer.RelationExpr.Custom {
469
446
  return {
470
447
  customRelation: {
471
- relation: $expr(relation) as any,
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 | C4Expression,
455
+ expr: Expression,
479
456
  operator: WhereOperator<TestTag, string>,
480
- ): ElementWhereExpr | RelationWhereExpr {
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 | C4ElementExpression,
501
- ): C4InOutExpr {
489
+ expr: InOutExpr | ModelLayer.FqnExpr,
490
+ ): ModelLayer.RelationExpr.InOut {
502
491
  const innerExpression = !isString(expr)
503
- ? expr as C4Expression
504
- : $expr(expr.replace(/->/g, '').trim() as ElementRefExpr) as any
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 | C4ElementExpression,
511
- ): C4IncomingExpr {
499
+ expr: IncomingExpr | ModelLayer.FqnExpr,
500
+ ): ModelLayer.RelationExpr.Incoming {
512
501
  const innerExpression = !isString(expr)
513
- ? expr as C4Expression
514
- : $expr(expr.replace('-> ', '') as ElementRefExpr) as any
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 | C4ElementExpression,
521
- ): C4OutgoingExpr {
509
+ expr: OutgoingExpr | ModelLayer.FqnExpr,
510
+ ): ModelLayer.RelationExpr.Outgoing {
522
511
  const innerExpression = !isString(expr)
523
- ? expr as C4Expression
524
- : $expr(expr.replace(' ->', '') as ElementRefExpr) as any
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
- ): C4RelationExpr {
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 | C4Expression): C4Expression {
531
+ export function $expr(expr: Expression | ModelLayer.Expression): ModelLayer.Expression {
543
532
  if (!isString(expr)) {
544
- return expr as C4Expression
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
- expanded: expr.replace('._', '') as Fqn,
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
- element: expr.replace('.*', '') as Fqn,
566
- isChildren: true,
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
- element: expr.replace('.**', '') as Fqn,
572
- isDescendants: true,
565
+ ref: {
566
+ model: expr.replace('.**', '') as Fqn,
567
+ },
568
+ selector: 'descendants',
573
569
  }
574
570
  }
575
571
  return {
576
- element: expr as Fqn,
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<C4CustomRelationExpr['customRelation'], 'relation' | 'navigateTo'>
591
+ } & Omit<ModelLayer.RelationExpr.Custom['customRelation'], 'expr' | 'navigateTo'>
594
592
  }
595
- export function $include(expr: Expression | C4Expression, props?: CustomProps): ViewRulePredicate {
596
- let _expr = props?.where ? $where(expr, props.where) : $expr(expr)
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(expr: C4Expression, props?: CustomProps['with']): C4CustomRelationExpr | C4CustomElementExpr {
603
- if (isRelationExpression(expr) || isRelationWhere(expr)) {
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
- relation: expr,
610
+ expr,
607
611
  ...props as any,
608
612
  },
609
613
  }
610
- } else if (isElementRef(expr) || isElementWhere(expr)) {
614
+ } else if (ModelLayer.FqnExpr.is(expr) || ModelLayer.FqnExpr.isWhere(expr)) {
611
615
  return {
612
616
  custom: {
613
- expr: 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(expr: Expression | C4Expression, where?: WhereOperator<TestTag, string>): ViewRulePredicate {
622
- let _expr = where ? $where(expr, where) : $expr(expr)
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 C4ElementExpression],
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 { ElementExpression, Expression, RelationExpression } from '../../types/expression'
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 RelationExpression ? RelationshipWhere
32
- : Expr extends ElementExpression ? ElementWhere
31
+ where: Expr extends ModelLayer.RelationExpr ? RelationshipWhere
32
+ : Expr extends ModelLayer.FqnExpr ? ElementWhere
33
33
  : never
34
- filterWhere: Expr extends RelationExpression ? ConnectionWhereFilter
35
- : Expr extends ElementExpression ? ElementWhereFilter
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> extends PredicateCtx<Expr> {
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> extends PredicateCtx<Expr> {
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
  }