@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.
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.BpuZeqlX.d.mts → core.CZR9J1Qx.d.mts} +2 -2
  12. package/dist/shared/{core.Djro-kuQ.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.CFDwncxs.d.mts → core.DJvmfnEi.d.mts} +481 -186
  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 +7 -8
  70. package/dist/shared/core.30yYKXcZ.d.mts +0 -186
  71. package/src/types/expression.ts +0 -207
@@ -1,7 +1,6 @@
1
1
  export type {
2
2
  CustomColor,
3
3
  ExclusiveUnion,
4
- IconUrl,
5
4
  IteratorLike,
6
5
  KeysOf,
7
6
  NonEmptyArray,
@@ -9,10 +8,23 @@ export type {
9
8
  NTuple,
10
9
  Point,
11
10
  Predicate,
12
- ProjectId,
13
11
  XYPoint,
14
12
  } from './_common'
15
13
 
14
+ export {
15
+ AsFqn,
16
+ GlobalFqn,
17
+ isGlobalFqn,
18
+ splitGlobalFqn,
19
+ } from './scalars'
20
+
21
+ export type {
22
+ Fqn,
23
+ IconUrl,
24
+ ProjectId,
25
+ Tag,
26
+ } from './scalars'
27
+
16
28
  export { DeploymentElement } from './deployments'
17
29
  export type {
18
30
  DeployedInstance,
@@ -26,7 +38,6 @@ export type {
26
38
  } from './deployments'
27
39
 
28
40
  export {
29
- AsFqn,
30
41
  BorderStyles,
31
42
  DefaultElementShape,
32
43
  DefaultPaddingSize,
@@ -43,55 +54,13 @@ export type {
43
54
  ElementKindSpecificationStyle,
44
55
  ElementShape,
45
56
  ElementStyle,
46
- Fqn,
47
57
  Link,
48
- Tag,
49
58
  TagSpec,
50
59
  TypedElement,
51
60
  } from './element'
52
61
 
53
- export {
54
- isCustomElement,
55
- isCustomRelationExpr,
56
- isElement,
57
- isElementKindExpr,
58
- isElementPredicateExpr,
59
- isElementRef,
60
- isElementTagExpr,
61
- isElementWhere,
62
- isExpandedElementExpr,
63
- isIncoming,
64
- isInOut,
65
- isOutgoing,
66
- isRelation,
67
- isRelationExpression,
68
- isRelationPredicateExpr,
69
- isRelationWhere,
70
- isWildcard,
71
- } from './expression'
72
- export type {
73
- CustomElementExpr,
74
- CustomRelationExpr,
75
- DirectRelationExpr,
76
- ElementExpression,
77
- ElementKindExpr,
78
- ElementPredicateExpression,
79
- ElementRefExpr,
80
- ElementTagExpr,
81
- ElementWhereExpr,
82
- ExpandedElementExpr,
83
- Expression,
84
- IncomingExpr,
85
- InOutExpr,
86
- NonWilcard,
87
- OutgoingExpr,
88
- RelationExpression,
89
- RelationPredicateExpression,
90
- RelationWhereExpr,
91
- WildcardExpr,
92
- } from './expression'
93
-
94
62
  export { ExpressionV2, FqnExpr, FqnRef, RelationExpr } from './expression-v2'
63
+ export { ModelLayer } from './expression-v2-model'
95
64
 
96
65
  export type {
97
66
  GlobalDynamicPredicates,
@@ -1,12 +1,14 @@
1
+ import type { NonEmptyArray } from './_common'
1
2
  import type {
2
3
  DeploymentElement,
3
4
  DeploymentNodeKind,
4
5
  DeploymentNodeKindSpecification,
5
6
  DeploymentRelation,
6
7
  } from './deployments'
7
- import type { ElementKindSpecification, Tag, TypedElement } from './element'
8
+ import type { Element, ElementKindSpecification, TypedElement } from './element'
8
9
  import type { ModelGlobals } from './global'
9
10
  import type { ModelRelation, RelationId, RelationshipKindSpecification } from './relation'
11
+ import type { ProjectId, Tag } from './scalars'
10
12
  import type { ComputedView, DiagramView, LikeC4View } from './view'
11
13
 
12
14
  /**
@@ -50,6 +52,7 @@ export interface ParsedLikeC4ModelData<
50
52
  elements: Record<DeploymentFqns, DeploymentElement>
51
53
  relations: Record<RelationId, DeploymentRelation>
52
54
  }
55
+ imports: Record<ProjectId, NonEmptyArray<Element>>
53
56
  }
54
57
 
55
58
  export type AnyParsedLikeC4ModelData = ParsedLikeC4ModelData<any, any, any, any, any, any>
@@ -1,6 +1,7 @@
1
1
  import type { Tagged } from 'type-fest'
2
2
  import type { NonEmptyArray } from './_common'
3
- import type { Fqn, Link, Tag } from './element'
3
+ import type { Link } from './element'
4
+ import type { Fqn, Tag } from './scalars'
4
5
  import type { Color, ThemeColor } from './theme'
5
6
  import type { ViewId } from './view'
6
7
 
@@ -0,0 +1,39 @@
1
+ import { isTruthy } from 'remeda'
2
+ import type { Tagged } from 'type-fest'
3
+ import { invariant } from '../errors'
4
+
5
+ export type ProjectId = Tagged<string, 'ProjectID'>
6
+
7
+ export type IconUrl = Tagged<string, 'IconUrl'> | 'none'
8
+
9
+ // Full-qualified-name
10
+ export type Fqn<Id extends string = string> = Tagged<Id, 'Fqn'>
11
+
12
+ export type Tag<Tags extends string = string> = Tagged<Tags, 'Tag'>
13
+
14
+ export function AsFqn(name: string, parent?: Fqn | null): Fqn {
15
+ return (parent ? parent + '.' + name : name) as Fqn
16
+ }
17
+
18
+ export type GlobalFqn<Id extends string = string> = Tagged<Fqn<Id>, 'GlobalFqn'>
19
+ export function GlobalFqn(projectId: ProjectId, name: string): GlobalFqn {
20
+ invariant(isTruthy(projectId), 'Project ID must start with @')
21
+ return '@' + projectId + '.' + name as GlobalFqn
22
+ }
23
+
24
+ export function isGlobalFqn(fqn: string): fqn is GlobalFqn {
25
+ return fqn.startsWith('@')
26
+ }
27
+
28
+ export function splitGlobalFqn<Id extends string>(fqn: Fqn<Id> | GlobalFqn<Id>): [ProjectId | null, Fqn<Id>] {
29
+ if (!fqn.startsWith('@')) {
30
+ return [null, fqn]
31
+ }
32
+ const firstDot = fqn.indexOf('.')
33
+ if (firstDot < 2) {
34
+ throw new Error('Invalid global FQN')
35
+ }
36
+ const projectId = fqn.slice(1, firstDot) as ProjectId
37
+ const name = fqn.slice(firstDot + 1) as Fqn<Id>
38
+ return [projectId, name]
39
+ }
@@ -1,5 +1,6 @@
1
1
  import type { NonEmptyArray } from './_common'
2
- import type { BorderStyle, ElementShape, Fqn } from './element'
2
+ import type { BorderStyle, ElementShape } from './element'
3
+ import type { Fqn } from './scalars'
3
4
  import type { ThemeColor } from './theme'
4
5
  import type { AutoLayoutDirection, ViewManualLayout } from './view'
5
6
 
package/src/types/view.ts CHANGED
@@ -1,19 +1,18 @@
1
1
  import { isArray, isNullish } from 'remeda'
2
2
  import type { Tagged } from 'type-fest'
3
- import type { IconUrl, NonEmptyArray, Point, XYPoint } from './_common'
3
+ import type { NonEmptyArray, Point, XYPoint } from './_common'
4
4
  import {
5
5
  type BorderStyle,
6
6
  type ElementShape,
7
7
  type ElementStyle,
8
- type Fqn,
9
8
  type Link,
10
- type Tag,
11
9
  ElementKind,
12
10
  } from './element'
13
- import type { ElementExpression, ElementPredicateExpression, Expression } from './expression'
14
11
  import type { ExpressionV2, FqnExpr } from './expression-v2'
12
+ import type { ModelLayer } from './expression-v2-model'
15
13
  import type { GlobalPredicateId, GlobalStyleID } from './global'
16
14
  import type { RelationId, RelationshipArrowType, RelationshipKind, RelationshipLineType } from './relation'
15
+ import type { Fqn, IconUrl, Tag } from './scalars'
17
16
  import type { Color, ShapeSize, SpacingSize, TextSize, ThemeColorValues } from './theme'
18
17
  import type { ElementNotation } from './view-notation'
19
18
 
@@ -21,12 +20,12 @@ export type ViewId<Id extends string = string> = Tagged<Id, 'ViewID'>
21
20
 
22
21
  export type ViewRulePredicate =
23
22
  | {
24
- include: Expression[]
23
+ include: ModelLayer.Expression[]
25
24
  exclude?: never
26
25
  }
27
26
  | {
28
27
  include?: never
29
- exclude: Expression[]
28
+ exclude: ModelLayer.Expression[]
30
29
  }
31
30
 
32
31
  export function isViewRulePredicate(rule: DeploymentViewRule): rule is DeploymentViewRulePredicate
@@ -47,7 +46,7 @@ export function isViewRuleGlobalPredicateRef(rule: ViewRule): rule is ViewRuleGl
47
46
  }
48
47
 
49
48
  export interface ViewRuleStyle {
50
- targets: ElementExpression[]
49
+ targets: ModelLayer.FqnExpr[]
51
50
  notation?: string
52
51
  style: ElementStyle & {
53
52
  color?: Color
@@ -198,7 +197,7 @@ export interface DynamicViewParallelSteps {
198
197
  export type DynamicViewStepOrParallel = DynamicViewStep | DynamicViewParallelSteps
199
198
 
200
199
  export type DynamicViewIncludeRule = {
201
- include: ElementPredicateExpression[]
200
+ include: ModelLayer.AnyFqnExpr[]
202
201
  }
203
202
 
204
203
  export type DynamicViewRule =
@@ -1,186 +0,0 @@
1
- import { LiteralUnion, Tagged, Simplify, UnionToIntersection, TupleToUnion } from 'type-fest';
2
-
3
- declare const ThemeColors: readonly ["amber", "blue", "gray", "slate", "green", "indigo", "muted", "primary", "red", "secondary", "sky"];
4
- type ThemeColor = typeof ThemeColors[number];
5
- type HexColorLiteral = `#${string}`;
6
- type ColorLiteral = HexColorLiteral;
7
- type Color = LiteralUnion<ThemeColor, string>;
8
- type ShapeSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
9
- /**
10
- * For padding, margin, etc.
11
- */
12
- type SpacingSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
13
- type TextSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
14
- declare function isThemeColor(color: Color): color is ThemeColor;
15
- interface ElementThemeColorValues {
16
- fill: ColorLiteral;
17
- stroke: ColorLiteral;
18
- hiContrast: ColorLiteral;
19
- loContrast: ColorLiteral;
20
- }
21
- type ElementThemeColors = {
22
- [key in ThemeColor]: ElementThemeColorValues;
23
- };
24
- interface RelationshipThemeColorValues {
25
- lineColor: ColorLiteral;
26
- labelBgColor: ColorLiteral;
27
- labelColor: ColorLiteral;
28
- }
29
- interface ThemeColorValues {
30
- elements: ElementThemeColorValues;
31
- relationships: RelationshipThemeColorValues;
32
- }
33
- type RelationshipThemeColors = {
34
- [key in ThemeColor]: RelationshipThemeColorValues;
35
- };
36
- interface LikeC4Theme {
37
- font: 'Arial';
38
- shadow: ColorLiteral;
39
- relationships: RelationshipThemeColors;
40
- elements: ElementThemeColors;
41
- sizes: {
42
- [key in ShapeSize]: {
43
- width: number;
44
- height: number;
45
- };
46
- };
47
- spacing: {
48
- [key in SpacingSize]: number;
49
- };
50
- textSizes: {
51
- [key in TextSize]: number;
52
- };
53
- }
54
-
55
- type ProjectId = Tagged<string, 'ProjectID'>;
56
- type NonEmptyArray<T> = [T, ...T[]];
57
- type NonEmptyReadonlyArray<T> = readonly [T, ...T[]];
58
- type IconUrl = Tagged<string, 'IconUrl'> | 'none';
59
- type CustomColor = string;
60
- type Point = readonly [x: number, y: number];
61
- interface XYPoint {
62
- x: number;
63
- y: number;
64
- }
65
- type KeysOf<T> = keyof T extends infer K extends string ? K : never;
66
- type AllNever<Expressions> = UnionToIntersection<{
67
- [Name in keyof Expressions]: {
68
- -readonly [Key in keyof Expressions[Name]]?: never;
69
- };
70
- }[keyof Expressions]>;
71
- /**
72
- * @example
73
- * type Variant1 = {
74
- * a: string
75
- * }
76
- * type Variant2 = {
77
- * b: number
78
- * }
79
- *
80
- * type Variants = ExclusiveUnion<{
81
- * Variant1: Variant1,
82
- * Variant2: Variant2
83
- * }>
84
- *
85
- * Fail here
86
- * const variant1: Variants = {
87
- * a: 'one',
88
- * b: 1
89
- * }
90
- */
91
- type ExclusiveUnion<Expressions> = Expressions extends object ? {
92
- [Name in keyof Expressions]: Simplify<Omit<AllNever<Expressions>, keyof Expressions[Name]> & Expressions[Name]>;
93
- }[keyof Expressions] : Expressions;
94
- /**
95
- * Copy from https://github.com/remeda/remeda/blob/main/src/internal/types/NTuple.ts
96
- * An array with *exactly* N elements in it.
97
- *
98
- * Only literal N values are supported. For very large N the type might result
99
- * in a recurse depth error. For negative N the type would result in an infinite
100
- * recursion. None of these have protections because this is an internal type!
101
- */
102
- type NTuple<T, N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : NTuple<T, N, [...Result, T]>;
103
- type IteratorLike<T> = IteratorObject<T, BuiltinIteratorReturn>;
104
- type Predicate<T> = (x: T) => boolean;
105
-
106
- type Fqn<Id extends string = string> = Tagged<Id, 'Fqn'>;
107
- declare function AsFqn(name: string, parent?: Fqn | null): Fqn;
108
- declare const BorderStyles: readonly ["solid", "dashed", "dotted", "none"];
109
- type BorderStyle = TupleToUnion<typeof BorderStyles>;
110
- type ElementKind<Kinds extends string = string> = Tagged<Kinds, 'ElementKind'>;
111
- declare namespace ElementKind {
112
- const Group: ElementKind;
113
- }
114
- declare const ElementShapes: readonly ["rectangle", "person", "browser", "mobile", "cylinder", "storage", "queue"];
115
- type ElementShape = TupleToUnion<typeof ElementShapes>;
116
- declare const DefaultThemeColor: ThemeColor;
117
- declare const DefaultElementShape: ElementShape;
118
- declare const DefaultShapeSize: ShapeSize;
119
- declare const DefaultPaddingSize: SpacingSize;
120
- declare const DefaultTextSize: TextSize;
121
- interface ElementStyle {
122
- readonly border?: BorderStyle;
123
- /**
124
- * In percentage 0-100, 0 is fully transparent
125
- *
126
- * @default 100
127
- */
128
- readonly opacity?: number;
129
- /**
130
- * If true, the element is rendered as multiple shapes
131
- * @default false
132
- */
133
- readonly multiple?: boolean;
134
- /**
135
- * Shape size
136
- *
137
- * @default 'md'
138
- */
139
- readonly size?: ShapeSize;
140
- readonly padding?: SpacingSize;
141
- readonly textSize?: TextSize;
142
- }
143
- type Tag<Tags extends string = string> = Tagged<Tags, 'Tag'>;
144
- interface TagSpec {
145
- readonly id: Tag;
146
- readonly style: ElementStyle;
147
- }
148
- interface Link {
149
- readonly title?: string;
150
- readonly url: string;
151
- readonly relative?: string;
152
- }
153
- interface TypedElement<Ids extends string, Kinds extends string, Tags extends string, MetadataKeys extends string = never> {
154
- readonly id: Fqn<Ids>;
155
- readonly kind: ElementKind<Kinds>;
156
- readonly title: string;
157
- readonly description: string | null;
158
- readonly technology: string | null;
159
- readonly tags: NonEmptyArray<Tag<Tags>> | null;
160
- readonly links: NonEmptyArray<Link> | null;
161
- readonly icon?: IconUrl;
162
- readonly shape?: ElementShape;
163
- readonly color?: Color;
164
- readonly style?: ElementStyle;
165
- readonly notation?: string;
166
- readonly metadata?: Record<MetadataKeys, string>;
167
- }
168
- interface Element extends TypedElement<string, string, string, string> {
169
- }
170
- interface ElementKindSpecificationStyle {
171
- shape?: ElementShape;
172
- icon?: IconUrl;
173
- color?: Color;
174
- border?: BorderStyle;
175
- opacity?: number;
176
- size?: ShapeSize;
177
- padding?: SpacingSize;
178
- textSize?: TextSize;
179
- }
180
- interface ElementKindSpecification {
181
- readonly technology?: string;
182
- readonly notation?: string;
183
- readonly style: ElementKindSpecificationStyle;
184
- }
185
-
186
- export { AsFqn as A, BorderStyles as B, type CustomColor as C, DefaultElementShape as D, type ExclusiveUnion as E, type Fqn as F, type ElementThemeColorValues as G, type HexColorLiteral as H, type IconUrl as I, type RelationshipThemeColorValues as J, type KeysOf as K, type LikeC4Theme as L, type SpacingSize as M, type NonEmptyArray as N, type TextSize as O, type Point as P, type ThemeColor as Q, type RelationshipThemeColors as R, type ShapeSize as S, type ThemeColorValues as T, type XYPoint as X, type IteratorLike as a, type NonEmptyReadonlyArray as b, type NTuple as c, type Predicate as d, type ProjectId as e, DefaultPaddingSize as f, DefaultShapeSize as g, DefaultTextSize as h, DefaultThemeColor as i, ElementKind as j, ElementShapes as k, type BorderStyle as l, type Element as m, type ElementKindSpecification as n, type ElementKindSpecificationStyle as o, type ElementShape as p, type ElementStyle as q, type Link as r, type Tag as s, type TagSpec as t, type TypedElement as u, isThemeColor as v, ThemeColors as w, type Color as x, type ColorLiteral as y, type ElementThemeColors as z };
@@ -1,207 +0,0 @@
1
- import type { IconUrl } from './_common'
2
- import type { BorderStyle, ElementKind, ElementShape, Fqn, Tag } from './element'
3
- import type { WhereOperator } from './operators'
4
- import type { RelationshipArrowType, RelationshipLineType } from './relation'
5
- import type { Color, ShapeSize } from './theme'
6
- import type { ViewId } from './view'
7
-
8
- interface BaseExpr {
9
- where?: never
10
- element?: never
11
- custom?: never
12
- expanded?: never
13
- elementKind?: never
14
- elementTag?: never
15
- isEqual?: never
16
- isChildren?: never
17
- isDescendants?: never
18
- wildcard?: never
19
- source?: never
20
- target?: never
21
- inout?: never
22
- incoming?: never
23
- outgoing?: never
24
- customRelation?: never
25
- }
26
-
27
- export interface ElementRefExpr extends Omit<BaseExpr, 'element' | 'isChildren' | 'isDescendants'> {
28
- element: Fqn
29
- isChildren?: boolean
30
- isDescendants?: boolean
31
- }
32
- export function isElementRef(expr: Expression): expr is ElementRefExpr {
33
- return 'element' in expr
34
- }
35
-
36
- export interface ExpandedElementExpr extends Omit<BaseExpr, 'expanded'> {
37
- expanded: Fqn
38
- }
39
- export function isExpandedElementExpr(expr: Expression): expr is ExpandedElementExpr {
40
- return 'expanded' in expr
41
- }
42
-
43
- export interface CustomElementExpr extends Omit<BaseExpr, 'custom'> {
44
- custom: {
45
- expr: ElementExpression | ElementWhereExpr
46
- title?: string
47
- description?: string
48
- technology?: string
49
- notation?: string
50
- shape?: ElementShape
51
- color?: Color
52
- icon?: IconUrl
53
- border?: BorderStyle
54
- opacity?: number
55
- navigateTo?: ViewId
56
- multiple?: boolean
57
- size?: ShapeSize
58
- padding?: ShapeSize
59
- textSize?: ShapeSize
60
- }
61
- }
62
-
63
- export function isCustomElement(expr: Expression): expr is CustomElementExpr {
64
- return 'custom' in expr && (isElement(expr.custom.expr) || isElementWhere(expr.custom.expr))
65
- }
66
-
67
- export interface WildcardExpr extends Omit<BaseExpr, 'wildcard'> {
68
- wildcard: true
69
- }
70
- export function isWildcard(expr: Expression): expr is WildcardExpr {
71
- return 'wildcard' in expr
72
- }
73
- export interface ElementKindExpr extends Omit<BaseExpr, 'elementKind' | 'isEqual'> {
74
- elementKind: ElementKind
75
- isEqual: boolean
76
- }
77
- export function isElementKindExpr(expr: Expression): expr is ElementKindExpr {
78
- return 'elementKind' in expr && 'isEqual' in expr
79
- }
80
-
81
- export interface ElementTagExpr extends Omit<BaseExpr, 'elementTag' | 'isEqual'> {
82
- elementTag: Tag
83
- isEqual: boolean
84
- }
85
- export function isElementTagExpr(expr: Expression): expr is ElementTagExpr {
86
- return 'elementTag' in expr && 'isEqual' in expr
87
- }
88
-
89
- export type NonWilcard =
90
- | ElementRefExpr
91
- | ElementKindExpr
92
- | ElementTagExpr
93
- | ExpandedElementExpr
94
-
95
- export type ElementExpression =
96
- | NonWilcard
97
- | WildcardExpr
98
-
99
- export function isElement(expr: Expression): expr is ElementExpression {
100
- return isElementRef(expr)
101
- || isWildcard(expr)
102
- || isElementKindExpr(expr)
103
- || isElementTagExpr(expr)
104
- || isExpandedElementExpr(expr)
105
- }
106
-
107
- export interface ElementWhereExpr extends Omit<BaseExpr, 'where'> {
108
- where: {
109
- expr: ElementExpression
110
- condition: WhereOperator<string, string>
111
- }
112
- }
113
- export function isElementWhere(expr: Expression): expr is ElementWhereExpr {
114
- return 'where' in expr && isElement(expr.where.expr)
115
- }
116
-
117
- export type ElementPredicateExpression = ElementExpression | ElementWhereExpr | CustomElementExpr
118
- export function isElementPredicateExpr(expr: Expression): expr is ElementPredicateExpression {
119
- return isElement(expr) || isElementWhere(expr) || isCustomElement(expr)
120
- }
121
-
122
- export interface DirectRelationExpr extends Omit<BaseExpr, 'source' | 'target'> {
123
- source: ElementExpression
124
- target: ElementExpression
125
- isBidirectional?: boolean
126
- }
127
- export function isRelation(expr: Expression): expr is DirectRelationExpr {
128
- return 'source' in expr && 'target' in expr
129
- }
130
-
131
- export interface InOutExpr extends Omit<BaseExpr, 'inout'> {
132
- inout: ElementExpression
133
- }
134
- export function isInOut(expr: Expression): expr is InOutExpr {
135
- return 'inout' in expr
136
- }
137
-
138
- export interface IncomingExpr extends Omit<BaseExpr, 'incoming'> {
139
- incoming: ElementExpression
140
- }
141
- export function isIncoming(expr: Expression): expr is IncomingExpr {
142
- return 'incoming' in expr
143
- }
144
- export interface OutgoingExpr extends Omit<BaseExpr, 'outgoing'> {
145
- outgoing: ElementExpression
146
- }
147
- export function isOutgoing(expr: Expression): expr is OutgoingExpr {
148
- return 'outgoing' in expr
149
- }
150
-
151
- export type RelationExpression = DirectRelationExpr | InOutExpr | IncomingExpr | OutgoingExpr
152
-
153
- export function isRelationExpression(expr: Expression): expr is RelationExpression {
154
- return isRelation(expr) || isInOut(expr) || isIncoming(expr) || isOutgoing(expr)
155
- }
156
-
157
- export interface RelationWhereExpr extends Omit<BaseExpr, 'where'> {
158
- where: {
159
- expr: RelationExpression
160
- condition: WhereOperator<string, string>
161
- }
162
- }
163
- export function isRelationWhere(expr: Expression): expr is RelationWhereExpr {
164
- return 'where' in expr && isRelationExpression(expr.where.expr)
165
- }
166
-
167
- export interface CustomRelationExpr extends Omit<BaseExpr, 'customRelation'> {
168
- customRelation: {
169
- relation: RelationExpression | RelationWhereExpr
170
- title?: string
171
- description?: string
172
- technology?: string
173
- notation?: string
174
- // Link to dynamic view
175
- navigateTo?: ViewId
176
- // Notes for walkthrough
177
- notes?: string
178
- color?: Color
179
- line?: RelationshipLineType
180
- head?: RelationshipArrowType
181
- tail?: RelationshipArrowType
182
- }
183
- }
184
- export function isCustomRelationExpr(expr: Expression): expr is CustomRelationExpr {
185
- return 'customRelation' in expr
186
- }
187
-
188
- export type RelationPredicateExpression = RelationExpression | RelationWhereExpr | CustomRelationExpr
189
-
190
- export function isRelationPredicateExpr(expr: Expression): expr is RelationPredicateExpression {
191
- return isRelationExpression(expr) || isRelationWhere(expr) || isCustomRelationExpr(expr)
192
- }
193
-
194
- export type Expression = ElementPredicateExpression | RelationPredicateExpression
195
-
196
- // export const Expr = {
197
- // isElementRef,
198
- // isWildcard,
199
- // isElementKindExpr,
200
- // isElementTagExpr,
201
- // isElement,
202
- // isRelation,
203
- // isInOut,
204
- // isIncoming,
205
- // isOutgoing,
206
- // isAnyRelation,
207
- // }