@likec4/core 1.30.0 → 1.32.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 (186) hide show
  1. package/README.md +407 -5
  2. package/dist/builder/index.d.mts +221 -42
  3. package/dist/builder/index.mjs +118 -65
  4. package/dist/compute-view/index.d.mts +23 -7
  5. package/dist/compute-view/index.mjs +11 -6
  6. package/dist/compute-view/relationships-view/index.d.mts +9 -7
  7. package/dist/compute-view/relationships-view/index.mjs +3 -2
  8. package/dist/index.d.mts +10 -14
  9. package/dist/index.mjs +10 -6
  10. package/dist/model/index.d.mts +173 -19
  11. package/dist/model/index.mjs +6 -1
  12. package/dist/shared/core.BaYE_r29.d.mts +258 -0
  13. package/dist/shared/core.Bk7wEZFG.mjs +276 -0
  14. package/dist/shared/core.BrCnZFTn.mjs +32 -0
  15. package/dist/shared/core.BuO4ncfY.d.mts +146 -0
  16. package/dist/shared/{core.CAcZ6_cP.mjs → core.CBpKAlhj.mjs} +1742 -4128
  17. package/dist/shared/core.CCWXGc6G.d.mts +920 -0
  18. package/dist/shared/core.CUYDgv2-.mjs +214 -0
  19. package/dist/shared/{core.Cu-UdkSl.mjs → core.CpXlRyE5.mjs} +7 -494
  20. package/dist/shared/{core.C-YXI-43.mjs → core.Cy9smucx.mjs} +3 -1
  21. package/dist/shared/core.CywrQs86.d.mts +31 -0
  22. package/dist/shared/core.DoK86JEe.mjs +518 -0
  23. package/dist/shared/core.Dpq3P3YJ.d.mts +1265 -0
  24. package/dist/shared/{core.D2830qgg.d.mts → core.Pf5I9o0e.d.mts} +1 -1
  25. package/dist/shared/core.cbA9VZ02.mjs +2681 -0
  26. package/dist/shared/{core.CQXU9DF7.mjs → core.rmvsy0n3.mjs} +23 -32
  27. package/dist/types/aux.d.mts +3 -0
  28. package/dist/types/aux.mjs +1 -0
  29. package/dist/types/index.d.mts +7 -45
  30. package/dist/types/index.mjs +130 -3
  31. package/dist/utils/index.d.mts +221 -53
  32. package/dist/utils/index.mjs +14 -10
  33. package/package.json +19 -10
  34. package/src/builder/Builder.deploymentModel.ts +82 -18
  35. package/src/builder/Builder.element.ts +40 -20
  36. package/src/builder/Builder.model.ts +66 -17
  37. package/src/builder/Builder.ts +168 -76
  38. package/src/builder/Builder.view-common.ts +35 -17
  39. package/src/builder/Builder.view-deployment.ts +25 -25
  40. package/src/builder/Builder.view-element.ts +13 -12
  41. package/src/builder/Builder.views.ts +12 -7
  42. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +62 -34
  43. package/src/builder/__snapshots__/Builder-style2.compute-model.json5 +319 -0
  44. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +45 -24
  45. package/src/builder/_types.ts +34 -27
  46. package/src/compute-view/compute-view.ts +31 -34
  47. package/src/compute-view/deployment-view/__test__/TestHelper.ts +27 -14
  48. package/src/compute-view/deployment-view/__test__/fixture.ts +15 -13
  49. package/src/compute-view/deployment-view/_types.ts +10 -10
  50. package/src/compute-view/deployment-view/clean-connections.ts +5 -7
  51. package/src/compute-view/deployment-view/compute.ts +16 -13
  52. package/src/compute-view/deployment-view/memory/memory.ts +5 -6
  53. package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +4 -5
  54. package/src/compute-view/deployment-view/predicates/relation-direct.ts +25 -50
  55. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +5 -7
  56. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +7 -11
  57. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +7 -10
  58. package/src/compute-view/deployment-view/predicates/utils.ts +37 -31
  59. package/src/compute-view/deployment-view/predicates/wildcard.ts +3 -2
  60. package/src/compute-view/deployment-view/stages/stage-final.ts +2 -2
  61. package/src/compute-view/deployment-view/stages/stage-include.ts +1 -1
  62. package/src/compute-view/deployment-view/utils.ts +79 -72
  63. package/src/compute-view/dynamic-view/__test__/fixture.ts +20 -11
  64. package/src/compute-view/dynamic-view/compute.ts +60 -53
  65. package/src/compute-view/element-view/__test__/TestHelper.ts +53 -29
  66. package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +26 -26
  67. package/src/compute-view/element-view/__test__/fixture.ts +134 -83
  68. package/src/compute-view/element-view/_types.ts +14 -19
  69. package/src/compute-view/element-view/clean-connections.ts +12 -8
  70. package/src/compute-view/element-view/compute.ts +61 -51
  71. package/src/compute-view/element-view/memory/NodeGroup.ts +8 -9
  72. package/src/compute-view/element-view/memory/memory.ts +22 -22
  73. package/src/compute-view/element-view/memory/stage-include.ts +5 -3
  74. package/src/compute-view/element-view/predicates/_utils.ts +18 -14
  75. package/src/compute-view/element-view/predicates/element-expand.ts +4 -5
  76. package/src/compute-view/element-view/predicates/element-kind-tag.ts +3 -4
  77. package/src/compute-view/element-view/predicates/element-ref.ts +3 -4
  78. package/src/compute-view/element-view/predicates/relation-direct.ts +16 -12
  79. package/src/compute-view/element-view/predicates/relation-in-out.ts +7 -8
  80. package/src/compute-view/element-view/predicates/relation-in.ts +19 -26
  81. package/src/compute-view/element-view/predicates/relation-out.ts +20 -21
  82. package/src/compute-view/element-view/predicates/wildcard.ts +3 -3
  83. package/src/compute-view/element-view/utils.ts +25 -23
  84. package/src/compute-view/index.ts +1 -1
  85. package/src/compute-view/memory/AbstractStageExclude.ts +3 -4
  86. package/src/compute-view/memory/AbstractStageInclude.ts +1 -1
  87. package/src/compute-view/memory/_types.ts +3 -2
  88. package/src/compute-view/relationships-view/_types.ts +3 -4
  89. package/src/compute-view/relationships-view/compute.ts +8 -11
  90. package/src/compute-view/relationships-view/layout.ts +6 -6
  91. package/src/compute-view/relationships-view/utils.ts +4 -4
  92. package/src/compute-view/utils/ancestorsOfNode.ts +7 -7
  93. package/src/compute-view/utils/applyCustomElementProperties.ts +16 -8
  94. package/src/compute-view/utils/applyCustomRelationProperties.ts +19 -9
  95. package/src/compute-view/utils/applyViewRuleStyles.ts +18 -10
  96. package/src/compute-view/utils/buildComputedNodes.ts +40 -40
  97. package/src/compute-view/utils/buildElementNotations.ts +14 -14
  98. package/src/compute-view/utils/elementExpressionToPredicate.ts +14 -15
  99. package/src/compute-view/utils/link-nodes-with-edges.ts +6 -4
  100. package/src/compute-view/utils/merge-props-from-relationships.ts +52 -20
  101. package/src/compute-view/utils/relationExpressionToPredicates.ts +19 -19
  102. package/src/compute-view/utils/resolve-extended-views.ts +8 -7
  103. package/src/compute-view/utils/resolve-global-rules.ts +31 -26
  104. package/src/compute-view/utils/topological-sort.ts +14 -14
  105. package/src/compute-view/utils/view-hash.ts +2 -2
  106. package/src/compute-view/utils/with-readable-edges.ts +9 -5
  107. package/src/index.ts +0 -32
  108. package/src/model/DeploymentElementModel.ts +182 -137
  109. package/src/model/DeploymentModel.ts +88 -65
  110. package/src/model/ElementModel.ts +92 -72
  111. package/src/model/LikeC4Model.ts +430 -241
  112. package/src/model/RelationModel.ts +69 -26
  113. package/src/model/__test__/fixture.ts +50 -36
  114. package/src/model/connection/Connection.ts +2 -2
  115. package/src/model/connection/deployment/DeploymentConnectionModel.ts +21 -24
  116. package/src/model/connection/deployment/find.ts +1 -1
  117. package/src/model/connection/model/ConnectionModel.ts +21 -20
  118. package/src/model/connection/model/find.ts +7 -7
  119. package/src/model/connection/ops.ts +6 -6
  120. package/src/model/guards.ts +66 -14
  121. package/src/model/index.ts +20 -7
  122. package/src/model/types.ts +41 -97
  123. package/src/model/view/EdgeModel.ts +47 -41
  124. package/src/model/view/LikeC4ViewModel.ts +130 -80
  125. package/src/model/view/NodeModel.ts +102 -96
  126. package/src/theme/element.ts +1 -1
  127. package/src/theme/index.ts +9 -9
  128. package/src/theme/relationships.ts +1 -1
  129. package/src/types/_common.ts +21 -15
  130. package/src/types/aux.ts +285 -0
  131. package/src/types/const.ts +34 -0
  132. package/src/types/expression-model.ts +292 -0
  133. package/src/types/expression.ts +311 -0
  134. package/src/types/fqnRef.ts +88 -0
  135. package/src/types/geometry.ts +131 -0
  136. package/src/types/global.ts +10 -8
  137. package/src/types/index.ts +39 -201
  138. package/src/types/model-data.ts +52 -84
  139. package/src/types/model-deployment.ts +87 -0
  140. package/src/types/model-dump.ts +72 -0
  141. package/src/types/model-logical.ts +111 -0
  142. package/src/types/model-spec.ts +81 -0
  143. package/src/types/operators.ts +51 -52
  144. package/src/types/scalar.ts +114 -0
  145. package/src/types/styles.ts +123 -0
  146. package/src/types/view-changes.ts +4 -5
  147. package/src/types/view-common.ts +157 -0
  148. package/src/types/view-computed.ts +113 -0
  149. package/src/types/view-layouted.ts +82 -0
  150. package/src/types/view-parsed.deployment.ts +40 -0
  151. package/src/types/view-parsed.dynamic.ts +78 -0
  152. package/src/types/view-parsed.element.ts +65 -0
  153. package/src/types/view.ts +122 -542
  154. package/src/utils/compare-natural.ts +43 -1
  155. package/src/utils/getOrCreate.ts +0 -34
  156. package/src/utils/index.ts +7 -12
  157. package/src/utils/iterable/filter.ts +1 -1
  158. package/src/utils/iterable/find.ts +3 -1
  159. package/src/utils/iterable/head.ts +22 -0
  160. package/src/utils/iterable/index.ts +1 -0
  161. package/src/utils/iterable/map.ts +1 -1
  162. package/src/utils/iterable/reduce.ts +1 -1
  163. package/src/utils/iterable/some.ts +1 -1
  164. package/src/utils/memoize-prop.ts +30 -0
  165. package/src/utils/object-hash.ts +1 -1
  166. package/src/utils/relations.ts +14 -11
  167. package/src/utils/string-hash.ts +1 -1
  168. package/dist/shared/core.CZR9J1Qx.d.mts +0 -146
  169. package/dist/shared/core.CiFKryGW.d.mts +0 -745
  170. package/dist/shared/core.DJvmfnEi.d.mts +0 -1153
  171. package/dist/shared/core.DgfwjBtu.mjs +0 -495
  172. package/dist/shared/core.SjLhMA7a.d.mts +0 -62
  173. package/src/builder/__snapshots__/Builder.spec.ts.snap +0 -374
  174. package/src/compute-view/element-view/predicates.ts +0 -520
  175. package/src/compute-view/utils/uniqueTags.ts +0 -21
  176. package/src/types/deployments.ts +0 -170
  177. package/src/types/element.ts +0 -109
  178. package/src/types/expression-v2-model.ts +0 -314
  179. package/src/types/expression-v2.ts +0 -392
  180. package/src/types/overview-graph.ts +0 -43
  181. package/src/types/relation.ts +0 -61
  182. package/src/types/scalars.ts +0 -39
  183. package/src/types/theme.ts +0 -82
  184. package/src/types/view-notation.ts +0 -9
  185. package/src/utils/graphlib.ts +0 -10
  186. /package/src/{errors/index.ts → utils/invariant.ts} +0 -0
