@agilewallaby/c4-model 2.0.0 → 2.2.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,10 +1,6 @@
1
1
  {
2
2
  "name": "@agilewallaby/c4-model",
3
- "version": "2.0.0",
4
- "files": [
5
- "src",
6
- "README.md"
7
- ],
3
+ "version": "2.2.0",
8
4
  "publishConfig": {
9
5
  "access": "public"
10
6
  },
@@ -15,8 +11,7 @@
15
11
  "dependencies": {
16
12
  "change-case": "^5.4.4",
17
13
  "glob": "^10.3.10",
18
- "testcontainers": "^10.28.0",
19
- "tslib": "^2.3.0"
14
+ "testcontainers": "^10.28.0"
20
15
  },
21
16
  "type": "module",
22
17
  "main": "./src/index.js",
@@ -26,6 +21,5 @@
26
21
  "import": "./src/index.js",
27
22
  "types": "./src/index.d.ts"
28
23
  }
29
- },
30
- "module": "./src/index.js"
24
+ }
31
25
  }
@@ -0,0 +1,30 @@
1
+ import { TechnologyDefinition } from './core';
2
+ export type ElementKind = 'person' | 'softwareSystem' | 'container' | 'component';
3
+ export declare class ElementArchetype {
4
+ readonly name: string;
5
+ readonly elementKind: ElementKind;
6
+ readonly parent?: ElementArchetype | undefined;
7
+ readonly ownDescription?: string;
8
+ readonly ownTechnology?: string;
9
+ readonly ownTags: ReadonlyArray<string>;
10
+ readonly description?: string;
11
+ readonly technology?: string;
12
+ readonly tags: ReadonlyArray<string>;
13
+ constructor(name: string, elementKind: ElementKind, definition?: TechnologyDefinition, parent?: ElementArchetype | undefined);
14
+ }
15
+ export declare class RelationshipArchetype {
16
+ readonly name: string;
17
+ readonly parent?: RelationshipArchetype | undefined;
18
+ readonly ownDescription?: string;
19
+ readonly ownTechnology?: string;
20
+ readonly ownTags: ReadonlyArray<string>;
21
+ readonly description?: string;
22
+ readonly technology?: string;
23
+ readonly tags: ReadonlyArray<string>;
24
+ constructor(name: string, definition?: TechnologyDefinition, parent?: RelationshipArchetype | undefined);
25
+ }
26
+ export declare function mergeArchetypeWithOverride(archetype: {
27
+ description?: string;
28
+ technology?: string;
29
+ tags: ReadonlyArray<string>;
30
+ }, override?: TechnologyDefinition): TechnologyDefinition;
@@ -0,0 +1,20 @@
1
+ import { Model } from './model';
2
+ type Catalog = Record<string, unknown>;
3
+ type RootCatalog = Record<string, Catalog>;
4
+ export interface AnyC4Module {
5
+ readonly key: string;
6
+ registerDefinitions(model: Model): Catalog;
7
+ buildRelationships(local: Catalog, dependencies: RootCatalog): void;
8
+ }
9
+ export interface BuildModelOptions {
10
+ modelName?: string;
11
+ modules?: ReadonlyArray<AnyC4Module>;
12
+ globPath?: string;
13
+ searchRoot?: string;
14
+ }
15
+ export declare function buildModelWithCatalog<TRoot>(options?: BuildModelOptions): Promise<{
16
+ model: Model;
17
+ catalog: TRoot;
18
+ }>;
19
+ export declare function buildModel(options?: BuildModelOptions): Promise<Model>;
20
+ export {};
@@ -1,7 +1,8 @@
1
1
  import { Element, TechnicalElement, TechnologyDefinition } from './core';
2
+ import { ElementArchetype } from './archetype';
2
3
  export type ComponentDefinition = TechnologyDefinition;
