@likec4/core 1.23.1 → 1.24.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 (72) hide show
  1. package/dist/builder/index.d.mts +3 -3
  2. package/dist/builder/index.d.ts +3 -3
  3. package/dist/builder/index.mjs +2 -2
  4. package/dist/compute-view/index.d.mts +4 -4
  5. package/dist/compute-view/index.d.ts +4 -4
  6. package/dist/compute-view/index.mjs +4 -4
  7. package/dist/index.d.mts +7 -8
  8. package/dist/index.d.ts +7 -8
  9. package/dist/index.mjs +4 -4
  10. package/dist/model/index.d.mts +5 -5
  11. package/dist/model/index.d.ts +5 -5
  12. package/dist/model/index.mjs +1 -1
  13. package/dist/shared/{core.3xeQpJ_K.d.cts → core.3L0y_SNW.d.mts} +2 -2
  14. package/dist/shared/{core.QP35c488.d.cts → core.Bhx0OGK8.d.mts} +1 -1
  15. package/dist/shared/{core.QP35c488.d.mts → core.Bhx0OGK8.d.ts} +1 -1
  16. package/dist/shared/{core.DsDq-blc.d.ts → core.BreLKHbT.d.mts} +1 -2
  17. package/dist/shared/{core.DQCc-Jxk.d.ts → core.BsAIrb_r.d.ts} +1 -1
  18. package/dist/shared/{core.GIZxdz4M.mjs → core.C92OYZca.mjs} +1 -1
  19. package/dist/shared/{core.CJaCUZQ9.d.mts → core.C9UbC1nX.d.ts} +1 -2
  20. package/dist/shared/{core.s6UB2oA0.d.ts → core.DBToPQ3n.d.ts} +2 -2
  21. package/dist/shared/{core.1pNr6Ryk.d.ts → core.DbfQeUKm.d.mts} +5 -4
  22. package/dist/shared/core.FFJhmauw.mjs +2078 -0
  23. package/dist/shared/{core.BYs5deiY.d.cts → core.RiWsY3jz.d.mts} +1 -1
  24. package/dist/shared/{core.uGbvOLGK.mjs → core.gWObeLn9.mjs} +28 -9
  25. package/dist/shared/{core.DKJ2y3NP.d.mts → core.k4jahJ8j.d.ts} +5 -4
  26. package/dist/types/index.d.mts +4 -4
  27. package/dist/types/index.d.ts +4 -4
  28. package/dist/types/index.mjs +1 -1
  29. package/dist/utils/index.d.mts +46 -4
  30. package/dist/utils/index.d.ts +46 -4
  31. package/dist/utils/index.mjs +2 -2
  32. package/package.json +3 -27
  33. package/src/compute-view/deployment-view/clean-connections.ts +1 -1
  34. package/src/compute-view/deployment-view/stages/stage-final.ts +1 -1
  35. package/src/compute-view/element-view/compute.ts +1 -1
  36. package/src/compute-view/element-view/memory/memory.ts +1 -1
  37. package/src/compute-view/memory/ops.ts +1 -1
  38. package/src/compute-view/relationships-view/layout.ts +1 -1
  39. package/src/compute-view/relationships-view/utils.ts +1 -1
  40. package/src/model/DeploymentElementModel.ts +4 -6
  41. package/src/model/DeploymentModel.ts +1 -1
  42. package/src/model/LikeC4Model.ts +22 -1
  43. package/src/model/view/LikeC4ViewModel.ts +5 -6
  44. package/src/types/deployments.ts +0 -1
  45. package/src/types/index.ts +1 -1
  46. package/src/types/theme.ts +1 -1
  47. package/src/utils/index.ts +7 -1
  48. package/src/utils/mnemonist.ts +7 -0
  49. package/src/utils/set.ts +5 -3
  50. package/dist/builder/index.cjs +0 -887
  51. package/dist/builder/index.d.cts +0 -509
  52. package/dist/compute-view/index.cjs +0 -86
  53. package/dist/compute-view/index.d.cts +0 -23
  54. package/dist/index.cjs +0 -3857
  55. package/dist/index.d.cts +0 -146
  56. package/dist/model/index.cjs +0 -40
  57. package/dist/model/index.d.cts +0 -259
  58. package/dist/shared/core.BHQYwEvc.d.mts +0 -12
  59. package/dist/shared/core.BS_nXBsP.d.cts +0 -858
  60. package/dist/shared/core.BYiA0A6H.cjs +0 -39
  61. package/dist/shared/core.CEJQrbXY.cjs +0 -441
  62. package/dist/shared/core.D0KD4FiT.d.mts +0 -127
  63. package/dist/shared/core.DEzbhxsA.cjs +0 -14874
  64. package/dist/shared/core.DUbKSpjd.cjs +0 -26
  65. package/dist/shared/core.DqmAHWZs.cjs +0 -7501
  66. package/dist/shared/core.OjOfEBRQ.d.cts +0 -731
  67. package/dist/shared/core.QP35c488.d.ts +0 -185
  68. package/dist/shared/core.f1tiPwpd.mjs +0 -14819
  69. package/dist/types/index.cjs +0 -110
  70. package/dist/types/index.d.cts +0 -72
  71. package/dist/utils/index.cjs +0 -99
  72. package/dist/utils/index.d.cts +0 -340
