@likec4/core 1.17.1 → 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 (184) 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 +22 -0
  6. package/dist/compute-view/index.d.ts +22 -0
  7. package/dist/compute-view/index.js +78 -0
  8. package/dist/index.d.mts +10 -919
  9. package/dist/index.d.ts +10 -919
  10. package/dist/{index.mjs → index.js} +7 -1688
  11. package/dist/model/index.d.mts +254 -0
  12. package/dist/model/index.d.ts +254 -0
  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.CoLQkcYL.d.cts → core.C05RDLhi.d.ts} +460 -362
  18. package/dist/shared/{core.CoLQkcYL.d.mts → core.CmYMqgha.d.mts} +460 -362
  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/{core.BXTs-8n7.mjs → view.CyZrG8BJ.js} +108 -47
  26. package/dist/types/index.d.mts +71 -1
  27. package/dist/types/index.d.ts +71 -1
  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 +59 -47
  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 +224 -0
  36. package/src/builder/Builder.deploymentModel.ts +385 -0
  37. package/src/builder/Builder.element.ts +19 -19
  38. package/src/builder/Builder.model.ts +67 -42
  39. package/src/builder/Builder.ts +533 -367
  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 +113 -18
  49. package/src/builder/index.ts +10 -4
  50. package/src/colors/index.ts +2 -2
  51. package/src/compute-view/compute-view.ts +83 -0
  52. package/src/compute-view/deployment-view/__test__/TestHelper.ts +236 -0
  53. package/src/compute-view/deployment-view/__test__/fixture.ts +198 -0
  54. package/src/compute-view/deployment-view/_types.ts +37 -0
  55. package/src/compute-view/deployment-view/clean-connections.ts +238 -0
  56. package/src/compute-view/deployment-view/compute.ts +125 -0
  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 +237 -0
  61. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +61 -0
  62. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +95 -0
  63. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +88 -0
  64. package/src/compute-view/deployment-view/predicates/wildcard.ts +29 -0
  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 +276 -0
  69. package/src/compute-view/dynamic-view/__test__/fixture.ts +58 -0
  70. package/src/compute-view/dynamic-view/compute.ts +324 -0
  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 +458 -0
  73. package/src/compute-view/element-view/__test__/fixture.ts +675 -0
  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 +315 -0
  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 +4 -0
  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/__snapshots__/sortNodes.spec.ts.snap +113 -0
  101. package/src/compute-view/utils/ancestorsOfNode.ts +19 -0
  102. package/src/compute-view/utils/applyCustomElementProperties.ts +66 -0
  103. package/src/compute-view/utils/applyCustomRelationProperties.ts +41 -0
  104. package/src/compute-view/utils/applyViewRuleStyles.ts +53 -0
  105. package/src/compute-view/utils/buildComputedNodes.ts +148 -0
  106. package/src/compute-view/utils/buildElementNotations.ts +63 -0
  107. package/src/compute-view/utils/elementExpressionToPredicate.ts +50 -0
  108. package/src/compute-view/utils/link-nodes-with-edges.ts +54 -0
  109. package/src/compute-view/utils/merge-props-from-relationships.ts +128 -0
  110. package/src/compute-view/utils/relationExpressionToPredicates.ts +55 -0
  111. package/src/compute-view/utils/resolve-extended-views.ts +69 -0
  112. package/src/compute-view/utils/resolve-global-rules.ts +83 -0
  113. package/src/compute-view/utils/topological-sort.ts +256 -0
  114. package/src/compute-view/utils/uniqueTags.test.ts +42 -0
  115. package/src/compute-view/utils/uniqueTags.ts +21 -0
  116. package/src/compute-view/utils/view-hash.ts +27 -0
  117. package/src/compute-view/utils/with-readable-edges.ts +36 -0
  118. package/src/index.ts +22 -12
  119. package/src/model/DeploymentElementModel.ts +599 -0
  120. package/src/model/DeploymentModel.ts +370 -0
  121. package/src/model/ElementModel.ts +221 -0
  122. package/src/model/LikeC4Model.test-d.ts +152 -0
  123. package/src/model/LikeC4Model.ts +336 -457
  124. package/src/model/RelationModel.ts +85 -0
  125. package/src/model/__test__/fixture.ts +149 -338
  126. package/src/model/connection/Connection.ts +72 -0
  127. package/src/model/connection/deployment/DeploymentConnectionModel.ts +178 -0
  128. package/src/model/connection/deployment/find.ts +120 -0
  129. package/src/model/connection/deployment/index.ts +8 -0
  130. package/src/model/connection/index.ts +22 -0
  131. package/src/model/connection/model/ConnectionModel.ts +157 -0
  132. package/src/model/connection/model/find.ts +117 -0
  133. package/src/model/connection/model/index.ts +8 -0
  134. package/src/model/connection/ops.ts +274 -0
  135. package/src/model/guards.ts +9 -0
  136. package/src/model/index.ts +46 -2
  137. package/src/model/types.ts +112 -15
  138. package/src/model/view/EdgeModel.ts +103 -0
  139. package/src/model/view/LikeC4ViewModel.ts +226 -0
  140. package/src/model/view/NodeModel.ts +229 -0
  141. package/src/types/_common.ts +55 -1
  142. package/src/types/deployments.ts +169 -0
  143. package/src/types/element.ts +9 -5
  144. package/src/types/expression-v2.ts +172 -0
  145. package/src/types/expression.ts +17 -11
  146. package/src/types/global.ts +3 -3
  147. package/src/types/index.ts +220 -12
  148. package/src/types/model.ts +75 -12
  149. package/src/types/operators.ts +1 -1
  150. package/src/types/overview-graph.ts +2 -2
  151. package/src/types/relation.ts +18 -14
  152. package/src/types/theme.ts +0 -1
  153. package/src/types/view-notation.ts +2 -2
  154. package/src/types/view.ts +117 -41
  155. package/src/utils/{commonHead.ts → common-head.ts} +2 -0
  156. package/src/utils/const.ts +1 -0
  157. package/src/utils/fqn.ts +203 -56
  158. package/src/utils/getOrCreate.ts +42 -0
  159. package/src/utils/graphlib.ts +10 -0
  160. package/src/utils/index.ts +74 -6
  161. package/src/utils/iterable/_types.ts +5 -0
  162. package/src/utils/iterable/filter.ts +55 -0
  163. package/src/utils/iterable/flat.ts +17 -0
  164. package/src/utils/iterable/index.ts +12 -0
  165. package/src/utils/iterable/map.ts +40 -0
  166. package/src/utils/iterable/reduce.ts +24 -0
  167. package/src/utils/iterable/some.ts +36 -0
  168. package/src/utils/iterable/to.ts +19 -0
  169. package/src/utils/iterable/unique.ts +29 -0
  170. package/src/utils/object-hash.ts +3 -0
  171. package/src/utils/relations.ts +3 -64
  172. package/src/utils/set.ts +78 -0
  173. package/src/utils/string-hash.ts +16 -0
  174. package/dist/index.cjs +0 -5452
  175. package/dist/index.d.cts +0 -1053
  176. package/dist/shared/core.CoLQkcYL.d.ts +0 -734
  177. package/dist/shared/core.DIYZvpVg.cjs +0 -353
  178. package/dist/types/index.cjs +0 -70
  179. package/dist/types/index.d.cts +0 -2
  180. package/dist/types/index.mjs +0 -1
  181. package/src/builder/Builder.test-d.ts +0 -69
  182. package/src/builder/Builder.view.ts +0 -358
  183. package/src/model/LikeC4DiagramModel.ts +0 -338
  184. package/src/model/LikeC4ViewModel.ts +0 -320
