@likec4/core 1.41.0 → 1.42.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 (255) hide show
  1. package/builder/package.json +4 -0
  2. package/compute-view/package.json +4 -0
  3. package/compute-view/relationships/package.json +4 -0
  4. package/dist/builder/index.d.mts +13 -11
  5. package/dist/builder/index.mjs +111 -91
  6. package/dist/compute-view/index.d.mts +8 -7
  7. package/dist/compute-view/index.mjs +14 -11
  8. package/dist/compute-view/relationships-view/index.d.mts +9 -8
  9. package/dist/compute-view/relationships-view/index.mjs +6 -6
  10. package/dist/index.d.mts +7 -7
  11. package/dist/index.mjs +11 -11
  12. package/dist/model/connection/deployment/index.d.mts +11 -10
  13. package/dist/model/connection/deployment/index.mjs +2 -2
  14. package/dist/model/connection/index.d.mts +12 -11
  15. package/dist/model/connection/index.mjs +3 -3
  16. package/dist/model/connection/model/index.d.mts +11 -10
  17. package/dist/model/connection/model/index.mjs +2 -2
  18. package/dist/model/index.d.mts +14 -14
  19. package/dist/model/index.mjs +4 -5
  20. package/dist/shared/{core.Ae86Y3tB.mjs → core.01VTr9qu.mjs} +8 -26
  21. package/dist/shared/core.1vX5a9AY.mjs +86 -0
  22. package/dist/shared/{core.BVNaR17u.mjs → core.B7KhhkRY.mjs} +1 -1
  23. package/dist/shared/core.B85MJLTf.mjs +5 -0
  24. package/dist/shared/{core.DA5vzwZ9.mjs → core.BIqHjQiH.mjs} +56 -42
  25. package/dist/shared/core.BKlholso.mjs +3 -0
  26. package/dist/shared/core.BR4zXDH-.mjs +13 -0
  27. package/dist/shared/{core.CXy1NLUG.mjs → core.BYNkXQ8A.mjs} +21 -12
  28. package/dist/shared/{core.BuoXfSMj.mjs → core.BbE4y-yl.mjs} +1 -1
  29. package/dist/shared/core.BoYfZOBm.mjs +3 -0
  30. package/dist/shared/core.BsSXS-_R.mjs +7 -0
  31. package/dist/shared/{core.DJp8fgok.mjs → core.BzTakU3I.mjs} +14 -10
  32. package/dist/shared/{core.4u1dVmfX.mjs → core.C2TiyjI6.mjs} +2 -2
  33. package/dist/shared/{core.DLpidoWc.mjs → core.C3JowhaZ.mjs} +3 -3
  34. package/dist/shared/{core.CNGyqkJh.mjs → core.C4x8aaWa.mjs} +3 -1
  35. package/dist/shared/{core.BB6zA-UU.mjs → core.C8YY6Uub.mjs} +38 -9
  36. package/dist/shared/{core.Asc11Mjy.mjs → core.C8sl5Y8Z.mjs} +122 -58
  37. package/dist/shared/{core.BvMRMo7Z.mjs → core.CNgZvKb8.mjs} +3 -5198
  38. package/dist/shared/{core.CUG6vpyL.d.mts → core.CQngdcuj.d.mts} +85 -4
  39. package/dist/shared/{core.Be1n9a0i.mjs → core.C_Ni6yHl.mjs} +5 -4
  40. package/dist/shared/core.CbT8JVYL.mjs +5 -0
  41. package/dist/shared/core.CqAJJpK_.mjs +3 -0
  42. package/dist/shared/{core.BXsxn-hf.d.mts → core.D0PjZzIS.d.mts} +27 -15
  43. package/dist/shared/{core.DgesAwC8.d.mts → core.D5fzJWbF.d.mts} +2 -2
  44. package/dist/shared/{core.hfOE3RfK.d.mts → core.DACpKp35.d.mts} +5 -5
  45. package/dist/shared/core.DFi2dOTl.mjs +39548 -0
  46. package/dist/shared/{core.xSQO0XYD.d.mts → core.DIol3syK.d.mts} +2 -2
  47. package/dist/shared/{core.DlG1xWt2.mjs → core.DMMOWQqc.mjs} +3 -2
  48. package/dist/shared/core.DNbUPnve.mjs +3990 -0
  49. package/dist/shared/{core.CCD1ID81.mjs → core.DRJma0Ol.mjs} +4 -3
  50. package/dist/shared/{core.DgttqsJc.mjs → core.DRhg-gVU.mjs} +9 -9
  51. package/dist/shared/core.DSO_rTC2.mjs +5322 -0
  52. package/dist/shared/{core.FUPplpae.d.mts → core.D_vkffV4.d.mts} +4 -2
  53. package/dist/shared/core.DdMJk7nx.d.mts +476 -0
  54. package/dist/shared/{core.BhpgpOep.d.mts → core.Dgs6-nuz.d.mts} +2 -2
  55. package/dist/shared/{core.Be4Jy9Qx.mjs → core.FZ305VYd.mjs} +2 -2
  56. package/dist/shared/core.OHD4KXm9.mjs +5 -0
  57. package/dist/shared/{core.GTgsmXS_.mjs → core.QJD_fcrc.mjs} +2 -2
  58. package/dist/shared/core.RfnaEmgA.mjs +7 -0
  59. package/dist/shared/core.fHR_8Tnq.d.mts +450 -0
  60. package/dist/shared/{core.D0EgVMQK.mjs → core.lRvxPoao.mjs} +14 -12
  61. package/dist/shared/{core.CaT0SUUK.mjs → core.rCeaAqgW.mjs} +1 -84
  62. package/dist/shared/{core.zxTBF_PD.d.mts → core.s9uwOt60.d.mts} +4 -4
  63. package/dist/shared/core.yna0OdV5.d.mts +98 -0
  64. package/dist/styles/index.d.mts +106 -0
  65. package/dist/styles/index.mjs +1 -0
  66. package/dist/types/_aux.d.mts +2 -2
  67. package/dist/types/expression-model.d.mts +3 -4
  68. package/dist/types/expression.d.mts +3 -4
  69. package/dist/types/fqnRef.d.mts +2 -2
  70. package/dist/types/fqnRef.mjs +3 -3
  71. package/dist/types/index.d.mts +8 -8
  72. package/dist/types/index.mjs +150 -5
  73. package/dist/types/scalar.mjs +3 -2
  74. package/dist/utils/graphology/index.d.mts +1864 -0
  75. package/dist/utils/graphology/index.mjs +1 -0
  76. package/dist/utils/index.d.mts +11 -6
  77. package/dist/utils/index.mjs +21 -37
  78. package/dist/utils/iterable/index.d.mts +1 -1
  79. package/dist/utils/iterable/index.mjs +45 -7
  80. package/model/package.json +4 -0
  81. package/package.json +42 -24
  82. package/styles/package.json +4 -0
  83. package/types/package.json +4 -0
  84. package/utils/graphology/package.json +4 -0
  85. package/utils/package.json +4 -0
  86. package/dist/shared/core.6_Vp2iiN.mjs +0 -172
  87. package/dist/shared/core.CUw_2J9j.mjs +0 -47
  88. package/dist/shared/core.CzdwsPmY.d.mts +0 -69
  89. package/dist/shared/core.D-ZGWDDt.d.mts +0 -831
  90. package/dist/shared/core.DoM6aM9N.mjs +0 -7
  91. package/dist/shared/core.ILwny7BV.mjs +0 -38
  92. package/dist/theme/index.d.mts +0 -11
  93. package/dist/theme/index.mjs +0 -232
  94. package/src/builder/Builder.deployment.ts +0 -224
  95. package/src/builder/Builder.deploymentModel.ts +0 -449
  96. package/src/builder/Builder.element.ts +0 -241
  97. package/src/builder/Builder.model.ts +0 -494
  98. package/src/builder/Builder.ts +0 -946
  99. package/src/builder/Builder.view-common.ts +0 -273
  100. package/src/builder/Builder.view-deployment.ts +0 -135
  101. package/src/builder/Builder.view-element.ts +0 -202
  102. package/src/builder/Builder.views.ts +0 -399
  103. package/src/builder/Builder.with.ts +0 -156
  104. package/src/builder/_types.ts +0 -324
  105. package/src/builder/index.ts +0 -11
  106. package/src/compute-view/compute-view.ts +0 -80
  107. package/src/compute-view/deployment-view/_types.ts +0 -38
  108. package/src/compute-view/deployment-view/clean-connections.ts +0 -236
  109. package/src/compute-view/deployment-view/compute.ts +0 -94
  110. package/src/compute-view/deployment-view/memory/index.ts +0 -9
  111. package/src/compute-view/deployment-view/memory/memory.ts +0 -96
  112. package/src/compute-view/deployment-view/predicates/deploymentRefs-where.ts +0 -18
  113. package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +0 -154
  114. package/src/compute-view/deployment-view/predicates/index.ts +0 -8
  115. package/src/compute-view/deployment-view/predicates/relation-direct.ts +0 -243
  116. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +0 -70
  117. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +0 -101
  118. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +0 -95
  119. package/src/compute-view/deployment-view/predicates/relation-where.ts +0 -18
  120. package/src/compute-view/deployment-view/predicates/utils.ts +0 -282
  121. package/src/compute-view/deployment-view/predicates/wildcard.ts +0 -41
  122. package/src/compute-view/deployment-view/stages/stage-exclude.ts +0 -5
  123. package/src/compute-view/deployment-view/stages/stage-final.ts +0 -245
  124. package/src/compute-view/deployment-view/stages/stage-include.ts +0 -95
  125. package/src/compute-view/deployment-view/utils.ts +0 -297
  126. package/src/compute-view/dynamic-view/compute.ts +0 -312
  127. package/src/compute-view/element-view/_types.ts +0 -47
  128. package/src/compute-view/element-view/clean-connections.ts +0 -117
  129. package/src/compute-view/element-view/compute.ts +0 -324
  130. package/src/compute-view/element-view/memory/NodeGroup.ts +0 -31
  131. package/src/compute-view/element-view/memory/index.ts +0 -10
  132. package/src/compute-view/element-view/memory/memory.ts +0 -178
  133. package/src/compute-view/element-view/memory/stage-exclude.ts +0 -59
  134. package/src/compute-view/element-view/memory/stage-final.ts +0 -129
  135. package/src/compute-view/element-view/memory/stage-include.ts +0 -130
  136. package/src/compute-view/element-view/predicates/_utils.ts +0 -91
  137. package/src/compute-view/element-view/predicates/element-expand.ts +0 -29
  138. package/src/compute-view/element-view/predicates/element-kind-tag.ts +0 -27
  139. package/src/compute-view/element-view/predicates/element-ref.ts +0 -24
  140. package/src/compute-view/element-view/predicates/relation-direct.ts +0 -321
  141. package/src/compute-view/element-view/predicates/relation-in-out.ts +0 -64
  142. package/src/compute-view/element-view/predicates/relation-in.ts +0 -115
  143. package/src/compute-view/element-view/predicates/relation-out.ts +0 -119
  144. package/src/compute-view/element-view/predicates/wildcard.ts +0 -88
  145. package/src/compute-view/element-view/utils.ts +0 -65
  146. package/src/compute-view/index.ts +0 -4
  147. package/src/compute-view/memory/AbstractMemory.ts +0 -45
  148. package/src/compute-view/memory/AbstractStageExclude.ts +0 -215
  149. package/src/compute-view/memory/AbstractStageInclude.ts +0 -200
  150. package/src/compute-view/memory/_types.ts +0 -148
  151. package/src/compute-view/memory/index.ts +0 -5
  152. package/src/compute-view/memory/ops.ts +0 -43
  153. package/src/compute-view/relationships-view/_types.ts +0 -16
  154. package/src/compute-view/relationships-view/compute.ts +0 -159
  155. package/src/compute-view/relationships-view/index.ts +0 -3
  156. package/src/compute-view/relationships-view/layout.ts +0 -358
  157. package/src/compute-view/relationships-view/utils.ts +0 -73
  158. package/src/compute-view/utils/ancestorsOfNode.ts +0 -19
  159. package/src/compute-view/utils/applyCustomElementProperties.ts +0 -107
  160. package/src/compute-view/utils/applyCustomRelationProperties.ts +0 -58
  161. package/src/compute-view/utils/applyViewRuleStyles.ts +0 -73
  162. package/src/compute-view/utils/buildComputedNodes.ts +0 -166
  163. package/src/compute-view/utils/buildElementNotations.ts +0 -64
  164. package/src/compute-view/utils/elementExpressionToPredicate.ts +0 -50
  165. package/src/compute-view/utils/link-nodes-with-edges.ts +0 -56
  166. package/src/compute-view/utils/merge-props-from-relationships.ts +0 -161
  167. package/src/compute-view/utils/relationExpressionToPredicates.ts +0 -55
  168. package/src/compute-view/utils/resolve-extended-views.ts +0 -85
  169. package/src/compute-view/utils/resolve-global-rules.ts +0 -88
  170. package/src/compute-view/utils/topological-sort.ts +0 -256
  171. package/src/compute-view/utils/view-hash.ts +0 -45
  172. package/src/compute-view/utils/with-readable-edges.ts +0 -40
  173. package/src/index.ts +0 -32
  174. package/src/model/DeploymentElementModel.ts +0 -712
  175. package/src/model/DeploymentModel.ts +0 -393
  176. package/src/model/ElementModel.ts +0 -316
  177. package/src/model/LikeC4Model.ts +0 -882
  178. package/src/model/RelationModel.ts +0 -152
  179. package/src/model/connection/Connection.ts +0 -72
  180. package/src/model/connection/deployment/DeploymentConnectionModel.ts +0 -185
  181. package/src/model/connection/deployment/find.ts +0 -120
  182. package/src/model/connection/deployment/index.ts +0 -8
  183. package/src/model/connection/index.ts +0 -22
  184. package/src/model/connection/model/ConnectionModel.ts +0 -158
  185. package/src/model/connection/model/find.ts +0 -117
  186. package/src/model/connection/model/index.ts +0 -8
  187. package/src/model/connection/ops.ts +0 -276
  188. package/src/model/guards.ts +0 -77
  189. package/src/model/index.ts +0 -72
  190. package/src/model/types.ts +0 -67
  191. package/src/model/utils.ts +0 -66
  192. package/src/model/view/EdgeModel.ts +0 -121
  193. package/src/model/view/LikeC4ViewModel.ts +0 -361
  194. package/src/model/view/LikeC4ViewsFolder.ts +0 -151
  195. package/src/model/view/NodeModel.ts +0 -247
  196. package/src/theme/element.ts +0 -61
  197. package/src/theme/index.ts +0 -127
  198. package/src/theme/relationships.ts +0 -54
  199. package/src/types/RichText.ts +0 -205
  200. package/src/types/_aux.ts +0 -317
  201. package/src/types/_common.ts +0 -102
  202. package/src/types/const.ts +0 -34
  203. package/src/types/expression-model.ts +0 -294
  204. package/src/types/expression.ts +0 -313
  205. package/src/types/fqnRef.ts +0 -91
  206. package/src/types/geometry.ts +0 -159
  207. package/src/types/global.ts +0 -21
  208. package/src/types/index.ts +0 -44
  209. package/src/types/model-data.ts +0 -77
  210. package/src/types/model-deployment.ts +0 -78
  211. package/src/types/model-dump.ts +0 -79
  212. package/src/types/model-logical.ts +0 -126
  213. package/src/types/model-spec.ts +0 -88
  214. package/src/types/operators.ts +0 -156
  215. package/src/types/project.ts +0 -14
  216. package/src/types/scalar.ts +0 -162
  217. package/src/types/styles.ts +0 -122
  218. package/src/types/view-changes.ts +0 -32
  219. package/src/types/view-common.ts +0 -157
  220. package/src/types/view-computed.ts +0 -126
  221. package/src/types/view-layouted.ts +0 -94
  222. package/src/types/view-parsed.deployment.ts +0 -39
  223. package/src/types/view-parsed.dynamic.ts +0 -89
  224. package/src/types/view-parsed.element.ts +0 -65
  225. package/src/types/view.ts +0 -113
  226. package/src/utils/common-head.ts +0 -22
  227. package/src/utils/compare-natural.ts +0 -60
  228. package/src/utils/const.ts +0 -1
  229. package/src/utils/fqn.ts +0 -302
  230. package/src/utils/getOrCreate.ts +0 -8
  231. package/src/utils/guards.ts +0 -9
  232. package/src/utils/index.ts +0 -68
  233. package/src/utils/invariant.ts +0 -29
  234. package/src/utils/iterable/_types.ts +0 -5
  235. package/src/utils/iterable/filter.ts +0 -55
  236. package/src/utils/iterable/find.ts +0 -38
  237. package/src/utils/iterable/first.ts +0 -48
  238. package/src/utils/iterable/flat.ts +0 -17
  239. package/src/utils/iterable/head.ts +0 -22
  240. package/src/utils/iterable/index.ts +0 -15
  241. package/src/utils/iterable/map.ts +0 -40
  242. package/src/utils/iterable/reduce.ts +0 -24
  243. package/src/utils/iterable/some.ts +0 -36
  244. package/src/utils/iterable/to.ts +0 -19
  245. package/src/utils/iterable/unique.ts +0 -23
  246. package/src/utils/markdown/index.ts +0 -2
  247. package/src/utils/markdown/to-html.ts +0 -32
  248. package/src/utils/markdown/to-text.ts +0 -14
  249. package/src/utils/memoize-prop.ts +0 -30
  250. package/src/utils/mnemonist.ts +0 -9
  251. package/src/utils/object-hash.ts +0 -14
  252. package/src/utils/promises.ts +0 -24
  253. package/src/utils/relations.ts +0 -36
  254. package/src/utils/set.ts +0 -83
  255. package/src/utils/string-hash.ts +0 -16
