@likec4/core 1.17.1 → 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 +246 -434
- package/dist/index.d.ts +246 -434
- 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.mts → core.DMYY7C8s.d.mts} +398 -249
- package/dist/shared/{core.CoLQkcYL.d.ts → 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 +38 -40
- 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 -1053
- package/dist/shared/core.BXTs-8n7.mjs +0 -293
- package/dist/shared/core.CoLQkcYL.d.cts +0 -734
- package/dist/shared/core.DIYZvpVg.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,10 +1,14 @@
|
|
|
1
1
|
import { isArray, isString, map } from 'remeda'
|
|
2
|
-
import type { LiteralUnion, Simplify, Tagged } from 'type-fest'
|
|
2
|
+
import type { LiteralUnion, Simplify, Tagged, Writable } from 'type-fest'
|
|
3
3
|
import {
|
|
4
4
|
type AutoLayoutDirection,
|
|
5
5
|
type CustomElementExpr,
|
|
6
6
|
type CustomRelationExpr,
|
|
7
|
+
type DeploymentElementExpression,
|
|
8
|
+
type DeploymentExpression,
|
|
9
|
+
type DeploymentView,
|
|
7
10
|
type ElementExpression as C4ElementExpression,
|
|
11
|
+
type ElementView,
|
|
8
12
|
type Expression as C4Expression,
|
|
9
13
|
type Fqn,
|
|
10
14
|
isElementPredicateExpr,
|
|
@@ -15,25 +19,58 @@ import {
|
|
|
15
19
|
import type { AnyTypes, Types } from './_types'
|
|
16
20
|
import type { views, ViewsBuilder as Builder } from './Builder.views'
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
interface AViewBuilder<
|
|
23
|
+
Types extends AnyTypes,
|
|
24
|
+
Fqn extends string,
|
|
25
|
+
TypedExpr,
|
|
26
|
+
ElementExpr extends string = ViewPredicate.ElementExpr<Fqn>,
|
|
27
|
+
Expr extends string = ViewPredicate.AllExpression<ElementExpr>
|
|
28
|
+
> {
|
|
29
|
+
Types: Types
|
|
30
|
+
ElementExpr: ElementExpr
|
|
31
|
+
Expr: Expr
|
|
32
|
+
TypedExpr: TypedExpr
|
|
33
|
+
$expr(expr: Expr | TypedExpr): TypedExpr
|
|
34
|
+
include(...exprs: Expr[]): this
|
|
35
|
+
exclude(...exprs: Expr[]): this
|
|
36
|
+
style(rule: ViewRuleStyle): this
|
|
37
|
+
autoLayout(layout: AutoLayoutDirection): this
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ViewBuilder<T extends AnyTypes> extends AViewBuilder<T, T['Fqn'], C4Expression> {
|
|
41
|
+
$expr(expr: ViewPredicate.Expression<T> | C4Expression): TypedC4Expression<T>
|
|
42
|
+
include(...exprs: C4Expression[]): this
|
|
43
|
+
exclude(...exprs: C4Expression[]): this
|
|
44
|
+
style(rule: ViewRuleStyle): this
|
|
45
|
+
autoLayout(layout: AutoLayoutDirection): this
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface DeploymentViewBuilder<T extends AnyTypes>
|
|
49
|
+
extends AViewBuilder<T, T['DeploymentFqn'], DeploymentExpression>
|
|
50
|
+
{
|
|
51
|
+
$expr(expr: ViewPredicate.DeploymentExpression<T> | DeploymentExpression): TypedDeploymentExpression<T>
|
|
52
|
+
include(...exprs: DeploymentExpression[]): this
|
|
53
|
+
exclude(...exprs: DeploymentExpression[]): this
|
|
54
|
+
style(rule: ViewRuleStyle): this
|
|
55
|
+
autoLayout(layout: AutoLayoutDirection): this
|
|
23
56
|
}
|
|
24
57
|
|
|
25
58
|
export namespace ViewPredicate {
|
|
26
|
-
export type ElementExpr<Fqn extends string> = '*' | Fqn | `${Fqn}.*` | `${Fqn}._`
|
|
59
|
+
export type ElementExpr<Fqn extends string> = '*' | Fqn | `${Fqn}.*` | `${Fqn}._` | `${Fqn}.**`
|
|
27
60
|
|
|
28
|
-
type AllExpression<ElementExpr extends string> =
|
|
61
|
+
export type AllExpression<ElementExpr extends string> =
|
|
29
62
|
| ElementExpr
|
|
30
63
|
| `-> ${ElementExpr} ->`
|
|
31
64
|
| `-> ${ElementExpr}`
|
|
32
65
|
| `${ElementExpr} ->`
|
|
33
66
|
| `${ElementExpr} ${'->' | '<->'} ${ElementExpr}`
|
|
34
67
|
|
|
35
|
-
export type Expression<T extends AnyTypes> = T extends
|
|
36
|
-
? AllExpression<ViewPredicate.ElementExpr<F>>
|
|
68
|
+
export type Expression<T extends AnyTypes> = T extends
|
|
69
|
+
Types<any, infer F extends string, any, any, any, any, any, any> ? AllExpression<ViewPredicate.ElementExpr<F>>
|
|
70
|
+
: never
|
|
71
|
+
|
|
72
|
+
export type DeploymentExpression<T extends AnyTypes> = T extends
|
|
73
|
+
Types<any, any, any, any, any, any, any, infer F extends string> ? AllExpression<ViewPredicate.ElementExpr<F>>
|
|
37
74
|
: never
|
|
38
75
|
|
|
39
76
|
export type WhereTag<Tag extends string> = `tag ${'is' | 'is not'} #${Tag}`
|
|
@@ -67,7 +104,11 @@ export namespace ViewPredicate {
|
|
|
67
104
|
}
|
|
68
105
|
}
|
|
69
106
|
|
|
107
|
+
type Op<T> = (b: T) => T
|
|
70
108
|
export type ViewRuleBuilderOp<Types extends AnyTypes> = (b: ViewBuilder<Types>) => ViewBuilder<Types>
|
|
109
|
+
export type DeploymentViewRuleBuilderOp<Types extends AnyTypes> = (
|
|
110
|
+
b: DeploymentViewBuilder<Types>
|
|
111
|
+
) => DeploymentViewBuilder<Types>
|
|
71
112
|
|
|
72
113
|
export interface AddViewHelper<Props = unknown> {
|
|
73
114
|
// <
|
|
@@ -145,8 +186,28 @@ export interface AddViewOfHelper<Props = unknown> {
|
|
|
145
186
|
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
146
187
|
}
|
|
147
188
|
|
|
189
|
+
export interface AddDeploymentViewHelper<Props = unknown> {
|
|
190
|
+
<
|
|
191
|
+
const Id extends string,
|
|
192
|
+
T extends AnyTypes
|
|
193
|
+
>(
|
|
194
|
+
id: Id,
|
|
195
|
+
builder: DeploymentViewRuleBuilderOp<T>
|
|
196
|
+
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
197
|
+
|
|
198
|
+
<
|
|
199
|
+
const Id extends string,
|
|
200
|
+
T extends AnyTypes
|
|
201
|
+
>(
|
|
202
|
+
id: Id,
|
|
203
|
+
propsOrTitle: Props | string | undefined,
|
|
204
|
+
builder: DeploymentViewRuleBuilderOp<T>
|
|
205
|
+
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
206
|
+
}
|
|
207
|
+
|
|
148
208
|
// To hook types
|
|
149
209
|
type TypedC4Expression<Types extends AnyTypes> = Tagged<C4Expression, 'typed', Types>
|
|
210
|
+
type TypedDeploymentExpression<Types extends AnyTypes> = Tagged<DeploymentExpression, 'typed', Types>
|
|
150
211
|
|
|
151
212
|
function parseWhere(where: ViewPredicate.WhereOperator<AnyTypes>): WhereOperator<any, any> {
|
|
152
213
|
if (isString(where)) {
|
|
@@ -200,15 +261,13 @@ function parseWhere(where: ViewPredicate.WhereOperator<AnyTypes>): WhereOperator
|
|
|
200
261
|
throw new Error(`Unknown where operator: ${where}`)
|
|
201
262
|
}
|
|
202
263
|
|
|
203
|
-
function $include<
|
|
264
|
+
function $include<B extends AViewBuilder<AnyTypes, any, any>>(
|
|
204
265
|
...args:
|
|
205
|
-
| [
|
|
206
|
-
| [
|
|
207
|
-
|
|
208
|
-
): (b: ViewBuilder<Types>) => ViewBuilder<Types> {
|
|
266
|
+
| [B['Expr']]
|
|
267
|
+
| [B['Expr'], ViewPredicate.Custom<B['Types']>]
|
|
268
|
+
): (b: B) => B {
|
|
209
269
|
return (b) => {
|
|
210
|
-
let expr =
|
|
211
|
-
const isElement = isElementPredicateExpr(expr)
|
|
270
|
+
let expr = b.$expr(args[0])
|
|
212
271
|
if (args.length === 2) {
|
|
213
272
|
const condition = args[1].where ? parseWhere(args[1].where) : undefined
|
|
214
273
|
if (condition) {
|
|
@@ -222,6 +281,7 @@ function $include<Types extends AnyTypes>(
|
|
|
222
281
|
|
|
223
282
|
const custom = args[1].with
|
|
224
283
|
if (custom) {
|
|
284
|
+
const isElement = isElementPredicateExpr(expr)
|
|
225
285
|
if (isElement) {
|
|
226
286
|
expr = {
|
|
227
287
|
custom: {
|
|
@@ -239,19 +299,18 @@ function $include<Types extends AnyTypes>(
|
|
|
239
299
|
}
|
|
240
300
|
}
|
|
241
301
|
}
|
|
242
|
-
b.include(expr)
|
|
302
|
+
b.include(expr as any)
|
|
243
303
|
return b
|
|
244
304
|
}
|
|
245
305
|
}
|
|
246
306
|
|
|
247
|
-
function $exclude<
|
|
307
|
+
function $exclude<B extends AViewBuilder<AnyTypes, any, any>>(
|
|
248
308
|
...args:
|
|
249
|
-
| [
|
|
250
|
-
| [
|
|
251
|
-
|
|
252
|
-
): (b: ViewBuilder<Types>) => ViewBuilder<Types> {
|
|
309
|
+
| [B['Expr']]
|
|
310
|
+
| [B['Expr'], ViewPredicate.Custom<B['Types']>]
|
|
311
|
+
): (b: B) => B {
|
|
253
312
|
return (b) => {
|
|
254
|
-
let expr =
|
|
313
|
+
let expr = b.$expr(args[0]) as C4Expression
|
|
255
314
|
if (args.length === 2 && args[1].where) {
|
|
256
315
|
const condition = parseWhere(args[1].where)
|
|
257
316
|
expr = {
|
|
@@ -266,93 +325,219 @@ function $exclude<Types extends AnyTypes>(
|
|
|
266
325
|
}
|
|
267
326
|
}
|
|
268
327
|
|
|
328
|
+
const asTypedExpr = <Types extends AnyTypes>(expr: C4Expression): TypedC4Expression<Types> => {
|
|
329
|
+
return expr as TypedC4Expression<Types>
|
|
330
|
+
}
|
|
269
331
|
function $expr<Types extends AnyTypes>(expr: ViewPredicate.Expression<Types> | C4Expression): TypedC4Expression<Types> {
|
|
270
332
|
if (!isString(expr)) {
|
|
271
333
|
return expr as TypedC4Expression<Types>
|
|
272
334
|
}
|
|
273
335
|
if (expr === '*') {
|
|
274
|
-
return { wildcard: true }
|
|
336
|
+
return asTypedExpr({ wildcard: true })
|
|
275
337
|
}
|
|
276
338
|
if (expr.startsWith('->')) {
|
|
277
339
|
if (expr.endsWith('->')) {
|
|
278
|
-
return {
|
|
340
|
+
return asTypedExpr({
|
|
279
341
|
inout: $expr(expr.replace(/->/g, '').trim()) as any
|
|
280
|
-
}
|
|
342
|
+
})
|
|
281
343
|
}
|
|
282
|
-
return {
|
|
344
|
+
return asTypedExpr({
|
|
283
345
|
incoming: $expr(expr.replace('-> ', '')) as any
|
|
284
|
-
}
|
|
346
|
+
})
|
|
285
347
|
}
|
|
286
348
|
if (expr.endsWith(' ->')) {
|
|
287
|
-
return {
|
|
349
|
+
return asTypedExpr({
|
|
288
350
|
outgoing: $expr(expr.replace(' ->', '')) as any
|
|
289
|
-
}
|
|
351
|
+
})
|
|
290
352
|
}
|
|
291
353
|
if (expr.includes(' <-> ')) {
|
|
292
354
|
const [source, target] = expr.split(' <-> ')
|
|
293
|
-
return {
|
|
355
|
+
return asTypedExpr({
|
|
294
356
|
source: $expr(source) as any,
|
|
295
357
|
target: $expr(target) as any,
|
|
296
358
|
isBidirectional: true
|
|
297
|
-
}
|
|
359
|
+
})
|
|
298
360
|
}
|
|
299
361
|
if (expr.includes(' -> ')) {
|
|
300
362
|
const [source, target] = expr.split(' -> ')
|
|
301
|
-
return {
|
|
363
|
+
return asTypedExpr({
|
|
302
364
|
source: $expr(source) as any,
|
|
303
365
|
target: $expr(target) as any
|
|
304
|
-
}
|
|
366
|
+
})
|
|
305
367
|
}
|
|
306
368
|
if (expr.endsWith('._')) {
|
|
307
|
-
return {
|
|
369
|
+
return asTypedExpr({
|
|
308
370
|
expanded: expr.replace('._', '') as Fqn
|
|
309
|
-
}
|
|
371
|
+
})
|
|
310
372
|
}
|
|
311
373
|
if (expr.endsWith('.*')) {
|
|
312
|
-
return {
|
|
374
|
+
return asTypedExpr({
|
|
313
375
|
element: expr.replace('.*', '') as Fqn,
|
|
314
|
-
|
|
315
|
-
}
|
|
376
|
+
isChildren: true
|
|
377
|
+
})
|
|
378
|
+
}
|
|
379
|
+
if (expr.endsWith('.**')) {
|
|
380
|
+
return asTypedExpr({
|
|
381
|
+
element: expr.replace('.**', '') as Fqn,
|
|
382
|
+
isDescendants: true
|
|
383
|
+
})
|
|
316
384
|
}
|
|
317
|
-
return {
|
|
318
|
-
element: expr as any as Fqn
|
|
319
|
-
|
|
320
|
-
} as TypedC4Expression<Types>
|
|
385
|
+
return asTypedExpr({
|
|
386
|
+
element: expr as any as Fqn
|
|
387
|
+
})
|
|
321
388
|
}
|
|
322
389
|
|
|
323
|
-
|
|
324
|
-
|
|
390
|
+
const asTypedDeploymentExpression = <Types extends AnyTypes>(
|
|
391
|
+
expr: DeploymentExpression
|
|
392
|
+
): TypedDeploymentExpression<Types> => {
|
|
393
|
+
return expr as TypedDeploymentExpression<Types>
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function $deploymentExpr<Types extends AnyTypes>(
|
|
397
|
+
expr: ViewPredicate.DeploymentExpression<Types> | DeploymentExpression
|
|
398
|
+
): TypedDeploymentExpression<Types> {
|
|
399
|
+
if (!isString(expr)) {
|
|
400
|
+
return expr as TypedDeploymentExpression<Types>
|
|
401
|
+
}
|
|
402
|
+
if (expr === '*') {
|
|
403
|
+
return asTypedDeploymentExpression({ wildcard: true })
|
|
404
|
+
}
|
|
405
|
+
if (expr.startsWith('->')) {
|
|
406
|
+
if (expr.endsWith('->')) {
|
|
407
|
+
return asTypedDeploymentExpression({
|
|
408
|
+
inout: $deploymentExpr(expr.replace(/->/g, '').trim()) as any
|
|
409
|
+
})
|
|
410
|
+
}
|
|
411
|
+
return asTypedDeploymentExpression({
|
|
412
|
+
incoming: $deploymentExpr(expr.replace('-> ', '')) as any
|
|
413
|
+
})
|
|
414
|
+
}
|
|
415
|
+
if (expr.endsWith(' ->')) {
|
|
416
|
+
return asTypedDeploymentExpression({
|
|
417
|
+
outgoing: $deploymentExpr(expr.replace(' ->', '')) as any
|
|
418
|
+
})
|
|
419
|
+
}
|
|
420
|
+
if (expr.includes(' <-> ')) {
|
|
421
|
+
const [source, target] = expr.split(' <-> ')
|
|
422
|
+
return asTypedDeploymentExpression({
|
|
423
|
+
source: $deploymentExpr(source) as DeploymentElementExpression,
|
|
424
|
+
target: $deploymentExpr(target) as DeploymentElementExpression,
|
|
425
|
+
isBidirectional: true
|
|
426
|
+
})
|
|
427
|
+
}
|
|
428
|
+
if (expr.includes(' -> ')) {
|
|
429
|
+
const [source, target] = expr.split(' -> ')
|
|
430
|
+
return asTypedDeploymentExpression({
|
|
431
|
+
source: $deploymentExpr(source) as DeploymentElementExpression,
|
|
432
|
+
target: $deploymentExpr(target) as DeploymentElementExpression
|
|
433
|
+
})
|
|
434
|
+
}
|
|
435
|
+
if (expr.endsWith('._')) {
|
|
436
|
+
return asTypedDeploymentExpression({
|
|
437
|
+
ref: {
|
|
438
|
+
id: expr.replace('._', '') as Fqn
|
|
439
|
+
},
|
|
440
|
+
selector: 'expanded'
|
|
441
|
+
})
|
|
442
|
+
}
|
|
443
|
+
if (expr.endsWith('.**')) {
|
|
444
|
+
return asTypedDeploymentExpression({
|
|
445
|
+
ref: {
|
|
446
|
+
id: expr.replace('.**', '') as Fqn
|
|
447
|
+
},
|
|
448
|
+
selector: 'descendants'
|
|
449
|
+
})
|
|
450
|
+
}
|
|
451
|
+
if (expr.endsWith('.*')) {
|
|
452
|
+
return asTypedDeploymentExpression({
|
|
453
|
+
ref: {
|
|
454
|
+
id: expr.replace('.*', '') as Fqn
|
|
455
|
+
},
|
|
456
|
+
selector: 'children'
|
|
457
|
+
})
|
|
458
|
+
}
|
|
459
|
+
return asTypedDeploymentExpression({
|
|
460
|
+
ref: {
|
|
461
|
+
id: expr as any as Fqn
|
|
462
|
+
}
|
|
463
|
+
})
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function $style<B extends AViewBuilder<AnyTypes, any, any>>(
|
|
467
|
+
element: B['ElementExpr'] | NonEmptyArray<B['ElementExpr']>,
|
|
325
468
|
{ notation, ...style }: ViewRuleStyle['style'] & { notation?: string }
|
|
326
|
-
): (b:
|
|
469
|
+
): (b: B) => B {
|
|
327
470
|
return (b) =>
|
|
328
471
|
b.style({
|
|
329
|
-
targets: (isArray(element) ? element : [element]).map(e =>
|
|
330
|
-
...notation ? { notation } : {},
|
|
472
|
+
targets: (isArray(element) ? element : [element]).map(e => b.$expr(e as any) as C4ElementExpression),
|
|
473
|
+
...(notation ? { notation } : {}),
|
|
331
474
|
style: {
|
|
332
475
|
...style
|
|
333
476
|
}
|
|
334
477
|
})
|
|
335
478
|
}
|
|
336
479
|
|
|
337
|
-
function $autoLayout<
|
|
480
|
+
function $autoLayout<B extends AViewBuilder<AnyTypes, any, any>>(
|
|
338
481
|
layout: AutoLayoutDirection
|
|
339
|
-
): (b:
|
|
482
|
+
): (b: B) => B {
|
|
340
483
|
return (b) => b.autoLayout(layout)
|
|
341
484
|
}
|
|
342
485
|
|
|
343
|
-
function $rules<
|
|
486
|
+
function $rules<B extends AViewBuilder<AnyTypes, any, any>>(...rules: Op<B>[]): (b: B) => B {
|
|
344
487
|
return (b) => rules.reduce((b, rule) => rule(b), b)
|
|
345
488
|
}
|
|
346
489
|
|
|
347
|
-
export { $autoLayout, $exclude, $
|
|
490
|
+
export { $autoLayout, $exclude, $include, $rules, $style }
|
|
348
491
|
|
|
349
492
|
export type ViewHelpers<T = unknown> = {
|
|
350
493
|
views: typeof views
|
|
351
494
|
view: AddViewHelper<T>
|
|
352
495
|
viewOf: AddViewOfHelper<T>
|
|
496
|
+
deploymentView: AddDeploymentViewHelper<T>
|
|
353
497
|
$include: typeof $include
|
|
354
498
|
$exclude: typeof $exclude
|
|
355
499
|
$style: typeof $style
|
|
356
500
|
$rules: typeof $rules
|
|
357
501
|
$autoLayout: typeof $autoLayout
|
|
358
502
|
}
|
|
503
|
+
|
|
504
|
+
export function mkViewBuilder(view: Writable<DeploymentView>): DeploymentViewBuilder<AnyTypes>
|
|
505
|
+
export function mkViewBuilder(view: Writable<ElementView>): ViewBuilder<AnyTypes>
|
|
506
|
+
export function mkViewBuilder(
|
|
507
|
+
view: Writable<ElementView | DeploymentView>
|
|
508
|
+
): DeploymentViewBuilder<AnyTypes> | ViewBuilder<AnyTypes> {
|
|
509
|
+
const viewBuilder = {
|
|
510
|
+
$expr: view.__ === 'deployment' ? $deploymentExpr : $expr,
|
|
511
|
+
autoLayout(autoLayout: unknown) {
|
|
512
|
+
view.rules.push({
|
|
513
|
+
direction: autoLayout
|
|
514
|
+
} as any)
|
|
515
|
+
return viewBuilder
|
|
516
|
+
},
|
|
517
|
+
exclude(expr: unknown) {
|
|
518
|
+
view.rules.push({
|
|
519
|
+
exclude: [expr]
|
|
520
|
+
} as any)
|
|
521
|
+
return viewBuilder
|
|
522
|
+
},
|
|
523
|
+
include(expr: unknown) {
|
|
524
|
+
view.rules.push({
|
|
525
|
+
include: [expr]
|
|
526
|
+
} as any)
|
|
527
|
+
return viewBuilder
|
|
528
|
+
},
|
|
529
|
+
style(rule: any) {
|
|
530
|
+
view.rules.push(rule)
|
|
531
|
+
return viewBuilder
|
|
532
|
+
}
|
|
533
|
+
// title(title: string) {
|
|
534
|
+
// view.title = title
|
|
535
|
+
// return viewBuilder
|
|
536
|
+
// },
|
|
537
|
+
// description(description: string) {
|
|
538
|
+
// view.description = description
|
|
539
|
+
// return viewBuilder
|
|
540
|
+
// }
|
|
541
|
+
}
|
|
542
|
+
return viewBuilder as any
|
|
543
|
+
}
|
package/src/builder/_types.ts
CHANGED
|
@@ -2,26 +2,32 @@ import type { IfNever, IsLiteral, Tagged, TupleToUnion } from 'type-fest'
|
|
|
2
2
|
import type {
|
|
3
3
|
BorderStyle,
|
|
4
4
|
Color,
|
|
5
|
+
DeploymentNodeKindSpecification,
|
|
5
6
|
ElementKindSpecification,
|
|
6
7
|
ElementShape,
|
|
8
|
+
KeysOf,
|
|
9
|
+
NonEmptyArray,
|
|
7
10
|
ParsedLikeC4Model,
|
|
8
11
|
RelationshipArrowType,
|
|
9
12
|
RelationshipKindSpecification,
|
|
10
13
|
RelationshipLineType
|
|
11
14
|
} from '../types'
|
|
12
15
|
|
|
13
|
-
type KeysOf<T> = keyof T extends infer K extends string ? K : never
|
|
14
|
-
|
|
15
16
|
export type BuilderSpecification = {
|
|
16
17
|
elements: {
|
|
17
18
|
[kind: string]: Partial<ElementKindSpecification>
|
|
18
19
|
}
|
|
19
|
-
relationships?:
|
|
20
|
+
relationships?: {
|
|
21
|
+
[kind: string]: Partial<RelationshipKindSpecification>
|
|
22
|
+
}
|
|
23
|
+
deployments?: {
|
|
24
|
+
[kind: string]: Partial<DeploymentNodeKindSpecification>
|
|
25
|
+
}
|
|
20
26
|
tags?: [string, ...string[]]
|
|
21
27
|
metadataKeys?: [string, ...string[]]
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
type Metadata<MetadataKey extends string> = IfNever<MetadataKey, never, Record<MetadataKey, string>>
|
|
30
|
+
export type Metadata<MetadataKey extends string> = IfNever<MetadataKey, never, Record<MetadataKey, string>>
|
|
25
31
|
|
|
26
32
|
export type NewElementProps<Tag, Metadata> = {
|
|
27
33
|
title?: string
|
|
@@ -40,6 +46,23 @@ export type NewElementProps<Tag, Metadata> = {
|
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
|
|
49
|
+
export type NewDeploymentNodeProps<Tag, Metadata> = {
|
|
50
|
+
title?: string
|
|
51
|
+
description?: string
|
|
52
|
+
technology?: string
|
|
53
|
+
tags?: IfNever<Tag, never, [Tag, ...Tag[]]>
|
|
54
|
+
metadata?: Metadata
|
|
55
|
+
icon?: string
|
|
56
|
+
shape?: ElementShape
|
|
57
|
+
color?: Color
|
|
58
|
+
links?: NonEmptyArray<string | { title?: string; url: string }>
|
|
59
|
+
style?: {
|
|
60
|
+
border?: BorderStyle
|
|
61
|
+
// 0-100
|
|
62
|
+
opacity?: number
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
43
66
|
export type NewViewProps<Tag> = {
|
|
44
67
|
title?: string
|
|
45
68
|
description?: string
|
|
@@ -58,7 +81,7 @@ export type NewRelationProps<Kind, Tag, Metadata> = {
|
|
|
58
81
|
tail?: RelationshipArrowType
|
|
59
82
|
line?: RelationshipLineType
|
|
60
83
|
color?: Color
|
|
61
|
-
links?:
|
|
84
|
+
links?: NonEmptyArray<string | { title?: string; url: string }>
|
|
62
85
|
}
|
|
63
86
|
|
|
64
87
|
export type Invalid<Message extends string> = Tagged<Message, 'Error'>
|
|
@@ -74,7 +97,9 @@ export interface Types<
|
|
|
74
97
|
ViewId extends string,
|
|
75
98
|
RelationshipKind extends string,
|
|
76
99
|
Tag extends string,
|
|
77
|
-
MetadataKey extends string
|
|
100
|
+
MetadataKey extends string,
|
|
101
|
+
DeploymentKind extends string,
|
|
102
|
+
DeploymentFqn extends string
|
|
78
103
|
> {
|
|
79
104
|
ElementKind: ElementKind
|
|
80
105
|
Fqn: Fqn
|
|
@@ -82,6 +107,8 @@ export interface Types<
|
|
|
82
107
|
RelationshipKind: RelationshipKind
|
|
83
108
|
Tag: Tag
|
|
84
109
|
MetadataKey: MetadataKey
|
|
110
|
+
DeploymentKind: DeploymentKind
|
|
111
|
+
DeploymentFqn: DeploymentFqn
|
|
85
112
|
|
|
86
113
|
Tags: IfNever<Tag, never, [Tag, ...Tag[]]>
|
|
87
114
|
// Metadata: Metadata<MetadataKey>
|
|
@@ -89,6 +116,8 @@ export interface Types<
|
|
|
89
116
|
NewElementProps: NewElementProps<Tag, Metadata<MetadataKey>>
|
|
90
117
|
NewRelationshipProps: NewRelationProps<RelationshipKind, Tag, Metadata<MetadataKey>>
|
|
91
118
|
NewViewProps: NewViewProps<Tag>
|
|
119
|
+
|
|
120
|
+
NewDeploymentNodeProps: NewDeploymentNodeProps<Tag, Metadata<MetadataKey>>
|
|
92
121
|
}
|
|
93
122
|
|
|
94
123
|
/**
|
|
@@ -101,7 +130,9 @@ export interface TypesNested<
|
|
|
101
130
|
ViewId extends string,
|
|
102
131
|
RelationshipKind extends string,
|
|
103
132
|
Tag extends string,
|
|
104
|
-
MetadataKey extends string
|
|
133
|
+
MetadataKey extends string,
|
|
134
|
+
DeploymentKind extends string,
|
|
135
|
+
DeploymentFqn extends string
|
|
105
136
|
> extends
|
|
106
137
|
Types<
|
|
107
138
|
ElementKind,
|
|
@@ -109,7 +140,9 @@ export interface TypesNested<
|
|
|
109
140
|
ViewId,
|
|
110
141
|
RelationshipKind,
|
|
111
142
|
Tag,
|
|
112
|
-
MetadataKey
|
|
143
|
+
MetadataKey,
|
|
144
|
+
DeploymentKind,
|
|
145
|
+
DeploymentFqn
|
|
113
146
|
>
|
|
114
147
|
{
|
|
115
148
|
Parent: Parent
|
|
@@ -121,6 +154,8 @@ export type AnyTypes = Types<
|
|
|
121
154
|
any,
|
|
122
155
|
any,
|
|
123
156
|
any,
|
|
157
|
+
any,
|
|
158
|
+
any,
|
|
124
159
|
any
|
|
125
160
|
>
|
|
126
161
|
|
|
@@ -131,6 +166,8 @@ export type AnyTypesNested = TypesNested<
|
|
|
131
166
|
any,
|
|
132
167
|
any,
|
|
133
168
|
any,
|
|
169
|
+
any,
|
|
170
|
+
any,
|
|
134
171
|
any
|
|
135
172
|
>
|
|
136
173
|
|
|
@@ -141,18 +178,23 @@ export namespace Types {
|
|
|
141
178
|
never,
|
|
142
179
|
KeysOf<Spec['relationships']>,
|
|
143
180
|
TupleToUnion<Spec['tags']>,
|
|
144
|
-
TupleToUnion<Spec['metadataKeys']
|
|
181
|
+
TupleToUnion<Spec['metadataKeys']>,
|
|
182
|
+
KeysOf<Spec['deployments']>,
|
|
183
|
+
never
|
|
145
184
|
>
|
|
146
185
|
: never
|
|
147
186
|
|
|
148
|
-
export type AddFqn<T, Id extends string> = T extends TypesNested<infer P, any, any, any, any, any, any
|
|
187
|
+
export type AddFqn<T, Id extends string> = T extends TypesNested<infer P, any, any, any, any, any, any, any, any>
|
|
188
|
+
? TypesNested<
|
|
149
189
|
P,
|
|
150
190
|
T['ElementKind'],
|
|
151
191
|
`${P}.${Id}` | T['Fqn'],
|
|
152
192
|
T['ViewId'],
|
|
153
193
|
T['RelationshipKind'],
|
|
154
194
|
T['Tag'],
|
|
155
|
-
T['MetadataKey']
|
|
195
|
+
T['MetadataKey'],
|
|
196
|
+
T['DeploymentKind'],
|
|
197
|
+
T['DeploymentFqn']
|
|
156
198
|
>
|
|
157
199
|
: T extends AnyTypes ? Types<
|
|
158
200
|
T['ElementKind'],
|
|
@@ -160,11 +202,37 @@ export namespace Types {
|
|
|
160
202
|
T['ViewId'],
|
|
161
203
|
T['RelationshipKind'],
|
|
162
204
|
T['Tag'],
|
|
163
|
-
T['MetadataKey']
|
|
205
|
+
T['MetadataKey'],
|
|
206
|
+
T['DeploymentKind'],
|
|
207
|
+
T['DeploymentFqn']
|
|
208
|
+
>
|
|
209
|
+
: never
|
|
210
|
+
|
|
211
|
+
export type AddDeploymentFqn<T, Id extends string> = T extends
|
|
212
|
+
TypesNested<infer P, any, any, any, any, any, any, any, any> ? TypesNested<
|
|
213
|
+
P,
|
|
214
|
+
T['ElementKind'],
|
|
215
|
+
T['Fqn'],
|
|
216
|
+
T['ViewId'],
|
|
217
|
+
T['RelationshipKind'],
|
|
218
|
+
T['Tag'],
|
|
219
|
+
T['MetadataKey'],
|
|
220
|
+
T['DeploymentKind'],
|
|
221
|
+
`${P}.${Id}` | T['DeploymentFqn']
|
|
222
|
+
>
|
|
223
|
+
: T extends AnyTypes ? Types<
|
|
224
|
+
T['ElementKind'],
|
|
225
|
+
T['Fqn'],
|
|
226
|
+
T['ViewId'],
|
|
227
|
+
T['RelationshipKind'],
|
|
228
|
+
T['Tag'],
|
|
229
|
+
T['MetadataKey'],
|
|
230
|
+
T['DeploymentKind'],
|
|
231
|
+
Id | T['DeploymentFqn']
|
|
164
232
|
>
|
|
165
233
|
: never
|
|
166
234
|
|
|
167
|
-
export type AddView<T, Id extends string> = T extends TypesNested<infer P, any, any, any, any, any, any>
|
|
235
|
+
export type AddView<T, Id extends string> = T extends TypesNested<infer P, any, any, any, any, any, any, any, any>
|
|
168
236
|
? TypesNested<
|
|
169
237
|
P,
|
|
170
238
|
T['ElementKind'],
|
|
@@ -172,7 +240,9 @@ export namespace Types {
|
|
|
172
240
|
Id | T['ViewId'],
|
|
173
241
|
T['RelationshipKind'],
|
|
174
242
|
T['Tag'],
|
|
175
|
-
T['MetadataKey']
|
|
243
|
+
T['MetadataKey'],
|
|
244
|
+
T['DeploymentKind'],
|
|
245
|
+
T['DeploymentFqn']
|
|
176
246
|
>
|
|
177
247
|
: T extends AnyTypes ? Types<
|
|
178
248
|
T['ElementKind'],
|
|
@@ -180,7 +250,9 @@ export namespace Types {
|
|
|
180
250
|
Id | T['ViewId'],
|
|
181
251
|
T['RelationshipKind'],
|
|
182
252
|
T['Tag'],
|
|
183
|
-
T['MetadataKey']
|
|
253
|
+
T['MetadataKey'],
|
|
254
|
+
T['DeploymentKind'],
|
|
255
|
+
T['DeploymentFqn']
|
|
184
256
|
>
|
|
185
257
|
: never
|
|
186
258
|
|