@@ -1,887 +0,0 @@
1
- 'use strict';
2
-
3
- const model_index = require('../shared/core.DqmAHWZs.cjs');
4
- const object_hash = require('../shared/core.DEzbhxsA.cjs');
5
- const view = require('../shared/core.CEJQrbXY.cjs');
6
- const chunkWIMGWYZL = require('../shared/core.DUbKSpjd.cjs');
7
-
8
- function n(...r){return chunkWIMGWYZL.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
- chunkWIMGWYZL.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
- chunkWIMGWYZL.invariant(sourceEl, `Element with id "${relation.source}" not found`);
443
- const targetEl = _elements.get(relation.target);
444
- chunkWIMGWYZL.invariant(targetEl, `Element with id "${relation.target}" not found`);
445
- chunkWIMGWYZL.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
- chunkWIMGWYZL.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
- chunkWIMGWYZL.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
- chunkWIMGWYZL.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
- chunkWIMGWYZL.invariant(parent, `Instance ${node.id} of ${node.element} must be deployed under a parent node`);
491
- chunkWIMGWYZL.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
- chunkWIMGWYZL.invariant(
501
- !object_hash.isSameHierarchy(relation.source.id, relation.target.id),
502
- "Cannot create relationship between elements in the same hierarchy"
503
- );
504
- chunkWIMGWYZL.invariant(
505
- _deployments.has(relation.source.id),
506
- `Relation "${relation.source.id} -> ${relation.target.id}" references non-existing source`
507
- );
508
- chunkWIMGWYZL.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
- size: specStyle?.size,
620
- padding: specStyle?.padding,
621
- textSize: specStyle?.textSize,
622
- ...style
623
- }, object_hash.l),
624
- links,
625
- ...icon && { icon },
626
- ...spec2,
627
- ...props
628
- });
629
- return b;
630
- };
631
- add.with = (...ops) => (b) => {
632
- add(b);
633
- const { __fqn, __addSourcelessRelation } = b;
634
- try {
635
- b.__fqn = (child) => `${__fqn(id)}.${child}`;
636
- b.__addSourcelessRelation = (relation) => {
637
- return b.__addRelation({
638
- ...relation,
639
- source: __fqn(id)
640
- });
641
- };
642
- ops.reduce((b2, op) => op(b2), b);
643
- } finally {
644
- b.__fqn = __fqn;
645
- b.__addSourcelessRelation = __addSourcelessRelation;
646
- }
647
- return b;
648
- };
649
- return add;
650
- }
651
- )
652
- },
653
- views: {
654
- views: (...ops) => {
655
- return (b) => {
656
- return ops.reduce((b2, op) => op(b2), b);
657
- };
658
- },
659
- view: (id, _props, _builder) => {
660
- const [generic, builder2] = createGenericView(id, _props, _builder);
661
- const view = {
662
- ...generic,
663
- __: "element",
664
- rules: []
665
- };
666
- const add = (b) => {
667
- b.__addView(view);
668
- if (builder2) {
669
- builder2(mkViewBuilder(view));
670
- }
671
- return b;
672
- };
673
- add.with = (...ops) => (b) => {
674
- add(b);
675
- const elementViewBuilder = mkViewBuilder(view);
676
- for (const op of ops) {
677
- op(elementViewBuilder);
678
- }
679
- return b;
680
- };
681
- return add;
682
- },
683
- viewOf: (id, viewOf, _props, _builder) => {
684
- const [generic, builder2] = createGenericView(id, _props, _builder);
685
- const view = {
686
- ...generic,
687
- viewOf,
688
- __: "element",
689
- rules: []
690
- };
691
- const add = (b) => {
692
- b.__addView(view);
693
- if (builder2) {
694
- builder2(mkViewBuilder(view));
695
- }
696
- return b;
697
- };
698
- add.with = (...ops) => (b) => {
699
- add(b);
700
- const elementViewBuilder = mkViewBuilder(view);
701
- for (const op of ops) {
702
- op(elementViewBuilder);
703
- }
704
- return b;
705
- };
706
- return add;
707
- },
708
- deploymentView: (id, _props, _builder) => {
709
- const [generic, builder2] = createGenericView(id, _props, _builder);
710
- const view = {
711
- ...generic,
712
- __: "deployment",
713
- rules: []
714
- };
715
- const add = (b) => {
716
- b.__addView(view);
717
- if (builder2) {
718
- builder2(mkViewBuilder(view));
719
- }
720
- return b;
721
- };
722
- add.with = (...ops) => (b) => {
723
- add(b);
724
- const elementViewBuilder = mkViewBuilder(view);
725
- for (const op of ops) {
726
- op(elementViewBuilder);
727
- }
728
- return b;
729
- };
730
- return add;
731
- },
732
- $autoLayout,
733
- $exclude,
734
- $include,
735
- $rules,
736
- $style
737
- },
738
- deployment: {
739
- deployment: (...ops) => {
740
- return (b) => {
741
- return ops.reduce((b2, op) => op(b2), b);
742
- };
743
- },
744
- instanceOf: (id, target, _props) => {
745
- return (b) => {
746
- if (view.n(target)) {
747
- target = id;
748
- id = object_hash.nameFromFqn(id);
749
- } else if (typeof target === "string") {
750
- _props ??= {};
751
- } else {
752
- _props = target;
753
- target = id;
754
- id = object_hash.nameFromFqn(id);
755
- }
756
- const {
757
- links,
758
- title,
759
- ...props
760
- } = typeof _props === "string" ? { title: _props } : { ..._props };
761
- const _id = b.__fqn(id);
762
- chunkWIMGWYZL.invariant(_elements.has(target), `Target element with id "${target}" not found`);
763
- b.__addDeployment({
764
- id: _id,
765
- element: target,
766
- ...title && { title },
767
- ...links && { links: mapLinks(links) },
768
- ...props
769
- });
770
- return b;
771
- };
772
- },
773
- rel: (source, target, _props) => {
774
- return (b) => {
775
- const {
776
- title,
777
- links,
778
- ...props
779
- } = typeof _props === "string" ? { title: _props } : { ..._props };
780
- b.__addDeploymentRelation({
781
- source: {
782
- id: source
783
- },
784
- target: {
785
- id: target
786
- },
787
- ...title && { title },
788
- ...links && { links: mapLinks(links) },
789
- ...props
790
- });
791
- return b;
792
- };
793
- },
794
- ...model_index.i(
795
- spec.deployments ?? {},
796
- ({ style: specStyle, ...spec2 }, kind) => (id, _props) => {
797
- const add = (b) => {
798
- const {
799
- links,
800
- icon: _icon,
801
- style,
802
- title,
803
- ...props
804
- } = typeof _props === "string" ? { title: _props } : { ..._props };
805
- const icon = _icon ?? specStyle?.icon;
806
- const _id = b.__fqn(id);
807
- b.__addDeployment({
808
- id: _id,
809
- kind,
810
- title: title ?? object_hash.nameFromFqn(_id),
811
- description: null,
812
- technology: null,
813
- tags: null,
814
- color: specStyle?.color ?? view.DefaultThemeColor,
815
- shape: specStyle?.shape ?? view.DefaultElementShape,
816
- style: model_index.d({
817
- border: specStyle?.border,
818
- opacity: specStyle?.opacity,
819
- size: specStyle?.size,
820
- padding: specStyle?.padding,
821
- textSize: specStyle?.textSize,
822
- ...style
823
- }, object_hash.l),
824
- ...links && { links: mapLinks(links) },
825
- ...icon && { icon },
826
- ...spec2,
827
- ...props
828
- });
829
- return b;
830
- };
831
- add.with = (...ops) => (b) => {
832
- add(b);
833
- const { __fqn } = b;
834
- try {
835
- b.__fqn = (child) => `${__fqn(id)}.${child}`;
836
- ops.reduce((b2, op) => op(b2), b);
837
- } finally {
838
- b.__fqn = __fqn;
839
- }
840
- return b;
841
- };
842
- return add;
843
- }
844
- )
845
- }
846
- }),
847
- with: (...ops) => {
848
- return ops.reduce((b, op) => op(b), self).clone();
849
- },
850
- model: (cb) => {
851
- const b = self.clone();
852
- const helpers = b.helpers().model;
853
- const _ = helpers.model;
854
- return cb({ ...helpers, _ }, _)(b);
855
- },
856
- deployment: (cb) => {
857
- const b = self.clone();
858
- const helpers = b.helpers().deployment;
859
- const _ = helpers.deployment;
860
- return cb({ ...helpers, _ }, _)(b);
861
- },
862
- views: (cb) => {
863
- const b = self.clone();
864
- const helpers = b.helpers().views;
865
- return cb({
866
- ...helpers,
867
- _: helpers.views
868
- }, helpers.views)(b);
869
- }
870
- };
871
- return self;
872
- }
873
- exports.Builder = void 0;
874
- ((Builder2) => {
875
- function forSpecification(spec) {
876
- const b = builder(spec);
877
- return {
878
- ...b.helpers(),
879
- builder: b
880
- };
881
- }
882
- Builder2.forSpecification = forSpecification;
883
- function specification(spec) {
884
- return builder(spec);
885
- }
886
- Builder2.specification = specification;
887
- })(exports.Builder || (exports.Builder = {}));