@@ -0,0 +1,29 @@
1
+ import type { IteratorLike } from '../../types'
2
+
3
+ /**
4
+ * Returns an iterable that yields only unique values.
5
+ * It uses a Set to keep track of the values.
6
+ */
7
+ export function iunique(): <T>(iterable: Iterable<T>) => IteratorLike<T>
8
+ export function iunique<T>(iterable: Iterable<T>): IteratorLike<T>
9
+
10
+ export function iunique<T>(iterable?: Iterable<T>): IteratorLike<T> | ((iterable: Iterable<T>) => IteratorLike<T>) {
11
+ if (iterable) {
12
+ return (function*(): IteratorLike<T> {
13
+ yield* _iunique(iterable)
14
+ return
15
+ })()
16
+ }
17
+ return _iunique
18
+ }
19
+
20
+ function* _iunique<T>(iterable: Iterable<T>): IteratorLike<T> {
21
+ const seen = new Set<T>()
22
+ for (const item of iterable) {
23
+ if (!seen.has(item)) {
24
+ seen.add(item)
25
+ yield item
26
+ }
27
+ }
28
+ return
29
+ }
@@ -0,0 +1,3 @@
1
+ import objectHash from 'object-hash'
2
+
3
+ export { objectHash }
@@ -1,18 +1,18 @@
1
1
  import type { Fqn } from '../types'
