@likec4/core 1.19.1 → 1.20.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.
Files changed (91) hide show
  1. package/dist/builder/index.cjs +881 -0
  2. package/dist/builder/index.d.cts +503 -0
  3. package/dist/builder/index.d.mts +5 -4
  4. package/dist/builder/index.d.ts +5 -4
  5. package/dist/builder/{index.js → index.mjs} +14 -4
  6. package/dist/compute-view/index.cjs +86 -0
  7. package/dist/compute-view/index.d.cts +23 -0
  8. package/dist/compute-view/index.d.mts +3 -2
  9. package/dist/compute-view/index.d.ts +3 -2
  10. package/dist/compute-view/{index.js → index.mjs} +6 -5
  11. package/dist/index.cjs +4320 -0
  12. package/dist/index.d.cts +270 -0
  13. package/dist/index.d.mts +130 -4
  14. package/dist/index.d.ts +130 -4
  15. package/dist/{index.js → index.mjs} +512 -7
  16. package/dist/model/index.cjs +40 -0
  17. package/dist/model/index.d.cts +259 -0
  18. package/dist/model/index.d.mts +8 -3
  19. package/dist/model/index.d.ts +8 -3
  20. package/dist/model/index.mjs +1 -0
  21. package/dist/shared/core.B2QYWlYe.cjs +435 -0
  22. package/dist/shared/core.B72vUaNB.d.cts +850 -0
  23. package/dist/shared/core.BGus30EM.cjs +8027 -0
  24. package/dist/shared/core.BRuJ3Wzf.d.mts +12 -0
  25. package/dist/shared/{core.BZ9Msq7w.d.mts → core.BdbFkE_p.d.cts} +14 -4
  26. package/dist/shared/core.BvdNMbcA.d.cts +12 -0
  27. package/dist/shared/{object_hash.CE_oF3I3.js → core.BxvDITEI.mjs} +26 -389
  28. package/dist/shared/core.ByNgh-mC.d.cts +127 -0
  29. package/dist/shared/core.C9DCnJh8.cjs +908 -0
  30. package/dist/shared/{index.DafVOuVd.js → core.CqCTxzMY.mjs} +1111 -572
  31. package/dist/shared/core.D74xkKkG.d.cts +148 -0
  32. package/dist/shared/{core.C05RDLhi.d.ts → core.D_Gc58Gt.d.ts} +23 -5
  33. package/dist/shared/core.Damrzla-.d.ts +12 -0
  34. package/dist/shared/{core.CmYMqgha.d.mts → core.Dfzrh1VA.d.mts} +23 -5
  35. package/dist/shared/core.DsoCu540.cjs +26 -0
  36. package/dist/shared/{view.CyZrG8BJ.js → core.DunIMHRf.mjs} +27 -1
  37. package/dist/shared/{core.BIfgabEw.d.ts → core.ZWiGANIJ.d.ts} +14 -4
  38. package/dist/shared/core.gv1bMwCC.cjs +39 -0
  39. package/dist/shared/core.jy6z2iRn.d.mts +729 -0
  40. package/dist/shared/core.m3rCQAv6.mjs +37 -0
  41. package/dist/types/index.cjs +107 -0
  42. package/dist/types/index.d.cts +72 -0
  43. package/dist/types/index.d.mts +2 -2
  44. package/dist/types/index.d.ts +2 -2
  45. package/dist/types/{index.js → index.mjs} +1 -1
  46. package/dist/utils/index.cjs +95 -0
  47. package/dist/utils/index.d.cts +356 -0
  48. package/dist/utils/index.d.mts +1 -64
  49. package/dist/utils/index.d.ts +1 -64
  50. package/dist/utils/index.mjs +56 -0
  51. package/package.json +52 -26
  52. package/src/builder/Builder.view-common.ts +21 -1
  53. package/src/compute-view/deployment-view/__test__/fixture.ts +31 -3
  54. package/src/compute-view/deployment-view/_types.ts +2 -1
  55. package/src/compute-view/deployment-view/compute.ts +4 -36
  56. package/src/compute-view/deployment-view/predicates/index.ts +8 -0
  57. package/src/compute-view/deployment-view/predicates/relation-direct.ts +125 -99
  58. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +16 -8
  59. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +18 -12
  60. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +16 -9
  61. package/src/compute-view/deployment-view/predicates/relation-where.ts +18 -0
  62. package/src/compute-view/deployment-view/predicates/utils.ts +214 -0
  63. package/src/compute-view/element-view/__test__/fixture.ts +17 -4
  64. package/src/compute-view/element-view/compute.ts +3 -2
  65. package/src/compute-view/element-view/predicates.ts +520 -0
  66. package/src/compute-view/element-view/utils.ts +11 -7
  67. package/src/compute-view/index.ts +1 -0
  68. package/src/compute-view/relationships-view/_types.ts +16 -0
  69. package/src/compute-view/relationships-view/compute.ts +74 -0
  70. package/src/compute-view/relationships-view/layout.ts +357 -0
  71. package/src/compute-view/relationships-view/utils.ts +40 -0
  72. package/src/compute-view/utils/relationExpressionToPredicates.ts +11 -4
  73. package/src/index.ts +16 -0
  74. package/src/model/DeploymentElementModel.ts +18 -1
  75. package/src/model/ElementModel.ts +13 -0
  76. package/src/model/LikeC4Model.ts +2 -2
  77. package/src/model/RelationModel.ts +9 -0
  78. package/src/model/connection/deployment/DeploymentConnectionModel.ts +11 -1
  79. package/src/model/guards.ts +17 -1
  80. package/src/model/view/LikeC4ViewModel.ts +7 -1
  81. package/src/model/view/NodeModel.ts +5 -0
  82. package/src/types/deployments.ts +1 -0
  83. package/src/types/expression-v2.ts +12 -0
  84. package/src/types/index.ts +1 -0
  85. package/src/types/operators.ts +46 -6
  86. package/src/types/view.ts +2 -2
  87. package/src/utils/index.ts +0 -5
  88. package/src/utils/iterable/unique.ts +1 -7
  89. package/dist/model/index.js +0 -1
  90. package/dist/utils/index.js +0 -347
  91. /package/dist/shared/{chunk-RAAYCPUM.M-JWF7SS.js → core.M-JWF7SS.mjs} +0 -0
