@agilewallaby/c4-model 2.5.0 → 2.6.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 +1 -1
- package/src/buildModel.d.ts +4 -2
- package/src/container.d.ts +3 -3
- package/src/index.cjs +15 -15
- package/src/index.d.ts +20 -19
- package/src/index.js +15 -15
- package/src/model.d.ts +12 -12
- package/src/softwareSystem.d.ts +3 -3
package/package.json
CHANGED
package/src/buildModel.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { Model } from './model';
|
|
2
|
+
import { ElementArchetype, RelationshipArchetype } from './archetype';
|
|
2
3
|
type Catalog = Record<string, unknown>;
|
|
3
4
|
type RootCatalog = Record<string, Catalog>;
|
|
4
5
|
export interface AnyC4Module {
|
|
5
6
|
readonly key: string;
|
|
6
|
-
registerDefinitions(model: Model): Catalog;
|
|
7
|
-
buildRelationships(local: Catalog, dependencies: RootCatalog): void;
|
|
7
|
+
registerDefinitions(model: Model, archetypes: Record<string, ElementArchetype | RelationshipArchetype>): Catalog;
|
|
8
|
+
buildRelationships(local: Catalog, dependencies: RootCatalog, archetypes: Record<string, ElementArchetype | RelationshipArchetype>): void;
|
|
8
9
|
}
|
|
9
10
|
export interface BuildModelOptions {
|
|
10
11
|
modelName?: string;
|
|
11
12
|
modules?: ReadonlyArray<AnyC4Module>;
|
|
12
13
|
globPath?: string;
|
|
13
14
|
searchRoot?: string;
|
|
15
|
+
archetypes?: Record<string, ElementArchetype | RelationshipArchetype>;
|
|
14
16
|
}
|
|
15
17
|
export declare function buildModelWithCatalog<TRoot>(options?: BuildModelOptions): Promise<{
|
|
16
18
|
model: Model;
|
package/src/container.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { Component, ComponentDefinition } from './component';
|
|
|
3
3
|
import { ElementArchetype } from './archetype';
|
|
4
4
|
export type ContainerDefinition = TechnologyDefinition;
|
|
5
5
|
interface DefineComponent {
|
|
6
|
-
|
|
6
|
+
component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
|
|
7
7
|
}
|
|
8
8
|
export declare class ContainerGroup extends Group implements DefineComponent {
|
|
9
9
|
readonly name: string;
|
|
10
10
|
private readonly container;
|
|
11
11
|
private _components;
|
|
12
12
|
constructor(name: string, container: DefineComponent);
|
|
13
|
-
|
|
13
|
+
component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
|
|
14
14
|
getComponents(): ReadonlyArray<Component>;
|
|
15
15
|
}
|
|
16
16
|
export declare class Container extends TechnicalElement implements DefineComponent {
|
|
@@ -18,7 +18,7 @@ export declare class Container extends TechnicalElement implements DefineCompone
|
|
|
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
22
|
addGroup(groupName: string): ContainerGroup;
|
|
23
23
|
getGroups(): ReadonlyArray<ContainerGroup>;
|
|
24
24
|
getComponentsNotInGroups(): ReadonlyArray<Component>;
|
package/src/index.cjs
CHANGED
|
@@ -275,8 +275,8 @@ var ContainerGroup = class extends Group {
|
|
|
275
275
|
this.container = container;
|
|
276
276
|
}
|
|
277
277
|
_components = /* @__PURE__ */ new Map();
|
|
278
|
-
|
|
279
|
-
const component = this.container.
|
|
278
|
+
component(name, archetypeOrDef, override) {
|
|
279
|
+
const component = this.container.component(name, archetypeOrDef, override);
|
|
280
280
|
this._components.set(name, component);
|
|
281
281
|
return component;
|
|
282
282
|
}
|
|
@@ -291,7 +291,7 @@ var Container = class extends TechnicalElement {
|
|
|
291
291
|
}
|
|
292
292
|
_components = /* @__PURE__ */ new Map();
|
|
293
293
|
_groups = /* @__PURE__ */ new Map();
|
|
294
|
-
|
|
294
|
+
component(name, archetypeOrDef, override) {
|
|
295
295
|
if (this._components.has(name)) {
|
|
296
296
|
throw Error(`A Component named '${name}' is defined elsewhere in this Container. A Component can be defined only once.`);
|
|
297
297
|
}
|
|
@@ -335,8 +335,8 @@ var SoftwareSystemGroup = class extends Group {
|
|
|
335
335
|
this.softwareSystem = softwareSystem;
|
|
336
336
|
}
|
|
337
337
|
_containers = /* @__PURE__ */ new Map();
|
|
338
|
-
|
|
339
|
-
const container = this.softwareSystem.
|
|
338
|
+
container(name, archetypeOrDef, override) {
|
|
339
|
+
const container = this.softwareSystem.container(name, archetypeOrDef, override);
|
|
340
340
|
this._containers.set(name, container);
|
|
341
341
|
return container;
|
|
342
342
|
}
|
|
@@ -351,7 +351,7 @@ var SoftwareSystem = class extends Element {
|
|
|
351
351
|
}
|
|
352
352
|
_containers = /* @__PURE__ */ new Map();
|
|
353
353
|
_groups = /* @__PURE__ */ new Map();
|
|
354
|
-
|
|
354
|
+
container(name, archetypeOrDef, override) {
|
|
355
355
|
if (this._containers.has(name)) {
|
|
356
356
|
throw Error(`A Container named '${name}' is defined elsewhere in this SoftwareSystem. A Container can be defined only once.`);
|
|
357
357
|
}
|
|
@@ -407,13 +407,13 @@ var ModelGroup = class extends Group {
|
|
|
407
407
|
}
|
|
408
408
|
softwareSystems = /* @__PURE__ */ new Map();
|
|
409
409
|
people = /* @__PURE__ */ new Map();
|
|
410
|
-
|
|
411
|
-
const softwareSystem = this.model.
|
|
410
|
+
softwareSystem(name, archetypeOrDef, override) {
|
|
411
|
+
const softwareSystem = this.model.softwareSystem(name, archetypeOrDef, override);
|
|
412
412
|
this.softwareSystems.set(name, softwareSystem);
|
|
413
413
|
return softwareSystem;
|
|
414
414
|
}
|
|
415
|
-
|
|
416
|
-
const person = this.model.
|
|
415
|
+
person(name, archetypeOrDef, override) {
|
|
416
|
+
const person = this.model.person(name, archetypeOrDef, override);
|
|
417
417
|
this.people.set(name, person);
|
|
418
418
|
return person;
|
|
419
419
|
}
|
|
@@ -431,7 +431,7 @@ var Model = class {
|
|
|
431
431
|
softwareSystems = /* @__PURE__ */ new Map();
|
|
432
432
|
people = /* @__PURE__ */ new Map();
|
|
433
433
|
groups = /* @__PURE__ */ new Map();
|
|
434
|
-
|
|
434
|
+
softwareSystem(name, archetypeOrDef, override) {
|
|
435
435
|
if (this.softwareSystems.has(name)) {
|
|
436
436
|
throw Error(`A SoftwareSystem named '${name}' is defined elsewhere in this Model. A SoftwareSystem can be defined only once.`);
|
|
437
437
|
}
|
|
@@ -456,7 +456,7 @@ var Model = class {
|
|
|
456
456
|
}
|
|
457
457
|
return group;
|
|
458
458
|
}
|
|
459
|
-
|
|
459
|
+
person(name, archetypeOrDef, override) {
|
|
460
460
|
if (this.people.has(name)) {
|
|
461
461
|
throw Error(`A Person named '${name}' is defined elsewhere in this Model. A Person can be defined only once.`);
|
|
462
462
|
}
|
|
@@ -866,7 +866,7 @@ var import_url = require("url");
|
|
|
866
866
|
var import_meta = {};
|
|
867
867
|
var _dirname = typeof __dirname !== "undefined" ? __dirname : (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url));
|
|
868
868
|
async function buildModelWithCatalog(options = {}) {
|
|
869
|
-
const { modelName = "model", modules: explicitModules } = options;
|
|
869
|
+
const { modelName = "model", modules: explicitModules, archetypes = {} } = options;
|
|
870
870
|
const model = new Model(modelName);
|
|
871
871
|
let c4Modules;
|
|
872
872
|
if (explicitModules) {
|
|
@@ -886,13 +886,13 @@ async function buildModelWithCatalog(options = {}) {
|
|
|
886
886
|
const registrations = [];
|
|
887
887
|
const rootCatalog = {};
|
|
888
888
|
for (const instance of c4Modules) {
|
|
889
|
-
const local = instance.registerDefinitions(model);
|
|
889
|
+
const local = instance.registerDefinitions(model, archetypes);
|
|
890
890
|
rootCatalog[instance.key] = local;
|
|
891
891
|
registrations.push({ instance, key: instance.key, local });
|
|
892
892
|
}
|
|
893
893
|
for (const { instance, key, local } of registrations) {
|
|
894
894
|
const dependencies = Object.fromEntries(Object.entries(rootCatalog).filter(([k]) => k !== key));
|
|
895
|
-
instance.buildRelationships(local, dependencies);
|
|
895
|
+
instance.buildRelationships(local, dependencies, archetypes);
|
|
896
896
|
}
|
|
897
897
|
return { model, catalog: rootCatalog };
|
|
898
898
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -77,14 +77,14 @@ export declare class Component extends TechnicalElement {
|
|
|
77
77
|
}
|
|
78
78
|
export type ContainerDefinition = TechnologyDefinition;
|
|
79
79
|
export interface DefineComponent {
|
|
80
|
-
|
|
80
|
+
component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
|
|
81
81
|
}
|
|
82
82
|
export declare class ContainerGroup extends Group implements DefineComponent {
|
|
83
83
|
readonly name: string;
|
|
84
84
|
private readonly container;
|
|
85
85
|
private _components;
|
|
86
86
|
constructor(name: string, container: DefineComponent);
|
|
87
|
-
|
|
87
|
+
component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
|
|
88
88
|
getComponents(): ReadonlyArray<Component>;
|
|
89
89
|
}
|
|
90
90
|
export declare class Container extends TechnicalElement implements DefineComponent {
|
|
@@ -92,7 +92,7 @@ export declare class Container extends TechnicalElement implements DefineCompone
|
|
|
92
92
|
private _components;
|
|
93
93
|
private _groups;
|
|
94
94
|
constructor(name: string, definition?: ContainerDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
|
|
95
|
-
|
|
95
|
+
component(name: string, archetypeOrDef?: ElementArchetype | ComponentDefinition, override?: ComponentDefinition): Component;
|
|
96
96
|
addGroup(groupName: string): ContainerGroup;
|
|
97
97
|
getGroups(): ReadonlyArray<ContainerGroup>;
|
|
98
98
|
getComponentsNotInGroups(): ReadonlyArray<Component>;
|
|
@@ -100,7 +100,7 @@ export declare class Container extends TechnicalElement implements DefineCompone
|
|
|
100
100
|
}
|
|
101
101
|
export type SoftwareSystemDefinition = Definition;
|
|
102
102
|
export interface DefineContainer {
|
|
103
|
-
|
|
103
|
+
container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
|
|
104
104
|
}
|
|
105
105
|
export interface SoftwareSystemReference {
|
|
106
106
|
name: string;
|
|
@@ -110,7 +110,7 @@ export declare class SoftwareSystemGroup extends Group implements DefineContaine
|
|
|
110
110
|
private readonly softwareSystem;
|
|
111
111
|
private _containers;
|
|
112
112
|
constructor(name: string, softwareSystem: DefineContainer);
|
|
113
|
-
|
|
113
|
+
container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
|
|
114
114
|
getContainers(): ReadonlyArray<Container>;
|
|
115
115
|
}
|
|
116
116
|
export declare class SoftwareSystem extends Element$1 implements DefineContainer {
|
|
@@ -118,7 +118,7 @@ export declare class SoftwareSystem extends Element$1 implements DefineContainer
|
|
|
118
118
|
private _containers;
|
|
119
119
|
private _groups;
|
|
120
120
|
constructor(name: string, definition?: SoftwareSystemDefinition, archetype?: ElementArchetype, overrideDefinition?: TechnologyDefinition);
|
|
121
|
-
|
|
121
|
+
container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
|
|
122
122
|
addGroup(groupName: string): SoftwareSystemGroup;
|
|
123
123
|
getGroups(): ReadonlyArray<SoftwareSystemGroup>;
|
|
124
124
|
getChildElements(): ReadonlyArray<Element$1>;
|
|
@@ -134,16 +134,16 @@ export type CatalogKeyOf<TRoot, TModule> = {
|
|
|
134
134
|
[K in keyof TRoot]: TRoot[K] extends TModule ? K : never;
|
|
135
135
|
}[keyof TRoot];
|
|
136
136
|
export type Dependencies<TRoot, TModule> = Omit<TRoot, CatalogKeyOf<TRoot, TModule>>;
|
|
137
|
-
export interface C4Module<TRoot, TLocal
|
|
137
|
+
export interface C4Module<TRoot, TLocal, TArchetypes = Record<string, ElementArchetype | RelationshipArchetype>> {
|
|
138
138
|
readonly key: CatalogKeyOf<TRoot, TLocal>;
|
|
139
|
-
registerDefinitions(model: Model): TLocal;
|
|
140
|
-
buildRelationships(local: TLocal, dependencies: Dependencies<TRoot, TLocal
|
|
139
|
+
registerDefinitions(model: Model, archetypes: TArchetypes): TLocal;
|
|
140
|
+
buildRelationships(local: TLocal, dependencies: Dependencies<TRoot, TLocal>, archetypes: TArchetypes): void;
|
|
141
141
|
}
|
|
142
142
|
export interface DefineSoftwareSystem {
|
|
143
|
-
|
|
143
|
+
softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
|
|
144
144
|
}
|
|
145
145
|
export interface DefinePerson {
|
|
146
|
-
|
|
146
|
+
person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
|
|
147
147
|
}
|
|
148
148
|
export declare class ModelGroup extends Group implements DefineSoftwareSystem, DefinePerson {
|
|
149
149
|
readonly name: string;
|
|
@@ -151,14 +151,14 @@ export declare class ModelGroup extends Group implements DefineSoftwareSystem, D
|
|
|
151
151
|
private softwareSystems;
|
|
152
152
|
private people;
|
|
153
153
|
constructor(name: string, model: DefineSoftwareSystem & DefinePerson);
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
|
|
155
|
+
person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
|
|
156
156
|
getSoftwareSystems(): ReadonlyArray<SoftwareSystem>;
|
|
157
157
|
getPeople(): ReadonlyArray<Person>;
|
|
158
158
|
}
|
|
159
159
|
export interface ModelDefinitions {
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
|
|
161
|
+
person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
|
|
162
162
|
}
|
|
163
163
|
export declare class Model {
|
|
164
164
|
name: string;
|
|
@@ -166,9 +166,9 @@ export declare class Model {
|
|
|
166
166
|
private softwareSystems;
|
|
167
167
|
private people;
|
|
168
168
|
private groups;
|
|
169
|
-
|
|
169
|
+
softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
|
|
170
170
|
addGroup(groupName: string): Group & ModelDefinitions;
|
|
171
|
-
|
|
171
|
+
person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
|
|
172
172
|
validate(): void;
|
|
173
173
|
getPeople(): ReadonlyArray<Person>;
|
|
174
174
|
getSoftwareSystems(): ReadonlyArray<SoftwareSystem>;
|
|
@@ -235,14 +235,15 @@ export type Catalog = Record<string, unknown>;
|
|
|
235
235
|
export type RootCatalog = Record<string, Catalog>;
|
|
236
236
|
export interface AnyC4Module {
|
|
237
237
|
readonly key: string;
|
|
238
|
-
registerDefinitions(model: Model): Catalog;
|
|
239
|
-
buildRelationships(local: Catalog, dependencies: RootCatalog): void;
|
|
238
|
+
registerDefinitions(model: Model, archetypes: Record<string, ElementArchetype | RelationshipArchetype>): Catalog;
|
|
239
|
+
buildRelationships(local: Catalog, dependencies: RootCatalog, archetypes: Record<string, ElementArchetype | RelationshipArchetype>): void;
|
|
240
240
|
}
|
|
241
241
|
export interface BuildModelOptions {
|
|
242
242
|
modelName?: string;
|
|
243
243
|
modules?: ReadonlyArray<AnyC4Module>;
|
|
244
244
|
globPath?: string;
|
|
245
245
|
searchRoot?: string;
|
|
246
|
+
archetypes?: Record<string, ElementArchetype | RelationshipArchetype>;
|
|
246
247
|
}
|
|
247
248
|
export declare function buildModelWithCatalog<TRoot>(options?: BuildModelOptions): Promise<{
|
|
248
249
|
model: Model;
|
package/src/index.js
CHANGED
|
@@ -223,8 +223,8 @@ var ContainerGroup = class extends Group {
|
|
|
223
223
|
this.container = container;
|
|
224
224
|
}
|
|
225
225
|
_components = /* @__PURE__ */ new Map();
|
|
226
|
-
|
|
227
|
-
const component = this.container.
|
|
226
|
+
component(name, archetypeOrDef, override) {
|
|
227
|
+
const component = this.container.component(name, archetypeOrDef, override);
|
|
228
228
|
this._components.set(name, component);
|
|
229
229
|
return component;
|
|
230
230
|
}
|
|
@@ -239,7 +239,7 @@ var Container = class extends TechnicalElement {
|
|
|
239
239
|
}
|
|
240
240
|
_components = /* @__PURE__ */ new Map();
|
|
241
241
|
_groups = /* @__PURE__ */ new Map();
|
|
242
|
-
|
|
242
|
+
component(name, archetypeOrDef, override) {
|
|
243
243
|
if (this._components.has(name)) {
|
|
244
244
|
throw Error(`A Component named '${name}' is defined elsewhere in this Container. A Component can be defined only once.`);
|
|
245
245
|
}
|
|
@@ -283,8 +283,8 @@ var SoftwareSystemGroup = class extends Group {
|
|
|
283
283
|
this.softwareSystem = softwareSystem;
|
|
284
284
|
}
|
|
285
285
|
_containers = /* @__PURE__ */ new Map();
|
|
286
|
-
|
|
287
|
-
const container = this.softwareSystem.
|
|
286
|
+
container(name, archetypeOrDef, override) {
|
|
287
|
+
const container = this.softwareSystem.container(name, archetypeOrDef, override);
|
|
288
288
|
this._containers.set(name, container);
|
|
289
289
|
return container;
|
|
290
290
|
}
|
|
@@ -299,7 +299,7 @@ var SoftwareSystem = class extends Element {
|
|
|
299
299
|
}
|
|
300
300
|
_containers = /* @__PURE__ */ new Map();
|
|
301
301
|
_groups = /* @__PURE__ */ new Map();
|
|
302
|
-
|
|
302
|
+
container(name, archetypeOrDef, override) {
|
|
303
303
|
if (this._containers.has(name)) {
|
|
304
304
|
throw Error(`A Container named '${name}' is defined elsewhere in this SoftwareSystem. A Container can be defined only once.`);
|
|
305
305
|
}
|
|
@@ -355,13 +355,13 @@ var ModelGroup = class extends Group {
|
|
|
355
355
|
}
|
|
356
356
|
softwareSystems = /* @__PURE__ */ new Map();
|
|
357
357
|
people = /* @__PURE__ */ new Map();
|
|
358
|
-
|
|
359
|
-
const softwareSystem = this.model.
|
|
358
|
+
softwareSystem(name, archetypeOrDef, override) {
|
|
359
|
+
const softwareSystem = this.model.softwareSystem(name, archetypeOrDef, override);
|
|
360
360
|
this.softwareSystems.set(name, softwareSystem);
|
|
361
361
|
return softwareSystem;
|
|
362
362
|
}
|
|
363
|
-
|
|
364
|
-
const person = this.model.
|
|
363
|
+
person(name, archetypeOrDef, override) {
|
|
364
|
+
const person = this.model.person(name, archetypeOrDef, override);
|
|
365
365
|
this.people.set(name, person);
|
|
366
366
|
return person;
|
|
367
367
|
}
|
|
@@ -379,7 +379,7 @@ var Model = class {
|
|
|
379
379
|
softwareSystems = /* @__PURE__ */ new Map();
|
|
380
380
|
people = /* @__PURE__ */ new Map();
|
|
381
381
|
groups = /* @__PURE__ */ new Map();
|
|
382
|
-
|
|
382
|
+
softwareSystem(name, archetypeOrDef, override) {
|
|
383
383
|
if (this.softwareSystems.has(name)) {
|
|
384
384
|
throw Error(`A SoftwareSystem named '${name}' is defined elsewhere in this Model. A SoftwareSystem can be defined only once.`);
|
|
385
385
|
}
|
|
@@ -404,7 +404,7 @@ var Model = class {
|
|
|
404
404
|
}
|
|
405
405
|
return group;
|
|
406
406
|
}
|
|
407
|
-
|
|
407
|
+
person(name, archetypeOrDef, override) {
|
|
408
408
|
if (this.people.has(name)) {
|
|
409
409
|
throw Error(`A Person named '${name}' is defined elsewhere in this Model. A Person can be defined only once.`);
|
|
410
410
|
}
|
|
@@ -813,7 +813,7 @@ import { join, dirname } from "path";
|
|
|
813
813
|
import { fileURLToPath } from "url";
|
|
814
814
|
var _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
815
815
|
async function buildModelWithCatalog(options = {}) {
|
|
816
|
-
const { modelName = "model", modules: explicitModules } = options;
|
|
816
|
+
const { modelName = "model", modules: explicitModules, archetypes = {} } = options;
|
|
817
817
|
const model = new Model(modelName);
|
|
818
818
|
let c4Modules;
|
|
819
819
|
if (explicitModules) {
|
|
@@ -833,13 +833,13 @@ async function buildModelWithCatalog(options = {}) {
|
|
|
833
833
|
const registrations = [];
|
|
834
834
|
const rootCatalog = {};
|
|
835
835
|
for (const instance of c4Modules) {
|
|
836
|
-
const local = instance.registerDefinitions(model);
|
|
836
|
+
const local = instance.registerDefinitions(model, archetypes);
|
|
837
837
|
rootCatalog[instance.key] = local;
|
|
838
838
|
registrations.push({ instance, key: instance.key, local });
|
|
839
839
|
}
|
|
840
840
|
for (const { instance, key, local } of registrations) {
|
|
841
841
|
const dependencies = Object.fromEntries(Object.entries(rootCatalog).filter(([k]) => k !== key));
|
|
842
|
-
instance.buildRelationships(local, dependencies);
|
|
842
|
+
instance.buildRelationships(local, dependencies, archetypes);
|
|
843
843
|
}
|
|
844
844
|
return { model, catalog: rootCatalog };
|
|
845
845
|
}
|
package/src/model.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { Group } from './core';
|
|
2
2
|
import { SoftwareSystem, SoftwareSystemDefinition } from './softwareSystem';
|
|
3
3
|
import { Person, PersonDefinition } from './person';
|
|
4
|
-
import { ElementArchetype } from './archetype';
|
|
4
|
+
import { ElementArchetype, RelationshipArchetype } from './archetype';
|
|
5
5
|
export type CatalogKeyOf<TRoot, TModule> = {
|
|
6
6
|
[K in keyof TRoot]: TRoot[K] extends TModule ? K : never;
|
|
7
7
|
}[keyof TRoot];
|
|
8
8
|
export type Dependencies<TRoot, TModule> = Omit<TRoot, CatalogKeyOf<TRoot, TModule>>;
|
|
9
|
-
export interface C4Module<TRoot, TLocal
|
|
9
|
+
export interface C4Module<TRoot, TLocal, TArchetypes = Record<string, ElementArchetype | RelationshipArchetype>> {
|
|
10
10
|
readonly key: CatalogKeyOf<TRoot, TLocal>;
|
|
11
|
-
registerDefinitions(model: Model): TLocal;
|
|
12
|
-
buildRelationships(local: TLocal, dependencies: Dependencies<TRoot, TLocal
|
|
11
|
+
registerDefinitions(model: Model, archetypes: TArchetypes): TLocal;
|
|
12
|
+
buildRelationships(local: TLocal, dependencies: Dependencies<TRoot, TLocal>, archetypes: TArchetypes): void;
|
|
13
13
|
}
|
|
14
14
|
interface DefineSoftwareSystem {
|
|
15
|
-
|
|
15
|
+
softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
|
|
16
16
|
}
|
|
17
17
|
interface DefinePerson {
|
|
18
|
-
|
|
18
|
+
person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
|
|
19
19
|
}
|
|
20
20
|
export declare class ModelGroup extends Group implements DefineSoftwareSystem, DefinePerson {
|
|
21
21
|
readonly name: string;
|
|
@@ -23,14 +23,14 @@ export declare class ModelGroup extends Group implements DefineSoftwareSystem, D
|
|
|
23
23
|
private softwareSystems;
|
|
24
24
|
private people;
|
|
25
25
|
constructor(name: string, model: DefineSoftwareSystem & DefinePerson);
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
|
|
27
|
+
person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
|
|
28
28
|
getSoftwareSystems(): ReadonlyArray<SoftwareSystem>;
|
|
29
29
|
getPeople(): ReadonlyArray<Person>;
|
|
30
30
|
}
|
|
31
31
|
export interface ModelDefinitions {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
|
|
33
|
+
person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
|
|
34
34
|
}
|
|
35
35
|
export declare class Model {
|
|
36
36
|
name: string;
|
|
@@ -38,9 +38,9 @@ export declare class Model {
|
|
|
38
38
|
private softwareSystems;
|
|
39
39
|
private people;
|
|
40
40
|
private groups;
|
|
41
|
-
|
|
41
|
+
softwareSystem(name: string, archetypeOrDef?: ElementArchetype | SoftwareSystemDefinition, override?: SoftwareSystemDefinition): SoftwareSystem;
|
|
42
42
|
addGroup(groupName: string): Group & ModelDefinitions;
|
|
43
|
-
|
|
43
|
+
person(name: string, archetypeOrDef?: ElementArchetype | PersonDefinition, override?: PersonDefinition): Person;
|
|
44
44
|
validate(): void;
|
|
45
45
|
getPeople(): ReadonlyArray<Person>;
|
|
46
46
|
getSoftwareSystems(): ReadonlyArray<SoftwareSystem>;
|
package/src/softwareSystem.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Container, ContainerDefinition } from './container';
|
|
|
3
3
|
import { ElementArchetype } from './archetype';
|
|
4
4
|
export type SoftwareSystemDefinition = Definition;
|
|
5
5
|
interface DefineContainer {
|
|
6
|
-
|
|
6
|
+
container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
|
|
7
7
|
}
|
|
8
8
|
export interface SoftwareSystemReference {
|
|
9
9
|
name: string;
|
|
@@ -13,7 +13,7 @@ export declare class SoftwareSystemGroup extends Group implements DefineContaine
|
|
|
13
13
|
private readonly softwareSystem;
|
|
14
14
|
private _containers;
|
|
15
15
|
constructor(name: string, softwareSystem: DefineContainer);
|
|
16
|
-
|
|
16
|
+
container(name: string, archetypeOrDef?: ElementArchetype | ContainerDefinition, override?: ContainerDefinition): Container;
|
|
17
17
|
getContainers(): ReadonlyArray<Container>;
|
|
18
18
|
}
|
|
19
19
|
export declare class SoftwareSystem extends Element implements DefineContainer {
|
|
@@ -21,7 +21,7 @@ export declare class SoftwareSystem extends Element implements DefineContainer {
|
|
|
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
25
|
addGroup(groupName: string): SoftwareSystemGroup;
|
|
26
26
|
getGroups(): ReadonlyArray<SoftwareSystemGroup>;
|
|
27
27
|
getChildElements(): ReadonlyArray<Element>;
|