@likec4/core 1.17.0 → 1.18.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/dist/compute-view/index.d.mts +91 -0
- package/dist/compute-view/index.d.ts +91 -0
- package/dist/compute-view/index.mjs +79 -0
- package/dist/index.d.mts +248 -435
- package/dist/index.d.ts +248 -435
- package/dist/index.mjs +418 -1322
- package/dist/model/index.d.mts +642 -0
- package/dist/model/index.d.ts +642 -0
- package/dist/model/index.mjs +2 -0
- package/dist/shared/core.BBgiAAv1.mjs +144 -0
- package/dist/shared/core.BPyJvuMU.mjs +2420 -0
- package/dist/shared/core.BQ4AbfvB.mjs +9228 -0
- package/dist/shared/{core.CoLQkcYL.d.ts → core.DMYY7C8s.d.mts} +398 -249
- package/dist/shared/{core.CoLQkcYL.d.cts → core.DMYY7C8s.d.ts} +398 -249
- package/dist/shared/core.k12s_keD.mjs +203 -0
- package/dist/types/index.d.mts +69 -1
- package/dist/types/index.d.ts +69 -1
- package/dist/types/index.mjs +21 -1
- package/package.json +40 -42
- package/src/builder/Builder.deployment.ts +219 -0
- package/src/builder/Builder.deploymentModel.ts +360 -0
- package/src/builder/Builder.element.ts +17 -19
- package/src/builder/Builder.model.ts +13 -2
- package/src/builder/Builder.test-d.ts +59 -4
- package/src/builder/Builder.ts +238 -53
- package/src/builder/Builder.view.ts +238 -53
- package/src/builder/_types.ts +87 -15
- package/src/compute-view/LikeC4ModelGraph.ts +330 -0
- package/src/compute-view/compute-view.ts +92 -0
- package/src/compute-view/deployment-view/Memory.ts +108 -0
- package/src/compute-view/deployment-view/Stage.ts +145 -0
- package/src/compute-view/deployment-view/__test__/fixture.ts +210 -0
- package/src/compute-view/deployment-view/_types.ts +29 -0
- package/src/compute-view/deployment-view/clean-connections.ts +229 -0
- package/src/compute-view/deployment-view/compute.ts +111 -0
- package/src/compute-view/deployment-view/predicates/deployment-ref.ts +146 -0
- package/src/compute-view/deployment-view/predicates/relation-direct.ts +130 -0
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +43 -0
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +46 -0
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +49 -0
- package/src/compute-view/deployment-view/predicates/wildcard.ts +29 -0
- package/src/compute-view/deployment-view/utils.ts +212 -0
- package/src/compute-view/dynamic-view/__test__/fixture.ts +58 -0
- package/src/compute-view/dynamic-view/compute.ts +310 -0
- package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +456 -0
- package/src/compute-view/element-view/__test__/fixture.ts +645 -0
- package/src/compute-view/element-view/compute.ts +734 -0
- package/src/compute-view/element-view/predicates.ts +517 -0
- package/src/compute-view/index.ts +5 -0
- package/src/compute-view/utils/__snapshots__/sortNodes.spec.ts.snap +113 -0
- package/src/compute-view/utils/ancestorsOfNode.ts +19 -0
- package/src/compute-view/utils/applyCustomElementProperties.ts +66 -0
- package/src/compute-view/utils/applyCustomRelationProperties.ts +41 -0
- package/src/compute-view/utils/applyViewRuleStyles.ts +53 -0
- package/src/compute-view/utils/buildComputedNodes.ts +148 -0
- package/src/compute-view/utils/buildElementNotations.ts +63 -0
- package/src/compute-view/utils/derive-edge-props-from-relationships.ts +97 -0
- package/src/compute-view/utils/elementExpressionToPredicate.ts +52 -0
- package/src/compute-view/utils/link-nodes-with-edges.ts +58 -0
- package/src/compute-view/utils/relationExpressionToPredicates.ts +55 -0
- package/src/compute-view/utils/resolve-extended-views.ts +65 -0
- package/src/compute-view/utils/resolve-global-rules.ts +83 -0
- package/src/compute-view/utils/sortNodes.ts +101 -0
- package/src/compute-view/utils/topological-sort.ts +160 -0
- package/src/compute-view/utils/uniqueTags.test.ts +42 -0
- package/src/compute-view/utils/uniqueTags.ts +21 -0
- package/src/compute-view/utils/view-hash.ts +27 -0
- package/src/compute-view/utils/with-readable-edges.ts +31 -0
- package/src/index.ts +5 -1
- package/src/model/DeploymentElementModel.ts +534 -0
- package/src/model/DeploymentModel.ts +364 -0
- package/src/model/ElementModel.ts +195 -0
- package/src/model/LikeC4Model.test-d.ts +151 -0
- package/src/model/LikeC4Model.ts +280 -457
- package/src/model/RelationModel.ts +84 -0
- package/src/model/__test__/fixture.ts +153 -338
- package/src/model/connection/ConnectionModel.ts +94 -0
- package/src/model/connection/DeploymentConnectionModel.ts +99 -0
- package/src/model/connection/deployment.ts +124 -0
- package/src/model/connection/model.ts +123 -0
- package/src/model/index.ts +4 -2
- package/src/model/types.ts +95 -15
- package/src/model/view/EdgeModel.ts +103 -0
- package/src/model/view/LikeC4ViewModel.ts +220 -0
- package/src/model/view/NodeModel.ts +228 -0
- package/src/types/_common.ts +2 -0
- package/src/types/deployments.ts +237 -0
- package/src/types/element.ts +7 -3
- package/src/types/expression.ts +8 -6
- package/src/types/index.ts +1 -0
- package/src/types/model.ts +68 -9
- package/src/types/overview-graph.ts +2 -2
- package/src/types/relation.ts +4 -4
- package/src/types/view-notation.ts +2 -2
- package/src/types/view.ts +104 -30
- package/src/utils/{commonHead.ts → common-head.ts} +2 -0
- package/src/utils/fqn.ts +83 -27
- package/src/utils/getOrCreate.ts +42 -0
- package/src/utils/graphlib.ts +10 -0
- package/src/utils/index.ts +4 -1
- package/src/utils/object-hash.ts +3 -0
- package/src/utils/set.ts +76 -0
- package/src/utils/string-hash.ts +16 -0
- package/dist/index.cjs +0 -5452
- package/dist/index.d.cts +0 -1052
- package/dist/shared/core.CoLQkcYL.d.mts +0 -734
- package/dist/shared/core.v5DxGcX6.mjs +0 -293
- package/dist/shared/core.zN6ZscFQ.cjs +0 -353
- package/dist/types/index.cjs +0 -70
- package/dist/types/index.d.cts +0 -2
- package/src/model/LikeC4DiagramModel.ts +0 -338
- package/src/model/LikeC4ViewModel.ts +0 -320
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { isNullish } from 'remeda'
|
|
2
|
-
import { nonNullable } from '../errors'
|
|
3
|
-
import {
|
|
4
|
-
type ElementKind as C4ElementKind,
|
|
5
|
-
type ElementShape as C4ElementShape,
|
|
6
|
-
type Tag as C4Tag
|
|
7
|
-
} from '../types/element'
|
|
8
|
-
import type { Color as C4Color } from '../types/theme'
|
|
9
|
-
import type { ComputedEdge, ComputedNode, ComputedView } from '../types/view'
|
|
10
|
-
import type { LikeC4Model } from './LikeC4Model'
|
|
11
|
-
import { type EdgeId, type ElementOrFqn, type Fqn, getId, type IncomingFilter, type OutgoingFilter } from './types'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* All methods are view-scoped, i.e. only return elements and connections in the view.
|
|
15
|
-
*/
|
|
16
|
-
export class LikeC4ViewModel {
|
|
17
|
-
private readonly _rootElements = new Set<LikeC4ViewModel.Element>()
|
|
18
|
-
|
|
19
|
-
private readonly _elements = new Map<Fqn, LikeC4ViewModel.Element>()
|
|
20
|
-
|
|
21
|
-
private readonly _connections: Map<EdgeId, LikeC4ViewModel.Connection>
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
public readonly view: ComputedView,
|
|
25
|
-
public readonly model: LikeC4Model<LikeC4ViewModel>
|
|
26
|
-
) {
|
|
27
|
-
for (const node of view.nodes) {
|
|
28
|
-
const el = new LikeC4ViewModel.Element(node, this)
|
|
29
|
-
this._elements.set(node.id, el)
|
|
30
|
-
if (isNullish(node.parent)) {
|
|
31
|
-
this._rootElements.add(el)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
this._connections = new Map(view.edges.map(e => [e.id, new LikeC4ViewModel.Connection(e, this)]))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get id() {
|
|
38
|
-
return this.view.id
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get title() {
|
|
42
|
-
return this.view.title
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get viewOf() {
|
|
46
|
-
if (this.view.__ !== 'dynamic') {
|
|
47
|
-
return this.view.viewOf ? this.model.element(this.view.viewOf) : null
|
|
48
|
-
}
|
|
49
|
-
return null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get tags(): C4Tag[] {
|
|
53
|
-
return this.view.tags ?? []
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public roots(): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
57
|
-
return [...this._rootElements]
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public elements(): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
61
|
-
return [...this._elements.values()]
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public element(id: Fqn): LikeC4ViewModel.Element {
|
|
65
|
-
return nonNullable(this._elements.get(id), `LikeC4ViewModel.Element ${id} in view ${this.id} not found`)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public hasElement(id: Fqn): boolean {
|
|
69
|
-
return this._elements.has(id)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public connections(): ReadonlyArray<LikeC4ViewModel.Connection> {
|
|
73
|
-
return [...this._connections.values()]
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public connection(id: EdgeId): LikeC4ViewModel.Connection {
|
|
77
|
-
return nonNullable(this._connections.get(id), `Connection ${id} in view ${this.id} not found`)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public findConnections(
|
|
81
|
-
source: ElementOrFqn,
|
|
82
|
-
target: ElementOrFqn,
|
|
83
|
-
direction: 'both' | 'direct' = 'direct'
|
|
84
|
-
): ReadonlyArray<LikeC4ViewModel.Connection> {
|
|
85
|
-
const sourceId = getId(source)
|
|
86
|
-
const targetId = getId(target)
|
|
87
|
-
return this.connections().filter(c =>
|
|
88
|
-
(c.source.id === sourceId && c.target.id === targetId)
|
|
89
|
-
|| (direction === 'both' && c.source.id === targetId && c.target.id === sourceId)
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public parent(element: ElementOrFqn): LikeC4ViewModel.Element | null {
|
|
94
|
-
const el = this.element(getId(element))
|
|
95
|
-
return el.node.parent ? this.element(el.node.parent) : null
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public children(element: ElementOrFqn): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
99
|
-
const el = this.element(getId(element))
|
|
100
|
-
return el.node.children.map(c => this.element(c))
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Get all sibling (i.e. same parent)
|
|
104
|
-
public siblings(element: ElementOrFqn): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
105
|
-
const id = getId(element)
|
|
106
|
-
const parent = this.parent(id)
|
|
107
|
-
const siblings = parent ? this.children(parent) : this.roots()
|
|
108
|
-
return siblings.filter(e => e.id !== id)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Get all ancestor elements (i.e. parent, parent’s parent, etc.)
|
|
113
|
-
* (from closest to root)
|
|
114
|
-
*/
|
|
115
|
-
public ancestors(element: ElementOrFqn): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
116
|
-
let id = getId(element)
|
|
117
|
-
const result = [] as LikeC4ViewModel.Element[]
|
|
118
|
-
let parent
|
|
119
|
-
while (parent = this.parent(id)) {
|
|
120
|
-
result.push(parent)
|
|
121
|
-
id = parent.id
|
|
122
|
-
}
|
|
123
|
-
return result
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public descendants(element: ElementOrFqn): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
127
|
-
const children = this.children(element)
|
|
128
|
-
return children.flatMap(c => [c, ...this.descendants(c.id)])
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public incoming(
|
|
132
|
-
element: ElementOrFqn,
|
|
133
|
-
filter: IncomingFilter = 'all'
|
|
134
|
-
): ReadonlyArray<LikeC4ViewModel.Connection> {
|
|
135
|
-
const el = this.element(getId(element))
|
|
136
|
-
const edges = el.node.inEdges.map(e => nonNullable(this._connections.get(e), `Edge ${e} not found`))
|
|
137
|
-
|
|
138
|
-
if (filter === 'all' || edges.length === 0) {
|
|
139
|
-
return edges
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return edges.filter(rel => {
|
|
143
|
-
if (filter === 'direct') {
|
|
144
|
-
return rel.target.id === el.id
|
|
145
|
-
}
|
|
146
|
-
return rel.target.id !== el.id
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public incomers(
|
|
151
|
-
element: ElementOrFqn,
|
|
152
|
-
filter: IncomingFilter = 'all'
|
|
153
|
-
): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
154
|
-
return [...new Set(this.incoming(element, filter).map(r => r.source))]
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Outgoing relationships from the element and its descendants
|
|
159
|
-
*/
|
|
160
|
-
public outgoing(
|
|
161
|
-
element: ElementOrFqn,
|
|
162
|
-
filter: OutgoingFilter = 'all'
|
|
163
|
-
): ReadonlyArray<LikeC4ViewModel.Connection> {
|
|
164
|
-
const el = this.element(getId(element))
|
|
165
|
-
const edges = el.node.outEdges.map(e => nonNullable(this._connections.get(e), `Edge ${e} not found`))
|
|
166
|
-
|
|
167
|
-
if (filter === 'all' || edges.length === 0) {
|
|
168
|
-
return edges
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return edges.filter(rel => {
|
|
172
|
-
if (filter === 'direct') {
|
|
173
|
-
return rel.source.id === el.id
|
|
174
|
-
}
|
|
175
|
-
return rel.source.id !== el.id
|
|
176
|
-
})
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public outgoers(
|
|
180
|
-
element: ElementOrFqn,
|
|
181
|
-
filter: OutgoingFilter = 'all'
|
|
182
|
-
): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
183
|
-
return [...new Set(this.outgoing(element, filter).map(r => r.target))]
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export namespace LikeC4ViewModel {
|
|
188
|
-
/**
|
|
189
|
-
* Represents an element in the view. (Diagram node)
|
|
190
|
-
* All methods are view-scoped, i.e. `children` returns only children of the element in the view.
|
|
191
|
-
*/
|
|
192
|
-
export class Element {
|
|
193
|
-
constructor(
|
|
194
|
-
public readonly node: ComputedNode,
|
|
195
|
-
private readonly viewmodel: LikeC4ViewModel
|
|
196
|
-
) {
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
get id() {
|
|
200
|
-
return this.node.id
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
get title() {
|
|
204
|
-
return this.node.title
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
get kind(): C4ElementKind {
|
|
208
|
-
return this.node.kind
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
get isRoot(): boolean {
|
|
212
|
-
return isNullish(this.node.parent)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
get hasNested(): boolean {
|
|
216
|
-
return this.node.children.length > 0
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
get shape(): C4ElementShape {
|
|
220
|
-
return this.node.shape
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
get color(): C4Color {
|
|
224
|
-
return this.node.color
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
get tags(): C4Tag[] {
|
|
228
|
-
return this.node.tags ?? []
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
public model(): LikeC4Model.ElementModel<LikeC4ViewModel> {
|
|
232
|
-
return this.viewmodel.model.element(this.id)
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
public parent(): LikeC4ViewModel.Element | null {
|
|
236
|
-
return this.node.parent ? this.viewmodel.element(this.node.parent) : null
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
public metadata(key: string): string | undefined
|
|
240
|
-
public metadata(key: string, defaultValue: string): string
|
|
241
|
-
public metadata(key: string, defaultValue?: string): string | undefined {
|
|
242
|
-
return this.model().metadata(key) ?? defaultValue
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
public hasMetadata(key: string): boolean {
|
|
246
|
-
return this.model().hasMetadata(key)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
public ancestors(): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
250
|
-
return this.viewmodel.ancestors(this)
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
public siblings(): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
254
|
-
return this.viewmodel.siblings(this)
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
public descendants(): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
258
|
-
return this.viewmodel.descendants(this)
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
public children(): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
262
|
-
return this.viewmodel.children(this)
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
public incoming(filter: 'all' | 'direct' | 'to-descendants' = 'all'): ReadonlyArray<LikeC4ViewModel.Connection> {
|
|
266
|
-
return this.viewmodel.incoming(this, filter)
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
public incomers(filter: 'all' | 'direct' | 'to-descendants' = 'all'): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
270
|
-
return this.viewmodel.incomers(this, filter)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
public outgoing(filter: OutgoingFilter = 'all'): ReadonlyArray<LikeC4ViewModel.Connection> {
|
|
274
|
-
return this.viewmodel.outgoing(this, filter)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
public outgoers(filter: OutgoingFilter = 'all'): ReadonlyArray<LikeC4ViewModel.Element> {
|
|
278
|
-
return this.viewmodel.outgoers(this, filter)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
public connectionsTo(target: Fqn | LikeC4ViewModel.Element): ReadonlyArray<LikeC4ViewModel.Connection> {
|
|
282
|
-
return this.viewmodel.findConnections(this, target)
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Represents a connection between two elements.
|
|
288
|
-
* May be source from multiple model relationships.
|
|
289
|
-
*/
|
|
290
|
-
export class Connection {
|
|
291
|
-
constructor(
|
|
292
|
-
public readonly edge: ComputedEdge,
|
|
293
|
-
private readonly viewmodel: LikeC4ViewModel
|
|
294
|
-
) {
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
get id() {
|
|
298
|
-
return this.edge.id
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
get source(): LikeC4ViewModel.Element {
|
|
302
|
-
return this.viewmodel.element(this.edge.source)
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
get target(): LikeC4ViewModel.Element {
|
|
306
|
-
return this.viewmodel.element(this.edge.target)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
get tags(): C4Tag[] {
|
|
310
|
-
return this.edge.tags ?? []
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Model relationships
|
|
315
|
-
*/
|
|
316
|
-
relationships(): ReadonlyArray<LikeC4Model.Relationship<LikeC4ViewModel>> {
|
|
317
|
-
return this.edge.relations.map(r => nonNullable(this.viewmodel.model.relationship(r)))
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|