@agilewallaby/c4-model 2.8.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilewallaby/c4-model",
3
- "version": "2.8.0",
3
+ "version": "4.0.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,5 +1,11 @@
1
1
  import { TechnologyDefinition } from './core';
2
- export type ElementKind = 'person' | 'softwareSystem' | 'container' | 'component';
2
+ export declare const ELEMENT_KINDS: {
3
+ readonly person: "person";
4
+ readonly softwareSystem: "softwareSystem";
5
+ readonly container: "container";
6
+ readonly component: "component";
7
+ };
8
+ export type ElementKind = (typeof ELEMENT_KINDS)[keyof typeof ELEMENT_KINDS];
3
9
  export declare class ElementArchetype {
4
10
  readonly name: string;
5
11
  readonly elementKind: ElementKind;
@@ -10,6 +16,7 @@ export declare class ElementArchetype {
10
16
  readonly description?: string;
11
17
  readonly technology?: string;
12
18
  readonly tags: ReadonlyArray<string>;
19
+ get canonicalName(): string;
13
20
  constructor(name: string, elementKind: ElementKind, definition?: TechnologyDefinition, parent?: ElementArchetype | undefined);
14
21
  }
15
22
  export declare class RelationshipArchetype {
@@ -21,6 +28,7 @@ export declare class RelationshipArchetype {
21
28
  readonly description?: string;
22
29
  readonly technology?: string;
23
30
  readonly tags: ReadonlyArray<string>;
31
+ get canonicalName(): string;
24
32
  constructor(name: string, definition?: TechnologyDefinition, parent?: RelationshipArchetype | undefined);
25
33
  }
26
34
  export declare function mergeArchetypeWithOverride(archetype: {
package/src/index.cjs CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  Component: () => Component,
34
34
  Container: () => Container,
35
35
  ContainerGroup: () => ContainerGroup,
36
+ ELEMENT_KINDS: () => ELEMENT_KINDS,
36
37
  ElementArchetype: () => ElementArchetype,
37
38
  Model: () => Model,
38
39
  ModelGroup: () => ModelGroup,
@@ -41,7 +42,6 @@ __export(index_exports, {
41
42
  SoftwareSystem: () => SoftwareSystem,
42
43
  SoftwareSystemGroup: () => SoftwareSystemGroup,
43
44
  StructurizrDSLWriter: () => StructurizrDSLWriter,
44
- View: () => View,
45
45
  Views: () => Views,
46
46
  buildModel: () => buildModel,
47
47
  exportWorkspaceJson: () => exportWorkspaceJson,
@@ -52,52 +52,6 @@ __export(index_exports, {
52
52
  });
53
53
  module.exports = __toCommonJS(index_exports);
54
54
 
55
- // libs/c4-model/src/archetype.ts
56
- var ElementArchetype = class {
57
- constructor(name, elementKind, definition, parent) {
58
- this.name = name;
59
- this.elementKind = elementKind;
60
- this.parent = parent;
61
- this.ownDescription = definition?.description;
62
- this.ownTechnology = definition?.technology;
63
- this.ownTags = definition?.tags ?? [];
64
- this.description = this.ownDescription ?? parent?.description;
65
- this.technology = this.ownTechnology ?? parent?.technology;
66
- this.tags = [...parent?.tags ?? [], ...this.ownTags];
67
- }
68
- ownDescription;
69
- ownTechnology;
70
- ownTags;
71
- description;
72
- technology;
73
- tags;
74
- };
75
- var RelationshipArchetype = class {
76
- constructor(name, definition, parent) {
77
- this.name = name;
78
- this.parent = parent;
79
- this.ownDescription = definition?.description;
80
- this.ownTechnology = definition?.technology;
81
- this.ownTags = definition?.tags ?? [];
82
- this.description = this.ownDescription ?? parent?.description;
83
- this.technology = this.ownTechnology ?? parent?.technology;
84
- this.tags = [...parent?.tags ?? [], ...this.ownTags];
85
- }
86
- ownDescription;
87
- ownTechnology;
88
- ownTags;
89
- description;
90
- technology;
91
- tags;
92
- };
93
- function mergeArchetypeWithOverride(archetype, override) {
94
- return {
95
- description: override?.description ?? archetype.description,
96
- technology: override?.technology ?? archetype.technology,
97
- tags: [...archetype.tags, ...override?.tags ?? []]
98
- };
99
- }
100
-
101
55
  // node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js
102
56
  var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
103
57
  var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
@@ -184,6 +138,64 @@ function splitPrefixSuffix(input, options = {}) {
184
138
  ];
185
139
  }
186
140
 
141
+ // libs/c4-model/src/archetype.ts
142
+ var ELEMENT_KINDS = {
143
+ person: "person",
144
+ softwareSystem: "softwareSystem",
145
+ container: "container",
146
+ component: "component"
147
+ };
148
+ var ElementArchetype = class {
149
+ constructor(name, elementKind, definition, parent) {
150
+ this.name = name;
151
+ this.elementKind = elementKind;
152
+ this.parent = parent;
153
+ this.ownDescription = definition?.description;
154
+ this.ownTechnology = definition?.technology;
155
+ this.ownTags = definition?.tags ?? [];
156
+ this.description = this.ownDescription ?? parent?.description;
157
+ this.technology = this.ownTechnology ?? parent?.technology;
158
+ this.tags = [...parent?.tags ?? [], ...this.ownTags];
159
+ }
160
+ ownDescription;
161
+ ownTechnology;
162
+ ownTags;
163
+ description;
164
+ technology;
165
+ tags;
166
+ get canonicalName() {
167
+ return camelCase(this.name);
168
+ }
169
+ };
170
+ var RelationshipArchetype = class {
171
+ constructor(name, definition, parent) {
172
+ this.name = name;
173
+ this.parent = parent;
174
+ this.ownDescription = definition?.description;
175
+ this.ownTechnology = definition?.technology;
176
+ this.ownTags = definition?.tags ?? [];
177
+ this.description = this.ownDescription ?? parent?.description;
178
+ this.technology = this.ownTechnology ?? parent?.technology;
179
+ this.tags = [...parent?.tags ?? [], ...this.ownTags];
180
+ }
181
+ ownDescription;
182
+ ownTechnology;
183
+ ownTags;
184
+ description;
185
+ technology;
186
+ tags;
187
+ get canonicalName() {
188
+ return camelCase(this.name);
189
+ }
190
+ };
191
+ function mergeArchetypeWithOverride(archetype, override) {
192
+ return {
193
+ description: override?.description ?? archetype.description,
194
+ technology: override?.technology ?? archetype.technology,
195
+ tags: [...archetype.tags, ...override?.tags ?? []]
196
+ };
197
+ }
198
+
187
199
  // libs/c4-model/src/core.ts
188
200
  var Element = class {
189
201
  constructor(name, defaultTags = [], definition, archetype, overrideDefinition) {
@@ -629,6 +641,10 @@ var View = class {
629
641
  addProperty(name, value) {
630
642
  this._properties.set(name, value);
631
643
  }
644
+ with(callback) {
645
+ callback(this);
646
+ return this;
647
+ }
632
648
  get scopes() {
633
649
  return this._scopes;
634
650
  }
@@ -762,7 +778,7 @@ var StructurizrDSLWriter = class {
762
778
  if (elementArchetypes.length === 0 && relationshipArchetypes.length === 0) return "";
763
779
  let dsl = this.writeLine(`archetypes {`, level);
764
780
  for (const arch of elementArchetypes) {
765
- const baseType = arch.parent ? arch.parent.name : arch.elementKind;
781
+ const baseType = arch.parent ? arch.parent.canonicalName : arch.elementKind;
766
782
  let inner = "";
767
783
  if (arch.ownDescription) {
768
784
  inner += this.writeLine(`description "${arch.ownDescription}"`, level + 2);
@@ -774,15 +790,15 @@ var StructurizrDSLWriter = class {
774
790
  inner += this.writeLine(`tags ${arch.ownTags.map((t) => `"${t}"`).join(" ")}`, level + 2);
775
791
  }
776
792
  if (inner) {
777
- dsl += this.writeLine(`${arch.name} = ${baseType} {`, level + 1);
793
+ dsl += this.writeLine(`${arch.canonicalName} = ${baseType} {`, level + 1);
778
794
  dsl += inner;
779
795
  dsl += this.writeLine(`}`, level + 1);
780
796
  } else {
781
- dsl += this.writeLine(`${arch.name} = ${baseType} {}`, level + 1);
797
+ dsl += this.writeLine(`${arch.canonicalName} = ${baseType} {}`, level + 1);
782
798
  }
783
799
  }
784
800
  for (const arch of relationshipArchetypes) {
785
- const arrow = arch.parent ? `--${arch.parent.name}->` : `->`;
801
+ const arrow = arch.parent ? `--${arch.parent.canonicalName}->` : `->`;
786
802
  let inner = "";
787
803
  if (arch.ownDescription) {
788
804
  inner += this.writeLine(`description "${arch.ownDescription}"`, level + 2);
@@ -794,11 +810,11 @@ var StructurizrDSLWriter = class {
794
810
  inner += this.writeLine(`tags ${arch.ownTags.map((t) => `"${t}"`).join(" ")}`, level + 2);
795
811
  }
796
812
  if (inner) {
797
- dsl += this.writeLine(`${arch.name} = ${arrow} {`, level + 1);
813
+ dsl += this.writeLine(`${arch.canonicalName} = ${arrow} {`, level + 1);
798
814
  dsl += inner;
799
815
  dsl += this.writeLine(`}`, level + 1);
800
816
  } else {
801
- dsl += this.writeLine(`${arch.name} = ${arrow} {}`, level + 1);
817
+ dsl += this.writeLine(`${arch.canonicalName} = ${arrow} {}`, level + 1);
802
818
  }
803
819
  }
804
820
  dsl += this.writeLine(`}`, level);
@@ -806,7 +822,7 @@ var StructurizrDSLWriter = class {
806
822
  }
807
823
  writeElement(elementType, element, level, closeElement = true) {
808
824
  let elementDsl = "";
809
- const type = element.archetype ? element.archetype.name : elementType;
825
+ const type = element.archetype ? element.archetype.canonicalName : elementType;
810
826
  elementDsl += this.writeLine(`${element.canonicalName} = ${type} "${element.name}" {`, level);
811
827
  if (element.archetype) {
812
828
  const ovr = element.overrideDefinition;
@@ -899,7 +915,7 @@ var StructurizrDSLWriter = class {
899
915
  writeRelationship(relationship, level) {
900
916
  let dsl = "";
901
917
  if (relationship.archetype) {
902
- const arrow = `--${relationship.archetype.name}->`;
918
+ const arrow = `--${relationship.archetype.canonicalName}->`;
903
919
  const ovr = relationship.overrideDefinition;
904
920
  const desc = ovr?.description ?? relationship.description ?? "uses";
905
921
  dsl += this.writeLine(
@@ -996,7 +1012,9 @@ var StructurizrDSLWriter = class {
996
1012
  }
997
1013
  writeView(view, viewType, level) {
998
1014
  let viewDsl = this.writeLine(`${viewType}${view.subject ? ' "' + view.subject.canonicalName + '"' : ""} "${view.key}" {`, level);
999
- viewDsl += this.writeLine(`description "${view.description}"`, level + 1);
1015
+ if (view.description) {
1016
+ viewDsl += this.writeLine(`description "${view.description}"`, level + 1);
1017
+ }
1000
1018
  if (view.title) {
1001
1019
  viewDsl += this.writeLine(`title "${view.title}"`, level + 1);
1002
1020
  }
@@ -1241,6 +1259,7 @@ async function exportWorkspaceJson(model, views) {
1241
1259
  Component,
1242
1260
  Container,
1243
1261
  ContainerGroup,
1262
+ ELEMENT_KINDS,
1244
1263
  ElementArchetype,
1245
1264
  Model,
1246
1265
  ModelGroup,
@@ -1249,7 +1268,6 @@ async function exportWorkspaceJson(model, views) {
1249
1268
  SoftwareSystem,
1250
1269
  SoftwareSystemGroup,
1251
1270
  StructurizrDSLWriter,
1252
- View,
1253
1271
  Views,
1254
1272
  buildModel,
1255
1273
  exportWorkspaceJson,
package/src/index.d.ts CHANGED
@@ -43,7 +43,13 @@ declare class Group<TChild extends Element$1 | Group = never> {
43
43
  get canonicalName(): string;
44
44
  with<TChildren extends Record<string, TChild>>(callback: (self: this) => TChildren): this & TChildren;
45
45
  }
46
- export type ElementKind = "person" | "softwareSystem" | "container" | "component";
46
+ export declare const ELEMENT_KINDS: {
47
+ readonly person: "person";
48
+ readonly softwareSystem: "softwareSystem";
49
+ readonly container: "container";
50
+ readonly component: "component";
51
+ };
52
+ export type ElementKind = (typeof ELEMENT_KINDS)[keyof typeof ELEMENT_KINDS];
47
53
  export declare class ElementArchetype {
48
54
  readonly name: string;
49
55
  readonly elementKind: ElementKind;
@@ -54,6 +60,7 @@ export declare class ElementArchetype {
54
60
  readonly description?: string;
55
61
  readonly technology?: string;
56
62
  readonly tags: ReadonlyArray<string>;
63
+ get canonicalName(): string;
57
64
  constructor(name: string, elementKind: ElementKind, definition?: TechnologyDefinition, parent?: ElementArchetype | undefined);
58
65
  }
59
66
  export declare class RelationshipArchetype {
@@ -65,6 +72,7 @@ export declare class RelationshipArchetype {
65
72
  readonly description?: string;
66
73
  readonly technology?: string;
67
74
  readonly tags: ReadonlyArray<string>;
75
+ get canonicalName(): string;
68
76
  constructor(name: string, definition?: TechnologyDefinition, parent?: RelationshipArchetype | undefined);
69
77
  }
70
78
  export declare function mergeArchetypeWithOverride(archetype: {
@@ -147,11 +155,13 @@ export declare class Person extends Element$1 {
147
155
  constructor(name: string, definition?: PersonDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
148
156
  getChildElements(): ReadonlyArray<Element$1>;
149
157
  }
150
- export interface ViewDefinition<T extends Element$1> {
151
- subject?: T;
152
- description: string;
158
+ export interface BaseViewDefinition {
159
+ description?: string;
153
160
  title?: string;
154
161
  }
162
+ export interface ScopedViewDefinition<T extends Element$1> extends BaseViewDefinition {
163
+ subject: T;
164
+ }
155
165
  export type AutoLayoutDirection = "tb" | "bt" | "lr" | "rl";
156
166
  export interface AutoLayout {
157
167
  direction?: AutoLayoutDirection;
@@ -192,16 +202,7 @@ export interface RelationshipStyleEntry {
192
202
  tag: string;
193
203
  definition: RelationshipStyleDefinition;
194
204
  }
195
- export declare class View<T extends Element$1> {
196
- readonly key: string;
197
- readonly subject?: T;
198
- readonly description: string;
199
- readonly title?: string;
200
- private _scopes;
201
- private _autoLayout?;
202
- private _isDefault;
203
- private _properties;
204
- constructor(key: string, viewDefinition: ViewDefinition<T>);
205
+ export interface ViewBuilder {
205
206
  includeAll(): void;
206
207
  includeElement(element: Element$1): void;
207
208
  includeExpression(expression: string): void;
@@ -211,10 +212,17 @@ export declare class View<T extends Element$1> {
211
212
  autoLayout(direction?: AutoLayoutDirection, rankSeparation?: number, nodeSeparation?: number): void;
212
213
  setDefault(): void;
213
214
  addProperty(name: string, value: string): void;
214
- get scopes(): ReadonlyArray<string>;
215
- get autoLayoutConfig(): AutoLayout | undefined;
216
- get isDefault(): boolean;
217
- get properties(): ReadonlyMap<string, string>;
215
+ }
216
+ export interface ReadonlyView<T extends Element$1> {
217
+ readonly key: string;
218
+ readonly subject?: T;
219
+ readonly description?: string;
220
+ readonly title?: string;
221
+ readonly scopes: ReadonlyArray<string>;
222
+ readonly autoLayoutConfig: AutoLayout | undefined;
223
+ readonly isDefault: boolean;
224
+ readonly properties: ReadonlyMap<string, string>;
225
+ with(callback: (builder: ViewBuilder) => void): ReadonlyView<T>;
218
226
  }
219
227
  export declare class Views {
220
228
  private readonly _systemLandscapeViews;
@@ -225,18 +233,18 @@ export declare class Views {
225
233
  private _relationshipStyles;
226
234
  private _themes;
227
235
  private _properties;
228
- addSystemLandscapeView(key: string, definition: ViewDefinition<Element$1>): View<Element$1>;
229
- addSystemContextView(key: string, definition: ViewDefinition<SoftwareSystem>): View<SoftwareSystem>;
230
- addContainerView(key: string, definition: ViewDefinition<SoftwareSystem>): View<SoftwareSystem>;
231
- addComponentView(key: string, definition: ViewDefinition<Container>): View<Container>;
236
+ addSystemLandscapeView(key: string, definition: BaseViewDefinition): ReadonlyView<Element$1>;
237
+ addSystemContextView(key: string, definition: ScopedViewDefinition<SoftwareSystem>): ReadonlyView<SoftwareSystem>;
238
+ addContainerView(key: string, definition: ScopedViewDefinition<SoftwareSystem>): ReadonlyView<SoftwareSystem>;
239
+ addComponentView(key: string, definition: ScopedViewDefinition<Container>): ReadonlyView<Container>;
232
240
  addElementStyle(tag: string, definition: ElementStyleDefinition): void;
233
241
  addRelationshipStyle(tag: string, definition: RelationshipStyleDefinition): void;
234
242
  addTheme(url: string): void;
235
243
  addProperty(name: string, value: string): void;
236
- get systemLandscapeViews(): ReadonlyArray<View<Element$1>>;
237
- get systemContextViews(): ReadonlyArray<View<SoftwareSystem>>;
238
- get containerViews(): ReadonlyArray<View<SoftwareSystem>>;
239
- get componentViews(): ReadonlyArray<View<Container>>;
244
+ get systemLandscapeViews(): ReadonlyArray<ReadonlyView<Element$1>>;
245
+ get systemContextViews(): ReadonlyArray<ReadonlyView<SoftwareSystem>>;
246
+ get containerViews(): ReadonlyArray<ReadonlyView<SoftwareSystem>>;
247
+ get componentViews(): ReadonlyArray<ReadonlyView<Container>>;
240
248
  get elementStyles(): ReadonlyArray<ElementStyleEntry>;
241
249
  get relationshipStyles(): ReadonlyArray<RelationshipStyleEntry>;
242
250
  get themes(): ReadonlyArray<string>;
package/src/index.js CHANGED
@@ -1,49 +1,3 @@
1
- // libs/c4-model/src/archetype.ts
2
- var ElementArchetype = class {
3
- constructor(name, elementKind, definition, parent) {
4
- this.name = name;
5
- this.elementKind = elementKind;
6
- this.parent = parent;
7
- this.ownDescription = definition?.description;
8
- this.ownTechnology = definition?.technology;
9
- this.ownTags = definition?.tags ?? [];
10
- this.description = this.ownDescription ?? parent?.description;
11
- this.technology = this.ownTechnology ?? parent?.technology;
12
- this.tags = [...parent?.tags ?? [], ...this.ownTags];
13
- }
14
- ownDescription;
15
- ownTechnology;
16
- ownTags;
17
- description;
18
- technology;
19
- tags;
20
- };
21
- var RelationshipArchetype = class {
22
- constructor(name, definition, parent) {
23
- this.name = name;
24
- this.parent = parent;
25
- this.ownDescription = definition?.description;
26
- this.ownTechnology = definition?.technology;
27
- this.ownTags = definition?.tags ?? [];
28
- this.description = this.ownDescription ?? parent?.description;
29
- this.technology = this.ownTechnology ?? parent?.technology;
30
- this.tags = [...parent?.tags ?? [], ...this.ownTags];
31
- }
32
- ownDescription;
33
- ownTechnology;
34
- ownTags;
35
- description;
36
- technology;
37
- tags;
38
- };
39
- function mergeArchetypeWithOverride(archetype, override) {
40
- return {
41
- description: override?.description ?? archetype.description,
42
- technology: override?.technology ?? archetype.technology,
43
- tags: [...archetype.tags, ...override?.tags ?? []]
44
- };
45
- }
46
-
47
1
  // node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js
48
2
  var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
49
3
  var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
@@ -130,6 +84,64 @@ function splitPrefixSuffix(input, options = {}) {
130
84
  ];
131
85
  }
132
86
 
87
+ // libs/c4-model/src/archetype.ts
88
+ var ELEMENT_KINDS = {
89
+ person: "person",
90
+ softwareSystem: "softwareSystem",
91
+ container: "container",
92
+ component: "component"
93
+ };
94
+ var ElementArchetype = class {
95
+ constructor(name, elementKind, definition, parent) {
96
+ this.name = name;
97
+ this.elementKind = elementKind;
98
+ this.parent = parent;
99
+ this.ownDescription = definition?.description;
100
+ this.ownTechnology = definition?.technology;
101
+ this.ownTags = definition?.tags ?? [];
102
+ this.description = this.ownDescription ?? parent?.description;
103
+ this.technology = this.ownTechnology ?? parent?.technology;
104
+ this.tags = [...parent?.tags ?? [], ...this.ownTags];
105
+ }
106
+ ownDescription;
107
+ ownTechnology;
108
+ ownTags;
109
+ description;
110
+ technology;
111
+ tags;
112
+ get canonicalName() {
113
+ return camelCase(this.name);
114
+ }
115
+ };
116
+ var RelationshipArchetype = class {
117
+ constructor(name, definition, parent) {
118
+ this.name = name;
119
+ this.parent = parent;
120
+ this.ownDescription = definition?.description;
121
+ this.ownTechnology = definition?.technology;
122
+ this.ownTags = definition?.tags ?? [];
123
+ this.description = this.ownDescription ?? parent?.description;
124
+ this.technology = this.ownTechnology ?? parent?.technology;
125
+ this.tags = [...parent?.tags ?? [], ...this.ownTags];
126
+ }
127
+ ownDescription;
128
+ ownTechnology;
129
+ ownTags;
130
+ description;
131
+ technology;
132
+ tags;
133
+ get canonicalName() {
134
+ return camelCase(this.name);
135
+ }
136
+ };
137
+ function mergeArchetypeWithOverride(archetype, override) {
138
+ return {
139
+ description: override?.description ?? archetype.description,
140
+ technology: override?.technology ?? archetype.technology,
141
+ tags: [...archetype.tags, ...override?.tags ?? []]
142
+ };
143
+ }
144
+
133
145
  // libs/c4-model/src/core.ts
134
146
  var Element = class {
135
147
  constructor(name, defaultTags = [], definition, archetype, overrideDefinition) {
@@ -575,6 +587,10 @@ var View = class {
575
587
  addProperty(name, value) {
576
588
  this._properties.set(name, value);
577
589
  }
590
+ with(callback) {
591
+ callback(this);
592
+ return this;
593
+ }
578
594
  get scopes() {
579
595
  return this._scopes;
580
596
  }
@@ -708,7 +724,7 @@ var StructurizrDSLWriter = class {
708
724
  if (elementArchetypes.length === 0 && relationshipArchetypes.length === 0) return "";
709
725
  let dsl = this.writeLine(`archetypes {`, level);
710
726
  for (const arch of elementArchetypes) {
711
- const baseType = arch.parent ? arch.parent.name : arch.elementKind;
727
+ const baseType = arch.parent ? arch.parent.canonicalName : arch.elementKind;
712
728
  let inner = "";
713
729
  if (arch.ownDescription) {
714
730
  inner += this.writeLine(`description "${arch.ownDescription}"`, level + 2);
@@ -720,15 +736,15 @@ var StructurizrDSLWriter = class {
720
736
  inner += this.writeLine(`tags ${arch.ownTags.map((t) => `"${t}"`).join(" ")}`, level + 2);
721
737
  }
722
738
  if (inner) {
723
- dsl += this.writeLine(`${arch.name} = ${baseType} {`, level + 1);
739
+ dsl += this.writeLine(`${arch.canonicalName} = ${baseType} {`, level + 1);
724
740
  dsl += inner;
725
741
  dsl += this.writeLine(`}`, level + 1);
726
742
  } else {
727
- dsl += this.writeLine(`${arch.name} = ${baseType} {}`, level + 1);
743
+ dsl += this.writeLine(`${arch.canonicalName} = ${baseType} {}`, level + 1);
728
744
  }
729
745
  }
730
746
  for (const arch of relationshipArchetypes) {
731
- const arrow = arch.parent ? `--${arch.parent.name}->` : `->`;
747
+ const arrow = arch.parent ? `--${arch.parent.canonicalName}->` : `->`;
732
748
  let inner = "";
733
749
  if (arch.ownDescription) {
734
750
  inner += this.writeLine(`description "${arch.ownDescription}"`, level + 2);
@@ -740,11 +756,11 @@ var StructurizrDSLWriter = class {
740
756
  inner += this.writeLine(`tags ${arch.ownTags.map((t) => `"${t}"`).join(" ")}`, level + 2);
741
757
  }
742
758
  if (inner) {
743
- dsl += this.writeLine(`${arch.name} = ${arrow} {`, level + 1);
759
+ dsl += this.writeLine(`${arch.canonicalName} = ${arrow} {`, level + 1);
744
760
  dsl += inner;
745
761
  dsl += this.writeLine(`}`, level + 1);
746
762
  } else {
747
- dsl += this.writeLine(`${arch.name} = ${arrow} {}`, level + 1);
763
+ dsl += this.writeLine(`${arch.canonicalName} = ${arrow} {}`, level + 1);
748
764
  }
749
765
  }
750
766
  dsl += this.writeLine(`}`, level);
@@ -752,7 +768,7 @@ var StructurizrDSLWriter = class {
752
768
  }
753
769
  writeElement(elementType, element, level, closeElement = true) {
754
770
  let elementDsl = "";
755
- const type = element.archetype ? element.archetype.name : elementType;
771
+ const type = element.archetype ? element.archetype.canonicalName : elementType;
756
772
  elementDsl += this.writeLine(`${element.canonicalName} = ${type} "${element.name}" {`, level);
757
773
  if (element.archetype) {
758
774
  const ovr = element.overrideDefinition;
@@ -845,7 +861,7 @@ var StructurizrDSLWriter = class {
845
861
  writeRelationship(relationship, level) {
846
862
  let dsl = "";
847
863
  if (relationship.archetype) {
848
- const arrow = `--${relationship.archetype.name}->`;
864
+ const arrow = `--${relationship.archetype.canonicalName}->`;
849
865
  const ovr = relationship.overrideDefinition;
850
866
  const desc = ovr?.description ?? relationship.description ?? "uses";
851
867
  dsl += this.writeLine(
@@ -942,7 +958,9 @@ var StructurizrDSLWriter = class {
942
958
  }
943
959
  writeView(view, viewType, level) {
944
960
  let viewDsl = this.writeLine(`${viewType}${view.subject ? ' "' + view.subject.canonicalName + '"' : ""} "${view.key}" {`, level);
945
- viewDsl += this.writeLine(`description "${view.description}"`, level + 1);
961
+ if (view.description) {
962
+ viewDsl += this.writeLine(`description "${view.description}"`, level + 1);
963
+ }
946
964
  if (view.title) {
947
965
  viewDsl += this.writeLine(`title "${view.title}"`, level + 1);
948
966
  }
@@ -1185,6 +1203,7 @@ export {
1185
1203
  Component,
1186
1204
  Container,
1187
1205
  ContainerGroup,
1206
+ ELEMENT_KINDS,
1188
1207
  ElementArchetype,
1189
1208
  Model,
1190
1209
  ModelGroup,
@@ -1193,7 +1212,6 @@ export {
1193
1212
  SoftwareSystem,
1194
1213
  SoftwareSystemGroup,
1195
1214
  StructurizrDSLWriter,
1196
- View,
1197
1215
  Views,
1198
1216
  buildModel,
1199
1217
  exportWorkspaceJson,
package/src/views.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { Container } from './container';
2
2
  import { Element } from './core';
3
3
  import { SoftwareSystem } from './softwareSystem';
4
- interface ViewDefinition<T extends Element> {
5
- subject?: T;
6
- description: string;
4
+ interface BaseViewDefinition {
5
+ description?: string;
7
6
  title?: string;
8
7
  }
8
+ interface ScopedViewDefinition<T extends Element> extends BaseViewDefinition {
9
+ subject: T;
10
+ }
9
11
  export type AutoLayoutDirection = 'tb' | 'bt' | 'lr' | 'rl';
10
12
  export interface AutoLayout {
11
13
  direction?: AutoLayoutDirection;
@@ -46,16 +48,7 @@ export interface RelationshipStyleEntry {
46
48
  tag: string;
47
49
  definition: RelationshipStyleDefinition;
48
50
  }
49
- export declare class View<T extends Element> {
50
- readonly key: string;
51
- readonly subject?: T;
52
- readonly description: string;
53
- readonly title?: string;
54
- private _scopes;
55
- private _autoLayout?;
56
- private _isDefault;
57
- private _properties;
58
- constructor(key: string, viewDefinition: ViewDefinition<T>);
51
+ export interface ViewBuilder {
59
52
  includeAll(): void;
60
53
  includeElement(element: Element): void;
61
54
  includeExpression(expression: string): void;
@@ -65,10 +58,17 @@ export declare class View<T extends Element> {
65
58
  autoLayout(direction?: AutoLayoutDirection, rankSeparation?: number, nodeSeparation?: number): void;
66
59
  setDefault(): void;
67
60
  addProperty(name: string, value: string): void;
68
- get scopes(): ReadonlyArray<string>;
69
- get autoLayoutConfig(): AutoLayout | undefined;
70
- get isDefault(): boolean;
71
- get properties(): ReadonlyMap<string, string>;
61
+ }
62
+ export interface ReadonlyView<T extends Element> {
63
+ readonly key: string;
64
+ readonly subject?: T;
65
+ readonly description?: string;
66
+ readonly title?: string;
67
+ readonly scopes: ReadonlyArray<string>;
68
+ readonly autoLayoutConfig: AutoLayout | undefined;
69
+ readonly isDefault: boolean;
70
+ readonly properties: ReadonlyMap<string, string>;
71
+ with(callback: (builder: ViewBuilder) => void): ReadonlyView<T>;
72
72
  }
73
73
  export declare class Views {
74
74
  private readonly _systemLandscapeViews;
@@ -79,18 +79,18 @@ export declare class Views {
79
79
  private _relationshipStyles;
80
80
  private _themes;
81
81
  private _properties;
82
- addSystemLandscapeView(key: string, definition: ViewDefinition<Element>): View<Element>;
83
- addSystemContextView(key: string, definition: ViewDefinition<SoftwareSystem>): View<SoftwareSystem>;
84
- addContainerView(key: string, definition: ViewDefinition<SoftwareSystem>): View<SoftwareSystem>;
85
- addComponentView(key: string, definition: ViewDefinition<Container>): View<Container>;
82
+ addSystemLandscapeView(key: string, definition: BaseViewDefinition): ReadonlyView<Element>;
83
+ addSystemContextView(key: string, definition: ScopedViewDefinition<SoftwareSystem>): ReadonlyView<SoftwareSystem>;
84
+ addContainerView(key: string, definition: ScopedViewDefinition<SoftwareSystem>): ReadonlyView<SoftwareSystem>;
85
+ addComponentView(key: string, definition: ScopedViewDefinition<Container>): ReadonlyView<Container>;
86
86
  addElementStyle(tag: string, definition: ElementStyleDefinition): void;
87
87
  addRelationshipStyle(tag: string, definition: RelationshipStyleDefinition): void;
88
88
  addTheme(url: string): void;
89
89
  addProperty(name: string, value: string): void;
90
- get systemLandscapeViews(): ReadonlyArray<View<Element>>;
91
- get systemContextViews(): ReadonlyArray<View<SoftwareSystem>>;
92
- get containerViews(): ReadonlyArray<View<SoftwareSystem>>;
93
- get componentViews(): ReadonlyArray<View<Container>>;
90
+ get systemLandscapeViews(): ReadonlyArray<ReadonlyView<Element>>;
91
+ get systemContextViews(): ReadonlyArray<ReadonlyView<SoftwareSystem>>;
92
+ get containerViews(): ReadonlyArray<ReadonlyView<SoftwareSystem>>;
93
+ get componentViews(): ReadonlyArray<ReadonlyView<Container>>;
94
94
  get elementStyles(): ReadonlyArray<ElementStyleEntry>;
95
95
  get relationshipStyles(): ReadonlyArray<RelationshipStyleEntry>;
96
96
  get themes(): ReadonlyArray<string>;