@likec4/core 1.10.1 → 1.11.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/dist/index.cjs +406 -120
- package/dist/index.d.cts +202 -242
- package/dist/index.d.mts +202 -242
- package/dist/index.d.ts +202 -242
- package/dist/index.mjs +407 -122
- package/dist/shared/{core.DeifT5lC.mjs → core.CUlHblBQ.mjs} +5 -5
- package/dist/shared/{core.Czd51Dd8.d.cts → core.aVt8heZL.d.cts} +198 -354
- package/dist/shared/{core.Czd51Dd8.d.mts → core.aVt8heZL.d.mts} +198 -354
- package/dist/shared/{core.Czd51Dd8.d.ts → core.aVt8heZL.d.ts} +198 -354
- package/dist/types/index.cjs +1 -2
- package/dist/types/index.d.cts +2 -1
- package/dist/types/index.d.mts +2 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.mjs +1 -1
- package/package.json +10 -6
- package/src/index.ts +2 -0
- package/src/model/LikeC4DiagramModel.ts +338 -0
- package/src/model/LikeC4Model.ts +227 -145
- package/src/model/LikeC4ViewModel.ts +45 -43
- package/src/model/index.ts +3 -2
- package/src/model/types.ts +13 -0
- package/src/types/index.ts +0 -2
- package/src/types/model.ts +10 -1
- package/src/utils/promises.ts +13 -2
- package/src/model/__test__/LikeC4Model.spec.ts +0 -79
- package/src/utils/compare-natural.spec.ts +0 -37
- package/src/utils/fqn.spec.ts +0 -202
- package/src/utils/relations.spec.ts +0 -266
- package/dist/shared/{core.Db3ntVII.cjs → core.D78YmZ_A.cjs} +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { u, e, n as nonNullable, D as
|
|
2
|
-
export { A as AsFqn, B as BorderStyles,
|
|
1
|
+
import { u, e, n as nonNullable, D as DefaultRelationshipColor, a as DefaultElementShape, b as DefaultThemeColor } from './shared/core.CUlHblBQ.mjs';
|
|
2
|
+
export { A as AsFqn, B as BorderStyles, K as DefaultArrowType, J as DefaultLineStyle, E as ElementShapes, c as Expr, V as StepEdgeId, X as extractStep, $ as getBBoxCenter, Y as getParallelStepsPrefix, i as invariant, G as isAndOperator, Z as isComputedDynamicView, _ as isComputedElementView, h as isCustomElement, x as isCustomRelationExpr, R as isDynamicView, P as isDynamicViewIncludeRule, Q as isDynamicViewParallelSteps, m as isElement, k as isElementKindExpr, p as isElementPredicateExpr, f as isElementRef, l as isElementTagExpr, S as isElementView, o as isElementWhere, g as isExpandedElementExpr, T as isExtendsElementView, r as isInOut, s as isIncoming, C as isKindEqual, F as isNotOperator, H as isOrOperator, t as isOutgoing, q as isRelation, v as isRelationExpression, y as isRelationPredicateExpr, w as isRelationWhere, U as isScopedElementView, W as isStepEdgeId, z as isTagEqual, L as isThemeColor, O as isViewRuleAutoLayout, M as isViewRulePredicate, N as isViewRuleStyle, j as isWildcard, d as nonexhaustive, I as whereOperatorAsPredicate } from './shared/core.CUlHblBQ.mjs';
|
|
3
3
|
|
|
4
4
|
const { min: min$4, max: max$4 } = Math;
|
|
5
5
|
|
|
@@ -3655,14 +3655,256 @@ function computeColorValues(color) {
|
|
|
3655
3655
|
}
|
|
3656
3656
|
}
|
|
3657
3657
|
|
|
3658
|
-
function r$1(...
|
|
3658
|
+
function r$1(...n){return u(Object.values,n)}
|
|
3659
3659
|
|
|
3660
3660
|
function i(...e){return u(r,e)}var r=(e,t)=>e.length>=t;
|
|
3661
3661
|
|
|
3662
|
+
function o(r,n){let e=Math.ceil(r),t=Math.floor(n);if(t<e)throw new RangeError(`randomInteger: The range [${r.toString()},${n.toString()}] contains no integer`);return Math.floor(Math.random()*(t-e+1)+e)}
|
|
3663
|
+
|
|
3662
3664
|
function t(r){return typeof r=="string"}
|
|
3663
3665
|
|
|
3664
3666
|
function n(e){return !!e}
|
|
3665
3667
|
|
|
3668
|
+
function getId(element) {
|
|
3669
|
+
return t(element) ? element : element.id;
|
|
3670
|
+
}
|
|
3671
|
+
|
|
3672
|
+
class LikeC4DiagramModel {
|
|
3673
|
+
constructor(view, model) {
|
|
3674
|
+
this.view = view;
|
|
3675
|
+
this.model = model;
|
|
3676
|
+
for (const node of view.nodes) {
|
|
3677
|
+
const el = new LikeC4DiagramModel.Element(node, this);
|
|
3678
|
+
this._elements.set(node.id, el);
|
|
3679
|
+
if (e(node.parent)) {
|
|
3680
|
+
this._rootElements.add(el);
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
this._connections = new Map(view.edges.map((e) => [e.id, new LikeC4DiagramModel.Connection(e, this)]));
|
|
3684
|
+
}
|
|
3685
|
+
_rootElements = /* @__PURE__ */ new Set();
|
|
3686
|
+
_elements = /* @__PURE__ */ new Map();
|
|
3687
|
+
_connections;
|
|
3688
|
+
get isDynamic() {
|
|
3689
|
+
return this.view.__ === "dynamic";
|
|
3690
|
+
}
|
|
3691
|
+
get id() {
|
|
3692
|
+
return this.view.id;
|
|
3693
|
+
}
|
|
3694
|
+
get title() {
|
|
3695
|
+
return this.view.title;
|
|
3696
|
+
}
|
|
3697
|
+
get viewOf() {
|
|
3698
|
+
if (e(this.view.__) || this.view.__ === "element") {
|
|
3699
|
+
const computedView = this.view;
|
|
3700
|
+
return computedView.viewOf ? this.model.element(computedView.viewOf) : null;
|
|
3701
|
+
}
|
|
3702
|
+
return null;
|
|
3703
|
+
}
|
|
3704
|
+
get tags() {
|
|
3705
|
+
return this.view.tags ?? [];
|
|
3706
|
+
}
|
|
3707
|
+
roots() {
|
|
3708
|
+
return [...this._rootElements];
|
|
3709
|
+
}
|
|
3710
|
+
elements() {
|
|
3711
|
+
return [...this._elements.values()];
|
|
3712
|
+
}
|
|
3713
|
+
element(id) {
|
|
3714
|
+
return nonNullable(this._elements.get(id), `LikeC4DiagramModel.Element ${id} in view ${this.view.id} not found`);
|
|
3715
|
+
}
|
|
3716
|
+
hasElement(id) {
|
|
3717
|
+
return this._elements.has(id);
|
|
3718
|
+
}
|
|
3719
|
+
connections() {
|
|
3720
|
+
return [...this._connections.values()];
|
|
3721
|
+
}
|
|
3722
|
+
connection(id) {
|
|
3723
|
+
return nonNullable(this._connections.get(id), `Connection ${id} in view ${this.view.id} not found`);
|
|
3724
|
+
}
|
|
3725
|
+
findConnections(source, target, direction = "direct") {
|
|
3726
|
+
const sourceId = getId(source);
|
|
3727
|
+
const targetId = getId(target);
|
|
3728
|
+
return this.connections().filter(
|
|
3729
|
+
(c) => c.source.id === sourceId && c.target.id === targetId || direction === "both" && c.source.id === targetId && c.target.id === sourceId
|
|
3730
|
+
);
|
|
3731
|
+
}
|
|
3732
|
+
parent(element) {
|
|
3733
|
+
const el = this.element(getId(element));
|
|
3734
|
+
return el.node.parent ? this.element(el.node.parent) : null;
|
|
3735
|
+
}
|
|
3736
|
+
children(element) {
|
|
3737
|
+
const el = this.element(getId(element));
|
|
3738
|
+
return el.node.children.map((c) => this.element(c));
|
|
3739
|
+
}
|
|
3740
|
+
// Get all sibling (i.e. same parent)
|
|
3741
|
+
siblings(element) {
|
|
3742
|
+
const id = getId(element);
|
|
3743
|
+
const parent = this.parent(id);
|
|
3744
|
+
const siblings = parent ? this.children(parent) : this.roots();
|
|
3745
|
+
return siblings.filter((e) => e.id !== id);
|
|
3746
|
+
}
|
|
3747
|
+
/**
|
|
3748
|
+
* Get all ancestor elements (i.e. parent, parent’s parent, etc.)
|
|
3749
|
+
* (from closest to root)
|
|
3750
|
+
*/
|
|
3751
|
+
ancestors(element) {
|
|
3752
|
+
let id = getId(element);
|
|
3753
|
+
const result = [];
|
|
3754
|
+
let parent;
|
|
3755
|
+
while (parent = this.parent(id)) {
|
|
3756
|
+
result.push(parent);
|
|
3757
|
+
id = parent.id;
|
|
3758
|
+
}
|
|
3759
|
+
return result;
|
|
3760
|
+
}
|
|
3761
|
+
descendants(element) {
|
|
3762
|
+
const children = this.children(element);
|
|
3763
|
+
return children.flatMap((c) => [c, ...this.descendants(c.id)]);
|
|
3764
|
+
}
|
|
3765
|
+
incoming(element, filter = "all") {
|
|
3766
|
+
const el = this.element(getId(element));
|
|
3767
|
+
const edges = el.node.inEdges.map((e) => this.connection(e));
|
|
3768
|
+
if (filter === "all" || edges.length === 0) {
|
|
3769
|
+
return edges;
|
|
3770
|
+
}
|
|
3771
|
+
return edges.filter((rel) => {
|
|
3772
|
+
if (filter === "direct") {
|
|
3773
|
+
return rel.target.id === el.id;
|
|
3774
|
+
}
|
|
3775
|
+
return rel.target.id !== el.id;
|
|
3776
|
+
});
|
|
3777
|
+
}
|
|
3778
|
+
incomers(element, filter = "all") {
|
|
3779
|
+
return this.incoming(element, filter).map((r) => r.source);
|
|
3780
|
+
}
|
|
3781
|
+
/**
|
|
3782
|
+
* Outgoing relationships from the element and its descendants
|
|
3783
|
+
*/
|
|
3784
|
+
outgoing(element, filter = "all") {
|
|
3785
|
+
const el = this.element(getId(element));
|
|
3786
|
+
const edges = el.node.outEdges.map((e) => this.connection(e));
|
|
3787
|
+
if (filter === "all" || edges.length === 0) {
|
|
3788
|
+
return edges;
|
|
3789
|
+
}
|
|
3790
|
+
return edges.filter((rel) => {
|
|
3791
|
+
if (filter === "direct") {
|
|
3792
|
+
return rel.source.id === el.id;
|
|
3793
|
+
}
|
|
3794
|
+
return rel.source.id !== el.id;
|
|
3795
|
+
});
|
|
3796
|
+
}
|
|
3797
|
+
outgoers(element, filter = "all") {
|
|
3798
|
+
return this.outgoing(element, filter).map((r) => r.target);
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
((LikeC4DiagramModel2) => {
|
|
3802
|
+
class Element {
|
|
3803
|
+
constructor(node, view) {
|
|
3804
|
+
this.node = node;
|
|
3805
|
+
this.view = view;
|
|
3806
|
+
}
|
|
3807
|
+
get id() {
|
|
3808
|
+
return this.node.id;
|
|
3809
|
+
}
|
|
3810
|
+
get title() {
|
|
3811
|
+
return this.node.title;
|
|
3812
|
+
}
|
|
3813
|
+
get kind() {
|
|
3814
|
+
return this.node.kind;
|
|
3815
|
+
}
|
|
3816
|
+
get isRoot() {
|
|
3817
|
+
return e(this.node.parent);
|
|
3818
|
+
}
|
|
3819
|
+
get hasNested() {
|
|
3820
|
+
return this.node.children.length > 0;
|
|
3821
|
+
}
|
|
3822
|
+
get shape() {
|
|
3823
|
+
return this.node.shape;
|
|
3824
|
+
}
|
|
3825
|
+
get color() {
|
|
3826
|
+
return this.node.color;
|
|
3827
|
+
}
|
|
3828
|
+
get tags() {
|
|
3829
|
+
return this.node.tags ?? [];
|
|
3830
|
+
}
|
|
3831
|
+
get level() {
|
|
3832
|
+
return this.node.level;
|
|
3833
|
+
}
|
|
3834
|
+
get depth() {
|
|
3835
|
+
return this.node.depth ?? 0;
|
|
3836
|
+
}
|
|
3837
|
+
model() {
|
|
3838
|
+
return this.view.model.element(this.id);
|
|
3839
|
+
}
|
|
3840
|
+
parent() {
|
|
3841
|
+
return this.node.parent ? this.view.element(this.node.parent) : null;
|
|
3842
|
+
}
|
|
3843
|
+
metadata(key, defaultValue) {
|
|
3844
|
+
return this.model().metadata(key) ?? defaultValue;
|
|
3845
|
+
}
|
|
3846
|
+
hasMetadata(key) {
|
|
3847
|
+
return this.model().hasMetadata(key);
|
|
3848
|
+
}
|
|
3849
|
+
ancestors() {
|
|
3850
|
+
return this.view.ancestors(this);
|
|
3851
|
+
}
|
|
3852
|
+
siblings() {
|
|
3853
|
+
return this.view.siblings(this);
|
|
3854
|
+
}
|
|
3855
|
+
descendants() {
|
|
3856
|
+
return this.view.descendants(this);
|
|
3857
|
+
}
|
|
3858
|
+
children() {
|
|
3859
|
+
return this.view.children(this);
|
|
3860
|
+
}
|
|
3861
|
+
incoming(filter = "all") {
|
|
3862
|
+
return this.view.incoming(this, filter);
|
|
3863
|
+
}
|
|
3864
|
+
incomers(filter = "all") {
|
|
3865
|
+
return this.view.incomers(this, filter);
|
|
3866
|
+
}
|
|
3867
|
+
outgoing(filter = "all") {
|
|
3868
|
+
return this.view.outgoing(this, filter);
|
|
3869
|
+
}
|
|
3870
|
+
outgoers(filter = "all") {
|
|
3871
|
+
return this.view.outgoers(this, filter);
|
|
3872
|
+
}
|
|
3873
|
+
connectionsTo(target) {
|
|
3874
|
+
return this.view.findConnections(this, target);
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
LikeC4DiagramModel2.Element = Element;
|
|
3878
|
+
class Connection {
|
|
3879
|
+
constructor(edge, view) {
|
|
3880
|
+
this.edge = edge;
|
|
3881
|
+
this.view = view;
|
|
3882
|
+
}
|
|
3883
|
+
get id() {
|
|
3884
|
+
return this.edge.id;
|
|
3885
|
+
}
|
|
3886
|
+
get source() {
|
|
3887
|
+
return this.view.element(this.edge.source);
|
|
3888
|
+
}
|
|
3889
|
+
get target() {
|
|
3890
|
+
return this.view.element(this.edge.target);
|
|
3891
|
+
}
|
|
3892
|
+
get tags() {
|
|
3893
|
+
return this.edge.tags ?? [];
|
|
3894
|
+
}
|
|
3895
|
+
get color() {
|
|
3896
|
+
return this.edge.color ?? DefaultRelationshipColor;
|
|
3897
|
+
}
|
|
3898
|
+
/**
|
|
3899
|
+
* Model relationships
|
|
3900
|
+
*/
|
|
3901
|
+
relationships() {
|
|
3902
|
+
return this.edge.relations.map((r) => nonNullable(this.view.model.relationship(r)));
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
LikeC4DiagramModel2.Connection = Connection;
|
|
3906
|
+
})(LikeC4DiagramModel || (LikeC4DiagramModel = {}));
|
|
3907
|
+
|
|
3666
3908
|
function getDefaultExportFromCjs (x) {
|
|
3667
3909
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3668
3910
|
}
|
|
@@ -3860,16 +4102,16 @@ class LikeC4ViewModel {
|
|
|
3860
4102
|
this.model = model;
|
|
3861
4103
|
for (const node of view.nodes) {
|
|
3862
4104
|
const el = new LikeC4ViewModel.Element(node, this);
|
|
3863
|
-
this
|
|
4105
|
+
this._elements.set(node.id, el);
|
|
3864
4106
|
if (e(node.parent)) {
|
|
3865
|
-
this
|
|
4107
|
+
this._rootElements.add(el);
|
|
3866
4108
|
}
|
|
3867
4109
|
}
|
|
3868
|
-
this
|
|
4110
|
+
this._connections = new Map(view.edges.map((e) => [e.id, new LikeC4ViewModel.Connection(e, this)]));
|
|
3869
4111
|
}
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
4112
|
+
_rootElements = /* @__PURE__ */ new Set();
|
|
4113
|
+
_elements = /* @__PURE__ */ new Map();
|
|
4114
|
+
_connections;
|
|
3873
4115
|
get id() {
|
|
3874
4116
|
return this.view.id;
|
|
3875
4117
|
}
|
|
@@ -3886,41 +4128,41 @@ class LikeC4ViewModel {
|
|
|
3886
4128
|
return this.view.tags ?? [];
|
|
3887
4129
|
}
|
|
3888
4130
|
roots() {
|
|
3889
|
-
return [...this
|
|
4131
|
+
return [...this._rootElements];
|
|
3890
4132
|
}
|
|
3891
4133
|
elements() {
|
|
3892
|
-
return [...this
|
|
4134
|
+
return [...this._elements.values()];
|
|
3893
4135
|
}
|
|
3894
4136
|
element(id) {
|
|
3895
|
-
return nonNullable(this
|
|
4137
|
+
return nonNullable(this._elements.get(id), `LikeC4ViewModel.Element ${id} in view ${this.id} not found`);
|
|
3896
4138
|
}
|
|
3897
4139
|
hasElement(id) {
|
|
3898
|
-
return this
|
|
4140
|
+
return this._elements.has(id);
|
|
3899
4141
|
}
|
|
3900
4142
|
connections() {
|
|
3901
|
-
return [...this
|
|
4143
|
+
return [...this._connections.values()];
|
|
3902
4144
|
}
|
|
3903
4145
|
connection(id) {
|
|
3904
|
-
return nonNullable(this
|
|
4146
|
+
return nonNullable(this._connections.get(id), `Connection ${id} in view ${this.id} not found`);
|
|
3905
4147
|
}
|
|
3906
4148
|
findConnections(source, target, direction = "direct") {
|
|
3907
|
-
const sourceId =
|
|
3908
|
-
const targetId =
|
|
4149
|
+
const sourceId = getId(source);
|
|
4150
|
+
const targetId = getId(target);
|
|
3909
4151
|
return this.connections().filter(
|
|
3910
4152
|
(c) => c.source.id === sourceId && c.target.id === targetId || direction === "both" && c.source.id === targetId && c.target.id === sourceId
|
|
3911
4153
|
);
|
|
3912
4154
|
}
|
|
3913
4155
|
parent(element) {
|
|
3914
|
-
const el = this.element(
|
|
4156
|
+
const el = this.element(getId(element));
|
|
3915
4157
|
return el.node.parent ? this.element(el.node.parent) : null;
|
|
3916
4158
|
}
|
|
3917
4159
|
children(element) {
|
|
3918
|
-
const el = this.element(
|
|
4160
|
+
const el = this.element(getId(element));
|
|
3919
4161
|
return el.node.children.map((c) => this.element(c));
|
|
3920
4162
|
}
|
|
3921
4163
|
// Get all sibling (i.e. same parent)
|
|
3922
4164
|
siblings(element) {
|
|
3923
|
-
const id =
|
|
4165
|
+
const id = getId(element);
|
|
3924
4166
|
const parent = this.parent(id);
|
|
3925
4167
|
const siblings = parent ? this.children(parent) : this.roots();
|
|
3926
4168
|
return siblings.filter((e) => e.id !== id);
|
|
@@ -3930,7 +4172,7 @@ class LikeC4ViewModel {
|
|
|
3930
4172
|
* (from closest to root)
|
|
3931
4173
|
*/
|
|
3932
4174
|
ancestors(element) {
|
|
3933
|
-
let id =
|
|
4175
|
+
let id = getId(element);
|
|
3934
4176
|
const result = [];
|
|
3935
4177
|
let parent;
|
|
3936
4178
|
while (parent = this.parent(id)) {
|
|
@@ -3944,8 +4186,8 @@ class LikeC4ViewModel {
|
|
|
3944
4186
|
return children.flatMap((c) => [c, ...this.descendants(c.id)]);
|
|
3945
4187
|
}
|
|
3946
4188
|
incoming(element, filter = "all") {
|
|
3947
|
-
const el = this.element(
|
|
3948
|
-
const edges = el.node.inEdges.map((e) => nonNullable(this
|
|
4189
|
+
const el = this.element(getId(element));
|
|
4190
|
+
const edges = el.node.inEdges.map((e) => nonNullable(this._connections.get(e), `Edge ${e} not found`));
|
|
3949
4191
|
if (filter === "all" || edges.length === 0) {
|
|
3950
4192
|
return edges;
|
|
3951
4193
|
}
|
|
@@ -3963,8 +4205,8 @@ class LikeC4ViewModel {
|
|
|
3963
4205
|
* Outgoing relationships from the element and its descendants
|
|
3964
4206
|
*/
|
|
3965
4207
|
outgoing(element, filter = "all") {
|
|
3966
|
-
const el = this.element(
|
|
3967
|
-
const edges = el.node.outEdges.map((e) => nonNullable(this
|
|
4208
|
+
const el = this.element(getId(element));
|
|
4209
|
+
const edges = el.node.outEdges.map((e) => nonNullable(this._connections.get(e), `Edge ${e} not found`));
|
|
3968
4210
|
if (filter === "all" || edges.length === 0) {
|
|
3969
4211
|
return edges;
|
|
3970
4212
|
}
|
|
@@ -4077,103 +4319,126 @@ class LikeC4ViewModel {
|
|
|
4077
4319
|
LikeC4ViewModel2.Connection = Connection;
|
|
4078
4320
|
})(LikeC4ViewModel || (LikeC4ViewModel = {}));
|
|
4079
4321
|
|
|
4080
|
-
const RelationsSet = Set;
|
|
4081
|
-
const MapRelations = Map;
|
|
4082
4322
|
class LikeC4Model {
|
|
4083
|
-
constructor(
|
|
4084
|
-
this.
|
|
4085
|
-
|
|
4323
|
+
constructor(type, sourcemodel, elements, relations) {
|
|
4324
|
+
this.type = type;
|
|
4325
|
+
this.sourcemodel = sourcemodel;
|
|
4326
|
+
for (const el of elements) {
|
|
4086
4327
|
this.addElement(el);
|
|
4087
4328
|
}
|
|
4088
|
-
for (const rel of
|
|
4329
|
+
for (const rel of relations) {
|
|
4089
4330
|
this.addRelation(rel);
|
|
4090
4331
|
}
|
|
4091
|
-
this.#views = new Map(
|
|
4092
|
-
r$1(computed.views).map((v) => [v.id, new LikeC4ViewModel(v, this)])
|
|
4093
|
-
);
|
|
4094
4332
|
}
|
|
4095
|
-
|
|
4333
|
+
_elements = /* @__PURE__ */ new Map();
|
|
4096
4334
|
// Parent element for given FQN
|
|
4097
|
-
|
|
4335
|
+
_parents = /* @__PURE__ */ new Map();
|
|
4098
4336
|
// Children elements for given FQN
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4337
|
+
_children = /* @__PURE__ */ new Map();
|
|
4338
|
+
_rootElements = /* @__PURE__ */ new Set();
|
|
4339
|
+
_relations = /* @__PURE__ */ new Map();
|
|
4102
4340
|
// Incoming to an element or its descendants
|
|
4103
|
-
|
|
4341
|
+
_incoming = /* @__PURE__ */ new Map();
|
|
4104
4342
|
// Outgoing from an element or its descendants
|
|
4105
|
-
|
|
4343
|
+
_outgoing = /* @__PURE__ */ new Map();
|
|
4106
4344
|
// Relationships inside the element, among descendants
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
static
|
|
4111
|
-
|
|
4345
|
+
_internal = /* @__PURE__ */ new Map();
|
|
4346
|
+
_cacheAscendingSiblings = /* @__PURE__ */ new Map();
|
|
4347
|
+
_views = /* @__PURE__ */ new Map();
|
|
4348
|
+
static create(source) {
|
|
4349
|
+
if (source.__ === "layouted") {
|
|
4350
|
+
return LikeC4Model.layouted(source);
|
|
4351
|
+
}
|
|
4352
|
+
return LikeC4Model.computed(source);
|
|
4353
|
+
}
|
|
4354
|
+
static computed(source) {
|
|
4355
|
+
const instance = new LikeC4Model(
|
|
4356
|
+
"computed",
|
|
4357
|
+
source,
|
|
4358
|
+
r$1(source.elements),
|
|
4359
|
+
r$1(source.relations)
|
|
4360
|
+
);
|
|
4361
|
+
for (const view of r$1(source.views)) {
|
|
4362
|
+
instance._views.set(view.id, new LikeC4ViewModel(view, instance));
|
|
4363
|
+
}
|
|
4364
|
+
return instance;
|
|
4365
|
+
}
|
|
4366
|
+
static layouted(source) {
|
|
4367
|
+
const instance = new LikeC4Model(
|
|
4368
|
+
"layouted",
|
|
4369
|
+
source,
|
|
4370
|
+
r$1(source.elements),
|
|
4371
|
+
r$1(source.relations)
|
|
4372
|
+
);
|
|
4373
|
+
for (const view of r$1(source.views)) {
|
|
4374
|
+
instance._views.set(view.id, new LikeC4DiagramModel(view, instance));
|
|
4375
|
+
}
|
|
4376
|
+
return instance;
|
|
4112
4377
|
}
|
|
4113
4378
|
/**
|
|
4114
4379
|
* Returns the root elements of the model.
|
|
4115
4380
|
*/
|
|
4116
4381
|
roots() {
|
|
4117
|
-
return [...this
|
|
4382
|
+
return [...this._rootElements];
|
|
4118
4383
|
}
|
|
4119
4384
|
/**
|
|
4120
4385
|
* Returns all elements in the model.
|
|
4121
4386
|
*/
|
|
4122
4387
|
elements() {
|
|
4123
|
-
return [...this
|
|
4388
|
+
return [...this._elements.values()];
|
|
4124
4389
|
}
|
|
4125
4390
|
/**
|
|
4126
4391
|
* Returns a specific element by its FQN.
|
|
4127
4392
|
*/
|
|
4128
4393
|
element(id) {
|
|
4129
|
-
return nonNullable(this
|
|
4394
|
+
return nonNullable(this._elements.get(id), `Element ${id} not found`);
|
|
4130
4395
|
}
|
|
4131
4396
|
/**
|
|
4132
4397
|
* Returns all relationships in the model.
|
|
4133
4398
|
*/
|
|
4134
4399
|
relationships() {
|
|
4135
|
-
return [...this
|
|
4400
|
+
return [...this._relations.values()];
|
|
4136
4401
|
}
|
|
4137
4402
|
/**
|
|
4138
4403
|
* Returns a specific relationship by its ID.
|
|
4139
4404
|
*/
|
|
4140
4405
|
relationship(id) {
|
|
4141
|
-
return nonNullable(this
|
|
4406
|
+
return nonNullable(this._relations.get(id), `Relation ${id} not found`);
|
|
4142
4407
|
}
|
|
4143
4408
|
/**
|
|
4144
4409
|
* Returns all views in the model.
|
|
4145
4410
|
*/
|
|
4146
4411
|
views() {
|
|
4147
|
-
return [...this
|
|
4412
|
+
return [...this._views.values()];
|
|
4148
4413
|
}
|
|
4149
4414
|
/**
|
|
4150
4415
|
* Returns a specific view by its ID.
|
|
4151
4416
|
*/
|
|
4152
4417
|
view(viewId) {
|
|
4153
|
-
return nonNullable(this
|
|
4418
|
+
return nonNullable(this._views.get(viewId), `View ${viewId} not found`);
|
|
4154
4419
|
}
|
|
4155
4420
|
/**
|
|
4156
4421
|
* Returns the parent element of given element.
|
|
4157
4422
|
* @see ancestors
|
|
4158
4423
|
*/
|
|
4159
4424
|
parent(element) {
|
|
4160
|
-
const id =
|
|
4161
|
-
return this
|
|
4425
|
+
const id = getId(element);
|
|
4426
|
+
return this._parents.get(id) || null;
|
|
4162
4427
|
}
|
|
4163
4428
|
/**
|
|
4164
4429
|
* Get all children of the element (only direct children),
|
|
4165
4430
|
* @see descendants
|
|
4166
4431
|
*/
|
|
4167
4432
|
children(element) {
|
|
4168
|
-
const id =
|
|
4433
|
+
const id = getId(element);
|
|
4169
4434
|
return this._childrenOf(id);
|
|
4170
4435
|
}
|
|
4171
4436
|
/**
|
|
4172
4437
|
* Get all sibling (i.e. same parent)
|
|
4173
4438
|
*/
|
|
4174
4439
|
siblings(element) {
|
|
4175
|
-
const id =
|
|
4176
|
-
const parent = this
|
|
4440
|
+
const id = getId(element);
|
|
4441
|
+
const parent = this._parents.get(id);
|
|
4177
4442
|
const siblings = parent ? this._childrenOf(parent.id) : this.roots();
|
|
4178
4443
|
return siblings.filter((e) => e.id !== id);
|
|
4179
4444
|
}
|
|
@@ -4185,7 +4450,7 @@ class LikeC4Model {
|
|
|
4185
4450
|
let id = t(element) ? element : element.id;
|
|
4186
4451
|
const result = [];
|
|
4187
4452
|
let parent;
|
|
4188
|
-
while (parent = this
|
|
4453
|
+
while (parent = this._parents.get(id)) {
|
|
4189
4454
|
result.push(parent);
|
|
4190
4455
|
id = parent.id;
|
|
4191
4456
|
}
|
|
@@ -4195,7 +4460,7 @@ class LikeC4Model {
|
|
|
4195
4460
|
* Get all descendant elements (i.e. children, children’s children, etc.)
|
|
4196
4461
|
*/
|
|
4197
4462
|
descendants(element) {
|
|
4198
|
-
const id =
|
|
4463
|
+
const id = getId(element);
|
|
4199
4464
|
const children = this._childrenOf(id);
|
|
4200
4465
|
return children.flatMap((c) => [c, ...this.descendants(c.id)]);
|
|
4201
4466
|
}
|
|
@@ -4204,7 +4469,7 @@ class LikeC4Model {
|
|
|
4204
4469
|
* @see incomers
|
|
4205
4470
|
*/
|
|
4206
4471
|
incoming(element, filter = "all") {
|
|
4207
|
-
const id =
|
|
4472
|
+
const id = getId(element);
|
|
4208
4473
|
const incoming = Array.from(this._incomingTo(id));
|
|
4209
4474
|
if (filter === "all" || incoming.length === 0) {
|
|
4210
4475
|
return incoming;
|
|
@@ -4227,7 +4492,7 @@ class LikeC4Model {
|
|
|
4227
4492
|
* @see outgoers
|
|
4228
4493
|
*/
|
|
4229
4494
|
outgoing(element, filter = "all") {
|
|
4230
|
-
const id =
|
|
4495
|
+
const id = getId(element);
|
|
4231
4496
|
const outgoing = Array.from(this._outgoingFrom(id));
|
|
4232
4497
|
if (filter === "all" || outgoing.length === 0) {
|
|
4233
4498
|
return outgoing;
|
|
@@ -4249,7 +4514,7 @@ class LikeC4Model {
|
|
|
4249
4514
|
* Relationships inside the element, among descendants
|
|
4250
4515
|
*/
|
|
4251
4516
|
internal(element) {
|
|
4252
|
-
const id =
|
|
4517
|
+
const id = getId(element);
|
|
4253
4518
|
return Array.from(this._internalOf(id));
|
|
4254
4519
|
}
|
|
4255
4520
|
/**
|
|
@@ -4257,14 +4522,14 @@ class LikeC4Model {
|
|
|
4257
4522
|
* (from closest to root)
|
|
4258
4523
|
*/
|
|
4259
4524
|
ascendingSiblings(element) {
|
|
4260
|
-
const id =
|
|
4261
|
-
let siblings = this
|
|
4525
|
+
const id = getId(element);
|
|
4526
|
+
let siblings = this._cacheAscendingSiblings.get(id);
|
|
4262
4527
|
if (!siblings) {
|
|
4263
4528
|
siblings = [
|
|
4264
4529
|
...this.siblings(id),
|
|
4265
4530
|
...this.ancestors(id).flatMap((a) => this.siblings(a.id))
|
|
4266
4531
|
];
|
|
4267
|
-
this
|
|
4532
|
+
this._cacheAscendingSiblings.set(id, siblings);
|
|
4268
4533
|
}
|
|
4269
4534
|
return siblings.slice();
|
|
4270
4535
|
}
|
|
@@ -4272,29 +4537,29 @@ class LikeC4Model {
|
|
|
4272
4537
|
* Resolve all views that contain the element
|
|
4273
4538
|
*/
|
|
4274
4539
|
viewsWithElement(element) {
|
|
4275
|
-
const id =
|
|
4276
|
-
return [...this
|
|
4540
|
+
const id = getId(element);
|
|
4541
|
+
return [...this._views.values()].filter((v) => v.hasElement(id));
|
|
4277
4542
|
}
|
|
4278
4543
|
addElement(parsed) {
|
|
4279
|
-
if (this
|
|
4544
|
+
if (this._elements.has(parsed.id)) {
|
|
4280
4545
|
throw new Error(`Element ${parsed.id} already exists`);
|
|
4281
4546
|
}
|
|
4282
|
-
const el = new LikeC4Model.
|
|
4283
|
-
this
|
|
4547
|
+
const el = new LikeC4Model.ElementModel(parsed, this);
|
|
4548
|
+
this._elements.set(el.id, el);
|
|
4284
4549
|
const parentId = parentFqn(el.id);
|
|
4285
4550
|
if (parentId) {
|
|
4286
|
-
this
|
|
4551
|
+
this._parents.set(el.id, this.element(parentId));
|
|
4287
4552
|
this._childrenOf(parentId).push(el);
|
|
4288
4553
|
} else {
|
|
4289
|
-
this
|
|
4554
|
+
this._rootElements.add(el);
|
|
4290
4555
|
}
|
|
4291
4556
|
}
|
|
4292
4557
|
addRelation(relation) {
|
|
4293
|
-
if (this
|
|
4558
|
+
if (this._relations.has(relation.id)) {
|
|
4294
4559
|
throw new Error(`Relation ${relation.id} already exists`);
|
|
4295
4560
|
}
|
|
4296
4561
|
const rel = new LikeC4Model.Relationship(relation, this);
|
|
4297
|
-
this
|
|
4562
|
+
this._relations.set(rel.id, rel);
|
|
4298
4563
|
this._incomingTo(relation.target).add(rel);
|
|
4299
4564
|
this._outgoingFrom(relation.source).add(rel);
|
|
4300
4565
|
const relParent = commonAncestor(relation.source, relation.target);
|
|
@@ -4317,40 +4582,85 @@ class LikeC4Model {
|
|
|
4317
4582
|
}
|
|
4318
4583
|
}
|
|
4319
4584
|
_childrenOf(id) {
|
|
4320
|
-
let children = this
|
|
4585
|
+
let children = this._children.get(id);
|
|
4321
4586
|
if (!children) {
|
|
4322
4587
|
children = [];
|
|
4323
|
-
this
|
|
4588
|
+
this._children.set(id, children);
|
|
4324
4589
|
}
|
|
4325
4590
|
return children;
|
|
4326
4591
|
}
|
|
4327
4592
|
_incomingTo(id) {
|
|
4328
|
-
let incoming = this
|
|
4593
|
+
let incoming = this._incoming.get(id);
|
|
4329
4594
|
if (!incoming) {
|
|
4330
|
-
incoming = new
|
|
4331
|
-
this
|
|
4595
|
+
incoming = /* @__PURE__ */ new Set();
|
|
4596
|
+
this._incoming.set(id, incoming);
|
|
4332
4597
|
}
|
|
4333
4598
|
return incoming;
|
|
4334
4599
|
}
|
|
4335
4600
|
_outgoingFrom(id) {
|
|
4336
|
-
let outgoing = this
|
|
4601
|
+
let outgoing = this._outgoing.get(id);
|
|
4337
4602
|
if (!outgoing) {
|
|
4338
|
-
outgoing = new
|
|
4339
|
-
this
|
|
4603
|
+
outgoing = /* @__PURE__ */ new Set();
|
|
4604
|
+
this._outgoing.set(id, outgoing);
|
|
4340
4605
|
}
|
|
4341
4606
|
return outgoing;
|
|
4342
4607
|
}
|
|
4343
4608
|
_internalOf(id) {
|
|
4344
|
-
let internal = this
|
|
4609
|
+
let internal = this._internal.get(id);
|
|
4345
4610
|
if (!internal) {
|
|
4346
|
-
internal = new
|
|
4347
|
-
this
|
|
4611
|
+
internal = /* @__PURE__ */ new Set();
|
|
4612
|
+
this._internal.set(id, internal);
|
|
4348
4613
|
}
|
|
4349
4614
|
return internal;
|
|
4350
4615
|
}
|
|
4351
4616
|
}
|
|
4352
4617
|
((LikeC4Model2) => {
|
|
4353
|
-
|
|
4618
|
+
function isModel(model) {
|
|
4619
|
+
return model instanceof LikeC4Model2;
|
|
4620
|
+
}
|
|
4621
|
+
LikeC4Model2.isModel = isModel;
|
|
4622
|
+
((ViewModel2) => {
|
|
4623
|
+
function isLayouted2(model) {
|
|
4624
|
+
return model instanceof LikeC4DiagramModel;
|
|
4625
|
+
}
|
|
4626
|
+
ViewModel2.isLayouted = isLayouted2;
|
|
4627
|
+
})(LikeC4Model2.ViewModel || (LikeC4Model2.ViewModel = {}));
|
|
4628
|
+
function isLayouted(model) {
|
|
4629
|
+
return model.type === "layouted";
|
|
4630
|
+
}
|
|
4631
|
+
LikeC4Model2.isLayouted = isLayouted;
|
|
4632
|
+
class Relationship {
|
|
4633
|
+
constructor(relationship, model) {
|
|
4634
|
+
this.relationship = relationship;
|
|
4635
|
+
this.model = model;
|
|
4636
|
+
}
|
|
4637
|
+
get id() {
|
|
4638
|
+
return this.relationship.id;
|
|
4639
|
+
}
|
|
4640
|
+
get title() {
|
|
4641
|
+
return this.relationship.title;
|
|
4642
|
+
}
|
|
4643
|
+
get kind() {
|
|
4644
|
+
return this.relationship.kind ?? null;
|
|
4645
|
+
}
|
|
4646
|
+
get tags() {
|
|
4647
|
+
return this.relationship.tags ?? [];
|
|
4648
|
+
}
|
|
4649
|
+
get source() {
|
|
4650
|
+
return this.model.element(this.relationship.source);
|
|
4651
|
+
}
|
|
4652
|
+
get target() {
|
|
4653
|
+
return this.model.element(this.relationship.target);
|
|
4654
|
+
}
|
|
4655
|
+
metadata(key, defaultValue) {
|
|
4656
|
+
return this.relationship.metadata?.[key] ?? defaultValue;
|
|
4657
|
+
}
|
|
4658
|
+
hasMetadata(key) {
|
|
4659
|
+
return n(this.relationship.metadata?.[key]);
|
|
4660
|
+
}
|
|
4661
|
+
}
|
|
4662
|
+
LikeC4Model2.Relationship = Relationship;
|
|
4663
|
+
class ElementModel {
|
|
4354
4664
|
constructor(element, model) {
|
|
4355
4665
|
this.element = element;
|
|
4356
4666
|
this.model = model;
|
|
@@ -4425,46 +4735,21 @@ class LikeC4Model {
|
|
|
4425
4735
|
// return
|
|
4426
4736
|
// }
|
|
4427
4737
|
}
|
|
4428
|
-
LikeC4Model2.
|
|
4429
|
-
class Relationship {
|
|
4430
|
-
constructor(relationship, model) {
|
|
4431
|
-
this.relationship = relationship;
|
|
4432
|
-
this.model = model;
|
|
4433
|
-
}
|
|
4434
|
-
get id() {
|
|
4435
|
-
return this.relationship.id;
|
|
4436
|
-
}
|
|
4437
|
-
get title() {
|
|
4438
|
-
return this.relationship.title;
|
|
4439
|
-
}
|
|
4440
|
-
get kind() {
|
|
4441
|
-
return this.relationship.kind ?? null;
|
|
4442
|
-
}
|
|
4443
|
-
get tags() {
|
|
4444
|
-
return this.relationship.tags ?? [];
|
|
4445
|
-
}
|
|
4446
|
-
get source() {
|
|
4447
|
-
return this.model.element(this.relationship.source);
|
|
4448
|
-
}
|
|
4449
|
-
get target() {
|
|
4450
|
-
return this.model.element(this.relationship.target);
|
|
4451
|
-
}
|
|
4452
|
-
metadata(key, defaultValue) {
|
|
4453
|
-
return this.relationship.metadata?.[key] ?? defaultValue;
|
|
4454
|
-
}
|
|
4455
|
-
hasMetadata(key) {
|
|
4456
|
-
return n(this.relationship.metadata?.[key]);
|
|
4457
|
-
}
|
|
4458
|
-
}
|
|
4459
|
-
LikeC4Model2.Relationship = Relationship;
|
|
4738
|
+
LikeC4Model2.ElementModel = ElementModel;
|
|
4460
4739
|
})(LikeC4Model || (LikeC4Model = {}));
|
|
4461
4740
|
|
|
4462
4741
|
const DELAY = "LIKEC4_DELAY";
|
|
4463
|
-
function delay(
|
|
4742
|
+
function delay(...args) {
|
|
4743
|
+
let ms = 100;
|
|
4744
|
+
if (args.length === 2) {
|
|
4745
|
+
ms = o(args[0], args[1]);
|
|
4746
|
+
} else if (args.length === 1) {
|
|
4747
|
+
ms = args[0];
|
|
4748
|
+
}
|
|
4464
4749
|
return new Promise((resolve) => {
|
|
4465
4750
|
setTimeout(() => {
|
|
4466
4751
|
resolve(DELAY);
|
|
4467
|
-
}, ms);
|
|
4752
|
+
}, ms ?? 100);
|
|
4468
4753
|
});
|
|
4469
4754
|
}
|
|
4470
4755
|
|
|
@@ -4488,4 +4773,4 @@ const compareRelations = (a, b) => {
|
|
|
4488
4773
|
return compareFqnHierarchically(a.target, b.target);
|
|
4489
4774
|
};
|
|
4490
4775
|
|
|
4491
|
-
export { DefaultElementShape, DefaultThemeColor, ElementColors, LikeC4Model, LikeC4ViewModel, RelationshipColors, ancestorsFqn, commonAncestor, compareByFqnHierarchically, compareFqnHierarchically, compareNatural, compareRelations, computeColorValues, defaultTheme, delay, i as hasAtLeast, isAncestor, isDescendantOf, isNonEmptyArray, isSameHierarchy, isString, nameFromFqn, nonNullable, notDescendantOf, parentFqn, parentFqnPredicate, sortByFqnHierarchically, sortNaturalByFqn };
|
|
4776
|
+
export { DefaultElementShape, DefaultRelationshipColor, DefaultThemeColor, ElementColors, LikeC4DiagramModel, LikeC4Model, LikeC4ViewModel, RelationshipColors, ancestorsFqn, commonAncestor, compareByFqnHierarchically, compareFqnHierarchically, compareNatural, compareRelations, computeColorValues, defaultTheme, delay, i as hasAtLeast, isAncestor, isDescendantOf, isNonEmptyArray, isSameHierarchy, isString, nameFromFqn, nonNullable, notDescendantOf, parentFqn, parentFqnPredicate, sortByFqnHierarchically, sortNaturalByFqn };
|