@agilewallaby/c4-model 2.6.0 → 2.8.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/src/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export interface Definition {
7
7
  export interface TechnologyDefinition extends Definition {
8
8
  technology?: string;
9
9
  }
10
- declare abstract class Element$1 {
10
+ declare abstract class Element$1<TChild extends Element$1 = never> {
11
11
  readonly name: string;
12
12
  readonly description?: string;
13
13
  readonly tags: ReadonlyArray<string>;
@@ -18,11 +18,12 @@ declare abstract class Element$1 {
18
18
  get canonicalName(): string;
19
19
  uses(otherElement: Element$1, archetypeOrDef?: RelationshipArchetype | TechnologyDefinition, override?: TechnologyDefinition): void;
20
20
  get relationships(): ReadonlyArray<Relationship>;
21
+ with<TChildren extends Record<string, TChild>>(callback: (self: this) => TChildren): this & TChildren;
21
22
  abstract getChildElements(): ReadonlyArray<Element$1>;
22
23
  getRelationshipsInHierarchy(): ReadonlyArray<Relationship>;
23
24
  getChildElementNames(path?: string): ReadonlyArray<string>;
24
25
  }
25
- declare abstract class TechnicalElement extends Element$1 {
26
+ declare abstract class TechnicalElement<TChild extends Element$1 = never> extends Element$1<TChild> {
26
27
  readonly technology?: string;
27
28
  constructor(name: string, defaultTags?: string[], definition?: TechnologyDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
28
29
  }
@@ -36,9 +37,11 @@ declare class Relationship {
36
37
  readonly overrideDefinition?: TechnologyDefinition;
37
38
  constructor(source: Element$1, destination: Element$1, definition?: TechnologyDefinition, archetype?: RelationshipArchetype, overrideDefinition?: TechnologyDefinition);
38
39
  }
39
- declare class Group {
40
+ declare class Group<TChild extends Element$1 | Group = never> {
40
41
  readonly name: string;
41
42
  constructor(name: string);
43
+ get canonicalName(): string;
44
+ with<TChildren extends Record<string, TChild>>(callback: (self: this) => TChildren): this & TChildren;
42
45
  }
43
46
  export type ElementKind = "person" | "softwareSystem" | "container" | "component";
44
47
  export declare class ElementArchetype {
@@ -79,21 +82,28 @@ export type ContainerDefinition = TechnologyDefinition;
79
82
  export interface DefineComponent {
80
83
  component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
81
84
  }
82
- export declare class ContainerGroup extends Group implements DefineComponent {
85
+ export declare class ContainerGroup extends Group<Component> implements DefineComponent {
83
86
  readonly name: string;
84
87
  private readonly container;
88
+ private readonly pathSegments;
85
89
  private _components;
86
- constructor(name: string, container: DefineComponent);
90
+ private _groups;
91
+ constructor(name: string, container: DefineComponent, pathSegments?: string[]);
92
+ get canonicalName(): string;
93
+ get dslName(): string;
87
94
  component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
95
+ group(groupName: string): ContainerGroup;
96
+ getGroups(): ReadonlyArray<ContainerGroup>;
88
97
  getComponents(): ReadonlyArray<Component>;
98
+ getAllComponents(): ReadonlyArray<Component>;
89
99
  }
90
- export declare class Container extends TechnicalElement implements DefineComponent {
100
+ export declare class Container extends TechnicalElement<Component> implements DefineComponent {
91
101
  readonly name: string;
92
102
  private _components;
93
103
  private _groups;
94
104
  constructor(name: string, definition?: ContainerDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
95
105
  component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
96
- addGroup(groupName: string): ContainerGroup;
106
+ group(groupName: string): ContainerGroup;
97
107
  getGroups(): ReadonlyArray<ContainerGroup>;
98
108
  getComponentsNotInGroups(): ReadonlyArray<Component>;
99
109
  getChildElements(): ReadonlyArray<Element$1>;
@@ -105,21 +115,28 @@ export interface DefineContainer {
105
115
  export interface SoftwareSystemReference {
106
116
  name: string;
107
117
  }
108
- export declare class SoftwareSystemGroup extends Group implements DefineContainer {
118
+ export declare class SoftwareSystemGroup extends Group<Container> implements DefineContainer {
109
119
  readonly name: string;
110
120
  private readonly softwareSystem;
121
+ private readonly pathSegments;
111
122
  private _containers;
112
- constructor(name: string, softwareSystem: DefineContainer);
123
+ private _groups;
124
+ constructor(name: string, softwareSystem: DefineContainer, pathSegments?: string[]);
125
+ get canonicalName(): string;
126
+ get dslName(): string;
113
127
  container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
128
+ group(groupName: string): SoftwareSystemGroup;
129
+ getGroups(): ReadonlyArray<SoftwareSystemGroup>;
114
130
  getContainers(): ReadonlyArray<Container>;
131
+ getAllContainers(): ReadonlyArray<Container>;
115
132
  }
116
- export declare class SoftwareSystem extends Element$1 implements DefineContainer {
133
+ export declare class SoftwareSystem extends Element$1<Container> implements DefineContainer {
117
134
  readonly name: string;
118
135
  private _containers;
119
136
  private _groups;
120
137
  constructor(name: string, definition?: SoftwareSystemDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
121
138
  container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
122
- addGroup(groupName: string): SoftwareSystemGroup;
139
+ group(groupName: string): SoftwareSystemGroup;
123
140
  getGroups(): ReadonlyArray<SoftwareSystemGroup>;
124
141
  getChildElements(): ReadonlyArray<Element$1>;
125
142
  getContainersNotInGroups(): ReadonlyArray<Container>;
@@ -130,6 +147,101 @@ export declare class Person extends Element$1 {
130
147
  constructor(name: string, definition?: PersonDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
131
148
  getChildElements(): ReadonlyArray<Element$1>;
132
149
  }
150
+ export interface ViewDefinition<T extends Element$1> {
151
+ subject?: T;
152
+ description: string;
153
+ title?: string;
154
+ }
155
+ export type AutoLayoutDirection = "tb" | "bt" | "lr" | "rl";
156
+ export interface AutoLayout {
157
+ direction?: AutoLayoutDirection;
158
+ rankSeparation?: number;
159
+ nodeSeparation?: number;
160
+ }
161
+ export type ElementShape = "Box" | "RoundedBox" | "Circle" | "Ellipse" | "Hexagon" | "Diamond" | "Cylinder" | "Bucket" | "Pipe" | "Person" | "Robot" | "Folder" | "WebBrowser" | "Window" | "Terminal" | "Shell" | "MobileDevicePortrait" | "MobileDeviceLandscape" | "Component";
162
+ export interface ElementStyleDefinition {
163
+ shape?: ElementShape;
164
+ icon?: string;
165
+ width?: number;
166
+ height?: number;
167
+ background?: string;
168
+ color?: string;
169
+ stroke?: string;
170
+ strokeWidth?: number;
171
+ fontSize?: number;
172
+ border?: "solid" | "dashed" | "dotted";
173
+ opacity?: number;
174
+ metadata?: boolean;
175
+ description?: boolean;
176
+ }
177
+ export interface RelationshipStyleDefinition {
178
+ thickness?: number;
179
+ color?: string;
180
+ style?: "solid" | "dashed" | "dotted";
181
+ routing?: "Direct" | "Orthogonal" | "Curved";
182
+ fontSize?: number;
183
+ width?: number;
184
+ position?: number;
185
+ opacity?: number;
186
+ }
187
+ export interface ElementStyleEntry {
188
+ tag: string;
189
+ definition: ElementStyleDefinition;
190
+ }
191
+ export interface RelationshipStyleEntry {
192
+ tag: string;
193
+ definition: RelationshipStyleDefinition;
194
+ }
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
+ includeAll(): void;
206
+ includeElement(element: Element$1): void;
207
+ includeExpression(expression: string): void;
208
+ excludeAll(): void;
209
+ excludeElement(element: Element$1): void;
210
+ excludeExpression(expression: string): void;
211
+ autoLayout(direction?: AutoLayoutDirection, rankSeparation?: number, nodeSeparation?: number): void;
212
+ setDefault(): void;
213
+ 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>;
218
+ }
219
+ export declare class Views {
220
+ private readonly _systemLandscapeViews;
221
+ private readonly _systemContextViews;
222
+ private readonly _containerViews;
223
+ private readonly _componentViews;
224
+ private _elementStyles;
225
+ private _relationshipStyles;
226
+ private _themes;
227
+ 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>;
232
+ addElementStyle(tag: string, definition: ElementStyleDefinition): void;
233
+ addRelationshipStyle(tag: string, definition: RelationshipStyleDefinition): void;
234
+ addTheme(url: string): void;
235
+ 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>>;
240
+ get elementStyles(): ReadonlyArray<ElementStyleEntry>;
241
+ get relationshipStyles(): ReadonlyArray<RelationshipStyleEntry>;
242
+ get themes(): ReadonlyArray<string>;
243
+ get properties(): ReadonlyMap<string, string>;
244
+ }
133
245
  export type CatalogKeyOf<TRoot, TModule> = {
134
246
  [K in keyof TRoot]: TRoot[K] extends TModule ? K : never;
135
247
  }[keyof TRoot];
@@ -137,7 +249,8 @@ export type Dependencies<TRoot, TModule> = Omit<TRoot, CatalogKeyOf<TRoot, TModu
137
249
  export interface C4Module<TRoot, TLocal, TArchetypes = Record<string, ElementArchetype | RelationshipArchetype>> {
138
250
  readonly key: CatalogKeyOf<TRoot, TLocal>;
139
251
  registerDefinitions(model: Model, archetypes: TArchetypes): TLocal;
140
- buildRelationships(local: TLocal, dependencies: Dependencies<TRoot, TLocal>, archetypes: TArchetypes): void;
252
+ addRelationships(local: TLocal, dependencies: Dependencies<TRoot, TLocal>, archetypes: TArchetypes): void;
253
+ addViews?(views: Views, local: TLocal, dependencies: Dependencies<TRoot, TLocal>): void;
141
254
  }
142
255
  export interface DefineSoftwareSystem {
143
256
  softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
@@ -145,16 +258,24 @@ export interface DefineSoftwareSystem {
145
258
  export interface DefinePerson {
146
259
  person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
147
260
  }
148
- export declare class ModelGroup extends Group implements DefineSoftwareSystem, DefinePerson {
261
+ export declare class ModelGroup extends Group<Person | SoftwareSystem> implements DefineSoftwareSystem, DefinePerson {
149
262
  readonly name: string;
150
263
  private readonly model;
264
+ private readonly pathSegments;
151
265
  private softwareSystems;
152
266
  private people;
153
- constructor(name: string, model: DefineSoftwareSystem & DefinePerson);
267
+ private _groups;
268
+ constructor(name: string, model: DefineSoftwareSystem & DefinePerson, pathSegments?: string[]);
269
+ get canonicalName(): string;
270
+ get dslName(): string;
154
271
  softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
155
272
  person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
273
+ group(groupName: string): ModelGroup;
274
+ getGroups(): ReadonlyArray<ModelGroup>;
156
275
  getSoftwareSystems(): ReadonlyArray<SoftwareSystem>;
157
276
  getPeople(): ReadonlyArray<Person>;
277
+ getAllSoftwareSystems(): ReadonlyArray<SoftwareSystem>;
278
+ getAllPeople(): ReadonlyArray<Person>;
158
279
  }
159
280
  export interface ModelDefinitions {
160
281
  softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
@@ -167,7 +288,7 @@ export declare class Model {
167
288
  private people;
168
289
  private groups;
169
290
  softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
170
- addGroup(groupName: string): Group & ModelDefinitions;
291
+ group(groupName: string): ModelGroup;
171
292
  person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
172
293
  validate(): void;
173
294
  getPeople(): ReadonlyArray<Person>;
@@ -176,40 +297,6 @@ export declare class Model {
176
297
  getSoftwareSystemsNotInGroups(): ReadonlyArray<SoftwareSystem>;
177
298
  getGroups(): ReadonlyArray<ModelGroup>;
178
299
  }
179
- export interface ViewDefinition<T extends Element$1> {
180
- subject?: T;
181
- description: string;
182
- title?: string;
183
- }
184
- export declare class View<T extends Element$1> {
185
- readonly key: string;
186
- readonly subject?: T;
187
- readonly description: string;
188
- readonly title?: string;
189
- private _scopes;
190
- constructor(key: string, viewDefinition: ViewDefinition<T>);
191
- includeAll(): void;
192
- includeElement(element: T): void;
193
- includeExpression(expression: string): void;
194
- excludeAll(): void;
195
- excludeElement(element: T): void;
196
- excludeExpression(expression: string): void;
197
- get scopes(): ReadonlyArray<string>;
198
- }
199
- export declare class Views {
200
- private readonly _systemLandscapeViews;
201
- private readonly _systemContextViews;
202
- private readonly _containerViews;
203
- private readonly _componentViews;
204
- addSystemLandscapeView(key: string, definition: ViewDefinition<Element$1>): View<Element$1>;
205
- addSystemContextView(key: string, definition: ViewDefinition<SoftwareSystem>): View<SoftwareSystem>;
206
- addContainerView(key: string, definition: ViewDefinition<SoftwareSystem>): View<SoftwareSystem>;
207
- addComponentView(key: string, definition: ViewDefinition<Container>): View<Container>;
208
- get systemLandscapeViews(): ReadonlyArray<View<Element$1>>;
209
- get systemContextViews(): ReadonlyArray<View<SoftwareSystem>>;
210
- get containerViews(): ReadonlyArray<View<SoftwareSystem>>;
211
- get componentViews(): ReadonlyArray<View<Container>>;
212
- }
213
300
  export declare class StructurizrDSLWriter {
214
301
  private readonly model;
215
302
  private readonly views;
@@ -224,9 +311,14 @@ export declare class StructurizrDSLWriter {
224
311
  private writeSoftwareSystem;
225
312
  private writeRelationship;
226
313
  private writeRelationships;
314
+ private hasNestedModelGroups;
315
+ private hasNestedSoftwareSystemGroups;
316
+ private hasNestedContainerGroups;
317
+ private hasNestedGroups;
227
318
  private writeModelGroup;
228
319
  private writeModel;
229
320
  private writeView;
321
+ private writeStyles;
230
322
  private writeViews;
231
323
  write(): string;
232
324
  private writeLine;
@@ -236,24 +328,28 @@ export type RootCatalog = Record<string, Catalog>;
236
328
  export interface AnyC4Module {
237
329
  readonly key: string;
238
330
  registerDefinitions(model: Model, archetypes: Record<string, ElementArchetype | RelationshipArchetype>): Catalog;
239
- buildRelationships(local: Catalog, dependencies: RootCatalog, archetypes: Record<string, ElementArchetype | RelationshipArchetype>): void;
331
+ addRelationships(local: Catalog, dependencies: RootCatalog, archetypes: Record<string, ElementArchetype | RelationshipArchetype>): void;
332
+ addViews?(views: Views, local: Catalog, dependencies: RootCatalog): void;
240
333
  }
241
- export interface BuildModelOptions {
334
+ export interface BuildModelOptions<TRoot = Record<string, unknown>> {
242
335
  modelName?: string;
243
336
  modules?: ReadonlyArray<AnyC4Module>;
244
337
  globPath?: string;
245
338
  searchRoot?: string;
246
339
  archetypes?: Record<string, ElementArchetype | RelationshipArchetype>;
340
+ addViews?: (views: Views, catalog: TRoot) => void;
247
341
  }
248
- export declare function buildModelWithCatalog<TRoot>(options?: BuildModelOptions): Promise<{
342
+ export declare function buildModel<TRoot>(options?: BuildModelOptions<TRoot>): Promise<{
249
343
  model: Model;
250
344
  catalog: TRoot;
345
+ views: Views;
251
346
  }>;
252
- export declare function buildModel(options?: BuildModelOptions): Promise<Model>;
253
- export interface GenerateDiagramsOptions<TRoot> extends BuildModelOptions {
254
- views: (catalog: TRoot) => Views;
347
+ export interface GenerateDiagramsOptions<TRoot> extends BuildModelOptions<TRoot> {
255
348
  outputDir: string;
256
349
  }
257
350
  export declare function generateDiagrams<TRoot>(options: GenerateDiagramsOptions<TRoot>): Promise<string[]>;
351
+ export declare function validateModel(model: Model, views: Views): Promise<void>;
352
+ export declare function exportWorkspaceJsonFromDsl(dsl: string): Promise<unknown>;
353
+ export declare function exportWorkspaceJson(model: Model, views: Views): Promise<unknown>;
258
354
 
259
355
  export {};