@agilewallaby/c4-model 2.6.0 → 2.7.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.6.0",
3
+ "version": "2.7.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -5,7 +5,7 @@ export type ContainerDefinition = TechnologyDefinition;
5
5
  interface DefineComponent {
6
6
  component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
7
7
  }
8
- export declare class ContainerGroup extends Group implements DefineComponent {
8
+ export declare class ContainerGroup extends Group<Component> implements DefineComponent {
9
9
  readonly name: string;
10
10
  private readonly container;
11
11
  private _components;
@@ -13,13 +13,13 @@ export declare class ContainerGroup extends Group implements DefineComponent {
13
13
  component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
14
14
  getComponents(): ReadonlyArray<Component>;
15
15
  }
16
- export declare class Container extends TechnicalElement implements DefineComponent {
16
+ export declare class Container extends TechnicalElement<Component> implements DefineComponent {
17
17
  readonly name: string;
18
18
  private _components;
19
19
  private _groups;
20
20
  constructor(name: string, definition?: ContainerDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
21
21
  component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
22
- addGroup(groupName: string): ContainerGroup;
22
+ group(groupName: string): ContainerGroup;
23
23
  getGroups(): ReadonlyArray<ContainerGroup>;
24
24
  getComponentsNotInGroups(): ReadonlyArray<Component>;
25
25
  getChildElements(): ReadonlyArray<Element>;
package/src/core.d.ts CHANGED
@@ -6,7 +6,7 @@ export interface Definition {
6
6
  export interface TechnologyDefinition extends Definition {
7
7
  technology?: string;
8
8
  }
9
- export declare abstract class Element {
9
+ export declare abstract class Element<TChild extends Element = never> {
10
10
  readonly name: string;
11
11
  readonly description?: string;
12
12
  readonly tags: ReadonlyArray<string>;
@@ -17,11 +17,12 @@ export declare abstract class Element {
17
17
  get canonicalName(): string;
18
18
  uses(otherElement: Element, archetypeOrDef?: RelationshipArchetype | TechnologyDefinition, override?: TechnologyDefinition): void;
19
19
  get relationships(): ReadonlyArray<Relationship>;
20
+ with<TChildren extends Record<string, TChild>>(callback: (self: this) => TChildren): this & TChildren;
20
21
  abstract getChildElements(): ReadonlyArray<Element>;
21
22
  getRelationshipsInHierarchy(): ReadonlyArray<Relationship>;
22
23
  getChildElementNames(path?: string): ReadonlyArray<string>;
23
24
  }
24
- export declare abstract class TechnicalElement extends Element {
25
+ export declare abstract class TechnicalElement<TChild extends Element = never> extends Element<TChild> {
25
26
  readonly technology?: string;
26
27
  constructor(name: string, defaultTags?: string[], definition?: TechnologyDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
27
28
  }
@@ -35,7 +36,9 @@ export declare class Relationship {
35
36
  readonly overrideDefinition?: TechnologyDefinition;
36
37
  constructor(source: Element, destination: Element, definition?: TechnologyDefinition, archetype?: RelationshipArchetype, overrideDefinition?: TechnologyDefinition);
37
38
  }
38
- export declare class Group {
39
+ export declare class Group<TChild extends Element | Group = never> {
39
40
  readonly name: string;
40
41
  constructor(name: string);
42
+ get canonicalName(): string;
43
+ with<TChildren extends Record<string, TChild>>(callback: (self: this) => TChildren): this & TChildren;
41
44
  }
package/src/index.cjs CHANGED
@@ -214,6 +214,10 @@ var Element = class {
214
214
  get relationships() {
215
215
  return this._relationships;
216
216
  }
217
+ with(callback) {
218
+ const children = callback(this);
219
+ return Object.assign(this, children);
220
+ }
217
221
  getRelationshipsInHierarchy() {
218
222
  return this._relationships.concat(this.getChildElements().flatMap((element) => element.getRelationshipsInHierarchy()));
219
223
  }
@@ -252,6 +256,13 @@ var Group = class {
252
256
  constructor(name) {
253
257
  this.name = name;
254
258
  }
259
+ get canonicalName() {
260
+ return camelCase(this.name);
261
+ }
262
+ with(callback) {
263
+ const children = callback(this);
264
+ return Object.assign(this, children);
265
+ }
255
266
  // TODO: Implement this in some useful way?
256
267
  // public addToGroup(groupCollection: string, groupMember: T) {}
257
268
  };
@@ -307,7 +318,7 @@ var Container = class extends TechnicalElement {
307
318
  this._components.set(name, component);
308
319
  return component;
309
320
  }
310
- addGroup(groupName) {
321
+ group(groupName) {
311
322
  let group = this._groups.get(groupName);
312
323
  if (!group) {
313
324
  group = new ContainerGroup(groupName, this);
@@ -367,7 +378,7 @@ var SoftwareSystem = class extends Element {
367
378
  this._containers.set(name, container);
368
379
  return container;
369
380
  }
370
- addGroup(groupName) {
381
+ group(groupName) {
371
382
  let group = this._groups.get(groupName);
372
383
  if (!group) {
373
384
  group = new SoftwareSystemGroup(groupName, this);
@@ -448,7 +459,7 @@ var Model = class {
448
459
  return system;
449
460
  }
450
461
  // TODO:Should be a Group<SoftwareSystem | Person> if that is added back in
451
- addGroup(groupName) {
462
+ group(groupName) {
452
463
  let group = this.groups.get(groupName);
453
464
  if (!group) {
454
465
  group = new ModelGroup(groupName, this);
@@ -472,6 +483,7 @@ var Model = class {
472
483
  this.people.set(name, person);
473
484
  return person;
474
485
  }
486
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
475
487
  validate() {
476
488
  }
477
489
  getPeople() {
@@ -698,7 +710,7 @@ var StructurizrDSLWriter = class {
698
710
  }
699
711
  writeContainerGroup(group, level) {
700
712
  let containerGroupDsl = "";
701
- containerGroupDsl += this.writeLine(`${group.name} = group "${group.name}" {`, level);
713
+ containerGroupDsl += this.writeLine(`${group.canonicalName} = group "${group.name}" {`, level);
702
714
  group.getComponents().forEach((component) => {
703
715
  containerGroupDsl += this.writeComponent(component, level + 1);
704
716
  });
@@ -722,7 +734,7 @@ var StructurizrDSLWriter = class {
722
734
  }
723
735
  writeSoftwareSystemGroup(group, level) {
724
736
  let softwareSystemGroupDsl = "";
725
- softwareSystemGroupDsl += this.writeLine(`${group.name} = group "${group.name}" {`, level);
737
+ softwareSystemGroupDsl += this.writeLine(`${group.canonicalName} = group "${group.name}" {`, level);
726
738
  group.getContainers().forEach((container) => {
727
739
  softwareSystemGroupDsl += this.writeContainer(container, level + 1);
728
740
  });
@@ -780,7 +792,7 @@ var StructurizrDSLWriter = class {
780
792
  }
781
793
  writeModelGroup(group, level) {
782
794
  let modelGroupDsl = "";
783
- modelGroupDsl += this.writeLine(`${group.name} = group "${group.name}" {`, level);
795
+ modelGroupDsl += this.writeLine(`${group.canonicalName} = group "${group.name}" {`, level);
784
796
  group.getPeople().forEach((person) => {
785
797
  modelGroupDsl += this.writeElement("person", person, level + 1);
786
798
  });
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,7 +82,7 @@ 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;
85
88
  private _components;
@@ -87,13 +90,13 @@ export declare class ContainerGroup extends Group implements DefineComponent {
87
90
  component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
88
91
  getComponents(): ReadonlyArray<Component>;
89
92
  }
90
- export declare class Container extends TechnicalElement implements DefineComponent {
93
+ export declare class Container extends TechnicalElement<Component> implements DefineComponent {
91
94
  readonly name: string;
92
95
  private _components;
93
96
  private _groups;
94
97
  constructor(name: string, definition?: ContainerDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
95
98
  component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
96
- addGroup(groupName: string): ContainerGroup;
99
+ group(groupName: string): ContainerGroup;
97
100
  getGroups(): ReadonlyArray<ContainerGroup>;
98
101
  getComponentsNotInGroups(): ReadonlyArray<Component>;
99
102
  getChildElements(): ReadonlyArray<Element$1>;
@@ -105,7 +108,7 @@ export interface DefineContainer {
105
108
  export interface SoftwareSystemReference {
106
109
  name: string;
107
110
  }
108
- export declare class SoftwareSystemGroup extends Group implements DefineContainer {
111
+ export declare class SoftwareSystemGroup extends Group<Container> implements DefineContainer {
109
112
  readonly name: string;
110
113
  private readonly softwareSystem;
111
114
  private _containers;
@@ -113,13 +116,13 @@ export declare class SoftwareSystemGroup extends Group implements DefineContaine
113
116
  container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
114
117
  getContainers(): ReadonlyArray<Container>;
115
118
  }
116
- export declare class SoftwareSystem extends Element$1 implements DefineContainer {
119
+ export declare class SoftwareSystem extends Element$1<Container> implements DefineContainer {
117
120
  readonly name: string;
118
121
  private _containers;
119
122
  private _groups;
120
123
  constructor(name: string, definition?: SoftwareSystemDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
121
124
  container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
122
- addGroup(groupName: string): SoftwareSystemGroup;
125
+ group(groupName: string): SoftwareSystemGroup;
123
126
  getGroups(): ReadonlyArray<SoftwareSystemGroup>;
124
127
  getChildElements(): ReadonlyArray<Element$1>;
125
128
  getContainersNotInGroups(): ReadonlyArray<Container>;
@@ -145,7 +148,7 @@ export interface DefineSoftwareSystem {
145
148
  export interface DefinePerson {
146
149
  person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
147
150
  }
148
- export declare class ModelGroup extends Group implements DefineSoftwareSystem, DefinePerson {
151
+ export declare class ModelGroup extends Group<Person | SoftwareSystem> implements DefineSoftwareSystem, DefinePerson {
149
152
  readonly name: string;
150
153
  private readonly model;
151
154
  private softwareSystems;
@@ -167,7 +170,7 @@ export declare class Model {
167
170
  private people;
168
171
  private groups;
169
172
  softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
170
- addGroup(groupName: string): Group & ModelDefinitions;
173
+ group(groupName: string): Group & ModelDefinitions;
171
174
  person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
172
175
  validate(): void;
173
176
  getPeople(): ReadonlyArray<Person>;
package/src/index.js CHANGED
@@ -162,6 +162,10 @@ var Element = class {
162
162
  get relationships() {
163
163
  return this._relationships;
164
164
  }
165
+ with(callback) {
166
+ const children = callback(this);
167
+ return Object.assign(this, children);
168
+ }
165
169
  getRelationshipsInHierarchy() {
166
170
  return this._relationships.concat(this.getChildElements().flatMap((element) => element.getRelationshipsInHierarchy()));
167
171
  }
@@ -200,6 +204,13 @@ var Group = class {
200
204
  constructor(name) {
201
205
  this.name = name;
202
206
  }
207
+ get canonicalName() {
208
+ return camelCase(this.name);
209
+ }
210
+ with(callback) {
211
+ const children = callback(this);
212
+ return Object.assign(this, children);
213
+ }
203
214
  // TODO: Implement this in some useful way?
204
215
  // public addToGroup(groupCollection: string, groupMember: T) {}
205
216
  };
@@ -255,7 +266,7 @@ var Container = class extends TechnicalElement {
255
266
  this._components.set(name, component);
256
267
  return component;
257
268
  }
258
- addGroup(groupName) {
269
+ group(groupName) {
259
270
  let group = this._groups.get(groupName);
260
271
  if (!group) {
261
272
  group = new ContainerGroup(groupName, this);
@@ -315,7 +326,7 @@ var SoftwareSystem = class extends Element {
315
326
  this._containers.set(name, container);
316
327
  return container;
317
328
  }
318
- addGroup(groupName) {
329
+ group(groupName) {
319
330
  let group = this._groups.get(groupName);
320
331
  if (!group) {
321
332
  group = new SoftwareSystemGroup(groupName, this);
@@ -396,7 +407,7 @@ var Model = class {
396
407
  return system;
397
408
  }
398
409
  // TODO:Should be a Group<SoftwareSystem | Person> if that is added back in
399
- addGroup(groupName) {
410
+ group(groupName) {
400
411
  let group = this.groups.get(groupName);
401
412
  if (!group) {
402
413
  group = new ModelGroup(groupName, this);
@@ -420,6 +431,7 @@ var Model = class {
420
431
  this.people.set(name, person);
421
432
  return person;
422
433
  }
434
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
423
435
  validate() {
424
436
  }
425
437
  getPeople() {
@@ -646,7 +658,7 @@ var StructurizrDSLWriter = class {
646
658
  }
647
659
  writeContainerGroup(group, level) {
648
660
  let containerGroupDsl = "";
649
- containerGroupDsl += this.writeLine(`${group.name} = group "${group.name}" {`, level);
661
+ containerGroupDsl += this.writeLine(`${group.canonicalName} = group "${group.name}" {`, level);
650
662
  group.getComponents().forEach((component) => {
651
663
  containerGroupDsl += this.writeComponent(component, level + 1);
652
664
  });
@@ -670,7 +682,7 @@ var StructurizrDSLWriter = class {
670
682
  }
671
683
  writeSoftwareSystemGroup(group, level) {
672
684
  let softwareSystemGroupDsl = "";
673
- softwareSystemGroupDsl += this.writeLine(`${group.name} = group "${group.name}" {`, level);
685
+ softwareSystemGroupDsl += this.writeLine(`${group.canonicalName} = group "${group.name}" {`, level);
674
686
  group.getContainers().forEach((container) => {
675
687
  softwareSystemGroupDsl += this.writeContainer(container, level + 1);
676
688
  });
@@ -728,7 +740,7 @@ var StructurizrDSLWriter = class {
728
740
  }
729
741
  writeModelGroup(group, level) {
730
742
  let modelGroupDsl = "";
731
- modelGroupDsl += this.writeLine(`${group.name} = group "${group.name}" {`, level);
743
+ modelGroupDsl += this.writeLine(`${group.canonicalName} = group "${group.name}" {`, level);
732
744
  group.getPeople().forEach((person) => {
733
745
  modelGroupDsl += this.writeElement("person", person, level + 1);
734
746
  });
package/src/model.d.ts CHANGED
@@ -17,7 +17,7 @@ interface DefineSoftwareSystem {
17
17
  interface DefinePerson {
18
18
  person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
19
19
  }
20
- export declare class ModelGroup extends Group implements DefineSoftwareSystem, DefinePerson {
20
+ export declare class ModelGroup extends Group<Person | SoftwareSystem> implements DefineSoftwareSystem, DefinePerson {
21
21
  readonly name: string;
22
22
  private readonly model;
23
23
  private softwareSystems;
@@ -39,7 +39,7 @@ export declare class Model {
39
39
  private people;
40
40
  private groups;
41
41
  softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
42
- addGroup(groupName: string): Group & ModelDefinitions;
42
+ group(groupName: string): Group & ModelDefinitions;
43
43
  person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
44
44
  validate(): void;
45
45
  getPeople(): ReadonlyArray<Person>;
@@ -8,7 +8,7 @@ interface DefineContainer {
8
8
  export interface SoftwareSystemReference {
9
9
  name: string;
10
10
  }
11
- export declare class SoftwareSystemGroup extends Group implements DefineContainer {
11
+ export declare class SoftwareSystemGroup extends Group<Container> implements DefineContainer {
12
12
  readonly name: string;
13
13
  private readonly softwareSystem;
14
14
  private _containers;
@@ -16,13 +16,13 @@ export declare class SoftwareSystemGroup extends Group implements DefineContaine
16
16
  container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
17
17
  getContainers(): ReadonlyArray<Container>;
18
18
  }
19
- export declare class SoftwareSystem extends Element implements DefineContainer {
19
+ export declare class SoftwareSystem extends Element<Container> implements DefineContainer {
20
20
  readonly name: string;
21
21
  private _containers;
22
22
  private _groups;
23
23
  constructor(name: string, definition?: SoftwareSystemDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
24
24
  container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
25
- addGroup(groupName: string): SoftwareSystemGroup;
25
+ group(groupName: string): SoftwareSystemGroup;
26
26
  getGroups(): ReadonlyArray<SoftwareSystemGroup>;
27
27
  getChildElements(): ReadonlyArray<Element>;
28
28
  getContainersNotInGroups(): ReadonlyArray<Container>;