2
2
  import { commonAncestor, compareFqnHierarchically, isAncestor } from './fqn'
3
3
 
4
- type Relation = {
4
+ export type Relation = {
5
5
  source: string
6
6
  target: string
7
7
  }
8
8
 
9
- type RelationPredicate = (rel: Relation) => boolean
9
+ export type RelationPredicate = (rel: Relation) => boolean
10
10
 
11
11
  /**
12
12
  * Compares two relations hierarchically.
13
13
  * From the most general (implicit) to the most specific.
14
14
  */
15
- export const compareRelations = <T extends { source: string; target: string }>(a: T, b: T) => {
15
+ export const compareRelations = <T extends { source: string; target: string }>(a: T, b: T): number => {
16
16
  const parentA = commonAncestor(a.source as Fqn, a.target as Fqn)
17
17
  const parentB = commonAncestor(b.source as Fqn, b.target as Fqn)
18
18
  if (parentA && !parentB) {
@@ -31,64 +31,3 @@ export const compareRelations = <T extends { source: string; target: string }>(a
31
31
  }
32
32
  return compareFqnHierarchically(a.target, b.target)
33
33
  }
34
-
35
- export const isInside = (parent: Fqn): RelationPredicate => {
36
- const prefix = parent + '.'
37
- return (rel: Relation) => {
38
- return rel.source.startsWith(prefix) && rel.target.startsWith(prefix)
39
- }
40
- }
41
-
42
- export const isBetween = (source: Fqn, target: Fqn): RelationPredicate => {
43
- const sourcePrefix = source + '.'
44
- const targetPrefix = target + '.'
45
- return (rel: Relation) => {
46
- return (
47
- (rel.source === source || (rel.source + '.').startsWith(sourcePrefix))
48
- && (rel.target === target || (rel.target + '.').startsWith(targetPrefix))
49
- )
50
- }
51
- }
52
-
53
- export const isAnyBetween = (source: Fqn, target: Fqn): RelationPredicate => {
54
- const predicates = [isBetween(source, target), isBetween(target, source)]
55
- return (rel) => predicates.some(p => p(rel))
56
- }
57
-
58
- export const isIncoming = (target: Fqn): RelationPredicate => {
59
- const targetPrefix = target + '.'
60
- return (rel: Relation) => {
61
- return (
62
- !(rel.source + '.').startsWith(targetPrefix)
63
- && (rel.target === target || (rel.target + '.').startsWith(targetPrefix))
64
- )
65
- }
66
- }
67
-
68
- export const isOutgoing = (source: Fqn): RelationPredicate => {
69
- const sourcePrefix = source + '.'
70
- return (rel: Relation) => {
71
- return (
72
- (rel.source === source || (rel.source + '.').startsWith(sourcePrefix))
73
- && !(rel.target + '.').startsWith(sourcePrefix)
74
- )
75
- }
76
- }
77
-
78
- export const isAnyInOut = (source: Fqn): RelationPredicate => {
79
- const predicates = [isIncoming(source), isOutgoing(source)]
80
- return (rel: Relation) => {
81
- return predicates.some(p => p(rel))
82
- }
83
- }
84
-
85
- export const hasRelation = <R extends { source: Fqn; target: Fqn }>(rel: R) => {
86
- return <E extends { id: Fqn }>(element: E) => {
87
- return (
88
- rel.source === element.id
89
- || rel.target === element.id
90
- || isAncestor(element.id, rel.source)
91
- || isAncestor(element.id, rel.target)
92
- )
93
- }
94
- }
@@ -0,0 +1,78 @@
1
+ import { intersection as _intersection, symmetricDifference as _symmetricDifference } from 'mnemonist/set'
2
+ import type { NonEmptyArray } from '../types/_common'
3
+
4
+ /**
5
+ * Returns new set as a union of given sets
6
+ * Keeps order of elements
7
+ */
8
+ export function union<T>(...sets: ReadonlySet<T>[]): Set<T> {
9
+ let result = new Set<T>()
10
+ for (const set of sets) {
11
+ for (const value of set) {
12
+ result.add(value)
13
+ }
14
+ }
15
+ return result
16
+ }
17
+
18
+ /**
19
+ * Returns new set as an intersection of all sets
20
+ * Keeps order from the first set
21
+ */
22
+ export function intersection<T>(first: ReadonlySet<T>, ...sets: NonEmptyArray<ReadonlySet<NoInfer<T>>>): Set<T> {
23
+ let result = new Set<T>()
24
+ // If first set is empty, return empty set
25
+ if (first.size === 0) {
26
+ return result
27
+ }
28
+ let other = sets.length > 1 ? _intersection(...sets as any) : sets[0]
29
+ if (other.size === 0) {
30
+ return result
31
+ }
32
+ for (const value of first) {
33
+ if (other.has(value)) {
34
+ result.add(value)
35
+ }
36
+ }
37
+ return result
38
+ }
39
+
40
+ export function difference<T>(a: ReadonlySet<T>, b: ReadonlySet<NoInfer<T>>): Set<T> {
41
+ if (a.size === 0) {
42
+ return new Set<T>()
43
+ }
44
+ if (b.size === 0) {
45
+ return new Set(a)
46
+ }
47
+ let result = new Set<T>()
48
+ for (const value of a) {
49
+ if (!b.has(value)) {
50
+ result.add(value)
51
+ }
52
+ }
53
+ return result
54
+ }
55
+
56
+ export function equals<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean {
57
+ return a.size === b.size && [...a].every(value => b.has(value))
58
+ }
59
+
60
+ export function symmetricDifference<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): Set<T> {
61
+ return _symmetricDifference(a as Set<T>, b as Set<T>)
62
+ }
63
+
64
+ export function hasIntersection<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean {
65
+ if (a.size === 0 || b.size === 0) {
66
+ return false
67
+ }
68
+ // Swap sets to iterate over smaller set
69
+ if (b.size < a.size) {
70
+ ;[a, b] = [b, a]
71
+ }
72
+ for (const value of a) {
73
+ if (b.has(value)) {
74
+ return true
75
+ }
76
+ }
77
+ return false
78
+ }
@@ -0,0 +1,16 @@
1
+ import { invariant } from '../errors'
2
+
3
+ /**
4
+ * @see https://gist.github.com/victor-homyakov/bcb7d7911e4a388b1c810f8c3ce17bcf
5
+ */
6
+ export function stringHash(str: string): string {
7
+ let hash = 5381
8
+ const len = str.length
9
+ invariant(len > 0, 'stringHash: empty string')
10
+
11
+ for (let i = 0; i < len; i++) {
12
+ hash = (hash * 33) ^ str.charCodeAt(i)
13
+ }
14
+
15
+ return (hash >>> 0).toString(36)
16
+ }