@likec4/core 1.31.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +407 -5
  2. package/dist/builder/index.d.mts +221 -42
  3. package/dist/builder/index.mjs +118 -65
  4. package/dist/compute-view/index.d.mts +23 -7
  5. package/dist/compute-view/index.mjs +11 -6
  6. package/dist/compute-view/relationships-view/index.d.mts +9 -7
  7. package/dist/compute-view/relationships-view/index.mjs +3 -2
  8. package/dist/index.d.mts +10 -14
  9. package/dist/index.mjs +9 -6
  10. package/dist/model/index.d.mts +173 -19
  11. package/dist/model/index.mjs +6 -1
  12. package/dist/shared/core.BaYE_r29.d.mts +258 -0
  13. package/dist/shared/core.Bk7wEZFG.mjs +276 -0
  14. package/dist/shared/core.BrCnZFTn.mjs +32 -0
  15. package/dist/shared/core.BuO4ncfY.d.mts +146 -0
  16. package/dist/shared/{core.Bq753SYD.mjs → core.CBpKAlhj.mjs} +2012 -4422
  17. package/dist/shared/core.CCWXGc6G.d.mts +920 -0
  18. package/dist/shared/core.CUYDgv2-.mjs +214 -0
  19. package/dist/shared/{core.Cu-UdkSl.mjs → core.CpXlRyE5.mjs} +7 -494
  20. package/dist/shared/{core.C-YXI-43.mjs → core.Cy9smucx.mjs} +3 -1
  21. package/dist/shared/core.CywrQs86.d.mts +31 -0
  22. package/dist/shared/core.DoK86JEe.mjs +518 -0
  23. package/dist/shared/core.Dpq3P3YJ.d.mts +1265 -0
  24. package/dist/shared/{core.D2830qgg.d.mts → core.Pf5I9o0e.d.mts} +1 -1
  25. package/dist/shared/core.cbA9VZ02.mjs +2681 -0
  26. package/dist/shared/{core.CQXU9DF7.mjs → core.rmvsy0n3.mjs} +23 -32
  27. package/dist/types/aux.d.mts +3 -0
  28. package/dist/types/aux.mjs +1 -0
  29. package/dist/types/index.d.mts +7 -45
  30. package/dist/types/index.mjs +130 -3
  31. package/dist/utils/index.d.mts +221 -53
  32. package/dist/utils/index.mjs +14 -10
  33. package/package.json +15 -7
  34. package/src/builder/Builder.deploymentModel.ts +82 -18
  35. package/src/builder/Builder.element.ts +40 -20
  36. package/src/builder/Builder.model.ts +66 -17
  37. package/src/builder/Builder.ts +168 -76
  38. package/src/builder/Builder.view-common.ts +35 -17
  39. package/src/builder/Builder.view-deployment.ts +25 -25
  40. package/src/builder/Builder.view-element.ts +13 -12
  41. package/src/builder/Builder.views.ts +12 -7
  42. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +62 -34
  43. package/src/builder/__snapshots__/Builder-style2.compute-model.json5 +319 -0
  44. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +45 -24
  45. package/src/builder/_types.ts +34 -27
  46. package/src/compute-view/compute-view.ts +31 -34
  47. package/src/compute-view/deployment-view/__test__/TestHelper.ts +27 -14
  48. package/src/compute-view/deployment-view/__test__/fixture.ts +15 -13
  49. package/src/compute-view/deployment-view/_types.ts +10 -10
  50. package/src/compute-view/deployment-view/clean-connections.ts +5 -7
  51. package/src/compute-view/deployment-view/compute.ts +16 -13
  52. package/src/compute-view/deployment-view/memory/memory.ts +5 -6
  53. package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +4 -5
  54. package/src/compute-view/deployment-view/predicates/relation-direct.ts +25 -50
  55. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +5 -7
  56. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +7 -11
  57. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +7 -10
  58. package/src/compute-view/deployment-view/predicates/utils.ts +37 -31
  59. package/src/compute-view/deployment-view/predicates/wildcard.ts +3 -2
  60. package/src/compute-view/deployment-view/stages/stage-final.ts +2 -2
  61. package/src/compute-view/deployment-view/stages/stage-include.ts +1 -1
  62. package/src/compute-view/deployment-view/utils.ts +79 -72
  63. package/src/compute-view/dynamic-view/__test__/fixture.ts +20 -11
  64. package/src/compute-view/dynamic-view/compute.ts +60 -53
  65. package/src/compute-view/element-view/__test__/TestHelper.ts +53 -29
  66. package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +26 -26
  67. package/src/compute-view/element-view/__test__/fixture.ts +134 -83
  68. package/src/compute-view/element-view/_types.ts +14 -19
  69. package/src/compute-view/element-view/clean-connections.ts +12 -8
  70. package/src/compute-view/element-view/compute.ts +61 -51
  71. package/src/compute-view/element-view/memory/NodeGroup.ts +8 -9
  72. package/src/compute-view/element-view/memory/memory.ts +22 -22
  73. package/src/compute-view/element-view/memory/stage-include.ts +5 -3
  74. package/src/compute-view/element-view/predicates/_utils.ts +18 -14
  75. package/src/compute-view/element-view/predicates/element-expand.ts +4 -5
  76. package/src/compute-view/element-view/predicates/element-kind-tag.ts +3 -4
  77. package/src/compute-view/element-view/predicates/element-ref.ts +3 -4
  78. package/src/compute-view/element-view/predicates/relation-direct.ts +16 -12
  79. package/src/compute-view/element-view/predicates/relation-in-out.ts +7 -8
  80. package/src/compute-view/element-view/predicates/relation-in.ts +19 -26
  81. package/src/compute-view/element-view/predicates/relation-out.ts +20 -21
  82. package/src/compute-view/element-view/predicates/wildcard.ts +3 -3
  83. package/src/compute-view/element-view/utils.ts +25 -23
  84. package/src/compute-view/index.ts +1 -1
  85. package/src/compute-view/memory/AbstractStageExclude.ts +3 -4
  86. package/src/compute-view/memory/AbstractStageInclude.ts +1 -1
  87. package/src/compute-view/memory/_types.ts +3 -2
  88. package/src/compute-view/relationships-view/_types.ts +3 -4
  89. package/src/compute-view/relationships-view/compute.ts +8 -11
  90. package/src/compute-view/relationships-view/layout.ts +6 -6
  91. package/src/compute-view/relationships-view/utils.ts +4 -4
  92. package/src/compute-view/utils/ancestorsOfNode.ts +7 -7
  93. package/src/compute-view/utils/applyCustomElementProperties.ts +16 -8
  94. package/src/compute-view/utils/applyCustomRelationProperties.ts +19 -9
  95. package/src/compute-view/utils/applyViewRuleStyles.ts +18 -10
  96. package/src/compute-view/utils/buildComputedNodes.ts +40 -40
  97. package/src/compute-view/utils/buildElementNotations.ts +14 -14
  98. package/src/compute-view/utils/elementExpressionToPredicate.ts +14 -15
  99. package/src/compute-view/utils/link-nodes-with-edges.ts +6 -4
  100. package/src/compute-view/utils/merge-props-from-relationships.ts +52 -20
  101. package/src/compute-view/utils/relationExpressionToPredicates.ts +19 -19
  102. package/src/compute-view/utils/resolve-extended-views.ts +8 -7
  103. package/src/compute-view/utils/resolve-global-rules.ts +31 -26
  104. package/src/compute-view/utils/topological-sort.ts +14 -14
  105. package/src/compute-view/utils/view-hash.ts +2 -2
  106. package/src/compute-view/utils/with-readable-edges.ts +9 -5
  107. package/src/index.ts +0 -32
  108. package/src/model/DeploymentElementModel.ts +171 -144
  109. package/src/model/DeploymentModel.ts +88 -65
  110. package/src/model/ElementModel.ts +85 -74
  111. package/src/model/LikeC4Model.ts +430 -241
  112. package/src/model/RelationModel.ts +63 -29
  113. package/src/model/__test__/fixture.ts +50 -36
  114. package/src/model/connection/Connection.ts +2 -2
  115. package/src/model/connection/deployment/DeploymentConnectionModel.ts +21 -24
  116. package/src/model/connection/deployment/find.ts +1 -1
  117. package/src/model/connection/model/ConnectionModel.ts +21 -20
  118. package/src/model/connection/model/find.ts +7 -7
  119. package/src/model/connection/ops.ts +6 -6
  120. package/src/model/guards.ts +66 -14
  121. package/src/model/index.ts +20 -7
  122. package/src/model/types.ts +41 -97
  123. package/src/model/view/EdgeModel.ts +47 -41
  124. package/src/model/view/LikeC4ViewModel.ts +130 -80
  125. package/src/model/view/NodeModel.ts +102 -96
  126. package/src/theme/element.ts +1 -1
  127. package/src/theme/index.ts +9 -9
  128. package/src/theme/relationships.ts +1 -1
  129. package/src/types/_common.ts +21 -15
  130. package/src/types/aux.ts +285 -0
  131. package/src/types/const.ts +34 -0
  132. package/src/types/expression-model.ts +292 -0
  133. package/src/types/expression.ts +311 -0
  134. package/src/types/fqnRef.ts +88 -0
  135. package/src/types/geometry.ts +131 -0
  136. package/src/types/global.ts +10 -8
  137. package/src/types/index.ts +39 -201
  138. package/src/types/model-data.ts +52 -84
  139. package/src/types/model-deployment.ts +87 -0
  140. package/src/types/model-dump.ts +72 -0
  141. package/src/types/model-logical.ts +111 -0
  142. package/src/types/model-spec.ts +81 -0
  143. package/src/types/operators.ts +51 -52
  144. package/src/types/scalar.ts +114 -0
  145. package/src/types/styles.ts +123 -0
  146. package/src/types/view-changes.ts +4 -5
  147. package/src/types/view-common.ts +157 -0
  148. package/src/types/view-computed.ts +113 -0
  149. package/src/types/view-layouted.ts +82 -0
  150. package/src/types/view-parsed.deployment.ts +40 -0
  151. package/src/types/view-parsed.dynamic.ts +78 -0
  152. package/src/types/view-parsed.element.ts +65 -0
  153. package/src/types/view.ts +122 -542
  154. package/src/utils/compare-natural.ts +43 -1
  155. package/src/utils/getOrCreate.ts +0 -34
  156. package/src/utils/index.ts +7 -12
  157. package/src/utils/iterable/filter.ts +1 -1
  158. package/src/utils/iterable/find.ts +3 -1
  159. package/src/utils/iterable/head.ts +22 -0
  160. package/src/utils/iterable/index.ts +1 -0
  161. package/src/utils/iterable/map.ts +1 -1
  162. package/src/utils/iterable/reduce.ts +1 -1
  163. package/src/utils/iterable/some.ts +1 -1
  164. package/src/utils/memoize-prop.ts +30 -0
  165. package/src/utils/object-hash.ts +1 -1
  166. package/src/utils/relations.ts +14 -11
  167. package/src/utils/string-hash.ts +1 -1
  168. package/dist/shared/core.CQDU11hR.d.mts +0 -753
  169. package/dist/shared/core.DJvmfnEi.d.mts +0 -1153
  170. package/dist/shared/core.DgfwjBtu.mjs +0 -495
  171. package/dist/shared/core.Dx7siloV.d.mts +0 -146
  172. package/dist/shared/core.SjLhMA7a.d.mts +0 -62
  173. package/src/builder/__snapshots__/Builder.spec.ts.snap +0 -374
  174. package/src/compute-view/element-view/predicates.ts +0 -520
  175. package/src/compute-view/utils/uniqueTags.ts +0 -21
  176. package/src/types/deployments.ts +0 -170
  177. package/src/types/element.ts +0 -109
  178. package/src/types/expression-v2-model.ts +0 -314
  179. package/src/types/expression-v2.ts +0 -392
  180. package/src/types/overview-graph.ts +0 -43
  181. package/src/types/relation.ts +0 -61
  182. package/src/types/scalars.ts +0 -39
  183. package/src/types/theme.ts +0 -82
  184. package/src/types/view-notation.ts +0 -9
  185. package/src/utils/graphlib.ts +0 -10
  186. /package/src/{errors/index.ts → utils/invariant.ts} +0 -0
