@likec4/core 1.12.1 → 1.13.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 (35) hide show
  1. package/dist/index.cjs +777 -251
  2. package/dist/index.d.cts +301 -32
  3. package/dist/index.d.mts +301 -32
  4. package/dist/index.d.ts +301 -32
  5. package/dist/index.mjs +774 -252
  6. package/dist/shared/{core.BvFch1jG.mjs → core.BJDxVHFh.mjs} +19 -19
  7. package/dist/shared/{core.dY8efyk0.d.ts → core.C4jDMQ1i.d.cts} +242 -238
  8. package/dist/shared/{core.dY8efyk0.d.cts → core.C4jDMQ1i.d.mts} +242 -238
  9. package/dist/shared/{core.dY8efyk0.d.mts → core.C4jDMQ1i.d.ts} +242 -238
  10. package/dist/shared/{core.CTiE4teS.cjs → core.IR7XOEkQ.cjs} +19 -18
  11. package/dist/types/index.cjs +1 -1
  12. package/dist/types/index.d.cts +1 -1
  13. package/dist/types/index.d.mts +1 -1
  14. package/dist/types/index.d.ts +1 -1
  15. package/dist/types/index.mjs +1 -1
  16. package/package.json +4 -3
  17. package/src/builder/Builder.element.ts +221 -0
  18. package/src/builder/Builder.model.ts +346 -0
  19. package/src/builder/Builder.test-d.ts +69 -0
  20. package/src/builder/Builder.ts +574 -0
  21. package/src/builder/Builder.view.ts +358 -0
  22. package/src/builder/Builder.views.ts +318 -0
  23. package/src/builder/_types.ts +195 -0
  24. package/src/builder/index.ts +5 -0
  25. package/src/index.ts +4 -0
  26. package/src/model/LikeC4DiagramModel.ts +5 -5
  27. package/src/model/LikeC4Model.ts +63 -46
  28. package/src/model/LikeC4ViewModel.ts +7 -7
  29. package/src/model/__test__/fixture.ts +5 -0
  30. package/src/types/element.ts +19 -11
  31. package/src/types/model.ts +13 -8
  32. package/src/types/relation.ts +1 -1
  33. package/src/types/view-changes.ts +6 -2
  34. package/src/types/view.ts +53 -22
  35. package/src/utils/fqn.ts +12 -11
@@ -1,4 +1,14 @@
1
- import { LiteralUnion, Tagged, UnwrapTagged } from 'type-fest';
1
+ import { Tagged, LiteralUnion, TupleToUnion } from 'type-fest';
2
+
3
+ type NonEmptyArray<T> = [T, ...T[]];
4
+ type NonEmptyReadonlyArray<T> = readonly [T, ...T[]];
5
+ type IconUrl = Tagged<string, 'IconUrl'>;
6
+ type CustomColor = string;
7
+ type Point = readonly [x: number, y: number];
8
+ interface XYPoint {
9
+ x: number;
10
+ y: number;
11
+ }
2
12
 
3
13
  declare const ThemeColors: readonly ["amber", "blue", "gray", "slate", "green", "indigo", "muted", "primary", "red", "secondary", "sky"];
4
14
  type ThemeColor = typeof ThemeColors[number];
@@ -34,30 +44,20 @@ interface LikeC4Theme {
34
44
  elements: ElementThemeColors;
35
45
  }
36
46
 
37
- type NonEmptyArray<T> = [T, ...T[]];
38
- type NonEmptyReadonlyArray<T> = readonly [T, ...T[]];
39
- type IconUrl = Tagged<string, 'IconUrl'>;
40
- type CustomColor = string;
41
- type Point = readonly [x: number, y: number];
42
- interface XYPoint {
43
- x: number;
44
- y: number;
45
- }
46
-
47
- type Fqn = Tagged<string, 'Fqn'>;
47
+ type Fqn<Id extends string = string> = Tagged<Id, 'Fqn'>;
48
48
  declare function AsFqn(name: string, parent?: Fqn | null): Fqn;
49
49
  declare const BorderStyles: readonly ["solid", "dashed", "dotted", "none"];
50
- type BorderStyle = typeof BorderStyles[number];
51
- type ElementKind = Tagged<string, 'ElementKind'>;
50
+ type BorderStyle = TupleToUnion<typeof BorderStyles>;
51
+ type ElementKind<Kinds extends string = string> = Tagged<Kinds, 'ElementKind'>;
52
52
  declare const ElementShapes: readonly ["rectangle", "person", "browser", "mobile", "cylinder", "storage", "queue"];
53
- type ElementShape = typeof ElementShapes[number];
53
+ type ElementShape = TupleToUnion<typeof ElementShapes>;
54
54
  declare const DefaultThemeColor = "primary";
55
55
  declare const DefaultElementShape = "rectangle";
56
56
  interface ElementStyle {
57
57
  border?: BorderStyle;
58
58
  opacity?: number;
59
59
  }