@@ -1,7 +1,6 @@
1
1
  import compare from 'natural-compare-lite'
2
2
  import { isString } from 'remeda'
3
3
 
4
-
5
4
  export function compareNatural(a: string | undefined, b: string | undefined): -1 | 0 | 1 {
6
5
  if (a === b) return 0
7
6
  if (isString(a)) {
@@ -12,3 +11,46 @@ export function compareNatural(a: string | undefined, b: string | undefined): -1
12
11
  }
13
12
  return isString(b) ? -1 : 0
14
13
  }
14
+
15
+ /**
16
+ * Compares two strings hierarchically based on their depth.
17
+ * From parent nodes to leaves
18
+ *
19
+ * @example
20
+ * const lines = [
21
+ * 'a.b.c',
22
+ * 'a',
23
+ * 'a.b',
24
+ * 'a.c.c',
25
+ * ]
26
+ * lines.sort(compareNaturalHierarchically('.'))
27
+ * // [
28
+ * // 'a',
29
+ * // 'a.b',
30
+ * // 'a.b.c',
31
+ * // 'a.c.c',
32
+ * // ]
33
+ */
34
+ export function compareNaturalHierarchically(
35
+ separator = '.',
36
+ ): (a: string | undefined, b: string | undefined) => number {
37
+ return (a, b) => {
38
+ if (a === b) return 0
39
+ if (!a) return -1
40
+ if (!b) return 1
41
+ const aParts = a.split(separator)
42
+ const bParts = b.split(separator)
43
+ if (aParts.length !== bParts.length) {
44
+ return aParts.length - bParts.length
45
+ }
46
+ for (let i = 0; i < aParts.length; i++) {
47
+ const aPart = aParts[i]!
48
+ const bPart = bParts[i]!
49
+ const comparison = compare(aPart, bPart)
50
+ if (comparison !== 0) {
51
+ return comparison
52
+ }
53
+ }
54
+ return 0
55
+ }
56
+ }
@@ -1,9 +1,3 @@
1
- // export function getOrCreate<K, V>(map: Map<K, V>): Map<K, V> & {
2
- // get(key: K, create: (key: K) => V): V
3
- // get(key: K): V | undefined
4
- // }
5
- // export function getOrCreate<K, V>(map: Map<K, V>, key: K, create: (key: K) => V): V
6
- // export function getOrCreate<K, V>(map: Map<K, V>, key?: K, create?: (key: K) => V) {
7
1
  export function getOrCreate<K, V>(map: Map<K, V>, key: K, create: (key: K) => V): V {
8
2
  let entry = map.get(key)
9
3
  if (!entry) {
@@ -12,31 +6,3 @@ export function getOrCreate<K, V>(map: Map<K, V>, key: K, create: (key: K) => V)
12
6
  }
13
7
  return entry
14
8
  }
