@likec4/core 1.30.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 +10 -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.CAcZ6_cP.mjs → core.CBpKAlhj.mjs} +1742 -4128
  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 +19 -10
  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 +182 -137
  109. package/src/model/DeploymentModel.ts +88 -65
  110. package/src/model/ElementModel.ts +92 -72
  111. package/src/model/LikeC4Model.ts +430 -241
  112. package/src/model/RelationModel.ts +69 -26
  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.CZR9J1Qx.d.mts +0 -146
  169. package/dist/shared/core.CiFKryGW.d.mts +0 -745
  170. package/dist/shared/core.DJvmfnEi.d.mts +0 -1153
  171. package/dist/shared/core.DgfwjBtu.mjs +0 -495
  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,392 +0,0 @@
1
- import { invariant } from '../errors'
2
- import type { ExclusiveUnion } from './_common'
3
- import type { DeploymentRef as DeploymentModelRef, PredicateSelector } from './deployments'
4
- import type { BorderStyle, ElementKind, ElementShape } from './element'
5
- import type { WhereOperator } from './operators'
6
- import type { RelationshipArrowType, RelationshipLineType } from './relation'
7
- import { type Fqn, type IconUrl, type ProjectId, type Tag, GlobalFqn } from './scalars'
8
- import type { Color, ShapeSize } from './theme'
9
- import type { ViewId } from './view'
10
-
11
- export namespace FqnRef {
12
- /**
13
- * Represents a reference to an instance within a deployment.
14
- *
15
- * @template D - The type representing the deployment fqn. Defaults to `Fqn`.
16
- * @template M - The type representing the model fqn. Defaults to `Fqn`.
17
- *
18
- * @property {D} deployment - TThe fully qualified name (FQN) of the deployed instance.
19
- * @property {M} element - The element reference within the deployment.
20
- */
21
- export type InsideInstanceRef<D = Fqn, M = Fqn> = {
22
- deployment: D
23
- element: M
24
- }
25
- export const isInsideInstanceRef = (ref: FqnRef): ref is InsideInstanceRef => {
26
- return 'deployment' in ref && 'element' in ref
27
- }
28
-
29
- /**
30
- * Represents a reference to a deployment element.
31
- *
32
- * @template F - The type of the fully qualified name (FQN) of the deployment element. Defaults to `Fqn`.
33
- * @property {F} deployment - The fully qualified name (FQN) of the deployment element.
34
- */
35
- export type DeploymentElementRef<F = Fqn> = {
36
- deployment: F
37
- }
38
- export const isDeploymentElementRef = (ref: FqnRef): ref is DeploymentElementRef => {
39
- return 'deployment' in ref && !('element' in ref)
40
- }
41
-
42
- export type DeploymentRef<D = Fqn, M = Fqn> = DeploymentElementRef<D> | InsideInstanceRef<D, M>
43
- export const isDeploymentRef = (ref: FqnRef): ref is DeploymentRef => {
44
- return !isModelRef(ref) && !isImportRef(ref)
45
- }
46
-
47
- /**
48
- * Reference to logical model element
49
- */
50
- export type ModelRef<F = Fqn> = {
51
- model: F
52
- }
53
- export const isModelRef = (ref: FqnRef): ref is ModelRef => {
54
- return 'model' in ref && !('project' in ref)
55
- }
56
-
57
- /**
58
- * Reference to imported logical model element
59
- */
60
- export type ImportRef<F = Fqn> = {
61
- project: ProjectId
62
- model: F
63
- }
64
- export const isImportRef = (ref: FqnRef): ref is ImportRef => {
65
- return 'project' in ref && 'model' in ref
66
- }
67
-
68
- export const toDeploymentRef = (ref: FqnRef): DeploymentModelRef => {
69
- invariant(isDeploymentRef(ref), 'Expected DeploymentRef')
70
- return isInsideInstanceRef(ref)
71
- ? {
72
- id: ref.deployment,
73
- element: ref.element,
74
- }
75
- : {
76
- id: ref.deployment,
77
- }
78
- }
79
-
80
- export const toModelFqn = (ref: FqnRef): Fqn => {
81
- if (isImportRef(ref)) {
82
- return GlobalFqn(ref.project, ref.model)
83
- }
84
- if (isModelRef(ref)) {
85
- return ref.model
86
- }
87
- throw new Error('Expected FqnRef.ModelRef or FqnRef.ImportRef')
88
- }
89
- }
90
-
91
- export type FqnRef<D = Fqn, M = Fqn> = ExclusiveUnion<{
92
- InsideInstanceRef: FqnRef.InsideInstanceRef<D, M>
93
- DeploymentRef: FqnRef.DeploymentRef<D>
94
- ModelRef: FqnRef.ModelRef<M>
95
- ImportRef: FqnRef.ImportRef<M>
96
- }>
97
-
98
- export namespace FqnExpr {
99
- export type Wildcard = {
100
- wildcard: true
101
- }
102
- export const isWildcard = (expr: ExpressionV2): expr is FqnExpr.Wildcard => {
103
- return 'wildcard' in expr && expr.wildcard === true
104
- }
105
-
106
- export type ModelRef<M = Fqn> = {
107
- ref: FqnRef.ModelRef<M> | FqnRef.ImportRef<M>
108
- selector?: PredicateSelector
109
- }
110
- export const isModelRef = (ref: ExpressionV2): ref is FqnExpr.ModelRef => {
111
- return 'ref' in ref && (FqnRef.isModelRef(ref.ref) || FqnRef.isImportRef(ref.ref))
112
- }
113
-
114
- export type DeploymentRef<D = Fqn, M = Fqn> = {
115
- ref: FqnRef.DeploymentRef<D> | FqnRef.InsideInstanceRef<D, M>
116
- selector?: PredicateSelector
117
- }
118
- export const isDeploymentRef = (ref: ExpressionV2): ref is FqnExpr.DeploymentRef => {
119
- return 'ref' in ref && FqnRef.isDeploymentRef(ref.ref)
120
- }
121
-
122
- export type ElementKindExpr = {
123
- elementKind: ElementKind
124
- isEqual: boolean
125
- }
126
- export function isElementKindExpr(expr: ExpressionV2): expr is ElementKindExpr {
127
- return 'elementKind' in expr && 'isEqual' in expr
128
- }
129
-
130
- export type ElementTagExpr = {
131
- elementTag: Tag
132
- isEqual: boolean
133
- }
134
- export function isElementTagExpr(expr: ExpressionV2): expr is ElementTagExpr {
135
- return 'elementTag' in expr && 'isEqual' in expr
136
- }
137
-
138
- export type NonWildcard<D = Fqn, M = Fqn> = ExclusiveUnion<{
139
- ModelRef: ModelRef<M>
140
- DeploymentRef: DeploymentRef<D, M>
141
- ElementKind: ElementKindExpr
142
- ElementTag: ElementTagExpr
143
- }>
144
-
145
- export type Where<D = Fqn, M = Fqn> = {
146
- where: {
147
- expr: ExclusiveUnion<{
148
- Wildcard: Wildcard
149
- ModelRef: ModelRef<M>
150
- DeploymentRef: DeploymentRef<D, M>
151
- ElementKind: ElementKindExpr
152
- ElementTag: ElementTagExpr
153
- }>
154
- condition: WhereOperator<string, string>
155
- }
156
- }
157
-
158
- export const isWhere = (expr: ExpressionV2): expr is FqnExpr.Where => {
159
- return 'where' in expr && is(expr.where.expr)
160
- }
161
-
162
- export type Custom<D = Fqn, M = Fqn> = {
163
- custom: {
164
- expr: OrWhere<D, M>
165
- title?: string
166
- description?: string
167
- technology?: string
168
- notation?: string
169
- shape?: ElementShape
170
- color?: Color
171
- icon?: IconUrl
172
- border?: BorderStyle
173
- opacity?: number
174
- navigateTo?: ViewId
175
- multiple?: boolean
176
- size?: ShapeSize
177
- padding?: ShapeSize
178
- textSize?: ShapeSize
179
- }
180
- }
181
-
182
- export const isCustom = (expr: ExpressionV2): expr is Custom => {
183
- return 'custom' in expr && (is(expr.custom.expr) || isWhere(expr.custom.expr))
184
- }
185
-
186
- export const is = (expr: ExpressionV2): expr is FqnExpr => {
187
- return isWildcard(expr)
188
- || isModelRef(expr)
189
- || isDeploymentRef(expr)
190
- || isElementKindExpr(expr)
191
- || isElementTagExpr(expr)
192
- }
193
-
194
- export type OrWhere<D = Fqn, M = Fqn> = ExclusiveUnion<{
195
- Wildcard: FqnExpr.Wildcard
196
- ModelRef: FqnExpr.ModelRef<M>
197
- DeploymentRef: FqnExpr.DeploymentRef<D, M>
198
- ElementKind: ElementKindExpr
199
- ElementTag: ElementTagExpr
200
- Where: FqnExpr.Where<D, M>
201
- }>
202
-
203
- export type Any<D = Fqn, M = Fqn> = ExclusiveUnion<{
204
- Wildcard: Wildcard
205
- ModelRef: ModelRef<M>
206
- DeploymentRef: DeploymentRef<D, M>
207
- ElementKind: ElementKindExpr
208
- ElementTag: ElementTagExpr
209
- Where: Where<D, M>
210
- Custom: Custom<D, M>
211
- }>
212
-
213
- export const unwrap = (expr: FqnExpr): Wildcard | ModelRef | DeploymentRef | ElementKindExpr | ElementTagExpr => {
214
- if (isCustom(expr)) {
215
- expr = expr.custom.expr
216
- }
217
- if (isWhere(expr)) {
218
- expr = expr.where.expr
219
- }
220
- return expr
221
- }
222
- }
223
-
224
- export type FqnExpr<D = Fqn, M = Fqn> = ExclusiveUnion<{
225
- Wildcard: FqnExpr.Wildcard
226
- ModelRef: FqnExpr.ModelRef<M>
227
- DeploymentRef: FqnExpr.DeploymentRef<D, M>
228
- ElementKind: FqnExpr.ElementKindExpr
229
- ElementTag: FqnExpr.ElementTagExpr
230
- }>
231
-
232
- export namespace RelationExpr {
233
- export type Endpoint<D = Fqn, M = Fqn> = FqnExpr.Where<D, M>['where']['expr']
234
-
235
- export type Direct<D = Fqn, M = Fqn> = {
236
- source: Endpoint<D, M>
237
- target: Endpoint<D, M>
238
- isBidirectional?: boolean
239
- }
240
- export const isDirect = (expr: ExpressionV2): expr is RelationExpr.Direct => {
241
- return 'source' in expr && 'target' in expr
242
- }
243
- export type Incoming<D = Fqn, M = Fqn> = {
244
- incoming: Endpoint<D, M>
245
- }
246
- export const isIncoming = (expr: ExpressionV2): expr is RelationExpr.Incoming => {
247
- return 'incoming' in expr
248
- }
249
- export type Outgoing<D = Fqn, M = Fqn> = {
250
- outgoing: Endpoint<D, M>
251
- }
252
- export const isOutgoing = (expr: ExpressionV2): expr is RelationExpr.Outgoing => {
253
- return 'outgoing' in expr
254
- }
255
- export type InOut<D = Fqn, M = Fqn> = {
256
- inout: Endpoint<D, M>
257
- }
258
- export const isInOut = (expr: ExpressionV2): expr is RelationExpr.InOut => {
259
- return 'inout' in expr
260
- }
261
- export type Where<D = Fqn, M = Fqn> = {
262
- where: {
263
- expr: ExclusiveUnion<{
264
- Direct: RelationExpr.Direct<D, M>
265
- Incoming: RelationExpr.Incoming<D, M>
266
- Outgoing: RelationExpr.Outgoing<D, M>
267
- InOut: RelationExpr.InOut<D, M>
268
- }>
269
- condition: WhereOperator<string, string>
270
- }
271
- }
272
- export const isWhere = (expr: ExpressionV2): expr is RelationExpr.Where => {
273
- return 'where' in expr &&
274
- (isDirect(expr.where.expr) || isIncoming(expr.where.expr) || isOutgoing(expr.where.expr) ||
275
- isInOut(expr.where.expr))
276
- }
277
-
278
- export type Custom<D = Fqn, M = Fqn> = {
279
- customRelation: {
280
- expr: OrWhere<D, M>
281
- title?: string
282
- description?: string
283
- technology?: string
284
- notation?: string
285
- // Link to dynamic view
286
- navigateTo?: ViewId
287
- // Notes for walkthrough
288
- notes?: string
289
- color?: Color
290
- line?: RelationshipLineType
291
- head?: RelationshipArrowType
292
- tail?: RelationshipArrowType
293
- }
294
- }
295
-
296
- export const isCustom = (expr: ExpressionV2): expr is Custom => {
297
- return 'customRelation' in expr
298
- }
299
-
300
- export const is = (expr: ExpressionV2): expr is RelationExpr => {
301
- return isDirect(expr)
302
- || isIncoming(expr)
303
- || isOutgoing(expr)
304
- || isInOut(expr)
305
- }
306
-
307
- export type OrWhere<D = Fqn, M = Fqn> = ExclusiveUnion<{
308
- Direct: Direct<D, M>
309
- Incoming: Incoming<D, M>
310
- Outgoing: Outgoing<D, M>
311
- InOut: InOut<D, M>
312
- Where: Where<D, M>
313
- }>
314
-
315
- export type Any<D = Fqn, M = Fqn> = ExclusiveUnion<{
316
- Direct: Direct<D, M>
317
- Incoming: Incoming<D, M>
318
- Outgoing: Outgoing<D, M>
319
- InOut: InOut<D, M>
320
- Where: Where<D, M>
321
- Custom: Custom<D, M>
322
- }>
323
-
324
- export const unwrap = (expr: RelationExpr): Direct | Incoming | Outgoing | InOut => {
325
- if (isCustom(expr)) {
326
- expr = expr.customRelation.expr
327
- }
328
- if (isWhere(expr)) {
329
- expr = expr.where.expr
330
- }
331
- return expr
332
- }
333
- }
334
-
335
- export type RelationExpr<D = Fqn, M = Fqn> = ExclusiveUnion<{
336
- Direct: RelationExpr.Direct<D, M>
337
- Incoming: RelationExpr.Incoming<D, M>
338
- Outgoing: RelationExpr.Outgoing<D, M>
339
- InOut: RelationExpr.InOut<D, M>
340
- }>
341
-
342
- /**
343
- * Represents a version 2 expression which can be one of several types.
344
- *
345
- * @template D - The type for the deployment FQN, defaults to `Fqn`.
346
- * @template M - The type for the model FQN, defaults to `Fqn`.
347
- */
348
- export type ExpressionV2<D = Fqn, M = Fqn> = ExclusiveUnion<{
349
- Wildcard: FqnExpr.Wildcard
350
- ModelRef: FqnExpr.ModelRef<M>
351
- DeploymentRef: FqnExpr.DeploymentRef<D, M>
352
- ElementKind: FqnExpr.ElementKindExpr
353
- ElementTag: FqnExpr.ElementTagExpr
354
- Custom: FqnExpr.Custom<D, M>
355
- Direct: RelationExpr.Direct<D, M>
356
- Incoming: RelationExpr.Incoming<D, M>
357
- Outgoing: RelationExpr.Outgoing<D, M>
358
- InOut: RelationExpr.InOut<D, M>
359
- Where: ExpressionV2.Where<D, M>
360
- CustomRelation: RelationExpr.Custom<D, M>
361
- }>
362
-
363
- export namespace ExpressionV2 {
364
- export type Where<D = Fqn, M = Fqn> = FqnExpr.Where<D, M> | RelationExpr.Where<D, M>
365
- // export type Where<D = Fqn, M = Fqn> = {
366
- // where: ExclusiveUnion<{
367
- // Fqn: FqnExpr.Where<D, M>['where']['expr']
368
- // Relation: RelationExpr.Where<D, M>['where']['expr']
369
- // }>
370
- // condition: WhereOperator<string, string>
371
- // }
372
-
373
- export const isWhere = (expr: ExpressionV2): expr is ExpressionV2.Where => {
374
- return 'where' in expr
375
- }
376
-
377
- export const isRelationWhere = (expr: ExpressionV2): expr is RelationExpr.Where => {
378
- return RelationExpr.isWhere(expr)
379
- }
380
-
381
- export const isFqnExprWhere = (expr: ExpressionV2): expr is FqnExpr.Where => {
382
- return FqnExpr.isWhere(expr)
383
- }
384
-
385
- export const isFqnExpr = (expr: ExpressionV2): expr is FqnExpr.Any => {
386
- return FqnExpr.is(expr) || FqnExpr.isWhere(expr) || FqnExpr.isCustom(expr)
387
- }
388
-
389
- export const isRelation = (expr: ExpressionV2): expr is RelationExpr.Any => {
390
- return RelationExpr.is(expr) || RelationExpr.isWhere(expr) || RelationExpr.isCustom(expr)
391
- }
392
- }
@@ -1,43 +0,0 @@
1
- import type { NonEmptyArray, Point, XYPoint } from './_common'
2
- import type { BBox, ViewId } from './view'
3
-
4
- /**
5
- * OverviewGraph is a graph representation of all views in a model
6
- */
7
- export namespace OverviewGraph {
8
- export type Node = {
9
- id: string
10
- type: 'folder' | 'file'
11
- path: string
12
- label: string
13
- parentId: string | null
14
- position: XYPoint
15
- width: number
16
- height: number
17
- } | {
18
- id: string
19
- type: 'view'
20
- viewId: ViewId
21
- label: string
22
- parentId: string | null
23
- position: XYPoint
24
- width: number
25
- height: number
26
- }
27
-
28
- /**
29
- * Edge represents a navigational link from one view to another
30
- */
31
- export type Edge = {
32
- id: string
33
- source: string
34
- target: string
35
- points: NonEmptyArray<Point>
36
- }
37
- }
38
-
39
- export interface OverviewGraph {
40
- nodes: OverviewGraph.Node[]
41
- edges: OverviewGraph.Edge[]
42
- bounds: BBox
43
- }
@@ -1,61 +0,0 @@
1
- import type { Tagged } from 'type-fest'
2
- import type { NonEmptyArray } from './_common'
3
- import type { Link } from './element'
4
- import type { Fqn, Tag } from './scalars'
5
- import type { Color, ThemeColor } from './theme'
6
- import type { ViewId } from './view'
7
-
8
- export type RelationId = Tagged<string, 'RelationID'>
9
- export type RelationshipKind<Kinds extends string = string> = Tagged<Kinds, 'RelationshipKind'>
10
-
11
- export type RelationshipLineType = 'dashed' | 'solid' | 'dotted'
12
-
13
- // reference: https://graphviz.org/docs/attr-types/arrowType/
14
- export type RelationshipArrowType =
15
- | 'none'
16
- | 'normal'
17
- | 'onormal'
18
- | 'dot'
19
- | 'odot'
20
- | 'diamond'
21
- | 'odiamond'
22
- | 'crow'
23
- | 'open'
24
- | 'vee'
25
-
26
- export const DefaultLineStyle: RelationshipLineType = 'dashed'
27
- export const DefaultArrowType: RelationshipArrowType = 'normal'
28
- export const DefaultRelationshipColor: ThemeColor = 'gray'
29
-
30
- export interface AbstractRelation {
31
- readonly id: RelationId
32
- readonly title?: string
33
- readonly description?: string
34
- readonly technology?: string
35
- readonly tags?: NonEmptyArray<Tag> | null
36
- readonly kind?: RelationshipKind
37
- readonly color?: Color
38
- readonly line?: RelationshipLineType
39
- readonly head?: RelationshipArrowType
40
- readonly tail?: RelationshipArrowType
41
- readonly links?: NonEmptyArray<Link> | null
42
- // Link to dynamic view
43
- readonly navigateTo?: ViewId
44
- readonly metadata?: { [key: string]: string }
45
- }
46
-
47
- // TODO: rename to Relationship
48
- export interface ModelRelation extends AbstractRelation {
49
- readonly source: Fqn
50
- readonly target: Fqn
51
- readonly title: string
52
- }
53
-
54
- export interface RelationshipKindSpecification {
55
- readonly technology?: string
56
- readonly notation?: string
57
- readonly color?: Color
58
- readonly line?: RelationshipLineType
59
- readonly head?: RelationshipArrowType
60
- readonly tail?: RelationshipArrowType
61
- }
@@ -1,39 +0,0 @@
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,82 +0,0 @@
1
- import type { LiteralUnion } from 'type-fest'
2
-
3
- export const ThemeColors = [
4
- 'amber',
5
- 'blue',
6
- 'gray',
7
- 'slate',
8
- 'green',
9
- 'indigo',
10
- 'muted',
11
- 'primary',
12
- 'red',
13
- 'secondary',
14
- 'sky',
15
- ] as const
16
- export type ThemeColor = typeof ThemeColors[number]
17
-
18
- export type HexColorLiteral = `#${string}`
19
-
20
- export type ColorLiteral = HexColorLiteral
21
-
22
- export type Color = LiteralUnion<ThemeColor, string>
23
-
24
- export type ShapeSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
25
-
26
- /**
27
- * For padding, margin, etc.
28
- */
29
- export type SpacingSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
30
-
31
- export type TextSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
32
-
33
- export function isThemeColor(color: Color): color is ThemeColor {
34
- return color in ThemeColors
35
- }
36
-
37
- export interface ElementThemeColorValues {
38
- fill: ColorLiteral
39
- stroke: ColorLiteral
40
- // Main text (title, etc.)
41
- hiContrast: ColorLiteral
42
- // Secondary text (description, etc.)
43
- loContrast: ColorLiteral
44
- }
45
-
46
- export type ElementThemeColors = {
47
- [key in ThemeColor]: ElementThemeColorValues
48
- }
49
-
50
- export interface RelationshipThemeColorValues {
51
- lineColor: ColorLiteral
52
- labelBgColor: ColorLiteral
53
- labelColor: ColorLiteral
54
- }
55
-
56
- export interface ThemeColorValues {
57
- elements: ElementThemeColorValues
58
- relationships: RelationshipThemeColorValues
59
- }
60
-
61
- export type RelationshipThemeColors = {
62
- [key in ThemeColor]: RelationshipThemeColorValues
63
- }
64
-
65
- export interface LikeC4Theme {
66
- font: 'Arial'
67
- shadow: ColorLiteral
68
- relationships: RelationshipThemeColors
69
- elements: ElementThemeColors
70
- sizes: {
71
- [key in ShapeSize]: {
72
- width: number
73
- height: number
74
- }
75
- }
76
- spacing: {
77
- [key in SpacingSize]: number
78
- }
79
- textSizes: {
80
- [key in TextSize]: number
81
- }
82
- }
@@ -1,9 +0,0 @@
1
- import type { ElementShape } from './element'
2
- import type { Color } from './theme'
3
-
4
- export type ElementNotation = {
5
- kinds: string[]
6
- shape: ElementShape
7
- color: Color
8
- title: string
9
- }
@@ -1,10 +0,0 @@
1
- import dagre from '@dagrejs/dagre'
2
-
3
- const Graph = dagre.graphlib.Graph
4
-
5
- export { Graph }
6
-
7
- export const postorder = dagre.graphlib.alg.postorder
8
- export const preorder = dagre.graphlib.alg.preorder
9
- export const findCycles = dagre.graphlib.alg.findCycles
10
- export const isAcyclic = dagre.graphlib.alg.isAcyclic
File without changes