@@ -1,156 +0,0 @@
1
- import { allPass, anyPass, isNot, isNullish, isString } from 'remeda'
2
- import { nonexhaustive } from '../utils/invariant'
3
- import type * as aux from './_aux'
4
- import type { Any } from './_aux'
5
- import type { NonEmptyArray } from './_common'
6
-
7
- export type EqualOperator<V> = {
8
- eq: V
9
- neq?: never
10
- } | {
11
- eq?: never
12
- neq: V
13
- }
14
-
15
- type AllNever = {
16
- not?: never
17
- and?: never
18
- or?: never
19
- tag?: never
20
- kind?: never
21
- participant?: never
22
- operator?: never
23
- }
24
-
25
- export type TagEqual<A extends Any> = Omit<AllNever, 'tag'> & {
26
- tag: EqualOperator<aux.Tag<A>> | aux.Tag<A>
27
- }
28
- export function isTagEqual<A extends Any>(operator: WhereOperator<A>): operator is TagEqual<A> {
29
- return 'tag' in operator
30
- }
31
-
32
- export type KindEqual<A extends Any> = Omit<AllNever, 'kind'> & {
33
- kind: EqualOperator<aux.AllKinds<A>> | aux.AllKinds<A>
34
- }
35
- export function isKindEqual<A extends Any>(operator: WhereOperator<A>): operator is KindEqual<A> {
36
- return 'kind' in operator
37
- }
38
-
39
- export type Participant = 'source' | 'target'
40
- export type ParticipantOperator<A extends Any> = Omit<AllNever, 'participant' | 'operator'> & {
41
- participant: Participant
42
- operator: KindEqual<A> | TagEqual<A>
43
- }
44
- export function isParticipantOperator<A extends Any>(
45
- operator: WhereOperator<A>,
46
- ): operator is ParticipantOperator<A> {
47
- return 'participant' in operator
48
- }
49
-
50
- export type NotOperator<A extends Any> = Omit<AllNever, 'not'> & {
51
- not: WhereOperator<A>
52
- }
53
- export function isNotOperator<A extends Any>(operator: WhereOperator<A>): operator is NotOperator<A> {
54
- return 'not' in operator
55
- }
56
-
57
- export type AndOperator<A extends Any> = Omit<AllNever, 'and'> & {
58
- and: NonEmptyArray<WhereOperator<A>>
59
- }
60
- export function isAndOperator<A extends Any>(operator: WhereOperator<A>): operator is AndOperator<A> {
61
- return 'and' in operator
62
- }
63
-
64
- export type OrOperator<A extends Any> = Omit<AllNever, 'or'> & {
65
- or: NonEmptyArray<WhereOperator<A>>
66
- }
67
- export function isOrOperator<A extends Any>(operator: WhereOperator<A>): operator is OrOperator<A> {
68
- return 'or' in operator
69
- }
70
-
71
- export type WhereOperator<A extends Any = Any> =
72
- | TagEqual<A>
73
- | KindEqual<A>
74
- | ParticipantOperator<A>
75
- | NotOperator<A>
76
- | AndOperator<A>
77
- | OrOperator<A>
78
-
79
- export type Filterable<A extends Any> = {
80
- tags?: aux.Tags<A> | null | undefined
81
- kind?: aux.AllKinds<A> | null | undefined
82
- source?: Filterable<A>
83
- target?: Filterable<A>
84
- }
85
-
86
- export type OperatorPredicate<A extends Any> = (value: Filterable<A>) => boolean
87
-
88
- export function whereOperatorAsPredicate<A extends Any>(
89
- operator: WhereOperator<A>,
90
- ): OperatorPredicate<A> {
91
- switch (true) {
92
- case isParticipantOperator(operator): {
93
- const participant = operator.participant
94
- const participantPredicate = whereOperatorAsPredicate(operator.operator)
95
-
96
- return participantIs(participant, participantPredicate)
97
- }
98
- case isTagEqual(operator): {
99
- if (isString(operator.tag) || 'eq' in operator.tag) {
100
- const tag = isString(operator.tag) ? operator.tag : operator.tag.eq
101
- return (value) => {
102
- return Array.isArray(value.tags) && value.tags.includes(tag)
103
- }
104
- }
105
- const tag = operator.tag.neq
106
- return (value) => {
107
- return !Array.isArray(value.tags) || !value.tags.includes(tag)
108
- }
109
- }
110
- case isKindEqual(operator): {
111
- if (isString(operator.kind) || 'eq' in operator.kind) {
112
- const kind = isString(operator.kind) ? operator.kind : operator.kind.eq
113
- return (value) => {
114
- return value.kind === kind
115
- }
116
- }
117
- const kind = operator.kind.neq
118
- return (value) => {
119
- return isNullish(value.kind) || value.kind !== kind
120
- }
121
- }
122
- case isNotOperator(operator): {
123
- const predicate = whereOperatorAsPredicate(operator.not)
124
- return isNot(predicate)
125
- }
126
- case isAndOperator(operator): {
127
- const predicates = operator.and.map(whereOperatorAsPredicate)
128
- return allPass(predicates)
129
- }
130
- case isOrOperator(operator): {
131
- const predicates = operator.or.map(whereOperatorAsPredicate)
132
- return anyPass(predicates)
133
- }
134
- default:
135
- nonexhaustive(operator)
136
- }
137
- }
138
-
139
- function participantIs<A extends Any>(
140
- participant: Participant,
141
- predicate: OperatorPredicate<A>,
142
- ): OperatorPredicate<A> {
143
- return (value) => {
144
- if (!value.source || !value.target) {
145
- return false
146
- }
147
- switch (participant) {
148
- case 'source': {
149
- return predicate(value.source)
150
- }
151
- case 'target': {
152
- return predicate(value.target)
153
- }
154
- }
155
- }
156
- }
@@ -1,14 +0,0 @@
1
- import * as scalar from './scalar'
2
-
3
- /**
4
- * Configuration of the project, as read from the config file.
5
- * LikeC4 projects encapsulate models, and can import from each other
6
- */
7
- export interface LikeC4Project {
8
- /**
9
- * ID of the project, casted to {@link scalar.ProjectId}
10
- */
11
- readonly id: scalar.ProjectId
12
-
13
- title?: string
14
- }
@@ -1,162 +0,0 @@
1
- import { isString, isTruthy } from 'remeda'
2
- import type { Tagged } from 'type-fest'
3
- import { invariant } from '../utils'
4
-
5
- export type ProjectId<T = string> = Tagged<T, 'ProjectID'>
6
- export function ProjectId(name: string): ProjectId {
7
- return name as unknown as ProjectId
8
- }
9
-
10
- export type MarkdownOrString = { txt: string; md?: never } | { md: string; txt?: never }
11
-
12
- /**
13
- * Converts a MarkdownOrString object or a plain string into a simple string representation.
14
- * This utility function handles different types of text content and normalizes them to a string format.
15
- *
16
- * @param value - The content to be flattened.
17
- * Can be one of:
18
- * - A plain string
19
- * - A MarkdownOrString object with either txt or md property
20
- * - undefined or null
21
- *
22
- * @returns The string content contained within the input value.
23
- * - Returns the input directly if it's already a string
24
- * - Returns the txt property if available in a MarkdownOrString object
25
- * - Falls back to the md property if txt is not available
26
- * - Returns null if:
27
- * - The input is null or undefined
28
- * - The resulting string value is empty, whitespace, or null
29
- *
30
- * @example
31
- * // String input
32
- * flattenMarkdownOrString("Hello world") // Returns: "Hello world"
33
- * flattenMarkdownOrString(" ") // Returns: null
34
- *
35
- * // MarkdownOrString with txt property
36
- * flattenMarkdownOrString({ txt: "Plain text" }) // Returns: "Plain text"
37
- * flattenMarkdownOrString({ txt: " " }) // Returns: null
38
- *
39
- * // MarkdownOrString with md property
40
- * flattenMarkdownOrString({ md: "**Bold markdown**" }) // Returns: "**Bold markdown**"
41
- *
42
- * // Null input
43
- * flattenMarkdownOrString(null) // Returns: null
44
- */
45
- export function flattenMarkdownOrString(value: MarkdownOrString | string): string
46
- export function flattenMarkdownOrString(value: MarkdownOrString | string | undefined | null): string | null
47
- export function flattenMarkdownOrString(value: MarkdownOrString | string | undefined | null): string | null {
48
- if (value === null || value === undefined) {
49
- return null
50
- }
51
- const content = isString(value) ? value : value.txt ?? value.md
52
- return isTruthy(content?.trim()) ? content : null
53
- }
54
-
55
- export type BuiltInIcon = 'none' | `${'aws' | 'azure' | 'gcp' | 'tech'}:${string}`
56
- export type Icon = Tagged<string, 'Icon'> | BuiltInIcon
57
- export type IconUrl = Icon
58
-
59
- /**
60
- * Full-qualified-name for model elements
61
- *
62
- * @param This - Fqn of the element (specific element)
63
- * @param All - The type of all known FQNs
64
- *
65
- * @example
66
- * ```ts
67
- * type ElementAFqn = Fqn<'a', 'a' | ' | 'b'>
68
- *
69
- * ```
70
- */
71
- export type Fqn<Id = string> = Tagged<Id, 'Fqn'>
72
- export function Fqn(name: string, parent?: Fqn | null): Fqn {
73
- return (parent ? parent + '.' + name : name) as unknown as Fqn
74
- }
75
-
76
- export type ElementKind<Kinds = string> = Tagged<Kinds, 'ElementKind'>
77
- export const GroupElementKind = '@group' as ElementKind<'@group'>
78
- export type GroupElementKind = typeof GroupElementKind
79
-
80
- export function isGroupElementKind<V extends { kind?: any }>(v: V): v is V & { kind: GroupElementKind } {
81
- return v.kind === GroupElementKind
82
- }
83
-
84
- /**
85
- * Full-qualified-name for deployment elements
86
- */
87
- export type DeploymentFqn<T = string> = Tagged<T, 'DeploymentFqn'>
88
- export function DeploymentFqn(name: string, parent?: DeploymentFqn | null): DeploymentFqn {
89
- return (parent ? parent + '.' + name : name) as unknown as DeploymentFqn
90
- }
91
-
92
- export type DeploymentKind<Kinds = string> = Tagged<Kinds, 'DeploymentKind'>
93
- export type ViewId<Id = string> = Tagged<Id, 'ViewId'>
94
- export function ViewId(id: string): ViewId {
95
- return id as any
96
- }
97
-
98
- export type AnyFqn<T = string> = DeploymentFqn<T> | Fqn<T>
99
-
100
- /**
101
- * @deprecated Use {@link RelationshipKind} instead
102
- */
103
- export type RelationKind<Kinds = string> = RelationshipKind<Kinds>
104
-
105
- export type RelationshipKind<Kinds = string> = Tagged<Kinds, 'RelationshipKind'>
106
- export type RelationId<Id = string> = Tagged<Id, 'RelationId'>
107
- export function RelationId(id: string): RelationId {
108
- return id as any
109
- }
110
-
111
- export type Tag<T = string> = Tagged<T, 'Tag'>
112
-
113
- export type GlobalFqn<Id = string> = Tagged<Fqn<Id>, 'GlobalFqn'>
114
- export function GlobalFqn<A>(projectId: A | ProjectId<A>, name: string): GlobalFqn<A> {
115
- invariant(isTruthy(projectId), 'Project ID must start with @')
116
- return '@' + projectId + '.' + name as any
117
- }
118
-
119
- export function isGlobalFqn<A extends string>(fqn: A): fqn is GlobalFqn<A> {
120
- return fqn.startsWith('@')
121
- }
122
-
123
- export function splitGlobalFqn<I extends string>(fqn: Fqn<I> | GlobalFqn<I>): [ProjectId | null, Fqn<I>] {
124
- if (!fqn.startsWith('@')) {
125
- return [null, fqn]
126
- }
127
- const firstDot = fqn.indexOf('.')
128
- if (firstDot < 2) {
129
- throw new Error('Invalid global FQN')
130
- }
131
- const projectId = fqn.slice(1, firstDot) as ProjectId<I>
132
- const name = fqn.slice(firstDot + 1) as Fqn<I>
133
- return [projectId, name]
134
- }
135
-
136
- export type NodeId = Tagged<string, 'NodeId' | 'Fqn' | 'DeploymentFqn'>
137
- export function NodeId(id: string): NodeId {
138
- return id as any
139
- }
140
- export type EdgeId = Tagged<string, 'EdgeId'>
141
- export function EdgeId(id: string): EdgeId {
142
- return id as any
143
- }
144
-
145
- export type StepEdgeIdLiteral = `step-${number}` | `step-${number}.${number}`
146
- export type StepEdgeId = Tagged<StepEdgeIdLiteral, 'EdgeId'>
147
- export function stepEdgeId(step: number, parallelStep?: number): StepEdgeId {
148
- const id = `step-${String(step).padStart(2, '0')}` as StepEdgeId
149
- return parallelStep ? `${id}.${parallelStep}` as StepEdgeId : id
150
- }
151
- export const StepEdgeKind = '@step'
152
-
153
- export function isStepEdgeId(id: string): id is StepEdgeId {
154
- return id.startsWith('step-')
155
- }
156
-
157
- export function extractStep(id: EdgeId): number {
158
- if (!isStepEdgeId(id)) {
159
- throw new Error(`Invalid step edge id: ${id}`)
160
- }
161
- return parseFloat(id.slice('step-'.length))
162
- }
@@ -1,122 +0,0 @@
1
- import type { Tagged, TupleToUnion } from 'type-fest'
2
-
3
- /**
4
- * For padding, margin, etc.
5
- */
6
- export type SpacingSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
7
- export type TextSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
8
- export type ShapeSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
9
-
10
- export const BorderStyles = ['solid', 'dashed', 'dotted', 'none'] as const
11
-
12
- export type BorderStyle = TupleToUnion<typeof BorderStyles>
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
-
26
- export type HexColor = `#${string}`
27
-
28
- export type ColorLiteral =
29
- | HexColor
30
- | `rgb(${number},${number},${number})`
31
- | `rgba(${number},${number},${number},${number})`
32
-
33
- export type CustomColor<T = string> = Tagged<T, 'CustomColor'>
34
-
35
- export type CustomColorDefinitions = { [key: string]: ThemeColorValues }
36
-
37
- export type RelationshipLineType = 'dashed' | 'solid' | 'dotted'
38
-
39
- // reference: https://graphviz.org/docs/attr-types/arrowType/
40
- export type RelationshipArrowType =
41
- | 'none'
42
- | 'normal'
43
- | 'onormal'
44
- | 'dot'
45
- | 'odot'
46
- | 'diamond'
47
- | 'odiamond'
48
- | 'crow'
49
- | 'open'
50
- | 'vee'
51
-
52
- export const ThemeColors = [
53
- 'amber',
54
- 'blue',
55
- 'gray',
56
- 'slate',
57
- 'green',
58
- 'indigo',
59
- 'muted',
60
- 'primary',
61
- 'red',
62
- 'secondary',
63
- 'sky',
64
- ] as const
65
- export type ThemeColor = typeof ThemeColors[number]
66
-
67
- /**
68
- * Backward compatibility alias
69
- * @deprecated Use {@link ThemeColor} instead
70
- */
71
- export type Color = ThemeColor | ColorLiteral
72
-
73
- export function isThemeColor(color: string): color is ThemeColor {
74
- return ThemeColors.includes(color as ThemeColor)
75
- }
76
-
77
- export interface ElementThemeColorValues {
78
- fill: ColorLiteral
79
- stroke: ColorLiteral
80
- // Main text (title, etc.)
81
- hiContrast: ColorLiteral
82
- // Secondary text (description, etc.)
83
- loContrast: ColorLiteral
84
- }
85
-
86
- export type ElementThemeColors = {
87
- [key in ThemeColor]: ElementThemeColorValues
88
- }
89
-
90
- export interface RelationshipThemeColorValues {
91
- lineColor: ColorLiteral
92
- labelBgColor: ColorLiteral
93
- labelColor: ColorLiteral
94
- }
95
-
96
- export interface ThemeColorValues {
97
- elements: ElementThemeColorValues
98
- relationships: RelationshipThemeColorValues
99
- }
100
-
101
- export type RelationshipThemeColors = {
102
- [key in ThemeColor]: RelationshipThemeColorValues
103
- }
104
-
105
- export interface LikeC4Theme {
106
- font: 'Arial'
107
- shadow: ColorLiteral
108
- relationships: RelationshipThemeColors
109
- elements: ElementThemeColors
110
- sizes: {
111
- [key in ShapeSize]: {
112
- width: number
113
- height: number
114
- }
115
- }
116
- spacing: {
117
- [key in SpacingSize]: number
118
- }
119
- textSizes: {
120
- [key in TextSize]: number
121
- }
122
- }
@@ -1,32 +0,0 @@
1
- import type { NonEmptyArray } from './_common'
2
- import type * as scalar from './scalar'
3
- import type { BorderStyle, ElementShape, ThemeColor } from './styles'
4
- import type { AutoLayoutDirection, ViewManualLayout } from './view-common'
5
-
6
- export namespace ViewChange {
7
- export interface ChangeElementStyle {
8
- op: 'change-element-style'
9
- style: {
10
- border?: BorderStyle
11
- opacity?: number
12
- shape?: ElementShape
13
- color?: ThemeColor
14
- }
15
- targets: NonEmptyArray<scalar.Fqn | scalar.DeploymentFqn>
16
- }
17
-
18
- export interface SaveManualLayout {
19
- op: 'save-manual-layout'
20
- layout: ViewManualLayout
21
- }
22
-
23
- export interface ChangeAutoLayout {
24
- op: 'change-autolayout'
25
- layout: {
26
- direction: AutoLayoutDirection
27
- nodeSep?: number | null
28
- rankSep?: number | null
29
- }
30
- }
31
- }
32
- export type ViewChange = ViewChange.ChangeElementStyle | ViewChange.SaveManualLayout | ViewChange.ChangeAutoLayout
@@ -1,157 +0,0 @@
1
- import type * as aux from './_aux'
2
- import type { AnyAux } from './_aux'
3
- import type { NonEmptyArray } from './_common'
4
- import type { _stage } from './const'
5
-
6
- import type { BBox, Point, XYPoint } from './geometry'
7
- import type { GlobalPredicateId, GlobalStyleID } from './global'
8
- import * as scalar from './scalar'
9
- import type {
10
- BorderStyle,
11
- Color,
12
- ElementShape,
13
- ShapeSize,
14
- SpacingSize,
15
- TextSize,
16
- } from './styles'
17
-
18
- export interface AnyIncludePredicate<Expr> {
19
- include: Expr[]
20
- exclude?: never
21
- }
22
- export interface AnyExcludePredicate<Expr> {
23
- include?: never
24
- exclude: Expr[]
25
- }
26
-
27
- export interface AnyViewRuleStyle<Expr> {
28
- targets: Expr[]
29
- notation?: string
30
- style: {
31
- border?: BorderStyle
32
- opacity?: number
33
- multiple?: boolean
34
- size?: ShapeSize
35
- padding?: SpacingSize
36
- textSize?: TextSize
37
- color?: Color
38
- shape?: ElementShape
39
- icon?: scalar.Icon
40
- }
41
- }
42
-
43
- export interface ViewRuleGlobalStyle {
44
- styleId: GlobalStyleID
45
- }
46
- export function isViewRuleGlobalStyle(rule: object): rule is ViewRuleGlobalStyle {
47
- return 'styleId' in rule
48
- }
49
-
50
- export interface ViewRuleGlobalPredicateRef {
51
- predicateId: GlobalPredicateId
52
- }
53
- export function isViewRuleGlobalPredicateRef(rule: object): rule is ViewRuleGlobalPredicateRef {
54
- return 'predicateId' in rule
55
- }
56
-
57
- export type AutoLayoutDirection = 'TB' | 'BT' | 'LR' | 'RL'
58
- export function isAutoLayoutDirection(autoLayout: unknown): autoLayout is AutoLayoutDirection {
59
- return autoLayout === 'TB' || autoLayout === 'BT' || autoLayout === 'LR' || autoLayout === 'RL'
60
- }
61
-
62
- export interface ViewRuleAutoLayout {
63
- direction: AutoLayoutDirection
64
- nodeSep?: number
65
- rankSep?: number
66
- }
67
-
68
- export function isViewRuleAutoLayout(rule: object): rule is ViewRuleAutoLayout {
69
- return 'direction' in rule
70
- }
71
-
72
- export interface ViewAutoLayout {
73
- direction: ViewRuleAutoLayout['direction']
74
- rankSep?: number
75
- nodeSep?: number
76
- }
77
-
78
- export type ViewManualLayout = {
79
- // Object hash of previous layout
80
- readonly hash: string
81
- readonly x: number
82
- readonly y: number
83
- readonly width: number
84
- readonly height: number
85
- readonly autoLayout: ViewAutoLayout
86
- readonly nodes: Record<string, {
87
- isCompound: boolean
88
- x: number
89
- y: number
90
- width: number
91
- height: number
92
- }>
93
- readonly edges: Record<string, {
94
- // Graphviz edge POS
95
- dotpos?: string
96
- // Bezier points
97
- points: NonEmptyArray<Point>
98
- // Control points to adjust the edge
99
- controlPoints?: NonEmptyArray<XYPoint>
100
- labelBBox?: BBox
101
- }>
102
- }
103
-
104
- export type ViewType = 'element' | 'dynamic' | 'deployment'
105
-
106
- export interface BaseViewProperties<A extends AnyAux> extends aux.WithOptionalTags<A>, aux.WithOptionalLinks {
107
- readonly id: aux.StrictViewId<A>
108
- readonly title: string | null
109
- readonly description: scalar.MarkdownOrString | null
110
- /**
111
- * For all views we find common ancestor path.
112
- * This is used to generate relative paths, i.e.:
113
- * - "/home/project/index.c4" becomes "index.c4"
114
- * - "/home/project/subdir/views.c4" becomes "subdir/views.c4"
115
- *
116
- * Undefined if the view is auto-generated.
117
- */
118
- readonly relativePath?: string | undefined
119
- }
120
-
121
- export interface BaseParsedViewProperties<A extends AnyAux> extends BaseViewProperties<A> {
122
- /**
123
- * Internal field to identify the stage of the view.
124
- * This is used to create the correct type of the view.
125
- */
126
- readonly [_stage]: 'parsed'
127
- /**
128
- * URI to the source file of this view.
129
- * Undefined if the view is auto-generated.
130
- */
131
- readonly docUri?: string | undefined
132
-
133
- /**
134
- * If the view is changed manually this field contains the layout data.
135
- */
136
- readonly manualLayout?: ViewManualLayout | undefined
137
- }
138
-
139
- export type NodeNotation = {
140
- kinds: string[]
141
- shape: ElementShape
142
- color: Color
143
- title: string
144
- }
145
-
146
- export interface ViewWithNotation {
147
- notation?: {
148
- nodes: NodeNotation[]
149
- }
150
- }
151
- export interface ViewWithHash {
152
- /**
153
- * Hash of the view object.
154
- * This is used to detect changes in layout
155
- */
156
- hash: string
157
- }