3
4
  export declare class Component extends TechnicalElement {
4
5
  readonly name: string;
5
- constructor(name: string, definition?: ComponentDefinition);
6
+ constructor(name: string, definition?: ComponentDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
6
7
  getChildElements(): ReadonlyArray<Element>;
7
8
  }
@@ -1,23 +1,24 @@
1
1
  import { Element, Group, TechnicalElement, TechnologyDefinition } from './core';
2
2
  import { Component, ComponentDefinition } from './component';
3
+ import { ElementArchetype } from './archetype';
3
4
  export type ContainerDefinition = TechnologyDefinition;
4
5
  interface DefineComponent {
5
- defineComponent(name: string, definition?: ComponentDefinition): Component;
6
+ defineComponent(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
6
7
  }
7
8
  export declare class ContainerGroup extends Group implements DefineComponent {
8
9
  readonly name: string;
9
10
  private readonly container;
10
11
  private _components;
11
12
  constructor(name: string, container: DefineComponent);
12
- defineComponent(name: string, definition?: ComponentDefinition): Component;
13
+ defineComponent(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
13
14
  getComponents(): ReadonlyArray<Component>;
14
15
  }
15
16
  export declare class Container extends TechnicalElement implements DefineComponent {
16
17
  readonly name: string;
17
18
  private _components;
18
19
  private _groups;
19
- constructor(name: string, definition?: ContainerDefinition);
20
- defineComponent(name: string, definition?: ComponentDefinition): Component;
20
+ constructor(name: string, definition?: ContainerDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
21
+ defineComponent(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
21
22
  addGroup(groupName: string): ContainerGroup;
22
23
  getGroups(): ReadonlyArray<ContainerGroup>;
23
24
  getComponentsNotInGroups(): ReadonlyArray<Component>;
package/src/core.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ElementArchetype, RelationshipArchetype } from './archetype';
1
2
  export interface Definition {
2
3
  description?: string;
3
4
  tags?: string[];
@@ -9,10 +10,12 @@ export declare abstract class Element {
9
10
  readonly name: string;
10
11
  readonly description?: string;
11
12
  readonly tags: ReadonlyArray<string>;
13
+ readonly archetype?: ElementArchetype;
14
+ readonly overrideDefinition?: TechnologyDefinition;
12
15
  private _relationships;
13
- constructor(name: string, defaultTags?: string[], definition?: Definition);
16
+ constructor(name: string, defaultTags?: string[], definition?: Definition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
14
17
  get canonicalName(): string;
15
- uses(otherElement: Element, definition?: TechnologyDefinition): void;
18
+ uses(otherElement: Element, archetypeOrDef?: RelationshipArchetype | TechnologyDefinition, override?: TechnologyDefinition): void;
16
19
  get relationships(): ReadonlyArray<Relationship>;
17
20
  abstract getChildElements(): ReadonlyArray<Element>;
18
21
  getRelationshipsInHierarchy(): ReadonlyArray<Relationship>;
@@ -20,7 +23,7 @@ export declare abstract class Element {
20
23
  }
21
24
  export declare abstract class TechnicalElement extends Element {
22
25
  readonly technology?: string;
23
- constructor(name: string, defaultTags?: string[], definition?: TechnologyDefinition);
26
+ constructor(name: string, defaultTags?: string[], definition?: TechnologyDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
24
27
  }
25
28
  export declare class Relationship {
26
29
  readonly source: Element;
@@ -28,7 +31,9 @@ export declare class Relationship {
28
31
  readonly description?: string;
29
32
  readonly tags: ReadonlyArray<string>;
30
33
  readonly technology?: string;
31
- constructor(source: Element, destination: Element, definition?: TechnologyDefinition);
34
+ readonly archetype?: RelationshipArchetype;
35
+ readonly overrideDefinition?: TechnologyDefinition;
36
+ constructor(source: Element, destination: Element, definition?: TechnologyDefinition, archetype?: RelationshipArchetype, overrideDefinition?: TechnologyDefinition);
32
37
  }
33
38
  export declare class Group {
34
39
  readonly name: string;
@@ -1,4 +1,4 @@
1
- import { BuildModelOptions } from './model';
1
+ import { BuildModelOptions } from './buildModel';
2
2
  import { Views } from './views';
3
3
  export interface GenerateDiagramsOptions<TRoot> extends BuildModelOptions {
4
4
  views: (catalog: TRoot) => Views;
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './archetype';
1
2
  export * from './model';
2
3
  export * from './person';
3
4
  export * from './softwareSystem';
@@ -5,4 +6,5 @@ export * from './container';
5
6
  export * from './component';
6
7
  export * from './views';
7
8
  export * from './structurizrDslWriter';
9
+ export * from './buildModel';
8
10
  export * from './generateDiagrams';