@likec4/core 1.18.0 → 1.19.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 (176) hide show
  1. package/LICENSE +1 -1
  2. package/dist/builder/index.d.mts +502 -0
  3. package/dist/builder/index.d.ts +502 -0
  4. package/dist/builder/index.js +871 -0
  5. package/dist/compute-view/index.d.mts +9 -78
  6. package/dist/compute-view/index.d.ts +9 -78
  7. package/dist/compute-view/index.js +78 -0
  8. package/dist/index.d.mts +9 -730
  9. package/dist/index.d.ts +9 -730
  10. package/dist/{index.mjs → index.js} +7 -784
  11. package/dist/model/index.d.mts +218 -606
  12. package/dist/model/index.d.ts +218 -606
  13. package/dist/model/index.js +1 -0
  14. package/dist/shared/chunk-RAAYCPUM.M-JWF7SS.js +21 -0
  15. package/dist/shared/core.BIfgabEw.d.ts +719 -0
  16. package/dist/shared/core.BZ9Msq7w.d.mts +719 -0
  17. package/dist/shared/{core.DMYY7C8s.d.mts → core.C05RDLhi.d.ts} +179 -230
  18. package/dist/shared/{core.DMYY7C8s.d.ts → core.CmYMqgha.d.mts} +179 -230
  19. package/dist/shared/core.D6-fWbM3.d.ts +127 -0
  20. package/dist/shared/core.D74xkKkG.d.mts +148 -0
  21. package/dist/shared/core.D74xkKkG.d.ts +148 -0
  22. package/dist/shared/core.sLaWHBjR.d.mts +127 -0
  23. package/dist/shared/index.-BdzdI2C.js +7443 -0
  24. package/dist/shared/object_hash.CE_oF3I3.js +1222 -0
  25. package/dist/shared/view.CyZrG8BJ.js +354 -0
  26. package/dist/types/index.d.mts +4 -2
  27. package/dist/types/index.d.ts +4 -2
  28. package/dist/types/index.js +20 -0
  29. package/dist/utils/index.d.mts +404 -0
  30. package/dist/utils/index.d.ts +404 -0
  31. package/dist/utils/index.js +330 -0
  32. package/package.json +47 -33
  33. package/src/builder/Builder-style1.test-d.ts +190 -0
  34. package/src/builder/Builder-style2.test-d.ts +175 -0
  35. package/src/builder/Builder.deployment.ts +25 -20
  36. package/src/builder/Builder.deploymentModel.ts +80 -55
  37. package/src/builder/Builder.element.ts +2 -0
  38. package/src/builder/Builder.model.ts +57 -43
  39. package/src/builder/Builder.ts +412 -431
  40. package/src/builder/Builder.view-common.ts +234 -0
  41. package/src/builder/Builder.view-deployment.ts +135 -0
  42. package/src/builder/Builder.view-element.ts +189 -0
  43. package/src/builder/Builder.views.ts +109 -33
  44. package/src/builder/Builder.with.ts +475 -0
  45. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +374 -0
  46. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +183 -0
  47. package/src/builder/__snapshots__/Builder.spec.ts.snap +374 -0
  48. package/src/builder/_types.ts +28 -5
  49. package/src/builder/index.ts +10 -4
  50. package/src/colors/index.ts +2 -2
  51. package/src/compute-view/compute-view.ts +45 -54
  52. package/src/compute-view/deployment-view/__test__/TestHelper.ts +236 -0
  53. package/src/compute-view/deployment-view/__test__/fixture.ts +50 -62
  54. package/src/compute-view/deployment-view/_types.ts +26 -18
  55. package/src/compute-view/deployment-view/clean-connections.ts +173 -164
  56. package/src/compute-view/deployment-view/compute.ts +51 -37
  57. package/src/compute-view/deployment-view/memory/index.ts +9 -0
  58. package/src/compute-view/deployment-view/memory/memory.ts +97 -0
  59. package/src/compute-view/deployment-view/predicates/elements.ts +144 -0
  60. package/src/compute-view/deployment-view/predicates/relation-direct.ts +183 -76
  61. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +38 -20
  62. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +72 -23
  63. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +61 -22
  64. package/src/compute-view/deployment-view/predicates/wildcard.ts +15 -15
  65. package/src/compute-view/deployment-view/stages/stage-exclude.ts +5 -0
  66. package/src/compute-view/deployment-view/stages/stage-final.ts +245 -0
  67. package/src/compute-view/deployment-view/stages/stage-include.ts +95 -0
  68. package/src/compute-view/deployment-view/utils.ts +95 -31
  69. package/src/compute-view/dynamic-view/__test__/fixture.ts +4 -4
  70. package/src/compute-view/dynamic-view/compute.ts +59 -45
  71. package/src/compute-view/element-view/__test__/TestHelper.ts +258 -0
  72. package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +64 -62
  73. package/src/compute-view/element-view/__test__/fixture.ts +147 -117
  74. package/src/compute-view/element-view/_types.ts +48 -0
  75. package/src/compute-view/element-view/clean-connections.ts +113 -0
  76. package/src/compute-view/element-view/compute.ts +264 -683
  77. package/src/compute-view/element-view/memory/NodeGroup.ts +31 -0
  78. package/src/compute-view/element-view/memory/index.ts +10 -0
  79. package/src/compute-view/element-view/memory/memory.ts +177 -0
  80. package/src/compute-view/element-view/memory/stage-exclude.ts +59 -0
  81. package/src/compute-view/element-view/memory/stage-final.ts +129 -0
  82. package/src/compute-view/element-view/memory/stage-include.ts +128 -0
  83. package/src/compute-view/element-view/predicates/_utils.ts +86 -0
  84. package/src/compute-view/element-view/predicates/element-expand.ts +33 -0
  85. package/src/compute-view/element-view/predicates/element-kind-tag.ts +26 -0
  86. package/src/compute-view/element-view/predicates/element-ref.ts +37 -0
  87. package/src/compute-view/element-view/predicates/relation-direct.ts +309 -0
  88. package/src/compute-view/element-view/predicates/relation-in-out.ts +66 -0
  89. package/src/compute-view/element-view/predicates/relation-in.ts +118 -0
  90. package/src/compute-view/element-view/predicates/relation-out.ts +116 -0
  91. package/src/compute-view/element-view/predicates/wildcard.ts +88 -0
  92. package/src/compute-view/element-view/utils.ts +59 -0
  93. package/src/compute-view/index.ts +3 -4
  94. package/src/compute-view/memory/AbstractMemory.ts +45 -0
  95. package/src/compute-view/memory/AbstractStageExclude.ts +216 -0
  96. package/src/compute-view/memory/AbstractStageInclude.ts +200 -0
  97. package/src/compute-view/memory/_types.ts +147 -0
  98. package/src/compute-view/memory/index.ts +5 -0
  99. package/src/compute-view/memory/ops.ts +43 -0
  100. package/src/compute-view/utils/buildComputedNodes.ts +4 -4
  101. package/src/compute-view/utils/elementExpressionToPredicate.ts +1 -3
  102. package/src/compute-view/utils/link-nodes-with-edges.ts +3 -7
  103. package/src/compute-view/utils/{derive-edge-props-from-relationships.ts → merge-props-from-relationships.ts} +54 -23
  104. package/src/compute-view/utils/relationExpressionToPredicates.ts +2 -2
  105. package/src/compute-view/utils/resolve-extended-views.ts +44 -40
  106. package/src/compute-view/utils/resolve-global-rules.ts +6 -6
  107. package/src/compute-view/utils/topological-sort.ts +167 -71
  108. package/src/compute-view/utils/with-readable-edges.ts +14 -9
  109. package/src/index.ts +22 -16
  110. package/src/model/DeploymentElementModel.ts +150 -85
  111. package/src/model/DeploymentModel.ts +27 -21
  112. package/src/model/ElementModel.ts +51 -25
  113. package/src/model/LikeC4Model.test-d.ts +4 -3
  114. package/src/model/LikeC4Model.ts +98 -42
  115. package/src/model/RelationModel.ts +5 -4
  116. package/src/model/__test__/fixture.ts +5 -9
  117. package/src/model/connection/Connection.ts +72 -0
  118. package/src/model/connection/deployment/DeploymentConnectionModel.ts +178 -0
  119. package/src/model/connection/{deployment.ts → deployment/find.ts} +14 -18
  120. package/src/model/connection/deployment/index.ts +8 -0
  121. package/src/model/connection/index.ts +22 -0
  122. package/src/model/connection/model/ConnectionModel.ts +157 -0
  123. package/src/model/connection/{model.ts → model/find.ts} +43 -49
  124. package/src/model/connection/model/index.ts +8 -0
  125. package/src/model/connection/ops.ts +274 -0
  126. package/src/model/guards.ts +9 -0
  127. package/src/model/index.ts +45 -3
  128. package/src/model/types.ts +35 -18
  129. package/src/model/view/EdgeModel.ts +6 -6
  130. package/src/model/view/LikeC4ViewModel.ts +14 -8
  131. package/src/model/view/NodeModel.ts +6 -5
  132. package/src/types/_common.ts +53 -1
  133. package/src/types/deployments.ts +88 -156
  134. package/src/types/element.ts +2 -2
  135. package/src/types/expression-v2.ts +172 -0
  136. package/src/types/expression.ts +9 -5
  137. package/src/types/global.ts +3 -3
  138. package/src/types/index.ts +220 -13
  139. package/src/types/model.ts +28 -24
  140. package/src/types/operators.ts +1 -1
  141. package/src/types/relation.ts +14 -10
  142. package/src/types/theme.ts +0 -1
  143. package/src/types/view.ts +20 -18
  144. package/src/utils/const.ts +1 -0
  145. package/src/utils/fqn.ts +140 -49
  146. package/src/utils/getOrCreate.ts +1 -1
  147. package/src/utils/index.ts +74 -9
  148. package/src/utils/iterable/_types.ts +5 -0
  149. package/src/utils/iterable/filter.ts +55 -0
  150. package/src/utils/iterable/flat.ts +17 -0
  151. package/src/utils/iterable/index.ts +12 -0
  152. package/src/utils/iterable/map.ts +40 -0
  153. package/src/utils/iterable/reduce.ts +24 -0
  154. package/src/utils/iterable/some.ts +36 -0
  155. package/src/utils/iterable/to.ts +19 -0
  156. package/src/utils/iterable/unique.ts +29 -0
  157. package/src/utils/relations.ts +3 -64
  158. package/src/utils/set.ts +11 -9
  159. package/src/utils/string-hash.ts +1 -1
  160. package/dist/compute-view/index.mjs +0 -79
  161. package/dist/model/index.mjs +0 -2
  162. package/dist/shared/core.BBgiAAv1.mjs +0 -144
  163. package/dist/shared/core.BPyJvuMU.mjs +0 -2420
  164. package/dist/shared/core.BQ4AbfvB.mjs +0 -9228
  165. package/dist/shared/core.k12s_keD.mjs +0 -203
  166. package/dist/types/index.mjs +0 -21
  167. package/src/builder/Builder.test-d.ts +0 -124
  168. package/src/builder/Builder.view.ts +0 -543
  169. package/src/compute-view/LikeC4ModelGraph.ts +0 -330
  170. package/src/compute-view/deployment-view/Memory.ts +0 -108
  171. package/src/compute-view/deployment-view/Stage.ts +0 -145
  172. package/src/compute-view/deployment-view/predicates/deployment-ref.ts +0 -146
  173. package/src/compute-view/element-view/predicates.ts +0 -517
  174. package/src/compute-view/utils/sortNodes.ts +0 -101
  175. package/src/model/connection/ConnectionModel.ts +0 -94
  176. package/src/model/connection/DeploymentConnectionModel.ts +0 -99
