@likec4/core 1.41.0 → 1.42.1

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,65 +0,0 @@
1
- import { filter, hasAtLeast, only } from 'remeda'
2
- import type { ConnectionModel } from '../../model'
3
- import {
4
- type AnyAux,
5
- type ComputedEdge,
6
- type ComputedNode,
7
- type scalar,
8
- } from '../../types'
9
- import { invariant } from '../../utils'
10
- import { buildComputedNodes, elementModelToNodeSource } from '../utils/buildComputedNodes'
11
- import { mergePropsFromRelationships } from '../utils/merge-props-from-relationships'
12
- import type { Memory } from './_types'
13
-
14
- export const NoWhere = () => true
15
- export const NoFilter = <T>(x: T[] | readonly T[]): T[] => x as T[]
16
-
17
- export function toComputedEdges<A extends AnyAux>(
18
- connections: ReadonlyArray<ConnectionModel<A>>,
19
- ): ComputedEdge<A>[] {
20
- return connections.reduce((acc, e) => {
21
- // const modelRelations = []
22
- // const deploymentRelations = []
23
- const relations = [
24
- ...e.relations,
25
- ]
26
- invariant(hasAtLeast(relations, 1), 'Edge must have at least one relation')
27
-
28
- const source = e.source.id
29
- const target = e.target.id
30
-
31
- const {
32
- title,
33
- ...props
34
- } = mergePropsFromRelationships(
35
- relations.map(r => r.$relationship),
36
- // Prefer only single relationship
37
- // https://github.com/likec4/likec4/issues/1423
38
- only(
39
- filter(relations, r => r.source.id === source && r.target.id === target),
40
- )?.$relationship,
41
- )
42
-
43
- const edge: ComputedEdge<A> = {
44
- id: e.id,
45
- parent: e.boundary?.id as scalar.NodeId ?? null,
46
- source: source as scalar.NodeId,
47
- target: target as scalar.NodeId,
48
- label: title ?? null,
49
- relations: relations.map((r) => r.id),
50
- ...props,
51
- }
52
-
53
- acc.push(edge)
54
- return acc
55
- }, [] as ComputedEdge<A>[])
56
- }
57
-
58
- export function buildNodes<A extends AnyAux>(
59
- memory: Memory,
60
- ): ReadonlyMap<scalar.NodeId, ComputedNode<A>> {
61
- return buildComputedNodes(
62
- [...memory.final].map(elementModelToNodeSource),
63
- memory.groups,
64
- )
65
- }
@@ -1,4 +0,0 @@
1
- export { computeLikeC4Model, computeParsedModelData, computeView, unsafeComputeView } from './compute-view'
2
- export type { ComputeViewResult } from './compute-view'
3
- export { resolveRulesExtendedViews } from './utils/resolve-extended-views'
4
- export { viewsWithReadableEdges, withReadableEdges } from './utils/with-readable-edges'
@@ -1,45 +0,0 @@
1
- import type { AnyCtx, ComputeMemory, GenericCtx, MutableState, StageExpression } from './_types'
2
-
3
- export abstract class AbstractMemory<T extends AnyCtx = GenericCtx> implements ComputeMemory<T> {
4
- /**
5
- * Provides access to context types
6
- * !IMPORTANT: Should not be called in runtime
7
- *
8
- * @example
9
- * ```ts
10
- * type State = SomeMemory['Ctx']['MutableState']
11
- * ```
12
- */
13
- public get Ctx(): T {
14
- throw new Error('Should not be called in runtime')
15
- }
16
-
17
- protected constructor(protected state: MutableState<T>) {
18
- }
19
-
20
- public get elements(): ReadonlySet<T['Element']> {
21
- return this.state.elements
22
- }
23
- public get explicits(): ReadonlySet<T['Element']> {
24
- return this.state.explicits
25
- }
26
- public get final(): ReadonlySet<T['Element']> {
27
- return this.state.final
28
- }
29
- public get connections(): ReadonlyArray<T['Connection']> {
30
- return this.state.connections
31
- }
32
-
33
- public isEmpty(): boolean {
34
- return this.elements.size === 0 && this.connections.length === 0
35
- && this.explicits.size === 0 && this.final.size === 0
36
- }
37
-
38
- abstract mutableState(): MutableState<T>
39
-
40
- abstract stageInclude(expr: StageExpression<T>): T['StageInclude']
41
-
42
- abstract stageExclude(expr: StageExpression<T>): T['StageExclude']
43
-
44
- abstract update(newstate: Partial<MutableState<T>>): T['Memory']
45
- }
@@ -1,215 +0,0 @@
1
- import { isBoolean, pipe } from 'remeda'
2
- import { findAscendingConnections } from '../../model'
3
- import { difference, intersection, invariant, isDescendantOf, isIterable } from '../../utils'
4
- import { ifilter, isome, toSet } from '../../utils/iterable'
5
- import type { AnyCtx, CtxConnection, CtxElement, MutableState, StageExclude, StageExpression } from './_types'
6
-
7
- export abstract class AbstractStageExclude<T extends AnyCtx> implements StageExclude<T> {
8
- // Removed elements
9
- protected excluded = {
10
- elements: new Set<CtxElement<T>>(),
11
- connections: [] as CtxConnection<T>[],
12
- }
13
-
14
- constructor(
15
- public readonly memory: T['Memory'],
16
- public readonly expression: StageExpression<T>,
17
- ) {
18
- }
19
-
20
- protected markedToMoveExplicitToImplicit = false
21
-
22
- protected _removeElement(element: CtxElement<T>): void {
23
- this.excluded.elements.add(element)
24
- }
25
-
26
- public exclude(element: CtxElement<T> | Iterable<CtxElement<T>> | false | undefined | null): this {
27
- if (!element) {
28
- return this
29
- }
30
- if (isIterable(element)) {
31
- for (const el of element) {
32
- this._removeElement(el)
33
- }
34
- return this
35
- }
36
- this._removeElement(element)
37
- return this
38
- }
39
-
40
- protected _removeConnection(connection: CtxConnection<T>): void {
41
- this.excluded.connections.push(connection)
42
- }
43
- /**
44
- * Excludes from the memory relationships from given connections (still connection may be included, but without given relationships)
45
- * @param moveExplicitToImplicit - if true, disconnected explicit elements will be moved to implicit
46
- * @default false
47
- */
48
- public excludeConnections(
49
- connection: CtxConnection<T> | Iterable<CtxConnection<T>>,
50
- moveExplicitToImplicit?: boolean,
51
- ) {
52
- if (isBoolean(moveExplicitToImplicit)) {
53
- invariant(!this.markedToMoveExplicitToImplicit, 'Already marked to move explicits')
54
- this.markedToMoveExplicitToImplicit = moveExplicitToImplicit
55
- }
56
- if (isIterable(connection)) {
57
- for (const c of connection) {
58
- this._removeConnection(c)
59
- }
60
- return this
61
- }
62
- this._removeConnection(connection)
63
- return this
64
- }
65
-
66
- public isDirty(): boolean {
67
- return this.excluded.elements.size > 0 || this.excluded.connections.length > 0
68
- }
69
-
70
- public isEmpty(): boolean {
71
- return !this.isDirty()
72
- }
73
-
74
- /**
75
- * Determines whether disconnected explicits should become implicits.
76
- * By default moves all disconnected explicits to implicits, if there were operation to exclude elements.
77
- *
78
- * Override this method to change the behavior.
79
- */
80
- protected filterForMoveToImplicits(disconnectedExplicits: Set<CtxElement<T>>): Set<CtxElement<T>> {
81
- if (this.markedToMoveExplicitToImplicit || this.excluded.elements.size > 0) {
82
- return disconnectedExplicits
83
- }
84
- return new Set()
85
- }
86
-
87
- // Check if Leaf EXPLICIT elements are becoming IMPLICIT
88
- // (it means that they are not connected anymore)
89
- protected moveDisconnectedExplicitsToImplicits(state: MutableState<T>): MutableState<T> {
90
- // Check if EXPLICIT elements are becoming IMPLICIT
91
- let disconnected = difference(
92
- new Set(this.memory.connections.flatMap(c => [c.source, c.target])),
93
- new Set(state.connections.flatMap(c => [c.source, c.target])),
94
- )
95
- // Ensure existing in implicits
96
- disconnected = intersection(
97
- disconnected,
98
- state.elements,
99
- )
100
- // Ensure this is a leaf explici element
101
- disconnected = pipe(
102
- disconnected,
103
- ifilter(el => {
104
- return state.explicits.has(el) && !isome(state.final, isDescendantOf(el))
105
- }),
106
- toSet(),
107
- )
108
- if (disconnected.size > 0) {
109
- disconnected = this.filterForMoveToImplicits(disconnected)
110
- state.explicits = difference(state.explicits, disconnected)
111
- // Exclude from final elements
112
- state.final = difference(state.final, disconnected)
113
- }
114
- return state
115
- }
116
-
117
- protected removeElements(state: MutableState<T>): MutableState<T> {
118
- state.elements = difference(state.elements, this.excluded.elements)
119
- state.explicits = difference(state.explicits, this.excluded.elements)
120
- state.final = difference(state.final, this.excluded.elements)
121
- return state
122
- }
123
-
124
- protected removeConnections(state: MutableState<T>): MutableState<T> {
125
- const excludedMap = this.excluded.connections.reduce((acc, c) => {
126
- const existing = acc.get(c.id)
127
- if (existing) {
128
- acc.set(c.id, existing.mergeWith(c) as CtxConnection<T>)
129
- } else {
130
- acc.set(c.id, c)
131
- }
132
- return acc
133
- }, new Map<string, CtxConnection<T>>())
134
-
135
- // were connected before and not anymore
136
- let disconnected = new Set<CtxElement<T>>()
137
-
138
- state.connections = state.connections.reduce((acc, c) => {
139
- const excluded = excludedMap.get(c.id)
140
- if (excluded) {
141
- disconnected.add(c.source)
142
- disconnected.add(c.target)
143
- const diff = c.difference(excluded) as CtxConnection<T>
144
- if (diff.nonEmpty()) {
145
- acc.push(diff)
146
- }
147
- } else {
148
- acc.push(c)
149
- }
150
- return acc
151
- }, [] as CtxConnection<T>[])
152
-
153
- for (const stillExists of state.connections) {
154
- disconnected.delete(stillExists.source)
155
- disconnected.delete(stillExists.target)
156
- if (stillExists.boundary && state.elements.has(stillExists.boundary)) {
157
- disconnected.delete(stillExists.boundary)
158
- }
159
- }
160
-
161
- if (disconnected.size === 0) {
162
- return state
163
- }
164
- // Keep explicits
165
- disconnected = difference(disconnected, state.explicits)
166
- // Even if not connected, implicit elements should be kept
167
- // state.elements = difference(state.elements, excludedElements)
168
- state.final = difference(state.final, disconnected)
169
-
170
- return state
171
- }
172
-
173
- /**
174
- * Precommit hook
175
- */
176
- protected precommit(state: MutableState<T>): MutableState<T> {
177
- return state
178
- }
179
-
180
- /**
181
- * Postcommit hook
182
- */
183
- protected postcommit(state: MutableState<T>): MutableState<T> {
184
- invariant(difference(state.explicits, state.elements).size === 0, 'Explicits must be subset of elements')
185
- invariant(difference(state.final, state.elements).size === 0, 'Final elements must be subset of elements')
186
- return state
187
- }
188
-
189
- public commit(): T['Memory'] {
190
- let state = this.precommit(this.memory.mutableState())
191
-
192
- // Exclude connections from excluded elements
193
- if (this.excluded.elements.size > 0) {
194
- const excludedConnections = state.connections
195
- .filter(c => this.excluded.elements.has(c.source) || this.excluded.elements.has(c.target))
196
- .flatMap(c => [
197
- c,
198
- ...findAscendingConnections(state.connections, c)
199
- .map(asc => asc.intersect(c) as CtxConnection<T>),
200
- ])
201
- .filter(asc => asc.nonEmpty())
202
- this.excludeConnections(excludedConnections)
203
- }
204
- if (this.excluded.connections.length > 0) {
205
- state = this.removeConnections(state)
206
- }
207
- if (this.excluded.elements.size > 0) {
208
- state = this.removeElements(state)
209
- }
210
-
211
- // state = this.moveDisconnectedExplicitsToImplicits(state)
212
-
213
- return this.memory.update(this.postcommit(state))
214
- }
215
- }
@@ -1,200 +0,0 @@
1
- import { partition } from 'remeda'
2
- import { mergeConnections } from '../../model'
3
- import { intersection, isIterable, union } from '../../utils'
4
- import type {
5
- AnyCtx,
6
- CtxConnection as Connection,
7
- CtxElement as Elem,
8
- GenericCtx,
9
- MutableState,
10
- StageExpression,
11
- StageInclude,
12
- } from './_types'
13
-
14
- export abstract class AbstractStageInclude<T extends AnyCtx = GenericCtx> implements StageInclude<T> {
15
- // New elements
16
- protected explicits = new Set<Elem<T>>()
17
- protected implicits = new Set<Elem<T>>()
18
-
19
- // Ordered Set of explicit and implicit elements
20
- protected _ordered = new Set<Elem<T>>()
21
-
22
- protected _connections = [] as Connection<T>[]
23
-
24
- constructor(
25
- public readonly memory: T['Memory'],
26
- public readonly expression: StageExpression<T>,
27
- ) {
28
- }
29
-
30
- get elements(): ReadonlySet<Elem<T>> {
31
- return this.explicits
32
- }
33
-
34
- /**
35
- * Connections from this stage
36
- */
37
- get connections(): readonly Connection<T>[] {
38
- return this._connections
39
- }
40
-
41
- mergedConnections(): readonly Connection<T>[] {
42
- return mergeConnections([
43
- ...this.memory.connections,
44
- ...this._connections,
45
- ])
46
- }
47
-
48
- public connectWithExisting(
49
- _element: Elem<T> | Iterable<Elem<T>>,
50
- _direction?: 'in' | 'out' | 'both',
51
- ): boolean {
52
- throw new Error('Method not implements, depends on the model')
53
- }
54
-
55
- /**
56
- * Possible to override
57
- */
58
- protected _addExplicit(elements: Elem<T>): void {
59
- this._ordered.add(elements)
60
- this.explicits.add(elements)
61
- this.implicits.delete(elements)
62
- }
63
-
64
- public addExplicit(element: Elem<T> | Iterable<Elem<T>> | false | undefined | null): this {
65
- if (!element) {
66
- return this
67
- }
68
- if (isIterable(element)) {
69
- for (const el of element) {
70
- this._addExplicit(el)
71
- }
72
- return this
73
- }
74
- this._addExplicit(element)
75
- return this
76
- }
77
-
78
- /**
79
- * Possible to override
80
- */
81
- protected _addImplicit(elements: Elem<T>): void {
82
- if (this.explicits.has(elements)) {
83
- return
84
- }
85
- this._ordered.add(elements)
86
- this.implicits.add(elements)
87
- }
88
-
89
- public addImplicit(elements: Elem<T> | Iterable<Elem<T>> | false | undefined | null): this {
90
- if (!elements) {
91
- return this
92
- }
93
- if (isIterable(elements)) {
94
- for (const el of elements) {
95
- this._addImplicit(el)
96
- }
97
- return this
98
- }
99
- this._addImplicit(elements)
100
- return this
101
- }
102
-
103
- /**
104
- * Possible to override
105
- */
106
- protected _addConnection(connection: Connection<T>): void {
107
- this._connections.push(connection)
108
- this._addImplicit(connection.source)
109
- this._addImplicit(connection.target)
110
- }
111
-
112
- public addConnections(connection: Connection<T> | Iterable<Connection<T>>): this {
113
- if (isIterable(connection)) {
114
- for (const c of connection) {
115
- this._addConnection(c)
116
- }
117
- return this
118
- }
119
- this._addConnection(connection)
120
- return this
121
- }
122
-
123
- public isDirty(): boolean {
124
- return this.explicits.size > 0 || this.implicits.size > 0 || this._connections.length > 0
125
- }
126
-
127
- public isEmpty(): boolean {
128
- return !this.isDirty()
129
- }
130
-
131
- /**
132
- * Precommit hook
133
- */
134
- protected precommit(state: MutableState<T>): MutableState<T> {
135
- return state
136
- }
137
-
138
- /**
139
- * Postcommit hook
140
- */
141
- protected postcommit(state: MutableState<T>): MutableState<T> {
142
- return state
143
- }
144
-
145
- protected processConnections(connections: Connection<T>[]): Connection<T>[] { // To preserve order, we split new connections into two sets
146
- return connections
147
- }
148
-
149
- public commit(): T['Memory'] {
150
- let state = this.precommit(this.memory.mutableState())
151
-
152
- let fromConnections = new Set<Elem<T>>()
153
-
154
- if (this._connections.length > 0) {
155
- // To preserve order, we split new connections into two sets
156
- // First are outgoing from known elements (in memory.elements)
157
- const [fromKnown, rest] = partition(
158
- this._connections,
159
- c => state.final.has(c.source),
160
- )
161
-
162
- state.connections = this.processConnections(
163
- mergeConnections([
164
- ...state.connections,
165
- ...fromKnown,
166
- ...rest,
167
- ]),
168
- )
169
-
170
- fromConnections = new Set(state.connections.flatMap(c => [c.source, c.target]))
171
- }
172
-
173
- state.elements = union(
174
- state.elements,
175
- this._ordered,
176
- this.explicits,
177
- fromConnections,
178
- this.implicits,
179
- )
180
-
181
- state.explicits = intersection(
182
- state.elements,
183
- union(
184
- state.explicits,
185
- this.explicits,
186
- ),
187
- )
188
-
189
- state.final = intersection(
190
- state.elements,
191
- union(
192
- state.final,
193
- this.explicits,
194
- fromConnections,
195
- ),
196
- )
197
-
198
- return this.memory.update(this.postcommit(state))
199
- }
200
- }
@@ -1,148 +0,0 @@
1
- import type { Connection } from '../../model/connection'
2
- import type { DeploymentElementModel } from '../../model/DeploymentElementModel'
3
- import type { ElementModel } from '../../model/ElementModel'
4
- import type { AnyAux } from '../../types'
5
-
6
- type Element<A extends AnyAux> = ElementModel<A> | DeploymentElementModel<A>
7
-
8
- export interface ComputeCtx<
9
- E extends Element<AnyAux>,
10
- C extends Connection<E, any>,
11
- M extends ComputeMemory<any>,
12
- Inc extends StageInclude<any>,
13
- Exc extends StageExclude<any>,
14
- Expr = unknown,
15
- > {
16
- Element: E
17
- Connection: C
18
- Memory: M
19
- StageInclude: Inc
20
- StageExclude: Exc
21
- Expr: Expr
22
- MutableState: State<this>
23
- }
24
-
25
- // export type AnyCtx = ComputeCtx<any, any, ComputeMemory<any>, StageInclude<any>, StageExclude<any>, any>
26
- export type AnyCtx = GenericCtx
27
-
28
- export type GenericCtx = ComputeCtx<
29
- any,
30
- Connection<any, any>,
31
- ComputeMemory<GenericCtx>,
32
- StageInclude<GenericCtx>,
33
- StageExclude<GenericCtx>,
34
- unknown
35
- >
36
-
37
- export interface State<T extends AnyCtx> {
38
- elements: Set<CtxElement<T>>
39
- explicits: Set<CtxElement<T>>
40
- final: Set<CtxElement<T>>
41
- connections: Array<CtxConnection<T>>
42
- }
43
-
44
- export type MutableState<T extends AnyCtx> = T['MutableState']
45
-
46
- export type StageExpression<T extends AnyCtx> = T['Expr']
47
-
48
- export type CtxElement<T extends AnyCtx> = T['Element']
49
- export type CtxConnection<T extends AnyCtx> = T['Connection']
50
- export type CtxMemory<T extends AnyCtx> = T['Memory']
51
-
52
- export interface ComputeMemory<T extends AnyCtx> {
53
- /**
54
- * All resolved elements, includes:
55
- * - explicit elements (included by element predicates, always appear in the view unless excluded)
56
- * - elements from resolved connections (may be excluded, if connection is redundant @see excludeRedundantRelationships
57
- * - implicit elements (not added directly, not included in the view, used for resolving connections)
58
- */
59
- readonly elements: ReadonlySet<CtxElement<T>>
60
-
61
- /**
62
- * Explicit elements
63
- */
64
- readonly explicits: ReadonlySet<CtxElement<T>>
65
-
66
- /**
67
- * Final set of elements to be included in the view
68
- * (`elements` excluding implicits)
69
- * Keeps order in which elements were added
70
- */
71
- readonly final: ReadonlySet<CtxElement<T>>
72
-
73
- /**
74
- * Resolved connections
75
- */
76
- readonly connections: ReadonlyArray<CtxConnection<T>>
77
-
78
- isEmpty(): boolean
79
-
80
- stageInclude(expression: T['Expr']): T['StageInclude']
81
-
82
- stageExclude(expression: T['Expr']): T['StageExclude']
83
-
84
- /**
85
- * Returns shallow copy of state
86
- */
87
- mutableState(): T['MutableState']
88
-
89
- /**
90
- * Returns new memory with updated state
91
- */
92
- update(newstate: Partial<T['MutableState']>): T['Memory']
93
- }
94
-
95
- interface Stage<T extends AnyCtx> {
96
- readonly memory: CtxMemory<T>
97
-
98
- readonly expression: StageExpression<T>
99
-
100
- /**
101
- * Has changes
102
- */
103
- isDirty(): boolean
104
-
105
- /**
106
- * Has no changes
107
- */
108
- isEmpty(): boolean
109
-
110
- commit(): T['Memory']
111
- }
112
-
113
- export interface StageInclude<T extends AnyCtx> extends Stage<T> {
114
- readonly elements: ReadonlySet<CtxElement<T>>
115
-
116
- readonly connections: ReadonlyArray<CtxConnection<T>>
117
-
118
- addExplicit(element: CtxElement<T> | Iterable<CtxElement<T>> | false | undefined | null): this
119
-
120
- addImplicit(element: CtxElement<T> | Iterable<CtxElement<T>> | false | undefined | null): this
121
-
122
- /**
123
- * Connects element with existing ones in the memory
124
- *
125
- * @param direction - direction of the connection
126
- * @default 'both'
127
- */
128
- connectWithExisting(
129
- element: CtxElement<T> | Iterable<CtxElement<T>>,
130
- direction?: 'in' | 'out' | 'both',
131
- ): boolean
132
-
133
- addConnections(connection: CtxConnection<T> | Iterable<CtxConnection<T>>): this
134
- }
135
-
136
- export interface StageExclude<T extends AnyCtx> extends Stage<T> {
137
- /**
138
- * Excludes from the memory relationships from given connections (still connection may be included, but without given relationships)
139
- * @param moveExplicitToImplicit - if true, disconnected explicit elements will be moved to implicit
140
- * @default false
141
- */
142
- excludeConnections(
143
- connection: CtxConnection<T> | Iterable<CtxConnection<T>>,
144
- moveExplicitToImplicit?: boolean,
145
- ): this
146
-
147
- exclude(element: CtxElement<T> | Iterable<CtxElement<T>> | false | undefined | null): this
148
- }
@@ -1,5 +0,0 @@
1
- export type * from './_types'
2
- export { AbstractMemory } from './AbstractMemory'
3
- export { AbstractStageExclude } from './AbstractStageExclude'
4
- export { AbstractStageInclude } from './AbstractStageInclude'
5
- export { treeFromMemoryState } from './ops'