@likec4/core 1.18.0 → 1.19.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/LICENSE +1 -1
- package/dist/builder/index.d.mts +502 -0
- package/dist/builder/index.d.ts +502 -0
- package/dist/builder/index.js +871 -0
- package/dist/compute-view/index.d.mts +9 -78
- package/dist/compute-view/index.d.ts +9 -78
- package/dist/compute-view/index.js +78 -0
- package/dist/index.d.mts +9 -730
- package/dist/index.d.ts +9 -730
- package/dist/{index.mjs → index.js} +7 -784
- package/dist/model/index.d.mts +218 -606
- package/dist/model/index.d.ts +218 -606
- package/dist/model/index.js +1 -0
- package/dist/shared/chunk-RAAYCPUM.M-JWF7SS.js +21 -0
- package/dist/shared/core.BIfgabEw.d.ts +719 -0
- package/dist/shared/core.BZ9Msq7w.d.mts +719 -0
- package/dist/shared/{core.DMYY7C8s.d.mts → core.C05RDLhi.d.ts} +179 -230
- package/dist/shared/{core.DMYY7C8s.d.ts → core.CmYMqgha.d.mts} +179 -230
- package/dist/shared/core.D6-fWbM3.d.ts +127 -0
- package/dist/shared/core.D74xkKkG.d.mts +148 -0
- package/dist/shared/core.D74xkKkG.d.ts +148 -0
- package/dist/shared/core.sLaWHBjR.d.mts +127 -0
- package/dist/shared/index.-BdzdI2C.js +7443 -0
- package/dist/shared/object_hash.CE_oF3I3.js +1222 -0
- package/dist/shared/view.CyZrG8BJ.js +354 -0
- package/dist/types/index.d.mts +4 -2
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.js +20 -0
- package/dist/utils/index.d.mts +404 -0
- package/dist/utils/index.d.ts +404 -0
- package/dist/utils/index.js +330 -0
- package/package.json +47 -33
- package/src/builder/Builder-style1.test-d.ts +190 -0
- package/src/builder/Builder-style2.test-d.ts +175 -0
- package/src/builder/Builder.deployment.ts +25 -20
- package/src/builder/Builder.deploymentModel.ts +80 -55
- package/src/builder/Builder.element.ts +2 -0
- package/src/builder/Builder.model.ts +57 -43
- package/src/builder/Builder.ts +412 -431
- package/src/builder/Builder.view-common.ts +234 -0
- package/src/builder/Builder.view-deployment.ts +135 -0
- package/src/builder/Builder.view-element.ts +189 -0
- package/src/builder/Builder.views.ts +109 -33
- package/src/builder/Builder.with.ts +475 -0
- package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +374 -0
- package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +183 -0
- package/src/builder/__snapshots__/Builder.spec.ts.snap +374 -0
- package/src/builder/_types.ts +28 -5
- package/src/builder/index.ts +10 -4
- package/src/colors/index.ts +2 -2
- package/src/compute-view/compute-view.ts +45 -54
- package/src/compute-view/deployment-view/__test__/TestHelper.ts +236 -0
- package/src/compute-view/deployment-view/__test__/fixture.ts +50 -62
- package/src/compute-view/deployment-view/_types.ts +26 -18
- package/src/compute-view/deployment-view/clean-connections.ts +173 -164
- package/src/compute-view/deployment-view/compute.ts +51 -37
- package/src/compute-view/deployment-view/memory/index.ts +9 -0
- package/src/compute-view/deployment-view/memory/memory.ts +97 -0
- package/src/compute-view/deployment-view/predicates/elements.ts +144 -0
- package/src/compute-view/deployment-view/predicates/relation-direct.ts +183 -76
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +38 -20
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +72 -23
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +61 -22
- package/src/compute-view/deployment-view/predicates/wildcard.ts +15 -15
- package/src/compute-view/deployment-view/stages/stage-exclude.ts +5 -0
- package/src/compute-view/deployment-view/stages/stage-final.ts +245 -0
- package/src/compute-view/deployment-view/stages/stage-include.ts +95 -0
- package/src/compute-view/deployment-view/utils.ts +95 -31
- package/src/compute-view/dynamic-view/__test__/fixture.ts +4 -4
- package/src/compute-view/dynamic-view/compute.ts +59 -45
- package/src/compute-view/element-view/__test__/TestHelper.ts +258 -0
- package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +64 -62
- package/src/compute-view/element-view/__test__/fixture.ts +147 -117
- package/src/compute-view/element-view/_types.ts +48 -0
- package/src/compute-view/element-view/clean-connections.ts +113 -0
- package/src/compute-view/element-view/compute.ts +264 -683
- package/src/compute-view/element-view/memory/NodeGroup.ts +31 -0
- package/src/compute-view/element-view/memory/index.ts +10 -0
- package/src/compute-view/element-view/memory/memory.ts +177 -0
- package/src/compute-view/element-view/memory/stage-exclude.ts +59 -0
- package/src/compute-view/element-view/memory/stage-final.ts +129 -0
- package/src/compute-view/element-view/memory/stage-include.ts +128 -0
- package/src/compute-view/element-view/predicates/_utils.ts +86 -0
- package/src/compute-view/element-view/predicates/element-expand.ts +33 -0
- package/src/compute-view/element-view/predicates/element-kind-tag.ts +26 -0
- package/src/compute-view/element-view/predicates/element-ref.ts +37 -0
- package/src/compute-view/element-view/predicates/relation-direct.ts +309 -0
- package/src/compute-view/element-view/predicates/relation-in-out.ts +66 -0
- package/src/compute-view/element-view/predicates/relation-in.ts +118 -0
- package/src/compute-view/element-view/predicates/relation-out.ts +116 -0
- package/src/compute-view/element-view/predicates/wildcard.ts +88 -0
- package/src/compute-view/element-view/utils.ts +59 -0
- package/src/compute-view/index.ts +3 -4
- package/src/compute-view/memory/AbstractMemory.ts +45 -0
- package/src/compute-view/memory/AbstractStageExclude.ts +216 -0
- package/src/compute-view/memory/AbstractStageInclude.ts +200 -0
- package/src/compute-view/memory/_types.ts +147 -0
- package/src/compute-view/memory/index.ts +5 -0
- package/src/compute-view/memory/ops.ts +43 -0
- package/src/compute-view/utils/buildComputedNodes.ts +4 -4
- package/src/compute-view/utils/elementExpressionToPredicate.ts +1 -3
- package/src/compute-view/utils/link-nodes-with-edges.ts +3 -7
- package/src/compute-view/utils/{derive-edge-props-from-relationships.ts → merge-props-from-relationships.ts} +54 -23
- package/src/compute-view/utils/relationExpressionToPredicates.ts +2 -2
- package/src/compute-view/utils/resolve-extended-views.ts +44 -40
- package/src/compute-view/utils/resolve-global-rules.ts +6 -6
- package/src/compute-view/utils/topological-sort.ts +167 -71
- package/src/compute-view/utils/with-readable-edges.ts +14 -9
- package/src/index.ts +22 -16
- package/src/model/DeploymentElementModel.ts +150 -85
- package/src/model/DeploymentModel.ts +27 -21
- package/src/model/ElementModel.ts +51 -25
- package/src/model/LikeC4Model.test-d.ts +4 -3
- package/src/model/LikeC4Model.ts +98 -42
- package/src/model/RelationModel.ts +5 -4
- package/src/model/__test__/fixture.ts +5 -9
- package/src/model/connection/Connection.ts +72 -0
- package/src/model/connection/deployment/DeploymentConnectionModel.ts +178 -0
- package/src/model/connection/{deployment.ts → deployment/find.ts} +14 -18
- package/src/model/connection/deployment/index.ts +8 -0
- package/src/model/connection/index.ts +22 -0
- package/src/model/connection/model/ConnectionModel.ts +157 -0
- package/src/model/connection/{model.ts → model/find.ts} +43 -49
- package/src/model/connection/model/index.ts +8 -0
- package/src/model/connection/ops.ts +274 -0
- package/src/model/guards.ts +9 -0
- package/src/model/index.ts +45 -3
- package/src/model/types.ts +35 -18
- package/src/model/view/EdgeModel.ts +6 -6
- package/src/model/view/LikeC4ViewModel.ts +14 -8
- package/src/model/view/NodeModel.ts +6 -5
- package/src/types/_common.ts +53 -1
- package/src/types/deployments.ts +88 -156
- package/src/types/element.ts +2 -2
- package/src/types/expression-v2.ts +172 -0
- package/src/types/expression.ts +9 -5
- package/src/types/global.ts +3 -3
- package/src/types/index.ts +220 -13
- package/src/types/model.ts +28 -24
- package/src/types/operators.ts +1 -1
- package/src/types/relation.ts +14 -10
- package/src/types/theme.ts +0 -1
- package/src/types/view.ts +20 -18
- package/src/utils/const.ts +1 -0
- package/src/utils/fqn.ts +140 -49
- package/src/utils/getOrCreate.ts +1 -1
- package/src/utils/index.ts +74 -9
- package/src/utils/iterable/_types.ts +5 -0
- package/src/utils/iterable/filter.ts +55 -0
- package/src/utils/iterable/flat.ts +17 -0
- package/src/utils/iterable/index.ts +12 -0
- package/src/utils/iterable/map.ts +40 -0
- package/src/utils/iterable/reduce.ts +24 -0
- package/src/utils/iterable/some.ts +36 -0
- package/src/utils/iterable/to.ts +19 -0
- package/src/utils/iterable/unique.ts +29 -0
- package/src/utils/relations.ts +3 -64
- package/src/utils/set.ts +11 -9
- package/src/utils/string-hash.ts +1 -1
- package/dist/compute-view/index.mjs +0 -79
- package/dist/model/index.mjs +0 -2
- package/dist/shared/core.BBgiAAv1.mjs +0 -144
- package/dist/shared/core.BPyJvuMU.mjs +0 -2420
- package/dist/shared/core.BQ4AbfvB.mjs +0 -9228
- package/dist/shared/core.k12s_keD.mjs +0 -203
- package/dist/types/index.mjs +0 -21
- package/src/builder/Builder.test-d.ts +0 -124
- package/src/builder/Builder.view.ts +0 -543
- package/src/compute-view/LikeC4ModelGraph.ts +0 -330
- package/src/compute-view/deployment-view/Memory.ts +0 -108
- package/src/compute-view/deployment-view/Stage.ts +0 -145
- package/src/compute-view/deployment-view/predicates/deployment-ref.ts +0 -146
- package/src/compute-view/element-view/predicates.ts +0 -517
- package/src/compute-view/utils/sortNodes.ts +0 -101
- package/src/model/connection/ConnectionModel.ts +0 -94
- package/src/model/connection/DeploymentConnectionModel.ts +0 -99
|
@@ -1,543 +0,0 @@
|
|
|
1
|
-
import { isArray, isString, map } from 'remeda'
|
|
2
|
-
import type { LiteralUnion, Simplify, Tagged, Writable } from 'type-fest'
|
|
3
|
-
import {
|
|
4
|
-
type AutoLayoutDirection,
|
|
5
|
-
type CustomElementExpr,
|
|
6
|
-
type CustomRelationExpr,
|
|
7
|
-
type DeploymentElementExpression,
|
|
8
|
-
type DeploymentExpression,
|
|
9
|
-
type DeploymentView,
|
|
10
|
-
type ElementExpression as C4ElementExpression,
|
|
11
|
-
type ElementView,
|
|
12
|
-
type Expression as C4Expression,
|
|
13
|
-
type Fqn,
|
|
14
|
-
isElementPredicateExpr,
|
|
15
|
-
type NonEmptyArray,
|
|
16
|
-
type ViewRuleStyle,
|
|
17
|
-
type WhereOperator
|
|
18
|
-
} from '../types'
|
|
19
|
-
import type { AnyTypes, Types } from './_types'
|
|
20
|
-
import type { views, ViewsBuilder as Builder } from './Builder.views'
|
|
21
|
-
|
|
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
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export namespace ViewPredicate {
|
|
59
|
-
export type ElementExpr<Fqn extends string> = '*' | Fqn | `${Fqn}.*` | `${Fqn}._` | `${Fqn}.**`
|
|
60
|
-
|
|
61
|
-
export type AllExpression<ElementExpr extends string> =
|
|
62
|
-
| ElementExpr
|
|
63
|
-
| `-> ${ElementExpr} ->`
|
|
64
|
-
| `-> ${ElementExpr}`
|
|
65
|
-
| `${ElementExpr} ->`
|
|
66
|
-
| `${ElementExpr} ${'->' | '<->'} ${ElementExpr}`
|
|
67
|
-
|
|
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>>
|
|
74
|
-
: never
|
|
75
|
-
|
|
76
|
-
export type WhereTag<Tag extends string> = `tag ${'is' | 'is not'} #${Tag}`
|
|
77
|
-
export type WhereKind<Kind extends string> = `kind ${'is' | 'is not'} ${Kind}`
|
|
78
|
-
|
|
79
|
-
export type WhereEq<Types extends AnyTypes> =
|
|
80
|
-
| ViewPredicate.WhereTag<Types['Tag']>
|
|
81
|
-
| ViewPredicate.WhereKind<Types['ElementKind']>
|
|
82
|
-
|
|
83
|
-
export type WhereOperator<Types extends AnyTypes> = ViewPredicate.WhereEq<Types> | {
|
|
84
|
-
and: NonEmptyArray<ViewPredicate.WhereOperator<Types>>
|
|
85
|
-
or?: never
|
|
86
|
-
not?: never
|
|
87
|
-
} | {
|
|
88
|
-
or: NonEmptyArray<ViewPredicate.WhereOperator<Types>>
|
|
89
|
-
and?: never
|
|
90
|
-
not?: never
|
|
91
|
-
} | {
|
|
92
|
-
not: ViewPredicate.WhereOperator<Types>
|
|
93
|
-
and?: never
|
|
94
|
-
or?: never
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export type Custom<Types extends AnyTypes> = {
|
|
98
|
-
where?: ViewPredicate.WhereOperator<Types>
|
|
99
|
-
with?: Simplify<
|
|
100
|
-
Omit<CustomElementExpr['custom'] & CustomRelationExpr['customRelation'], 'expr' | 'relation' | 'navigateTo'> & {
|
|
101
|
-
navigateTo?: Types['ViewId']
|
|
102
|
-
}
|
|
103
|
-
>
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
type Op<T> = (b: T) => T
|
|
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>
|
|
112
|
-
|
|
113
|
-
export interface AddViewHelper<Props = unknown> {
|
|
114
|
-
// <
|
|
115
|
-
// const Id extends string,
|
|
116
|
-
// T extends AnyTypes
|
|
117
|
-
// >(
|
|
118
|
-
// id: Id
|
|
119
|
-
// ): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
120
|
-
|
|
121
|
-
<
|
|
122
|
-
const Id extends string,
|
|
123
|
-
T extends AnyTypes
|
|
124
|
-
>(
|
|
125
|
-
id: Id,
|
|
126
|
-
builder: (b: ViewBuilder<T>) => ViewBuilder<T>
|
|
127
|
-
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
128
|
-
|
|
129
|
-
<
|
|
130
|
-
const Id extends string,
|
|
131
|
-
T extends AnyTypes
|
|
132
|
-
>(
|
|
133
|
-
id: Id,
|
|
134
|
-
propsOrTitle: Props | string
|
|
135
|
-
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
136
|
-
|
|
137
|
-
<
|
|
138
|
-
const Id extends string,
|
|
139
|
-
T extends AnyTypes
|
|
140
|
-
>(
|
|
141
|
-
id: Id,
|
|
142
|
-
propsOrTitle: Props | string | undefined,
|
|
143
|
-
builder: (b: ViewBuilder<T>) => ViewBuilder<T>
|
|
144
|
-
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface AddViewOfHelper<Props = unknown> {
|
|
148
|
-
<
|
|
149
|
-
const Id extends string,
|
|
150
|
-
T extends AnyTypes,
|
|
151
|
-
Of extends string & T['Fqn']
|
|
152
|
-
>(
|
|
153
|
-
id: Id,
|
|
154
|
-
of: Of
|
|
155
|
-
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
156
|
-
|
|
157
|
-
<
|
|
158
|
-
const Id extends string,
|
|
159
|
-
T extends AnyTypes,
|
|
160
|
-
Of extends string & T['Fqn']
|
|
161
|
-
>(
|
|
162
|
-
id: Id,
|
|
163
|
-
of: Of,
|
|
164
|
-
builder: (b: ViewBuilder<T>) => ViewBuilder<T>
|
|
165
|
-
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
166
|
-
|
|
167
|
-
<
|
|
168
|
-
const Id extends string,
|
|
169
|
-
T extends AnyTypes,
|
|
170
|
-
Of extends string & T['Fqn']
|
|
171
|
-
>(
|
|
172
|
-
id: Id,
|
|
173
|
-
of: Of,
|
|
174
|
-
propsOrTitle: Props | string
|
|
175
|
-
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
176
|
-
|
|
177
|
-
<
|
|
178
|
-
const Id extends string,
|
|
179
|
-
T extends AnyTypes,
|
|
180
|
-
Of extends string & T['Fqn']
|
|
181
|
-
>(
|
|
182
|
-
id: Id,
|
|
183
|
-
of: Of,
|
|
184
|
-
propsOrTitle: Props | string | undefined,
|
|
185
|
-
builder: (b: ViewBuilder<T>) => ViewBuilder<T>
|
|
186
|
-
): (builder: Builder<T>) => Builder<Types.AddView<T, Id>>
|
|
187
|
-
}
|
|
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
|
-
|
|
208
|
-
// To hook types
|
|
209
|
-
type TypedC4Expression<Types extends AnyTypes> = Tagged<C4Expression, 'typed', Types>
|
|
210
|
-
type TypedDeploymentExpression<Types extends AnyTypes> = Tagged<DeploymentExpression, 'typed', Types>
|
|
211
|
-
|
|
212
|
-
function parseWhere(where: ViewPredicate.WhereOperator<AnyTypes>): WhereOperator<any, any> {
|
|
213
|
-
if (isString(where)) {
|
|
214
|
-
const op = where as LiteralUnion<ViewPredicate.WhereEq<AnyTypes>, string>
|
|
215
|
-
switch (true) {
|
|
216
|
-
case op.startsWith('tag is not #'):
|
|
217
|
-
return {
|
|
218
|
-
tag: {
|
|
219
|
-
neq: op.replace('tag is not #', '')
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
case op.startsWith('tag is #'):
|
|
223
|
-
return {
|
|
224
|
-
tag: {
|
|
225
|
-
eq: op.replace('tag is #', '')
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
case op.startsWith('kind is not '):
|
|
229
|
-
return {
|
|
230
|
-
kind: {
|
|
231
|
-
neq: op.replace('kind is not ', '')
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
case op.startsWith('kind is '):
|
|
235
|
-
return {
|
|
236
|
-
kind: {
|
|
237
|
-
eq: op.replace('kind is ', '')
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
default:
|
|
241
|
-
throw new Error(`Unknown where operator: ${where}`)
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (where.and) {
|
|
246
|
-
return {
|
|
247
|
-
and: map(where.and, parseWhere)
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (where.or) {
|
|
251
|
-
return {
|
|
252
|
-
or: map(where.or, parseWhere)
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (where.not) {
|
|
256
|
-
return {
|
|
257
|
-
not: parseWhere(where.not)
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
throw new Error(`Unknown where operator: ${where}`)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function $include<B extends AViewBuilder<AnyTypes, any, any>>(
|
|
265
|
-
...args:
|
|
266
|
-
| [B['Expr']]
|
|
267
|
-
| [B['Expr'], ViewPredicate.Custom<B['Types']>]
|
|
268
|
-
): (b: B) => B {
|
|
269
|
-
return (b) => {
|
|
270
|
-
let expr = b.$expr(args[0])
|
|
271
|
-
if (args.length === 2) {
|
|
272
|
-
const condition = args[1].where ? parseWhere(args[1].where) : undefined
|
|
273
|
-
if (condition) {
|
|
274
|
-
expr = {
|
|
275
|
-
where: {
|
|
276
|
-
expr: expr as any,
|
|
277
|
-
condition
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const custom = args[1].with
|
|
283
|
-
if (custom) {
|
|
284
|
-
const isElement = isElementPredicateExpr(expr)
|
|
285
|
-
if (isElement) {
|
|
286
|
-
expr = {
|
|
287
|
-
custom: {
|
|
288
|
-
...custom,
|
|
289
|
-
expr: expr as any
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
} else {
|
|
293
|
-
expr = {
|
|
294
|
-
customRelation: {
|
|
295
|
-
...custom,
|
|
296
|
-
relation: expr as any
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
b.include(expr as any)
|
|
303
|
-
return b
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function $exclude<B extends AViewBuilder<AnyTypes, any, any>>(
|
|
308
|
-
...args:
|
|
309
|
-
| [B['Expr']]
|
|
310
|
-
| [B['Expr'], ViewPredicate.Custom<B['Types']>]
|
|
311
|
-
): (b: B) => B {
|
|
312
|
-
return (b) => {
|
|
313
|
-
let expr = b.$expr(args[0]) as C4Expression
|
|
314
|
-
if (args.length === 2 && args[1].where) {
|
|
315
|
-
const condition = parseWhere(args[1].where)
|
|
316
|
-
expr = {
|
|
317
|
-
where: {
|
|
318
|
-
expr: expr as any,
|
|
319
|
-
condition
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
b.exclude(expr)
|
|
324
|
-
return b
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const asTypedExpr = <Types extends AnyTypes>(expr: C4Expression): TypedC4Expression<Types> => {
|
|
329
|
-
return expr as TypedC4Expression<Types>
|
|
330
|
-
}
|
|
331
|
-
function $expr<Types extends AnyTypes>(expr: ViewPredicate.Expression<Types> | C4Expression): TypedC4Expression<Types> {
|
|
332
|
-
if (!isString(expr)) {
|
|
333
|
-
return expr as TypedC4Expression<Types>
|
|
334
|
-
}
|
|
335
|
-
if (expr === '*') {
|
|
336
|
-
return asTypedExpr({ wildcard: true })
|
|
337
|
-
}
|
|
338
|
-
if (expr.startsWith('->')) {
|
|
339
|
-
if (expr.endsWith('->')) {
|
|
340
|
-
return asTypedExpr({
|
|
341
|
-
inout: $expr(expr.replace(/->/g, '').trim()) as any
|
|
342
|
-
})
|
|
343
|
-
}
|
|
344
|
-
return asTypedExpr({
|
|
345
|
-
incoming: $expr(expr.replace('-> ', '')) as any
|
|
346
|
-
})
|
|
347
|
-
}
|
|
348
|
-
if (expr.endsWith(' ->')) {
|
|
349
|
-
return asTypedExpr({
|
|
350
|
-
outgoing: $expr(expr.replace(' ->', '')) as any
|
|
351
|
-
})
|
|
352
|
-
}
|
|
353
|
-
if (expr.includes(' <-> ')) {
|
|
354
|
-
const [source, target] = expr.split(' <-> ')
|
|
355
|
-
return asTypedExpr({
|
|
356
|
-
source: $expr(source) as any,
|
|
357
|
-
target: $expr(target) as any,
|
|
358
|
-
isBidirectional: true
|
|
359
|
-
})
|
|
360
|
-
}
|
|
361
|
-
if (expr.includes(' -> ')) {
|
|
362
|
-
const [source, target] = expr.split(' -> ')
|
|
363
|
-
return asTypedExpr({
|
|
364
|
-
source: $expr(source) as any,
|
|
365
|
-
target: $expr(target) as any
|
|
366
|
-
})
|
|
367
|
-
}
|
|
368
|
-
if (expr.endsWith('._')) {
|
|
369
|
-
return asTypedExpr({
|
|
370
|
-
expanded: expr.replace('._', '') as Fqn
|
|
371
|
-
})
|
|
372
|
-
}
|
|
373
|
-
if (expr.endsWith('.*')) {
|
|
374
|
-
return asTypedExpr({
|
|
375
|
-
element: expr.replace('.*', '') as Fqn,
|
|
376
|
-
isChildren: true
|
|
377
|
-
})
|
|
378
|
-
}
|
|
379
|
-
if (expr.endsWith('.**')) {
|
|
380
|
-
return asTypedExpr({
|
|
381
|
-
element: expr.replace('.**', '') as Fqn,
|
|
382
|
-
isDescendants: true
|
|
383
|
-
})
|
|
384
|
-
}
|
|
385
|
-
return asTypedExpr({
|
|
386
|
-
element: expr as any as Fqn
|
|
387
|
-
})
|
|
388
|
-
}
|
|
389
|
-
|
|
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']>,
|
|
468
|
-
{ notation, ...style }: ViewRuleStyle['style'] & { notation?: string }
|
|
469
|
-
): (b: B) => B {
|
|
470
|
-
return (b) =>
|
|
471
|
-
b.style({
|
|
472
|
-
targets: (isArray(element) ? element : [element]).map(e => b.$expr(e as any) as C4ElementExpression),
|
|
473
|
-
...(notation ? { notation } : {}),
|
|
474
|
-
style: {
|
|
475
|
-
...style
|
|
476
|
-
}
|
|
477
|
-
})
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
function $autoLayout<B extends AViewBuilder<AnyTypes, any, any>>(
|
|
481
|
-
layout: AutoLayoutDirection
|
|
482
|
-
): (b: B) => B {
|
|
483
|
-
return (b) => b.autoLayout(layout)
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
function $rules<B extends AViewBuilder<AnyTypes, any, any>>(...rules: Op<B>[]): (b: B) => B {
|
|
487
|
-
return (b) => rules.reduce((b, rule) => rule(b), b)
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
export { $autoLayout, $exclude, $include, $rules, $style }
|
|
491
|
-
|
|
492
|
-
export type ViewHelpers<T = unknown> = {
|
|
493
|
-
views: typeof views
|
|
494
|
-
view: AddViewHelper<T>
|
|
495
|
-
viewOf: AddViewOfHelper<T>
|
|
496
|
-
deploymentView: AddDeploymentViewHelper<T>
|
|
497
|
-
$include: typeof $include
|
|
498
|
-
$exclude: typeof $exclude
|
|
499
|
-
$style: typeof $style
|
|
500
|
-
$rules: typeof $rules
|
|
501
|
-
$autoLayout: typeof $autoLayout
|
|
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
|
-
}
|