@@ -1,101 +0,0 @@
1
- import { difference, filter, map, pipe, sort, tap } from 'remeda'
2
- import { invariant, nonNullable } from '../../errors'
3
- import type { Fqn } from '../../types/element'
4
- import type { ComputedEdge, ComputedNode, EdgeId } from '../../types/view'
5
- import { compareByFqnHierarchically } from '../../utils/fqn'
6
- import { Graph, postorder } from '../../utils/graphlib'
7
- import { compareRelations } from '../../utils/relations'
8
-
9
- // side effect
10
- function sortChildren(nodes: readonly ComputedNode[]) {
11
- nodes.forEach(parent => {
12
- if (parent.children.length > 0) {
13
- parent.children = nodes.flatMap(n => (n.parent === parent.id ? n.id : []))
14
- }
15
- })
16
- }
17
-
18
- export function sortNodes({
19
- nodes,
20
- edges
21
- }: {
22
- nodes: ComputedNode[]
23
- edges: ComputedEdge[]
24
- }): ComputedNode[] {
25
- if (nodes.length < 2) {
26
- return nodes
27
- }
28
- if (edges.length === 0) {
29
- return pipe(
30
- nodes,
31
- sort(compareByFqnHierarchically),
32
- tap(sortChildren)
33
- )
34
- }
35
-
36
- const g = new Graph({
37
- compound: false,
38
- directed: true,
39
- multigraph: false
40
- })
41
-
42
- const getNode = (id: Fqn) =>
43
- nonNullable(
44
- nodes.find(n => n.id === id),
45
- 'Edge not found'
46
- )
47
- const getEdge = (id: EdgeId) =>
48
- nonNullable(
49
- edges.find(edge => edge.id === id),
50
- 'Edge not found'
51
- )
52
-
53
- for (const e of [...edges].sort(compareRelations)) {
54
- g.setEdge(e.source, e.target)
55
- }
56
-
57
- for (const n of nodes) {
58
- g.setNode(n.id, n.id)
59
- if (n.children.length > 0) {
60
- n.inEdges.forEach(e => {
61
- const edge = getEdge(e)
62
- // if this edge from leaf to the child of this node
63
- if (edge.target !== n.id && getNode(edge.source).children.length === 0) {
64
- // const id = `${edge.source}:${n.id}`
65
- g.setEdge(edge.source, n.id)
66
- }
67
- })
68
- // n.outEdges.forEach(e => {
69
- // const edge = getEdge(e)
70
- // if (edge.source !== n.id) {
71
- // const id = `${n.id}:${edge.target}`
72
- // g.setEdge(n.id, edge.target, undefined, id)
73
- // }
74
- // })
75
- }
76
- if (n.parent) {
77
- g.setEdge(n.parent, n.id)
78
- }
79
- }
80
-
81
- let sources = g.sources() as unknown as Fqn[]
82
- if (sources.length === 0) {
83
- sources = pipe(
84
- nodes,
85
- filter(n => n.inEdges.length === 0 || n.parent === null),
86
- sort(compareByFqnHierarchically),
87
- map(n => n.id)
88
- )
89
- }
90
- // sources = sources.sort(compareFqnHierarchically)
91
- const orderedIds = postorder(g, sources).reverse() as Fqn[]
92
- const sorted = orderedIds.map(getNode)
93
- if (sorted.length < nodes.length) {
94
- const unsorted = difference(nodes, sorted).sort(compareByFqnHierarchically)
95
- sorted.push(...unsorted)
96
- }
97
-
98
- invariant(sorted.length === nodes.length, 'Not all nodes were processed by graphlib')
99
- sortChildren(sorted)
100
- return sorted
101
- }
@@ -1,94 +0,0 @@
1
- import { invariant } from '../../errors'
2
- import { difference, equals, union } from '../../utils/set'
3
- import { stringHash } from '../../utils/string-hash'
4
- import type { ElementModel } from '../ElementModel'
5
- import type { RelationshipModel } from '../RelationModel'
6
- import type { AnyAux } from '../types'
7
-
8
- export interface Connection<Elem = any, Id = any> {
9
- readonly id: Id
10
- readonly source: Elem
11
- readonly target: Elem
12
-
13
- /**
14
- * Common ancestor of the source and target elements.
15
- * Represents the boundary of the connection.
16
- */
17
- readonly boundary: Elem | null
18
-
19
- /**
20
- * Human readable expression of the connection
21
- * Mostly used for testing and debugging
22
- */
23
- readonly expression: string
24
-
25
- mergeWith(this: Connection<any, any>, other: typeof this): typeof this
26
-
27
- nonEmpty(): boolean
28
-
29
- difference(this: Connection<Elem, Id>, other: Connection<Elem, Id>): typeof this
30
- }
31
-
32
- /**
33
- * Connection refers to any relationships between two elements,
34
- * both direct and implicit ones (between their nested elements).
35
- *
36
- * Merges relationships together to an single edge on the diagram.
37
- */
38
- export class ConnectionModel<M extends AnyAux = AnyAux> implements Connection<ElementModel<M>, M['EdgeId']> {
39
- public readonly id: M['EdgeId']
40
-
41
- /**
42
- * Common ancestor of the source and target elements.
43
- * Represents the boundary of the connection.
44
- */
45
- public readonly boundary: ElementModel<M> | null
46
-
47
- constructor(
48
- public readonly source: ElementModel<M>,
49
- public readonly target: ElementModel<M>,
50
- public readonly relations: ReadonlySet<RelationshipModel<M>>
51
- ) {
52
- this.id = stringHash(`model:${source.id}:${target.id}`) as M['EdgeId']
53
- this.boundary = source.commonAncestor(target)
54
- }
55
-
56
- /**
57
- * Human readable expression of the connection
58
- * Mostly used for testing and debugging
59
- */
60
- get expression(): string {
61
- return `${this.source.id} -> ${this.target.id}`
62
- }
63
-
64
- nonEmpty(): boolean {
65
- return this.relations.size > 0
66
- }
67
-
68
- mergeWith(other: ConnectionModel<M>): ConnectionModel<M> {
69
- invariant(this.source.id === other.source.id, 'Cannot merge connections with different sources')
70
- invariant(this.target.id === other.target.id, 'Cannot merge connections with different targets')
71
- return new ConnectionModel(
72
- this.source,
73
- this.target,
74
- union(this.relations, other.relations)
75
- )
76
- }
77
-
78
- difference(other: ConnectionModel<M>): ConnectionModel<M> {
79
- invariant(this.source.id === other.source.id, 'Cannot difference connection with different sources')
80
- invariant(this.target.id === other.target.id, 'Cannot difference connection with different targets')
81
- return new ConnectionModel(
82
- this.source,
83
- this.target,
84
- difference(this.relations, other.relations)
85
- )
86
- }
87
-
88
- equals(other: ConnectionModel<M>): boolean {
89
- return this.id === other.id
90
- && this.source.id === other.source.id
91
- && this.target.id === other.target.id
92
- && equals(this.relations, other.relations)
93
- }
94
- }
@@ -1,99 +0,0 @@
1
- import { invariant } from '../../errors'
2
- import { stringHash } from '../../utils'
3
- import { equals } from '../../utils/set'
4
- import {
5
- type DeploymentElementModel,
6
- DeploymentNodeModel,
7
- type DeploymentRelationModel,
8
- RelationshipsAccum
9
- } from '../DeploymentElementModel'
10
- import type { RelationshipModel } from '../RelationModel'
11
- import type { AnyAux, IteratorLike } from '../types'
12
- import type { Connection } from './ConnectionModel'
13
-
14
- /**
15
- * Connection is ephemeral entity, result of a resolving relationships between source and target.
16
- * Includes direct relationships and/or between their nested elements.
17
- */
18
- export class DeploymentConnectionModel<M extends AnyAux = AnyAux>
19
- implements Connection<DeploymentElementModel<M>, M['EdgeId']>
20
- {
21
- /**
22
- * Common ancestor of the source and target elements.
23
- * Represents the boundary of the connection.
24
- */
25
- readonly boundary: DeploymentNodeModel<M> | null
26
-
27
- constructor(
28
- public readonly source: DeploymentElementModel<M>,
29
- public readonly target: DeploymentElementModel<M>,
30
- public readonly relations: RelationshipsAccum<M>
31
- ) {
32
- this.id = stringHash(`deployment:${source.id}:${target.id}`) as M['EdgeId']
33
- this.boundary = source.commonAncestor(target)
34
- }
35
-
36
- readonly id: M['EdgeId']
37
-
38
- /**
39
- * Human readable expression of the connection
40
- * Mostly used for testing and debugging
41
- */
42
- get expression(): string {
43
- return `${this.source.id} -> ${this.target.id}`
44
- }
45
-
46
- nonEmpty(): boolean {
47
- return this.relations.nonEmpty
48
- }
49
-
50
- /**
51
- * Check if connection contains deployment relation,
52
- * that is directly connected to source or target.
53
- */
54
- public hasDirectDeploymentRelation(): boolean {
55
- for (const relation of this.relations.deployment) {
56
- if (relation.source.id === this.source.id || relation.target.id === this.target.id) {
57
- return true
58
- }
59
- }
60
- return false
61
- }
62
-
63
- public *values(): IteratorLike<RelationshipModel<M> | DeploymentRelationModel<M>> {
64
- yield* this.relations.model
65
- yield* this.relations.deployment
66
- }
67
-
68
- /**
69
- * Merge with another connection, if it has the same source and target.
70
- * Returns new connection with union of relationships.
71
- */
72
- public mergeWith(other: DeploymentConnectionModel<M>): DeploymentConnectionModel<M> {
73
- invariant(this.source.id === other.source.id, 'Cannot merge connections with different sources')
74
- invariant(this.target.id === other.target.id, 'Cannot merge connections with different targets')
75
- return new DeploymentConnectionModel(
76
- this.source,
77
- this.target,
78
- this.relations.union(other.relations)
79
- )
80
- }
81
-
82
- public difference(other: DeploymentConnectionModel<M>): DeploymentConnectionModel<M> {
83
- invariant(this.source.id === other.source.id, 'Cannot difference connection with different sources')
84
- invariant(this.target.id === other.target.id, 'Cannot difference connection with different targets')
85
- return new DeploymentConnectionModel(
86
- this.source,
87
- this.target,
88
- this.relations.difference(other.relations)
89
- )
90
- }
91
-
92
- public equals(other: DeploymentConnectionModel<M>): boolean {
93
- return this.id === other.id
94
- && this.source.id === other.source.id
95
- && this.target.id === other.target.id
96
- && equals(this.relations.model, other.relations.model)
97
- && equals(this.relations.deployment, other.relations.deployment)
98
- }
99
- }