@agilewallaby/c4-model 0.0.1
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/README.md +11 -0
- package/package.json +13 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/component.d.ts +12 -0
- package/src/lib/component.js +23 -0
- package/src/lib/component.js.map +1 -0
- package/src/lib/container.d.ts +16 -0
- package/src/lib/container.js +37 -0
- package/src/lib/container.js.map +1 -0
- package/src/lib/core.d.ts +38 -0
- package/src/lib/core.js +56 -0
- package/src/lib/core.js.map +1 -0
- package/src/lib/model.d.ts +16 -0
- package/src/lib/model.js +90 -0
- package/src/lib/model.js.map +1 -0
- package/src/lib/person.d.ts +9 -0
- package/src/lib/person.js +15 -0
- package/src/lib/person.js.map +1 -0
- package/src/lib/softwareSystem.d.ts +20 -0
- package/src/lib/softwareSystem.js +41 -0
- package/src/lib/softwareSystem.js.map +1 -0
- package/src/lib/tests/system1/c4.dsl.d.ts +2 -0
- package/src/lib/tests/system1/c4.dsl.js +9 -0
- package/src/lib/tests/system1/c4.dsl.js.map +1 -0
- package/src/lib/tests/system2/c4.dsl.d.ts +2 -0
- package/src/lib/tests/system2/c4.dsl.js +9 -0
- package/src/lib/tests/system2/c4.dsl.js.map +1 -0
package/README.md
ADDED
package/package.json
ADDED
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/model';
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/c4-model/src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Element, Reference, Relationship, RelationshipTarget, TechnologyDefinition } from "./core";
|
|
2
|
+
export interface ComponentDefinition extends TechnologyDefinition {
|
|
3
|
+
}
|
|
4
|
+
export declare class Component extends Element {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
private _relationships;
|
|
7
|
+
constructor(name: string, definition?: ComponentDefinition);
|
|
8
|
+
uses(otherElement: RelationshipTarget, definition?: TechnologyDefinition): void;
|
|
9
|
+
get relationships(): ReadonlyArray<Relationship>;
|
|
10
|
+
}
|
|
11
|
+
export declare class ReferencedComponent extends Reference<undefined> {
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReferencedComponent = exports.Component = void 0;
|
|
4
|
+
const core_1 = require("./core");
|
|
5
|
+
class Component extends core_1.Element {
|
|
6
|
+
constructor(name, definition) {
|
|
7
|
+
super(name, ["Component"], definition);
|
|
8
|
+
this.name = name;
|
|
9
|
+
this._relationships = [];
|
|
10
|
+
}
|
|
11
|
+
uses(otherElement, definition) {
|
|
12
|
+
const relationship = new core_1.Relationship(this, otherElement, definition);
|
|
13
|
+
this._relationships.push(relationship);
|
|
14
|
+
}
|
|
15
|
+
get relationships() {
|
|
16
|
+
return this._relationships;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.Component = Component;
|
|
20
|
+
class ReferencedComponent extends core_1.Reference {
|
|
21
|
+
}
|
|
22
|
+
exports.ReferencedComponent = ReferencedComponent;
|
|
23
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../../libs/c4-model/src/lib/component.ts"],"names":[],"mappings":";;;AAAA,iCAAmG;AAKnG,MAAa,SAAU,SAAQ,cAAO;IAIpC,YAAqC,IAAY,EAAE,UAAgC;QACjF,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,CAAA;QADH,SAAI,GAAJ,IAAI,CAAQ;QAFzC,mBAAc,GAAmB,EAAE,CAAA;IAI3C,CAAC;IAEM,IAAI,CAAC,YAAgC,EAAE,UAAiC;QAC7E,MAAM,YAAY,GAAG,IAAI,mBAAY,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;QACrE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACxC,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;CACF;AAhBD,8BAgBC;AAED,MAAa,mBAAoB,SAAQ,gBAAoB;CAC5D;AADD,kDACC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Element, Reference, Relationship, RelationshipTarget, TechnologyDefinition } from "./core";
|
|
2
|
+
import { Component, ComponentDefinition, ReferencedComponent } from "./component";
|
|
3
|
+
export interface ContainerDefinition extends TechnologyDefinition {
|
|
4
|
+
}
|
|
5
|
+
export declare class Container extends Element {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
private _relationships;
|
|
8
|
+
private _components;
|
|
9
|
+
constructor(name: string, definition?: ContainerDefinition);
|
|
10
|
+
uses(otherElement: RelationshipTarget, definition?: TechnologyDefinition): void;
|
|
11
|
+
get relationships(): ReadonlyArray<Relationship>;
|
|
12
|
+
defineComponent(name: string, definition?: ComponentDefinition): Component;
|
|
13
|
+
}
|
|
14
|
+
export declare class ReferencedContainer extends Reference<Component> {
|
|
15
|
+
referenceComponent(name: string): ReferencedComponent;
|
|
16
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReferencedContainer = exports.Container = void 0;
|
|
4
|
+
const core_1 = require("./core");
|
|
5
|
+
const component_1 = require("./component");
|
|
6
|
+
class Container extends core_1.Element {
|
|
7
|
+
constructor(name, definition) {
|
|
8
|
+
super(name, ["Container"], definition);
|
|
9
|
+
this.name = name;
|
|
10
|
+
this._relationships = [];
|
|
11
|
+
this._components = new Map();
|
|
12
|
+
}
|
|
13
|
+
uses(otherElement, definition) {
|
|
14
|
+
const relationship = new core_1.Relationship(this, otherElement, definition);
|
|
15
|
+
this._relationships.push(relationship);
|
|
16
|
+
}
|
|
17
|
+
get relationships() {
|
|
18
|
+
return this._relationships;
|
|
19
|
+
}
|
|
20
|
+
defineComponent(name, definition) {
|
|
21
|
+
if (this._components.has(name)) {
|
|
22
|
+
throw Error(`A Component named '${name}' is defined elsewhere in this Container. A Component can be defined only once, but can be referenced multiple times.`);
|
|
23
|
+
}
|
|
24
|
+
const component = new component_1.Component(name, definition);
|
|
25
|
+
this._components.set(name, component);
|
|
26
|
+
return component;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.Container = Container;
|
|
30
|
+
class ReferencedContainer extends core_1.Reference {
|
|
31
|
+
referenceComponent(name) {
|
|
32
|
+
const componentReference = this.referenceChild(name, (name) => new component_1.ReferencedComponent(name));
|
|
33
|
+
return componentReference;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ReferencedContainer = ReferencedContainer;
|
|
37
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../../../libs/c4-model/src/lib/container.ts"],"names":[],"mappings":";;;AAAA,iCAAmG;AACnG,2CAAiF;AAKjF,MAAa,SAAU,SAAQ,cAAO;IAKpC,YAAqC,IAAY,EAAE,UAAgC;QACjF,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,CAAA;QADH,SAAI,GAAJ,IAAI,CAAQ;QAHzC,mBAAc,GAAmB,EAAE,CAAA;QACnC,gBAAW,GAAG,IAAI,GAAG,EAAqB,CAAC;IAInD,CAAC;IAEM,IAAI,CAAC,YAAgC,EAAE,UAAiC;QAC7E,MAAM,YAAY,GAAG,IAAI,mBAAY,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;QACrE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACxC,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;IAEM,eAAe,CAAC,IAAY,EAAE,UAAgC;QACnE,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,KAAK,CAAC,sBAAsB,IAAI,uHAAuH,CAAC,CAAA;SAC/J;QAED,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QAEjD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAEtC,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AA7BD,8BA6BC;AAED,MAAa,mBAAoB,SAAQ,gBAAoB;IACpD,kBAAkB,CAAC,IAAY;QACpC,MAAM,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,+BAAmB,CAAC,IAAI,CAAC,CAAC,CAAA;QACrG,OAAO,kBAAyC,CAAA;IAClD,CAAC;CACF;AALD,kDAKC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Component, ReferencedComponent } from "./component";
|
|
2
|
+
import { Container, ReferencedContainer } from "./container";
|
|
3
|
+
import { ReferencedSoftwareSystem, SoftwareSystem } from "./softwareSystem";
|
|
4
|
+
import { Person } from "./person";
|
|
5
|
+
export interface Definition {
|
|
6
|
+
description?: string;
|
|
7
|
+
tags?: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface TechnologyDefinition extends Definition {
|
|
10
|
+
technology?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class Element {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly description?: string;
|
|
15
|
+
readonly tags: ReadonlyArray<string>;
|
|
16
|
+
constructor(name: string, defaultTags?: string[], definition?: Definition);
|
|
17
|
+
}
|
|
18
|
+
export declare abstract class TechnicalElement extends Element {
|
|
19
|
+
readonly technology?: string;
|
|
20
|
+
constructor(name: string, defaultTags?: string[], definition?: TechnologyDefinition);
|
|
21
|
+
}
|
|
22
|
+
export declare class Relationship {
|
|
23
|
+
readonly source: Element;
|
|
24
|
+
readonly destination: Element | Reference<SoftwareSystem | Container | Component>;
|
|
25
|
+
readonly description?: string;
|
|
26
|
+
readonly tags: ReadonlyArray<string>;
|
|
27
|
+
readonly technology?: string;
|
|
28
|
+
constructor(source: Element, destination: Element | Reference<SoftwareSystem | Container | Component>, definition?: TechnologyDefinition);
|
|
29
|
+
}
|
|
30
|
+
export declare class Reference<T> {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
private readonly _references;
|
|
33
|
+
constructor(name: string);
|
|
34
|
+
protected referenceChild(name: string, createChild: (childName: string) => Reference<T>): Reference<T>;
|
|
35
|
+
get references(): ReadonlyArray<Reference<T>>;
|
|
36
|
+
getChildElements(path?: string): ReadonlyArray<string>;
|
|
37
|
+
}
|
|
38
|
+
export type RelationshipTarget = Person | SoftwareSystem | ReferencedSoftwareSystem | Container | ReferencedContainer | Component | ReferencedComponent;
|
package/src/lib/core.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Reference = exports.Relationship = exports.TechnicalElement = exports.Element = void 0;
|
|
4
|
+
class Element {
|
|
5
|
+
constructor(name, defaultTags = [], definition) {
|
|
6
|
+
var _a;
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.description = definition === null || definition === void 0 ? void 0 : definition.description;
|
|
9
|
+
this.tags = ((_a = definition === null || definition === void 0 ? void 0 : definition.tags) !== null && _a !== void 0 ? _a : []).concat(["Element"]).concat(defaultTags);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.Element = Element;
|
|
13
|
+
class TechnicalElement extends Element {
|
|
14
|
+
constructor(name, defaultTags = [], definition) {
|
|
15
|
+
super(name, defaultTags, definition);
|
|
16
|
+
this.technology = definition === null || definition === void 0 ? void 0 : definition.technology;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.TechnicalElement = TechnicalElement;
|
|
20
|
+
class Relationship {
|
|
21
|
+
constructor(source, destination, definition) {
|
|
22
|
+
var _a;
|
|
23
|
+
this.source = source;
|
|
24
|
+
this.destination = destination;
|
|
25
|
+
this.description = definition === null || definition === void 0 ? void 0 : definition.description;
|
|
26
|
+
this.technology = definition === null || definition === void 0 ? void 0 : definition.technology;
|
|
27
|
+
this.tags = ((_a = definition === null || definition === void 0 ? void 0 : definition.tags) !== null && _a !== void 0 ? _a : []).concat(["Relationship"]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Relationship = Relationship;
|
|
31
|
+
class Reference {
|
|
32
|
+
constructor(name) {
|
|
33
|
+
this.name = name;
|
|
34
|
+
this._references = new Map();
|
|
35
|
+
}
|
|
36
|
+
referenceChild(name, createChild) {
|
|
37
|
+
let reference = this._references.get(name);
|
|
38
|
+
if (!reference) {
|
|
39
|
+
reference = createChild(name);
|
|
40
|
+
this._references.set(name, reference);
|
|
41
|
+
}
|
|
42
|
+
return reference;
|
|
43
|
+
}
|
|
44
|
+
get references() {
|
|
45
|
+
return Array.from(this._references.values());
|
|
46
|
+
}
|
|
47
|
+
getChildElements(path) {
|
|
48
|
+
const result = Array.from(this._references.values()).flatMap(reference => {
|
|
49
|
+
const currentPath = `${path ? path : '' + this.name}.${reference.name}`;
|
|
50
|
+
return [currentPath, ...reference.getChildElements(currentPath)];
|
|
51
|
+
});
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.Reference = Reference;
|
|
56
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../../libs/c4-model/src/lib/core.ts"],"names":[],"mappings":";;;AAcA,MAA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,CAAA;IAG9D,CAAC;IAES,cAAc,CAAC,IAAY,EAAE,WAAgD;QACrF,IAAI,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC1C,IAAI,CAAC,SAAS,EAAE;YACd,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;YAC7B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;SACtC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,IAAW,UAAU;QACnB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAA;IAC9C,CAAC;IAEM,gBAAgB,CAAC,IAAa;QACnC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACvE,MAAM,WAAW,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,EAAE,CAAA;YACvE,OAAO,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAA;QAClE,CAAC,CAAC,CAAA;QACF,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AA1BD,8BA0BC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReferencedSoftwareSystem, SoftwareSystem, SoftwareSystemDefinition } from './softwareSystem';
|
|
2
|
+
import { Person, PersonDefinition, ReferencedPerson } from './person';
|
|
3
|
+
export declare class Model {
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(name: string);
|
|
6
|
+
private softwareSystems;
|
|
7
|
+
private referencedSoftwareSystems;
|
|
8
|
+
private people;
|
|
9
|
+
private referencedPeople;
|
|
10
|
+
defineSoftwareSystem(name: string, definition?: SoftwareSystemDefinition): SoftwareSystem;
|
|
11
|
+
referenceSoftwareSystem(name: string): ReferencedSoftwareSystem;
|
|
12
|
+
definePerson(name: string, definition?: PersonDefinition): Person;
|
|
13
|
+
referencePerson(name: string): ReferencedPerson;
|
|
14
|
+
validate(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function buildModel(modelName: string, globPath?: string): Promise<Model>;
|
package/src/lib/model.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildModel = exports.Model = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const glob_1 = require("glob");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const softwareSystem_1 = require("./softwareSystem");
|
|
8
|
+
const person_1 = require("./person");
|
|
9
|
+
class Model {
|
|
10
|
+
constructor(name) {
|
|
11
|
+
this.name = name;
|
|
12
|
+
this.softwareSystems = new Map();
|
|
13
|
+
this.referencedSoftwareSystems = new Map();
|
|
14
|
+
this.people = new Map();
|
|
15
|
+
this.referencedPeople = new Map();
|
|
16
|
+
}
|
|
17
|
+
defineSoftwareSystem(name, definition) {
|
|
18
|
+
if (this.softwareSystems.has(name)) {
|
|
19
|
+
throw Error(`A SoftwareSystem named '${name}' is defined elsewhere in this Model. A SoftwareSystem can be defined only once, but can be referenced multiple times.`);
|
|
20
|
+
}
|
|
21
|
+
const system = new softwareSystem_1.SoftwareSystem(name, definition);
|
|
22
|
+
this.softwareSystems.set(name, system);
|
|
23
|
+
return system;
|
|
24
|
+
}
|
|
25
|
+
referenceSoftwareSystem(name) {
|
|
26
|
+
let system = this.referencedSoftwareSystems.get(name);
|
|
27
|
+
if (!system) {
|
|
28
|
+
system = new softwareSystem_1.ReferencedSoftwareSystem(name);
|
|
29
|
+
this.referencedSoftwareSystems.set(name, system);
|
|
30
|
+
}
|
|
31
|
+
return system;
|
|
32
|
+
}
|
|
33
|
+
definePerson(name, definition) {
|
|
34
|
+
if (this.people.has(name)) {
|
|
35
|
+
throw Error(`A Person named '${name}' is defined elsewhere in this Model. A Person can be defined only once, but can be referenced multiple times.`);
|
|
36
|
+
}
|
|
37
|
+
const person = new person_1.Person(name, definition);
|
|
38
|
+
this.people.set(name, person);
|
|
39
|
+
return person;
|
|
40
|
+
}
|
|
41
|
+
referencePerson(name) {
|
|
42
|
+
let person = this.referencedPeople.get(name);
|
|
43
|
+
if (!person) {
|
|
44
|
+
person = new person_1.ReferencedPerson(name);
|
|
45
|
+
this.referencedPeople.set(name, person);
|
|
46
|
+
}
|
|
47
|
+
return person;
|
|
48
|
+
}
|
|
49
|
+
validate() {
|
|
50
|
+
const undefinedSoftwareSystems = Array.from(this.referencedSoftwareSystems.keys()).filter(name => !this.softwareSystems.has(name));
|
|
51
|
+
if (undefinedSoftwareSystems.length > 0) {
|
|
52
|
+
throw Error(`SoftwareSystems named '${undefinedSoftwareSystems.join("', '")}' are referenced but not defined.`);
|
|
53
|
+
}
|
|
54
|
+
const undefinedPeople = Array.from(this.referencedPeople.keys()).filter(name => !this.people.has(name));
|
|
55
|
+
if (undefinedPeople.length > 0) {
|
|
56
|
+
throw Error(`People named '${undefinedPeople.join("', '")}' are referenced but not defined.`);
|
|
57
|
+
}
|
|
58
|
+
const definedElements = Array.from(this.softwareSystems.values()).flatMap(system => system.getChildElements());
|
|
59
|
+
const referencedElements = Array.from(this.referencedSoftwareSystems.values()).flatMap(system => system.getChildElements());
|
|
60
|
+
const undefinedElements = referencedElements.filter(name => !definedElements.includes(name));
|
|
61
|
+
if (undefinedElements.length > 0) {
|
|
62
|
+
throw Error(`Elements named '${undefinedElements.join("', '")}' are referenced but not defined.`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.Model = Model;
|
|
67
|
+
function buildModel(modelName, globPath = 'c4.dsl.ts') {
|
|
68
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const model = new Model(modelName);
|
|
70
|
+
const result = yield (0, glob_1.glob)(`**/${globPath}`, { cwd: __dirname });
|
|
71
|
+
if (result.length === 0) {
|
|
72
|
+
throw new Error(`No ${globPath} files found`);
|
|
73
|
+
}
|
|
74
|
+
for (const file of result) {
|
|
75
|
+
const moduleFile = (0, path_1.join)(__dirname, file);
|
|
76
|
+
console.log(`Accumulating model from ${moduleFile}`);
|
|
77
|
+
const module = yield Promise.resolve(`${moduleFile}`).then(s => require(s));
|
|
78
|
+
if (typeof module.buildModel === 'function') {
|
|
79
|
+
module.buildModel(model);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.log(`${file} does not contain the method 'buildModel'`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
model.validate();
|
|
86
|
+
return model;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.buildModel = buildModel;
|
|
90
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../../libs/c4-model/src/lib/model.ts"],"names":[],"mappings":";;;;AAAA,+BAA2B;AAC3B,+BAA2B;AAE3B,qDAAsG;AACtG,qCAAqE;AAErE,MAAa,KAAK;IAChB,YAAmB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAEvB,oBAAe,GAAG,IAAI,GAAG,EAA0B,CAAC;QACpD,8BAAyB,GAAG,IAAI,GAAG,EAAoC,CAAC;QAExE,WAAM,GAAG,IAAI,GAAG,EAAkB,CAAA;QAClC,qBAAgB,GAAG,IAAI,GAAG,EAA4B,CAAA;IAN5B,CAAC;IAQnC,oBAAoB,CAAC,IAAY,EAAE,UAAqC;QACtE,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAClC,MAAM,KAAK,CAAC,2BAA2B,IAAI,wHAAwH,CAAC,CAAA;SACrK;QACD,MAAM,MAAM,GAAG,IAAI,+BAA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,sBAgEC;AAED,SAAsB,UAAU,CAAC,SAAiB,EAAE,WAAmB,WAAW;;QAChF,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,SAAS,CAAC,CAAA;QAElC,MAAM,MAAM,GAAG,MAAM,IAAA,WAAI,EAAC,MAAM,QAAQ,EAAE,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAA;QAE/D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,MAAM,QAAQ,cAAc,CAAC,CAAA;SAC9C;QAED,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;YACzB,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAA;YACxC,OAAO,CAAC,GAAG,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAA;YAEpD,MAAM,MAAM,GAAG,yBAAc,UAAU,yBAAC,CAAA;YACxC,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE;gBAC3C,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;aACzB;iBACI;gBACH,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,2CAA2C,CAAC,CAAA;aAChE;SACF;QAED,KAAK,CAAC,QAAQ,EAAE,CAAA;QAEhB,OAAO,KAAK,CAAA;IACd,CAAC;CAAA;AAzBD,gCAyBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Definition, Element, Reference } from './core';
|
|
2
|
+
export interface PersonDefinition extends Definition {
|
|
3
|
+
}
|
|
4
|
+
export declare class Person extends Element {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
constructor(name: string, definition?: PersonDefinition);
|
|
7
|
+
}
|
|
8
|
+
export declare class ReferencedPerson extends Reference<undefined> {
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReferencedPerson = exports.Person = void 0;
|
|
4
|
+
const core_1 = require("./core");
|
|
5
|
+
class Person extends core_1.Element {
|
|
6
|
+
constructor(name, definition) {
|
|
7
|
+
super(name, ["Person"], definition);
|
|
8
|
+
this.name = name;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.Person = Person;
|
|
12
|
+
class ReferencedPerson extends core_1.Reference {
|
|
13
|
+
}
|
|
14
|
+
exports.ReferencedPerson = ReferencedPerson;
|
|
15
|
+
//# sourceMappingURL=person.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"person.js","sourceRoot":"","sources":["../../../../../libs/c4-model/src/lib/person.ts"],"names":[],"mappings":";;;AAAA,iCAAuD;AAKvD,MAAa,MAAO,SAAQ,cAAO;IACjC,YAAqC,IAAY,EAAE,UAA6B;QAC9E,KAAK,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAA;QADA,SAAI,GAAJ,IAAI,CAAQ;IAEjD,CAAC;CACF;AAJD,wBAIC;AAED,MAAa,gBAAiB,SAAQ,gBAAoB;CACzD;AADD,4CACC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Definition, Element, Reference, Relationship, RelationshipTarget, TechnologyDefinition } from './core';
|
|
2
|
+
import { Container, ContainerDefinition, ReferencedContainer } from './container';
|
|
3
|
+
export interface SoftwareSystemDefinition extends Definition {
|
|
4
|
+
}
|
|
5
|
+
export interface SoftwareSystemReference {
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class SoftwareSystem extends Element {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
private _relationships;
|
|
11
|
+
private _containers;
|
|
12
|
+
constructor(name: string, definition?: SoftwareSystemDefinition);
|
|
13
|
+
uses(otherElement: RelationshipTarget, definition?: TechnologyDefinition): void;
|
|
14
|
+
get relationships(): ReadonlyArray<Relationship>;
|
|
15
|
+
defineContainer(name: string, definition?: ContainerDefinition): Container;
|
|
16
|
+
getChildElements(): ReadonlyArray<string>;
|
|
17
|
+
}
|
|
18
|
+
export declare class ReferencedSoftwareSystem extends Reference<Container> {
|
|
19
|
+
referenceContainer(name: string): ReferencedContainer;
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReferencedSoftwareSystem = exports.SoftwareSystem = void 0;
|
|
4
|
+
const core_1 = require("./core");
|
|
5
|
+
const container_1 = require("./container");
|
|
6
|
+
class SoftwareSystem extends core_1.Element {
|
|
7
|
+
constructor(name, definition) {
|
|
8
|
+
super(name, ["Software System"], definition);
|
|
9
|
+
this.name = name;
|
|
10
|
+
this._relationships = [];
|
|
11
|
+
this._containers = new Map();
|
|
12
|
+
}
|
|
13
|
+
uses(otherElement, definition) {
|
|
14
|
+
const relationship = new core_1.Relationship(this, otherElement, definition);
|
|
15
|
+
this._relationships.push(relationship);
|
|
16
|
+
}
|
|
17
|
+
get relationships() {
|
|
18
|
+
return this._relationships;
|
|
19
|
+
}
|
|
20
|
+
defineContainer(name, definition) {
|
|
21
|
+
if (this._containers.has(name)) {
|
|
22
|
+
throw Error(`A Container named '${name}' is defined elsewhere in this SoftwareSystem. A Container can be defined only once, but can be referenced multiple times.`);
|
|
23
|
+
}
|
|
24
|
+
const container = new container_1.Container(name, definition);
|
|
25
|
+
this._containers.set(name, container);
|
|
26
|
+
return container;
|
|
27
|
+
}
|
|
28
|
+
getChildElements() {
|
|
29
|
+
const result = Array.from(this._containers.values()).map(container => `${this.name}.${container.name}`);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.SoftwareSystem = SoftwareSystem;
|
|
34
|
+
class ReferencedSoftwareSystem extends core_1.Reference {
|
|
35
|
+
referenceContainer(name) {
|
|
36
|
+
const containerReference = this.referenceChild(name, (name) => new container_1.ReferencedContainer(name));
|
|
37
|
+
return containerReference;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.ReferencedSoftwareSystem = ReferencedSoftwareSystem;
|
|
41
|
+
//# sourceMappingURL=softwareSystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"softwareSystem.js","sourceRoot":"","sources":["../../../../../libs/c4-model/src/lib/softwareSystem.ts"],"names":[],"mappings":";;;AAAA,iCAA+G;AAC/G,2CAAiF;AASjF,MAAa,cAAe,SAAQ,cAAO;IAKzC,YAAqC,IAAY,EAAE,UAAqC;QACtF,KAAK,CAAC,IAAI,EAAE,CAAC,iBAAiB,CAAC,EAAE,UAAU,CAAC,CAAA;QADT,SAAI,GAAJ,IAAI,CAAQ;QAHzC,mBAAc,GAAmB,EAAE,CAAA;QACnC,gBAAW,GAAG,IAAI,GAAG,EAAqB,CAAC;IAInD,CAAC;IAEM,IAAI,CAAC,YAAgC,EAAE,UAAiC;QAC7E,MAAM,YAAY,GAAG,IAAI,mBAAY,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;QACrE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACxC,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;IAEM,eAAe,CAAC,IAAY,EAAE,UAAgC;QACnE,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC9B,MAAM,KAAK,CAAC,sBAAsB,IAAI,4HAA4H,CAAC,CAAA;SACpK;QAED,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QAEjD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAEtC,OAAO,SAAS,CAAA;IAClB,CAAC;IAEM,gBAAgB;QACrB,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,CAAA;QACvG,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAlCD,wCAkCC;AAED,MAAa,wBAAyB,SAAQ,gBAAoB;IAEzD,kBAAkB,CAAC,IAAY;QACpC,MAAM,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,+BAAmB,CAAC,IAAI,CAAC,CAAC,CAAA;QACrG,OAAO,kBAAyC,CAAA;IAClD,CAAC;CACF;AAND,4DAMC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildModel = void 0;
|
|
4
|
+
function buildModel(model) {
|
|
5
|
+
model.definePerson('person1');
|
|
6
|
+
model.referenceSoftwareSystem('softwareSystem1');
|
|
7
|
+
}
|
|
8
|
+
exports.buildModel = buildModel;
|
|
9
|
+
//# sourceMappingURL=c4.dsl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"c4.dsl.js","sourceRoot":"","sources":["../../../../../../../libs/c4-model/src/lib/tests/system1/c4.dsl.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CAAC,KAAY;IACrC,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;IAC7B,KAAK,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,CAAA;AAClD,CAAC;AAHD,gCAGC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildModel = void 0;
|
|
4
|
+
function buildModel(model) {
|
|
5
|
+
model.referencePerson('person1');
|
|
6
|
+
model.defineSoftwareSystem('softwareSystem1');
|
|
7
|
+
}
|
|
8
|
+
exports.buildModel = buildModel;
|
|
9
|
+
//# sourceMappingURL=c4.dsl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"c4.dsl.js","sourceRoot":"","sources":["../../../../../../../libs/c4-model/src/lib/tests/system2/c4.dsl.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CAAC,KAAY;IACrC,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;IAChC,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAA;AAC/C,CAAC;AAHD,gCAGC"}
|