@@ -0,0 +1,881 @@
1
+ 'use strict';
2
+
3
+ const model_index = require('../shared/core.BGus30EM.cjs');
4
+ const object_hash = require('../shared/core.C9DCnJh8.cjs');
5
+ const view = require('../shared/core.B2QYWlYe.cjs');
6
+ const chunkRAAYCPUM = require('../shared/core.DsoCu540.cjs');
7
+
8
+ function n(...r){return chunkRAAYCPUM.u(Object.fromEntries,r)}
9
+
10
+ function isPlainObject(value) {
11
+ if (value === null || typeof value !== "object") {
12
+ return false;
13
+ }
14
+ const prototype = Object.getPrototypeOf(value);
15
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
16
+ return false;
17
+ }
18
+ if (Symbol.iterator in value) {
19
+ return false;
20
+ }
21
+ if (Symbol.toStringTag in value) {
22
+ return Object.prototype.toString.call(value) === "[object Module]";
23
+ }
24
+ return true;
25
+ }
26
+
27
+ function _defu(baseObject, defaults, namespace = ".", merger) {
28
+ if (!isPlainObject(defaults)) {
29
+ return _defu(baseObject, {}, namespace, merger);
30
+ }
31
+ const object = Object.assign({}, defaults);
32
+ for (const key in baseObject) {
33
+ if (key === "__proto__" || key === "constructor") {
34
+ continue;
35
+ }
36
+ const value = baseObject[key];
37
+ if (value === null || value === void 0) {
38
+ continue;
39
+ }
40
+ if (merger && merger(object, key, value, namespace)) {
41
+ continue;
42
+ }
43
+ if (Array.isArray(value) && Array.isArray(object[key])) {
44
+ object[key] = [...value, ...object[key]];
45
+ } else if (isPlainObject(value) && isPlainObject(object[key])) {
46
+ object[key] = _defu(
47
+ value,
48
+ object[key],
49
+ (namespace ? `${namespace}.` : "") + key.toString(),
50
+ merger
51
+ );
52
+ } else {
53
+ object[key] = value;
54
+ }
55
+ }
56
+ return object;
57
+ }
58
+ function createDefu(merger) {
59
+ return (...arguments_) => (
60
+ // eslint-disable-next-line unicorn/no-array-reduce
61
+ arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
62
+ );
63
+ }
64
+ const defu = createDefu();
65
+
66
+ function parseWhere(where) {
67
+ if (object_hash.t(where)) {
68
+ const op = where;
69
+ switch (true) {
70
+ case op.startsWith("tag is not #"):
71
+ return {
72
+ tag: {
73
+ neq: op.replace("tag is not #", "")
74
+ }
75
+ };
76
+ case op.startsWith("tag is #"):
77
+ return {
78
+ tag: {
79
+ eq: op.replace("tag is #", "")
80
+ }
81
+ };
82
+ case op.startsWith("kind is not "):
83
+ return {
84
+ kind: {
85
+ neq: op.replace("kind is not ", "")
86
+ }
87
+ };
88
+ case op.startsWith("kind is "):
89
+ return {
90
+ kind: {
91
+ eq: op.replace("kind is ", "")
92
+ }
93
+ };
94
+ case op.startsWith("source."):
95
+ return {
96
+ operator: parseWhere(op.replace("source.", "")),
97
+ participant: "source"
98
+ };
99
+ case op.startsWith("target."):
100
+ return {
101
+ operator: parseWhere(op.replace("target.", "")),
102
+ participant: "target"
103
+ };
104
+ default:
105
+ throw new Error(`Unknown where operator: ${where}`);
106
+ }
107
+ }
108
+ if (where.and) {
109
+ return {
110
+ and: object_hash.m(where.and, parseWhere)
111
+ };
112
+ }
113
+ if (where.or) {
114
+ return {
115
+ or: object_hash.m(where.or, parseWhere)
116
+ };
117
+ }
118
+ if (where.not) {
119
+ return {
120
+ not: parseWhere(where.not)
121
+ };
122
+ }
123
+ throw new Error(`Unknown where operator: ${where}`);
124
+ }
125
+ function $include(...args) {
126
+ return (b) => {
127
+ let expr = b.$expr(args[0]);
128
+ if (args.length === 2) {
129
+ const condition = args[1].where ? parseWhere(args[1].where) : void 0;
130
+ if (condition) {
131
+ expr = {
132
+ where: {
133
+ expr,
134
+ condition
135
+ }
136
+ };
137
+ }
138
+ const custom = args[1].with;
139
+ if (custom) {
140
+ const isElement = view.isElementPredicateExpr(expr);
141
+ if (isElement) {
142
+ expr = {
143
+ custom: {
144
+ ...custom,
145
+ expr
146
+ }
147
+ };
148
+ } else {
149
+ expr = {
150
+ customRelation: {
151
+ ...custom,
152
+ relation: expr
153
+ }
154
+ };
155
+ }
156
+ }
157
+ }
158
+ b.include(expr);
159
+ return b;
160
+ };
161
+ }
162
+ function $exclude(...args) {
163
+ return (b) => {
164
+ let expr = b.$expr(args[0]);
165
+ if (args.length === 2 && args[1].where) {
166
+ const condition = parseWhere(args[1].where);
167
+ expr = {
168
+ where: {
169
+ expr,
170
+ condition
171
+ }
172
+ };
173
+ }
174
+ b.exclude(expr);
175
+ return b;
176
+ };
177
+ }
178
+ function $style(element, { notation, ...style }) {
179
+ return (b) => b.style({
180
+ targets: (view.o(element) ? element : [element]).map((e) => b.$expr(e)),
181
+ ...notation ? { notation } : {},
182
+ style: {
183
+ ...style
184
+ }
185
+ });
186
+ }
187
+ function $autoLayout(layout) {
188
+ return (b) => b.autoLayout(layout);
189
+ }
190
+ function $rules(...rules) {
191
+ return (b) => rules.reduce((b2, rule) => rule(b2), b);
192
+ }
193
+
194
+ function $deploymentExpr(expr) {
195
+ if (!object_hash.t(expr)) {
196
+ return expr;
197
+ }
198
+ const asTypedDeploymentExpression = (expr2) => {
199
+ return expr2;
200
+ };
201
+ if (expr === "*") {
202
+ return asTypedDeploymentExpression({ wildcard: true });
203
+ }
204
+ if (expr.startsWith("->")) {
205
+ if (expr.endsWith("->")) {
206
+ return asTypedDeploymentExpression({
207
+ inout: $deploymentExpr(expr.replace(/->/g, "").trim())
208
+ });
209
+ }
210
+ return asTypedDeploymentExpression({
211
+ incoming: $deploymentExpr(expr.replace("-> ", ""))
212
+ });
213
+ }
214
+ if (expr.endsWith(" ->")) {
215
+ return asTypedDeploymentExpression({
216
+ outgoing: $deploymentExpr(expr.replace(" ->", ""))
217
+ });
218
+ }
219
+ if (expr.includes(" <-> ")) {
220
+ const [source, target] = expr.split(" <-> ");
221
+ return asTypedDeploymentExpression({
222
+ source: $deploymentExpr(source),
223
+ target: $deploymentExpr(target),
224
+ isBidirectional: true
225
+ });
226
+ }
227
+ if (expr.includes(" -> ")) {
228
+ const [source, target] = expr.split(" -> ");
229
+ return asTypedDeploymentExpression({
230
+ source: $deploymentExpr(source),
231
+ target: $deploymentExpr(target)
232
+ });
233
+ }
234
+ if (expr.endsWith("._")) {
235
+ return asTypedDeploymentExpression({
236
+ ref: {
237
+ deployment: expr.replace("._", "")
238
+ },
239
+ selector: "expanded"
240
+ });
241
+ }
242
+ if (expr.endsWith(".**")) {
243
+ return asTypedDeploymentExpression({
244
+ ref: {
245
+ deployment: expr.replace(".**", "")
246
+ },
247
+ selector: "descendants"
248
+ });
249
+ }
250
+ if (expr.endsWith(".*")) {
251
+ return asTypedDeploymentExpression({
252
+ ref: {
253
+ deployment: expr.replace(".*", "")
254
+ },
255
+ selector: "children"
256
+ });
257
+ }
258
+ return asTypedDeploymentExpression({
259
+ ref: {
260
+ deployment: expr
261
+ }
262
+ });
263
+ }
264
+
265
+ const asTypedExpr = (expr) => {
266
+ return expr;
267
+ };
268
+ function $expr(expr) {
269
+ if (!object_hash.t(expr)) {
270
+ return expr;
271
+ }
272
+ if (expr === "*") {
273
+ return asTypedExpr({ wildcard: true });
274
+ }
275
+ if (expr.startsWith("->")) {
276
+ if (expr.endsWith("->")) {
277
+ return asTypedExpr({
278
+ inout: $expr(expr.replace(/->/g, "").trim())
279
+ });
280
+ }
281
+ return asTypedExpr({
282
+ incoming: $expr(expr.replace("-> ", ""))
283
+ });
284
+ }
285
+ if (expr.endsWith(" ->")) {
286
+ return asTypedExpr({
287
+ outgoing: $expr(expr.replace(" ->", ""))
288
+ });
289
+ }
290
+ if (expr.includes(" <-> ")) {
291
+ const [source, target] = expr.split(" <-> ");
292
+ return asTypedExpr({
293
+ source: $expr(source),
294
+ target: $expr(target),
295
+ isBidirectional: true
296
+ });
297
+ }
298
+ if (expr.includes(" -> ")) {
299
+ const [source, target] = expr.split(" -> ");
300
+ return asTypedExpr({
301
+ source: $expr(source),
302
+ target: $expr(target)
303
+ });
304
+ }
305
+ if (expr.endsWith("._")) {
306
+ return asTypedExpr({
307
+ expanded: expr.replace("._", "")
308
+ });
309
+ }
310
+ if (expr.endsWith(".*")) {
311
+ return asTypedExpr({
312
+ element: expr.replace(".*", ""),
313
+ isChildren: true
314
+ });
315
+ }
316
+ if (expr.endsWith(".**")) {
317
+ return asTypedExpr({
318
+ element: expr.replace(".**", ""),
319
+ isDescendants: true
320
+ });
321
+ }
322
+ return asTypedExpr({
323
+ element: expr
324
+ });
325
+ }
326
+
327
+ function mkViewBuilder(view) {
328
+ const viewBuilder = {
329
+ $expr: view.__ === "deployment" ? $deploymentExpr : $expr,
330
+ autoLayout(autoLayout) {
331
+ view.rules.push({
332
+ direction: autoLayout
333
+ });
334
+ return viewBuilder;
335
+ },
336
+ exclude(expr) {
337
+ view.rules.push({
338
+ exclude: [expr]
339
+ });
340
+ return viewBuilder;
341
+ },
342
+ include(expr) {
343
+ view.rules.push({
344
+ include: [expr]
345
+ });
346
+ return viewBuilder;
347
+ },
348
+ style(rule) {
349
+ view.rules.push(rule);
350
+ return viewBuilder;
351
+ }
352
+ // title(title: string) {
353
+ // view.title = title
354
+ // return viewBuilder
355
+ // },
356
+ // description(description: string) {
357
+ // view.description = description
358
+ // return viewBuilder
359
+ // }
360
+ };
361
+ return viewBuilder;
362
+ }
363
+
364
+ function builder(spec, _elements = /* @__PURE__ */ new Map(), _relations = [], _views = /* @__PURE__ */ new Map(), _globals = {
365
+ predicates: {},
366
+ dynamicPredicates: {},
367
+ styles: {}
368
+ }, _deployments = /* @__PURE__ */ new Map(), _deploymentRelations = []) {
369
+ const toLikeC4Specification = () => ({
370
+ elements: {
371
+ ...structuredClone(spec.elements)
372
+ },
373
+ deployments: {
374
+ ...structuredClone(spec.deployments)
375
+ },
376
+ relationships: {
377
+ ...structuredClone(spec.relationships)
378
+ },
379
+ tags: spec.tags ?? []
380
+ });
381
+ const mapLinks = (links) => {
382
+ if (!links || !object_hash.i(links, 1)) {
383
+ return null;
384
+ }
385
+ return object_hash.m(links, (l) => typeof l === "string" ? { url: l } : l);
386
+ };
387
+ const createGenericView = (id, _props, builder2) => {
388
+ if (object_hash.t$1(_props)) {
389
+ builder2 = _props;
390
+ _props = {};
391
+ }
392
+ _props ??= {};
393
+ const {
394
+ links: _links = [],
395
+ title = null,
396
+ description = null,
397
+ tags = null,
398
+ ...props
399
+ } = typeof _props === "string" ? { title: _props } : { ..._props };
400
+ const links = mapLinks(_links);
401
+ return [{
402
+ id,
403
+ title,
404
+ description,
405
+ tags,
406
+ links,
407
+ customColorDefinitions: {},
408
+ ...props
409
+ }, builder2];
410
+ };
411
+ const self = {
412
+ get Types() {
413
+ throw new Error("Types are not available in runtime");
414
+ },
415
+ clone: () => {
416
+ return builder(
417
+ structuredClone(spec),
418
+ structuredClone(_elements),
419
+ structuredClone(_relations),
420
+ structuredClone(_views),
421
+ structuredClone(_globals),
422
+ structuredClone(_deployments),
423
+ structuredClone(_deploymentRelations)
424
+ );
425
+ },
426
+ __addElement: (element) => {
427
+ const parent = object_hash.parentFqn(element.id);
428
+ if (parent) {
429
+ chunkRAAYCPUM.invariant(
430
+ _elements.get(parent),
431
+ `Parent element with id "${parent}" not found for element with id "${element.id}"`
432
+ );
433
+ }
434
+ if (_elements.has(element.id)) {
435
+ throw new Error(`Element with id "${element.id}" already exists`);
436
+ }
437
+ _elements.set(element.id, element);
438
+ return self;
439
+ },
440
+ __addRelation(relation) {
441
+ const sourceEl = _elements.get(relation.source);
442
+ chunkRAAYCPUM.invariant(sourceEl, `Element with id "${relation.source}" not found`);
443
+ const targetEl = _elements.get(relation.target);
444
+ chunkRAAYCPUM.invariant(targetEl, `Element with id "${relation.target}" not found`);
445
+ chunkRAAYCPUM.invariant(
446
+ !object_hash.isSameHierarchy(sourceEl, targetEl),
447
+ "Cannot create relationship between elements in the same hierarchy"
448
+ );
449
+ _relations.push({
450
+ id: `rel${_relations.length + 1}`,
451
+ ...relation
452
+ });
453
+ return self;
454
+ },
455
+ /**
456
+ * Fully qualified name for nested elements
457
+ */
458
+ __fqn(id) {
459
+ chunkRAAYCPUM.invariant(id.trim() !== "", "Id must be non-empty");
460
+ return id;
461
+ },
462
+ __addSourcelessRelation() {
463
+ throw new Error("Can be called only in nested model");
464
+ },
465
+ __addView: (view$1) => {
466
+ if (_views.has(view$1.id)) {
467
+ throw new Error(`View with id "${view$1.id}" already exists`);
468
+ }
469
+ if (view.isScopedElementView(view$1)) {
470
+ chunkRAAYCPUM.invariant(
471
+ _elements.get(view$1.viewOf),
472
+ `Invalid scoped view ${view$1.id}, wlement with id "${view$1.viewOf}" not found`
473
+ );
474
+ }
475
+ _views.set(view$1.id, view$1);
476
+ return self;
477
+ },
478
+ __addDeployment: (node) => {
479
+ if (_deployments.has(node.id)) {
480
+ throw new Error(`Deployment with id "${node.id}" already exists`);
481
+ }
482
+ const parent = object_hash.parentFqn(node.id);
483
+ if (parent) {
484
+ chunkRAAYCPUM.invariant(
485
+ _deployments.get(parent),
486
+ `Parent element with id "${parent}" not found for node with id "${node.id}"`
487
+ );
488
+ }
489
+ if (view.DeploymentElement.isInstance(node)) {
490
+ chunkRAAYCPUM.invariant(parent, `Instance ${node.id} of ${node.element} must be deployed under a parent node`);
491
+ chunkRAAYCPUM.invariant(
492
+ _elements.get(node.element),
493
+ `Instance "${node.id}" references non-existing element "${node.element}"`
494
+ );
495
+ }
496
+ _deployments.set(node.id, node);
497
+ return self;
498
+ },
499
+ __addDeploymentRelation: (relation) => {
500
+ chunkRAAYCPUM.invariant(
501
+ !object_hash.isSameHierarchy(relation.source.id, relation.target.id),
502
+ "Cannot create relationship between elements in the same hierarchy"
503
+ );
504
+ chunkRAAYCPUM.invariant(
505
+ _deployments.has(relation.source.id),
506
+ `Relation "${relation.source.id} -> ${relation.target.id}" references non-existing source`
507
+ );
508
+ chunkRAAYCPUM.invariant(
509
+ _deployments.has(relation.target.id),
510
+ `Relation "${relation.source.id} -> ${relation.target.id}" references non-existing target`
511
+ );
512
+ _deploymentRelations.push({
513
+ id: `deploy_rel${_deploymentRelations.length + 1}`,
514
+ ...relation
515
+ });
516
+ return self;
517
+ },
518
+ build: () => ({
519
+ specification: toLikeC4Specification(),
520
+ elements: n(
521
+ structuredClone(
522
+ Array.from(_elements.entries())
523
+ )
524
+ ),
525
+ relations: model_index.l(_relations, (r) => [r.id, structuredClone(r)]),
526
+ globals: structuredClone(_globals),
527
+ deployments: {
528
+ elements: n(
529
+ structuredClone(
530
+ Array.from(_deployments.entries())
531
+ )
532
+ ),
533
+ relations: model_index.l(_deploymentRelations, (r) => [r.id, structuredClone(r)])
534
+ },
535
+ views: n(
536
+ structuredClone(
537
+ Array.from(_views.entries())
538
+ )
539
+ )
540
+ }),
541
+ toLikeC4Model: () => {
542
+ const parsed = self.build();
543
+ return model_index.LikeC4Model.compute(parsed);
544
+ },
545
+ helpers: () => ({
546
+ model: {
547
+ model: (...ops) => {
548
+ return (b) => {
549
+ return ops.reduce((b2, op) => op(b2), b);
550
+ };
551
+ },
552
+ rel: (source, target, _props) => {
553
+ return (b) => {
554
+ const {
555
+ title = "",
556
+ links: _links = [],
557
+ ...props
558
+ } = defu(
559
+ typeof _props === "string" ? { title: _props } : { ..._props },
560
+ { title: null, links: null }
561
+ );
562
+ const links = mapLinks(_links);
563
+ b.__addRelation({
564
+ source,
565
+ target,
566
+ title,
567
+ ...links && { links },
568
+ ...props
569
+ });
570
+ return b;
571
+ };
572
+ },
573
+ relTo: (target, _props) => {
574
+ return (b) => {
575
+ const {
576
+ title = "",
577
+ links: _links = [],
578
+ ...props
579
+ } = defu(
580
+ typeof _props === "string" ? { title: _props } : { ..._props },
581
+ { title: null, links: null }
582
+ );
583
+ const links = mapLinks(_links);
584
+ b.__addSourcelessRelation({
585
+ target,
586
+ title,
587
+ ...links && { links },
588
+ ...props
589
+ });
590
+ return b;
591
+ };
592
+ },
593
+ ...model_index.i(
594
+ spec.elements,
595
+ ({ style: specStyle, ...spec2 }, kind) => (id, _props) => {
596
+ const add = (b) => {
597
+ const {
598
+ links: _links,
599
+ icon: _icon,
600
+ style,
601
+ title,
602
+ ...props
603
+ } = typeof _props === "string" ? { title: _props } : { ..._props };
604
+ const links = mapLinks(_links);
605
+ const icon = _icon ?? specStyle?.icon;
606
+ const _id = b.__fqn(id);
607
+ b.__addElement({
608
+ id: _id,
609
+ kind,
610
+ title: title ?? object_hash.nameFromFqn(_id),
611
+ description: null,
612
+ technology: null,
613
+ tags: null,
614
+ color: specStyle?.color ?? view.DefaultThemeColor,
615
+ shape: specStyle?.shape ?? view.DefaultElementShape,
616
+ style: model_index.d({
617
+ border: specStyle?.border,
618
+ opacity: specStyle?.opacity,
619
+ ...style
620
+ }, object_hash.l),
621
+ links,
622
+ ...icon && { icon },
623
+ ...spec2,
624
+ ...props
625
+ });
626
+ return b;
627
+ };
628
+ add.with = (...ops) => (b) => {
629
+ add(b);
630
+ const { __fqn, __addSourcelessRelation } = b;
631
+ try {
632
+ b.__fqn = (child) => `${__fqn(id)}.${child}`;
633
+ b.__addSourcelessRelation = (relation) => {
634
+ return b.__addRelation({
635
+ ...relation,
636
+ source: __fqn(id)
637
+ });
638
+ };
639
+ ops.reduce((b2, op) => op(b2), b);
640
+ } finally {
641
+ b.__fqn = __fqn;
642
+ b.__addSourcelessRelation = __addSourcelessRelation;
643
+ }
644
+ return b;
645
+ };
646
+ return add;
647
+ }
648
+ )
649
+ },
650
+ views: {
651
+ views: (...ops) => {
652
+ return (b) => {
653
+ return ops.reduce((b2, op) => op(b2), b);
654
+ };
655
+ },
656
+ view: (id, _props, _builder) => {
657
+ const [generic, builder2] = createGenericView(id, _props, _builder);
658
+ const view = {
659
+ ...generic,
660
+ __: "element",
661
+ rules: []
662
+ };
663
+ const add = (b) => {
664
+ b.__addView(view);
665
+ if (builder2) {
666
+ builder2(mkViewBuilder(view));
667
+ }
668
+ return b;
669
+ };
670
+ add.with = (...ops) => (b) => {
671
+ add(b);
672
+ const elementViewBuilder = mkViewBuilder(view);
673
+ for (const op of ops) {
674
+ op(elementViewBuilder);
675
+ }
676
+ return b;
677
+ };
678
+ return add;
679
+ },
680
+ viewOf: (id, viewOf, _props, _builder) => {
681
+ const [generic, builder2] = createGenericView(id, _props, _builder);
682
+ const view = {
683
+ ...generic,
684
+ viewOf,
685
+ __: "element",
686
+ rules: []
687
+ };
688
+ const add = (b) => {
689
+ b.__addView(view);
690
+ if (builder2) {
691
+ builder2(mkViewBuilder(view));
692
+ }
693
+ return b;
694
+ };
695
+ add.with = (...ops) => (b) => {
696
+ add(b);
697
+ const elementViewBuilder = mkViewBuilder(view);
698
+ for (const op of ops) {
699
+ op(elementViewBuilder);
700
+ }
701
+ return b;
702
+ };
703
+ return add;
704
+ },
705
+ deploymentView: (id, _props, _builder) => {
706
+ const [generic, builder2] = createGenericView(id, _props, _builder);
707
+ const view = {
708
+ ...generic,
709
+ __: "deployment",
710
+ rules: []
711
+ };
712
+ const add = (b) => {
713
+ b.__addView(view);
714
+ if (builder2) {
715
+ builder2(mkViewBuilder(view));
716
+ }
717
+ return b;
718
+ };
719
+ add.with = (...ops) => (b) => {
720
+ add(b);
721
+ const elementViewBuilder = mkViewBuilder(view);
722
+ for (const op of ops) {
723
+ op(elementViewBuilder);
724
+ }
725
+ return b;
726
+ };
727
+ return add;
728
+ },
729
+ $autoLayout,
730
+ $exclude,
731
+ $include,
732
+ $rules,
733
+ $style
734
+ },
735
+ deployment: {
736
+ deployment: (...ops) => {
737
+ return (b) => {
738
+ return ops.reduce((b2, op) => op(b2), b);
739
+ };
740
+ },
741
+ instanceOf: (id, target, _props) => {
742
+ return (b) => {
743
+ if (view.n(target)) {
744
+ target = id;
745
+ id = object_hash.nameFromFqn(id);
746
+ } else if (typeof target === "string") {
747
+ _props ??= {};
748
+ } else {
749
+ _props = target;
750
+ target = id;
751
+ id = object_hash.nameFromFqn(id);
752
+ }
753
+ const {
754
+ links,
755
+ title,
756
+ ...props
757
+ } = typeof _props === "string" ? { title: _props } : { ..._props };
758
+ const _id = b.__fqn(id);
759
+ chunkRAAYCPUM.invariant(_elements.has(target), `Target element with id "${target}" not found`);
760
+ b.__addDeployment({
761
+ id: _id,
762
+ element: target,
763
+ ...title && { title },
764
+ ...links && { links: mapLinks(links) },
765
+ ...props
766
+ });
767
+ return b;
768
+ };
769
+ },
770
+ rel: (source, target, _props) => {
771
+ return (b) => {
772
+ const {
773
+ title,
774
+ links,
775
+ ...props
776
+ } = typeof _props === "string" ? { title: _props } : { ..._props };
777
+ b.__addDeploymentRelation({
778
+ source: {
779
+ id: source
780
+ },
781
+ target: {
782
+ id: target
783
+ },
784
+ ...title && { title },
785
+ ...links && { links: mapLinks(links) },
786
+ ...props
787
+ });
788
+ return b;
789
+ };
790
+ },
791
+ ...model_index.i(
792
+ spec.deployments ?? {},
793
+ ({ style: specStyle, ...spec2 }, kind) => (id, _props) => {
794
+ const add = (b) => {
795
+ const {
796
+ links,
797
+ icon: _icon,
798
+ style,
799
+ title,
800
+ ...props
801
+ } = typeof _props === "string" ? { title: _props } : { ..._props };
802
+ const icon = _icon ?? specStyle?.icon;
803
+ const _id = b.__fqn(id);
804
+ b.__addDeployment({
805
+ id: _id,
806
+ kind,
807
+ title: title ?? object_hash.nameFromFqn(_id),
808
+ description: null,
809
+ technology: null,
810
+ tags: null,
811
+ color: specStyle?.color ?? view.DefaultThemeColor,
812
+ shape: specStyle?.shape ?? view.DefaultElementShape,
813
+ style: model_index.d({
814
+ border: specStyle?.border,
815
+ opacity: specStyle?.opacity,
816
+ ...style
817
+ }, object_hash.l),
818
+ ...links && { links: mapLinks(links) },
819
+ ...icon && { icon },
820
+ ...spec2,
821
+ ...props
822
+ });
823
+ return b;
824
+ };
825
+ add.with = (...ops) => (b) => {
826
+ add(b);
827
+ const { __fqn } = b;
828
+ try {
829
+ b.__fqn = (child) => `${__fqn(id)}.${child}`;
830
+ ops.reduce((b2, op) => op(b2), b);
831
+ } finally {
832
+ b.__fqn = __fqn;
833
+ }
834
+ return b;
835
+ };
836
+ return add;
837
+ }
838
+ )
839
+ }
840
+ }),
841
+ with: (...ops) => {
842
+ return ops.reduce((b, op) => op(b), self).clone();
843
+ },
844
+ model: (cb) => {
845
+ const b = self.clone();
846
+ const helpers = b.helpers().model;
847
+ const _ = helpers.model;
848
+ return cb({ ...helpers, _ }, _)(b);
849
+ },
850
+ deployment: (cb) => {
851
+ const b = self.clone();
852
+ const helpers = b.helpers().deployment;
853
+ const _ = helpers.deployment;
854
+ return cb({ ...helpers, _ }, _)(b);
855
+ },
856
+ views: (cb) => {
857
+ const b = self.clone();
858
+ const helpers = b.helpers().views;
859
+ return cb({
860
+ ...helpers,
861
+ _: helpers.views
862
+ }, helpers.views)(b);
863
+ }
864
+ };
865
+ return self;
866
+ }
867
+ exports.Builder = void 0;
868
+ ((Builder2) => {
869
+ function forSpecification(spec) {
870
+ const b = builder(spec);
871
+ return {
872
+ ...b.helpers(),
873
+ builder: b
874
+ };
875
+ }
876
+ Builder2.forSpecification = forSpecification;
877
+ function specification(spec) {
878
+ return builder(spec);
879
+ }
880
+ Builder2.specification = specification;
881
+ })(exports.Builder || (exports.Builder = {}));