60
- type Tag = Tagged<string, 'Tag'>;
60
+ type Tag<Tags extends string = string> = Tagged<Tags, 'Tag'>;
61
61
  interface TagSpec {
62
62
  readonly id: Tag;
63
63
  readonly style: ElementStyle;
@@ -67,22 +67,22 @@ interface Link {
67
67
  readonly url: string;
68
68
  readonly relative?: string;
69
69
  }
70
- interface Element {
71
- readonly id: Fqn;
72
- readonly kind: ElementKind;
70
+ interface TypedElement<Ids extends string, Kinds extends string, Tags extends string, MetadataKeys extends string = never> {
71
+ readonly id: Fqn<Ids>;
72
+ readonly kind: ElementKind<Kinds>;
73
73
  readonly title: string;
74
74
  readonly description: string | null;
75
75
  readonly technology: string | null;
76
- readonly tags: NonEmptyArray<Tag> | null;
76
+ readonly tags: NonEmptyArray<Tag<Tags>> | null;
77
77
  readonly links: NonEmptyArray<Link> | null;
78
78
  readonly icon?: IconUrl;
79
79
  readonly shape?: ElementShape;
80
80
  readonly color?: Color;
81
81
  readonly style?: ElementStyle;
82
82
  readonly notation?: string;
83
- readonly metadata?: {
84
- [key: string]: string;
85
- };
83
+ readonly metadata?: Record<MetadataKeys, string>;
84
+ }
85
+ interface Element extends TypedElement<string, string, string, string> {
86
86
  }
87
87
  interface ElementKindSpecificationStyle {
88
88
  shape?: ElementShape;
@@ -139,194 +139,6 @@ type Filterable<FTag extends string = string, FKind extends string = string> = {
139
139
  type OperatorPredicate<V extends Filterable> = (value: V) => boolean;
140
140
  declare function whereOperatorAsPredicate<FTag extends string = string, FKind extends string = string>(operator: WhereOperator<FTag, FKind>): OperatorPredicate<Filterable<FTag, FKind>>;
141
141
 
142
- type RelationID = Tagged<string, 'RelationID'>;
143
- type RelationshipKind = Tagged<string, 'RelationshipKind'>;
144
- type RelationshipLineType = 'dashed' | 'solid' | 'dotted';
145
- type RelationshipArrowType = 'none' | 'normal' | 'onormal' | 'dot' | 'odot' | 'diamond' | 'odiamond' | 'crow' | 'open' | 'vee';
146
- declare const DefaultLineStyle = "dashed";
147
- declare const DefaultArrowType = "normal";
148
- declare const DefaultRelationshipColor = "gray";
149
- interface Relation {
150
- readonly id: RelationID;
151
- readonly source: Fqn;
152
- readonly target: Fqn;
153
- readonly title: string;
154
- readonly description?: string;
155
- readonly technology?: string;
156
- readonly tags?: NonEmptyArray<Tag>;
157
- readonly kind?: RelationshipKind;
158
- readonly color?: Color;
159
- readonly line?: RelationshipLineType;
160
- readonly head?: RelationshipArrowType;
161
- readonly tail?: RelationshipArrowType;
162
- readonly links?: NonEmptyArray<Link>;
163
- readonly navigateTo?: ViewID;
164
- readonly metadata?: {
165
- [key: string]: string;
166
- };
167
- }
168
- interface RelationshipKindSpecification {
169
- readonly technology?: string;
170
- readonly notation?: string;
171
- readonly color?: Color;
172
- readonly line?: RelationshipLineType;
173
- readonly head?: RelationshipArrowType;
174
- readonly tail?: RelationshipArrowType;
175
- }
176
-
177
- interface BaseExpr {
178
- where?: never;
179
- element?: never;
180
- custom?: never;
181
- expanded?: never;
182
- elementKind?: never;
183
- elementTag?: never;
184
- isEqual?: never;
185
- isDescedants?: never;
186
- wildcard?: never;
187
- source?: never;
188
- target?: never;
189
- inout?: never;
190
- incoming?: never;
191
- outgoing?: never;
192
- customRelation?: never;
193
- }
194
- interface ElementRefExpr extends Omit<BaseExpr, 'element' | 'isDescedants'> {
195
- element: Fqn;
196
- isDescedants?: boolean;
197
- }
198
- declare function isElementRef(expr: Expression): expr is ElementRefExpr;
199
- interface ExpandedElementExpr extends Omit<BaseExpr, 'expanded'> {
200
- expanded: Fqn;
201
- }
202
- declare function isExpandedElementExpr(expr: Expression): expr is ExpandedElementExpr;
203
- interface CustomElementExpr extends Omit<BaseExpr, 'custom'> {
204
- custom: {
205
- expr: ElementExpression | ElementWhereExpr;
206
- title?: string;
207
- description?: string;
208
- technology?: string;
209
- notation?: string;
210
- shape?: ElementShape;
211
- color?: Color;
212
- icon?: IconUrl;
213
- border?: BorderStyle;
214
- opacity?: number;
215
- navigateTo?: ViewID;
216
- };
217
- }
218
- declare function isCustomElement(expr: Expression): expr is CustomElementExpr;
219
- interface WildcardExpr extends Omit<BaseExpr, 'wildcard'> {
220
- wildcard: true;
221
- }
222
- declare function isWildcard(expr: Expression): expr is WildcardExpr;
223
- interface ElementKindExpr extends Omit<BaseExpr, 'elementKind' | 'isEqual'> {
224
- elementKind: ElementKind;
225
- isEqual: boolean;
226
- }
227
- declare function isElementKindExpr(expr: Expression): expr is ElementKindExpr;
228
- interface ElementTagExpr extends Omit<BaseExpr, 'elementTag' | 'isEqual'> {
229
- elementTag: Tag;
230
- isEqual: boolean;
231
- }
232
- declare function isElementTagExpr(expr: Expression): expr is ElementTagExpr;
233
- type ElementExpression = ElementRefExpr | WildcardExpr | ElementKindExpr | ElementTagExpr | ExpandedElementExpr;
234
- declare function isElement(expr: Expression): expr is ElementExpression;
235
- interface ElementWhereExpr extends Omit<BaseExpr, 'where'> {
236
- where: {
237
- expr: ElementExpression;
238
- condition: WhereOperator<string, string>;
239
- };
240
- }
241
- declare function isElementWhere(expr: Expression): expr is ElementWhereExpr;
242
- type ElementPredicateExpression = ElementExpression | ElementWhereExpr | CustomElementExpr;
243
- declare function isElementPredicateExpr(expr: Expression): expr is ElementPredicateExpression;
244
- interface RelationExpr extends Omit<BaseExpr, 'source' | 'target'> {
245
- source: ElementExpression;
246
- target: ElementExpression;
247
- isBidirectional?: boolean;
248
- }
249
- declare function isRelation(expr: Expression): expr is RelationExpr;
250
- interface InOutExpr extends Omit<BaseExpr, 'inout'> {
251
- inout: ElementExpression;
252
- }
253
- declare function isInOut(expr: Expression): expr is InOutExpr;
254
- interface IncomingExpr extends Omit<BaseExpr, 'incoming'> {
255
- incoming: ElementExpression;
256
- }
257
- declare function isIncoming(expr: Expression): expr is IncomingExpr;
258
- interface OutgoingExpr extends Omit<BaseExpr, 'outgoing'> {
259
- outgoing: ElementExpression;
260
- }
261
- declare function isOutgoing(expr: Expression): expr is OutgoingExpr;
262
- type RelationExpression = RelationExpr | InOutExpr | IncomingExpr | OutgoingExpr;
263
- declare function isRelationExpression(expr: Expression): expr is RelationExpression;
264
- interface RelationWhereExpr extends Omit<BaseExpr, 'where'> {
265
- where: {
266
- expr: RelationExpression;
267
- condition: WhereOperator<string, string>;
268
- };
269
- }
270
- declare function isRelationWhere(expr: Expression): expr is RelationWhereExpr;
271
- interface CustomRelationExpr extends Omit<BaseExpr, 'customRelation'> {
272
- customRelation: {
273
- relation: RelationExpression | RelationWhereExpr;
274
- title?: string;
275
- description?: string;
276
- technology?: string;
277
- notation?: string;
278
- navigateTo?: ViewID;
279
- notes?: string;
280
- color?: Color;
281
- line?: RelationshipLineType;
282
- head?: RelationshipArrowType;
283
- tail?: RelationshipArrowType;
284
- };
285
- }
286
- declare function isCustomRelationExpr(expr: Expression): expr is CustomRelationExpr;
287
- type RelationPredicateExpression = RelationExpression | RelationWhereExpr | CustomRelationExpr;
288
- declare function isRelationPredicateExpr(expr: Expression): expr is RelationPredicateExpression;
289
- type Expression = ElementPredicateExpression | RelationPredicateExpression;
290
-
291
- type expression_CustomElementExpr = CustomElementExpr;
292
- type expression_CustomRelationExpr = CustomRelationExpr;
293
- type expression_ElementExpression = ElementExpression;
294
- type expression_ElementKindExpr = ElementKindExpr;
295
- type expression_ElementPredicateExpression = ElementPredicateExpression;
296
- type expression_ElementRefExpr = ElementRefExpr;
297
- type expression_ElementTagExpr = ElementTagExpr;
298
- type expression_ElementWhereExpr = ElementWhereExpr;
299
- type expression_ExpandedElementExpr = ExpandedElementExpr;
300
- type expression_Expression = Expression;
301
- type expression_InOutExpr = InOutExpr;
302
- type expression_IncomingExpr = IncomingExpr;
303
- type expression_OutgoingExpr = OutgoingExpr;
304
- type expression_RelationExpr = RelationExpr;
305
- type expression_RelationExpression = RelationExpression;
306
- type expression_RelationPredicateExpression = RelationPredicateExpression;
307
- type expression_RelationWhereExpr = RelationWhereExpr;
308
- type expression_WildcardExpr = WildcardExpr;
309
- declare const expression_isCustomElement: typeof isCustomElement;
310
- declare const expression_isCustomRelationExpr: typeof isCustomRelationExpr;
311
- declare const expression_isElement: typeof isElement;
312
- declare const expression_isElementKindExpr: typeof isElementKindExpr;
313
- declare const expression_isElementPredicateExpr: typeof isElementPredicateExpr;
314
- declare const expression_isElementRef: typeof isElementRef;
315
- declare const expression_isElementTagExpr: typeof isElementTagExpr;
316
- declare const expression_isElementWhere: typeof isElementWhere;
317
- declare const expression_isExpandedElementExpr: typeof isExpandedElementExpr;
318
- declare const expression_isInOut: typeof isInOut;
319
- declare const expression_isIncoming: typeof isIncoming;
320
- declare const expression_isOutgoing: typeof isOutgoing;
321
- declare const expression_isRelation: typeof isRelation;
322
- declare const expression_isRelationExpression: typeof isRelationExpression;
323
- declare const expression_isRelationPredicateExpr: typeof isRelationPredicateExpr;
324
- declare const expression_isRelationWhere: typeof isRelationWhere;
325
- declare const expression_isWildcard: typeof isWildcard;
326
- declare namespace expression {
327
- export { type expression_CustomElementExpr as CustomElementExpr, type expression_CustomRelationExpr as CustomRelationExpr, type expression_ElementExpression as ElementExpression, type expression_ElementKindExpr as ElementKindExpr, type expression_ElementPredicateExpression as ElementPredicateExpression, type expression_ElementRefExpr as ElementRefExpr, type expression_ElementTagExpr as ElementTagExpr, type expression_ElementWhereExpr as ElementWhereExpr, type expression_ExpandedElementExpr as ExpandedElementExpr, type expression_Expression as Expression, type expression_InOutExpr as InOutExpr, type expression_IncomingExpr as IncomingExpr, type expression_OutgoingExpr as OutgoingExpr, type expression_RelationExpr as RelationExpr, type expression_RelationExpression as RelationExpression, type expression_RelationPredicateExpression as RelationPredicateExpression, type expression_RelationWhereExpr as RelationWhereExpr, type expression_WildcardExpr as WildcardExpr, expression_isCustomElement as isCustomElement, expression_isCustomRelationExpr as isCustomRelationExpr, expression_isElement as isElement, expression_isElementKindExpr as isElementKindExpr, expression_isElementPredicateExpr as isElementPredicateExpr, expression_isElementRef as isElementRef, expression_isElementTagExpr as isElementTagExpr, expression_isElementWhere as isElementWhere, expression_isExpandedElementExpr as isExpandedElementExpr, expression_isInOut as isInOut, expression_isIncoming as isIncoming, expression_isOutgoing as isOutgoing, expression_isRelation as isRelation, expression_isRelationExpression as isRelationExpression, expression_isRelationPredicateExpr as isRelationPredicateExpr, expression_isRelationWhere as isRelationWhere, expression_isWildcard as isWildcard };
328
- }
329
-
330
142
  type ElementNotation = {
331
143
  kinds: ElementKind[];
332
144
  shape: ElementShape;
@@ -334,7 +146,7 @@ type ElementNotation = {
334
146
  title: string;
335
147
  };
336
148
 
337
- type ViewID = Tagged<string, 'ViewID'>;
149
+ type ViewID<Id extends string = string> = Tagged<Id, 'ViewID'>;
338
150
  type ViewRulePredicate = {
339
151
  include: Expression[];
340
152
  exclude?: never;
@@ -362,12 +174,12 @@ interface ViewRuleAutoLayout {
362
174
  }
363
175
  declare function isViewRuleAutoLayout(rule: ViewRule): rule is ViewRuleAutoLayout;
364
176
  type ViewRule = ViewRulePredicate | ViewRuleStyle | ViewRuleAutoLayout;
365
- interface BasicView<ViewType extends 'element' | 'dynamic'> {
177
+ interface BasicView<ViewType extends 'element' | 'dynamic', ViewIDs extends string, Tags extends string> {
366
178
  readonly __?: ViewType;
367
- readonly id: ViewID;
179
+ readonly id: ViewID<ViewIDs>;
368
180
  readonly title: string | null;
369
181
  readonly description: string | null;
370
- readonly tags: NonEmptyArray<Tag> | null;
182
+ readonly tags: NonEmptyArray<Tag<Tags>> | null;
371
183
  readonly links: NonEmptyArray<Link> | null;
372
184
  /**
373
185
  * URI to the source file of this view.
@@ -389,17 +201,17 @@ interface BasicView<ViewType extends 'element' | 'dynamic'> {
389
201
  readonly manualLayout?: ViewManualLayout | undefined;
390
202
  readonly customColorDefinitions: CustomColorDefinitions;
391
203
  }
392
- interface BasicElementView extends BasicView<'element'> {
204
+ interface BasicElementView<ViewIDs extends string, Tags extends string> extends BasicView<'element', ViewIDs, Tags> {
393
205
  readonly viewOf?: Fqn;
394
206
  readonly rules: ViewRule[];
395
207
  }
396
- interface ScopedElementView extends BasicElementView {
208
+ interface ScopedElementView<ViewIDs extends string, Tags extends string> extends BasicElementView<ViewIDs, Tags> {
397
209
  readonly viewOf: Fqn;
398
210
  }
399
- interface ExtendsElementView extends BasicElementView {
400
- readonly extends: ViewID;
211
+ interface ExtendsElementView<ViewIDs extends string, Tags extends string> extends BasicElementView<ViewIDs, Tags> {
212
+ readonly extends: ViewID<ViewIDs>;
401
213
  }
402
- type ElementView = ScopedElementView | ExtendsElementView | BasicElementView;
214
+ type ElementView<ViewIDs extends string = string, Tags extends string = string> = ScopedElementView<ViewIDs, Tags> | ExtendsElementView<ViewIDs, Tags> | BasicElementView<ViewIDs, Tags>;
403
215
  interface DynamicViewStep {
404
216
  readonly source: Fqn;
405
217
  readonly target: Fqn;
@@ -425,7 +237,7 @@ type DynamicViewIncludeRule = {
425
237
  };
426
238
  declare function isDynamicViewIncludeRule(rule: DynamicViewRule): rule is DynamicViewIncludeRule;
427
239
  type DynamicViewRule = DynamicViewIncludeRule | ViewRuleStyle | ViewRuleAutoLayout;
428
- interface DynamicView extends BasicView<'dynamic'> {
240
+ interface DynamicView<ViewIDs extends string = string, Tags extends string = string> extends BasicView<'dynamic', ViewIDs, Tags> {
429
241
  readonly __: 'dynamic';
430
242
  readonly steps: DynamicViewStepOrParallel[];
431
243
  readonly rules: DynamicViewRule[];
@@ -434,12 +246,12 @@ declare function isDynamicViewParallelSteps(step: DynamicViewStepOrParallel): st
434
246
  type CustomColorDefinitions = {
435
247
  [key: string]: ThemeColorValues;
436
248
  };
437
- type LikeC4View = ElementView | DynamicView;
249
+ type LikeC4View<ViewIDs extends string = string, Tags extends string = string> = ElementView<ViewIDs, Tags> | DynamicView<ViewIDs, Tags>;
438
250
  declare function isDynamicView(view: LikeC4View): view is DynamicView;
439
251
  declare function isElementView(view: LikeC4View): view is ElementView;
440
- declare function isExtendsElementView(view: LikeC4View): view is ExtendsElementView;
441
- declare function isScopedElementView(view: LikeC4View): view is ScopedElementView;
442
- type NodeId = Tagged<string, 'Fqn'>;
252
+ declare function isExtendsElementView(view: LikeC4View): view is ExtendsElementView<string, string>;
253
+ declare function isScopedElementView(view: LikeC4View): view is ScopedElementView<string, string>;
254
+ type NodeId<IDs extends string = string> = Tagged<IDs, 'Fqn'>;
443
255
  type EdgeId = Tagged<string, 'EdgeId'>;
444
256
  type StepEdgeIdLiteral = `step-${number}` | `step-${number}.${number}`;
445
257
  type StepEdgeId = Tagged<StepEdgeIdLiteral, 'EdgeId'>;
@@ -523,15 +335,15 @@ interface ViewAutoLayout {
523
335
  rankSep?: number;
524
336
  nodeSep?: number;
525
337
  }
526
- interface ComputedElementView extends Omit<ElementView, 'rules' | 'docUri'>, ViewWithHash, ViewWithNotation {
527
- readonly extends?: ViewID;
338
+ interface ComputedElementView<ViewIDs extends string = string, Tags extends string = string> extends Omit<ElementView<ViewIDs, Tags>, 'rules' | 'docUri'>, ViewWithHash, ViewWithNotation {
339
+ readonly extends?: ViewID<ViewIDs>;
528
340
  readonly autoLayout: ViewAutoLayout;
529
341
  readonly nodes: ComputedNode[];
530
342
  readonly edges: ComputedEdge[];
531
343
  rules?: never;
532
344
  docUri?: never;
533
345
  }
534
- interface ComputedDynamicView extends Omit<DynamicView, 'rules' | 'steps' | 'docUri'>, ViewWithHash, ViewWithNotation {
346
+ interface ComputedDynamicView<ViewIDs extends string = string, Tags extends string = string> extends Omit<DynamicView<ViewIDs, Tags>, 'rules' | 'steps' | 'docUri'>, ViewWithHash, ViewWithNotation {
535
347
  readonly autoLayout: ViewAutoLayout;
536
348
  readonly nodes: ComputedNode[];
537
349
  readonly edges: ComputedEdge[];
@@ -540,7 +352,7 @@ interface ComputedDynamicView extends Omit<DynamicView, 'rules' | 'steps' | 'doc
540
352
  docUri?: never;
541
353
  }
542
354
  declare function isComputedDynamicView(view: ComputedView): view is ComputedDynamicView;
543
- type ComputedView = ComputedElementView | ComputedDynamicView;
355
+ type ComputedView<ViewIDs extends string = string, Tags extends string = string> = ComputedElementView<ViewIDs, Tags> | ComputedDynamicView<ViewIDs, Tags>;
544
356
  declare function isComputedElementView(view: ComputedView): view is ComputedElementView;
545
357
  type BBox = {
546
358
  x: number;
@@ -561,7 +373,7 @@ interface DiagramEdge extends ComputedEdge {
561
373
  labelBBox?: BBox | null;
562
374
  dotpos?: string;
563
375
  }
564
- interface DiagramView extends Omit<ComputedView, 'nodes' | 'edges' | 'manualLayout'> {
376
+ interface DiagramView<ViewIDs extends string = string, Tags extends string = string> extends Omit<ComputedView<ViewIDs, Tags>, 'nodes' | 'edges' | 'manualLayout'> {
565
377
  readonly nodes: DiagramNode[];
566
378
  readonly edges: DiagramEdge[];
567
379
  readonly bounds: BBox;
@@ -594,18 +406,206 @@ type ViewManualLayout = {
594
406
  }>;
595
407
  };
596
408
 
409
+ type RelationID = Tagged<string, 'RelationID'>;
410
+ type RelationshipKind<Kinds extends string = string> = Tagged<Kinds, 'RelationshipKind'>;
411
+ type RelationshipLineType = 'dashed' | 'solid' | 'dotted';
412
+ type RelationshipArrowType = 'none' | 'normal' | 'onormal' | 'dot' | 'odot' | 'diamond' | 'odiamond' | 'crow' | 'open' | 'vee';
413
+ declare const DefaultLineStyle = "dashed";
414
+ declare const DefaultArrowType = "normal";
415
+ declare const DefaultRelationshipColor = "gray";
416
+ interface Relation {
417
+ readonly id: RelationID;
418
+ readonly source: Fqn;
419
+ readonly target: Fqn;
420
+ readonly title: string;
421
+ readonly description?: string;
422
+ readonly technology?: string;
423
+ readonly tags?: NonEmptyArray<Tag>;
424
+ readonly kind?: RelationshipKind;
425
+ readonly color?: Color;
426
+ readonly line?: RelationshipLineType;
427
+ readonly head?: RelationshipArrowType;
428
+ readonly tail?: RelationshipArrowType;
429
+ readonly links?: NonEmptyArray<Link>;
430
+ readonly navigateTo?: ViewID;
431
+ readonly metadata?: {
432
+ [key: string]: string;
433
+ };
434
+ }
435
+ interface RelationshipKindSpecification {
436
+ readonly technology?: string;
437
+ readonly notation?: string;
438
+ readonly color?: Color;
439
+ readonly line?: RelationshipLineType;
440
+ readonly head?: RelationshipArrowType;
441
+ readonly tail?: RelationshipArrowType;
442
+ }
443
+
444
+ interface BaseExpr {
445
+ where?: never;
446
+ element?: never;
447
+ custom?: never;
448
+ expanded?: never;
449
+ elementKind?: never;
450
+ elementTag?: never;
451
+ isEqual?: never;
452
+ isDescedants?: never;
453
+ wildcard?: never;
454
+ source?: never;
455
+ target?: never;
456
+ inout?: never;
457
+ incoming?: never;
458
+ outgoing?: never;
459
+ customRelation?: never;
460
+ }
461
+ interface ElementRefExpr extends Omit<BaseExpr, 'element' | 'isDescedants'> {
462
+ element: Fqn;
463
+ isDescedants?: boolean;
464
+ }
465
+ declare function isElementRef(expr: Expression): expr is ElementRefExpr;
466
+ interface ExpandedElementExpr extends Omit<BaseExpr, 'expanded'> {
467
+ expanded: Fqn;
468
+ }
469
+ declare function isExpandedElementExpr(expr: Expression): expr is ExpandedElementExpr;
470
+ interface CustomElementExpr extends Omit<BaseExpr, 'custom'> {
471
+ custom: {
472
+ expr: ElementExpression | ElementWhereExpr;
473
+ title?: string;
474
+ description?: string;
475
+ technology?: string;
476
+ notation?: string;
477
+ shape?: ElementShape;
478
+ color?: Color;
479
+ icon?: IconUrl;
480
+ border?: BorderStyle;
481
+ opacity?: number;
482
+ navigateTo?: ViewID;
483
+ };
484
+ }
485
+ declare function isCustomElement(expr: Expression): expr is CustomElementExpr;
486
+ interface WildcardExpr extends Omit<BaseExpr, 'wildcard'> {
487
+ wildcard: true;
488
+ }
489
+ declare function isWildcard(expr: Expression): expr is WildcardExpr;
490
+ interface ElementKindExpr extends Omit<BaseExpr, 'elementKind' | 'isEqual'> {
491
+ elementKind: ElementKind;
492
+ isEqual: boolean;
493
+ }
494
+ declare function isElementKindExpr(expr: Expression): expr is ElementKindExpr;
495
+ interface ElementTagExpr extends Omit<BaseExpr, 'elementTag' | 'isEqual'> {
496
+ elementTag: Tag;
497
+ isEqual: boolean;
498
+ }
499
+ declare function isElementTagExpr(expr: Expression): expr is ElementTagExpr;
500
+ type ElementExpression = ElementRefExpr | WildcardExpr | ElementKindExpr | ElementTagExpr | ExpandedElementExpr;
501
+ declare function isElement(expr: Expression): expr is ElementExpression;
502
+ interface ElementWhereExpr extends Omit<BaseExpr, 'where'> {
503
+ where: {
504
+ expr: ElementExpression;
505
+ condition: WhereOperator<string, string>;
506
+ };
507
+ }
508
+ declare function isElementWhere(expr: Expression): expr is ElementWhereExpr;
509
+ type ElementPredicateExpression = ElementExpression | ElementWhereExpr | CustomElementExpr;
510
+ declare function isElementPredicateExpr(expr: Expression): expr is ElementPredicateExpression;
511
+ interface RelationExpr extends Omit<BaseExpr, 'source' | 'target'> {
512
+ source: ElementExpression;
513
+ target: ElementExpression;
514
+ isBidirectional?: boolean;
515
+ }
516
+ declare function isRelation(expr: Expression): expr is RelationExpr;
517
+ interface InOutExpr extends Omit<BaseExpr, 'inout'> {
518
+ inout: ElementExpression;
519
+ }
520
+ declare function isInOut(expr: Expression): expr is InOutExpr;
521
+ interface IncomingExpr extends Omit<BaseExpr, 'incoming'> {
522
+ incoming: ElementExpression;
523
+ }
524
+ declare function isIncoming(expr: Expression): expr is IncomingExpr;
525
+ interface OutgoingExpr extends Omit<BaseExpr, 'outgoing'> {
526
+ outgoing: ElementExpression;
527
+ }
528
+ declare function isOutgoing(expr: Expression): expr is OutgoingExpr;
529
+ type RelationExpression = RelationExpr | InOutExpr | IncomingExpr | OutgoingExpr;
530
+ declare function isRelationExpression(expr: Expression): expr is RelationExpression;
531
+ interface RelationWhereExpr extends Omit<BaseExpr, 'where'> {
532
+ where: {
533
+ expr: RelationExpression;
534
+ condition: WhereOperator<string, string>;
535
+ };
536
+ }
537
+ declare function isRelationWhere(expr: Expression): expr is RelationWhereExpr;
538
+ interface CustomRelationExpr extends Omit<BaseExpr, 'customRelation'> {
539
+ customRelation: {
540
+ relation: RelationExpression | RelationWhereExpr;
541
+ title?: string;
542
+ description?: string;
543
+ technology?: string;
544
+ notation?: string;
545
+ navigateTo?: ViewID;
546
+ notes?: string;
547
+ color?: Color;
548
+ line?: RelationshipLineType;
549
+ head?: RelationshipArrowType;
550
+ tail?: RelationshipArrowType;
551
+ };
552
+ }
553
+ declare function isCustomRelationExpr(expr: Expression): expr is CustomRelationExpr;
554
+ type RelationPredicateExpression = RelationExpression | RelationWhereExpr | CustomRelationExpr;
555
+ declare function isRelationPredicateExpr(expr: Expression): expr is RelationPredicateExpression;
556
+ type Expression = ElementPredicateExpression | RelationPredicateExpression;
557
+
558
+ type expression_CustomElementExpr = CustomElementExpr;
559
+ type expression_CustomRelationExpr = CustomRelationExpr;
560
+ type expression_ElementExpression = ElementExpression;
561
+ type expression_ElementKindExpr = ElementKindExpr;
562
+ type expression_ElementPredicateExpression = ElementPredicateExpression;
563
+ type expression_ElementRefExpr = ElementRefExpr;
564
+ type expression_ElementTagExpr = ElementTagExpr;
565
+ type expression_ElementWhereExpr = ElementWhereExpr;
566
+ type expression_ExpandedElementExpr = ExpandedElementExpr;
567
+ type expression_Expression = Expression;
568
+ type expression_InOutExpr = InOutExpr;
569
+ type expression_IncomingExpr = IncomingExpr;
570
+ type expression_OutgoingExpr = OutgoingExpr;
571
+ type expression_RelationExpr = RelationExpr;
572
+ type expression_RelationExpression = RelationExpression;
573
+ type expression_RelationPredicateExpression = RelationPredicateExpression;
574
+ type expression_RelationWhereExpr = RelationWhereExpr;
575
+ type expression_WildcardExpr = WildcardExpr;
576
+ declare const expression_isCustomElement: typeof isCustomElement;
577
+ declare const expression_isCustomRelationExpr: typeof isCustomRelationExpr;
578
+ declare const expression_isElement: typeof isElement;
579
+ declare const expression_isElementKindExpr: typeof isElementKindExpr;
580
+ declare const expression_isElementPredicateExpr: typeof isElementPredicateExpr;
581
+ declare const expression_isElementRef: typeof isElementRef;
582
+ declare const expression_isElementTagExpr: typeof isElementTagExpr;
583
+ declare const expression_isElementWhere: typeof isElementWhere;
584
+ declare const expression_isExpandedElementExpr: typeof isExpandedElementExpr;
585
+ declare const expression_isInOut: typeof isInOut;
586
+ declare const expression_isIncoming: typeof isIncoming;
587
+ declare const expression_isOutgoing: typeof isOutgoing;
588
+ declare const expression_isRelation: typeof isRelation;
589
+ declare const expression_isRelationExpression: typeof isRelationExpression;
590
+ declare const expression_isRelationPredicateExpr: typeof isRelationPredicateExpr;
591
+ declare const expression_isRelationWhere: typeof isRelationWhere;
592
+ declare const expression_isWildcard: typeof isWildcard;
593
+ declare namespace expression {
594
+ export { type expression_CustomElementExpr as CustomElementExpr, type expression_CustomRelationExpr as CustomRelationExpr, type expression_ElementExpression as ElementExpression, type expression_ElementKindExpr as ElementKindExpr, type expression_ElementPredicateExpression as ElementPredicateExpression, type expression_ElementRefExpr as ElementRefExpr, type expression_ElementTagExpr as ElementTagExpr, type expression_ElementWhereExpr as ElementWhereExpr, type expression_ExpandedElementExpr as ExpandedElementExpr, type expression_Expression as Expression, type expression_InOutExpr as InOutExpr, type expression_IncomingExpr as IncomingExpr, type expression_OutgoingExpr as OutgoingExpr, type expression_RelationExpr as RelationExpr, type expression_RelationExpression as RelationExpression, type expression_RelationPredicateExpression as RelationPredicateExpression, type expression_RelationWhereExpr as RelationWhereExpr, type expression_WildcardExpr as WildcardExpr, expression_isCustomElement as isCustomElement, expression_isCustomRelationExpr as isCustomRelationExpr, expression_isElement as isElement, expression_isElementKindExpr as isElementKindExpr, expression_isElementPredicateExpr as isElementPredicateExpr, expression_isElementRef as isElementRef, expression_isElementTagExpr as isElementTagExpr, expression_isElementWhere as isElementWhere, expression_isExpandedElementExpr as isExpandedElementExpr, expression_isInOut as isInOut, expression_isIncoming as isIncoming, expression_isOutgoing as isOutgoing, expression_isRelation as isRelation, expression_isRelationExpression as isRelationExpression, expression_isRelationPredicateExpr as isRelationPredicateExpr, expression_isRelationWhere as isRelationWhere, expression_isWildcard as isWildcard };
595
+ }
596
+
597
597
  /**
598
598
  * Parsed elements, relations, and views.
599
599
  */
600
- interface ParsedLikeC4Model {
600
+ interface ParsedLikeC4Model<ElementKinds extends string = string, RelationKinds extends string = string, Tags extends string = string, Fqns extends string = string, Views extends string = string> {
601
601
  specification: {
602
- tags: Tag[];
603
- elements: Record<UnwrapTagged<ElementKind>, ElementKindSpecification>;
604
- relationships: Record<UnwrapTagged<ElementKind>, RelationshipKindSpecification>;
602
+ tags: Tag<Tags>[];
603
+ elements: Record<ElementKinds, ElementKindSpecification>;
604
+ relationships: Record<RelationKinds, RelationshipKindSpecification>;
605
605
  };
606
- elements: Record<Fqn, Element>;
606
+ elements: Record<Fqns, TypedElement<Fqns, ElementKinds, Tags>>;
607
607
  relations: Record<RelationID, Relation>;
608
- views: Record<ViewID, LikeC4View>;
608
+ views: Record<Views, LikeC4View<Views, Tags>>;
609
609
  }
610
610
  /**
611
611
  * Same as `ParsedLikeC4Model` but with computed views.
@@ -678,9 +678,13 @@ declare namespace ViewChange {
678
678
  }
679
679
  interface ChangeAutoLayout {
680
680
  op: 'change-autolayout';
681
- layout: ViewRuleAutoLayout;
681
+ layout: {
682
+ direction: AutoLayoutDirection;
683
+ nodeSep?: number | null;
684
+ rankSep?: number | null;
685
+ };
682
686
  }
683
687
  }
684
688
  type ViewChange = ViewChange.ChangeElementStyle | ViewChange.SaveManualLayout | ViewChange.ChangeAutoLayout;
685
689
 
686
- export { isElement as $, AsFqn as A, BorderStyles as B, type ComputedView as C, type DiagramView as D, type EdgeId as E, type Fqn as F, isElementRef as G, type HexColorLiteral as H, type IconUrl as I, type ExpandedElementExpr as J, isExpandedElementExpr as K, type LayoutedLikeC4Model as L, type CustomElementExpr as M, type NodeId as N, isCustomElement as O, type Point as P, isWildcard as Q, type RelationID as R, type ElementKindExpr as S, type ThemeColorValues as T, isElementKindExpr as U, type ViewID as V, type WildcardExpr as W, type XYPoint as X, type ElementTagExpr as Y, isElementTagExpr as Z, type ElementExpression as _, type Tag as a, type ElementView as a$, type ElementWhereExpr as a0, isElementWhere as a1, type ElementPredicateExpression as a2, isElementPredicateExpr as a3, type RelationExpr as a4, isRelation as a5, type InOutExpr as a6, isInOut as a7, type IncomingExpr as a8, isIncoming as a9, type RelationshipLineType as aA, type RelationshipArrowType as aB, DefaultLineStyle as aC, DefaultArrowType as aD, DefaultRelationshipColor as aE, type RelationshipKindSpecification as aF, type ThemeColor as aG, type ColorLiteral as aH, isThemeColor as aI, type ElementThemeColorValues as aJ, type ElementThemeColors as aK, type RelationshipThemeColorValues as aL, type RelationshipThemeColors as aM, type LikeC4Theme as aN, type ViewRulePredicate as aO, isViewRulePredicate as aP, type ViewRuleStyle as aQ, isViewRuleStyle as aR, type AutoLayoutDirection as aS, isAutoLayoutDirection as aT, type ViewRuleAutoLayout as aU, isViewRuleAutoLayout as aV, type ViewRule as aW, type BasicView as aX, type BasicElementView as aY, type ScopedElementView as aZ, type ExtendsElementView as a_, type OutgoingExpr as aa, isOutgoing as ab, type RelationExpression as ac, isRelationExpression as ad, type RelationWhereExpr as ae, isRelationWhere as af, type CustomRelationExpr as ag, isCustomRelationExpr as ah, type RelationPredicateExpression as ai, isRelationPredicateExpr as aj, type Expression as ak, type ParsedLikeC4Model as al, type EqualOperator as am, type TagEqual as an, isTagEqual as ao, type KindEqual as ap, isKindEqual as aq, type NotOperator as ar, isNotOperator as as, type AndOperator as at, isAndOperator as au, type OrOperator as av, isOrOperator as aw, type WhereOperator as ax, whereOperatorAsPredicate as ay, OverviewGraph as az, type ComputedNode as b, type DynamicViewStep as b0, type DynamicViewParallelSteps as b1, type DynamicViewStepOrParallel as b2, type DynamicViewIncludeRule as b3, isDynamicViewIncludeRule as b4, type DynamicViewRule as b5, type DynamicView as b6, isDynamicViewParallelSteps as b7, type CustomColorDefinitions as b8, type LikeC4View as b9, isDynamicView as ba, isElementView as bb, isExtendsElementView as bc, isScopedElementView as bd, type StepEdgeIdLiteral as be, StepEdgeId as bf, isStepEdgeId as bg, extractStep as bh, getParallelStepsPrefix as bi, type ViewWithHash as bj, type ViewWithNotation as bk, type ViewAutoLayout as bl, type ComputedElementView as bm, type ComputedDynamicView as bn, isComputedDynamicView as bo, isComputedElementView as bp, type BBox as bq, getBBoxCenter as br, type ViewManualLayout as bs, ViewChange as bt, type ElementNotation as bu, type ElementKind as c, type ElementShape as d, type Color as e, type ComputedEdge as f, type ComputedLikeC4Model as g, type Element as h, type Relation as i, type RelationshipKind as j, type DiagramNode as k, type DiagramEdge as l, type NonEmptyArray as m, expression as n, type NonEmptyReadonlyArray as o, type CustomColor as p, type BorderStyle as q, ElementShapes as r, DefaultThemeColor as s, DefaultElementShape as t, type ElementStyle as u, type TagSpec as v, type Link as w, type ElementKindSpecificationStyle as x, type ElementKindSpecification as y, type ElementRefExpr as z };
690
+ export { type ExpandedElementExpr as $, type AutoLayoutDirection as A, type BorderStyle as B, type Color as C, type DiagramView as D, type ElementKindSpecification as E, type Fqn as F, AsFqn as G, type HexColorLiteral as H, type IconUrl as I, BorderStyles as J, ElementShapes as K, type LikeC4View as L, DefaultThemeColor as M, type NonEmptyArray as N, DefaultElementShape as O, type ParsedLikeC4Model as P, type ElementStyle as Q, type RelationshipKindSpecification as R, type TagSpec as S, type ThemeColorValues as T, type Link as U, type ViewRuleStyle as V, type TypedElement as W, type XYPoint as X, type ElementKindSpecificationStyle as Y, type ElementRefExpr as Z, isElementRef as _, type ElementShape as a, type ScopedElementView as a$, isExpandedElementExpr as a0, isCustomElement as a1, type WildcardExpr as a2, isWildcard as a3, type ElementKindExpr as a4, isElementKindExpr as a5, type ElementTagExpr as a6, isElementTagExpr as a7, type ElementExpression as a8, isElement as a9, type AndOperator as aA, isAndOperator as aB, type OrOperator as aC, isOrOperator as aD, type WhereOperator as aE, whereOperatorAsPredicate as aF, OverviewGraph as aG, DefaultLineStyle as aH, DefaultArrowType as aI, DefaultRelationshipColor as aJ, type ThemeColor as aK, type ColorLiteral as aL, isThemeColor as aM, type ElementThemeColorValues as aN, type ElementThemeColors as aO, type RelationshipThemeColorValues as aP, type RelationshipThemeColors as aQ, type LikeC4Theme as aR, type ViewRulePredicate as aS, isViewRulePredicate as aT, isViewRuleStyle as aU, isAutoLayoutDirection as aV, type ViewRuleAutoLayout as aW, isViewRuleAutoLayout as aX, type ViewRule as aY, type BasicView as aZ, type BasicElementView as a_, type ElementWhereExpr as aa, isElementWhere as ab, type ElementPredicateExpression as ac, isElementPredicateExpr as ad, type RelationExpr as ae, isRelation as af, type InOutExpr as ag, isInOut as ah, type IncomingExpr as ai, isIncoming as aj, type OutgoingExpr as ak, isOutgoing as al, type RelationExpression as am, isRelationExpression as an, type RelationWhereExpr as ao, isRelationWhere as ap, isCustomRelationExpr as aq, type RelationPredicateExpression as ar, isRelationPredicateExpr as as, type EqualOperator as at, type TagEqual as au, isTagEqual as av, type KindEqual as aw, isKindEqual as ax, type NotOperator as ay, isNotOperator as az, type RelationshipArrowType as b, type ExtendsElementView as b0, type ElementView as b1, type DynamicViewStep as b2, type DynamicViewParallelSteps as b3, type DynamicViewStepOrParallel as b4, type DynamicViewIncludeRule as b5, isDynamicViewIncludeRule as b6, type DynamicViewRule as b7, type DynamicView as b8, isDynamicViewParallelSteps as b9, type CustomColorDefinitions as ba, isDynamicView as bb, isElementView as bc, isExtendsElementView as bd, isScopedElementView as be, type StepEdgeIdLiteral as bf, StepEdgeId as bg, isStepEdgeId as bh, extractStep as bi, getParallelStepsPrefix as bj, type ViewWithHash as bk, type ViewWithNotation as bl, type ViewAutoLayout as bm, type ComputedElementView as bn, type ComputedDynamicView as bo, isComputedDynamicView as bp, isComputedElementView as bq, type BBox as br, getBBoxCenter as bs, type ViewManualLayout as bt, ViewChange as bu, type ElementNotation as bv, type RelationshipLineType as c, type Element as d, type Relation as e, type Expression as f, type CustomElementExpr as g, type CustomRelationExpr as h, type RelationID as i, type ViewID as j, type EdgeId as k, type ComputedView as l, type Tag as m, type ComputedNode as n, type NodeId as o, type ElementKind as p, type ComputedEdge as q, type ComputedLikeC4Model as r, type LayoutedLikeC4Model as s, type RelationshipKind as t, type DiagramNode as u, type DiagramEdge as v, expression as w, type NonEmptyReadonlyArray as x, type CustomColor as y, type Point as z };