@likec4/core 1.48.0 → 1.50.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/THIRD-PARTY-LICENSES.md +1034 -0
- package/dist/_chunks/Builder.view-element.mjs +2 -3284
- package/dist/_chunks/LikeC4Model.d.mts +21 -25
- package/dist/_chunks/_types.d.mts +1 -5
- package/dist/_chunks/_types2.d.mts +2 -4
- package/dist/_chunks/assignTagColors.mjs +1 -24
- package/dist/_chunks/geometry.mjs +1 -335
- package/dist/_chunks/index.d.mts +1995 -131
- package/dist/_chunks/index2.d.mts +153 -892
- package/dist/_chunks/index3.d.mts +15 -13
- package/dist/_chunks/index4.d.mts +229 -3
- package/dist/_chunks/index5.d.mts +392 -30
- package/dist/_chunks/libs/@mantine/colors-generator.mjs +2 -3403
- package/dist/_chunks/libs/@radix-ui/colors.mjs +1 -0
- package/dist/_chunks/libs/@ungap/structured-clone.mjs +1 -213
- package/dist/_chunks/libs/bail.mjs +1 -14
- package/dist/_chunks/libs/ccount.mjs +1 -25
- package/dist/_chunks/libs/character-entities-html4.mjs +1 -263
- package/dist/_chunks/libs/character-entities-legacy.mjs +1 -117
- package/dist/_chunks/libs/character-entities.mjs +2 -2136
- package/dist/_chunks/libs/comma-separated-tokens.mjs +1 -18
- package/dist/_chunks/libs/decode-named-character-reference.mjs +1 -21
- package/dist/_chunks/libs/defu.mjs +1 -42
- package/dist/_chunks/libs/devlop.mjs +1 -5
- package/dist/_chunks/libs/escape-string-regexp.mjs +1 -8
- package/dist/_chunks/libs/extend.mjs +1 -77
- package/dist/_chunks/libs/graphology-dag.mjs +1 -703
- package/dist/_chunks/libs/graphology.mjs +1 -4565
- package/dist/_chunks/libs/hast-util-sanitize.mjs +1 -863
- package/dist/_chunks/libs/hast-util-to-html.mjs +9 -2696
- package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
- package/dist/_chunks/libs/longest-streak.mjs +1 -30
- package/dist/_chunks/libs/markdown-table.mjs +2 -290
- package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +1 -653
- package/dist/_chunks/libs/mdast-util-from-markdown.mjs +3 -8522
- package/dist/_chunks/libs/mdast-util-gfm.mjs +15 -2393
- package/dist/_chunks/libs/mdast-util-to-hast.mjs +11 -1803
- package/dist/_chunks/libs/micromark-extension-gfm.mjs +1 -2243
- package/dist/_chunks/libs/mnemonist.d.mts +1 -91
- package/dist/_chunks/libs/mnemonist.mjs +1 -1978
- package/dist/_chunks/libs/natural-compare-lite.mjs +9 -42
- package/dist/_chunks/libs/ohash.mjs +1 -0
- package/dist/_chunks/libs/rehype-sanitize.mjs +1 -29
- package/dist/_chunks/libs/rehype-stringify.mjs +1 -34
- package/dist/_chunks/libs/remark-gfm.mjs +1 -36
- package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +3 -100
- package/dist/_chunks/libs/remark-parse.mjs +1 -39
- package/dist/_chunks/libs/remark-rehype.mjs +1 -171
- package/dist/_chunks/libs/remeda.mjs +2 -702
- package/dist/_chunks/libs/trough.mjs +1 -158
- package/dist/_chunks/libs/unified.mjs +1 -2212
- package/dist/_chunks/manual-layout.mjs +1 -0
- package/dist/_chunks/model.mjs +4 -1898
- package/dist/_chunks/rolldown-runtime.mjs +1 -42
- package/dist/_chunks/types.mjs +1 -0
- package/dist/_chunks/utils.mjs +1 -483
- package/dist/builder/index.d.mts +3 -6
- package/dist/builder/index.mjs +1 -662
- package/dist/compute-view/index.d.mts +85 -13
- package/dist/compute-view/index.mjs +2 -262
- package/dist/geometry/index.d.mts +2 -2
- package/dist/geometry/index.mjs +1 -3
- package/dist/index.d.mts +7 -13
- package/dist/index.mjs +1 -27
- package/dist/model/index.d.mts +4 -11
- package/dist/model/index.mjs +1 -11
- package/dist/styles/index.d.mts +2 -7
- package/dist/styles/index.mjs +1 -30
- package/dist/types/index.d.mts +3 -9
- package/dist/types/index.mjs +1 -15
- package/dist/utils/graphology/index.d.mts +1 -1
- package/dist/utils/graphology/index.mjs +1 -3
- package/dist/utils/index.d.mts +5 -10
- package/dist/utils/index.mjs +1 -17
- package/package.json +14 -13
- package/dist/_chunks/LikeC4Styles.mjs +0 -691
- package/dist/_chunks/RichText.d.mts +0 -84
- package/dist/_chunks/RichText.mjs +0 -148
- package/dist/_chunks/_aux.d.mts +0 -289
- package/dist/_chunks/_aux.mjs +0 -18
- package/dist/_chunks/calcDriftsFromSnapshot.mjs +0 -379
- package/dist/_chunks/connection.mjs +0 -0
- package/dist/_chunks/const.d.mts +0 -43
- package/dist/_chunks/const.mjs +0 -33
- package/dist/_chunks/expression-model.d.mts +0 -192
- package/dist/_chunks/expression-model.mjs +0 -103
- package/dist/_chunks/expression.d.mts +0 -347
- package/dist/_chunks/expression.mjs +0 -107
- package/dist/_chunks/find.d.mts +0 -82
- package/dist/_chunks/find.mjs +0 -646
- package/dist/_chunks/find2.d.mts +0 -78
- package/dist/_chunks/find2.mjs +0 -287
- package/dist/_chunks/fqnRef.d.mts +0 -58
- package/dist/_chunks/fqnRef.mjs +0 -41
- package/dist/_chunks/index6.d.mts +0 -43
- package/dist/_chunks/index7.d.mts +0 -268
- package/dist/_chunks/index8.d.mts +0 -144
- package/dist/_chunks/invariant.mjs +0 -18
- package/dist/_chunks/iterable.mjs +0 -146
- package/dist/_chunks/libs/graphology-types.d.mts +0 -601
- package/dist/_chunks/libs/graphology.d.mts +0 -6
- package/dist/_chunks/mnemonist.mjs +0 -0
- package/dist/_chunks/model2.mjs +0 -0
- package/dist/_chunks/relationships-view.mjs +0 -132
- package/dist/_chunks/scalar.d.mts +0 -109
- package/dist/_chunks/scalar.mjs +0 -84
- package/dist/compute-view/relationships-view/index.d.mts +0 -16
- package/dist/compute-view/relationships-view/index.mjs +0 -7
- package/dist/model/connection/deployment/index.d.mts +0 -12
- package/dist/model/connection/deployment/index.mjs +0 -9
- package/dist/model/connection/index.d.mts +0 -14
- package/dist/model/connection/index.mjs +0 -10
- package/dist/model/connection/model/index.d.mts +0 -12
- package/dist/model/connection/model/index.mjs +0 -8
- package/dist/types/RichText.d.mts +0 -3
- package/dist/types/RichText.mjs +0 -7
- package/dist/types/_aux.d.mts +0 -3
- package/dist/types/_aux.mjs +0 -3
- package/dist/types/expression-model.d.mts +0 -6
- package/dist/types/expression-model.mjs +0 -7
- package/dist/types/expression.d.mts +0 -5
- package/dist/types/expression.mjs +0 -7
- package/dist/types/fqnRef.d.mts +0 -4
- package/dist/types/fqnRef.mjs +0 -7
- package/dist/types/scalar.d.mts +0 -2
- package/dist/types/scalar.mjs +0 -7
- package/dist/utils/iterable/index.d.mts +0 -9
- package/dist/utils/iterable/index.mjs +0 -3
- package/dist/utils/mnemonist.d.mts +0 -2
- package/dist/utils/mnemonist.mjs +0 -12
package/dist/builder/index.mjs
CHANGED
|
@@ -1,662 +1 @@
|
|
|
1
|
-
import { C as t$5, H as t$1, J as n, O as e, P as e$3, Q as t$6, S as t$7, U as t$4, Y as t$2, Z as t$3, j as e$2, w as t, z as e$1 } from "../_chunks/libs/remeda.mjs";
|
|
2
|
-
import { A as isDeployedInstance, I as exact, N as _stage, P as _type, g as isElementView } from "../_chunks/LikeC4Styles.mjs";
|
|
3
|
-
import "../_chunks/libs/natural-compare-lite.mjs";
|
|
4
|
-
import { D as parentFqn, E as nameFromFqn, T as isSameHierarchy } from "../_chunks/utils.mjs";
|
|
5
|
-
import { t as invariant } from "../_chunks/invariant.mjs";
|
|
6
|
-
import { t as assignTagColors } from "../_chunks/assignTagColors.mjs";
|
|
7
|
-
import "../_chunks/libs/@mantine/colors-generator.mjs";
|
|
8
|
-
import "../_chunks/libs/graphology-dag.mjs";
|
|
9
|
-
import { n as import_default_map } from "../_chunks/libs/mnemonist.mjs";
|
|
10
|
-
import { t as defu } from "../_chunks/libs/defu.mjs";
|
|
11
|
-
import "../_chunks/libs/extend.mjs";
|
|
12
|
-
import { m as isGlobalFqn, v as splitGlobalFqn } from "../_chunks/scalar.mjs";
|
|
13
|
-
import { t as FqnRef } from "../_chunks/fqnRef.mjs";
|
|
14
|
-
import { n as ModelFqnExpr } from "../_chunks/expression-model.mjs";
|
|
15
|
-
import { n as computeLikeC4Model, t as $expr } from "../_chunks/Builder.view-element.mjs";
|
|
16
|
-
import "../_chunks/libs/graphology.mjs";
|
|
17
|
-
|
|
18
|
-
//#region src/builder/Builder.view-common.ts
|
|
19
|
-
function parseWhere(where) {
|
|
20
|
-
if (e(where)) {
|
|
21
|
-
const op = where;
|
|
22
|
-
switch (true) {
|
|
23
|
-
case op.startsWith("tag is not #"): return { tag: { neq: op.replace("tag is not #", "") } };
|
|
24
|
-
case op.startsWith("tag is #"): return { tag: { eq: op.replace("tag is #", "") } };
|
|
25
|
-
case op.startsWith("kind is not "): return { kind: { neq: op.replace("kind is not ", "") } };
|
|
26
|
-
case op.startsWith("kind is "): return { kind: { eq: op.replace("kind is ", "") } };
|
|
27
|
-
case op.startsWith("source."): return {
|
|
28
|
-
operator: parseWhere(op.replace("source.", "")),
|
|
29
|
-
participant: "source"
|
|
30
|
-
};
|
|
31
|
-
case op.startsWith("target."): return {
|
|
32
|
-
operator: parseWhere(op.replace("target.", "")),
|
|
33
|
-
participant: "target"
|
|
34
|
-
};
|
|
35
|
-
default: throw new Error(`Unknown where operator: ${where}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (where.and) return { and: t(where.and, parseWhere) };
|
|
39
|
-
if (where.or) return { or: t(where.or, parseWhere) };
|
|
40
|
-
if (where.not) return { not: parseWhere(where.not) };
|
|
41
|
-
throw new Error(`Unknown where operator: ${where}`);
|
|
42
|
-
}
|
|
43
|
-
function $include(...args) {
|
|
44
|
-
return (b) => {
|
|
45
|
-
let expr = b.$expr(args[0]);
|
|
46
|
-
if (args.length === 2) {
|
|
47
|
-
const condition = args[1].where ? parseWhere(args[1].where) : void 0;
|
|
48
|
-
if (condition) expr = { where: {
|
|
49
|
-
expr,
|
|
50
|
-
condition
|
|
51
|
-
} };
|
|
52
|
-
const custom = args[1].with;
|
|
53
|
-
if (custom) if (ModelFqnExpr.is(expr)) expr = { custom: {
|
|
54
|
-
...custom,
|
|
55
|
-
expr
|
|
56
|
-
} };
|
|
57
|
-
else expr = { customRelation: {
|
|
58
|
-
...custom,
|
|
59
|
-
expr
|
|
60
|
-
} };
|
|
61
|
-
}
|
|
62
|
-
b.include(expr);
|
|
63
|
-
return b;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function $exclude(...args) {
|
|
67
|
-
return (b) => {
|
|
68
|
-
let expr = b.$expr(args[0]);
|
|
69
|
-
if (args.length === 2 && args[1].where) {
|
|
70
|
-
const condition = parseWhere(args[1].where);
|
|
71
|
-
expr = { where: {
|
|
72
|
-
expr,
|
|
73
|
-
condition
|
|
74
|
-
} };
|
|
75
|
-
}
|
|
76
|
-
b.exclude(expr);
|
|
77
|
-
return b;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* @example
|
|
82
|
-
* builder.views(({ view, $style }, _) =>
|
|
83
|
-
* _(
|
|
84
|
-
* view('view1').with(
|
|
85
|
-
* $style('*', {
|
|
86
|
-
* color: 'red',
|
|
87
|
-
* }),
|
|
88
|
-
* $style(['bob', 'alice'], {
|
|
89
|
-
* color: 'blue',
|
|
90
|
-
* }),
|
|
91
|
-
* ),
|
|
92
|
-
* )
|
|
93
|
-
* )
|
|
94
|
-
*/
|
|
95
|
-
function $style(element, { notation, ...style }) {
|
|
96
|
-
return (b) => b.style({
|
|
97
|
-
targets: (e$1(element) ? element : [element]).map((e) => b.$expr(e)),
|
|
98
|
-
...notation ? { notation } : {},
|
|
99
|
-
style: { ...style }
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
function $autoLayout(layout) {
|
|
103
|
-
return (b) => b.autoLayout(layout);
|
|
104
|
-
}
|
|
105
|
-
function $rules(...rules) {
|
|
106
|
-
return (b) => rules.reduce((b, rule) => rule(b), b);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/builder/Builder.view-deployment.ts
|
|
111
|
-
function $deploymentExpr(expr) {
|
|
112
|
-
if (!e(expr)) return expr;
|
|
113
|
-
const asTypedDeploymentExpression = (expr) => {
|
|
114
|
-
return expr;
|
|
115
|
-
};
|
|
116
|
-
if (expr === "*") return asTypedDeploymentExpression({ wildcard: true });
|
|
117
|
-
if (expr.startsWith("->")) {
|
|
118
|
-
if (expr.endsWith("->")) return asTypedDeploymentExpression({ inout: $deploymentExpr(expr.replace(/->/g, "").trim()) });
|
|
119
|
-
return asTypedDeploymentExpression({ incoming: $deploymentExpr(expr.replace("-> ", "")) });
|
|
120
|
-
}
|
|
121
|
-
if (expr.endsWith(" ->")) return asTypedDeploymentExpression({ outgoing: $deploymentExpr(expr.replace(" ->", "")) });
|
|
122
|
-
if (expr.includes(" <-> ")) {
|
|
123
|
-
const [source, target] = expr.split(" <-> ");
|
|
124
|
-
return asTypedDeploymentExpression({
|
|
125
|
-
source: $deploymentExpr(source),
|
|
126
|
-
target: $deploymentExpr(target),
|
|
127
|
-
isBidirectional: true
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
if (expr.includes(" -> ")) {
|
|
131
|
-
const [source, target] = expr.split(" -> ");
|
|
132
|
-
return asTypedDeploymentExpression({
|
|
133
|
-
source: $deploymentExpr(source),
|
|
134
|
-
target: $deploymentExpr(target)
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
if (expr.endsWith("._")) return asTypedDeploymentExpression({
|
|
138
|
-
ref: { deployment: expr.replace("._", "") },
|
|
139
|
-
selector: "expanded"
|
|
140
|
-
});
|
|
141
|
-
if (expr.endsWith(".**")) return asTypedDeploymentExpression({
|
|
142
|
-
ref: { deployment: expr.replace(".**", "") },
|
|
143
|
-
selector: "descendants"
|
|
144
|
-
});
|
|
145
|
-
if (expr.endsWith(".*")) return asTypedDeploymentExpression({
|
|
146
|
-
ref: { deployment: expr.replace(".*", "") },
|
|
147
|
-
selector: "children"
|
|
148
|
-
});
|
|
149
|
-
return asTypedDeploymentExpression({ ref: { deployment: expr } });
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/builder/Builder.views.ts
|
|
154
|
-
function mkViewBuilder(view) {
|
|
155
|
-
const viewBuilder = {
|
|
156
|
-
$expr: view[_type] === "deployment" ? $deploymentExpr : $expr,
|
|
157
|
-
autoLayout(autoLayout) {
|
|
158
|
-
view.rules.push({ direction: autoLayout });
|
|
159
|
-
return viewBuilder;
|
|
160
|
-
},
|
|
161
|
-
exclude(expr) {
|
|
162
|
-
view.rules.push({ exclude: [expr] });
|
|
163
|
-
return viewBuilder;
|
|
164
|
-
},
|
|
165
|
-
include(expr) {
|
|
166
|
-
view.rules.push({ include: [expr] });
|
|
167
|
-
return viewBuilder;
|
|
168
|
-
},
|
|
169
|
-
style(rule) {
|
|
170
|
-
view.rules.push(rule);
|
|
171
|
-
return viewBuilder;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
return viewBuilder;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/builder/Builder.ts
|
|
179
|
-
function ensureObj(value) {
|
|
180
|
-
return e$1(value) ? t$1(value, (_) => ({})) : value;
|
|
181
|
-
}
|
|
182
|
-
function validateSpec({ tags, elements, deployments, relationships, ...specification }) {
|
|
183
|
-
const spectags = {};
|
|
184
|
-
if (tags) Object.assign(spectags, ensureObj(tags));
|
|
185
|
-
const _elements = ensureObj(elements);
|
|
186
|
-
for (const [kind, spec] of t$2(_elements)) if (spec.tags) for (const tag of spec.tags) invariant(tag in spectags, `Invalid specification for element kind "${kind}": tag "${tag}" not found`);
|
|
187
|
-
const _deployments = ensureObj(deployments ?? {});
|
|
188
|
-
for (const [kind, spec] of t$2(_deployments)) if (spec.tags) for (const tag of spec.tags) invariant(tag in spectags, `Invalid specification for deployment kind "${kind}": tag "${tag}" not found`);
|
|
189
|
-
return {
|
|
190
|
-
...specification,
|
|
191
|
-
tags: spectags,
|
|
192
|
-
elements: _elements,
|
|
193
|
-
deployments: _deployments,
|
|
194
|
-
relationships: ensureObj(relationships ?? {})
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
function toMarkdownOrString(input) {
|
|
198
|
-
if (e$2(input)) return null;
|
|
199
|
-
if (typeof input === "string") return { txt: input };
|
|
200
|
-
return input;
|
|
201
|
-
}
|
|
202
|
-
function builder(_spec, _elements = /* @__PURE__ */ new Map(), _relations = [], _views = /* @__PURE__ */ new Map(), _globals = {
|
|
203
|
-
predicates: {},
|
|
204
|
-
dynamicPredicates: {},
|
|
205
|
-
styles: {}
|
|
206
|
-
}, _deployments = /* @__PURE__ */ new Map(), _deploymentRelations = [], _imports = new import_default_map.default(() => /* @__PURE__ */ new Map())) {
|
|
207
|
-
const spec = validateSpec(_spec);
|
|
208
|
-
const toLikeC4Specification = () => {
|
|
209
|
-
return {
|
|
210
|
-
elements: structuredClone(spec.elements),
|
|
211
|
-
deployments: structuredClone(spec.deployments),
|
|
212
|
-
relationships: structuredClone(spec.relationships),
|
|
213
|
-
tags: assignTagColors(structuredClone(spec.tags)),
|
|
214
|
-
...spec.metadataKeys ? { metadataKeys: spec.metadataKeys } : {},
|
|
215
|
-
customColors: {}
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
const mapLinks = (links) => {
|
|
219
|
-
if (!links || !t$3(links, 1)) return;
|
|
220
|
-
return t(links, (l) => typeof l === "string" ? { url: l } : l);
|
|
221
|
-
};
|
|
222
|
-
const createGenericView = (id, _props, builder) => {
|
|
223
|
-
if (e$3(_props)) {
|
|
224
|
-
builder = _props;
|
|
225
|
-
_props = {};
|
|
226
|
-
}
|
|
227
|
-
_props ??= {};
|
|
228
|
-
const { links: _links = [], title = null, description = null, tags = [], ...props } = typeof _props === "string" ? { title: _props } : { ..._props };
|
|
229
|
-
const links = mapLinks(_links);
|
|
230
|
-
return [exact({
|
|
231
|
-
id,
|
|
232
|
-
title,
|
|
233
|
-
description: toMarkdownOrString(description),
|
|
234
|
-
tags,
|
|
235
|
-
links,
|
|
236
|
-
_stage: "parsed",
|
|
237
|
-
...props
|
|
238
|
-
}), builder];
|
|
239
|
-
};
|
|
240
|
-
const checkElementExists = (id) => {
|
|
241
|
-
const [project, fqn] = splitGlobalFqn(id);
|
|
242
|
-
const el = (project ? _imports.get(project) : _elements).get(fqn);
|
|
243
|
-
invariant(el, `Element with id "${id}" not found`);
|
|
244
|
-
return el;
|
|
245
|
-
};
|
|
246
|
-
const parseRelEndpoint = (endpoint) => {
|
|
247
|
-
if (typeof endpoint === "string") {
|
|
248
|
-
const [project, model] = splitGlobalFqn(endpoint);
|
|
249
|
-
if (project) return {
|
|
250
|
-
project,
|
|
251
|
-
model
|
|
252
|
-
};
|
|
253
|
-
return { model };
|
|
254
|
-
}
|
|
255
|
-
if ("project" in endpoint || "deployment" in endpoint) return endpoint;
|
|
256
|
-
return parseRelEndpoint(endpoint.model);
|
|
257
|
-
};
|
|
258
|
-
const self = {
|
|
259
|
-
get Types() {
|
|
260
|
-
throw new Error("Types are not available in runtime");
|
|
261
|
-
},
|
|
262
|
-
clone: () => {
|
|
263
|
-
const imports = new import_default_map.default(() => /* @__PURE__ */ new Map());
|
|
264
|
-
for (const [key, value] of _imports) imports.set(key, structuredClone(value));
|
|
265
|
-
return builder(structuredClone(spec), structuredClone(_elements), structuredClone(_relations), structuredClone(_views), structuredClone(_globals), structuredClone(_deployments), structuredClone(_deploymentRelations), imports);
|
|
266
|
-
},
|
|
267
|
-
__addElement: (element) => {
|
|
268
|
-
const [project, fqn] = splitGlobalFqn(element.id);
|
|
269
|
-
const parent = parentFqn(fqn);
|
|
270
|
-
const lookup = project ? _imports.get(project) : _elements;
|
|
271
|
-
if (parent) invariant(lookup.get(parent), `Parent element with id "${parent}" not found for element with id "${element.id}"`);
|
|
272
|
-
if (lookup.has(fqn)) throw new Error(`Element with id "${element.id}" already exists`);
|
|
273
|
-
lookup.set(fqn, project ? {
|
|
274
|
-
...element,
|
|
275
|
-
id: fqn
|
|
276
|
-
} : element);
|
|
277
|
-
return self;
|
|
278
|
-
},
|
|
279
|
-
__addRelation(relation) {
|
|
280
|
-
const source = parseRelEndpoint(relation.source);
|
|
281
|
-
const sourceFqn = FqnRef.flatten(source);
|
|
282
|
-
const target = parseRelEndpoint(relation.target);
|
|
283
|
-
const targetFqn = FqnRef.flatten(target);
|
|
284
|
-
const sourceEl = checkElementExists(sourceFqn);
|
|
285
|
-
const targetEl = checkElementExists(targetFqn);
|
|
286
|
-
if (isGlobalFqn(sourceFqn) && isGlobalFqn(targetFqn)) throw new Error("Cannot create relationship between global elements");
|
|
287
|
-
if (!isGlobalFqn(sourceFqn) && !isGlobalFqn(targetFqn)) invariant(!isSameHierarchy(sourceEl, targetEl), "Cannot create relationship between elements in the same hierarchy");
|
|
288
|
-
_relations.push({
|
|
289
|
-
id: `rel${_relations.length + 1}`,
|
|
290
|
-
...relation,
|
|
291
|
-
source,
|
|
292
|
-
target
|
|
293
|
-
});
|
|
294
|
-
return self;
|
|
295
|
-
},
|
|
296
|
-
__fqn(id) {
|
|
297
|
-
invariant(id.trim() !== "", "Id must be non-empty");
|
|
298
|
-
return id;
|
|
299
|
-
},
|
|
300
|
-
__deploymentFqn(id) {
|
|
301
|
-
invariant(id.trim() !== "", "Id must be non-empty");
|
|
302
|
-
return id;
|
|
303
|
-
},
|
|
304
|
-
__addSourcelessRelation() {
|
|
305
|
-
throw new Error("Can be called only in nested model");
|
|
306
|
-
},
|
|
307
|
-
__addView: (view) => {
|
|
308
|
-
if (_views.has(view.id)) throw new Error(`View with id "${view.id}" already exists`);
|
|
309
|
-
if (isElementView(view) && "viewOf" in view) invariant(_elements.get(view.viewOf), `Invalid scoped view ${view.id}, wlement with id "${view.viewOf}" not found`);
|
|
310
|
-
_views.set(view.id, view);
|
|
311
|
-
return self;
|
|
312
|
-
},
|
|
313
|
-
__addDeployment: (node) => {
|
|
314
|
-
if (_deployments.has(node.id)) throw new Error(`Deployment with id "${node.id}" already exists`);
|
|
315
|
-
const parent = parentFqn(node.id);
|
|
316
|
-
if (parent) invariant(_deployments.get(parent), `Parent element with id "${parent}" not found for node with id "${node.id}"`);
|
|
317
|
-
if (isDeployedInstance(node)) {
|
|
318
|
-
invariant(parent, `Instance ${node.id} of ${node.element} must be deployed under a parent node`);
|
|
319
|
-
invariant(_elements.get(node.element), `Instance "${node.id}" references non-existing element "${node.element}"`);
|
|
320
|
-
}
|
|
321
|
-
_deployments.set(node.id, node);
|
|
322
|
-
return self;
|
|
323
|
-
},
|
|
324
|
-
__addDeploymentRelation: (relation) => {
|
|
325
|
-
invariant(!isSameHierarchy(relation.source.deployment, relation.target.deployment), "Cannot create relationship between elements in the same hierarchy");
|
|
326
|
-
invariant(_deployments.has(relation.source.deployment), `Relation "${relation.source.deployment} -> ${relation.target.deployment}" references non-existing source`);
|
|
327
|
-
invariant(_deployments.has(relation.target.deployment), `Relation "${relation.source.deployment} -> ${relation.target.deployment}" references non-existing target`);
|
|
328
|
-
_deploymentRelations.push({
|
|
329
|
-
id: `deploy_rel${_deploymentRelations.length + 1}`,
|
|
330
|
-
...relation
|
|
331
|
-
});
|
|
332
|
-
return self;
|
|
333
|
-
},
|
|
334
|
-
build: (project) => ({
|
|
335
|
-
[_stage]: "parsed",
|
|
336
|
-
projectId: typeof project === "string" ? project : project?.id ?? "from-builder",
|
|
337
|
-
project: {
|
|
338
|
-
id: typeof project === "string" ? project : "from-builder",
|
|
339
|
-
...typeof project === "object" && project !== null ? project : {}
|
|
340
|
-
},
|
|
341
|
-
specification: toLikeC4Specification(),
|
|
342
|
-
elements: t$4(structuredClone(Array.from(_elements.entries()))),
|
|
343
|
-
relations: t$5(_relations, (r) => [r.id, structuredClone(r)]),
|
|
344
|
-
globals: structuredClone(_globals),
|
|
345
|
-
deployments: {
|
|
346
|
-
elements: t$4(structuredClone(Array.from(_deployments.entries()))),
|
|
347
|
-
relations: t$5(_deploymentRelations, (r) => [r.id, structuredClone(r)])
|
|
348
|
-
},
|
|
349
|
-
views: t$4(structuredClone(Array.from(_views.entries()))),
|
|
350
|
-
imports: t$6(Array.from(_imports.entries()), t(([projectId, elementsMap]) => [projectId, structuredClone([...elementsMap.values()])]), n(([_, elements]) => elements.length > 0), t$4())
|
|
351
|
-
}),
|
|
352
|
-
toLikeC4Model: (project) => {
|
|
353
|
-
return computeLikeC4Model(self.build(project));
|
|
354
|
-
},
|
|
355
|
-
helpers: () => ({
|
|
356
|
-
model: {
|
|
357
|
-
model: (...ops) => {
|
|
358
|
-
return (b) => {
|
|
359
|
-
return ops.reduce((b, op) => op(b), b);
|
|
360
|
-
};
|
|
361
|
-
},
|
|
362
|
-
rel: (source, target, _props) => {
|
|
363
|
-
return (b) => {
|
|
364
|
-
const { title = "", links: _links = [], description = null, notes = null, ...props } = defu(typeof _props === "string" ? { title: _props } : { ..._props }, {
|
|
365
|
-
title: null,
|
|
366
|
-
links: null
|
|
367
|
-
});
|
|
368
|
-
const links = mapLinks(_links);
|
|
369
|
-
b.__addRelation(exact({
|
|
370
|
-
source: { model: source },
|
|
371
|
-
target: { model: target },
|
|
372
|
-
title,
|
|
373
|
-
...description && { description: toMarkdownOrString(description) },
|
|
374
|
-
...notes && { notes: toMarkdownOrString(notes) },
|
|
375
|
-
links,
|
|
376
|
-
...props
|
|
377
|
-
}));
|
|
378
|
-
return b;
|
|
379
|
-
};
|
|
380
|
-
},
|
|
381
|
-
relTo: (target, _props) => {
|
|
382
|
-
return (b) => {
|
|
383
|
-
const { title = "", links, description = null, notes = null, ...props } = defu(typeof _props === "string" ? { title: _props } : { ..._props }, {
|
|
384
|
-
title: null,
|
|
385
|
-
links: null
|
|
386
|
-
});
|
|
387
|
-
b.__addSourcelessRelation(exact({
|
|
388
|
-
target: { model: target },
|
|
389
|
-
title,
|
|
390
|
-
...description && { description: toMarkdownOrString(description) },
|
|
391
|
-
...notes && { notes: toMarkdownOrString(notes) },
|
|
392
|
-
links: mapLinks(links),
|
|
393
|
-
...props
|
|
394
|
-
}));
|
|
395
|
-
return b;
|
|
396
|
-
};
|
|
397
|
-
},
|
|
398
|
-
...t$7(spec.elements, ({ style: specStyle, ...spec }, kind) => (id, _props) => {
|
|
399
|
-
const add = ((b) => {
|
|
400
|
-
const { links, icon: _icon, color, shape, style, title, description, summary, ...props } = typeof _props === "string" ? { title: _props } : { ..._props };
|
|
401
|
-
const icon = _icon ?? specStyle?.icon;
|
|
402
|
-
const _id = b.__fqn(id);
|
|
403
|
-
b.__addElement(exact({
|
|
404
|
-
id: _id,
|
|
405
|
-
kind,
|
|
406
|
-
title: title ?? nameFromFqn(_id),
|
|
407
|
-
...description && { description: toMarkdownOrString(description) },
|
|
408
|
-
...summary && { summary: toMarkdownOrString(summary) },
|
|
409
|
-
style: exact({
|
|
410
|
-
icon,
|
|
411
|
-
color: color ?? specStyle?.color,
|
|
412
|
-
shape: shape ?? specStyle?.shape,
|
|
413
|
-
border: specStyle?.border,
|
|
414
|
-
opacity: specStyle?.opacity,
|
|
415
|
-
size: specStyle?.size,
|
|
416
|
-
padding: specStyle?.padding,
|
|
417
|
-
textSize: specStyle?.textSize,
|
|
418
|
-
...style
|
|
419
|
-
}),
|
|
420
|
-
links: mapLinks(links),
|
|
421
|
-
...spec,
|
|
422
|
-
...props
|
|
423
|
-
}));
|
|
424
|
-
return b;
|
|
425
|
-
});
|
|
426
|
-
add.with = (...ops) => (b) => {
|
|
427
|
-
add(b);
|
|
428
|
-
const { __fqn, __addSourcelessRelation } = b;
|
|
429
|
-
try {
|
|
430
|
-
b.__fqn = (child) => `${__fqn(id)}.${child}`;
|
|
431
|
-
b.__addSourcelessRelation = (relation) => {
|
|
432
|
-
return b.__addRelation({
|
|
433
|
-
...relation,
|
|
434
|
-
source: { model: __fqn(id) }
|
|
435
|
-
});
|
|
436
|
-
};
|
|
437
|
-
ops.reduce((b, op) => op(b), b);
|
|
438
|
-
} finally {
|
|
439
|
-
b.__fqn = __fqn;
|
|
440
|
-
b.__addSourcelessRelation = __addSourcelessRelation;
|
|
441
|
-
}
|
|
442
|
-
return b;
|
|
443
|
-
};
|
|
444
|
-
return add;
|
|
445
|
-
})
|
|
446
|
-
},
|
|
447
|
-
views: {
|
|
448
|
-
views: (...ops) => {
|
|
449
|
-
return (b) => {
|
|
450
|
-
return ops.reduce((b, op) => op(b), b);
|
|
451
|
-
};
|
|
452
|
-
},
|
|
453
|
-
view: (id, _props, _builder) => {
|
|
454
|
-
const [generic, builder] = createGenericView(id, _props, _builder);
|
|
455
|
-
const view = {
|
|
456
|
-
...generic,
|
|
457
|
-
[_type]: "element",
|
|
458
|
-
rules: []
|
|
459
|
-
};
|
|
460
|
-
const add = (b) => {
|
|
461
|
-
b.__addView(view);
|
|
462
|
-
if (builder) builder(mkViewBuilder(view));
|
|
463
|
-
return b;
|
|
464
|
-
};
|
|
465
|
-
add.with = (...ops) => (b) => {
|
|
466
|
-
add(b);
|
|
467
|
-
const elementViewBuilder = mkViewBuilder(view);
|
|
468
|
-
for (const op of ops) op(elementViewBuilder);
|
|
469
|
-
return b;
|
|
470
|
-
};
|
|
471
|
-
return add;
|
|
472
|
-
},
|
|
473
|
-
viewOf: (id, viewOf, _props, _builder) => {
|
|
474
|
-
const [generic, builder] = createGenericView(id, _props, _builder);
|
|
475
|
-
const view = {
|
|
476
|
-
...generic,
|
|
477
|
-
viewOf,
|
|
478
|
-
[_type]: "element",
|
|
479
|
-
rules: []
|
|
480
|
-
};
|
|
481
|
-
const add = (b) => {
|
|
482
|
-
b.__addView(view);
|
|
483
|
-
if (builder) builder(mkViewBuilder(view));
|
|
484
|
-
return b;
|
|
485
|
-
};
|
|
486
|
-
add.with = (...ops) => (b) => {
|
|
487
|
-
add(b);
|
|
488
|
-
const elementViewBuilder = mkViewBuilder(view);
|
|
489
|
-
for (const op of ops) op(elementViewBuilder);
|
|
490
|
-
return b;
|
|
491
|
-
};
|
|
492
|
-
return add;
|
|
493
|
-
},
|
|
494
|
-
deploymentView: (id, _props, _builder) => {
|
|
495
|
-
const [generic, builder] = createGenericView(id, _props, _builder);
|
|
496
|
-
const view = {
|
|
497
|
-
...generic,
|
|
498
|
-
[_type]: "deployment",
|
|
499
|
-
rules: []
|
|
500
|
-
};
|
|
501
|
-
const add = (b) => {
|
|
502
|
-
b.__addView(view);
|
|
503
|
-
if (builder) builder(mkViewBuilder(view));
|
|
504
|
-
return b;
|
|
505
|
-
};
|
|
506
|
-
add.with = (...ops) => (b) => {
|
|
507
|
-
add(b);
|
|
508
|
-
const elementViewBuilder = mkViewBuilder(view);
|
|
509
|
-
for (const op of ops) op(elementViewBuilder);
|
|
510
|
-
return b;
|
|
511
|
-
};
|
|
512
|
-
return add;
|
|
513
|
-
},
|
|
514
|
-
$autoLayout,
|
|
515
|
-
$exclude,
|
|
516
|
-
$include,
|
|
517
|
-
$rules,
|
|
518
|
-
$style
|
|
519
|
-
},
|
|
520
|
-
deployment: {
|
|
521
|
-
deployment: (...ops) => {
|
|
522
|
-
return (b) => {
|
|
523
|
-
return ops.reduce((b, op) => op(b), b);
|
|
524
|
-
};
|
|
525
|
-
},
|
|
526
|
-
instanceOf: (id, target, _props) => {
|
|
527
|
-
return (b) => {
|
|
528
|
-
if (e$2(target)) {
|
|
529
|
-
target = id;
|
|
530
|
-
id = nameFromFqn(id);
|
|
531
|
-
} else if (typeof target === "string") _props ??= {};
|
|
532
|
-
else {
|
|
533
|
-
_props = target;
|
|
534
|
-
target = id;
|
|
535
|
-
id = nameFromFqn(id);
|
|
536
|
-
}
|
|
537
|
-
const { links, title, description, summary, icon, color, shape, style, ...props } = typeof _props === "string" ? { title: _props } : { ..._props };
|
|
538
|
-
const _id = b.__deploymentFqn(id);
|
|
539
|
-
b.__addDeployment(exact({
|
|
540
|
-
id: _id,
|
|
541
|
-
element: target,
|
|
542
|
-
...title && { title },
|
|
543
|
-
...summary && { summary: toMarkdownOrString(summary) },
|
|
544
|
-
...description && { description: toMarkdownOrString(description) },
|
|
545
|
-
style: exact({
|
|
546
|
-
icon,
|
|
547
|
-
color,
|
|
548
|
-
shape,
|
|
549
|
-
...style
|
|
550
|
-
}),
|
|
551
|
-
links: mapLinks(links),
|
|
552
|
-
...props
|
|
553
|
-
}));
|
|
554
|
-
return b;
|
|
555
|
-
};
|
|
556
|
-
},
|
|
557
|
-
rel: (source, target, _props) => {
|
|
558
|
-
return (b) => {
|
|
559
|
-
const { title = null, links, description = null, notes = null, ...props } = typeof _props === "string" ? { title: _props } : { ..._props };
|
|
560
|
-
b.__addDeploymentRelation(exact({
|
|
561
|
-
source: { deployment: source },
|
|
562
|
-
target: { deployment: target },
|
|
563
|
-
title,
|
|
564
|
-
...description && { description: toMarkdownOrString(description) },
|
|
565
|
-
...notes && { notes: toMarkdownOrString(notes) },
|
|
566
|
-
links: mapLinks(links),
|
|
567
|
-
...props
|
|
568
|
-
}));
|
|
569
|
-
return b;
|
|
570
|
-
};
|
|
571
|
-
},
|
|
572
|
-
...t$7(spec.deployments ?? {}, ({ style: specStyle, ...spec }, kind) => (id, _props) => {
|
|
573
|
-
const add = ((b) => {
|
|
574
|
-
const { links, icon: _icon, style, title, description, summary, color, shape, ...props } = typeof _props === "string" ? { title: _props } : { ..._props };
|
|
575
|
-
const icon = _icon ?? specStyle?.icon;
|
|
576
|
-
const _id = b.__deploymentFqn(id);
|
|
577
|
-
b.__addDeployment(exact({
|
|
578
|
-
id: _id,
|
|
579
|
-
kind,
|
|
580
|
-
title: title ?? nameFromFqn(_id),
|
|
581
|
-
...description && { description: toMarkdownOrString(description) },
|
|
582
|
-
...summary && { summary: toMarkdownOrString(summary) },
|
|
583
|
-
style: exact({
|
|
584
|
-
icon,
|
|
585
|
-
color: color ?? specStyle?.color,
|
|
586
|
-
shape: shape ?? specStyle?.shape,
|
|
587
|
-
border: specStyle?.border,
|
|
588
|
-
opacity: specStyle?.opacity,
|
|
589
|
-
size: specStyle?.size,
|
|
590
|
-
padding: specStyle?.padding,
|
|
591
|
-
textSize: specStyle?.textSize,
|
|
592
|
-
...style
|
|
593
|
-
}),
|
|
594
|
-
links: mapLinks(links),
|
|
595
|
-
...spec,
|
|
596
|
-
...props
|
|
597
|
-
}));
|
|
598
|
-
return b;
|
|
599
|
-
});
|
|
600
|
-
add.with = (...ops) => (b) => {
|
|
601
|
-
add(b);
|
|
602
|
-
const { __deploymentFqn } = b;
|
|
603
|
-
try {
|
|
604
|
-
b.__deploymentFqn = (child) => `${__deploymentFqn(id)}.${child}`;
|
|
605
|
-
ops.reduce((b, op) => op(b), b);
|
|
606
|
-
} finally {
|
|
607
|
-
b.__deploymentFqn = __deploymentFqn;
|
|
608
|
-
}
|
|
609
|
-
return b;
|
|
610
|
-
};
|
|
611
|
-
return add;
|
|
612
|
-
})
|
|
613
|
-
}
|
|
614
|
-
}),
|
|
615
|
-
with: (...ops) => {
|
|
616
|
-
const b = self.clone();
|
|
617
|
-
return ops.reduce((b, op) => op(b), b);
|
|
618
|
-
},
|
|
619
|
-
model: (cb) => {
|
|
620
|
-
const b = self.clone();
|
|
621
|
-
const helpers = b.helpers().model;
|
|
622
|
-
const _ = helpers.model;
|
|
623
|
-
return cb({
|
|
624
|
-
...helpers,
|
|
625
|
-
_
|
|
626
|
-
}, _)(b);
|
|
627
|
-
},
|
|
628
|
-
deployment: (cb) => {
|
|
629
|
-
const b = self.clone();
|
|
630
|
-
const helpers = b.helpers().deployment;
|
|
631
|
-
const _ = helpers.deployment;
|
|
632
|
-
return cb({
|
|
633
|
-
...helpers,
|
|
634
|
-
_
|
|
635
|
-
}, _)(b);
|
|
636
|
-
},
|
|
637
|
-
views: (cb) => {
|
|
638
|
-
const b = self.clone();
|
|
639
|
-
const helpers = b.helpers().views;
|
|
640
|
-
return cb({
|
|
641
|
-
...helpers,
|
|
642
|
-
_: helpers.views
|
|
643
|
-
}, helpers.views)(b);
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
return self;
|
|
647
|
-
}
|
|
648
|
-
const Builder = {
|
|
649
|
-
forSpecification(spec) {
|
|
650
|
-
const b = builder(spec);
|
|
651
|
-
return {
|
|
652
|
-
...b.helpers(),
|
|
653
|
-
builder: b
|
|
654
|
-
};
|
|
655
|
-
},
|
|
656
|
-
specification(spec) {
|
|
657
|
-
return builder(spec);
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
//#endregion
|
|
662
|
-
export { Builder };
|
|
1
|
+
import{t as e}from"../_chunks/libs/defu.mjs";import{B as t,C as n,F as r,M as i,Q as a,T as o,U as s,W as c,X as l,Y as u,et as d,k as f,w as p}from"../_chunks/libs/remeda.mjs";import{B as m,J as h,U as g,_t as _,g as v,gt as y,lt as b,pt as x,xt as S}from"../_chunks/types.mjs";import"../_chunks/geometry.mjs";import{B as C,Q as w,R as T,z as E}from"../_chunks/utils.mjs";import"../_chunks/libs/graphology-dag.mjs";import{t as D}from"../_chunks/libs/mnemonist.mjs";import"../_chunks/libs/natural-compare-lite.mjs";import"../_chunks/libs/ohash.mjs";import"../_chunks/libs/@ungap/structured-clone.mjs";import"../_chunks/libs/hast-util-sanitize.mjs";import"../_chunks/libs/rehype-sanitize.mjs";import"../_chunks/libs/hast-util-to-html.mjs";import"../_chunks/libs/character-entities-legacy.mjs";import"../_chunks/libs/character-entities-html4.mjs";import"../_chunks/libs/ccount.mjs";import"../_chunks/libs/comma-separated-tokens.mjs";import"../_chunks/libs/rehype-stringify.mjs";import"../_chunks/libs/devlop.mjs";import"../_chunks/libs/mdast-util-from-markdown.mjs";import"../_chunks/libs/escape-string-regexp.mjs";import"../_chunks/libs/mdast-util-find-and-replace.mjs";import"../_chunks/libs/mdast-util-gfm.mjs";import"../_chunks/libs/markdown-table.mjs";import"../_chunks/libs/longest-streak.mjs";import"../_chunks/libs/character-entities.mjs";import"../_chunks/libs/decode-named-character-reference.mjs";import"../_chunks/libs/micromark-extension-gfm.mjs";import"../_chunks/libs/remark-gfm.mjs";import"../_chunks/libs/remark-github-blockquote-alert.mjs";import"../_chunks/libs/remark-parse.mjs";import"../_chunks/libs/mdast-util-to-hast.mjs";import"../_chunks/libs/remark-rehype.mjs";import"../_chunks/libs/bail.mjs";import"../_chunks/libs/extend.mjs";import"../_chunks/libs/is-plain-obj.mjs";import"../_chunks/libs/trough.mjs";import"../_chunks/libs/unified.mjs";import"../_chunks/libs/@radix-ui/colors.mjs";import"../_chunks/libs/@mantine/colors-generator.mjs";import"../_chunks/model.mjs";import"../_chunks/manual-layout.mjs";import{n as O,t as k}from"../_chunks/Builder.view-element.mjs";import"../_chunks/libs/graphology.mjs";import{t as A}from"../_chunks/assignTagColors.mjs";function j(e){if(f(e)){let t=e;switch(!0){case t.startsWith(`tag is not #`):return{tag:{neq:t.replace(`tag is not #`,``)}};case t.startsWith(`tag is #`):return{tag:{eq:t.replace(`tag is #`,``)}};case t.startsWith(`kind is not `):return{kind:{neq:t.replace(`kind is not `,``)}};case t.startsWith(`kind is `):return{kind:{eq:t.replace(`kind is `,``)}};case t.startsWith(`source.`):return{operator:j(t.replace(`source.`,``)),participant:`source`};case t.startsWith(`target.`):return{operator:j(t.replace(`target.`,``)),participant:`target`};default:throw Error(`Unknown where operator: ${e}`)}}if(e.and)return{and:o(e.and,j)};if(e.or)return{or:o(e.or,j)};if(e.not)return{not:j(e.not)};throw Error(`Unknown where operator: ${e}`)}function M(...e){return t=>{let n=t.$expr(e[0]);if(e.length===2){let t=e[1].where?j(e[1].where):void 0;t&&(n={where:{expr:n,condition:t}});let r=e[1].with;r&&(n=g.is(n)?{custom:{...r,expr:n}}:{customRelation:{...r,expr:n}})}return t.include(n),t}}function N(...e){return t=>{let n=t.$expr(e[0]);if(e.length===2&&e[1].where){let t=j(e[1].where);n={where:{expr:n,condition:t}}}return t.exclude(n),t}}function P(e,{notation:n,...r}){return i=>i.style({targets:(t(e)?e:[e]).map(e=>i.$expr(e)),...n?{notation:n}:{},style:{...r}})}function F(e){return t=>t.autoLayout(e)}function I(...e){return t=>e.reduce((e,t)=>t(e),t)}function L(e){if(!f(e))return e;let t=e=>e;if(e===`*`)return t({wildcard:!0});if(e.startsWith(`->`))return e.endsWith(`->`)?t({inout:L(e.replace(/->/g,``).trim())}):t({incoming:L(e.replace(`-> `,``))});if(e.endsWith(` ->`))return t({outgoing:L(e.replace(` ->`,``))});if(e.includes(` <-> `)){let[n,r]=e.split(` <-> `);return t({source:L(n),target:L(r),isBidirectional:!0})}if(e.includes(` -> `)){let[n,r]=e.split(` -> `);return t({source:L(n),target:L(r)})}return e.endsWith(`._`)?t({ref:{deployment:e.replace(`._`,``)},selector:`expanded`}):e.endsWith(`.**`)?t({ref:{deployment:e.replace(`.**`,``)},selector:`descendants`}):e.endsWith(`.*`)?t({ref:{deployment:e.replace(`.*`,``)},selector:`children`}):t({ref:{deployment:e}})}function R(e){let t={$expr:e[_]===`deployment`?L:k,autoLayout(n){return e.rules.push({direction:n}),t},exclude(n){return e.rules.push({exclude:[n]}),t},include(n){return e.rules.push({include:[n]}),t},style(n){return e.rules.push(n),t}};return t}function z(e){return t(e)?s(e,e=>({})):e}function B({tags:e,elements:t,deployments:n,relationships:r,...i}){let a={};e&&Object.assign(a,z(e));let o=z(t);for(let[e,t]of l(o))if(t.tags)for(let n of t.tags)w(n in a,`Invalid specification for element kind "${e}": tag "${n}" not found`);let s=z(n??{});for(let[e,t]of l(s))if(t.tags)for(let n of t.tags)w(n in a,`Invalid specification for deployment kind "${e}": tag "${n}" not found`);return{...i,tags:a,elements:o,deployments:s,relationships:z(r??{})}}function V(e){return i(e)?null:typeof e==`string`?{txt:e}:e}function H(t,s=new Map,l=[],f=new Map,g={predicates:{},dynamicPredicates:{},styles:{}},k=new Map,j=[],L=new D.default(()=>new Map)){let z=B(t),U=()=>({elements:structuredClone(z.elements),deployments:structuredClone(z.deployments),relationships:structuredClone(z.relationships),tags:A(structuredClone(z.tags)),...z.metadataKeys?{metadataKeys:z.metadataKeys}:{},customColors:{}}),W=e=>{if(!(!e||!a(e,1)))return o(e,e=>typeof e==`string`?{url:e}:e)},G=(e,t,n)=>{r(t)&&(n=t,t={}),t??={};let{links:i=[],title:a=null,description:o=null,tags:s=[],...c}=typeof t==`string`?{title:t}:{...t},l=W(i);return[S({id:e,title:a,description:V(o),tags:s,links:l,_stage:`parsed`,...c}),n]},K=e=>{let[t,n]=x(e),r=(t?L.get(t):s).get(n);return w(r,`Element with id "${e}" not found`),r},q=e=>{if(typeof e==`string`){let[t,n]=x(e);return t?{project:t,model:n}:{model:n}}return`project`in e||`deployment`in e?e:q(e.model)},J={get Types(){throw Error(`Types are not available in runtime`)},clone:()=>{let e=new D.default(()=>new Map);for(let[t,n]of L)e.set(t,structuredClone(n));return H(structuredClone(z),structuredClone(s),structuredClone(l),structuredClone(f),structuredClone(g),structuredClone(k),structuredClone(j),e)},__addElement:e=>{let[t,n]=x(e.id),r=C(n),i=t?L.get(t):s;if(r&&w(i.get(r),`Parent element with id "${r}" not found for element with id "${e.id}"`),i.has(n))throw Error(`Element with id "${e.id}" already exists`);return i.set(n,t?{...e,id:n}:e),J},__addRelation(e){let t=q(e.source),n=h.flatten(t),r=q(e.target),i=h.flatten(r),a=K(n),o=K(i);if(b(n)&&b(i))throw Error(`Cannot create relationship between global elements`);return!b(n)&&!b(i)&&w(!T(a,o),`Cannot create relationship between elements in the same hierarchy`),l.push({id:`rel${l.length+1}`,...e,source:t,target:r}),J},__fqn(e){return w(e.trim()!==``,`Id must be non-empty`),e},__deploymentFqn(e){return w(e.trim()!==``,`Id must be non-empty`),e},__addSourcelessRelation(){throw Error(`Can be called only in nested model`)},__addView:e=>{if(f.has(e.id))throw Error(`View with id "${e.id}" already exists`);return v(e)&&`viewOf`in e&&w(s.get(e.viewOf),`Invalid scoped view ${e.id}, wlement with id "${e.viewOf}" not found`),f.set(e.id,e),J},__addDeployment:e=>{if(k.has(e.id))throw Error(`Deployment with id "${e.id}" already exists`);let t=C(e.id);return t&&w(k.get(t),`Parent element with id "${t}" not found for node with id "${e.id}"`),m(e)&&(w(t,`Instance ${e.id} of ${e.element} must be deployed under a parent node`),w(s.get(e.element),`Instance "${e.id}" references non-existing element "${e.element}"`)),k.set(e.id,e),J},__addDeploymentRelation:e=>(w(!T(e.source.deployment,e.target.deployment),`Cannot create relationship between elements in the same hierarchy`),w(k.has(e.source.deployment),`Relation "${e.source.deployment} -> ${e.target.deployment}" references non-existing source`),w(k.has(e.target.deployment),`Relation "${e.source.deployment} -> ${e.target.deployment}" references non-existing target`),j.push({id:`deploy_rel${j.length+1}`,...e}),J),build:e=>({[y]:`parsed`,projectId:typeof e==`string`?e:e?.id??`from-builder`,project:{id:typeof e==`string`?e:`from-builder`,...typeof e==`object`&&e?e:{}},specification:U(),elements:c(structuredClone(Array.from(s.entries()))),relations:p(l,e=>[e.id,structuredClone(e)]),globals:structuredClone(g),deployments:{elements:c(structuredClone(Array.from(k.entries()))),relations:p(j,e=>[e.id,structuredClone(e)])},views:c(structuredClone(Array.from(f.entries()))),imports:d(Array.from(L.entries()),o(([e,t])=>[e,structuredClone([...t.values()])]),u(([e,t])=>t.length>0),c())}),toLikeC4Model:e=>O(J.build(e)),helpers:()=>({model:{model:(...e)=>t=>e.reduce((e,t)=>t(e),t),rel:(t,n,r)=>i=>{let{title:a=``,links:o=[],description:s=null,notes:c=null,...l}=e(typeof r==`string`?{title:r}:{...r},{title:null,links:null}),u=W(o);return i.__addRelation(S({source:{model:t},target:{model:n},title:a,...s&&{description:V(s)},...c&&{notes:V(c)},links:u,...l})),i},relTo:(t,n)=>r=>{let{title:i=``,links:a,description:o=null,notes:s=null,...c}=e(typeof n==`string`?{title:n}:{...n},{title:null,links:null});return r.__addSourcelessRelation(S({target:{model:t},title:i,...o&&{description:V(o)},...s&&{notes:V(s)},links:W(a),...c})),r},...n(z.elements,({style:e,...t},n)=>(r,i)=>{let a=(a=>{let{links:o,icon:s,color:c,shape:l,style:u,title:d,description:f,summary:p,...m}=typeof i==`string`?{title:i}:{...i},h=s??e?.icon,g=a.__fqn(r);return a.__addElement(S({id:g,kind:n,title:d??E(g),...f&&{description:V(f)},...p&&{summary:V(p)},style:S({icon:h,color:c??e?.color,shape:l??e?.shape,border:e?.border,opacity:e?.opacity,size:e?.size,padding:e?.padding,textSize:e?.textSize,...u}),links:W(o),...t,...m})),a});return a.with=(...e)=>t=>{a(t);let{__fqn:n,__addSourcelessRelation:i}=t;try{t.__fqn=e=>`${n(r)}.${e}`,t.__addSourcelessRelation=e=>t.__addRelation({...e,source:{model:n(r)}}),e.reduce((e,t)=>t(e),t)}finally{t.__fqn=n,t.__addSourcelessRelation=i}return t},a})},views:{views:(...e)=>t=>e.reduce((e,t)=>t(e),t),view:(e,t,n)=>{let[r,i]=G(e,t,n),a={...r,[_]:`element`,rules:[]},o=e=>(e.__addView(a),i&&i(R(a)),e);return o.with=(...e)=>t=>{o(t);let n=R(a);for(let t of e)t(n);return t},o},viewOf:(e,t,n,r)=>{let[i,a]=G(e,n,r),o={...i,viewOf:t,[_]:`element`,rules:[]},s=e=>(e.__addView(o),a&&a(R(o)),e);return s.with=(...e)=>t=>{s(t);let n=R(o);for(let t of e)t(n);return t},s},deploymentView:(e,t,n)=>{let[r,i]=G(e,t,n),a={...r,[_]:`deployment`,rules:[]},o=e=>(e.__addView(a),i&&i(R(a)),e);return o.with=(...e)=>t=>{o(t);let n=R(a);for(let t of e)t(n);return t},o},$autoLayout:F,$exclude:N,$include:M,$rules:I,$style:P},deployment:{deployment:(...e)=>t=>e.reduce((e,t)=>t(e),t),instanceOf:(e,t,n)=>r=>{i(t)?(t=e,e=E(e)):typeof t==`string`?n??={}:(n=t,t=e,e=E(e));let{links:a,title:o,description:s,summary:c,icon:l,color:u,shape:d,style:f,...p}=typeof n==`string`?{title:n}:{...n},m=r.__deploymentFqn(e);return r.__addDeployment(S({id:m,element:t,...o&&{title:o},...c&&{summary:V(c)},...s&&{description:V(s)},style:S({icon:l,color:u,shape:d,...f}),links:W(a),...p})),r},rel:(e,t,n)=>r=>{let{title:i=null,links:a,description:o=null,notes:s=null,...c}=typeof n==`string`?{title:n}:{...n};return r.__addDeploymentRelation(S({source:{deployment:e},target:{deployment:t},title:i,...o&&{description:V(o)},...s&&{notes:V(s)},links:W(a),...c})),r},...n(z.deployments??{},({style:e,...t},n)=>(r,i)=>{let a=(a=>{let{links:o,icon:s,style:c,title:l,description:u,summary:d,color:f,shape:p,...m}=typeof i==`string`?{title:i}:{...i},h=s??e?.icon,g=a.__deploymentFqn(r);return a.__addDeployment(S({id:g,kind:n,title:l??E(g),...u&&{description:V(u)},...d&&{summary:V(d)},style:S({icon:h,color:f??e?.color,shape:p??e?.shape,border:e?.border,opacity:e?.opacity,size:e?.size,padding:e?.padding,textSize:e?.textSize,...c}),links:W(o),...t,...m})),a});return a.with=(...e)=>t=>{a(t);let{__deploymentFqn:n}=t;try{t.__deploymentFqn=e=>`${n(r)}.${e}`,e.reduce((e,t)=>t(e),t)}finally{t.__deploymentFqn=n}return t},a})}}),with:(...e)=>{let t=J.clone();return e.reduce((e,t)=>t(e),t)},model:e=>{let t=J.clone(),n=t.helpers().model,r=n.model;return e({...n,_:r},r)(t)},deployment:e=>{let t=J.clone(),n=t.helpers().deployment,r=n.deployment;return e({...n,_:r},r)(t)},views:e=>{let t=J.clone(),n=t.helpers().views;return e({...n,_:n.views},n.views)(t)}};return J}const U={forSpecification(e){let t=H(e);return{...t.helpers(),builder:t}},specification(e){return H(e)}};export{U as Builder};
|