@@ -1,170 +0,0 @@
1
- import type { MergeExclusive, Simplify, Tagged } from 'type-fest'
2
- import type { NonEmptyArray } from './_common'
3
- import type { ElementShape, ElementStyle, Link } from './element'
4
- import type { AbstractRelation, RelationId } from './relation'
5
- import type { Fqn, IconUrl, Tag } from './scalars'
6
- import type { Color } from './theme'
7
-
8
- export type DeploymentNodeKind<Kinds extends string = string> = Tagged<Kinds, 'DeploymentNodeKind'>
9
-
10
- export type DeploymentElementStyle = ElementStyle & {
11
- readonly icon?: IconUrl
12
- readonly shape?: ElementShape
13
- readonly color?: Color
14
- }
15
-
16
- export interface DeploymentNodeKindSpecification {
17
- readonly technology?: string
18
- readonly notation?: string
19
- readonly style: DeploymentElementStyle
20
- }
21
-
22
- export interface DeploymentNode {
23
- // Full-qualified-name for Deployment model
24
- readonly id: Fqn
25
- readonly kind: DeploymentNodeKind
26
- readonly title: string
27
- readonly description?: string | null
28
- readonly technology?: string | null
29
- readonly tags?: NonEmptyArray<Tag> | null
30
- readonly links?: NonEmptyArray<Link> | null
31
- readonly style?: DeploymentElementStyle
32
- readonly notation?: string
33
- readonly metadata?: Record<string, string>
34
- }
35
-
36
- export interface DeployedInstance {
37
- /**
38
- * Format: `<DeploymentNode Fqn>.<Instance Id>`
39
- * i.e parent fqn is deployment target
40
- */
41
- readonly id: Fqn
42
- readonly element: Fqn
43
- readonly title?: string
44
- readonly description?: string | null
45
- readonly technology?: string | null
46
- readonly tags?: NonEmptyArray<Tag> | null
47
- readonly links?: NonEmptyArray<Link> | null
48
- readonly style?: DeploymentElementStyle
49
- readonly notation?: string
50
- readonly metadata?: Record<string, string>
51
- }
52
-
53
- export type DeploymentElement = Simplify<MergeExclusive<DeploymentNode, DeployedInstance>>
54
-
55
- export namespace DeploymentElement {
56
- export const isDeploymentNode = (el: DeploymentElement): el is DeploymentNode => {
57
- return 'kind' in el && !('element' in el)
58
- }
59
- export const isInstance = (el: DeploymentElement): el is DeployedInstance => {
60
- return 'element' in el && !('kind' in el)
61
- }
62
- }
63
-
64
- export type PredicateSelector =
65
- | 'children' // ele.*
66
- | 'expanded' // ele._
67
- | 'descendants' // ele.**
68
-
69
- export interface DeploymentRef {
70
- // Reference to DeploymentNode or DeployedInstance
71
- readonly id: Fqn
72
- // Reference to element within DeployedInstance
73
- readonly element?: Fqn
74
- }
75
-
76
- /**
77
- * NOTE:
78
- */
79
- export interface DeploymentRelation extends AbstractRelation {
80
- readonly id: RelationId
81
- readonly source: DeploymentRef
82
- readonly target: DeploymentRef
83
- }
84
-
85
- // export namespace DeploymentRelationExpression {
86
- // // type LogicalRefEndpoint = {
87
- // // logicalRef: ElementRefExpr
88
- // // }
89
- // // export type DirectEndpoint = ExclusiveUnion<{
90
- // // DeploymentElementExpression: DeploymentElementExpression
91
- // // Logical: LogicalRefEndpoint
92
- // // }>
93
-
94
- // // export const isLogicalEndpoint = (expr: DirectEndpoint): expr is LogicalRefEndpoint => {
95
- // // return 'logicalRef' in expr
96
- // // }
97
-
98
- // export type Direct = {
99
- // source: FqnExpression.Element
100
- // target: FqnExpression.Element
101
- // isBidirectional?: boolean
102
- // }
103
- // export const isDirect = (expr: DeploymentExpression): expr is Direct => {
104
- // return 'source' in expr && 'target' in expr
105
- // }
106
- // export type Incoming = {
107
- // incoming: FqnExpression.Element
108
- // }
109
- // export const isIncoming = (expr: DeploymentExpression): expr is Incoming => {
110
- // return 'incoming' in expr
111
- // }
112
- // export type Outgoing = {
113
- // outgoing: FqnExpression.Element
114
- // }
115
- // export const isOutgoing = (expr: DeploymentExpression): expr is Outgoing => {
116
- // return 'outgoing' in expr
117
- // }
118
- // export type InOut = {
119
- // inout: FqnExpression.Element
120
- // }
121
- // export const isInOut = (expr: DeploymentExpression): expr is InOut => {
122
- // return 'inout' in expr
123
- // }
124
- // }
125
-
126
- // export type DeploymentRelationExpression = ExclusiveUnion<{
127
- // Direct: DeploymentRelationExpression.Direct
128
- // Incoming: DeploymentRelationExpression.Incoming
129
- // Outgoing: DeploymentRelationExpression.Outgoing
130
- // InOut: DeploymentRelationExpression.InOut
131
- // }>
132
-
133
- // export namespace DeploymentElementExpression {
134
- // export type Ref = {
135
- // ref: DeploymentRef
136
- // selector?: PredicateSelector
137
- // }
138
- // export const isRef = (expr: DeploymentExpression): expr is Ref => {
139
- // return 'ref' in expr
140
- // }
141
-
142
- // export type Wildcard = {
143
- // wildcard: true
144
- // }
145
- // export const isWildcard = (expr: DeploymentExpression): expr is Wildcard => {
146
- // return 'wildcard' in expr && expr.wildcard === true
147
- // }
148
- // }
149
-
150
- // export type DeploymentElementExpression = ExclusiveUnion<{
151
- // DeploymentRef: DeploymentElementExpression.Ref
152
- // Wildcard: DeploymentElementExpression.Wildcard
153
- // }>
154
-
155
- // export type DeploymentExpression = ExclusiveUnion<{
156
- // Element: DeploymentElementExpression
157
- // Relation: DeploymentRelationExpression
158
- // }>
159
-
160
- // export namespace DeploymentExpression {
161
- // export type Element = DeploymentElementExpression
162
- // export type Relation = DeploymentRelationExpression
163
-
164
- // export const isElement = (expr: DeploymentExpression): expr is DeploymentElementExpression => {
165
- // return DeploymentElementExpression.isRef(expr) || DeploymentElementExpression.isWildcard(expr)
166
- // }
167
- // export const isRelation = (expr: DeploymentExpression): expr is DeploymentRelationExpression => {
168
- // return !DeploymentExpression.isElement(expr)
169
- // }
170
- // }
@@ -1,109 +0,0 @@
1
- import type { Tagged, TupleToUnion } from 'type-fest'
2
- import type { NonEmptyArray } from './_common'
3
- import type { Fqn, IconUrl, Tag } from './scalars'
4
- import type { Color, ShapeSize, SpacingSize, TextSize, ThemeColor } from './theme'
5
-
6
- export const BorderStyles = ['solid', 'dashed', 'dotted', 'none'] as const
7
-
8
- export type BorderStyle = TupleToUnion<typeof BorderStyles>
9
-
10
- export type ElementKind<Kinds extends string = string> = Tagged<Kinds, 'ElementKind'>
11
- export namespace ElementKind {
12
- export const Group = '@group' as ElementKind
13
- }
14
- export const ElementShapes = [
15
- 'rectangle',
16
- 'person',
17
- 'browser',
18
- 'mobile',
19
- 'cylinder',
20
- 'storage',
21
- 'queue',
22
- ] as const
23
-
24
- export type ElementShape = TupleToUnion<typeof ElementShapes>
25
- export const DefaultThemeColor: ThemeColor = 'primary'
26
- export const DefaultElementShape: ElementShape = 'rectangle'
27
- export const DefaultShapeSize: ShapeSize = 'md'
28
- export const DefaultPaddingSize: SpacingSize = 'md'
29
- export const DefaultTextSize: TextSize = 'md'
30
-
31
- export interface ElementStyle {
32
- readonly border?: BorderStyle
33
- /**
34
- * In percentage 0-100, 0 is fully transparent
35
- *
36
- * @default 100
37
- */
38
- readonly opacity?: number
39
- /**
40
- * If true, the element is rendered as multiple shapes
41
- * @default false
42
- */
43
- readonly multiple?: boolean
44
-
45
- /**
46
- * Shape size
47
- *
48
- * @default 'md'
49
- */
50
- readonly size?: ShapeSize
51
-
52
- readonly padding?: SpacingSize
53
-
54
- readonly textSize?: TextSize
55
- }
56
-
57
- export interface TagSpec {
58
- readonly id: Tag
59
- readonly style: ElementStyle
60
- }
61
-
62
- export interface Link {
63
- readonly title?: string
64
- // Value from Likec4 DSL
65
- readonly url: string
66
- // Relative to workspace root (if url is relative),
67
- readonly relative?: string
68
- }
69
-
70
- export interface TypedElement<
71
- Ids extends string,
72
- Kinds extends string,
73
- Tags extends string,
74
- MetadataKeys extends string = never,
75
- > {
76
- readonly id: Fqn<Ids>
77
- readonly kind: ElementKind<Kinds>
78
- readonly title: string
79
- readonly description: string | null
80
- readonly technology: string | null
81
- readonly tags: NonEmptyArray<Tag<Tags>> | null
82
- readonly links: NonEmptyArray<Link> | null
83
- readonly icon?: IconUrl
84
- readonly shape?: ElementShape
85
- readonly color?: Color
86
- readonly style?: ElementStyle
87
- readonly notation?: string
88
- readonly metadata?: Record<MetadataKeys, string>
89
- }
90
-
91
- export interface Element extends TypedElement<string, string, string, string> {
92
- }
93
-
94
- export interface ElementKindSpecificationStyle {
95
- shape?: ElementShape
96
- icon?: IconUrl
97
- color?: Color
98
- border?: BorderStyle
99
- opacity?: number
100
- size?: ShapeSize
101
- padding?: SpacingSize
102
- textSize?: TextSize
103
- }
104
-
105
- export interface ElementKindSpecification {
106
- readonly technology?: string
107
- readonly notation?: string
108
- readonly style: ElementKindSpecificationStyle
109
- }
@@ -1,314 +0,0 @@
1
- import type { ExclusiveUnion } from './_common'
2
- import type { PredicateSelector } from './deployments'
3
- import type { BorderStyle, ElementKind, ElementShape } from './element'
4
- import type { WhereOperator } from './operators'
5
- import type { RelationshipArrowType, RelationshipLineType } from './relation'
6
- import { type Fqn, type IconUrl, type ProjectId, type Tag, GlobalFqn } from './scalars'
7
- import type { Color, ShapeSize } from './theme'
8
- import type { ViewId } from './view'
9
-
10
- export namespace ModelLayer {
11
- export namespace FqnRef {
12
- /**
13
- * Reference to logical model element
14
- */
15
- export type ModelRef<F = Fqn> = {
16
- model: F
17
- }
18
- export const isModelRef = (ref: FqnRef): ref is ModelRef => {
19
- return 'model' in ref && !('project' in ref)
20
- }
21
-
22
- /**
23
- * Reference to imported logical model element
24
- */
25
- export type ImportRef<F = Fqn> = {
26
- project: ProjectId
27
- model: F
28
- }
29
- export const isImportRef = (ref: FqnRef): ref is ImportRef => {
30
- return 'project' in ref && 'model' in ref
31
- }
32
-
33
- export const toFqn = (ref: FqnRef): Fqn => {
34
- if (isImportRef(ref)) {
35
- return GlobalFqn(ref.project, ref.model)
36
- }
37
- if (isModelRef(ref)) {
38
- return ref.model
39
- }
40
- throw new Error('Expected FqnRef.ModelRef or FqnRef.ImportRef')
41
- }
42
- }
43
-
44
- export type FqnRef<M = Fqn> = ExclusiveUnion<{
45
- ModelRef: FqnRef.ModelRef<M>
46
- ImportRef: FqnRef.ImportRef<M>
47
- }>
48
-
49
- export namespace FqnExpr {
50
- export type Wildcard = {
51
- wildcard: true
52
- }
53
- export const isWildcard = (expr: Expression): expr is FqnExpr.Wildcard => {
54
- return 'wildcard' in expr && expr.wildcard === true
55
- }
56
-
57
- export type ModelRef<M = Fqn> = {
58
- ref: FqnRef.ModelRef<M> | FqnRef.ImportRef<M>
59
- selector?: PredicateSelector
60
- }
61
- export const isModelRef = (ref: Expression): ref is FqnExpr.ModelRef => {
62
- return 'ref' in ref
63
- }
64
-
65
- export type ElementKindExpr = {
66
- elementKind: ElementKind
67
- isEqual: boolean
68
- }
69
- export function isElementKindExpr(expr: Expression): expr is ElementKindExpr {
70
- return 'elementKind' in expr && 'isEqual' in expr
71
- }
72
-
73
- export type ElementTagExpr = {
74
- elementTag: Tag
75
- isEqual: boolean
76
- }
77
- export function isElementTagExpr(expr: Expression): expr is ElementTagExpr {
78
- return 'elementTag' in expr && 'isEqual' in expr
79
- }
80
-
81
- export type NonWildcard<M = Fqn> = ExclusiveUnion<{
82
- ModelRef: ModelRef<M>
83
- ElementKind: ElementKindExpr
84
- ElementTag: ElementTagExpr
85
- }>
86
-
87
- export type Where<M = Fqn> = {
88
- where: {
89
- expr: ExclusiveUnion<{
90
- Wildcard: Wildcard
91
- ModelRef: ModelRef<M>
92
- ElementKind: ElementKindExpr
93
- ElementTag: ElementTagExpr
94
- }>
95
- condition: WhereOperator<string, string>
96
- }
97
- }
98
-
99
- export const isWhere = (expr: Expression): expr is FqnExpr.Where => {
100
- return 'where' in expr && is(expr.where.expr)
101
- }
102
-
103
- export type Custom<M = Fqn> = {
104
- custom: {
105
- expr: FqnExprOrWhere<M>
106
- title?: string
107
- description?: string
108
- technology?: string
109
- notation?: string
110
- shape?: ElementShape
111
- color?: Color
112
- icon?: IconUrl
113
- border?: BorderStyle
114
- opacity?: number
115
- navigateTo?: ViewId
116
- multiple?: boolean
117
- size?: ShapeSize
118
- padding?: ShapeSize
119
- textSize?: ShapeSize
120
- }
121
- }
122
-
123
- export const isCustom = (expr: Expression): expr is FqnExpr.Custom => {
124
- return 'custom' in expr && (is(expr.custom.expr) || isWhere(expr.custom.expr))
125
- }
126
-
127
- export const is = (expr: Expression): expr is FqnExpr => {
128
- return isWildcard(expr)
129
- || isModelRef(expr)
130
- || isElementKindExpr(expr)
131
- || isElementTagExpr(expr)
132
- }
133
- }
134
-
135
- export type FqnExpr<M = Fqn> = ExclusiveUnion<{
136
- Wildcard: FqnExpr.Wildcard
137
- ModelRef: FqnExpr.ModelRef<M>
138
- ElementKind: FqnExpr.ElementKindExpr
139
- ElementTag: FqnExpr.ElementTagExpr
140
- }>
141
-
142
- export type FqnExprOrWhere<M = Fqn> = ExclusiveUnion<{
143
- Wildcard: FqnExpr.Wildcard
144
- ModelRef: FqnExpr.ModelRef<M>
145
- ElementKind: FqnExpr.ElementKindExpr
146
- ElementTag: FqnExpr.ElementTagExpr
147
- Where: FqnExpr.Where<M>
148
- }>
149
-
150
- export type AnyFqnExpr<M = Fqn> = ExclusiveUnion<{
151
- Wildcard: FqnExpr.Wildcard
152
- ModelRef: FqnExpr.ModelRef<M>
153
- ElementKind: FqnExpr.ElementKindExpr
154
- ElementTag: FqnExpr.ElementTagExpr
155
- Where: FqnExpr.Where<M>
156
- Custom: FqnExpr.Custom<M>
157
- }>
158
-
159
- export function isAnyFqnExpr(expr: Expression): expr is AnyFqnExpr {
160
- return FqnExpr.is(expr)
161
- || FqnExpr.isWhere(expr)
162
- || FqnExpr.isCustom(expr)
163
- }
164
-
165
- export namespace RelationExpr {
166
- export type Direct<M = Fqn> = {
167
- source: FqnExpr<M>
168
- target: FqnExpr<M>
169
- isBidirectional?: boolean
170
- }
171
- export const isDirect = (expr: Expression): expr is RelationExpr.Direct => {
172
- return 'source' in expr && 'target' in expr
173
- }
174
- export type Incoming<M = Fqn> = {
175
- incoming: FqnExpr<M>
176
- }
177
- export const isIncoming = (expr: Expression): expr is RelationExpr.Incoming => {
178
- return 'incoming' in expr
179
- }
180
- export type Outgoing<M = Fqn> = {
181
- outgoing: FqnExpr<M>
182
- }
183
- export const isOutgoing = (expr: Expression): expr is RelationExpr.Outgoing => {
184
- return 'outgoing' in expr
185
- }
186
- export type InOut<M = Fqn> = {
187
- inout: FqnExpr<M>
188
- }
189
- export const isInOut = (expr: Expression): expr is RelationExpr.InOut => {
190
- return 'inout' in expr
191
- }
192
- export type Where<M = Fqn> = {
193
- where: {
194
- expr: ExclusiveUnion<{
195
- Direct: RelationExpr.Direct<M>
196
- Incoming: RelationExpr.Incoming<M>
197
- Outgoing: RelationExpr.Outgoing<M>
198
- InOut: RelationExpr.InOut<M>
199
- }>
200
- condition: WhereOperator<string, string>
201
- }
202
- }
203
- export const isWhere = (expr: Expression): expr is RelationExpr.Where => {
204
- return 'where' in expr && is(expr.where.expr)
205
- }
206
-
207
- export type Custom<M = Fqn> = {
208
- customRelation: {
209
- expr: RelationExprOrWhere<M>
210
- title?: string
211
- description?: string
212
- technology?: string
213
- notation?: string
214
- // Link to dynamic view
215
- navigateTo?: ViewId
216
- // Notes for walkthrough
217
- notes?: string
218
- color?: Color
219
- line?: RelationshipLineType
220
- head?: RelationshipArrowType
221
- tail?: RelationshipArrowType
222
- }
223
- }
224
-
225
- export const isCustom = (expr: Expression): expr is Custom => {
226
- return 'customRelation' in expr
227
- }
228
-
229
- export const is = (expr: Expression): expr is RelationExpr => {
230
- return isDirect(expr)
231
- || isIncoming(expr)
232
- || isOutgoing(expr)
233
- || isInOut(expr)
234
- }
235
- }
236
-
237
- export type RelationExpr<M = Fqn> = ExclusiveUnion<{
238
- Direct: RelationExpr.Direct<M>
239
- Incoming: RelationExpr.Incoming<M>
240
- Outgoing: RelationExpr.Outgoing<M>
241
- InOut: RelationExpr.InOut<M>
242
- }>
243
-
244
- export type RelationExprOrWhere<M = Fqn> = ExclusiveUnion<{
245
- Direct: RelationExpr.Direct<M>
246
- Incoming: RelationExpr.Incoming<M>
247
- Outgoing: RelationExpr.Outgoing<M>
248
- InOut: RelationExpr.InOut<M>
249
- Where: RelationExpr.Where<M>
250
- }>
251
-
252
- export type AnyRelationExpr<M = Fqn> = ExclusiveUnion<{
253
- Direct: RelationExpr.Direct<M>
254
- Incoming: RelationExpr.Incoming<M>
255
- Outgoing: RelationExpr.Outgoing<M>
256
- InOut: RelationExpr.InOut<M>
257
- Where: RelationExpr.Where<M>
258
- CustomRelation: RelationExpr.Custom<M>
259
- }>
260
-
261
- export function isAnyRelationExpr(expr: Expression): expr is AnyRelationExpr {
262
- return RelationExpr.is(expr)
263
- || RelationExpr.isWhere(expr)
264
- || RelationExpr.isCustom(expr)
265
- }
266
-
267
- /**
268
- * Represents a version 2 expression which can be one of several types.
269
- *
270
- * @template M - The type for the model FQN, defaults to `Fqn`.
271
- */
272
- export type Expression<M = Fqn> = ExclusiveUnion<{
273
- Wildcard: FqnExpr.Wildcard
274
- ModelRef: FqnExpr.ModelRef<M>
275
- ElementKind: FqnExpr.ElementKindExpr
276
- ElementTag: FqnExpr.ElementTagExpr
277
- Custom: FqnExpr.Custom<M>
278
- Direct: RelationExpr.Direct<M>
279
- Incoming: RelationExpr.Incoming<M>
280
- Outgoing: RelationExpr.Outgoing<M>
281
- InOut: RelationExpr.InOut<M>
282
- CustomRelation: RelationExpr.Custom<M>
283
- Where: Expression.Where<M>
284
- }>
285
-
286
- export function isExpression(expr: any): expr is Expression {
287
- return isAnyFqnExpr(expr)
288
- || isAnyRelationExpr(expr)
289
- }
290
-
291
- export namespace Expression {
292
- export type Where<M = Fqn> = FqnExpr.Where<M> | RelationExpr.Where<M>
293
-
294
- export const isWhere = (expr: Expression): expr is Expression.Where => {
295
- return 'where' in expr
296
- }
297
-
298
- export const isCustomFqnExpr = (expr: Expression): expr is FqnExpr.Custom => {
299
- return FqnExpr.isCustom(expr)
300
- }
301
-
302
- export const isCustomRelationExpr = (expr: Expression): expr is RelationExpr.Custom => {
303
- return RelationExpr.isCustom(expr)
304
- }
305
-
306
- export const isFqnExpr = (expr: Expression): expr is FqnExpr => {
307
- return FqnExpr.is(expr)
308
- }
309
-
310
- export const isRelation = (expr: Expression): expr is RelationExpr => {
311
- return RelationExpr.is(expr)
312
- }
313
- }
314
- }