@likec4/core 1.41.0 → 1.42.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/builder/package.json +4 -0
- package/compute-view/package.json +4 -0
- package/compute-view/relationships/package.json +4 -0
- package/dist/builder/index.d.mts +13 -11
- package/dist/builder/index.mjs +111 -91
- package/dist/compute-view/index.d.mts +8 -7
- package/dist/compute-view/index.mjs +14 -11
- package/dist/compute-view/relationships-view/index.d.mts +9 -8
- package/dist/compute-view/relationships-view/index.mjs +6 -6
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +11 -11
- package/dist/model/connection/deployment/index.d.mts +11 -10
- package/dist/model/connection/deployment/index.mjs +2 -2
- package/dist/model/connection/index.d.mts +12 -11
- package/dist/model/connection/index.mjs +3 -3
- package/dist/model/connection/model/index.d.mts +11 -10
- package/dist/model/connection/model/index.mjs +2 -2
- package/dist/model/index.d.mts +14 -14
- package/dist/model/index.mjs +4 -5
- package/dist/shared/{core.Ae86Y3tB.mjs → core.01VTr9qu.mjs} +8 -26
- package/dist/shared/core.1vX5a9AY.mjs +86 -0
- package/dist/shared/{core.BVNaR17u.mjs → core.B7KhhkRY.mjs} +1 -1
- package/dist/shared/core.B85MJLTf.mjs +5 -0
- package/dist/shared/{core.DA5vzwZ9.mjs → core.BIqHjQiH.mjs} +56 -42
- package/dist/shared/core.BKlholso.mjs +3 -0
- package/dist/shared/core.BR4zXDH-.mjs +13 -0
- package/dist/shared/{core.CXy1NLUG.mjs → core.BYNkXQ8A.mjs} +21 -12
- package/dist/shared/{core.BuoXfSMj.mjs → core.BbE4y-yl.mjs} +1 -1
- package/dist/shared/core.BoYfZOBm.mjs +3 -0
- package/dist/shared/core.BsSXS-_R.mjs +7 -0
- package/dist/shared/{core.DJp8fgok.mjs → core.BzTakU3I.mjs} +14 -10
- package/dist/shared/{core.4u1dVmfX.mjs → core.C2TiyjI6.mjs} +2 -2
- package/dist/shared/{core.DLpidoWc.mjs → core.C3JowhaZ.mjs} +3 -3
- package/dist/shared/{core.CNGyqkJh.mjs → core.C4x8aaWa.mjs} +3 -1
- package/dist/shared/{core.BB6zA-UU.mjs → core.C8YY6Uub.mjs} +38 -9
- package/dist/shared/{core.Asc11Mjy.mjs → core.C8sl5Y8Z.mjs} +122 -58
- package/dist/shared/{core.BvMRMo7Z.mjs → core.CNgZvKb8.mjs} +3 -5198
- package/dist/shared/{core.CUG6vpyL.d.mts → core.CQngdcuj.d.mts} +85 -4
- package/dist/shared/{core.Be1n9a0i.mjs → core.C_Ni6yHl.mjs} +5 -4
- package/dist/shared/core.CbT8JVYL.mjs +5 -0
- package/dist/shared/core.CqAJJpK_.mjs +3 -0
- package/dist/shared/{core.BXsxn-hf.d.mts → core.D0PjZzIS.d.mts} +27 -15
- package/dist/shared/{core.DgesAwC8.d.mts → core.D5fzJWbF.d.mts} +2 -2
- package/dist/shared/{core.hfOE3RfK.d.mts → core.DACpKp35.d.mts} +5 -5
- package/dist/shared/core.DFi2dOTl.mjs +39548 -0
- package/dist/shared/{core.xSQO0XYD.d.mts → core.DIol3syK.d.mts} +2 -2
- package/dist/shared/{core.DlG1xWt2.mjs → core.DMMOWQqc.mjs} +3 -2
- package/dist/shared/core.DNbUPnve.mjs +3990 -0
- package/dist/shared/{core.CCD1ID81.mjs → core.DRJma0Ol.mjs} +4 -3
- package/dist/shared/{core.DgttqsJc.mjs → core.DRhg-gVU.mjs} +9 -9
- package/dist/shared/core.DSO_rTC2.mjs +5322 -0
- package/dist/shared/{core.FUPplpae.d.mts → core.D_vkffV4.d.mts} +4 -2
- package/dist/shared/core.DdMJk7nx.d.mts +476 -0
- package/dist/shared/{core.BhpgpOep.d.mts → core.Dgs6-nuz.d.mts} +2 -2
- package/dist/shared/{core.Be4Jy9Qx.mjs → core.FZ305VYd.mjs} +2 -2
- package/dist/shared/core.OHD4KXm9.mjs +5 -0
- package/dist/shared/{core.GTgsmXS_.mjs → core.QJD_fcrc.mjs} +2 -2
- package/dist/shared/core.RfnaEmgA.mjs +7 -0
- package/dist/shared/core.fHR_8Tnq.d.mts +450 -0
- package/dist/shared/{core.D0EgVMQK.mjs → core.lRvxPoao.mjs} +14 -12
- package/dist/shared/{core.CaT0SUUK.mjs → core.rCeaAqgW.mjs} +1 -84
- package/dist/shared/{core.zxTBF_PD.d.mts → core.s9uwOt60.d.mts} +4 -4
- package/dist/shared/core.yna0OdV5.d.mts +98 -0
- package/dist/styles/index.d.mts +106 -0
- package/dist/styles/index.mjs +1 -0
- package/dist/types/_aux.d.mts +2 -2
- package/dist/types/expression-model.d.mts +3 -4
- package/dist/types/expression.d.mts +3 -4
- package/dist/types/fqnRef.d.mts +2 -2
- package/dist/types/fqnRef.mjs +3 -3
- package/dist/types/index.d.mts +8 -8
- package/dist/types/index.mjs +150 -5
- package/dist/types/scalar.mjs +3 -2
- package/dist/utils/graphology/index.d.mts +1864 -0
- package/dist/utils/graphology/index.mjs +1 -0
- package/dist/utils/index.d.mts +11 -6
- package/dist/utils/index.mjs +21 -37
- package/dist/utils/iterable/index.d.mts +1 -1
- package/dist/utils/iterable/index.mjs +45 -7
- package/model/package.json +4 -0
- package/package.json +42 -24
- package/styles/package.json +4 -0
- package/types/package.json +4 -0
- package/utils/graphology/package.json +4 -0
- package/utils/package.json +4 -0
- package/dist/shared/core.6_Vp2iiN.mjs +0 -172
- package/dist/shared/core.CUw_2J9j.mjs +0 -47
- package/dist/shared/core.CzdwsPmY.d.mts +0 -69
- package/dist/shared/core.D-ZGWDDt.d.mts +0 -831
- package/dist/shared/core.DoM6aM9N.mjs +0 -7
- package/dist/shared/core.ILwny7BV.mjs +0 -38
- package/dist/theme/index.d.mts +0 -11
- package/dist/theme/index.mjs +0 -232
- package/src/builder/Builder.deployment.ts +0 -224
- package/src/builder/Builder.deploymentModel.ts +0 -449
- package/src/builder/Builder.element.ts +0 -241
- package/src/builder/Builder.model.ts +0 -494
- package/src/builder/Builder.ts +0 -946
- package/src/builder/Builder.view-common.ts +0 -273
- package/src/builder/Builder.view-deployment.ts +0 -135
- package/src/builder/Builder.view-element.ts +0 -202
- package/src/builder/Builder.views.ts +0 -399
- package/src/builder/Builder.with.ts +0 -156
- package/src/builder/_types.ts +0 -324
- package/src/builder/index.ts +0 -11
- package/src/compute-view/compute-view.ts +0 -80
- package/src/compute-view/deployment-view/_types.ts +0 -38
- package/src/compute-view/deployment-view/clean-connections.ts +0 -236
- package/src/compute-view/deployment-view/compute.ts +0 -94
- package/src/compute-view/deployment-view/memory/index.ts +0 -9
- package/src/compute-view/deployment-view/memory/memory.ts +0 -96
- package/src/compute-view/deployment-view/predicates/deploymentRefs-where.ts +0 -18
- package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +0 -154
- package/src/compute-view/deployment-view/predicates/index.ts +0 -8
- package/src/compute-view/deployment-view/predicates/relation-direct.ts +0 -243
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +0 -70
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +0 -101
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +0 -95
- package/src/compute-view/deployment-view/predicates/relation-where.ts +0 -18
- package/src/compute-view/deployment-view/predicates/utils.ts +0 -282
- package/src/compute-view/deployment-view/predicates/wildcard.ts +0 -41
- package/src/compute-view/deployment-view/stages/stage-exclude.ts +0 -5
- package/src/compute-view/deployment-view/stages/stage-final.ts +0 -245
- package/src/compute-view/deployment-view/stages/stage-include.ts +0 -95
- package/src/compute-view/deployment-view/utils.ts +0 -297
- package/src/compute-view/dynamic-view/compute.ts +0 -312
- package/src/compute-view/element-view/_types.ts +0 -47
- package/src/compute-view/element-view/clean-connections.ts +0 -117
- package/src/compute-view/element-view/compute.ts +0 -324
- package/src/compute-view/element-view/memory/NodeGroup.ts +0 -31
- package/src/compute-view/element-view/memory/index.ts +0 -10
- package/src/compute-view/element-view/memory/memory.ts +0 -178
- package/src/compute-view/element-view/memory/stage-exclude.ts +0 -59
- package/src/compute-view/element-view/memory/stage-final.ts +0 -129
- package/src/compute-view/element-view/memory/stage-include.ts +0 -130
- package/src/compute-view/element-view/predicates/_utils.ts +0 -91
- package/src/compute-view/element-view/predicates/element-expand.ts +0 -29
- package/src/compute-view/element-view/predicates/element-kind-tag.ts +0 -27
- package/src/compute-view/element-view/predicates/element-ref.ts +0 -24
- package/src/compute-view/element-view/predicates/relation-direct.ts +0 -321
- package/src/compute-view/element-view/predicates/relation-in-out.ts +0 -64
- package/src/compute-view/element-view/predicates/relation-in.ts +0 -115
- package/src/compute-view/element-view/predicates/relation-out.ts +0 -119
- package/src/compute-view/element-view/predicates/wildcard.ts +0 -88
- package/src/compute-view/element-view/utils.ts +0 -65
- package/src/compute-view/index.ts +0 -4
- package/src/compute-view/memory/AbstractMemory.ts +0 -45
- package/src/compute-view/memory/AbstractStageExclude.ts +0 -215
- package/src/compute-view/memory/AbstractStageInclude.ts +0 -200
- package/src/compute-view/memory/_types.ts +0 -148
- package/src/compute-view/memory/index.ts +0 -5
- package/src/compute-view/memory/ops.ts +0 -43
- package/src/compute-view/relationships-view/_types.ts +0 -16
- package/src/compute-view/relationships-view/compute.ts +0 -159
- package/src/compute-view/relationships-view/index.ts +0 -3
- package/src/compute-view/relationships-view/layout.ts +0 -358
- package/src/compute-view/relationships-view/utils.ts +0 -73
- package/src/compute-view/utils/ancestorsOfNode.ts +0 -19
- package/src/compute-view/utils/applyCustomElementProperties.ts +0 -107
- package/src/compute-view/utils/applyCustomRelationProperties.ts +0 -58
- package/src/compute-view/utils/applyViewRuleStyles.ts +0 -73
- package/src/compute-view/utils/buildComputedNodes.ts +0 -166
- package/src/compute-view/utils/buildElementNotations.ts +0 -64
- package/src/compute-view/utils/elementExpressionToPredicate.ts +0 -50
- package/src/compute-view/utils/link-nodes-with-edges.ts +0 -56
- package/src/compute-view/utils/merge-props-from-relationships.ts +0 -161
- package/src/compute-view/utils/relationExpressionToPredicates.ts +0 -55
- package/src/compute-view/utils/resolve-extended-views.ts +0 -85
- package/src/compute-view/utils/resolve-global-rules.ts +0 -88
- package/src/compute-view/utils/topological-sort.ts +0 -256
- package/src/compute-view/utils/view-hash.ts +0 -45
- package/src/compute-view/utils/with-readable-edges.ts +0 -40
- package/src/index.ts +0 -32
- package/src/model/DeploymentElementModel.ts +0 -712
- package/src/model/DeploymentModel.ts +0 -393
- package/src/model/ElementModel.ts +0 -316
- package/src/model/LikeC4Model.ts +0 -882
- package/src/model/RelationModel.ts +0 -152
- package/src/model/connection/Connection.ts +0 -72
- package/src/model/connection/deployment/DeploymentConnectionModel.ts +0 -185
- package/src/model/connection/deployment/find.ts +0 -120
- package/src/model/connection/deployment/index.ts +0 -8
- package/src/model/connection/index.ts +0 -22
- package/src/model/connection/model/ConnectionModel.ts +0 -158
- package/src/model/connection/model/find.ts +0 -117
- package/src/model/connection/model/index.ts +0 -8
- package/src/model/connection/ops.ts +0 -276
- package/src/model/guards.ts +0 -77
- package/src/model/index.ts +0 -72
- package/src/model/types.ts +0 -67
- package/src/model/utils.ts +0 -66
- package/src/model/view/EdgeModel.ts +0 -121
- package/src/model/view/LikeC4ViewModel.ts +0 -361
- package/src/model/view/LikeC4ViewsFolder.ts +0 -151
- package/src/model/view/NodeModel.ts +0 -247
- package/src/theme/element.ts +0 -61
- package/src/theme/index.ts +0 -127
- package/src/theme/relationships.ts +0 -54
- package/src/types/RichText.ts +0 -205
- package/src/types/_aux.ts +0 -317
- package/src/types/_common.ts +0 -102
- package/src/types/const.ts +0 -34
- package/src/types/expression-model.ts +0 -294
- package/src/types/expression.ts +0 -313
- package/src/types/fqnRef.ts +0 -91
- package/src/types/geometry.ts +0 -159
- package/src/types/global.ts +0 -21
- package/src/types/index.ts +0 -44
- package/src/types/model-data.ts +0 -77
- package/src/types/model-deployment.ts +0 -78
- package/src/types/model-dump.ts +0 -79
- package/src/types/model-logical.ts +0 -126
- package/src/types/model-spec.ts +0 -88
- package/src/types/operators.ts +0 -156
- package/src/types/project.ts +0 -14
- package/src/types/scalar.ts +0 -162
- package/src/types/styles.ts +0 -122
- package/src/types/view-changes.ts +0 -32
- package/src/types/view-common.ts +0 -157
- package/src/types/view-computed.ts +0 -126
- package/src/types/view-layouted.ts +0 -94
- package/src/types/view-parsed.deployment.ts +0 -39
- package/src/types/view-parsed.dynamic.ts +0 -89
- package/src/types/view-parsed.element.ts +0 -65
- package/src/types/view.ts +0 -113
- package/src/utils/common-head.ts +0 -22
- package/src/utils/compare-natural.ts +0 -60
- package/src/utils/const.ts +0 -1
- package/src/utils/fqn.ts +0 -302
- package/src/utils/getOrCreate.ts +0 -8
- package/src/utils/guards.ts +0 -9
- package/src/utils/index.ts +0 -68
- package/src/utils/invariant.ts +0 -29
- package/src/utils/iterable/_types.ts +0 -5
- package/src/utils/iterable/filter.ts +0 -55
- package/src/utils/iterable/find.ts +0 -38
- package/src/utils/iterable/first.ts +0 -48
- package/src/utils/iterable/flat.ts +0 -17
- package/src/utils/iterable/head.ts +0 -22
- package/src/utils/iterable/index.ts +0 -15
- package/src/utils/iterable/map.ts +0 -40
- package/src/utils/iterable/reduce.ts +0 -24
- package/src/utils/iterable/some.ts +0 -36
- package/src/utils/iterable/to.ts +0 -19
- package/src/utils/iterable/unique.ts +0 -23
- package/src/utils/markdown/index.ts +0 -2
- package/src/utils/markdown/to-html.ts +0 -32
- package/src/utils/markdown/to-text.ts +0 -14
- package/src/utils/memoize-prop.ts +0 -30
- package/src/utils/mnemonist.ts +0 -9
- package/src/utils/object-hash.ts +0 -14
- package/src/utils/promises.ts +0 -24
- package/src/utils/relations.ts +0 -36
- package/src/utils/set.ts +0 -83
- package/src/utils/string-hash.ts +0 -16
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { isEmpty, isTruthy } from 'remeda'
|
|
2
|
-
import type { AnyAux, Color, IteratorLike, Link, scalar } from '../types'
|
|
3
|
-
import {
|
|
4
|
-
type Relationship,
|
|
5
|
-
type RelationshipLineType,
|
|
6
|
-
type RichTextOrEmpty,
|
|
7
|
-
DefaultLineStyle,
|
|
8
|
-
DefaultRelationshipColor,
|
|
9
|
-
FqnRef,
|
|
10
|
-
RichText,
|
|
11
|
-
} from '../types'
|
|
12
|
-
import type * as aux from '../types/_aux'
|
|
13
|
-
import { commonAncestor } from '../utils/fqn'
|
|
14
|
-
import type { DeploymentRelationModel } from './DeploymentElementModel'
|
|
15
|
-
import type { ElementModel } from './ElementModel'
|
|
16
|
-
import type { isDeploymentRelationModel } from './guards'
|
|
17
|
-
import type { LikeC4Model } from './LikeC4Model'
|
|
18
|
-
import type { WithMetadata, WithTags } from './types'
|
|
19
|
-
import type { LikeC4ViewModel, ViewsIterator } from './view/LikeC4ViewModel'
|
|
20
|
-
|
|
21
|
-
export type RelationshipsIterator<A extends AnyAux> = IteratorLike<RelationshipModel<A>>
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A relationship between two elements (in logical or deployment model)
|
|
25
|
-
* use {@link isDeploymentRelationModel} guard to check if the relationship is a deployment relationship
|
|
26
|
-
*/
|
|
27
|
-
export interface AnyRelationshipModel<A extends AnyAux = AnyAux> extends WithTags<A>, WithMetadata<A> {
|
|
28
|
-
readonly id: scalar.RelationId
|
|
29
|
-
readonly expression: string
|
|
30
|
-
readonly title: string | null
|
|
31
|
-
readonly technology: string | null
|
|
32
|
-
readonly description: RichTextOrEmpty
|
|
33
|
-
readonly navigateTo: LikeC4ViewModel<A> | null
|
|
34
|
-
readonly kind: aux.RelationKind<A> | null
|
|
35
|
-
readonly links: ReadonlyArray<Link>
|
|
36
|
-
readonly color: Color
|
|
37
|
-
readonly line: RelationshipLineType
|
|
38
|
-
isDeploymentRelation(): this is DeploymentRelationModel<A>
|
|
39
|
-
isModelRelation(): this is RelationshipModel<A>
|
|
40
|
-
views(): ViewsIterator<A>
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export class RelationshipModel<A extends AnyAux = AnyAux> implements AnyRelationshipModel<A> {
|
|
44
|
-
public readonly source: ElementModel<A>
|
|
45
|
-
public readonly target: ElementModel<A>
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Common ancestor of the source and target elements.
|
|
49
|
-
* Represents the boundary of the Relation.
|
|
50
|
-
*/
|
|
51
|
-
public readonly boundary: ElementModel<A> | null
|
|
52
|
-
|
|
53
|
-
constructor(
|
|
54
|
-
public readonly model: LikeC4Model<A>,
|
|
55
|
-
public readonly $relationship: Relationship<A>,
|
|
56
|
-
) {
|
|
57
|
-
this.source = model.element(FqnRef.flatten($relationship.source))
|
|
58
|
-
this.target = model.element(FqnRef.flatten($relationship.target))
|
|
59
|
-
const parent = commonAncestor(this.source.id, this.target.id)
|
|
60
|
-
this.boundary = parent ? this.model.element(parent) : null
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get id(): scalar.RelationId {
|
|
64
|
-
return this.$relationship.id
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get expression(): string {
|
|
68
|
-
return `${this.source.id} -> ${this.target.id}`
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get title(): string | null {
|
|
72
|
-
if (!isTruthy(this.$relationship.title)) {
|
|
73
|
-
return null
|
|
74
|
-
}
|
|
75
|
-
return this.$relationship.title
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
get technology(): string | null {
|
|
79
|
-
if (!isTruthy(this.$relationship.technology)) {
|
|
80
|
-
return null
|
|
81
|
-
}
|
|
82
|
-
return this.$relationship.technology
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get description(): RichTextOrEmpty {
|
|
86
|
-
return RichText.memoize(this, 'description', this.$relationship.description)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get navigateTo(): LikeC4ViewModel<A> | null {
|
|
90
|
-
return this.$relationship.navigateTo ? this.model.view(this.$relationship.navigateTo) : null
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get tags(): aux.Tags<A> {
|
|
94
|
-
return this.$relationship.tags ?? []
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
get kind(): aux.RelationKind<A> | null {
|
|
98
|
-
return this.$relationship.kind ?? null
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
get links(): ReadonlyArray<Link> {
|
|
102
|
-
return this.$relationship.links ?? []
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
get color(): Color {
|
|
106
|
-
return this.$relationship.color ?? DefaultRelationshipColor
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
get line(): RelationshipLineType {
|
|
110
|
-
return this.$relationship.line ?? DefaultLineStyle
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Iterate over all views that include this relationship.
|
|
115
|
-
*/
|
|
116
|
-
public *views(): ViewsIterator<A> {
|
|
117
|
-
for (const view of this.model.views()) {
|
|
118
|
-
if (view.includesRelation(this.id)) {
|
|
119
|
-
yield view
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public isDeploymentRelation(): this is DeploymentRelationModel<A> {
|
|
126
|
-
return false
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public isModelRelation(): this is RelationshipModel<A> {
|
|
130
|
-
return true
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public hasMetadata(): boolean {
|
|
134
|
-
return !!this.$relationship.metadata && !isEmpty(this.$relationship.metadata)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public getMetadata(): aux.Metadata<A>
|
|
138
|
-
public getMetadata(field: aux.MetadataKey<A>): string | undefined
|
|
139
|
-
public getMetadata(field?: aux.MetadataKey<A>) {
|
|
140
|
-
if (field) {
|
|
141
|
-
return this.$relationship.metadata?.[field]
|
|
142
|
-
}
|
|
143
|
-
return this.$relationship.metadata ?? {}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Checks if the relationship has the given tag.
|
|
148
|
-
*/
|
|
149
|
-
public isTagged(tag: aux.LooseTag<A>): boolean {
|
|
150
|
-
return this.tags.includes(tag as aux.Tag<A>)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { AnyAux, Fqn } from '../../types'
|
|
2
|
-
import { isAncestor } from '../../utils'
|
|
3
|
-
import type { DeploymentElementModel } from '../DeploymentElementModel'
|
|
4
|
-
import type { ElementModel } from '../ElementModel'
|
|
5
|
-
|
|
6
|
-
export interface Connection<Elem = ElementModel<AnyAux> | DeploymentElementModel<AnyAux>, Id = string> {
|
|
7
|
-
readonly id: Id
|
|
8
|
-
readonly source: Elem
|
|
9
|
-
readonly target: Elem
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Common ancestor of the source and target elements.
|
|
13
|
-
* Represents the boundary of the connection.
|
|
14
|
-
*/
|
|
15
|
-
readonly boundary: Elem | null
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Human readable expression of the connection
|
|
19
|
-
* Mostly used for testing and debugging
|
|
20
|
-
*/
|
|
21
|
-
readonly expression: string
|
|
22
|
-
|
|
23
|
-
mergeWith(this: Connection<Elem, Id>, other: typeof this): typeof this
|
|
24
|
-
|
|
25
|
-
nonEmpty(): boolean
|
|
26
|
-
|
|
27
|
-
difference(this: Connection<Elem, Id>, other: typeof this): typeof this
|
|
28
|
-
|
|
29
|
-
intersect(this: Connection<Elem, Id>, other: typeof this): typeof this
|
|
30
|
-
|
|
31
|
-
equals(other: Connection): boolean
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export namespace Connection {
|
|
35
|
-
type ConnectionPredicate = <C extends Connection<{ id: string }, any>>(connection: C) => boolean
|
|
36
|
-
|
|
37
|
-
type ElementId = Fqn | string
|
|
38
|
-
|
|
39
|
-
export const isInside = (fqn: ElementId): ConnectionPredicate => {
|
|
40
|
-
return (connection) => isAncestor(fqn, connection.source.id) && isAncestor(fqn, connection.target.id)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const isDirectedBetween = (source: ElementId, target: ElementId): ConnectionPredicate => {
|
|
44
|
-
return (connection) =>
|
|
45
|
-
(connection.source.id === source || isAncestor(source, connection.source.id))
|
|
46
|
-
&& (connection.target.id === target || isAncestor(target, connection.target.id))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const isAnyBetween = (source: ElementId, target: ElementId): ConnectionPredicate => {
|
|
50
|
-
const forward = isDirectedBetween(source, target),
|
|
51
|
-
backward = isDirectedBetween(target, source)
|
|
52
|
-
return (connection) => forward(connection) || backward(connection)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const isIncoming = (target: ElementId): ConnectionPredicate => {
|
|
56
|
-
return (connection) =>
|
|
57
|
-
(connection.target.id === target || isAncestor(target, connection.target.id))
|
|
58
|
-
&& !isAncestor(target, connection.source.id)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const isOutgoing = (source: ElementId): ConnectionPredicate => {
|
|
62
|
-
return (connection) =>
|
|
63
|
-
(connection.source.id === source || isAncestor(source, connection.source.id))
|
|
64
|
-
&& !isAncestor(source, connection.target.id)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export const isAnyInOut = (source: ElementId): ConnectionPredicate => {
|
|
68
|
-
const isIn = isIncoming(source),
|
|
69
|
-
isOut = isOutgoing(source)
|
|
70
|
-
return (connection) => isIn(connection) || isOut(connection)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import type { AnyAux, aux, IteratorLike } from '../../../types'
|
|
2
|
-
import { invariant, stringHash } from '../../../utils'
|
|
3
|
-
import { customInspectSymbol } from '../../../utils/const'
|
|
4
|
-
import { equals } from '../../../utils/set'
|
|
5
|
-
import {
|
|
6
|
-
type DeploymentElementModel,
|
|
7
|
-
type DeploymentRelationModel,
|
|
8
|
-
DeploymentNodeModel,
|
|
9
|
-
RelationshipsAccum,
|
|
10
|
-
} from '../../DeploymentElementModel'
|
|
11
|
-
import type { RelationshipModel } from '../../RelationModel'
|
|
12
|
-
import type { Connection } from '../Connection'
|
|
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<A extends AnyAux = AnyAux>
|
|
19
|
-
implements Connection<DeploymentElementModel<A>, aux.EdgeId>
|
|
20
|
-
{
|
|
21
|
-
readonly id: aux.EdgeId
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
public readonly source: DeploymentElementModel<A>,
|
|
25
|
-
public readonly target: DeploymentElementModel<A>,
|
|
26
|
-
public readonly relations: RelationshipsAccum<A>,
|
|
27
|
-
) {
|
|
28
|
-
this.id = stringHash(`deployment:${source.id}:${target.id}`) as aux.EdgeId
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Human readable expression of the connection
|
|
33
|
-
* Mostly used for testing and debugging
|
|
34
|
-
*/
|
|
35
|
-
get expression(): string {
|
|
36
|
-
return `${this.source.id} -> ${this.target.id}`
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private _boundary: DeploymentNodeModel<A> | null | undefined
|
|
40
|
-
/**
|
|
41
|
-
* Common ancestor of the source and target elements.
|
|
42
|
-
* Represents the boundary of the connection.
|
|
43
|
-
*/
|
|
44
|
-
get boundary(): DeploymentNodeModel<A> | null {
|
|
45
|
-
this._boundary ??= this.source.commonAncestor(this.target)
|
|
46
|
-
return this._boundary
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
nonEmpty(): boolean {
|
|
50
|
-
return this.relations.nonEmpty
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
[customInspectSymbol](
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
depth,
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
inspectOptions,
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
inspect,
|
|
60
|
-
) {
|
|
61
|
-
const asString = this.toString()
|
|
62
|
-
|
|
63
|
-
// Trick so that node displays the name of the constructor
|
|
64
|
-
Object.defineProperty(asString, 'constructor', {
|
|
65
|
-
value: DeploymentConnectionModel,
|
|
66
|
-
enumerable: false,
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
return asString
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
toString() {
|
|
73
|
-
const model = [...this.relations.model].map(c => ' ' + c.expression)
|
|
74
|
-
if (model.length) {
|
|
75
|
-
model.unshift(' model:')
|
|
76
|
-
} else {
|
|
77
|
-
model.unshift(' model: []')
|
|
78
|
-
}
|
|
79
|
-
const deployment = [...this.relations.deployment].map(c => ' ' + c.expression)
|
|
80
|
-
if (deployment.length) {
|
|
81
|
-
deployment.unshift(' deployment:')
|
|
82
|
-
} else {
|
|
83
|
-
deployment.unshift(' deployment: []')
|
|
84
|
-
}
|
|
85
|
-
return [
|
|
86
|
-
this.expression,
|
|
87
|
-
...model,
|
|
88
|
-
...deployment,
|
|
89
|
-
].join('\n')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Check if connection contains deployment relation,
|
|
94
|
-
* that is directly connected to source or target.
|
|
95
|
-
*/
|
|
96
|
-
public hasDirectDeploymentRelation(): boolean {
|
|
97
|
-
for (const relation of this.relations.deployment) {
|
|
98
|
-
if (relation.source.id === this.source.id || relation.target.id === this.target.id) {
|
|
99
|
-
return true
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return false
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
public *values(): IteratorLike<RelationshipModel<A> | DeploymentRelationModel<A>> {
|
|
106
|
-
yield* this.relations.model
|
|
107
|
-
yield* this.relations.deployment
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Merge with another connections, if it has the same source and target.
|
|
112
|
-
* Returns new connection with union of relationships.
|
|
113
|
-
*/
|
|
114
|
-
public mergeWith(others: DeploymentConnectionModel<A>[]): DeploymentConnectionModel<A>
|
|
115
|
-
/**
|
|
116
|
-
* Merge with another connection, if it has the same source and target.
|
|
117
|
-
* Returns new connection with union of relationships.
|
|
118
|
-
*/
|
|
119
|
-
public mergeWith(other: DeploymentConnectionModel<A>): DeploymentConnectionModel<A>
|
|
120
|
-
public mergeWith(other: DeploymentConnectionModel<A> | DeploymentConnectionModel<A>[]): DeploymentConnectionModel<A> {
|
|
121
|
-
if (Array.isArray(other)) {
|
|
122
|
-
return other.reduce((acc, o) => acc.mergeWith(o), this)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
invariant(this.source.id === other.source.id, 'Cannot merge connections with different sources')
|
|
126
|
-
invariant(this.target.id === other.target.id, 'Cannot merge connections with different targets')
|
|
127
|
-
return new DeploymentConnectionModel(
|
|
128
|
-
this.source,
|
|
129
|
-
this.target,
|
|
130
|
-
this.relations.union(other.relations),
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public difference(other: DeploymentConnectionModel<A>) {
|
|
135
|
-
return new DeploymentConnectionModel(
|
|
136
|
-
this.source,
|
|
137
|
-
this.target,
|
|
138
|
-
this.relations.difference(other.relations),
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public intersect(other: DeploymentConnectionModel<A>) {
|
|
143
|
-
return new DeploymentConnectionModel(
|
|
144
|
-
this.source,
|
|
145
|
-
this.target,
|
|
146
|
-
this.relations.intersect(other.relations),
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public equals(other: Connection): boolean {
|
|
151
|
-
invariant(other instanceof DeploymentConnectionModel, 'Other should ne DeploymentConnectionModel')
|
|
152
|
-
return this.id === other.id
|
|
153
|
-
&& this.source.id === other.source.id
|
|
154
|
-
&& this.target.id === other.target.id
|
|
155
|
-
&& equals(this.relations.model, other.relations.model)
|
|
156
|
-
&& equals(this.relations.deployment, other.relations.deployment)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Creates a clone of the current `DeploymentConnectionModel` instance with optional overrides.
|
|
161
|
-
* if `null` is provided in overrides, the corresponding relation set will be empty.
|
|
162
|
-
*/
|
|
163
|
-
public update(overrides?: {
|
|
164
|
-
model?: ReadonlySet<RelationshipModel<A>> | null
|
|
165
|
-
deployment?: ReadonlySet<DeploymentRelationModel<A>> | null
|
|
166
|
-
}): DeploymentConnectionModel<A> {
|
|
167
|
-
if (overrides) {
|
|
168
|
-
overrides = {
|
|
169
|
-
model: this.relations.model,
|
|
170
|
-
deployment: this.relations.deployment,
|
|
171
|
-
...overrides,
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return new DeploymentConnectionModel(
|
|
175
|
-
this.source,
|
|
176
|
-
this.target,
|
|
177
|
-
overrides
|
|
178
|
-
? new RelationshipsAccum(
|
|
179
|
-
overrides.model ?? new Set(),
|
|
180
|
-
overrides.deployment ?? new Set(),
|
|
181
|
-
)
|
|
182
|
-
: this.relations,
|
|
183
|
-
)
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import type { AnyAux } from '../../../types'
|
|
2
|
-
import { isSameHierarchy } from '../../../utils'
|
|
3
|
-
import type { DeploymentElementModel } from '../../DeploymentElementModel'
|
|
4
|
-
import { DeploymentConnectionModel } from './DeploymentConnectionModel'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Resolve connection from source to target
|
|
8
|
-
* If direction is `both`, also look for reverse connection
|
|
9
|
-
*
|
|
10
|
-
* @default direction directed
|
|
11
|
-
*/
|
|
12
|
-
export function findConnection<M extends AnyAux>(
|
|
13
|
-
source: DeploymentElementModel<M>,
|
|
14
|
-
target: DeploymentElementModel<NoInfer<M>>,
|
|
15
|
-
direction: 'directed',
|
|
16
|
-
):
|
|
17
|
-
| readonly [DeploymentConnectionModel<M>]
|
|
18
|
-
| readonly []
|
|
19
|
-
export function findConnection<M extends AnyAux>(
|
|
20
|
-
source: DeploymentElementModel<M>,
|
|
21
|
-
target: DeploymentElementModel<NoInfer<M>>,
|
|
22
|
-
direction: 'both',
|
|
23
|
-
):
|
|
24
|
-
| readonly [DeploymentConnectionModel<M>, DeploymentConnectionModel<M>]
|
|
25
|
-
| readonly [DeploymentConnectionModel<M>]
|
|
26
|
-
| readonly []
|
|
27
|
-
export function findConnection<M extends AnyAux>(
|
|
28
|
-
source: DeploymentElementModel<M>,
|
|
29
|
-
target: DeploymentElementModel<NoInfer<M>>,
|
|
30
|
-
direction?: 'directed' | 'both',
|
|
31
|
-
):
|
|
32
|
-
| readonly [DeploymentConnectionModel<M>, DeploymentConnectionModel<M>]
|
|
33
|
-
| readonly [DeploymentConnectionModel<M>]
|
|
34
|
-
| readonly []
|
|
35
|
-
export function findConnection<M extends AnyAux>(
|
|
36
|
-
source: DeploymentElementModel<M>,
|
|
37
|
-
target: DeploymentElementModel<NoInfer<M>>,
|
|
38
|
-
direction: 'directed' | 'both' = 'directed',
|
|
39
|
-
) {
|
|
40
|
-
if (source === target) {
|
|
41
|
-
return []
|
|
42
|
-
}
|
|
43
|
-
if (isSameHierarchy(source, target)) {
|
|
44
|
-
return []
|
|
45
|
-
}
|
|
46
|
-
const directedIntersection = source.allOutgoing.intersect(target.allIncoming)
|
|
47
|
-
|
|
48
|
-
const directed = directedIntersection.nonEmpty
|
|
49
|
-
? [
|
|
50
|
-
new DeploymentConnectionModel<M>(
|
|
51
|
-
source,
|
|
52
|
-
target,
|
|
53
|
-
directedIntersection,
|
|
54
|
-
),
|
|
55
|
-
] as const
|
|
56
|
-
: [] as const
|
|
57
|
-
|
|
58
|
-
if (direction === 'directed') {
|
|
59
|
-
return directed
|
|
60
|
-
}
|
|
61
|
-
return [
|
|
62
|
-
...directed,
|
|
63
|
-
...findConnection(target, source, 'directed'),
|
|
64
|
-
] as const
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Resolve all connections between element and others
|
|
69
|
-
* By default, look for both directions.
|
|
70
|
-
*
|
|
71
|
-
* @default direction both
|
|
72
|
-
*/
|
|
73
|
-
export function findConnectionsBetween<M extends AnyAux>(
|
|
74
|
-
element: DeploymentElementModel<M>,
|
|
75
|
-
others: Iterable<DeploymentElementModel<NoInfer<M>>>,
|
|
76
|
-
direction: 'directed' | 'both' = 'both',
|
|
77
|
-
): readonly DeploymentConnectionModel<M>[] {
|
|
78
|
-
if (element.allIncoming.isEmpty && element.allOutgoing.isEmpty) {
|
|
79
|
-
return []
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// We separate resolved connection,
|
|
83
|
-
// because we want return outgoing first
|
|
84
|
-
const outgoing = [] as DeploymentConnectionModel<M>[]
|
|
85
|
-
const incoming = [] as DeploymentConnectionModel<M>[]
|
|
86
|
-
for (const _other of others) {
|
|
87
|
-
if (element === _other) {
|
|
88
|
-
continue
|
|
89
|
-
}
|
|
90
|
-
for (const found of findConnection(element, _other, direction)) {
|
|
91
|
-
if (found.source === element) {
|
|
92
|
-
outgoing.push(found)
|
|
93
|
-
} else {
|
|
94
|
-
incoming.push(found)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return [
|
|
99
|
-
...outgoing,
|
|
100
|
-
...incoming,
|
|
101
|
-
]
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Resolve all connections within a given set of elements
|
|
106
|
-
*/
|
|
107
|
-
export function findConnectionsWithin<M extends AnyAux>(
|
|
108
|
-
elements: Iterable<DeploymentElementModel<M>>,
|
|
109
|
-
): readonly DeploymentConnectionModel<M>[] {
|
|
110
|
-
return [...elements].reduce((acc, el, index, array) => {
|
|
111
|
-
// skip for last element
|
|
112
|
-
if (index === array.length - 1) {
|
|
113
|
-
return acc
|
|
114
|
-
}
|
|
115
|
-
acc.push(
|
|
116
|
-
...findConnectionsBetween(el, array.slice(index + 1), 'both'),
|
|
117
|
-
)
|
|
118
|
-
return acc
|
|
119
|
-
}, [] as DeploymentConnectionModel<M>[])
|
|
120
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export { Connection } from './Connection'
|
|
2
|
-
export { DeploymentConnectionModel } from './deployment/DeploymentConnectionModel'
|
|
3
|
-
export { ConnectionModel } from './model/ConnectionModel'
|
|
4
|
-
export {
|
|
5
|
-
differenceConnections,
|
|
6
|
-
findAscendingConnections,
|
|
7
|
-
findDeepestNestedConnection,
|
|
8
|
-
findDescendantConnections,
|
|
9
|
-
hasSameSource,
|
|
10
|
-
hasSameSourceTarget,
|
|
11
|
-
hasSameTarget,
|
|
12
|
-
isAnyInOut,
|
|
13
|
-
isIncoming,
|
|
14
|
-
isNestedConnection,
|
|
15
|
-
isOutgoing,
|
|
16
|
-
mergeConnections,
|
|
17
|
-
sortConnectionsByBoundaryHierarchy,
|
|
18
|
-
sortDeepestFirst,
|
|
19
|
-
} from './ops'
|
|
20
|
-
|
|
21
|
-
export * as deployment from './deployment/find'
|
|
22
|
-
export * as model from './model/find'
|