@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,273 +0,0 @@
1
- import { isArray, isString, map } from 'remeda'
2
- import type { LiteralUnion, Simplify } from 'type-fest'
3
- import {
4
- type Any,
5
- type AnyAux,
6
- type AnyViewRuleStyle as ViewRuleStyle,
7
- type AutoLayoutDirection,
8
- type Expression,
9
- type ModelRelationExpr,
10
- type NonEmptyArray,
11
- type WhereOperator,
12
- ModelFqnExpr,
13
- } from '../types'
14
- import type { Participant, ParticipantOperator } from '../types/operators'
15
- import type { AnyTypes, Types } from './_types'
16
-
17
- export interface LikeC4ViewBuilder<
18
- Types extends AnyTypes,
19
- Fqn extends string,
20
- TypedExpr,
21
- ElementExpr extends string = ViewPredicate.ElementExpr<Fqn>,
22
- Expr extends string = ViewPredicate.AllExpression<ElementExpr>,
23
- > {
24
- Types: Types
25
- ElementExpr: ElementExpr
26
- Expr: Expr
27
- TypedExpr: TypedExpr
28
- $expr(expr: Expr | TypedExpr): TypedExpr
29
- include(...exprs: Expr[]): this
30
- exclude(...exprs: Expr[]): this
31
- style(rule: ViewRuleStyle<any>): this
32
- autoLayout(layout: AutoLayoutDirection): this
33
- }
34
-
35
- export namespace ViewPredicate {
36
- export type ElementExpr<Fqn extends string> = '*' | Fqn | `${Fqn}.*` | `${Fqn}._` | `${Fqn}.**`
37
-
38
- export type AllExpression<ElementExpr extends string> =
39
- | ElementExpr
40
- | `-> ${ElementExpr} ->`
41
- | `-> ${ElementExpr}`
42
- | `${ElementExpr} ->`
43
- | `${ElementExpr} ${'->' | '<->'} ${ElementExpr}`
44
-
45
- export type Expression<T extends AnyTypes> = T extends
46
- Types<any, infer F extends string, any, any, any, any, any, any> ? AllExpression<ViewPredicate.ElementExpr<F>>
47
- : never
48
-
49
- export type ConnectionExpression<T extends AnyTypes> = T extends
50
- Types<any, infer F extends string, any, any, any, any, any, any> ? `${F} -> ${F}`
51
- : never
52
-
53
- export type DeploymentExpression<T extends AnyTypes> = T extends
54
- Types<any, any, any, any, any, any, any, infer F extends string> ? AllExpression<ViewPredicate.ElementExpr<F>>
55
- : never
56
-
57
- export type DeploymentConnectionExpression<T extends AnyTypes> = T extends
58
- Types<any, any, any, any, any, any, any, infer F extends string> ? `${F} -> ${F}`
59
- : never
60
-
61
- export type WhereTag<Tag extends string> = `tag ${'is' | 'is not'} #${Tag}`
62
- export type WhereKind<Kind extends string> = `kind ${'is' | 'is not'} ${Kind}`
63
- export type WhereParticipant<Types extends AnyTypes> = `${Participant}.${
64
- | WhereTag<Types['Tag']>
65
- | WhereKind<Types['ElementKind']>}`
66
-
67
- export type WhereEq<Types extends AnyTypes> =
68
- | ViewPredicate.WhereTag<Types['Tag']>
69
- | ViewPredicate.WhereKind<Types['ElementKind']>
70
- | ViewPredicate.WhereKind<Types['DeploymentKind']>
71
- | ViewPredicate.WhereParticipant<Types>
72
-
73
- export type WhereOperator<Types extends AnyTypes> = ViewPredicate.WhereEq<Types> | {
74
- and: NonEmptyArray<ViewPredicate.WhereOperator<Types>>
75
- or?: never
76
- not?: never
77
- } | {
78
- or: NonEmptyArray<ViewPredicate.WhereOperator<Types>>
79
- and?: never
80
- not?: never
81
- } | {
82
- not: ViewPredicate.WhereOperator<Types>
83
- and?: never
84
- or?: never
85
- }
86
-
87
- export type Custom<Types extends AnyTypes> = {
88
- where?: ViewPredicate.WhereOperator<Types>
89
- with?: Simplify<
90
- Omit<
91
- ModelFqnExpr.Custom['custom'] & ModelRelationExpr.Custom['customRelation'],
92
- 'expr' | 'relation' | 'navigateTo'
93
- > & {
94
- navigateTo?: Types['ViewId']
95
- }
96
- >
97
- }
98
- }
99
-
100
- function parseWhere(where: ViewPredicate.WhereOperator<AnyTypes>): WhereOperator<Any> {
101
- if (isString(where)) {
102
- const op = where as LiteralUnion<ViewPredicate.WhereEq<AnyTypes>, string>
103
- switch (true) {
104
- case op.startsWith('tag is not #'):
105
- return {
106
- tag: {
107
- neq: op.replace('tag is not #', ''),
108
- },
109
- }
110
- case op.startsWith('tag is #'):
111
- return {
112
- tag: {
113
- eq: op.replace('tag is #', ''),
114
- },
115
- }
116
- case op.startsWith('kind is not '):
117
- return {
118
- kind: {
119
- neq: op.replace('kind is not ', ''),
120
- },
121
- }
122
- case op.startsWith('kind is '):
123
- return {
124
- kind: {
125
- eq: op.replace('kind is ', ''),
126
- },
127
- }
128
- case op.startsWith('source.'):
129
- return {
130
- operator: parseWhere(
131
- op.replace('source.', '') as ViewPredicate.WhereOperator<AnyTypes>,
132
- ) as ParticipantOperator<AnyAux>['operator'],
133
- participant: 'source',
134
- }
135
- case op.startsWith('target.'):
136
- return {
137
- operator: parseWhere(
138
- op.replace('target.', '') as ViewPredicate.WhereOperator<AnyTypes>,
139
- ) as ParticipantOperator<AnyAux>['operator'],
140
- participant: 'target',
141
- }
142
- default:
143
- throw new Error(`Unknown where operator: ${where}`)
144
- }
145
- }
146
-
147
- if (where.and) {
148
- return {
149
- and: map(where.and, parseWhere),
150
- }
151
- }
152
- if (where.or) {
153
- return {
154
- or: map(where.or, parseWhere),
155
- }
156
- }
157
- if (where.not) {
158
- return {
159
- not: parseWhere(where.not),
160
- }
161
- }
162
-
163
- throw new Error(`Unknown where operator: ${where}`)
164
- }
165
-
166
- function $include<B extends LikeC4ViewBuilder<AnyTypes, any, any>>(
167
- ...args:
168
- | [B['Expr']]
169
- | [B['TypedExpr']]
170
- | [B['Expr'], ViewPredicate.Custom<B['Types']>]
171
- ): (b: B) => B {
172
- return (b) => {
173
- let expr = b.$expr(args[0])
174
- if (args.length === 2) {
175
- const condition = args[1].where ? parseWhere(args[1].where) : undefined
176
- if (condition) {
177
- expr = {
178
- where: {
179
- expr: expr as any,
180
- condition,
181
- },
182
- }
183
- }
184
-
185
- const custom = args[1].with
186
- if (custom) {
187
- const isElement = ModelFqnExpr.is(expr)
188
- if (isElement) {
189
- expr = {
190
- custom: {
191
- ...custom,
192
- expr: expr as any,
193
- },
194
- }
195
- } else {
196
- expr = {
197
- customRelation: {
198
- ...custom,
199
- expr: expr as any,
200
- },
201
- }
202
- }
203
- }
204
- }
205
- b.include(expr as any)
206
- return b
207
- }
208
- }
209
-
210
- function $exclude<B extends LikeC4ViewBuilder<AnyTypes, any, any>>(
211
- ...args:
212
- | [B['Expr']]
213
- | [B['TypedExpr']]
214
- | [B['Expr'], ViewPredicate.Custom<B['Types']>]
215
- | [B['TypedExpr'], ViewPredicate.Custom<B['Types']>]
216
- ): (b: B) => B {
217
- return (b) => {
218
- let expr = b.$expr(args[0]) as Expression
219
- if (args.length === 2 && args[1].where) {
220
- const condition = parseWhere(args[1].where)
221
- expr = {
222
- where: {
223
- expr: expr as any,
224
- condition,
225
- },
226
- }
227
- }
228
- b.exclude(expr)
229
- return b
230
- }
231
- }
232
-
233
- /**
234
- * @example
235
- * builder.views(({ view, $style }, _) =>
236
- * _(
237
- * view('view1').with(
238
- * $style('*', {
239
- * color: 'red',
240
- * }),
241
- * $style(['bob', 'alice'], {
242
- * color: 'blue',
243
- * }),
244
- * ),
245
- * )
246
- * )
247
- */
248
- function $style<B extends LikeC4ViewBuilder<AnyTypes, any, any>>(
249
- element: B['ElementExpr'] | B['TypedExpr'] | NonEmptyArray<B['ElementExpr']>,
250
- { notation, ...style }: ViewRuleStyle<any>['style'] & { notation?: string },
251
- ): (b: B) => B {
252
- return (b) =>
253
- b.style({
254
- targets: (isArray(element) ? element : [element]).map(e => b.$expr(e as any) as ModelFqnExpr),
255
- ...(notation ? { notation } : {}),
256
- style: {
257
- ...style,
258
- },
259
- })
260
- }
261
-
262
- function $autoLayout<B extends LikeC4ViewBuilder<AnyTypes, any, any>>(
263
- layout: AutoLayoutDirection,
264
- ): (b: B) => B {
265
- return (b) => b.autoLayout(layout)
266
- }
267
-
268
- type Op<T> = (b: T) => T
269
- function $rules<B extends LikeC4ViewBuilder<AnyTypes, any, any>>(...rules: Op<B>[]): (b: B) => B {
270
- return (b) => rules.reduce((b, rule) => rule(b), b)
271
- }
272
-
273
- export { $autoLayout, $exclude, $include, $rules, $style }
@@ -1,135 +0,0 @@
1
- import { isString } from 'remeda'
2
- import { type DeploymentFqn, type Expression } from '../types'
3
- import type { AnyTypes, Types } from './_types'
4
- import type { LikeC4ViewBuilder, ViewPredicate } from './Builder.view-common'
5
- import type { ViewsBuilder } from './Builder.views'
6
-
7
- export interface DeploymentViewBuilder<T extends AnyTypes>
8
- extends LikeC4ViewBuilder<T, T['DeploymentFqn'], Types.ToExpression<T>>
9
- {
10
- }
11
-
12
- export type DeploymentRulesBuilderOp<Types extends AnyTypes> = (
13
- b: DeploymentViewBuilder<Types>,
14
- ) => DeploymentViewBuilder<Types>
15
-
16
- export interface AddDeploymentViewRules<Id extends string> {
17
- with<S extends AnyTypes>(
18
- ...rules: DeploymentRulesBuilderOp<S>[]
19
- ): (builder: ViewsBuilder<S>) => ViewsBuilder<Types.AddView<S, Id>>
20
- }
21
-
22
- /**
23
- * Chainable builder to create element
24
- */
25
- export interface AddDeploymentViewHelper {
26
- <
27
- const Id extends string,
28
- T extends AnyTypes,
29
- >(
30
- id: Id,
31
- ): AddDeploymentViewRules<Id> & {
32
- (builder: ViewsBuilder<T>): ViewsBuilder<Types.AddView<T, Id>>
33
- }
34
-
35
- <
36
- const Id extends string,
37
- T extends AnyTypes,
38
- >(
39
- id: Id,
40
- bulder: (b: DeploymentViewBuilder<T>) => DeploymentViewBuilder<T>,
41
- ): (builder: ViewsBuilder<T>) => ViewsBuilder<Types.AddView<T, Id>>
42
-
43
- <
44
- const Id extends string,
45
- T extends AnyTypes,
46
- >(
47
- id: Id,
48
- propsOrTitle: T['NewViewProps'] | string,
49
- ): AddDeploymentViewRules<Id> & {
50
- (builder: ViewsBuilder<T>): ViewsBuilder<Types.AddView<T, Id>>
51
- }
52
-
53
- <
54
- const Id extends string,
55
- T extends AnyTypes,
56
- >(
57
- id: Id,
58
- propsOrTitle: T['NewViewProps'] | string,
59
- bulder: (b: DeploymentViewBuilder<T>) => DeploymentViewBuilder<T>,
60
- ): (builder: ViewsBuilder<T>) => ViewsBuilder<Types.AddView<T, Id>>
61
- }
62
-
63
- export function $deploymentExpr<T extends AnyTypes>(
64
- expr: ViewPredicate.DeploymentExpression<T> | Expression,
65
- ): Types.ToExpression<T> {
66
- if (!isString(expr)) {
67
- return expr as any
68
- }
69
- const asTypedDeploymentExpression = (expr: Expression): Types.ToExpression<T> => {
70
- return expr as any
71
- }
72
-
73
- if (expr === '*') {
74
- return asTypedDeploymentExpression({ wildcard: true })
75
- }
76
- if (expr.startsWith('->')) {
77
- if (expr.endsWith('->')) {
78
- return asTypedDeploymentExpression({
79
- inout: $deploymentExpr(expr.replace(/->/g, '').trim()) as any,
80
- })
81
- }
82
- return asTypedDeploymentExpression({
83
- incoming: $deploymentExpr(expr.replace('-> ', '')) as any,
84
- })
85
- }
86
- if (expr.endsWith(' ->')) {
87
- return asTypedDeploymentExpression({
88
- outgoing: $deploymentExpr(expr.replace(' ->', '')) as any,
89
- })
90
- }
91
- if (expr.includes(' <-> ')) {
92
- const [source, target] = expr.split(' <-> ')
93
- return asTypedDeploymentExpression({
94
- source: $deploymentExpr(source) as any,
95
- target: $deploymentExpr(target) as any,
96
- isBidirectional: true,
97
- })
98
- }
99
- if (expr.includes(' -> ')) {
100
- const [source, target] = expr.split(' -> ')
101
- return asTypedDeploymentExpression({
102
- source: $deploymentExpr(source) as any,
103
- target: $deploymentExpr(target) as any,
104
- })
105
- }
106
- if (expr.endsWith('._')) {
107
- return asTypedDeploymentExpression({
108
- ref: {
109
- deployment: expr.replace('._', '') as DeploymentFqn,
110
- },
111
- selector: 'expanded',
112
- })
113
- }
114
- if (expr.endsWith('.**')) {
115
- return asTypedDeploymentExpression({
116
- ref: {
117
- deployment: expr.replace('.**', '') as DeploymentFqn,
118
- },
119
- selector: 'descendants',
120
- })
121
- }
122
- if (expr.endsWith('.*')) {
123
- return asTypedDeploymentExpression({
124
- ref: {
125
- deployment: expr.replace('.*', '') as DeploymentFqn,
126
- },
127
- selector: 'children',
128
- })
129
- }
130
- return asTypedDeploymentExpression({
131
- ref: {
132
- deployment: expr as DeploymentFqn,
133
- },
134
- })
135
- }
@@ -1,202 +0,0 @@
1
- import { isString } from 'remeda'
2
- import type { IsLiteral } from 'type-fest'
3
- import { type Expression, type Fqn } from '../types'
4
- import type { AnyTypes, Invalid, Types } from './_types'
5
- import type { LikeC4ViewBuilder, ViewPredicate } from './Builder.view-common'
6
- import type { ViewsBuilder } from './Builder.views'
7
-
8
- export interface ElementViewBuilder<T extends AnyTypes>
9
- extends LikeC4ViewBuilder<T, T['Fqn'], Expression<Types.ToAux<T>>>
10
- {
11
- }
12
-
13
- export type ElementViewRulesBuilder<T extends AnyTypes> = (b: ElementViewBuilder<T>) => ElementViewBuilder<T>
14
-
15
- export interface AddViewRules<Id extends string> {
16
- with<S extends AnyTypes>(
17
- ...rules: ElementViewRulesBuilder<S>[]
18
- ): (builder: ViewsBuilder<S>) => ViewsBuilder<Types.AddView<S, Id>>
19
- }
20
-
21
- export interface AddViewHelper {
22
- <
23
- const Id extends string,
24
- T extends AnyTypes,
25
- >(
26
- id: Id,
27
- ): AddViewRules<Id> & {
28
- (builder: ViewsBuilder<T>): ViewsBuilder<Types.AddView<T, Id>>
29
- }
30
-
31
- <
32
- const Id extends string,
33
- T extends AnyTypes,
34
- >(
35
- id: Id,
36
- builder: (b: ElementViewBuilder<T>) => ElementViewBuilder<T>,
37
- ): AddViewRules<Id> & {
38
- (builder: ViewsBuilder<T>): ViewsBuilder<Types.AddView<T, Id>>
39
- }
40
-
41
- <
42
- const Id extends string,
43
- T extends AnyTypes,
44
- >(
45
- id: Id,
46
- propsOrTitle: NoInfer<T['NewViewProps']> | string,
47
- ): AddViewRules<Id> & {
48
- (builder: ViewsBuilder<T>): ViewsBuilder<Types.AddView<T, Id>>
49
- }
50
-
51
- <
52
- const Id extends string,
53
- T extends AnyTypes,
54
- >(
55
- id: Id,
56
- propsOrTitle: NoInfer<T['NewViewProps']> | string | undefined,
57
- builder: (b: ElementViewBuilder<T>) => ElementViewBuilder<T>,
58
- ): AddViewRules<Id> & {
59
- (builder: ViewsBuilder<T>): ViewsBuilder<Types.AddView<T, Id>>
60
- }
61
- }
62
-
63
- type ValidFqn<T extends AnyTypes> = IsLiteral<T['Fqn']> extends true ? T['Fqn']
64
- : Invalid<'Fqn must be a literal'>
65
-
66
- export interface AddViewOfHelper {
67
- <
68
- const Id extends string,
69
- T extends AnyTypes,
70
- >(
71
- id: Id,
72
- of: ValidFqn<T>,
73
- ): (builder: ViewsBuilder<T>) => ViewsBuilder<Types.AddView<T, Id>>
74
-
75
- <
76
- const Id extends string,
77
- T extends AnyTypes,
78
- >(
79
- id: Id,
80
- of: ValidFqn<T>,
81
- propsOrTitle: T['NewViewProps'] | string | ElementViewRulesBuilder<T>,
82
- ): (builder: ViewsBuilder<T>) => ViewsBuilder<Types.AddView<T, Id>>
83
-
84
- <
85
- const Id extends string,
86
- T extends AnyTypes,
87
- >(
88
- id: Id,
89
- of: ValidFqn<T>,
90
- propsOrTitle: NoInfer<T>['NewViewProps'] | string,
91
- builder: (b: ElementViewBuilder<T>) => ElementViewBuilder<T>,
92
- ): (builder: ViewsBuilder<T>) => ViewsBuilder<Types.AddView<T, Id>>
93
- }
94
-
95
- export interface TypedAddViewOfHelper<A extends AnyTypes> {
96
- <
97
- const Id extends string,
98
- T extends AnyTypes,
99
- >(
100
- id: Id,
101
- of: ValidFqn<A>,
102
- ): AddViewRules<Id> & {
103
- (builder: ViewsBuilder<T>): ViewsBuilder<Types.AddView<T, Id>>
104
- }
105
-
106
- <
107
- const Id extends string,
108
- T extends AnyTypes,
109
- >(
110
- id: Id,
111
- of: ValidFqn<A>,
112
- builder: ((b: ElementViewBuilder<A>) => ElementViewBuilder<A>) | A['NewViewProps'] | string,
113
- ): AddViewRules<Id> & {
114
- (builder: ViewsBuilder<T>): ViewsBuilder<Types.AddView<T, Id>>
115
- }
116
-
117
- <
118
- const Id extends string,
119
- T extends AnyTypes,
120
- >(
121
- id: Id,
122
- of: ValidFqn<A>,
123
- propsOrTitle: A['NewViewProps'] | string,
124
- builder: (b: ElementViewBuilder<A>) => ElementViewBuilder<A>,
125
- ): AddViewRules<Id> & {
126
- (builder: ViewsBuilder<T>): ViewsBuilder<Types.AddView<T, Id>>
127
- }
128
- }
129
- // To hook types
130
- const asTypedExpr = <T extends AnyTypes>(expr: Expression): Expression<Types.ToAux<T>> => {
131
- return expr as Expression<Types.ToAux<T>>
132
- }
133
-
134
- export function $expr<T extends AnyTypes>(
135
- expr: ViewPredicate.Expression<T> | Expression,
136
- ): Expression<Types.ToAux<T>> {
137
- if (!isString(expr)) {
138
- return expr as Expression<Types.ToAux<T>>
139
- }
140
- if (expr === '*') {
141
- return asTypedExpr({ wildcard: true })
142
- }
143
- if (expr.startsWith('->')) {
144
- if (expr.endsWith('->')) {
145
- return asTypedExpr({
146
- inout: $expr(expr.replace(/->/g, '').trim()) as any,
147
- })
148
- }
149
- return asTypedExpr({
150
- incoming: $expr(expr.replace('-> ', '')) as any,
151
- })
152
- }
153
- if (expr.endsWith(' ->')) {
154
- return asTypedExpr({
155
- outgoing: $expr(expr.replace(' ->', '')) as any,
156
- })
157
- }
158
- if (expr.includes(' <-> ')) {
159
- const [source, target] = expr.split(' <-> ')
160
- return asTypedExpr({
161
- source: $expr(source) as any,
162
- target: $expr(target) as any,
163
- isBidirectional: true,
164
- })
165
- }
166
- if (expr.includes(' -> ')) {
167
- const [source, target] = expr.split(' -> ')
168
- return asTypedExpr({
169
- source: $expr(source) as any,
170
- target: $expr(target) as any,
171
- })
172
- }
173
- if (expr.endsWith('._')) {
174
- return asTypedExpr({
175
- ref: {
176
- model: expr.replace('._', '') as Fqn,
177
- },
178
- selector: 'expanded',
179
- })
180
- }
181
- if (expr.endsWith('.**')) {
182
- return asTypedExpr({
183
- ref: {
184
- model: expr.replace('.**', '') as Fqn,
185
- },
186
- selector: 'descendants',
187
- })
188
- }
189
- if (expr.endsWith('.*')) {
190
- return asTypedExpr({
191
- ref: {
192
- model: expr.replace('.*', '') as Fqn,
193
- },
194
- selector: 'children',
195
- })
196
- }
197
- return asTypedExpr({
198
- ref: {
199
- model: expr as any as Fqn,
200
- },
201
- })
202
- }