@likec4/generators 1.52.0 → 1.53.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/_chunks/chunk.mjs +11 -0
- package/dist/index.d.mts +18 -1
- package/dist/index.mjs +189 -47
- package/dist/likec4/index.d.mts +277169 -0
- package/dist/likec4/index.mjs +1799 -0
- package/likec4/package.json +4 -0
- package/package.json +22 -8
- package/src/drawio/generate-drawio.ts +73 -8
- package/src/drawio/index.ts +1 -0
- package/src/drawio/parse-drawio.ts +172 -18
- package/src/index.ts +2 -0
- package/src/likec4/generate-likec4.ts +72 -0
- package/src/likec4/index.ts +12 -0
- package/src/likec4/operators/base.ts +938 -0
- package/src/likec4/operators/deployment.ts +263 -0
- package/src/likec4/operators/expressions.ts +422 -0
- package/src/likec4/operators/index.ts +13 -0
- package/src/likec4/operators/likec4data.ts +33 -0
- package/src/likec4/operators/model.ts +222 -0
- package/src/likec4/operators/properties.ts +244 -0
- package/src/likec4/operators/specification.ts +119 -0
- package/src/likec4/operators/views.ts +390 -0
- package/src/likec4/schemas/common.ts +123 -0
- package/src/likec4/schemas/deployment.ts +113 -0
- package/src/likec4/schemas/expression.ts +218 -0
- package/src/likec4/schemas/index.ts +83 -0
- package/src/likec4/schemas/likec4data.ts +76 -0
- package/src/likec4/schemas/model.ts +127 -0
- package/src/likec4/schemas/specification.ts +83 -0
- package/src/likec4/schemas/views.ts +321 -0
- package/src/model/generate-likec4.ts +0 -5
|
@@ -0,0 +1,1799 @@
|
|
|
1
|
+
import { t as __exportAll } from "../_chunks/chunk.mjs";
|
|
2
|
+
import { CompositeGeneratorNode, NL, NewLineNode, joinToNode, toString } from "langium/generate";
|
|
3
|
+
import { entries, filter, hasAtLeast, identity, indexBy, isArray, isDeepEqual, isEmptyish, isFunction, isNonNullish, isNot, isNullish, isNumber, isObjectType, isString, map, mapToObj, mapValues, only, pickBy, pipe, piped, prop, randomString, values } from "remeda";
|
|
4
|
+
import { hasProp, invariant, nonexhaustive } from "@likec4/core";
|
|
5
|
+
import { exact } from "@likec4/core/types";
|
|
6
|
+
import { invariant as invariant$1, nameFromFqn, parentFqn, sortParentsFirst } from "@likec4/core/utils";
|
|
7
|
+
import { dedent } from "strip-indent";
|
|
8
|
+
import * as z$1 from "zod/v4";
|
|
9
|
+
import { BorderStyles, ElementShapes, IconPositions, RelationshipArrowTypes, Sizes, ThemeColors } from "@likec4/core/styles";
|
|
10
|
+
import { produce } from "immer";
|
|
11
|
+
import { LikeC4StylesConfigSchema } from "@likec4/config";
|
|
12
|
+
var base_exports = /* @__PURE__ */ __exportAll({
|
|
13
|
+
body: () => body,
|
|
14
|
+
eachOnFresh: () => eachOnFresh,
|
|
15
|
+
eq: () => eq,
|
|
16
|
+
executeOnCtx: () => executeOnCtx,
|
|
17
|
+
executeOnFresh: () => executeOnFresh,
|
|
18
|
+
foreach: () => foreach,
|
|
19
|
+
foreachNewLine: () => foreachNewLine,
|
|
20
|
+
fresh: () => fresh,
|
|
21
|
+
guard: () => guard,
|
|
22
|
+
indent: () => indent,
|
|
23
|
+
inlineText: () => inlineText,
|
|
24
|
+
join: () => join,
|
|
25
|
+
lazy: () => lazy,
|
|
26
|
+
lines: () => lines,
|
|
27
|
+
markdown: () => markdown,
|
|
28
|
+
markdownOrString: () => markdownOrString$1,
|
|
29
|
+
materialize: () => materialize,
|
|
30
|
+
merge: () => merge,
|
|
31
|
+
newline: () => newline,
|
|
32
|
+
noop: () => noop,
|
|
33
|
+
operation: () => operation,
|
|
34
|
+
print: () => print$1,
|
|
35
|
+
printProperty: () => printProperty,
|
|
36
|
+
property: () => property,
|
|
37
|
+
select: () => select,
|
|
38
|
+
separateComma: () => separateComma,
|
|
39
|
+
separateNewLine: () => separateNewLine,
|
|
40
|
+
separateWith: () => separateWith,
|
|
41
|
+
space: () => space,
|
|
42
|
+
spaceBetween: () => spaceBetween,
|
|
43
|
+
text: () => text,
|
|
44
|
+
when: () => when,
|
|
45
|
+
withctx: () => withctx,
|
|
46
|
+
zodOp: () => zodOp
|
|
47
|
+
});
|
|
48
|
+
function hasContent(out) {
|
|
49
|
+
if (typeof out === "string") return out.trimStart().length !== 0;
|
|
50
|
+
if (out instanceof CompositeGeneratorNode) return out.contents.some((e) => hasContent(e));
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
function hasContentOrNewLine(out) {
|
|
54
|
+
if (typeof out === "string") return out.trimStart().length !== 0;
|
|
55
|
+
if (out instanceof NewLineNode) return !out.ifNotEmpty;
|
|
56
|
+
if (out instanceof CompositeGeneratorNode) return out.contents.some((e) => hasContentOrNewLine(e));
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
function fresh(ctx) {
|
|
60
|
+
return {
|
|
61
|
+
ctx: ctx ?? void 0,
|
|
62
|
+
out: new CompositeGeneratorNode()
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Materialize context or operation into a string
|
|
67
|
+
*/
|
|
68
|
+
function materialize(ctx, defaultIndentation = 2) {
|
|
69
|
+
return toString(isFunction(ctx) ? executeOnFresh(void 0, [ctx]).out : ctx.out, defaultIndentation).replaceAll(/\r\n/g, "\n");
|
|
70
|
+
}
|
|
71
|
+
function executeOnCtx(ctx, op, ...ops) {
|
|
72
|
+
if (isArray(op)) {
|
|
73
|
+
invariant(ops.length === 0, "When first argument is an array, no additional operations are allowed");
|
|
74
|
+
ops = op;
|
|
75
|
+
} else ops = [op, ...ops];
|
|
76
|
+
for (const o of ops) ctx = o(ctx);
|
|
77
|
+
return ctx;
|
|
78
|
+
}
|
|
79
|
+
function executeOnFresh(ctx, op, ...ops) {
|
|
80
|
+
if (isArray(op)) return executeOnCtx(fresh(ctx), op);
|
|
81
|
+
return executeOnCtx(fresh(ctx), [op, ...ops]);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Execute each operation on a fresh context (new empty output node)
|
|
85
|
+
* This is map operation
|
|
86
|
+
*/
|
|
87
|
+
function eachOnFresh(ctx, ops) {
|
|
88
|
+
return ops.map((op) => op(fresh(ctx)));
|
|
89
|
+
}
|
|
90
|
+
function operation(opOrName, fn) {
|
|
91
|
+
const operationFn = typeof opOrName === "function" ? opOrName : fn;
|
|
92
|
+
const wrapped = (input) => {
|
|
93
|
+
const result = operationFn(input);
|
|
94
|
+
if (result instanceof CompositeGeneratorNode) return {
|
|
95
|
+
...input,
|
|
96
|
+
out: result
|
|
97
|
+
};
|
|
98
|
+
return input;
|
|
99
|
+
};
|
|
100
|
+
if (typeof opOrName === "string" && operationFn.name == "") Object.defineProperties(wrapped, { name: { value: `wrapped(${opOrName})` } });
|
|
101
|
+
return wrapped;
|
|
102
|
+
}
|
|
103
|
+
function isPrintable(value) {
|
|
104
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
105
|
+
}
|
|
106
|
+
function print$1(value) {
|
|
107
|
+
return operation(function printOp({ ctx, out }) {
|
|
108
|
+
let v = typeof value === "function" ? value(ctx) : value ?? ctx;
|
|
109
|
+
if (isNullish(v) || v === "") return;
|
|
110
|
+
invariant(isPrintable(v), "Value must be a string, number or boolean - got " + typeof v);
|
|
111
|
+
out.append(String(v));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const eq = () => print$1("=");
|
|
115
|
+
const space = () => print$1(" ");
|
|
116
|
+
function noop() {
|
|
117
|
+
return identity();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* To be used for recursive operations
|
|
121
|
+
*/
|
|
122
|
+
function lazy(op) {
|
|
123
|
+
return (input) => {
|
|
124
|
+
op()(input);
|
|
125
|
+
return input;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function newline(when) {
|
|
129
|
+
return operation(({ out }) => {
|
|
130
|
+
if (when === "ifNotEmpty") out.appendNewLineIfNotEmpty();
|
|
131
|
+
else out.appendNewLine();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Merge multiple operations into a single output node
|
|
136
|
+
*/
|
|
137
|
+
function merge(...ops) {
|
|
138
|
+
return operation(function merge({ ctx, out }) {
|
|
139
|
+
const nested = executeOnFresh(ctx, ops);
|
|
140
|
+
out.appendIf(hasContent(nested.out), nested.out);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function indent(...args) {
|
|
144
|
+
if (args.length === 1 && typeof args[0] === "string") {
|
|
145
|
+
const text = dedent(args[0]);
|
|
146
|
+
if (text.trimStart().length === 0) return noop();
|
|
147
|
+
return operation(function indent1({ out }) {
|
|
148
|
+
out.appendNewLineIfNotEmpty().indent({
|
|
149
|
+
indentEmptyLines: true,
|
|
150
|
+
indentedChildren: [joinToNode(text.split(/\r?\n/), { separator: NL })]
|
|
151
|
+
}).appendNewLineIfNotEmpty();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
const ops = args;
|
|
155
|
+
return operation(function indent2({ ctx, out }) {
|
|
156
|
+
const nested = executeOnFresh(ctx, ops);
|
|
157
|
+
if (hasContent(nested.out)) out.appendNewLineIfNotEmpty().indent({
|
|
158
|
+
indentEmptyLines: true,
|
|
159
|
+
indentedChildren: nested.out.contents
|
|
160
|
+
}).appendNewLineIfNotEmpty();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function body(...args) {
|
|
164
|
+
const keyword = only(args);
|
|
165
|
+
if (isString(keyword)) return body(keyword + " {", "}");
|
|
166
|
+
if (args.length === 2 && isString(args[0]) && isString(args[1])) {
|
|
167
|
+
const [open, close] = args;
|
|
168
|
+
return (...ops) => operation(function body({ ctx, out }) {
|
|
169
|
+
const bodyOutput = indent(lines(...ops))(fresh(ctx)).out;
|
|
170
|
+
out.appendIf(hasContent(bodyOutput), joinToNode([
|
|
171
|
+
open,
|
|
172
|
+
bodyOutput,
|
|
173
|
+
close
|
|
174
|
+
]));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const ops = args;
|
|
178
|
+
return body("{", "}")(...ops);
|
|
179
|
+
}
|
|
180
|
+
const QUOTE = "'";
|
|
181
|
+
const ESCAPED_QUOTE = "\\" + QUOTE;
|
|
182
|
+
function inlineText(value) {
|
|
183
|
+
return operation(({ ctx, out }) => {
|
|
184
|
+
let v = value ?? ctx;
|
|
185
|
+
if (isNullish(v)) return;
|
|
186
|
+
invariant(isString(v), "Value must be a string - got " + typeof v);
|
|
187
|
+
const escapedValue = v.replace(/(\r?\n|\t)+/g, " ").replaceAll(QUOTE, ESCAPED_QUOTE).trim();
|
|
188
|
+
out.append(`${QUOTE}${escapedValue}${QUOTE}`);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function multilineText(value, quotes = QUOTE) {
|
|
192
|
+
return merge(print$1(quotes), indent(value.replaceAll(QUOTE, ESCAPED_QUOTE)), print$1(quotes));
|
|
193
|
+
}
|
|
194
|
+
function text(value) {
|
|
195
|
+
return operation(function text({ ctx, out }) {
|
|
196
|
+
let v = typeof value === "function" ? value(ctx) : value ?? ctx;
|
|
197
|
+
if (isNullish(v)) return;
|
|
198
|
+
invariant(isString(v), "Value must be a string - got " + typeof v);
|
|
199
|
+
if (v.includes("\n")) return multilineText(v)({
|
|
200
|
+
ctx: v,
|
|
201
|
+
out
|
|
202
|
+
});
|
|
203
|
+
return inlineText()({
|
|
204
|
+
ctx: v,
|
|
205
|
+
out
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
const TRIPLE_QUOTE = QUOTE.repeat(3);
|
|
210
|
+
function markdown(value) {
|
|
211
|
+
return operation(function markdown(ctx) {
|
|
212
|
+
let v = value ?? ctx.ctx;
|
|
213
|
+
if (isNullish(v)) return;
|
|
214
|
+
invariant(isString(v), "Value must be a string - got " + typeof v);
|
|
215
|
+
return multilineText(v, TRIPLE_QUOTE)(ctx);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function markdownOrString$1(value) {
|
|
219
|
+
return operation(function markdownOrString(ctx) {
|
|
220
|
+
let v = value ?? ctx.ctx;
|
|
221
|
+
if (isNullish(v)) return;
|
|
222
|
+
if (typeof v === "string") return text(v)(ctx);
|
|
223
|
+
if ("md" in v) return markdown(v.md)(ctx);
|
|
224
|
+
if ("txt" in v) return multilineText(v.txt)(ctx);
|
|
225
|
+
throw new Error("Invalid MarkdownOrString value: " + v);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* helps to join operations
|
|
230
|
+
*
|
|
231
|
+
* @internal
|
|
232
|
+
*
|
|
233
|
+
* @see spaceBetween
|
|
234
|
+
* @see lines
|
|
235
|
+
* @see foreach
|
|
236
|
+
*/
|
|
237
|
+
function join(params) {
|
|
238
|
+
return operation(function joinOp({ ctx, out }) {
|
|
239
|
+
const { operations, ...joinOptions } = params;
|
|
240
|
+
const ops = Array.isArray(operations) ? operations : [operations];
|
|
241
|
+
invariant(hasAtLeast(ops, 1), "At least one operation is required");
|
|
242
|
+
let nested;
|
|
243
|
+
if (ops.length === 1) nested = ops[0](fresh(ctx)).out.contents;
|
|
244
|
+
else nested = pipe(eachOnFresh(ctx, ops), map((n) => n.out));
|
|
245
|
+
nested = filter(nested, hasContentOrNewLine);
|
|
246
|
+
return out.appendIf(nested.length > 0, joinToNode(nested, joinOptions));
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Joins all outputs with a space between
|
|
251
|
+
* @see lines
|
|
252
|
+
*/
|
|
253
|
+
function spaceBetween(...ops) {
|
|
254
|
+
return join({
|
|
255
|
+
operations: ops,
|
|
256
|
+
suffix: (node, _index, isLast) => {
|
|
257
|
+
return !isLast && hasContent(node) ? " " : void 0;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function lines(...args) {
|
|
262
|
+
let linesBetween = only(args);
|
|
263
|
+
if (isNumber(linesBetween)) {
|
|
264
|
+
let suffix = fresh(void 0);
|
|
265
|
+
for (let i = 0; i < linesBetween; i++) suffix.out.appendNewLine();
|
|
266
|
+
return (...ops) => {
|
|
267
|
+
return join({
|
|
268
|
+
operations: ops,
|
|
269
|
+
suffix: (_node, _index, isLast) => {
|
|
270
|
+
return !isLast ? suffix.out : void 0;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return join({
|
|
276
|
+
operations: args,
|
|
277
|
+
appendNewLineIfNotEmpty: true,
|
|
278
|
+
skipNewLineAfterLastItem: true
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
function withctx(...args) {
|
|
282
|
+
const ctx = args[0];
|
|
283
|
+
if (args.length === 1) return (...ops) => operation(function withctx1({ out }) {
|
|
284
|
+
executeOnCtx({
|
|
285
|
+
ctx,
|
|
286
|
+
out
|
|
287
|
+
}, ops);
|
|
288
|
+
});
|
|
289
|
+
const ops = args.slice(1);
|
|
290
|
+
return operation(function withctx2({ out }) {
|
|
291
|
+
executeOnCtx({
|
|
292
|
+
ctx,
|
|
293
|
+
out
|
|
294
|
+
}, ops);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Executes the given operation on the property of the context if it is non-nullish
|
|
299
|
+
* If no operation is provided, prints the property name and property value
|
|
300
|
+
* (use {@link printProperty} if you need print value only)
|
|
301
|
+
*
|
|
302
|
+
* @see printProperty
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts
|
|
306
|
+
* withctx({name: 'John'})(
|
|
307
|
+
* property(
|
|
308
|
+
* 'name',
|
|
309
|
+
* spaceBetween(
|
|
310
|
+
* print('Name:'),
|
|
311
|
+
* print()
|
|
312
|
+
* )
|
|
313
|
+
* )
|
|
314
|
+
* )
|
|
315
|
+
* // Output:
|
|
316
|
+
* // Name: John
|
|
317
|
+
* ```
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* withctx({name: 'John'})(
|
|
321
|
+
* property('name')
|
|
322
|
+
* )
|
|
323
|
+
* // Output:
|
|
324
|
+
* // name John
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
function property(propertyName, op) {
|
|
328
|
+
return operation(function propertyOp({ ctx, out }) {
|
|
329
|
+
const value = isObjectType(ctx) && hasProp(ctx, propertyName) ? ctx[propertyName] : void 0;
|
|
330
|
+
if (value === null || value === void 0) return;
|
|
331
|
+
if (!op) {
|
|
332
|
+
invariant(isPrintable(value), `Property ${propertyName} is not printable "${value}"`);
|
|
333
|
+
out.append(propertyName, " ", String(value));
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
op({
|
|
337
|
+
ctx: value,
|
|
338
|
+
out
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Prints context's property value
|
|
344
|
+
*
|
|
345
|
+
* @see property
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* withctx({name: 'John'})(
|
|
350
|
+
* printProperty('name')
|
|
351
|
+
* )
|
|
352
|
+
* // Output:
|
|
353
|
+
* // John
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
function printProperty(propertyName) {
|
|
357
|
+
return property(propertyName, print$1());
|
|
358
|
+
}
|
|
359
|
+
function foreach(...args) {
|
|
360
|
+
const [arg1, arg2] = args;
|
|
361
|
+
if (args.length === 2 && !isFunction(arg2)) {
|
|
362
|
+
const _op = arg1;
|
|
363
|
+
const joinOptions = arg2;
|
|
364
|
+
return operation(function foreachSingleOp({ ctx, out }) {
|
|
365
|
+
const items = [];
|
|
366
|
+
for (const value of ctx) {
|
|
367
|
+
const itemOut = _op(fresh(value)).out;
|
|
368
|
+
if (hasContent(itemOut)) items.push(itemOut);
|
|
369
|
+
}
|
|
370
|
+
out.appendIf(items.length > 0, joinToNode(items, joinOptions));
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
const ops = args;
|
|
374
|
+
return operation(({ ctx, out }) => {
|
|
375
|
+
for (const value of ctx) executeOnCtx({
|
|
376
|
+
ctx: value,
|
|
377
|
+
out
|
|
378
|
+
}, ops);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
function separateWith(separator) {
|
|
382
|
+
return { separator };
|
|
383
|
+
}
|
|
384
|
+
function separateNewLine(lines = 1) {
|
|
385
|
+
if (lines > 1) {
|
|
386
|
+
let suffix = fresh(void 0);
|
|
387
|
+
for (let i = 0; i < lines; i++) suffix.out.appendNewLine();
|
|
388
|
+
return separateWith(suffix.out);
|
|
389
|
+
}
|
|
390
|
+
return separateWith(NL);
|
|
391
|
+
}
|
|
392
|
+
function separateComma(addNewLine) {
|
|
393
|
+
if (addNewLine) return {
|
|
394
|
+
separator: ",",
|
|
395
|
+
appendNewLineIfNotEmpty: true,
|
|
396
|
+
skipNewLineAfterLastItem: true
|
|
397
|
+
};
|
|
398
|
+
return { separator: ", " };
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Executes given operations on each item of the iterable context
|
|
402
|
+
* And joins the results with a new line
|
|
403
|
+
*/
|
|
404
|
+
function foreachNewLine(...ops) {
|
|
405
|
+
return operation(function foreachNewLineOp({ ctx, out }) {
|
|
406
|
+
const items = [];
|
|
407
|
+
for (const value of ctx) {
|
|
408
|
+
const itemOut = executeOnFresh(value, ops).out;
|
|
409
|
+
if (hasContent(itemOut)) items.push(itemOut);
|
|
410
|
+
}
|
|
411
|
+
out.appendIf(items.length > 0, joinToNode(items, separateNewLine()));
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
function guard(condition, ...ops) {
|
|
415
|
+
return operation("guard", ({ ctx, out }) => {
|
|
416
|
+
if ("safeParse" in condition) {
|
|
417
|
+
const parsed = condition.safeParse(ctx);
|
|
418
|
+
if (parsed.success) executeOnCtx({
|
|
419
|
+
ctx: parsed.data,
|
|
420
|
+
out
|
|
421
|
+
}, ops);
|
|
422
|
+
else throw new Error(`Guard failed: ${z$1.prettifyError(parsed.error)}`);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
invariant(typeof condition === "function");
|
|
426
|
+
if (condition(ctx)) {
|
|
427
|
+
executeOnCtx({
|
|
428
|
+
ctx,
|
|
429
|
+
out
|
|
430
|
+
}, ops);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Executes operations on the context if the condition is true
|
|
437
|
+
*/
|
|
438
|
+
function when(condition, ...ops) {
|
|
439
|
+
return operation(function whenOp({ ctx, out }) {
|
|
440
|
+
if (condition(ctx)) executeOnCtx({
|
|
441
|
+
ctx,
|
|
442
|
+
out
|
|
443
|
+
}, ops);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
function select(selector, ...ops) {
|
|
447
|
+
return operation(function selectOp({ ctx, out }) {
|
|
448
|
+
const value = selector(ctx);
|
|
449
|
+
if (isNonNullish(value)) executeOnCtx({
|
|
450
|
+
ctx: value,
|
|
451
|
+
out
|
|
452
|
+
}, ops);
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Creates an execution function that runs operations
|
|
457
|
+
* with new context but using the same output
|
|
458
|
+
*/
|
|
459
|
+
function execToOut(out) {
|
|
460
|
+
return (ctx, ...ops) => executeOnCtx({
|
|
461
|
+
ctx,
|
|
462
|
+
out
|
|
463
|
+
}, ops);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Creates print operation with context based on zod schema
|
|
467
|
+
* @example
|
|
468
|
+
* ```ts
|
|
469
|
+
* const newOp = zodOp(schemas.directRelationExpr)(
|
|
470
|
+
* merge(
|
|
471
|
+
* property(
|
|
472
|
+
* 'source',
|
|
473
|
+
* fqnExpr(),
|
|
474
|
+
* ),
|
|
475
|
+
* print(v => v.isBidirectional ? ' <-> ' : ' -> '),
|
|
476
|
+
* property(
|
|
477
|
+
* 'target',
|
|
478
|
+
* fqnExpr(),
|
|
479
|
+
* ),
|
|
480
|
+
* ),
|
|
481
|
+
* )
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```ts
|
|
486
|
+
* const whereOperator = zodOp(schemas.whereOperator)(({ ctx, exec }) => {
|
|
487
|
+
* if ('and' in ctx) {
|
|
488
|
+
* return exec(ctx, whereAnd())
|
|
489
|
+
* }
|
|
490
|
+
* if ('or' in ctx) {
|
|
491
|
+
* return exec(ctx, whereOr())
|
|
492
|
+
* }
|
|
493
|
+
* nonexhaustive(ctx)
|
|
494
|
+
* })
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
function zodOp(schema) {
|
|
498
|
+
return (operation) => {
|
|
499
|
+
return () => {
|
|
500
|
+
return ({ ctx, out }) => {
|
|
501
|
+
const result = z$1.safeParse(schema, ctx);
|
|
502
|
+
if (result.success) {
|
|
503
|
+
const opres = operation({
|
|
504
|
+
ctx: result.data,
|
|
505
|
+
out,
|
|
506
|
+
exec: execToOut(out)
|
|
507
|
+
});
|
|
508
|
+
if (opres instanceof CompositeGeneratorNode) return {
|
|
509
|
+
ctx,
|
|
510
|
+
out: opres
|
|
511
|
+
};
|
|
512
|
+
if (typeof opres === "function") return {
|
|
513
|
+
ctx,
|
|
514
|
+
out,
|
|
515
|
+
...opres({
|
|
516
|
+
ctx,
|
|
517
|
+
out
|
|
518
|
+
})
|
|
519
|
+
};
|
|
520
|
+
return {
|
|
521
|
+
ctx,
|
|
522
|
+
out
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
throw result.error;
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
var common_exports = /* @__PURE__ */ __exportAll({
|
|
531
|
+
arrow: () => arrow,
|
|
532
|
+
border: () => border,
|
|
533
|
+
color: () => color,
|
|
534
|
+
customColor: () => customColor,
|
|
535
|
+
fqn: () => fqn,
|
|
536
|
+
icon: () => icon,
|
|
537
|
+
iconPosition: () => iconPosition,
|
|
538
|
+
id: () => id,
|
|
539
|
+
kind: () => kind,
|
|
540
|
+
line: () => line,
|
|
541
|
+
link: () => link,
|
|
542
|
+
links: () => links,
|
|
543
|
+
markdownOrString: () => markdownOrString,
|
|
544
|
+
metadata: () => metadata,
|
|
545
|
+
metadataValue: () => metadataValue$1,
|
|
546
|
+
opacity: () => opacity,
|
|
547
|
+
props: () => props,
|
|
548
|
+
shape: () => shape,
|
|
549
|
+
size: () => size,
|
|
550
|
+
style: () => style,
|
|
551
|
+
tag: () => tag,
|
|
552
|
+
tags: () => tags,
|
|
553
|
+
themeColor: () => themeColor,
|
|
554
|
+
viewId: () => viewId
|
|
555
|
+
});
|
|
556
|
+
const id = z$1.string().regex(/^[a-zA-Z0-9_.-]+$/, "id must consist of alphanumeric characters, underscores or hyphens");
|
|
557
|
+
const viewId = id.transform((value) => value);
|
|
558
|
+
const fqn = z$1.string().regex(/^[a-zA-Z0-9_.-]+$/, "FQN must consist of alphanumeric characters, dots, underscores or hyphens").transform((value) => value);
|
|
559
|
+
const kind = z$1.string().regex(/^[a-zA-Z0-9_-]+$/, "Kind must consist of alphanumeric characters, underscores or hyphens").transform((value) => value);
|
|
560
|
+
const opacity = z$1.int().min(0, "Opacity must be between 0 and 100").max(100, "Opacity must be between 0 and 100");
|
|
561
|
+
const shape = z$1.literal(ElementShapes);
|
|
562
|
+
const icon = z$1.string().nonempty("Icon cannot be empty").transform((value) => value);
|
|
563
|
+
const border = z$1.literal(BorderStyles);
|
|
564
|
+
const size = z$1.literal(Sizes);
|
|
565
|
+
const iconPosition = z$1.literal(IconPositions);
|
|
566
|
+
const arrow = z$1.literal(RelationshipArrowTypes);
|
|
567
|
+
const line = z$1.literal([
|
|
568
|
+
"dashed",
|
|
569
|
+
"solid",
|
|
570
|
+
"dotted"
|
|
571
|
+
]);
|
|
572
|
+
const link = z$1.union([z$1.string(), z$1.object({
|
|
573
|
+
title: z$1.string().optional(),
|
|
574
|
+
url: z$1.string()
|
|
575
|
+
})]).transform((value) => exact(typeof value === "string" ? { url: value } : value));
|
|
576
|
+
const links = z$1.array(link).readonly();
|
|
577
|
+
const themeColor = z$1.literal(ThemeColors);
|
|
578
|
+
const customColor = z$1.custom().refine((v) => typeof v === "string", "Custom color name must be a string").transform((value) => value);
|
|
579
|
+
const tag = z$1.string().nonempty("Tag cannot be empty").transform((tag) => tag.startsWith("#") ? tag.slice(1) : tag);
|
|
580
|
+
const tags = z$1.array(tag).readonly();
|
|
581
|
+
const markdownOrString = z$1.union([
|
|
582
|
+
z$1.string(),
|
|
583
|
+
z$1.strictObject({ md: z$1.string() }),
|
|
584
|
+
z$1.strictObject({ txt: z$1.string() })
|
|
585
|
+
]).transform((v) => typeof v === "string" ? { txt: v } : v);
|
|
586
|
+
const color = themeColor.or(customColor);
|
|
587
|
+
const style = z$1.object({
|
|
588
|
+
shape,
|
|
589
|
+
icon,
|
|
590
|
+
iconColor: color,
|
|
591
|
+
iconSize: size,
|
|
592
|
+
iconPosition,
|
|
593
|
+
color,
|
|
594
|
+
border,
|
|
595
|
+
opacity,
|
|
596
|
+
size,
|
|
597
|
+
padding: size,
|
|
598
|
+
textSize: size,
|
|
599
|
+
multiple: z$1.boolean()
|
|
600
|
+
}).partial();
|
|
601
|
+
const metadataValue$1 = z$1.union([
|
|
602
|
+
z$1.string(),
|
|
603
|
+
z$1.boolean(),
|
|
604
|
+
z$1.number()
|
|
605
|
+
]);
|
|
606
|
+
const metadata = z$1.record(z$1.string(), metadataValue$1.or(z$1.array(metadataValue$1)));
|
|
607
|
+
const props = z$1.object({
|
|
608
|
+
tags: tags.nullable(),
|
|
609
|
+
title: z$1.string(),
|
|
610
|
+
summary: markdownOrString.nullable(),
|
|
611
|
+
description: markdownOrString.nullable(),
|
|
612
|
+
notation: z$1.string().nullable(),
|
|
613
|
+
technology: z$1.string().nullable(),
|
|
614
|
+
links: links.nullable(),
|
|
615
|
+
metadata
|
|
616
|
+
}).partial();
|
|
617
|
+
var expression_exports = /* @__PURE__ */ __exportAll({
|
|
618
|
+
directRelationExpr: () => directRelationExpr$1,
|
|
619
|
+
elementKindExpr: () => elementKindExpr,
|
|
620
|
+
elementTagExpr: () => elementTagExpr,
|
|
621
|
+
expression: () => expression$1,
|
|
622
|
+
fqnExpr: () => fqnExpr$1,
|
|
623
|
+
fqnExprAny: () => fqnExprAny$1,
|
|
624
|
+
fqnExprCustom: () => fqnExprCustom$1,
|
|
625
|
+
fqnExprOrWhere: () => fqnExprOrWhere$1,
|
|
626
|
+
fqnRef: () => fqnRef$1,
|
|
627
|
+
incomingRelationExpr: () => incomingRelationExpr$1,
|
|
628
|
+
inoutRelationExpr: () => inoutRelationExpr,
|
|
629
|
+
outgoingRelationExpr: () => outgoingRelationExpr$1,
|
|
630
|
+
refDeployment: () => refDeployment,
|
|
631
|
+
refExpr: () => refExpr,
|
|
632
|
+
refModel: () => refModel,
|
|
633
|
+
relationExpr: () => relationExpr$1,
|
|
634
|
+
relationExprAny: () => relationExprAny$1,
|
|
635
|
+
relationExprCustom: () => relationExprCustom$1,
|
|
636
|
+
relationExprOrWhere: () => relationExprOrWhere$1,
|
|
637
|
+
selector: () => selector,
|
|
638
|
+
whereAnd: () => whereAnd$1,
|
|
639
|
+
whereExpr: () => whereExpr,
|
|
640
|
+
whereKind: () => whereKind,
|
|
641
|
+
whereMetadata: () => whereMetadata,
|
|
642
|
+
whereNot: () => whereNot$1,
|
|
643
|
+
whereOperator: () => whereOperator$1,
|
|
644
|
+
whereOr: () => whereOr$1,
|
|
645
|
+
whereParticipant: () => whereParticipant$1,
|
|
646
|
+
whereTag: () => whereTag,
|
|
647
|
+
wildcardExpr: () => wildcardExpr
|
|
648
|
+
});
|
|
649
|
+
const refModel = z$1.strictObject({
|
|
650
|
+
model: fqn,
|
|
651
|
+
project: z$1.string().optional()
|
|
652
|
+
});
|
|
653
|
+
const refDeployment = z$1.strictObject({
|
|
654
|
+
deployment: fqn,
|
|
655
|
+
element: fqn.nullish()
|
|
656
|
+
});
|
|
657
|
+
const fqnRef$1 = z$1.union([refModel, refDeployment]);
|
|
658
|
+
const selector = z$1.literal([
|
|
659
|
+
"children",
|
|
660
|
+
"expanded",
|
|
661
|
+
"descendants"
|
|
662
|
+
]);
|
|
663
|
+
/**
|
|
664
|
+
* Accepts a value directly (shorthand for equality), or an explicit {eq: value} / {neq: value}.
|
|
665
|
+
* Replicates the EqualOperator from the core.
|
|
666
|
+
*/
|
|
667
|
+
function equalOp(schema) {
|
|
668
|
+
return z$1.union([
|
|
669
|
+
schema.transform((value) => ({ eq: value })),
|
|
670
|
+
z$1.object({ eq: schema }),
|
|
671
|
+
z$1.object({ neq: schema })
|
|
672
|
+
]);
|
|
673
|
+
}
|
|
674
|
+
const whereTag = z$1.object({ tag: equalOp(tag) });
|
|
675
|
+
const whereKind = z$1.object({ kind: equalOp(kind) });
|
|
676
|
+
const whereMetadata = z$1.object({ metadata: z$1.object({
|
|
677
|
+
key: z$1.string(),
|
|
678
|
+
value: equalOp(z$1.string()).optional()
|
|
679
|
+
}) });
|
|
680
|
+
const whereParticipant$1 = z$1.object({
|
|
681
|
+
participant: z$1.literal(["source", "target"]),
|
|
682
|
+
operator: z$1.union([
|
|
683
|
+
whereTag,
|
|
684
|
+
whereKind,
|
|
685
|
+
whereMetadata
|
|
686
|
+
])
|
|
687
|
+
});
|
|
688
|
+
const whereAnd$1 = z$1.object({ get and() {
|
|
689
|
+
return z$1.array(whereOperator$1);
|
|
690
|
+
} });
|
|
691
|
+
const whereNot$1 = z$1.object({ get not() {
|
|
692
|
+
return whereOperator$1;
|
|
693
|
+
} });
|
|
694
|
+
const whereOr$1 = z$1.object({ get or() {
|
|
695
|
+
return z$1.array(whereOperator$1);
|
|
696
|
+
} });
|
|
697
|
+
const whereOperator$1 = z$1.union([
|
|
698
|
+
whereTag,
|
|
699
|
+
whereKind,
|
|
700
|
+
whereMetadata,
|
|
701
|
+
whereParticipant$1,
|
|
702
|
+
whereAnd$1,
|
|
703
|
+
whereOr$1,
|
|
704
|
+
whereNot$1
|
|
705
|
+
]);
|
|
706
|
+
const wildcardExpr = z$1.object({ wildcard: z$1.literal(true) });
|
|
707
|
+
const refExpr = z$1.object({
|
|
708
|
+
ref: fqnRef$1,
|
|
709
|
+
selector: selector.optional()
|
|
710
|
+
});
|
|
711
|
+
const elementKindExpr = z$1.object({
|
|
712
|
+
elementKind: kind,
|
|
713
|
+
isEqual: z$1.boolean()
|
|
714
|
+
});
|
|
715
|
+
const elementTagExpr = z$1.object({
|
|
716
|
+
elementTag: tag,
|
|
717
|
+
isEqual: z$1.boolean()
|
|
718
|
+
});
|
|
719
|
+
const fqnExpr$1 = z$1.union([
|
|
720
|
+
wildcardExpr,
|
|
721
|
+
refExpr,
|
|
722
|
+
elementKindExpr,
|
|
723
|
+
elementTagExpr
|
|
724
|
+
]);
|
|
725
|
+
const fqnExprWhere = z$1.strictObject({ where: z$1.strictObject({
|
|
726
|
+
expr: fqnExpr$1,
|
|
727
|
+
condition: whereOperator$1
|
|
728
|
+
}) });
|
|
729
|
+
const fqnExprOrWhere$1 = z$1.union([fqnExpr$1, fqnExprWhere]);
|
|
730
|
+
/**
|
|
731
|
+
* Common custom properties that apply to both elements and relations
|
|
732
|
+
*/
|
|
733
|
+
const commonCustomProperties = z$1.object({
|
|
734
|
+
title: z$1.string(),
|
|
735
|
+
description: markdownOrString,
|
|
736
|
+
technology: z$1.string(),
|
|
737
|
+
notation: z$1.string(),
|
|
738
|
+
notes: markdownOrString,
|
|
739
|
+
navigateTo: viewId,
|
|
740
|
+
color
|
|
741
|
+
});
|
|
742
|
+
const customElementProperties = z$1.object({
|
|
743
|
+
...commonCustomProperties.shape,
|
|
744
|
+
shape,
|
|
745
|
+
icon,
|
|
746
|
+
iconColor: color,
|
|
747
|
+
iconSize: size,
|
|
748
|
+
iconPosition,
|
|
749
|
+
border,
|
|
750
|
+
opacity,
|
|
751
|
+
multiple: z$1.boolean(),
|
|
752
|
+
size,
|
|
753
|
+
padding: size,
|
|
754
|
+
textSize: size
|
|
755
|
+
}).partial();
|
|
756
|
+
const customRelationProperties = z$1.object({
|
|
757
|
+
...commonCustomProperties.shape,
|
|
758
|
+
line,
|
|
759
|
+
head: arrow,
|
|
760
|
+
tail: arrow
|
|
761
|
+
}).partial();
|
|
762
|
+
const fqnExprCustom$1 = z$1.strictObject({ custom: customElementProperties.extend({ expr: fqnExprOrWhere$1 }) });
|
|
763
|
+
const fqnExprAny$1 = z$1.union([fqnExprOrWhere$1, fqnExprCustom$1]);
|
|
764
|
+
const directRelationExpr$1 = z$1.object({
|
|
765
|
+
source: fqnExpr$1,
|
|
766
|
+
target: fqnExpr$1,
|
|
767
|
+
isBidirectional: z$1.boolean().optional()
|
|
768
|
+
});
|
|
769
|
+
const incomingRelationExpr$1 = z$1.object({ incoming: fqnExpr$1 });
|
|
770
|
+
const outgoingRelationExpr$1 = z$1.object({ outgoing: fqnExpr$1 });
|
|
771
|
+
const inoutRelationExpr = z$1.object({ inout: fqnExpr$1 });
|
|
772
|
+
const relationExpr$1 = z$1.union([
|
|
773
|
+
directRelationExpr$1,
|
|
774
|
+
incomingRelationExpr$1,
|
|
775
|
+
outgoingRelationExpr$1,
|
|
776
|
+
inoutRelationExpr
|
|
777
|
+
]);
|
|
778
|
+
const relationExprOrWhere$1 = z$1.union([relationExpr$1, z$1.strictObject({ where: z$1.strictObject({
|
|
779
|
+
expr: relationExpr$1,
|
|
780
|
+
condition: whereOperator$1
|
|
781
|
+
}) })]);
|
|
782
|
+
const relationExprCustom$1 = z$1.strictObject({ customRelation: customRelationProperties.extend({ expr: relationExprOrWhere$1 }) });
|
|
783
|
+
const relationExprAny$1 = z$1.union([relationExprOrWhere$1, relationExprCustom$1]);
|
|
784
|
+
const whereExpr = z$1.object({ where: z$1.object({
|
|
785
|
+
expr: z$1.union([fqnExpr$1, relationExpr$1]),
|
|
786
|
+
condition: whereOperator$1
|
|
787
|
+
}) });
|
|
788
|
+
/**
|
|
789
|
+
* Full model expression, union of all fqn and relation expression variants.
|
|
790
|
+
* Replicates ModelExpression from the core.
|
|
791
|
+
*/
|
|
792
|
+
const expression$1 = z$1.union([
|
|
793
|
+
fqnExpr$1,
|
|
794
|
+
fqnExprCustom$1,
|
|
795
|
+
relationExpr$1,
|
|
796
|
+
relationExprCustom$1,
|
|
797
|
+
whereExpr
|
|
798
|
+
]);
|
|
799
|
+
var deployment_exports$1 = /* @__PURE__ */ __exportAll({
|
|
800
|
+
element: () => element$3,
|
|
801
|
+
instance: () => instance$1,
|
|
802
|
+
node: () => node$1,
|
|
803
|
+
relationship: () => relationship$4,
|
|
804
|
+
schema: () => schema$2
|
|
805
|
+
});
|
|
806
|
+
const node$1 = props.extend({
|
|
807
|
+
id: fqn,
|
|
808
|
+
kind,
|
|
809
|
+
style: style.optional(),
|
|
810
|
+
shape: shape.optional(),
|
|
811
|
+
color: color.optional(),
|
|
812
|
+
icon: icon.optional()
|
|
813
|
+
}).readonly().transform((value) => {
|
|
814
|
+
const { shape, color, icon, ...rest } = value;
|
|
815
|
+
if (shape || color || icon) return produce(rest, (draft) => {
|
|
816
|
+
draft.style = rest.style || {};
|
|
817
|
+
draft.style.shape = shape ?? rest.style?.shape;
|
|
818
|
+
draft.style.color = color ?? rest.style?.color;
|
|
819
|
+
draft.style.icon = icon ?? rest.style?.icon;
|
|
820
|
+
});
|
|
821
|
+
return rest;
|
|
822
|
+
}).transform(pickBy(isNonNullish));
|
|
823
|
+
const instance$1 = props.extend({
|
|
824
|
+
id: fqn,
|
|
825
|
+
element: fqn,
|
|
826
|
+
style: style.optional(),
|
|
827
|
+
shape: shape.optional(),
|
|
828
|
+
color: color.optional(),
|
|
829
|
+
icon: icon.optional()
|
|
830
|
+
}).readonly().transform((value) => {
|
|
831
|
+
const { shape, color, icon, ...rest } = value;
|
|
832
|
+
if (shape || color || icon) return produce(rest, (draft) => {
|
|
833
|
+
draft.style = rest.style || {};
|
|
834
|
+
draft.style.shape = shape ?? rest.style?.shape;
|
|
835
|
+
draft.style.color = color ?? rest.style?.color;
|
|
836
|
+
draft.style.icon = icon ?? rest.style?.icon;
|
|
837
|
+
});
|
|
838
|
+
return rest;
|
|
839
|
+
}).transform(pickBy(isNonNullish));
|
|
840
|
+
const relationshipEndpoint$1 = refDeployment;
|
|
841
|
+
const relationshipId$1 = id.transform((value) => value);
|
|
842
|
+
const relationship$4 = props.extend({
|
|
843
|
+
id: relationshipId$1.optional(),
|
|
844
|
+
title: z$1.string().nullish(),
|
|
845
|
+
source: relationshipEndpoint$1,
|
|
846
|
+
target: relationshipEndpoint$1,
|
|
847
|
+
navigateTo: viewId.nullish(),
|
|
848
|
+
color: color.nullish(),
|
|
849
|
+
kind: kind.nullish(),
|
|
850
|
+
line: line.nullish(),
|
|
851
|
+
head: arrow.nullish(),
|
|
852
|
+
tail: arrow.nullish()
|
|
853
|
+
}).readonly().transform(pickBy(isNonNullish));
|
|
854
|
+
const element$3 = z$1.union([node$1, instance$1]);
|
|
855
|
+
const elements$1 = z$1.record(fqn, element$3);
|
|
856
|
+
const relationships$1 = z$1.record(relationshipId$1, relationship$4);
|
|
857
|
+
const genRelationshipId$1 = (r) => r.id ?? randomString(8);
|
|
858
|
+
const schema$2 = z$1.object({
|
|
859
|
+
elements: z$1.union([elements$1, z$1.array(element$3)]).transform((v) => isArray(v) ? indexBy(v, prop("id")) : v).optional(),
|
|
860
|
+
relations: z$1.union([relationships$1, z$1.array(relationship$4)]).transform((v) => isArray(v) ? indexBy(v, genRelationshipId$1) : v).optional()
|
|
861
|
+
});
|
|
862
|
+
var model_exports$1 = /* @__PURE__ */ __exportAll({
|
|
863
|
+
element: () => element$2,
|
|
864
|
+
relationship: () => relationship$3,
|
|
865
|
+
schema: () => schema$1
|
|
866
|
+
});
|
|
867
|
+
/**
|
|
868
|
+
* Replicates the {@link Element} from the core,
|
|
869
|
+
* less strict, as the generator should be able to handle missing fields and provide defaults.
|
|
870
|
+
*/
|
|
871
|
+
const element$2 = z$1.object({
|
|
872
|
+
...props.shape,
|
|
873
|
+
id: fqn,
|
|
874
|
+
kind,
|
|
875
|
+
style: style.optional(),
|
|
876
|
+
shape: shape.optional(),
|
|
877
|
+
color: color.optional(),
|
|
878
|
+
icon: icon.optional()
|
|
879
|
+
}).transform((value) => {
|
|
880
|
+
let { shape, color, icon, ...rest } = value;
|
|
881
|
+
if (shape || color || icon) rest = produce(rest, (draft) => {
|
|
882
|
+
draft.style = rest.style || {};
|
|
883
|
+
draft.style.shape = shape ?? rest.style?.shape;
|
|
884
|
+
draft.style.color = color ?? rest.style?.color;
|
|
885
|
+
draft.style.icon = icon ?? rest.style?.icon;
|
|
886
|
+
});
|
|
887
|
+
return pickBy(rest, isNonNullish);
|
|
888
|
+
}).readonly();
|
|
889
|
+
const relationshipEndpoint = z$1.union([fqn, z$1.strictObject({ model: fqn })]).transform((v) => typeof v === "string" ? { model: v } : v);
|
|
890
|
+
const relationshipId = id.transform((value) => value);
|
|
891
|
+
const relationship$3 = z$1.object({
|
|
892
|
+
...props.shape,
|
|
893
|
+
id: relationshipId.optional(),
|
|
894
|
+
title: z$1.string().nullish(),
|
|
895
|
+
source: relationshipEndpoint,
|
|
896
|
+
target: relationshipEndpoint,
|
|
897
|
+
navigateTo: viewId.nullish(),
|
|
898
|
+
color: color.nullish(),
|
|
899
|
+
kind: kind.nullish(),
|
|
900
|
+
line: line.nullish(),
|
|
901
|
+
head: arrow.nullish(),
|
|
902
|
+
tail: arrow.nullish()
|
|
903
|
+
}).transform(pickBy(isNonNullish)).readonly();
|
|
904
|
+
const elements = z$1.record(fqn, element$2);
|
|
905
|
+
const relationships = z$1.record(relationshipId, relationship$3);
|
|
906
|
+
const genRelationshipId = (r) => r.id ?? randomString(8);
|
|
907
|
+
const schema$1 = z$1.object({
|
|
908
|
+
elements: z$1.union([elements, z$1.array(element$2)]).transform((v) => isArray(v) ? indexBy(v, prop("id")) : v).optional(),
|
|
909
|
+
relations: z$1.union([relationships, z$1.array(relationship$3)]).transform((v) => isArray(v) ? indexBy(v, genRelationshipId) : v).optional()
|
|
910
|
+
});
|
|
911
|
+
var specification_exports$1 = /* @__PURE__ */ __exportAll({
|
|
912
|
+
element: () => element$1,
|
|
913
|
+
relationship: () => relationship$2,
|
|
914
|
+
schema: () => schema,
|
|
915
|
+
tagSpec: () => tagSpec
|
|
916
|
+
});
|
|
917
|
+
/**
|
|
918
|
+
* Replicates the {@link ElementSpecification} from the core,
|
|
919
|
+
* less strict, as the generator should be able to handle missing fields and provide defaults.
|
|
920
|
+
*/
|
|
921
|
+
const element$1 = z$1.object({
|
|
922
|
+
tags: tags.nullable(),
|
|
923
|
+
title: z$1.string().nullable(),
|
|
924
|
+
summary: markdownOrString.nullable(),
|
|
925
|
+
description: markdownOrString.nullable(),
|
|
926
|
+
technology: z$1.string().nullable(),
|
|
927
|
+
notation: z$1.string().nullable(),
|
|
928
|
+
links: links.nullable(),
|
|
929
|
+
style: style.nullable()
|
|
930
|
+
}).partial().transform(pickBy(isNonNullish));
|
|
931
|
+
/**
|
|
932
|
+
* Replicates the {@link RelationshipSpecification} from the core,
|
|
933
|
+
* less strict, as the generator should be able to handle missing fields and provide defaults.
|
|
934
|
+
*/
|
|
935
|
+
const relationship$2 = z$1.object({
|
|
936
|
+
technology: z$1.string().nullable(),
|
|
937
|
+
notation: z$1.string().nullable(),
|
|
938
|
+
color: color.nullable(),
|
|
939
|
+
line: line.nullable(),
|
|
940
|
+
head: arrow.nullable(),
|
|
941
|
+
tail: arrow.nullable()
|
|
942
|
+
}).partial().transform(pickBy(isNonNullish));
|
|
943
|
+
const tagSpec = z$1.object({ color: z$1.string().regex(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/).optional().catch(void 0) }).partial().transform(pickBy(isNonNullish));
|
|
944
|
+
const schema = z$1.object({
|
|
945
|
+
elements: z$1.record(kind, element$1),
|
|
946
|
+
deployments: z$1.record(kind, element$1),
|
|
947
|
+
relationships: z$1.record(kind, relationship$2),
|
|
948
|
+
tags: z$1.union([z$1.record(tag, tagSpec), z$1.array(tag).transform((tags) => mapToObj(tags, (t) => [t, {}]))])
|
|
949
|
+
}).partial();
|
|
950
|
+
var views_exports$1 = /* @__PURE__ */ __exportAll({
|
|
951
|
+
anyView: () => anyView$1,
|
|
952
|
+
autoLayoutDirection: () => autoLayoutDirection,
|
|
953
|
+
deploymentView: () => deploymentView$1,
|
|
954
|
+
deploymentViewRule: () => deploymentViewRule$1,
|
|
955
|
+
dynamicStep: () => dynamicStep$1,
|
|
956
|
+
dynamicStepsParallel: () => dynamicStepsParallel$1,
|
|
957
|
+
dynamicStepsSeries: () => dynamicStepsSeries$1,
|
|
958
|
+
dynamicView: () => dynamicView$1,
|
|
959
|
+
dynamicViewIncludeRule: () => dynamicViewIncludeRule$1,
|
|
960
|
+
dynamicViewRule: () => dynamicViewRule$1,
|
|
961
|
+
dynamicViewStep: () => dynamicViewStep$1,
|
|
962
|
+
dynamicViewVariant: () => dynamicViewVariant,
|
|
963
|
+
elementView: () => elementView$1,
|
|
964
|
+
elementViewRule: () => elementViewRule$1,
|
|
965
|
+
viewRuleAutoLayout: () => viewRuleAutoLayout$1,
|
|
966
|
+
viewRuleExclude: () => viewRuleExclude,
|
|
967
|
+
viewRuleGlobalPredicate: () => viewRuleGlobalPredicate$1,
|
|
968
|
+
viewRuleGlobalStyle: () => viewRuleGlobalStyle$1,
|
|
969
|
+
viewRuleGroup: () => viewRuleGroup$1,
|
|
970
|
+
viewRuleInclude: () => viewRuleInclude,
|
|
971
|
+
viewRulePredicate: () => viewRulePredicate$1,
|
|
972
|
+
viewRuleRank: () => viewRuleRank$1,
|
|
973
|
+
viewRuleStyle: () => viewRuleStyle$1,
|
|
974
|
+
views: () => views$1
|
|
975
|
+
});
|
|
976
|
+
const autoLayoutDirection = z$1.literal([
|
|
977
|
+
"TB",
|
|
978
|
+
"BT",
|
|
979
|
+
"LR",
|
|
980
|
+
"RL"
|
|
981
|
+
]);
|
|
982
|
+
const viewRuleAutoLayout$1 = z$1.object({
|
|
983
|
+
direction: autoLayoutDirection,
|
|
984
|
+
nodeSep: z$1.number().optional(),
|
|
985
|
+
rankSep: z$1.number().optional()
|
|
986
|
+
}).transform((v) => v);
|
|
987
|
+
const viewRuleInclude = z$1.strictObject({ include: z$1.array(expression$1) });
|
|
988
|
+
const viewRuleExclude = z$1.strictObject({ exclude: z$1.array(expression$1) });
|
|
989
|
+
const viewRulePredicate$1 = z$1.union([viewRuleInclude, viewRuleExclude]).transform((v) => v);
|
|
990
|
+
const viewRuleStyle$1 = z$1.object({
|
|
991
|
+
targets: z$1.array(fqnExpr$1),
|
|
992
|
+
notation: z$1.string().optional(),
|
|
993
|
+
style
|
|
994
|
+
}).transform((v) => v);
|
|
995
|
+
const viewRuleGlobalStyle$1 = z$1.object({ styleId: z$1.string() }).transform((v) => v);
|
|
996
|
+
const viewRuleGlobalPredicate$1 = z$1.object({ predicateId: z$1.string() }).transform((v) => v);
|
|
997
|
+
const rankValue = z$1.literal([
|
|
998
|
+
"max",
|
|
999
|
+
"min",
|
|
1000
|
+
"same",
|
|
1001
|
+
"sink",
|
|
1002
|
+
"source"
|
|
1003
|
+
]);
|
|
1004
|
+
const viewRuleRank$1 = z$1.object({
|
|
1005
|
+
targets: z$1.array(fqnExpr$1),
|
|
1006
|
+
rank: rankValue
|
|
1007
|
+
}).transform((v) => v);
|
|
1008
|
+
const viewRuleGroup$1 = z$1.lazy(() => z$1.object({
|
|
1009
|
+
groupRules: z$1.array(z$1.union([viewRulePredicate$1, viewRuleGroup$1])),
|
|
1010
|
+
title: z$1.string().nullable(),
|
|
1011
|
+
color: color.optional(),
|
|
1012
|
+
border: border.optional(),
|
|
1013
|
+
opacity: opacity.optional(),
|
|
1014
|
+
multiple: z$1.boolean().optional(),
|
|
1015
|
+
size: size.optional(),
|
|
1016
|
+
padding: size.optional(),
|
|
1017
|
+
textSize: size.optional()
|
|
1018
|
+
}));
|
|
1019
|
+
const elementViewRule$1 = z$1.union([
|
|
1020
|
+
viewRulePredicate$1,
|
|
1021
|
+
viewRuleAutoLayout$1,
|
|
1022
|
+
viewRuleStyle$1,
|
|
1023
|
+
viewRuleGlobalStyle$1,
|
|
1024
|
+
viewRuleGlobalPredicate$1,
|
|
1025
|
+
viewRuleRank$1,
|
|
1026
|
+
viewRuleGroup$1
|
|
1027
|
+
]);
|
|
1028
|
+
const viewProps = z$1.object({
|
|
1029
|
+
id: viewId,
|
|
1030
|
+
_stage: z$1.literal("parsed").default("parsed"),
|
|
1031
|
+
title: z$1.string().nullish(),
|
|
1032
|
+
description: markdownOrString.nullish(),
|
|
1033
|
+
tags: tags.nullish(),
|
|
1034
|
+
links: links.nullish()
|
|
1035
|
+
});
|
|
1036
|
+
/**
|
|
1037
|
+
* Replicates ParsedElementView from the core,
|
|
1038
|
+
* less strict, as the generator should be able to handle missing fields and provide defaults.
|
|
1039
|
+
*/
|
|
1040
|
+
const elementView$1 = viewProps.extend({
|
|
1041
|
+
_type: z$1.literal("element"),
|
|
1042
|
+
viewOf: fqn.nullish(),
|
|
1043
|
+
extends: viewId.nullish(),
|
|
1044
|
+
rules: z$1.array(elementViewRule$1).optional().default([])
|
|
1045
|
+
});
|
|
1046
|
+
const deploymentViewRule$1 = z$1.union([
|
|
1047
|
+
viewRulePredicate$1,
|
|
1048
|
+
viewRuleAutoLayout$1,
|
|
1049
|
+
viewRuleStyle$1,
|
|
1050
|
+
viewRuleGlobalStyle$1,
|
|
1051
|
+
viewRuleGlobalPredicate$1
|
|
1052
|
+
]);
|
|
1053
|
+
/**
|
|
1054
|
+
* Replicates ParsedElementView from the core,
|
|
1055
|
+
* less strict, as the generator should be able to handle missing fields and provide defaults.
|
|
1056
|
+
*/
|
|
1057
|
+
const deploymentView$1 = viewProps.extend({
|
|
1058
|
+
_type: z$1.literal("deployment"),
|
|
1059
|
+
rules: z$1.array(deploymentViewRule$1).optional().default([])
|
|
1060
|
+
});
|
|
1061
|
+
const dynamicStep$1 = z$1.object({
|
|
1062
|
+
source: fqn,
|
|
1063
|
+
target: fqn,
|
|
1064
|
+
title: z$1.string().nullish().default(null),
|
|
1065
|
+
kind: z$1.string().nullish(),
|
|
1066
|
+
description: markdownOrString.nullish(),
|
|
1067
|
+
technology: z$1.string().nullish(),
|
|
1068
|
+
notation: z$1.string().nullish(),
|
|
1069
|
+
notes: markdownOrString.nullish(),
|
|
1070
|
+
color: color.optional(),
|
|
1071
|
+
line: line.optional(),
|
|
1072
|
+
head: arrow.optional(),
|
|
1073
|
+
tail: arrow.optional(),
|
|
1074
|
+
isBackward: z$1.boolean().optional(),
|
|
1075
|
+
navigateTo: viewId.nullish()
|
|
1076
|
+
}).readonly().transform(pickBy(isNonNullish));
|
|
1077
|
+
const dynamicStepsSeries$1 = z$1.object({
|
|
1078
|
+
seriesId: z$1.string().optional(),
|
|
1079
|
+
__series: z$1.array(z$1.any()).readonly()
|
|
1080
|
+
}).readonly().transform(pickBy(isNonNullish));
|
|
1081
|
+
const dynamicStepsParallel$1 = z$1.object({
|
|
1082
|
+
parallelId: z$1.string().optional(),
|
|
1083
|
+
__parallel: z$1.array(z$1.any()).readonly()
|
|
1084
|
+
}).readonly().transform(pickBy(isNonNullish));
|
|
1085
|
+
const dynamicViewStep$1 = z$1.union([
|
|
1086
|
+
dynamicStep$1,
|
|
1087
|
+
dynamicStepsSeries$1,
|
|
1088
|
+
dynamicStepsParallel$1
|
|
1089
|
+
]);
|
|
1090
|
+
const dynamicViewIncludeRule$1 = z$1.strictObject({ include: z$1.array(expression$1) });
|
|
1091
|
+
const dynamicViewRule$1 = z$1.union([
|
|
1092
|
+
dynamicViewIncludeRule$1,
|
|
1093
|
+
viewRuleGlobalPredicate$1,
|
|
1094
|
+
viewRuleStyle$1,
|
|
1095
|
+
viewRuleGlobalStyle$1,
|
|
1096
|
+
viewRuleAutoLayout$1
|
|
1097
|
+
]);
|
|
1098
|
+
const dynamicViewVariant = z$1.literal(["diagram", "sequence"]);
|
|
1099
|
+
/**
|
|
1100
|
+
* Replicates ParsedDynamicView from the core,
|
|
1101
|
+
* less strict, as the generator should be able to handle missing fields and provide defaults.
|
|
1102
|
+
*/
|
|
1103
|
+
const dynamicView$1 = viewProps.extend({
|
|
1104
|
+
_type: z$1.literal("dynamic"),
|
|
1105
|
+
variant: dynamicViewVariant.optional(),
|
|
1106
|
+
steps: z$1.array(dynamicViewStep$1).optional(),
|
|
1107
|
+
rules: z$1.array(dynamicViewRule$1).optional()
|
|
1108
|
+
});
|
|
1109
|
+
const anyView$1 = z$1.union([
|
|
1110
|
+
elementView$1,
|
|
1111
|
+
deploymentView$1,
|
|
1112
|
+
dynamicView$1
|
|
1113
|
+
]);
|
|
1114
|
+
const views$1 = z$1.record(viewId, anyView$1);
|
|
1115
|
+
const likec4data$1 = z$1.object({
|
|
1116
|
+
...schema$1.shape,
|
|
1117
|
+
views: views$1,
|
|
1118
|
+
project: z$1.object({
|
|
1119
|
+
id: z$1.string(),
|
|
1120
|
+
styles: LikeC4StylesConfigSchema.nullish()
|
|
1121
|
+
}),
|
|
1122
|
+
deployment: schema$2,
|
|
1123
|
+
deployments: schema$2,
|
|
1124
|
+
specification: schema
|
|
1125
|
+
}).partial().readonly().transform(normalizeStyles);
|
|
1126
|
+
function normalizeStyles(data) {
|
|
1127
|
+
const elementSpecs = data.specification?.elements;
|
|
1128
|
+
if (!isEmptyish(elementSpecs) && !isEmptyish(data.elements)) data = {
|
|
1129
|
+
...data,
|
|
1130
|
+
elements: mapValues(data.elements, (element) => normalizeElementStyles(element, elementSpecs))
|
|
1131
|
+
};
|
|
1132
|
+
return data;
|
|
1133
|
+
}
|
|
1134
|
+
function normalizeElementStyles(element, specs) {
|
|
1135
|
+
const spec = specs[element.kind];
|
|
1136
|
+
if (!spec) return element;
|
|
1137
|
+
const specStyle = spec.style ?? {};
|
|
1138
|
+
return produce(element, (draft) => {
|
|
1139
|
+
for (const key of [
|
|
1140
|
+
"description",
|
|
1141
|
+
"technology",
|
|
1142
|
+
"title",
|
|
1143
|
+
"tags",
|
|
1144
|
+
"summary"
|
|
1145
|
+
]) {
|
|
1146
|
+
const specValue = spec[key];
|
|
1147
|
+
const elementValue = element[key];
|
|
1148
|
+
if (isDeepEqual(specValue, elementValue)) delete draft[key];
|
|
1149
|
+
}
|
|
1150
|
+
if (!element.style) return;
|
|
1151
|
+
for (const [key, value] of entries(specStyle)) if (isDeepEqual(element.style?.[key], value)) delete draft.style[key];
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
const schemas = {
|
|
1155
|
+
common: common_exports,
|
|
1156
|
+
expr: expression_exports,
|
|
1157
|
+
specification: specification_exports$1,
|
|
1158
|
+
model: model_exports$1,
|
|
1159
|
+
deployment: deployment_exports$1,
|
|
1160
|
+
views: views_exports$1,
|
|
1161
|
+
likec4data: likec4data$1
|
|
1162
|
+
};
|
|
1163
|
+
var properties_exports = /* @__PURE__ */ __exportAll({
|
|
1164
|
+
colorProperty: () => colorProperty,
|
|
1165
|
+
descriptionProperty: () => descriptionProperty,
|
|
1166
|
+
iconProperty: () => iconProperty,
|
|
1167
|
+
linkProperty: () => linkProperty,
|
|
1168
|
+
linksProperty: () => linksProperty,
|
|
1169
|
+
markdownProperty: () => markdownProperty,
|
|
1170
|
+
metadataProperty: () => metadataProperty,
|
|
1171
|
+
metadataValue: () => metadataValue,
|
|
1172
|
+
notationProperty: () => notationProperty,
|
|
1173
|
+
notesProperty: () => notesProperty,
|
|
1174
|
+
opacityProperty: () => opacityProperty,
|
|
1175
|
+
styleBlockProperty: () => styleBlockProperty,
|
|
1176
|
+
styleProperties: () => styleProperties,
|
|
1177
|
+
summaryProperty: () => summaryProperty,
|
|
1178
|
+
tagsProperty: () => tagsProperty,
|
|
1179
|
+
technologyProperty: () => technologyProperty,
|
|
1180
|
+
textProperty: () => textProperty,
|
|
1181
|
+
titleProperty: () => titleProperty
|
|
1182
|
+
});
|
|
1183
|
+
/**
|
|
1184
|
+
* Print a property from the context as a text.
|
|
1185
|
+
*/
|
|
1186
|
+
function textProperty(propertyName, keyword) {
|
|
1187
|
+
return select((e) => e[propertyName], spaceBetween(print$1(keyword ?? propertyName), text()));
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Print a property from the context as a markdown string.
|
|
1191
|
+
*/
|
|
1192
|
+
function markdownProperty(propertyName, keyword) {
|
|
1193
|
+
return select((e) => e[propertyName], spaceBetween(print$1(keyword ?? propertyName), markdownOrString$1()));
|
|
1194
|
+
}
|
|
1195
|
+
const titleProperty = () => property("title", spaceBetween(print$1("title"), text()));
|
|
1196
|
+
const summaryProperty = () => property("summary", spaceBetween(print$1("summary"), markdownOrString$1()));
|
|
1197
|
+
const descriptionProperty = () => property("description", spaceBetween(print$1("description"), markdownOrString$1()));
|
|
1198
|
+
const notesProperty = () => property("notes", spaceBetween(print$1("notes"), markdownOrString$1()));
|
|
1199
|
+
const technologyProperty = () => property("technology", spaceBetween(print$1("technology"), text()));
|
|
1200
|
+
const notationProperty = () => property("notation", spaceBetween(print$1("notation"), text()));
|
|
1201
|
+
function printMetadataValue() {
|
|
1202
|
+
return operation(({ ctx, out }) => {
|
|
1203
|
+
if (isString(ctx)) return text()({
|
|
1204
|
+
ctx,
|
|
1205
|
+
out
|
|
1206
|
+
});
|
|
1207
|
+
return print$1()({
|
|
1208
|
+
ctx,
|
|
1209
|
+
out
|
|
1210
|
+
});
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
function metadataValue() {
|
|
1214
|
+
return piped(guard(isNot(isArray), printMetadataValue()), guard(isArray, body("[", "]")(foreach(printMetadataValue(), {
|
|
1215
|
+
appendNewLineIfNotEmpty: true,
|
|
1216
|
+
suffix(element, index, isLast) {
|
|
1217
|
+
return !isLast ? "," : void 0;
|
|
1218
|
+
}
|
|
1219
|
+
}))));
|
|
1220
|
+
}
|
|
1221
|
+
const metadataProperty = () => select((e) => e.metadata ? entries(e.metadata) : void 0, body("metadata")(foreach(spaceBetween(print$1((v) => v[0]), property("1", metadataValue())), separateNewLine())));
|
|
1222
|
+
const tagsProperty = () => property("tags", print$1((v) => v.map((t) => `#${t}`).join(", ")));
|
|
1223
|
+
function linkProperty() {
|
|
1224
|
+
return spaceBetween(select((l) => typeof l === "string" ? { url: l } : exact({
|
|
1225
|
+
url: l.url,
|
|
1226
|
+
title: l.title
|
|
1227
|
+
}), print$1("link"), print$1((v) => v.url), property("title", inlineText())));
|
|
1228
|
+
}
|
|
1229
|
+
const linksProperty = () => property("links", foreachNewLine(linkProperty()));
|
|
1230
|
+
function styleBlockProperty() {
|
|
1231
|
+
return select((e) => e.style, body("style")(styleProperties()));
|
|
1232
|
+
}
|
|
1233
|
+
function colorProperty() {
|
|
1234
|
+
return property("color", spaceBetween(print$1("color"), print$1()));
|
|
1235
|
+
}
|
|
1236
|
+
function opacityProperty() {
|
|
1237
|
+
return property("opacity", spaceBetween(print$1("opacity"), print$1((v) => `${v}%`)));
|
|
1238
|
+
}
|
|
1239
|
+
function iconProperty() {
|
|
1240
|
+
return property("icon", spaceBetween(print$1("icon"), print$1()));
|
|
1241
|
+
}
|
|
1242
|
+
const styleProperties = zodOp(style)(lines(property("shape"), colorProperty(), iconProperty(), property("iconColor"), property("iconSize"), property("iconPosition"), property("border"), opacityProperty(), property("size"), property("padding"), property("textSize"), property("multiple")));
|
|
1243
|
+
var expressions_exports = /* @__PURE__ */ __exportAll({
|
|
1244
|
+
directRelationExpr: () => directRelationExpr,
|
|
1245
|
+
expression: () => expression,
|
|
1246
|
+
fqnExpr: () => fqnExpr,
|
|
1247
|
+
fqnExprAny: () => fqnExprAny,
|
|
1248
|
+
fqnExprCustom: () => fqnExprCustom,
|
|
1249
|
+
fqnExprOrWhere: () => fqnExprOrWhere,
|
|
1250
|
+
fqnRef: () => fqnRef,
|
|
1251
|
+
inOutRelationExpr: () => inOutRelationExpr,
|
|
1252
|
+
incomingRelationExpr: () => incomingRelationExpr,
|
|
1253
|
+
outgoingRelationExpr: () => outgoingRelationExpr,
|
|
1254
|
+
relationExpr: () => relationExpr,
|
|
1255
|
+
relationExprAny: () => relationExprAny,
|
|
1256
|
+
relationExprCustom: () => relationExprCustom,
|
|
1257
|
+
relationExprOrWhere: () => relationExprOrWhere,
|
|
1258
|
+
whereAnd: () => whereAnd,
|
|
1259
|
+
whereKindEqual: () => whereKindEqual,
|
|
1260
|
+
whereMetadataEqual: () => whereMetadataEqual,
|
|
1261
|
+
whereNot: () => whereNot,
|
|
1262
|
+
whereOperator: () => whereOperator,
|
|
1263
|
+
whereOr: () => whereOr,
|
|
1264
|
+
whereParticipant: () => whereParticipant,
|
|
1265
|
+
whereTagEqual: () => whereTagEqual
|
|
1266
|
+
});
|
|
1267
|
+
function appendSelector(out, selector) {
|
|
1268
|
+
if (selector) switch (selector) {
|
|
1269
|
+
case "children":
|
|
1270
|
+
out.append(".*");
|
|
1271
|
+
break;
|
|
1272
|
+
case "descendants":
|
|
1273
|
+
out.append(".**");
|
|
1274
|
+
break;
|
|
1275
|
+
case "expanded":
|
|
1276
|
+
out.append("._");
|
|
1277
|
+
break;
|
|
1278
|
+
default: nonexhaustive(selector);
|
|
1279
|
+
}
|
|
1280
|
+
return out;
|
|
1281
|
+
}
|
|
1282
|
+
const whereTagEqual = zodOp(whereTag)(function whereTagEqualOp({ ctx: { tag }, out }) {
|
|
1283
|
+
if ("eq" in tag) return out.appendTemplate`tag is #${tag.eq}`;
|
|
1284
|
+
if ("neq" in tag) return out.appendTemplate`tag is not #${tag.neq}`;
|
|
1285
|
+
nonexhaustive(tag);
|
|
1286
|
+
});
|
|
1287
|
+
const whereKindEqual = zodOp(whereKind)(function whereKindEqualOp({ ctx: { kind }, out }) {
|
|
1288
|
+
if ("eq" in kind) return out.appendTemplate`kind is ${kind.eq}`;
|
|
1289
|
+
if ("neq" in kind) return out.appendTemplate`kind is not ${kind.neq}`;
|
|
1290
|
+
nonexhaustive(kind);
|
|
1291
|
+
});
|
|
1292
|
+
function quoteMetadataValue(v) {
|
|
1293
|
+
return v === "true" || v === "false" ? v : `"${v}"`;
|
|
1294
|
+
}
|
|
1295
|
+
const whereMetadataEqual = zodOp(whereMetadata)(function whereMetadataEqualOp({ ctx: { metadata }, out }) {
|
|
1296
|
+
const { key, value } = metadata;
|
|
1297
|
+
if (value === void 0) return out.appendTemplate`metadata.${key}`;
|
|
1298
|
+
if ("eq" in value) return out.append(`metadata.${key} is ${quoteMetadataValue(value.eq)}`);
|
|
1299
|
+
if ("neq" in value) return out.append(`metadata.${key} is not ${quoteMetadataValue(value.neq)}`);
|
|
1300
|
+
nonexhaustive(value);
|
|
1301
|
+
});
|
|
1302
|
+
const whereNot = zodOp(whereNot$1)(property("not", spaceBetween(print$1("not ("), lazy(() => whereOperator()), print$1(")"))));
|
|
1303
|
+
const whereParticipant = zodOp(whereParticipant$1)(function whereParticipantOp({ ctx: { participant, operator }, out }) {
|
|
1304
|
+
out.append(participant, ".");
|
|
1305
|
+
if ("tag" in operator) {
|
|
1306
|
+
whereTagEqual()({
|
|
1307
|
+
ctx: operator,
|
|
1308
|
+
out
|
|
1309
|
+
});
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
if ("kind" in operator) {
|
|
1313
|
+
whereKindEqual()({
|
|
1314
|
+
ctx: operator,
|
|
1315
|
+
out
|
|
1316
|
+
});
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
if ("metadata" in operator) {
|
|
1320
|
+
whereMetadataEqual()({
|
|
1321
|
+
ctx: operator,
|
|
1322
|
+
out
|
|
1323
|
+
});
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
nonexhaustive(operator);
|
|
1327
|
+
});
|
|
1328
|
+
const whereAnd = zodOp(whereAnd$1)(function whereAndOp({ ctx: { and }, out }) {
|
|
1329
|
+
const operands = map(and, (operand) => {
|
|
1330
|
+
let { out } = executeOnFresh(operand, whereOperator());
|
|
1331
|
+
if ("or" in operand) out = fresh().out.append("(", ...out.contents, ")");
|
|
1332
|
+
return out;
|
|
1333
|
+
});
|
|
1334
|
+
return out.append(joinToNode(operands, {
|
|
1335
|
+
appendNewLineIfNotEmpty: true,
|
|
1336
|
+
skipNewLineAfterLastItem: true,
|
|
1337
|
+
prefix(_element, index) {
|
|
1338
|
+
return index > 0 ? "and " : void 0;
|
|
1339
|
+
}
|
|
1340
|
+
}));
|
|
1341
|
+
});
|
|
1342
|
+
const whereOr = zodOp(whereOr$1)(({ ctx: { or }, out }) => {
|
|
1343
|
+
const operands = map(or, (operand) => {
|
|
1344
|
+
let { out } = executeOnFresh(operand, whereOperator());
|
|
1345
|
+
if ("and" in operand) out = fresh().out.append("(", ...out.contents, ")");
|
|
1346
|
+
return out;
|
|
1347
|
+
});
|
|
1348
|
+
return out.append(joinToNode(operands, {
|
|
1349
|
+
appendNewLineIfNotEmpty: true,
|
|
1350
|
+
skipNewLineAfterLastItem: true,
|
|
1351
|
+
prefix(_element, index) {
|
|
1352
|
+
return index > 0 ? "or " : void 0;
|
|
1353
|
+
}
|
|
1354
|
+
}));
|
|
1355
|
+
});
|
|
1356
|
+
const whereOperator = zodOp(whereOperator$1)(({ ctx, exec }) => {
|
|
1357
|
+
if ("and" in ctx) return exec(ctx, whereAnd());
|
|
1358
|
+
if ("or" in ctx) return exec(ctx, whereOr());
|
|
1359
|
+
if ("not" in ctx) return exec(ctx, whereNot());
|
|
1360
|
+
if ("tag" in ctx) return exec(ctx, whereTagEqual());
|
|
1361
|
+
if ("kind" in ctx) return exec(ctx, whereKindEqual());
|
|
1362
|
+
if ("metadata" in ctx) return exec(ctx, whereMetadataEqual());
|
|
1363
|
+
if ("participant" in ctx) return exec(ctx, whereParticipant());
|
|
1364
|
+
nonexhaustive(ctx);
|
|
1365
|
+
});
|
|
1366
|
+
const fqnRef = zodOp(fqnRef$1)(({ ctx, out }) => {
|
|
1367
|
+
if ("model" in ctx) out.append(ctx.model);
|
|
1368
|
+
else {
|
|
1369
|
+
out.append(ctx.deployment);
|
|
1370
|
+
if (ctx.element) out.append(".", ctx.element);
|
|
1371
|
+
}
|
|
1372
|
+
return out;
|
|
1373
|
+
});
|
|
1374
|
+
const fqnExpr = zodOp(fqnExpr$1)(({ ctx, out, exec }) => {
|
|
1375
|
+
if ("wildcard" in ctx) return out.append("*");
|
|
1376
|
+
if ("elementKind" in ctx) return out.append("element.kind").append(ctx.isEqual ? " = " : " != ").append(ctx.elementKind);
|
|
1377
|
+
if ("elementTag" in ctx) return out.append("element.tag").append(ctx.isEqual ? " = " : " != ").append(`#${ctx.elementTag}`);
|
|
1378
|
+
if ("ref" in ctx) {
|
|
1379
|
+
exec(ctx.ref, fqnRef());
|
|
1380
|
+
appendSelector(out, ctx.selector);
|
|
1381
|
+
return out;
|
|
1382
|
+
}
|
|
1383
|
+
nonexhaustive(ctx);
|
|
1384
|
+
});
|
|
1385
|
+
const fqnExprCustom = zodOp(fqnExprCustom$1)(({ ctx: { custom }, exec }) => {
|
|
1386
|
+
exec(custom.expr, fqnExprOrWhere());
|
|
1387
|
+
const customOp = withctx(custom)(body("with")(titleProperty(), descriptionProperty(), notationProperty(), notesProperty(), property("navigateTo"), styleProperties()));
|
|
1388
|
+
if ("where" in custom.expr) return exec({}, indent(customOp));
|
|
1389
|
+
return exec({}, space(), customOp);
|
|
1390
|
+
});
|
|
1391
|
+
const fqnExprOrWhere = zodOp(fqnExprOrWhere$1)(({ ctx, exec }) => {
|
|
1392
|
+
if ("where" in ctx) {
|
|
1393
|
+
exec(ctx.where.expr, fqnExpr());
|
|
1394
|
+
exec(ctx.where.condition, indent(print$1("where"), indent(whereOperator())));
|
|
1395
|
+
return;
|
|
1396
|
+
}
|
|
1397
|
+
exec(ctx, fqnExpr());
|
|
1398
|
+
});
|
|
1399
|
+
const fqnExprAny = zodOp(fqnExprAny$1)(({ ctx, out }) => {
|
|
1400
|
+
if ("custom" in ctx) return fqnExprCustom()({
|
|
1401
|
+
ctx,
|
|
1402
|
+
out
|
|
1403
|
+
});
|
|
1404
|
+
return fqnExprOrWhere()({
|
|
1405
|
+
ctx,
|
|
1406
|
+
out
|
|
1407
|
+
});
|
|
1408
|
+
});
|
|
1409
|
+
const directRelationExpr = zodOp(directRelationExpr$1)(merge(property("source", fqnExpr()), print$1((v) => v.isBidirectional ? " <-> " : " -> "), property("target", fqnExpr())));
|
|
1410
|
+
const incomingRelationExpr = zodOp(incomingRelationExpr$1)(merge(print$1("-> "), property("incoming", fqnExpr())));
|
|
1411
|
+
const outgoingRelationExpr = zodOp(outgoingRelationExpr$1)(merge(property("outgoing", fqnExpr()), print$1(" ->")));
|
|
1412
|
+
const inOutRelationExpr = zodOp(inoutRelationExpr)(merge(print$1("-> "), property("inout", fqnExpr()), print$1(" ->")));
|
|
1413
|
+
const relationExpr = zodOp(relationExpr$1)(({ ctx, exec }) => {
|
|
1414
|
+
if ("source" in ctx) return exec(ctx, directRelationExpr());
|
|
1415
|
+
if ("incoming" in ctx) return exec(ctx, incomingRelationExpr());
|
|
1416
|
+
if ("outgoing" in ctx) return exec(ctx, outgoingRelationExpr());
|
|
1417
|
+
if ("inout" in ctx) return exec(ctx, inOutRelationExpr());
|
|
1418
|
+
nonexhaustive(ctx);
|
|
1419
|
+
});
|
|
1420
|
+
const relationExprOrWhere = zodOp(relationExprOrWhere$1)(({ ctx, out }) => {
|
|
1421
|
+
if ("where" in ctx) return merge(withctx(ctx.where.expr)(relationExpr()), indent(print$1("where"), indent(withctx(ctx.where.condition)(whereOperator()))))({
|
|
1422
|
+
ctx,
|
|
1423
|
+
out
|
|
1424
|
+
});
|
|
1425
|
+
return relationExpr()({
|
|
1426
|
+
ctx,
|
|
1427
|
+
out
|
|
1428
|
+
});
|
|
1429
|
+
});
|
|
1430
|
+
const relationExprCustom = zodOp(relationExprCustom$1)(({ ctx: { customRelation }, exec }) => {
|
|
1431
|
+
exec(customRelation.expr, relationExprOrWhere());
|
|
1432
|
+
const customOp = withctx(customRelation)(body("with")(titleProperty(), descriptionProperty(), notationProperty(), markdownProperty("notes"), property("navigateTo"), styleProperties(), property("head"), property("tail"), property("line")));
|
|
1433
|
+
if ("where" in customRelation.expr) exec({}, indent(customOp));
|
|
1434
|
+
else exec({}, space(), customOp);
|
|
1435
|
+
});
|
|
1436
|
+
const relationExprAny = zodOp(relationExprAny$1)(({ ctx, exec }) => {
|
|
1437
|
+
if ("customRelation" in ctx) return exec(ctx, relationExprCustom());
|
|
1438
|
+
return exec(ctx, relationExprOrWhere());
|
|
1439
|
+
});
|
|
1440
|
+
const expression = zodOp(expression$1)(({ ctx, exec }) => {
|
|
1441
|
+
if ("custom" in ctx) return exec(ctx, fqnExprCustom());
|
|
1442
|
+
if ("customRelation" in ctx) return exec(ctx, relationExprCustom());
|
|
1443
|
+
if ("wildcard" in ctx || "ref" in ctx || "elementKind" in ctx || "elementTag" in ctx) return exec(ctx, fqnExpr());
|
|
1444
|
+
if ("source" in ctx || "incoming" in ctx || "outgoing" in ctx || "inout" in ctx) return exec(ctx, relationExpr());
|
|
1445
|
+
if ("where" in ctx) {
|
|
1446
|
+
const { expr, condition } = ctx.where;
|
|
1447
|
+
if ("source" in expr || "incoming" in expr || "outgoing" in expr || "inout" in expr) return exec({ where: {
|
|
1448
|
+
expr,
|
|
1449
|
+
condition
|
|
1450
|
+
} }, relationExprOrWhere());
|
|
1451
|
+
return exec({ where: {
|
|
1452
|
+
expr,
|
|
1453
|
+
condition
|
|
1454
|
+
} }, fqnExprOrWhere());
|
|
1455
|
+
}
|
|
1456
|
+
nonexhaustive(ctx);
|
|
1457
|
+
});
|
|
1458
|
+
var deployment_exports = /* @__PURE__ */ __exportAll({
|
|
1459
|
+
deployment: () => deployment,
|
|
1460
|
+
instance: () => instance,
|
|
1461
|
+
node: () => node,
|
|
1462
|
+
relationship: () => relationship$1
|
|
1463
|
+
});
|
|
1464
|
+
function buildTree$1(elements) {
|
|
1465
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
1466
|
+
const roots = [];
|
|
1467
|
+
const sorted = pipe(elements, sortParentsFirst);
|
|
1468
|
+
for (const element of sorted) {
|
|
1469
|
+
let node;
|
|
1470
|
+
if ("element" in element) node = element;
|
|
1471
|
+
else node = {
|
|
1472
|
+
...element,
|
|
1473
|
+
children: []
|
|
1474
|
+
};
|
|
1475
|
+
nodes.set(element.id, node);
|
|
1476
|
+
const parentId = parentFqn(element.id);
|
|
1477
|
+
const parent = parentId ? nodes.get(parentId) : void 0;
|
|
1478
|
+
if (parent && "children" in parent) parent.children.push(node);
|
|
1479
|
+
else roots.push(node);
|
|
1480
|
+
}
|
|
1481
|
+
return {
|
|
1482
|
+
roots,
|
|
1483
|
+
nodes,
|
|
1484
|
+
exists: (fqn) => nodes.has(fqn)
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
function hasStyleProps$1(el) {
|
|
1488
|
+
return !isEmptyish(el.style);
|
|
1489
|
+
}
|
|
1490
|
+
function hasElementProps$1(el) {
|
|
1491
|
+
return !!(el.description || el.summary || el.technology || el.notation || el.tags && el.tags.length > 0 || el.links && el.links.length > 0 || !isEmptyish(el.metadata) || hasStyleProps$1(el));
|
|
1492
|
+
}
|
|
1493
|
+
const elementProperties$1 = zodOp(schemas.deployment.element)(lines(tagsProperty(), technologyProperty(), summaryProperty(), descriptionProperty(), linksProperty(), metadataProperty(), select((e) => hasStyleProps$1(e) ? e.style : void 0, body("style")(styleProperties()))));
|
|
1494
|
+
const instance = zodOp(schemas.deployment.instance)(spaceBetween(when((v) => nameFromFqn(v.id) !== nameFromFqn(v.element), print$1((v) => nameFromFqn(v.id)), print$1(" =")), print$1("instanceOf"), printProperty("element"), when((v) => !!v.title && v.title !== nameFromFqn(v.id), property("title", inlineText())), when((e) => hasElementProps$1(e), body(elementProperties$1()))));
|
|
1495
|
+
function node() {
|
|
1496
|
+
return function nodeOp({ ctx, out }) {
|
|
1497
|
+
const el = ctx;
|
|
1498
|
+
if ("element" in el) {
|
|
1499
|
+
instance()({
|
|
1500
|
+
ctx: el,
|
|
1501
|
+
out
|
|
1502
|
+
});
|
|
1503
|
+
return {
|
|
1504
|
+
ctx,
|
|
1505
|
+
out
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
invariant$1("children" in el, "Node must have children property");
|
|
1509
|
+
const needsBody = el.children.length > 0 || hasElementProps$1(el);
|
|
1510
|
+
const name = nameFromFqn(el.id);
|
|
1511
|
+
const inline = [
|
|
1512
|
+
print$1(name),
|
|
1513
|
+
print$1("="),
|
|
1514
|
+
print$1(el.kind)
|
|
1515
|
+
];
|
|
1516
|
+
if (el.title && el.title !== name) inline.push(inlineText(el.title));
|
|
1517
|
+
if (needsBody) inline.push(body(lines(2)(withctx(el, elementProperties$1()), ...el.children.map((node) => withctx(node, nodeOp)))));
|
|
1518
|
+
return spaceBetween(...inline)({
|
|
1519
|
+
ctx,
|
|
1520
|
+
out
|
|
1521
|
+
});
|
|
1522
|
+
};
|
|
1523
|
+
}
|
|
1524
|
+
function hasRelationStyle$1(rel) {
|
|
1525
|
+
return !!(rel.color || rel.line || rel.head || rel.tail);
|
|
1526
|
+
}
|
|
1527
|
+
function hasRelationProps$1(rel) {
|
|
1528
|
+
return !!(rel.description || rel.summary || rel.technology || rel.tags && rel.tags.length > 0 || rel.links && rel.links.length > 0 || !isEmptyish(rel.metadata) || hasRelationStyle$1(rel) || rel.navigateTo);
|
|
1529
|
+
}
|
|
1530
|
+
const relationship$1 = zodOp(schemas.deployment.relationship)(spaceBetween(property("source", fqnRef()), print$1((rel) => rel.kind ? `-[${rel.kind}]->` : "->"), property("target", fqnRef()), property("title", inlineText()), when(hasRelationProps$1, body(tagsProperty(), technologyProperty(), summaryProperty(), descriptionProperty(), property("navigateTo"), linksProperty(), metadataProperty(), when(hasRelationStyle$1, body("style")(colorProperty(), property("line"), property("head"), property("tail")))))));
|
|
1531
|
+
const deployment = zodOp(schemas.deployment.schema)(body("deployment")(lines(2)(select((d) => buildTree$1(d.elements ? values(d.elements) : []).roots, lines(2)(foreach(node()))), select((d) => d.relations ? values(d.relations) : void 0, lines(2)(foreach(relationship$1()))))));
|
|
1532
|
+
var model_exports = /* @__PURE__ */ __exportAll({
|
|
1533
|
+
element: () => element,
|
|
1534
|
+
model: () => model,
|
|
1535
|
+
relationship: () => relationship
|
|
1536
|
+
});
|
|
1537
|
+
function buildTree(elements) {
|
|
1538
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
1539
|
+
const roots = [];
|
|
1540
|
+
const sorted = pipe(elements, sortParentsFirst);
|
|
1541
|
+
for (const element of sorted) {
|
|
1542
|
+
const node = {
|
|
1543
|
+
...element,
|
|
1544
|
+
children: []
|
|
1545
|
+
};
|
|
1546
|
+
nodes.set(element.id, node);
|
|
1547
|
+
const parentId = parentFqn(element.id);
|
|
1548
|
+
const parent = parentId ? nodes.get(parentId) : void 0;
|
|
1549
|
+
if (parent) parent.children.push(node);
|
|
1550
|
+
else roots.push(node);
|
|
1551
|
+
}
|
|
1552
|
+
return {
|
|
1553
|
+
roots,
|
|
1554
|
+
nodes,
|
|
1555
|
+
exists: (fqn) => nodes.has(fqn)
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
function hasStyleProps(el) {
|
|
1559
|
+
return !isEmptyish(el.style);
|
|
1560
|
+
}
|
|
1561
|
+
function hasElementProps(el) {
|
|
1562
|
+
return !!(el.description || el.summary || el.technology || el.notation || el.tags && el.tags.length > 0 || el.links && el.links.length > 0 || !isEmptyish(el.metadata) || hasStyleProps(el));
|
|
1563
|
+
}
|
|
1564
|
+
const elementProperties = zodOp(schemas.model.element)(lines(tagsProperty(), technologyProperty(), summaryProperty(), descriptionProperty(), linksProperty(), metadataProperty(), select((e) => hasStyleProps(e) ? e.style : void 0, body("style")(styleProperties()))));
|
|
1565
|
+
function elementTree() {
|
|
1566
|
+
return function elementTreeNodeOp({ ctx, out }) {
|
|
1567
|
+
const el = ctx;
|
|
1568
|
+
const needsBody = (ctx.children?.length ?? 0) > 0 || hasElementProps(el);
|
|
1569
|
+
const name = nameFromFqn(el.id);
|
|
1570
|
+
const inline = [
|
|
1571
|
+
print$1(name),
|
|
1572
|
+
print$1("="),
|
|
1573
|
+
print$1(el.kind)
|
|
1574
|
+
];
|
|
1575
|
+
if (el.title && el.title !== name) inline.push(inlineText(el.title));
|
|
1576
|
+
if (needsBody) inline.push(body(lines(2)(withctx(el, elementProperties()), ...(ctx.children ?? []).map((node) => withctx(node, elementTree())))));
|
|
1577
|
+
return spaceBetween(...inline)({
|
|
1578
|
+
ctx,
|
|
1579
|
+
out
|
|
1580
|
+
});
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
function hasRelationStyle(rel) {
|
|
1584
|
+
return !!(rel.color || rel.line || rel.head || rel.tail);
|
|
1585
|
+
}
|
|
1586
|
+
function hasRelationProps(rel) {
|
|
1587
|
+
return !!(rel.description || rel.summary || rel.technology || rel.tags && rel.tags.length > 0 || rel.links && rel.links.length > 0 || !isEmptyish(rel.metadata) || hasRelationStyle(rel) || rel.navigateTo);
|
|
1588
|
+
}
|
|
1589
|
+
const relationship = zodOp(schemas.model.relationship)(spaceBetween(property("source", fqnRef()), print$1((rel) => rel.kind ? `-[${rel.kind}]->` : "->"), property("target", fqnRef()), property("title", inlineText()), when(hasRelationProps, body(tagsProperty(), technologyProperty(), summaryProperty(), descriptionProperty(), property("navigateTo"), linksProperty(), metadataProperty(), when(hasRelationStyle, body("style")(colorProperty(), property("line"), property("head"), property("tail")))))));
|
|
1590
|
+
const element = zodOp(schemas.model.element)(elementTree());
|
|
1591
|
+
const model = zodOp(schemas.model.schema)(body("model")(lines(2)(select((d) => buildTree(d.elements ? values(d.elements) : []).roots, lines(2)(foreach(elementTree()))), select((d) => d.relations ? values(d.relations) : void 0, lines(2)(foreach(relationship()))))));
|
|
1592
|
+
var specification_exports = /* @__PURE__ */ __exportAll({
|
|
1593
|
+
elementKind: () => elementKind,
|
|
1594
|
+
relationshipKind: () => relationshipKind,
|
|
1595
|
+
specification: () => specification,
|
|
1596
|
+
tagSpecification: () => tagSpecification
|
|
1597
|
+
});
|
|
1598
|
+
const tagSpecification = zodOp(z$1.tuple([z$1.string(), tagSpec]))(spaceBetween(print$1("tag"), printProperty("0"), property("1", property("color", body(spaceBetween(print$1("color"), print$1()))))));
|
|
1599
|
+
const elementKind = (keyword) => zodOp(z$1.tuple([z$1.string(), element$1]))(spaceBetween(print$1(keyword), printProperty("0"), property("1", body(tagsProperty(), titleProperty(), summaryProperty(), descriptionProperty(), technologyProperty(), notationProperty(), linksProperty(), property("style", body("style")(styleProperties()))))));
|
|
1600
|
+
const relationshipKind = zodOp(z$1.tuple([z$1.string(), relationship$2]))(spaceBetween(print$1("relationship"), printProperty("0"), property("1", body(technologyProperty(), notationProperty(), colorProperty(), property("line"), property("head"), property("tail")))));
|
|
1601
|
+
const specification = zodOp(schema)(body("specification")(lines(2)(select((c) => c.elements && entries(c.elements), foreachNewLine(elementKind("element")())), select((c) => c.deployments && entries(c.deployments), foreachNewLine(elementKind("deploymentNode")())), select((c) => c.relationships && entries(c.relationships), foreachNewLine(relationshipKind())), select((c) => c.tags && entries(c.tags), foreachNewLine(tagSpecification())))));
|
|
1602
|
+
var views_exports = /* @__PURE__ */ __exportAll({
|
|
1603
|
+
anyView: () => anyView,
|
|
1604
|
+
deploymentView: () => deploymentView,
|
|
1605
|
+
deploymentViewRule: () => deploymentViewRule,
|
|
1606
|
+
dynamicStep: () => dynamicStep,
|
|
1607
|
+
dynamicStepsParallel: () => dynamicStepsParallel,
|
|
1608
|
+
dynamicStepsSeries: () => dynamicStepsSeries,
|
|
1609
|
+
dynamicView: () => dynamicView,
|
|
1610
|
+
dynamicViewIncludeRule: () => dynamicViewIncludeRule,
|
|
1611
|
+
dynamicViewRule: () => dynamicViewRule,
|
|
1612
|
+
dynamicViewStep: () => dynamicViewStep,
|
|
1613
|
+
elementView: () => elementView,
|
|
1614
|
+
elementViewRule: () => elementViewRule,
|
|
1615
|
+
viewRuleAutoLayout: () => viewRuleAutoLayout,
|
|
1616
|
+
viewRuleGlobalPredicate: () => viewRuleGlobalPredicate,
|
|
1617
|
+
viewRuleGlobalStyle: () => viewRuleGlobalStyle,
|
|
1618
|
+
viewRuleGroup: () => viewRuleGroup,
|
|
1619
|
+
viewRulePredicate: () => viewRulePredicate,
|
|
1620
|
+
viewRuleRank: () => viewRuleRank,
|
|
1621
|
+
viewRuleStyle: () => viewRuleStyle,
|
|
1622
|
+
views: () => views
|
|
1623
|
+
});
|
|
1624
|
+
const viewTitleProperty = () => property("title", spaceBetween(print$1("title"), inlineText()));
|
|
1625
|
+
const viewRulePredicate = zodOp(schemas.views.viewRulePredicate)(({ ctx, exec }) => {
|
|
1626
|
+
let exprs;
|
|
1627
|
+
let type;
|
|
1628
|
+
if ("include" in ctx) {
|
|
1629
|
+
exprs = ctx.include;
|
|
1630
|
+
type = "include";
|
|
1631
|
+
} else if ("exclude" in ctx) {
|
|
1632
|
+
exprs = ctx.exclude;
|
|
1633
|
+
type = "exclude";
|
|
1634
|
+
}
|
|
1635
|
+
invariant(exprs && type, "Invalid view rule predicate");
|
|
1636
|
+
if (!hasAtLeast(exprs, 1)) return;
|
|
1637
|
+
const isMultiple = hasAtLeast(exprs, 2);
|
|
1638
|
+
const exprOp = withctx(exprs)(foreach(expression(), separateComma(isMultiple)));
|
|
1639
|
+
exec(ctx, merge(print$1(type), ...isMultiple ? [indent(exprOp)] : [space(), exprOp]));
|
|
1640
|
+
});
|
|
1641
|
+
const viewRuleStyle = zodOp(schemas.views.viewRuleStyle)(spaceBetween(print$1("style"), property("targets", foreach(expression(), separateComma())), body("{", "}")(notationProperty(), property("style", styleProperties()))));
|
|
1642
|
+
const viewRuleGroup = zodOp(schemas.views.viewRuleGroup)(({ ctx, exec }) => {
|
|
1643
|
+
throw new Error("not implemented");
|
|
1644
|
+
});
|
|
1645
|
+
const viewRuleGlobalStyle = zodOp(schemas.views.viewRuleGlobalStyle)(({ ctx, exec }) => {
|
|
1646
|
+
throw new Error("not implemented");
|
|
1647
|
+
});
|
|
1648
|
+
const viewRuleGlobalPredicate = zodOp(schemas.views.viewRuleGlobalPredicate)(({ ctx, exec }) => {
|
|
1649
|
+
throw new Error("not implemented");
|
|
1650
|
+
});
|
|
1651
|
+
const mapping = {
|
|
1652
|
+
"TB": "TopBottom",
|
|
1653
|
+
"BT": "BottomTop",
|
|
1654
|
+
"LR": "LeftRight",
|
|
1655
|
+
"RL": "RightLeft"
|
|
1656
|
+
};
|
|
1657
|
+
const viewRuleAutoLayout = zodOp(schemas.views.viewRuleAutoLayout)(spaceBetween(print$1("autoLayout"), property("direction", print$1((v) => mapping[v])), guard(hasProp("rankSep"), spaceBetween(printProperty("rankSep"), printProperty("nodeSep")))));
|
|
1658
|
+
const viewRuleRank = zodOp(schemas.views.viewRuleRank)(({ ctx, exec }) => {
|
|
1659
|
+
throw new Error("not implemented");
|
|
1660
|
+
});
|
|
1661
|
+
const elementViewRule = zodOp(schemas.views.elementViewRule)(({ ctx, exec }) => {
|
|
1662
|
+
if ("include" in ctx || "exclude" in ctx) return exec(ctx, viewRulePredicate());
|
|
1663
|
+
if ("groupRules" in ctx) return exec(ctx, viewRuleGroup());
|
|
1664
|
+
if ("rank" in ctx) return exec(ctx, viewRuleRank());
|
|
1665
|
+
if ("direction" in ctx) return exec(ctx, viewRuleAutoLayout());
|
|
1666
|
+
if ("styleId" in ctx) return exec(ctx, viewRuleGlobalStyle());
|
|
1667
|
+
if ("predicateId" in ctx) return exec(ctx, viewRuleGlobalPredicate());
|
|
1668
|
+
if ("targets" in ctx && "style" in ctx) return exec(ctx, viewRuleStyle());
|
|
1669
|
+
nonexhaustive(ctx);
|
|
1670
|
+
});
|
|
1671
|
+
const elementView = zodOp(schemas.views.elementView.partial({ _type: true }))(spaceBetween(print$1("view"), print$1((v) => v.id), property("viewOf", spaceBetween(print$1("of"), print$1())), body(lines(2)(lines(tagsProperty(), viewTitleProperty(), descriptionProperty(), linksProperty()), property("rules", foreachNewLine(elementViewRule()))))));
|
|
1672
|
+
const deploymentViewRule = zodOp(schemas.views.deploymentViewRule)(({ ctx, exec }) => {
|
|
1673
|
+
if ("include" in ctx || "exclude" in ctx) return exec(ctx, viewRulePredicate());
|
|
1674
|
+
if ("direction" in ctx) return exec(ctx, viewRuleAutoLayout());
|
|
1675
|
+
if ("styleId" in ctx) return exec(ctx, viewRuleGlobalStyle());
|
|
1676
|
+
if ("predicateId" in ctx) return exec(ctx, viewRuleGlobalPredicate());
|
|
1677
|
+
if ("targets" in ctx && "style" in ctx) return exec(ctx, viewRuleStyle());
|
|
1678
|
+
nonexhaustive(ctx);
|
|
1679
|
+
});
|
|
1680
|
+
const deploymentView = zodOp(schemas.views.deploymentView.partial({ _type: true }))(spaceBetween(print$1("deployment view"), print$1((v) => v.id), body(lines(2)(lines(tagsProperty(), viewTitleProperty(), descriptionProperty(), linksProperty()), property("rules", foreachNewLine(deploymentViewRule()))))));
|
|
1681
|
+
const dynamicStep = zodOp(schemas.views.dynamicStep)(spaceBetween(print$1((v) => v.source), print$1((v) => v.isBackward ? "<-" : "->"), print$1((v) => v.target), body(lines(titleProperty(), technologyProperty(), descriptionProperty(), notesProperty(), property("navigateTo"), notationProperty(), colorProperty(), property("line"), property("head"), property("tail")))));
|
|
1682
|
+
const dynamicStepsSeries = zodOp(schemas.views.dynamicStepsSeries)(({ ctx, exec }) => {
|
|
1683
|
+
throw new Error("Not implemented");
|
|
1684
|
+
});
|
|
1685
|
+
const dynamicStepsParallel = zodOp(schemas.views.dynamicStepsParallel)(({ ctx, exec }) => {
|
|
1686
|
+
throw new Error("Not implemented");
|
|
1687
|
+
});
|
|
1688
|
+
const dynamicViewStep = zodOp(schemas.views.dynamicViewStep)(({ ctx, exec }) => {
|
|
1689
|
+
if ("__series" in ctx) return exec(ctx, dynamicStepsSeries());
|
|
1690
|
+
if ("__parallel" in ctx) return exec(ctx, dynamicStepsParallel());
|
|
1691
|
+
return exec(ctx, dynamicStep());
|
|
1692
|
+
});
|
|
1693
|
+
const dynamicViewIncludeRule = zodOp(schemas.views.dynamicViewIncludeRule)(({ ctx, exec }) => {
|
|
1694
|
+
if (!hasAtLeast(ctx.include, 1)) return;
|
|
1695
|
+
const isMultiple = hasAtLeast(ctx.include, 2);
|
|
1696
|
+
const exprOp = withctx(ctx.include)(foreach(expression(), separateComma(isMultiple)));
|
|
1697
|
+
exec(ctx, merge(print$1("include"), ...isMultiple ? [indent(exprOp)] : [space(), exprOp]));
|
|
1698
|
+
});
|
|
1699
|
+
const dynamicViewRule = zodOp(schemas.views.dynamicViewRule)(({ ctx, exec }) => {
|
|
1700
|
+
if ("include" in ctx) return exec(ctx, dynamicViewIncludeRule());
|
|
1701
|
+
if ("predicateId" in ctx) return exec(ctx, viewRuleGlobalPredicate());
|
|
1702
|
+
if ("targets" in ctx && "style" in ctx) return exec(ctx, viewRuleStyle());
|
|
1703
|
+
if ("styleId" in ctx) return exec(ctx, viewRuleGlobalStyle());
|
|
1704
|
+
if ("direction" in ctx) return exec(ctx, viewRuleAutoLayout());
|
|
1705
|
+
nonexhaustive(ctx);
|
|
1706
|
+
});
|
|
1707
|
+
const dynamicView = zodOp(schemas.views.dynamicView.partial({ _type: true }))(spaceBetween(print$1("dynamic view"), print$1((v) => v.id), body(lines(2)(lines(tagsProperty(), viewTitleProperty(), descriptionProperty(), linksProperty(), property("variant")), property("steps", foreachNewLine(dynamicViewStep())), property("rules", foreachNewLine(dynamicViewRule()))))));
|
|
1708
|
+
const anyView = zodOp(schemas.views.anyView)(({ ctx, exec }) => {
|
|
1709
|
+
if ("_type" in ctx) {
|
|
1710
|
+
if (ctx._type == "element") return exec(ctx, elementView());
|
|
1711
|
+
if (ctx._type === "deployment") return exec(ctx, deploymentView());
|
|
1712
|
+
if (ctx._type === "dynamic") return exec(ctx, dynamicView());
|
|
1713
|
+
}
|
|
1714
|
+
nonexhaustive(ctx);
|
|
1715
|
+
});
|
|
1716
|
+
const views = zodOp(schemas.views.views)(body("views")(select((ctx) => values(ctx), foreach(anyView(), {
|
|
1717
|
+
separator: new CompositeGeneratorNode().appendNewLine().appendNewLine(),
|
|
1718
|
+
prefix: (_, index, isLast) => index === 0 && !isLast ? NL : void 0
|
|
1719
|
+
}))));
|
|
1720
|
+
z$1.object({});
|
|
1721
|
+
const likec4data = zodOp(schemas.likec4data)(lines(2)(property("specification", specification()), model(), property("deployment", deployment()), property("deployments", deployment()), property("views", views())));
|
|
1722
|
+
var operators_exports = /* @__PURE__ */ __exportAll({
|
|
1723
|
+
base: () => base_exports,
|
|
1724
|
+
deployment: () => deployment,
|
|
1725
|
+
deploymentView: () => deploymentView,
|
|
1726
|
+
deployments: () => deployment_exports,
|
|
1727
|
+
dynamicView: () => dynamicView,
|
|
1728
|
+
elementView: () => elementView,
|
|
1729
|
+
expr: () => expressions_exports,
|
|
1730
|
+
expression: () => expression,
|
|
1731
|
+
likec4data: () => likec4data,
|
|
1732
|
+
model: () => model,
|
|
1733
|
+
models: () => model_exports,
|
|
1734
|
+
props: () => properties_exports,
|
|
1735
|
+
specification: () => specification,
|
|
1736
|
+
specifications: () => specification_exports,
|
|
1737
|
+
views: () => views_exports
|
|
1738
|
+
});
|
|
1739
|
+
function generateLikeC4(input, params) {
|
|
1740
|
+
params = {
|
|
1741
|
+
indentation: 2,
|
|
1742
|
+
...params
|
|
1743
|
+
};
|
|
1744
|
+
return materialize(withctx(input, likec4data()), params.indentation);
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Prints the result of an operation with the data
|
|
1748
|
+
*
|
|
1749
|
+
* @see operators
|
|
1750
|
+
*
|
|
1751
|
+
* @example
|
|
1752
|
+
* ```ts
|
|
1753
|
+
* print(operators.expression, {
|
|
1754
|
+
* ref: {
|
|
1755
|
+
* model: 'some.el',
|
|
1756
|
+
* },
|
|
1757
|
+
* selector: 'descendants',
|
|
1758
|
+
* })
|
|
1759
|
+
* // "some.el.**"
|
|
1760
|
+
* ```
|
|
1761
|
+
*
|
|
1762
|
+
* @example
|
|
1763
|
+
* ```ts
|
|
1764
|
+
* print(operators.model, {
|
|
1765
|
+
* elements: [
|
|
1766
|
+
* {
|
|
1767
|
+
* id: 'cloud',
|
|
1768
|
+
* kind: 'system',
|
|
1769
|
+
* },
|
|
1770
|
+
* {
|
|
1771
|
+
* id: 'cloud.mobile',
|
|
1772
|
+
* kind: 'mobileapp',
|
|
1773
|
+
* shape: 'mobile',
|
|
1774
|
+
* color: 'amber',
|
|
1775
|
+
* }
|
|
1776
|
+
* ],
|
|
1777
|
+
* })
|
|
1778
|
+
* // model {
|
|
1779
|
+
* // cloud = system {
|
|
1780
|
+
* // mobile = mobileapp {
|
|
1781
|
+
* // style {
|
|
1782
|
+
* // shape mobile
|
|
1783
|
+
* // color amber
|
|
1784
|
+
* // }
|
|
1785
|
+
* // }
|
|
1786
|
+
* // }
|
|
1787
|
+
* // }
|
|
1788
|
+
* ```
|
|
1789
|
+
*/
|
|
1790
|
+
function print(operator, data, params) {
|
|
1791
|
+
return materialize(withctx(data, operator()), params?.indentation);
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Same as {@link print} but uses tab indentation
|
|
1795
|
+
*/
|
|
1796
|
+
function printTabIndent(operator, data) {
|
|
1797
|
+
return materialize(withctx(data, operator()), " ");
|
|
1798
|
+
}
|
|
1799
|
+
export { generateLikeC4 as generate, operators_exports as operators, print, printTabIndent };
|