15
-
16
- // export class BetterMap<K, V> extends Map<K, V> {
17
- // constructor(iterable?: Iterable<readonly [K, V]> | null) {
18
- // super(iterable)
19
- // }
20
-
21
- // /**
22
- // * Returns the element associated with the specified key.
23
- // * If no element is associated with the specified key, and a create function is provided, a new element will be created and stored.
24
- // * @example
25
- // * ```ts
26
- // * const map = new BetterMap<Fqn, Element>()
27
- // *
28
- // * map.get(fqn, () => factory.createElement(fqn))
29
- // *
30
- // */
31
- // override get(key: K, create: (key: K) => V): V
32
- // override get(key: K): V | undefined
33
- // override get(key: K, create?: (key: K) => V) {
34
- // const entry = super.get(key)
35
- // if (!entry && create) {
36
- // const newEntry = create(key)
37
- // this.set(key, newEntry)
38
- // return newEntry
39
- // }
40
- // return entry
41
- // }
42
- // }
@@ -8,13 +8,10 @@ export {
8
8
  Stack,
9
9
  } from './mnemonist'
10
10
 
11
- export {
12
- commonHead,
13
- } from './common-head'
11
+ export { invariant, nonexhaustive, nonNullable } from './invariant'
14
12
 
15
- export {
16
- compareNatural,
17
- } from './compare-natural'
13
+ export { commonHead } from './common-head'
14
+ export { compareNatural, compareNaturalHierarchically } from './compare-natural'
18
15
  export {
19
16
  ancestorsFqn,
20
17
  commonAncestor,
@@ -34,9 +31,7 @@ export {
34
31
  sortParentsFirst,
35
32
  } from './fqn'
36
33
 
37
- export {
38
- getOrCreate,
39
- } from './getOrCreate'
34
+ export { getOrCreate } from './getOrCreate'
40
35
 
41
36
  export {
42
37
  hasAtLeast,
@@ -47,6 +42,7 @@ export {
47
42
  ifilter,
48
43
  ifind,
49
44
  iflat,
45
+ ihead,
50
46
  imap,
51
47
  ireduce,
52
48
  isIterable,
@@ -55,9 +51,8 @@ export {
55
51
  toArray,
56
52
  toSet,
57
53
  } from './iterable'
58
- export {
59
- delay,
60
- } from './promises'
54
+ export { memoizeProp } from './memoize-prop'
55
+ export { delay } from './promises'
61
56
 
62
57
  export {
63
58
  compareRelations,
@@ -1,6 +1,6 @@
1
1
  import { isFunction } from 'remeda'
2
- import { invariant } from '../../errors'
3
2
  import type { IteratorLike } from '../../types'
3
+ import { invariant } from '../../utils/invariant'
4
4
 
5
5
  /**
6
6
  * Filters an iterable based on a predicate.
@@ -1,5 +1,5 @@
1
1
  import { isFunction } from 'remeda'
2
- import { invariant } from '../../errors'
2
+ import { invariant } from '../../utils/invariant'
3
3
 
4
4
  /**
5
5
  * Finds the first element in the iterable that satisfies the predicate.
@@ -7,6 +7,7 @@ import { invariant } from '../../errors'
7
7
  * @signature
8
8
  * ifind(predicate)(data)
9
9
  */
10
+ export function ifind<T, S extends T>(predicate: (item: T) => item is S): (iterable: Iterable<T>) => S | undefined
10
11
  export function ifind<T>(predicate: (item: T) => boolean): (iterable: Iterable<T>) => T | undefined
11
12
  /**
12
13
  * Finds the first element in the iterable that satisfies the predicate.
@@ -14,6 +15,7 @@ export function ifind<T>(predicate: (item: T) => boolean): (iterable: Iterable<T
14
15
  * @signature
15
16
  * ifind(data, predicate)
16
17
  */
18
+ export function ifind<T, S extends T>(iterable: Iterable<T>, predicate: (item: T) => item is S): S | undefined
17
19
  export function ifind<T>(iterable: Iterable<T>, predicate: (item: T) => boolean): T | undefined
18
20
 
19
21
  export function ifind(arg1: unknown, arg2?: unknown) {
@@ -0,0 +1,22 @@
1
+ export function ihead<T>(): (iterable: Iterable<T>) => T | undefined
2
+ /**
3
+ * Finds the first element in the iterable that satisfies the predicate.
4
+ * Data first version of `find`.
5
+ * @signature
6
+ * ifind(data, predicate)
7
+ */
8
+ export function ihead<T>(iterable: Iterable<T>): T | undefined
9
+
10
+ export function ihead<T>(iterable?: Iterable<T>) {
11
+ if (!iterable) {
12
+ return _head
13
+ }
14
+ return _head(iterable)
15
+ }
16
+
17
+ function _head<T>(iter: Iterable<T>) {
18
+ for (const value of iter) {
19
+ return value
20
+ }
21
+ return
22
+ }
@@ -6,6 +6,7 @@ export { isIterable } from './_types'
6
6
  export { ifilter } from './filter'
7
7
  export { ifind } from './find'
8
8
  export { iflat } from './flat'
9
+ export { ihead } from './head'
9
10
  export { imap } from './map'
10
11
  export { ireduce } from './reduce'
11
12
  export { isome } from './some'
@@ -1,6 +1,6 @@
1
1
  import { isFunction } from 'remeda'
2
- import { invariant } from '../../errors'
3
2
  import type { IteratorLike } from '../../types'
3
+ import { invariant } from '../../utils/invariant'
4
4
 
5
5
  type MapFunction<T, S> = (item: T) => S
6
6
 
@@ -1,5 +1,5 @@
1
1
  import { isDefined, isFunction } from 'remeda'
2
- import { invariant } from '../../errors'
2
+ import { invariant } from '../../utils/invariant'
3
3
 
4
4
  export function ireduce<T, R>(reducer: (acc: R, item: T) => R, initialValue: R): (iterable: Iterable<T>) => R
5
5
  export function ireduce<T, R>(iterable: Iterable<T>, reducer: (acc: R, item: T) => R, initialValue: R): R
@@ -1,5 +1,5 @@
1
1
  import { isFunction } from 'remeda'
2
- import { invariant } from '../../errors'
2
+ import { invariant } from '../../utils/invariant'
3
3
 
4
4
  /**
5
5
  * Checks if at least one element in the iterable satisfies the predicate.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Saves the value returned by fn() in a hidden property tag of obj object, so next time memoizeProp() is called,
3
+ * that value will be returned, and fn won't be called.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * class Model {
8
+ * // using same Symbol
9
+ * get computed1() {
10
+ * return memoizeProp(this, Symbol.for('computed1'), () => doOnce())
11
+ * }
12
+ * // using string
13
+ * get computed2() {
14
+ * return memoizeProp(this, 'computed2', () => doOnce())
15
+ * }
16
+ *
17
+ * }
18
+ * ```
19
+ */
20
+ export function memoizeProp<Tag extends symbol | string, Res>(obj: object, tag: Tag, fn: () => Res): Res {
21
+ const tagSymbol = typeof tag === 'symbol' ? tag : Symbol.for(tag)
22
+ if (!obj.hasOwnProperty(tagSymbol)) {
23
+ Object.defineProperty(obj, tagSymbol, {
24
+ enumerable: false,
25
+ writable: false,
26
+ value: fn(),
27
+ })
28
+ }
29
+ return (obj as any)[tagSymbol]!
30
+ }
@@ -1,6 +1,6 @@
1
1
  import objecthash from 'object-hash'
2
2
  import { isNonNullish } from 'remeda'
3
- import { invariant } from '../errors'
3
+ import { invariant } from '../utils/invariant'
4
4
 
5
5
  export function objectHash(value: any): string {
6
6
  invariant(
@@ -1,20 +1,23 @@
1
- import type { Fqn } from '../types'
2
- import { commonAncestor, compareFqnHierarchically, isAncestor } from './fqn'
1
+ import { commonAncestor, compareFqnHierarchically } from './fqn'
3
2
 
4
- export type Relation = {
5
- source: string
6
- target: string
3
+ export type RelationshipLike = {
4
+ source: {
5
+ model: string
6
+ }
7
+ target: {
8
+ model: string
9
+ }
7
10
  }
8
11
 
9
- export type RelationPredicate = (rel: Relation) => boolean
12
+ export type RelationPredicate = (rel: RelationshipLike) => boolean
10
13
 
11
14
  /**
12
15
  * Compares two relations hierarchically.
13
16
  * From the most general (implicit) to the most specific.
14
17
  */
15
- export const compareRelations = <T extends { source: string; target: string }>(a: T, b: T): number => {
16
- const parentA = commonAncestor(a.source as Fqn, a.target as Fqn)
17
- const parentB = commonAncestor(b.source as Fqn, b.target as Fqn)
18
+ export const compareRelations = <T extends RelationshipLike>(a: T, b: T): number => {
19
+ const parentA = commonAncestor(a.source.model, a.target.model)
20
+ const parentB = commonAncestor(b.source.model, b.target.model)
18
21
  if (parentA && !parentB) {
19
22
  return 1
20
23
  }
@@ -25,9 +28,9 @@ export const compareRelations = <T extends { source: string; target: string }>(a
25
28
  if (compareParents !== 0) {
26
29
  return compareParents
27
30
  }
28
- const compareSource = compareFqnHierarchically(a.source, b.source)
31
+ const compareSource = compareFqnHierarchically(a.source.model, b.source.model)
29
32
  if (compareSource !== 0) {
30
33
  return compareSource
31
34
  }
32
- return compareFqnHierarchically(a.target, b.target)
35
+ return compareFqnHierarchically(a.target.model, b.target.model)
33
36
  }
@@ -1,4 +1,4 @@
1
- import { invariant } from '../errors'
1
+ import { invariant } from '../utils/invariant'
2
2
 
3
3
  /**
4
4
  * @see https://gist.github.com/victor-homyakov/bcb7d7911e4a388b1c810f8c3ce17bcf
@@ -1,146 +0,0 @@
1
- import { E as ElementModel, d as DeploymentElementModel, A as AnyAux, e as DeploymentNodeModel, D as DeployedInstanceModel, j as RelationshipsAccum, R as RelationshipModel, f as DeploymentRelationModel } from './core.CiFKryGW.mjs';
2
- import { F as Fqn, I as IteratorLike } from './core.SjLhMA7a.mjs';
3
-
4
- interface Connection<Elem = ElementModel | DeploymentElementModel, Id = string> {
5
- readonly id: Id;
6
- readonly source: Elem;
7
- readonly target: Elem;
8
- /**
9
- * Common ancestor of the source and target elements.
10
- * Represents the boundary of the connection.
11
- */
12
- readonly boundary: Elem | null;
13
- /**
14
- * Human readable expression of the connection
15
- * Mostly used for testing and debugging
16
- */
17
- readonly expression: string;
18
- mergeWith(this: Connection<Elem, Id>, other: typeof this): typeof this;
19
- nonEmpty(): boolean;
20
- difference(this: Connection<Elem, Id>, other: typeof this): typeof this;
21
- intersect(this: Connection<Elem, Id>, other: typeof this): typeof this;
22
- equals(other: Connection): boolean;
23
- }
24
- declare namespace Connection {
25
- type ConnectionPredicate = <C extends Connection<{
26
- id: string;
27
- }, any>>(connection: C) => boolean;
28
- type ElementId = Fqn | string;
29
- export const isInside: (fqn: ElementId) => ConnectionPredicate;
30
- export const isDirectedBetween: (source: ElementId, target: ElementId) => ConnectionPredicate;
31
- export const isAnyBetween: (source: ElementId, target: ElementId) => ConnectionPredicate;
32
- export const isIncoming: (target: ElementId) => ConnectionPredicate;
33
- export const isOutgoing: (source: ElementId) => ConnectionPredicate;
34
- export const isAnyInOut: (source: ElementId) => ConnectionPredicate;
35
- export { };
36
- }
37
-
38
- declare const customInspectSymbol: unique symbol;
39
-
40
- /**
41
- * Connection is ephemeral entity, result of a resolving relationships between source and target.
42
- * Includes direct relationships and/or between their nested elements.
43
- */
44
- declare class DeploymentConnectionModel<M extends AnyAux = AnyAux> implements Connection<DeploymentElementModel<M>, M['EdgeId']> {
45
- readonly source: DeploymentNodeModel<M> | DeployedInstanceModel<M>;
46
- readonly target: DeploymentNodeModel<M> | DeployedInstanceModel<M>;
47
- readonly relations: RelationshipsAccum<M>;
48
- constructor(source: DeploymentNodeModel<M> | DeployedInstanceModel<M>, target: DeploymentNodeModel<M> | DeployedInstanceModel<M>, relations: RelationshipsAccum<M>);
49
- readonly id: M['EdgeId'];
50
- /**
51
- * Human readable expression of the connection
52
- * Mostly used for testing and debugging
53
- */
54
- get expression(): string;
55
- private _boundary;
56
- /**
57
- * Common ancestor of the source and target elements.
58
- * Represents the boundary of the connection.
59
- */
60
- get boundary(): DeploymentNodeModel<M> | null;
61
- nonEmpty(): boolean;
62
- [customInspectSymbol](depth: any, inspectOptions: any, inspect: any): string;
63
- toString(): string;
64
- /**
65
- * Check if connection contains deployment relation,
66
- * that is directly connected to source or target.
67
- */
68
- hasDirectDeploymentRelation(): boolean;
69
- values(): IteratorLike<RelationshipModel<M> | DeploymentRelationModel<M>>;
70
- /**
71
- * Merge with another connections, if it has the same source and target.
72
- * Returns new connection with union of relationships.
73
- */
74
- mergeWith(others: DeploymentConnectionModel<M>[]): DeploymentConnectionModel<M>;
75
- /**
76
- * Merge with another connection, if it has the same source and target.
77
- * Returns new connection with union of relationships.
78
- */
79
- mergeWith(other: DeploymentConnectionModel<M>): DeploymentConnectionModel<M>;
80
- difference(other: DeploymentConnectionModel<M>): DeploymentConnectionModel<M>;
81
- intersect(other: DeploymentConnectionModel<M>): DeploymentConnectionModel<M>;
82
- equals(other: Connection): boolean;
83
- /**
84
- * Creates a clone of the current `DeploymentConnectionModel` instance with optional overrides.
85
- * if `null` is provided in overrides, the corresponding relation set will be empty.
86
- */
87
- update(overrides?: {
88
- model?: ReadonlySet<RelationshipModel<M>> | null;
89
- deployment?: ReadonlySet<DeploymentRelationModel<M>> | null;
90
- }): DeploymentConnectionModel<M>;
91
- }
92
-
93
- /**
94
- * Connection refers to any relationships between two elements,
95
- * both direct and implicit ones (between their nested elements).
96
- *
97
- * Merges relationships together to an single edge on the diagram.
98
- */
99
- declare class ConnectionModel<M extends AnyAux = AnyAux> implements Connection<ElementModel<M>, M['EdgeId']> {
100
- readonly source: ElementModel<M>;
101
- readonly target: ElementModel<M>;
102
- readonly relations: ReadonlySet<RelationshipModel<M>>;
103
- readonly id: M['EdgeId'];
104
- constructor(source: ElementModel<M>, target: ElementModel<M>, relations?: ReadonlySet<RelationshipModel<M>>);
105
- private _boundary;
106
- /**
107
- * Common ancestor of the source and target elements.
108
- * Represents the boundary of the connection.
109
- */
110
- get boundary(): ElementModel<M> | null;
111
- /**
112
- * Human readable expression of the connection
113
- * Mostly used for testing and debugging
114
- */
115
- get expression(): string;
116
- /**
117
- * Returns true if only includes relations between the source and target elements.
118
- */
119
- get isDirect(): boolean;
120
- /**
121
- * Returns true if includes relations between nested elements of the source and target elements.
122
- */
123
- get isImplicit(): boolean;
124
- get directRelations(): ReadonlySet<RelationshipModel<M>>;
125
- nonEmpty(): boolean;
126
- mergeWith(other: ConnectionModel<M>): ConnectionModel<M>;
127
- difference(other: ConnectionModel<M>): ConnectionModel<M>;
128
- intersect(other: ConnectionModel<M>): ConnectionModel<M>;
129
- equals(other: Connection): boolean;
130
- /**
131
- * Returns a new instance with the updated relations.
132
- *
133
- * @param relations - A readonly set of `RelationshipModel` instances representing the new relations.
134
- * @returns A new `ConnectionModel` instance with the updated relations.
135
- */
136
- update(relations: ReadonlySet<RelationshipModel<M>>): ConnectionModel<M>;
137
- [customInspectSymbol](depth: any, inspectOptions: any, inspect: any): string;
138
- toString(): string;
139
- /**
140
- * Creates a new connection with reversed direction (target becomes source and vice versa)
141
- * @param search - When true, attempts to find an existing connection between the reversed nodes
142
- */
143
- reversed(search?: boolean): ConnectionModel<M>;
144
- }
145
-
146
- export { Connection as C, DeploymentConnectionModel as D, ConnectionModel as a };