@likec4/core 1.31.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.
- package/README.md +407 -5
- package/dist/builder/index.d.mts +221 -42
- package/dist/builder/index.mjs +118 -65
- package/dist/compute-view/index.d.mts +23 -7
- package/dist/compute-view/index.mjs +11 -6
- package/dist/compute-view/relationships-view/index.d.mts +9 -7
- package/dist/compute-view/relationships-view/index.mjs +3 -2
- package/dist/index.d.mts +10 -14
- package/dist/index.mjs +9 -6
- package/dist/model/index.d.mts +173 -19
- package/dist/model/index.mjs +6 -1
- package/dist/shared/core.BaYE_r29.d.mts +258 -0
- package/dist/shared/core.Bk7wEZFG.mjs +276 -0
- package/dist/shared/core.BrCnZFTn.mjs +32 -0
- package/dist/shared/core.BuO4ncfY.d.mts +146 -0
- package/dist/shared/{core.Bq753SYD.mjs → core.CBpKAlhj.mjs} +2012 -4422
- package/dist/shared/core.CCWXGc6G.d.mts +920 -0
- package/dist/shared/core.CUYDgv2-.mjs +214 -0
- package/dist/shared/{core.Cu-UdkSl.mjs → core.CpXlRyE5.mjs} +7 -494
- package/dist/shared/{core.C-YXI-43.mjs → core.Cy9smucx.mjs} +3 -1
- package/dist/shared/core.CywrQs86.d.mts +31 -0
- package/dist/shared/core.DoK86JEe.mjs +518 -0
- package/dist/shared/core.Dpq3P3YJ.d.mts +1265 -0
- package/dist/shared/{core.D2830qgg.d.mts → core.Pf5I9o0e.d.mts} +1 -1
- package/dist/shared/core.cbA9VZ02.mjs +2681 -0
- package/dist/shared/{core.CQXU9DF7.mjs → core.rmvsy0n3.mjs} +23 -32
- package/dist/types/aux.d.mts +3 -0
- package/dist/types/aux.mjs +1 -0
- package/dist/types/index.d.mts +7 -45
- package/dist/types/index.mjs +130 -3
- package/dist/utils/index.d.mts +221 -53
- package/dist/utils/index.mjs +14 -10
- package/package.json +15 -7
- package/src/builder/Builder.deploymentModel.ts +82 -18
- package/src/builder/Builder.element.ts +40 -20
- package/src/builder/Builder.model.ts +66 -17
- package/src/builder/Builder.ts +168 -76
- package/src/builder/Builder.view-common.ts +35 -17
- package/src/builder/Builder.view-deployment.ts +25 -25
- package/src/builder/Builder.view-element.ts +13 -12
- package/src/builder/Builder.views.ts +12 -7
- package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +62 -34
- package/src/builder/__snapshots__/Builder-style2.compute-model.json5 +319 -0
- package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +45 -24
- package/src/builder/_types.ts +34 -27
- package/src/compute-view/compute-view.ts +31 -34
- package/src/compute-view/deployment-view/__test__/TestHelper.ts +27 -14
- package/src/compute-view/deployment-view/__test__/fixture.ts +15 -13
- package/src/compute-view/deployment-view/_types.ts +10 -10
- package/src/compute-view/deployment-view/clean-connections.ts +5 -7
- package/src/compute-view/deployment-view/compute.ts +16 -13
- package/src/compute-view/deployment-view/memory/memory.ts +5 -6
- package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +4 -5
- package/src/compute-view/deployment-view/predicates/relation-direct.ts +25 -50
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +5 -7
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +7 -11
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +7 -10
- package/src/compute-view/deployment-view/predicates/utils.ts +37 -31
- package/src/compute-view/deployment-view/predicates/wildcard.ts +3 -2
- package/src/compute-view/deployment-view/stages/stage-final.ts +2 -2
- package/src/compute-view/deployment-view/stages/stage-include.ts +1 -1
- package/src/compute-view/deployment-view/utils.ts +79 -72
- package/src/compute-view/dynamic-view/__test__/fixture.ts +20 -11
- package/src/compute-view/dynamic-view/compute.ts +60 -53
- package/src/compute-view/element-view/__test__/TestHelper.ts +53 -29
- package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +26 -26
- package/src/compute-view/element-view/__test__/fixture.ts +134 -83
- package/src/compute-view/element-view/_types.ts +14 -19
- package/src/compute-view/element-view/clean-connections.ts +12 -8
- package/src/compute-view/element-view/compute.ts +61 -51
- package/src/compute-view/element-view/memory/NodeGroup.ts +8 -9
- package/src/compute-view/element-view/memory/memory.ts +22 -22
- package/src/compute-view/element-view/memory/stage-include.ts +5 -3
- package/src/compute-view/element-view/predicates/_utils.ts +18 -14
- package/src/compute-view/element-view/predicates/element-expand.ts +4 -5
- package/src/compute-view/element-view/predicates/element-kind-tag.ts +3 -4
- package/src/compute-view/element-view/predicates/element-ref.ts +3 -4
- package/src/compute-view/element-view/predicates/relation-direct.ts +16 -12
- package/src/compute-view/element-view/predicates/relation-in-out.ts +7 -8
- package/src/compute-view/element-view/predicates/relation-in.ts +19 -26
- package/src/compute-view/element-view/predicates/relation-out.ts +20 -21
- package/src/compute-view/element-view/predicates/wildcard.ts +3 -3
- package/src/compute-view/element-view/utils.ts +25 -23
- package/src/compute-view/index.ts +1 -1
- package/src/compute-view/memory/AbstractStageExclude.ts +3 -4
- package/src/compute-view/memory/AbstractStageInclude.ts +1 -1
- package/src/compute-view/memory/_types.ts +3 -2
- package/src/compute-view/relationships-view/_types.ts +3 -4
- package/src/compute-view/relationships-view/compute.ts +8 -11
- package/src/compute-view/relationships-view/layout.ts +6 -6
- package/src/compute-view/relationships-view/utils.ts +4 -4
- package/src/compute-view/utils/ancestorsOfNode.ts +7 -7
- package/src/compute-view/utils/applyCustomElementProperties.ts +16 -8
- package/src/compute-view/utils/applyCustomRelationProperties.ts +19 -9
- package/src/compute-view/utils/applyViewRuleStyles.ts +18 -10
- package/src/compute-view/utils/buildComputedNodes.ts +40 -40
- package/src/compute-view/utils/buildElementNotations.ts +14 -14
- package/src/compute-view/utils/elementExpressionToPredicate.ts +14 -15
- package/src/compute-view/utils/link-nodes-with-edges.ts +6 -4
- package/src/compute-view/utils/merge-props-from-relationships.ts +52 -20
- package/src/compute-view/utils/relationExpressionToPredicates.ts +19 -19
- package/src/compute-view/utils/resolve-extended-views.ts +8 -7
- package/src/compute-view/utils/resolve-global-rules.ts +31 -26
- package/src/compute-view/utils/topological-sort.ts +14 -14
- package/src/compute-view/utils/view-hash.ts +2 -2
- package/src/compute-view/utils/with-readable-edges.ts +9 -5
- package/src/index.ts +0 -32
- package/src/model/DeploymentElementModel.ts +171 -144
- package/src/model/DeploymentModel.ts +88 -65
- package/src/model/ElementModel.ts +85 -74
- package/src/model/LikeC4Model.ts +430 -241
- package/src/model/RelationModel.ts +63 -29
- package/src/model/__test__/fixture.ts +50 -36
- package/src/model/connection/Connection.ts +2 -2
- package/src/model/connection/deployment/DeploymentConnectionModel.ts +21 -24
- package/src/model/connection/deployment/find.ts +1 -1
- package/src/model/connection/model/ConnectionModel.ts +21 -20
- package/src/model/connection/model/find.ts +7 -7
- package/src/model/connection/ops.ts +6 -6
- package/src/model/guards.ts +66 -14
- package/src/model/index.ts +20 -7
- package/src/model/types.ts +41 -97
- package/src/model/view/EdgeModel.ts +47 -41
- package/src/model/view/LikeC4ViewModel.ts +130 -80
- package/src/model/view/NodeModel.ts +102 -96
- package/src/theme/element.ts +1 -1
- package/src/theme/index.ts +9 -9
- package/src/theme/relationships.ts +1 -1
- package/src/types/_common.ts +21 -15
- package/src/types/aux.ts +285 -0
- package/src/types/const.ts +34 -0
- package/src/types/expression-model.ts +292 -0
- package/src/types/expression.ts +311 -0
- package/src/types/fqnRef.ts +88 -0
- package/src/types/geometry.ts +131 -0
- package/src/types/global.ts +10 -8
- package/src/types/index.ts +39 -201
- package/src/types/model-data.ts +52 -84
- package/src/types/model-deployment.ts +87 -0
- package/src/types/model-dump.ts +72 -0
- package/src/types/model-logical.ts +111 -0
- package/src/types/model-spec.ts +81 -0
- package/src/types/operators.ts +51 -52
- package/src/types/scalar.ts +114 -0
- package/src/types/styles.ts +123 -0
- package/src/types/view-changes.ts +4 -5
- package/src/types/view-common.ts +157 -0
- package/src/types/view-computed.ts +113 -0
- package/src/types/view-layouted.ts +82 -0
- package/src/types/view-parsed.deployment.ts +40 -0
- package/src/types/view-parsed.dynamic.ts +78 -0
- package/src/types/view-parsed.element.ts +65 -0
- package/src/types/view.ts +122 -542
- package/src/utils/compare-natural.ts +43 -1
- package/src/utils/getOrCreate.ts +0 -34
- package/src/utils/index.ts +7 -12
- package/src/utils/iterable/filter.ts +1 -1
- package/src/utils/iterable/find.ts +3 -1
- package/src/utils/iterable/head.ts +22 -0
- package/src/utils/iterable/index.ts +1 -0
- package/src/utils/iterable/map.ts +1 -1
- package/src/utils/iterable/reduce.ts +1 -1
- package/src/utils/iterable/some.ts +1 -1
- package/src/utils/memoize-prop.ts +30 -0
- package/src/utils/object-hash.ts +1 -1
- package/src/utils/relations.ts +14 -11
- package/src/utils/string-hash.ts +1 -1
- package/dist/shared/core.CQDU11hR.d.mts +0 -753
- package/dist/shared/core.DJvmfnEi.d.mts +0 -1153
- package/dist/shared/core.DgfwjBtu.mjs +0 -495
- package/dist/shared/core.Dx7siloV.d.mts +0 -146
- package/dist/shared/core.SjLhMA7a.d.mts +0 -62
- package/src/builder/__snapshots__/Builder.spec.ts.snap +0 -374
- package/src/compute-view/element-view/predicates.ts +0 -520
- package/src/compute-view/utils/uniqueTags.ts +0 -21
- package/src/types/deployments.ts +0 -170
- package/src/types/element.ts +0 -109
- package/src/types/expression-v2-model.ts +0 -314
- package/src/types/expression-v2.ts +0 -392
- package/src/types/overview-graph.ts +0 -43
- package/src/types/relation.ts +0 -61
- package/src/types/scalars.ts +0 -39
- package/src/types/theme.ts +0 -82
- package/src/types/view-notation.ts +0 -9
- package/src/utils/graphlib.ts +0 -10
- /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
|
+
}
|
package/src/utils/getOrCreate.ts
CHANGED
|
@@ -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
|
-
// }
|
package/src/utils/index.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
60
|
-
} from './promises'
|
|
54
|
+
export { memoizeProp } from './memoize-prop'
|
|
55
|
+
export { delay } from './promises'
|
|
61
56
|
|
|
62
57
|
export {
|
|
63
58
|
compareRelations,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isFunction } from 'remeda'
|
|
2
|
-
import { invariant } from '../../
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import { isDefined, isFunction } from 'remeda'
|
|
2
|
-
import { invariant } from '../../
|
|
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
|
|
@@ -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
|
+
}
|
package/src/utils/object-hash.ts
CHANGED
package/src/utils/relations.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { commonAncestor, compareFqnHierarchically, isAncestor } from './fqn'
|
|
1
|
+
import { commonAncestor, compareFqnHierarchically } from './fqn'
|
|
3
2
|
|
|
4
|
-
export type
|
|
5
|
-
source:
|
|
6
|
-
|
|
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:
|
|
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
|
|
16
|
-
const parentA = commonAncestor(a.source
|
|
17
|
-
const parentB = commonAncestor(b.source
|
|
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
|
}
|
package/src/utils/string-hash.ts
CHANGED