@likec4/core 1.18.0 → 1.19.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/LICENSE +1 -1
- package/dist/builder/index.d.mts +502 -0
- package/dist/builder/index.d.ts +502 -0
- package/dist/builder/index.js +871 -0
- package/dist/compute-view/index.d.mts +9 -78
- package/dist/compute-view/index.d.ts +9 -78
- package/dist/compute-view/index.js +78 -0
- package/dist/index.d.mts +9 -730
- package/dist/index.d.ts +9 -730
- package/dist/{index.mjs → index.js} +7 -784
- package/dist/model/index.d.mts +218 -606
- package/dist/model/index.d.ts +218 -606
- package/dist/model/index.js +1 -0
- package/dist/shared/chunk-RAAYCPUM.M-JWF7SS.js +21 -0
- package/dist/shared/core.BIfgabEw.d.ts +719 -0
- package/dist/shared/core.BZ9Msq7w.d.mts +719 -0
- package/dist/shared/{core.DMYY7C8s.d.mts → core.C05RDLhi.d.ts} +179 -230
- package/dist/shared/{core.DMYY7C8s.d.ts → core.CmYMqgha.d.mts} +179 -230
- package/dist/shared/core.D6-fWbM3.d.ts +127 -0
- package/dist/shared/core.D74xkKkG.d.mts +148 -0
- package/dist/shared/core.D74xkKkG.d.ts +148 -0
- package/dist/shared/core.sLaWHBjR.d.mts +127 -0
- package/dist/shared/index.-BdzdI2C.js +7443 -0
- package/dist/shared/object_hash.CE_oF3I3.js +1222 -0
- package/dist/shared/view.CyZrG8BJ.js +354 -0
- package/dist/types/index.d.mts +4 -2
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.js +20 -0
- package/dist/utils/index.d.mts +404 -0
- package/dist/utils/index.d.ts +404 -0
- package/dist/utils/index.js +330 -0
- package/package.json +47 -33
- package/src/builder/Builder-style1.test-d.ts +190 -0
- package/src/builder/Builder-style2.test-d.ts +175 -0
- package/src/builder/Builder.deployment.ts +25 -20
- package/src/builder/Builder.deploymentModel.ts +80 -55
- package/src/builder/Builder.element.ts +2 -0
- package/src/builder/Builder.model.ts +57 -43
- package/src/builder/Builder.ts +412 -431
- package/src/builder/Builder.view-common.ts +234 -0
- package/src/builder/Builder.view-deployment.ts +135 -0
- package/src/builder/Builder.view-element.ts +189 -0
- package/src/builder/Builder.views.ts +109 -33
- package/src/builder/Builder.with.ts +475 -0
- package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +374 -0
- package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +183 -0
- package/src/builder/__snapshots__/Builder.spec.ts.snap +374 -0
- package/src/builder/_types.ts +28 -5
- package/src/builder/index.ts +10 -4
- package/src/colors/index.ts +2 -2
- package/src/compute-view/compute-view.ts +45 -54
- package/src/compute-view/deployment-view/__test__/TestHelper.ts +236 -0
- package/src/compute-view/deployment-view/__test__/fixture.ts +50 -62
- package/src/compute-view/deployment-view/_types.ts +26 -18
- package/src/compute-view/deployment-view/clean-connections.ts +173 -164
- package/src/compute-view/deployment-view/compute.ts +51 -37
- package/src/compute-view/deployment-view/memory/index.ts +9 -0
- package/src/compute-view/deployment-view/memory/memory.ts +97 -0
- package/src/compute-view/deployment-view/predicates/elements.ts +144 -0
- package/src/compute-view/deployment-view/predicates/relation-direct.ts +183 -76
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +38 -20
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +72 -23
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +61 -22
- package/src/compute-view/deployment-view/predicates/wildcard.ts +15 -15
- package/src/compute-view/deployment-view/stages/stage-exclude.ts +5 -0
- package/src/compute-view/deployment-view/stages/stage-final.ts +245 -0
- package/src/compute-view/deployment-view/stages/stage-include.ts +95 -0
- package/src/compute-view/deployment-view/utils.ts +95 -31
- package/src/compute-view/dynamic-view/__test__/fixture.ts +4 -4
- package/src/compute-view/dynamic-view/compute.ts +59 -45
- package/src/compute-view/element-view/__test__/TestHelper.ts +258 -0
- package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +64 -62
- package/src/compute-view/element-view/__test__/fixture.ts +147 -117
- package/src/compute-view/element-view/_types.ts +48 -0
- package/src/compute-view/element-view/clean-connections.ts +113 -0
- package/src/compute-view/element-view/compute.ts +264 -683
- package/src/compute-view/element-view/memory/NodeGroup.ts +31 -0
- package/src/compute-view/element-view/memory/index.ts +10 -0
- package/src/compute-view/element-view/memory/memory.ts +177 -0
- package/src/compute-view/element-view/memory/stage-exclude.ts +59 -0
- package/src/compute-view/element-view/memory/stage-final.ts +129 -0
- package/src/compute-view/element-view/memory/stage-include.ts +128 -0
- package/src/compute-view/element-view/predicates/_utils.ts +86 -0
- package/src/compute-view/element-view/predicates/element-expand.ts +33 -0
- package/src/compute-view/element-view/predicates/element-kind-tag.ts +26 -0
- package/src/compute-view/element-view/predicates/element-ref.ts +37 -0
- package/src/compute-view/element-view/predicates/relation-direct.ts +309 -0
- package/src/compute-view/element-view/predicates/relation-in-out.ts +66 -0
- package/src/compute-view/element-view/predicates/relation-in.ts +118 -0
- package/src/compute-view/element-view/predicates/relation-out.ts +116 -0
- package/src/compute-view/element-view/predicates/wildcard.ts +88 -0
- package/src/compute-view/element-view/utils.ts +59 -0
- package/src/compute-view/index.ts +3 -4
- package/src/compute-view/memory/AbstractMemory.ts +45 -0
- package/src/compute-view/memory/AbstractStageExclude.ts +216 -0
- package/src/compute-view/memory/AbstractStageInclude.ts +200 -0
- package/src/compute-view/memory/_types.ts +147 -0
- package/src/compute-view/memory/index.ts +5 -0
- package/src/compute-view/memory/ops.ts +43 -0
- package/src/compute-view/utils/buildComputedNodes.ts +4 -4
- package/src/compute-view/utils/elementExpressionToPredicate.ts +1 -3
- package/src/compute-view/utils/link-nodes-with-edges.ts +3 -7
- package/src/compute-view/utils/{derive-edge-props-from-relationships.ts → merge-props-from-relationships.ts} +54 -23
- package/src/compute-view/utils/relationExpressionToPredicates.ts +2 -2
- package/src/compute-view/utils/resolve-extended-views.ts +44 -40
- package/src/compute-view/utils/resolve-global-rules.ts +6 -6
- package/src/compute-view/utils/topological-sort.ts +167 -71
- package/src/compute-view/utils/with-readable-edges.ts +14 -9
- package/src/index.ts +22 -16
- package/src/model/DeploymentElementModel.ts +150 -85
- package/src/model/DeploymentModel.ts +27 -21
- package/src/model/ElementModel.ts +51 -25
- package/src/model/LikeC4Model.test-d.ts +4 -3
- package/src/model/LikeC4Model.ts +98 -42
- package/src/model/RelationModel.ts +5 -4
- package/src/model/__test__/fixture.ts +5 -9
- package/src/model/connection/Connection.ts +72 -0
- package/src/model/connection/deployment/DeploymentConnectionModel.ts +178 -0
- package/src/model/connection/{deployment.ts → deployment/find.ts} +14 -18
- package/src/model/connection/deployment/index.ts +8 -0
- package/src/model/connection/index.ts +22 -0
- package/src/model/connection/model/ConnectionModel.ts +157 -0
- package/src/model/connection/{model.ts → model/find.ts} +43 -49
- package/src/model/connection/model/index.ts +8 -0
- package/src/model/connection/ops.ts +274 -0
- package/src/model/guards.ts +9 -0
- package/src/model/index.ts +45 -3
- package/src/model/types.ts +35 -18
- package/src/model/view/EdgeModel.ts +6 -6
- package/src/model/view/LikeC4ViewModel.ts +14 -8
- package/src/model/view/NodeModel.ts +6 -5
- package/src/types/_common.ts +53 -1
- package/src/types/deployments.ts +88 -156
- package/src/types/element.ts +2 -2
- package/src/types/expression-v2.ts +172 -0
- package/src/types/expression.ts +9 -5
- package/src/types/global.ts +3 -3
- package/src/types/index.ts +220 -13
- package/src/types/model.ts +28 -24
- package/src/types/operators.ts +1 -1
- package/src/types/relation.ts +14 -10
- package/src/types/theme.ts +0 -1
- package/src/types/view.ts +20 -18
- package/src/utils/const.ts +1 -0
- package/src/utils/fqn.ts +140 -49
- package/src/utils/getOrCreate.ts +1 -1
- package/src/utils/index.ts +74 -9
- package/src/utils/iterable/_types.ts +5 -0
- package/src/utils/iterable/filter.ts +55 -0
- package/src/utils/iterable/flat.ts +17 -0
- package/src/utils/iterable/index.ts +12 -0
- package/src/utils/iterable/map.ts +40 -0
- package/src/utils/iterable/reduce.ts +24 -0
- package/src/utils/iterable/some.ts +36 -0
- package/src/utils/iterable/to.ts +19 -0
- package/src/utils/iterable/unique.ts +29 -0
- package/src/utils/relations.ts +3 -64
- package/src/utils/set.ts +11 -9
- package/src/utils/string-hash.ts +1 -1
- package/dist/compute-view/index.mjs +0 -79
- package/dist/model/index.mjs +0 -2
- package/dist/shared/core.BBgiAAv1.mjs +0 -144
- package/dist/shared/core.BPyJvuMU.mjs +0 -2420
- package/dist/shared/core.BQ4AbfvB.mjs +0 -9228
- package/dist/shared/core.k12s_keD.mjs +0 -203
- package/dist/types/index.mjs +0 -21
- package/src/builder/Builder.test-d.ts +0 -124
- package/src/builder/Builder.view.ts +0 -543
- package/src/compute-view/LikeC4ModelGraph.ts +0 -330
- package/src/compute-view/deployment-view/Memory.ts +0 -108
- package/src/compute-view/deployment-view/Stage.ts +0 -145
- package/src/compute-view/deployment-view/predicates/deployment-ref.ts +0 -146
- package/src/compute-view/element-view/predicates.ts +0 -517
- package/src/compute-view/utils/sortNodes.ts +0 -101
- package/src/model/connection/ConnectionModel.ts +0 -94
- package/src/model/connection/DeploymentConnectionModel.ts +0 -99
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { T as requireIterator, S as requireForeach, R as getDefaultExportFromCjs, b as t, W as n, f as commonAncestor, h as compareFqnHierarchically } from '../shared/object_hash.CE_oF3I3.js';
|
|
2
|
+
export { D as DefaultMap, e as ancestorsFqn, c as commonHead, g as compareByFqnHierarchically, d as compareNatural, H as difference, I as equalsSet, v as getOrCreate, i as hasAtLeast, j as hierarchyDistance, k as hierarchyLevel, y as ifilter, z as iflat, A as imap, J as intersection, o as isAncestor, q as isDescendantOf, B as isIterable, w as isNonEmptyArray, a as isSameHierarchy, x as isString, C as isome, E as iunique, n as nameFromFqn, N as objectHash, p as parentFqn, s as sortByFqnHierarchically, r as sortNaturalByFqn, u as sortParentsFirst, M as stringHash, K as symmetricDifference, F as toArray, G as toSet, L as union } from '../shared/object_hash.CE_oF3I3.js';
|
|
3
|
+
import { i as invariant } from '../shared/chunk-RAAYCPUM.M-JWF7SS.js';
|
|
4
|
+
|
|
5
|
+
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)}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Mnemonist Linked List
|
|
9
|
+
* ======================
|
|
10
|
+
*
|
|
11
|
+
* Singly linked list implementation. Uses raw JavaScript objects as nodes
|
|
12
|
+
* as benchmarks proved it was the fastest thing to do.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
var linkedList$1;
|
|
16
|
+
var hasRequiredLinkedList;
|
|
17
|
+
|
|
18
|
+
function requireLinkedList () {
|
|
19
|
+
if (hasRequiredLinkedList) return linkedList$1;
|
|
20
|
+
hasRequiredLinkedList = 1;
|
|
21
|
+
var Iterator = requireIterator(),
|
|
22
|
+
forEach = requireForeach();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Linked List.
|
|
26
|
+
*
|
|
27
|
+
* @constructor
|
|
28
|
+
*/
|
|
29
|
+
function LinkedList() {
|
|
30
|
+
this.clear();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Method used to clear the list.
|
|
35
|
+
*
|
|
36
|
+
* @return {undefined}
|
|
37
|
+
*/
|
|
38
|
+
LinkedList.prototype.clear = function() {
|
|
39
|
+
|
|
40
|
+
// Properties
|
|
41
|
+
this.head = null;
|
|
42
|
+
this.tail = null;
|
|
43
|
+
this.size = 0;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Method used to get the first item of the list.
|
|
48
|
+
*
|
|
49
|
+
* @return {any}
|
|
50
|
+
*/
|
|
51
|
+
LinkedList.prototype.first = function() {
|
|
52
|
+
return this.head ? this.head.item : undefined;
|
|
53
|
+
};
|
|
54
|
+
LinkedList.prototype.peek = LinkedList.prototype.first;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Method used to get the last item of the list.
|
|
58
|
+
*
|
|
59
|
+
* @return {any}
|
|
60
|
+
*/
|
|
61
|
+
LinkedList.prototype.last = function() {
|
|
62
|
+
return this.tail ? this.tail.item : undefined;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Method used to add an item at the end of the list.
|
|
67
|
+
*
|
|
68
|
+
* @param {any} item - The item to add.
|
|
69
|
+
* @return {number}
|
|
70
|
+
*/
|
|
71
|
+
LinkedList.prototype.push = function(item) {
|
|
72
|
+
var node = {item: item, next: null};
|
|
73
|
+
|
|
74
|
+
if (!this.head) {
|
|
75
|
+
this.head = node;
|
|
76
|
+
this.tail = node;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.tail.next = node;
|
|
80
|
+
this.tail = node;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.size++;
|
|
84
|
+
|
|
85
|
+
return this.size;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Method used to add an item at the beginning of the list.
|
|
90
|
+
*
|
|
91
|
+
* @param {any} item - The item to add.
|
|
92
|
+
* @return {number}
|
|
93
|
+
*/
|
|
94
|
+
LinkedList.prototype.unshift = function(item) {
|
|
95
|
+
var node = {item: item, next: null};
|
|
96
|
+
|
|
97
|
+
if (!this.head) {
|
|
98
|
+
this.head = node;
|
|
99
|
+
this.tail = node;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (!this.head.next)
|
|
103
|
+
this.tail = this.head;
|
|
104
|
+
node.next = this.head;
|
|
105
|
+
this.head = node;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.size++;
|
|
109
|
+
|
|
110
|
+
return this.size;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Method used to retrieve & remove the first item of the list.
|
|
115
|
+
*
|
|
116
|
+
* @return {any}
|
|
117
|
+
*/
|
|
118
|
+
LinkedList.prototype.shift = function() {
|
|
119
|
+
if (!this.size)
|
|
120
|
+
return undefined;
|
|
121
|
+
|
|
122
|
+
var node = this.head;
|
|
123
|
+
|
|
124
|
+
this.head = node.next;
|
|
125
|
+
this.size--;
|
|
126
|
+
|
|
127
|
+
return node.item;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Method used to iterate over the list.
|
|
132
|
+
*
|
|
133
|
+
* @param {function} callback - Function to call for each item.
|
|
134
|
+
* @param {object} scope - Optional scope.
|
|
135
|
+
* @return {undefined}
|
|
136
|
+
*/
|
|
137
|
+
LinkedList.prototype.forEach = function(callback, scope) {
|
|
138
|
+
if (!this.size)
|
|
139
|
+
return;
|
|
140
|
+
|
|
141
|
+
scope = arguments.length > 1 ? scope : this;
|
|
142
|
+
|
|
143
|
+
var n = this.head,
|
|
144
|
+
i = 0;
|
|
145
|
+
|
|
146
|
+
while (n) {
|
|
147
|
+
callback.call(scope, n.item, i, this);
|
|
148
|
+
n = n.next;
|
|
149
|
+
i++;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Method used to convert the list into an array.
|
|
155
|
+
*
|
|
156
|
+
* @return {array}
|
|
157
|
+
*/
|
|
158
|
+
LinkedList.prototype.toArray = function() {
|
|
159
|
+
if (!this.size)
|
|
160
|
+
return [];
|
|
161
|
+
|
|
162
|
+
var array = new Array(this.size);
|
|
163
|
+
|
|
164
|
+
for (var i = 0, l = this.size, n = this.head; i < l; i++) {
|
|
165
|
+
array[i] = n.item;
|
|
166
|
+
n = n.next;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return array;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Method used to create an iterator over a list's values.
|
|
174
|
+
*
|
|
175
|
+
* @return {Iterator}
|
|
176
|
+
*/
|
|
177
|
+
LinkedList.prototype.values = function() {
|
|
178
|
+
var n = this.head;
|
|
179
|
+
|
|
180
|
+
return new Iterator(function() {
|
|
181
|
+
if (!n)
|
|
182
|
+
return {
|
|
183
|
+
done: true
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
var value = n.item;
|
|
187
|
+
n = n.next;
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
value: value,
|
|
191
|
+
done: false
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Method used to create an iterator over a list's entries.
|
|
198
|
+
*
|
|
199
|
+
* @return {Iterator}
|
|
200
|
+
*/
|
|
201
|
+
LinkedList.prototype.entries = function() {
|
|
202
|
+
var n = this.head,
|
|
203
|
+
i = 0;
|
|
204
|
+
|
|
205
|
+
return new Iterator(function() {
|
|
206
|
+
if (!n)
|
|
207
|
+
return {
|
|
208
|
+
done: true
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
var value = n.item;
|
|
212
|
+
n = n.next;
|
|
213
|
+
i++;
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
value: [i - 1, value],
|
|
217
|
+
done: false
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Attaching the #.values method to Symbol.iterator if possible.
|
|
224
|
+
*/
|
|
225
|
+
if (typeof Symbol !== 'undefined')
|
|
226
|
+
LinkedList.prototype[Symbol.iterator] = LinkedList.prototype.values;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Convenience known methods.
|
|
230
|
+
*/
|
|
231
|
+
LinkedList.prototype.toString = function() {
|
|
232
|
+
return this.toArray().join(',');
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
LinkedList.prototype.toJSON = function() {
|
|
236
|
+
return this.toArray();
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
LinkedList.prototype.inspect = function() {
|
|
240
|
+
var array = this.toArray();
|
|
241
|
+
|
|
242
|
+
// Trick so that node displays the name of the constructor
|
|
243
|
+
Object.defineProperty(array, 'constructor', {
|
|
244
|
+
value: LinkedList,
|
|
245
|
+
enumerable: false
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
return array;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
if (typeof Symbol !== 'undefined')
|
|
252
|
+
LinkedList.prototype[Symbol.for('nodejs.util.inspect.custom')] = LinkedList.prototype.inspect;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Static @.from function taking an arbitrary iterable & converting it into
|
|
256
|
+
* a list.
|
|
257
|
+
*
|
|
258
|
+
* @param {Iterable} iterable - Target iterable.
|
|
259
|
+
* @return {LinkedList}
|
|
260
|
+
*/
|
|
261
|
+
LinkedList.from = function(iterable) {
|
|
262
|
+
var list = new LinkedList();
|
|
263
|
+
|
|
264
|
+
forEach(iterable, function(value) {
|
|
265
|
+
list.push(value);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
return list;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Exporting.
|
|
273
|
+
*/
|
|
274
|
+
linkedList$1 = LinkedList;
|
|
275
|
+
return linkedList$1;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
var linkedListExports = requireLinkedList();
|
|
279
|
+
const linkedList = /*@__PURE__*/getDefaultExportFromCjs(linkedListExports);
|
|
280
|
+
|
|
281
|
+
function ireduce(arg1, arg2, arg3) {
|
|
282
|
+
const reducer = n(arg3) ? arg2 : arg1;
|
|
283
|
+
const initialValue = arg3 ?? arg2;
|
|
284
|
+
invariant(t(reducer));
|
|
285
|
+
function _reduce(iter) {
|
|
286
|
+
let acc = initialValue;
|
|
287
|
+
for (const value of iter) {
|
|
288
|
+
acc = reducer(acc, value);
|
|
289
|
+
}
|
|
290
|
+
return acc;
|
|
291
|
+
}
|
|
292
|
+
return n(arg3) ? _reduce(arg1) : _reduce;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const DELAY = "LIKEC4_DELAY";
|
|
296
|
+
function delay(...args) {
|
|
297
|
+
let ms = 100;
|
|
298
|
+
if (args.length === 2) {
|
|
299
|
+
ms = o(args[0], args[1]);
|
|
300
|
+
} else if (args.length === 1) {
|
|
301
|
+
ms = args[0];
|
|
302
|
+
}
|
|
303
|
+
return new Promise((resolve) => {
|
|
304
|
+
setTimeout(() => {
|
|
305
|
+
resolve(DELAY);
|
|
306
|
+
}, ms ?? 100);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const compareRelations = (a, b) => {
|
|
311
|
+
const parentA = commonAncestor(a.source, a.target);
|
|
312
|
+
const parentB = commonAncestor(b.source, b.target);
|
|
313
|
+
if (parentA && !parentB) {
|
|
314
|
+
return 1;
|
|
315
|
+
}
|
|
316
|
+
if (!parentA && parentB) {
|
|
317
|
+
return -1;
|
|
318
|
+
}
|
|
319
|
+
const compareParents = parentA && parentB ? compareFqnHierarchically(parentA, parentB) : 0;
|
|
320
|
+
if (compareParents !== 0) {
|
|
321
|
+
return compareParents;
|
|
322
|
+
}
|
|
323
|
+
const compareSource = compareFqnHierarchically(a.source, b.source);
|
|
324
|
+
if (compareSource !== 0) {
|
|
325
|
+
return compareSource;
|
|
326
|
+
}
|
|
327
|
+
return compareFqnHierarchically(a.target, b.target);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
export { linkedList as LinkedList, commonAncestor, compareFqnHierarchically, compareRelations, delay, ireduce };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://likec4.dev",
|
|
6
6
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
@@ -29,65 +29,79 @@
|
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
-
"
|
|
33
|
-
"default":
|
|
32
|
+
"development": "./src/index.ts",
|
|
33
|
+
"default": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./builder": {
|
|
40
|
+
"development": "./src/builder/index.ts",
|
|
41
|
+
"default": {
|
|
42
|
+
"types": "./dist/builder/index.d.ts",
|
|
43
|
+
"import": "./dist/builder/index.js",
|
|
44
|
+
"default": "./dist/builder/index.js"
|
|
45
|
+
}
|
|
34
46
|
},
|
|
35
47
|
"./compute-view": {
|
|
36
|
-
"
|
|
37
|
-
"default":
|
|
48
|
+
"development": "./src/compute-view/index.ts",
|
|
49
|
+
"default": {
|
|
50
|
+
"types": "./dist/compute-view/index.d.ts",
|
|
51
|
+
"import": "./dist/compute-view/index.js",
|
|
52
|
+
"default": "./dist/compute-view/index.js"
|
|
53
|
+
}
|
|
38
54
|
},
|
|
39
55
|
"./model": {
|
|
40
|
-
"
|
|
41
|
-
"default":
|
|
56
|
+
"development": "./src/model/index.ts",
|
|
57
|
+
"default": {
|
|
58
|
+
"types": "./dist/model/index.d.ts",
|
|
59
|
+
"import": "./dist/model/index.js",
|
|
60
|
+
"default": "./dist/model/index.js"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"./utils": {
|
|
64
|
+
"development": "./src/utils/index.ts",
|
|
65
|
+
"default": {
|
|
66
|
+
"types": "./dist/utils/index.d.ts",
|
|
67
|
+
"import": "./dist/utils/index.js",
|
|
68
|
+
"default": "./dist/utils/index.js"
|
|
69
|
+
}
|
|
42
70
|
},
|
|
43
71
|
"./types": {
|
|
44
|
-
"
|
|
45
|
-
"default":
|
|
72
|
+
"development": "./src/types/index.ts",
|
|
73
|
+
"default": {
|
|
74
|
+
"types": "./dist/types/index.d.ts",
|
|
75
|
+
"import": "./dist/types/index.js",
|
|
76
|
+
"default": "./dist/types/index.js"
|
|
77
|
+
}
|
|
46
78
|
}
|
|
47
79
|
},
|
|
48
80
|
"publishConfig": {
|
|
49
81
|
"registry": "https://registry.npmjs.org",
|
|
50
|
-
"access": "public"
|
|
51
|
-
"exports": {
|
|
52
|
-
".": {
|
|
53
|
-
"types": "./dist/index.d.mts",
|
|
54
|
-
"default": "./dist/index.mjs"
|
|
55
|
-
},
|
|
56
|
-
"./compute-view": {
|
|
57
|
-
"types": "./dist/compute-view/index.d.mts",
|
|
58
|
-
"default": "./dist/compute-view/index.mjs"
|
|
59
|
-
},
|
|
60
|
-
"./model": {
|
|
61
|
-
"types": "./dist/model/index.d.mts",
|
|
62
|
-
"default": "./dist/model/index.mjs"
|
|
63
|
-
},
|
|
64
|
-
"./types": {
|
|
65
|
-
"types": "./dist/types/index.d.mts",
|
|
66
|
-
"default": "./dist/types/index.mjs"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
82
|
+
"access": "public"
|
|
69
83
|
},
|
|
70
84
|
"dependencies": {
|
|
71
|
-
"defu": "^6.1.4",
|
|
72
85
|
"type-fest": "4.28.1"
|
|
73
86
|
},
|
|
74
87
|
"devDependencies": {
|
|
75
|
-
"@
|
|
76
|
-
"@
|
|
77
|
-
"@mantine/colors-generator": "7.15.1",
|
|
88
|
+
"@likec4/tsconfig": "1.19.0",
|
|
89
|
+
"@mantine/colors-generator": "7.15.2",
|
|
78
90
|
"@types/natural-compare-lite": "^1.4.2",
|
|
79
91
|
"@types/object-hash": "^3.0.6",
|
|
80
92
|
"chroma-js": "^3.1.2",
|
|
93
|
+
"defu": "^6.1.4",
|
|
81
94
|
"graphology": "^0.25.4",
|
|
82
95
|
"graphology-dag": "^0.4.1",
|
|
83
96
|
"graphology-types": "^0.24.8",
|
|
84
97
|
"mnemonist": "^0.39.8",
|
|
85
98
|
"natural-compare-lite": "^1.4.0",
|
|
86
99
|
"object-hash": "^3.0.0",
|
|
100
|
+
"obliterator": "^2.0.4",
|
|
87
101
|
"remeda": "^2.17.4",
|
|
88
102
|
"turbo": "^2.3.3",
|
|
89
103
|
"typescript": "^5.7.2",
|
|
90
|
-
"unbuild": "^3.
|
|
104
|
+
"unbuild": "^3.1.0",
|
|
91
105
|
"vitest": "^2.1.8"
|
|
92
106
|
},
|
|
93
107
|
"packageManager": "yarn@4.5.3"
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { expectTypeOf, test } from 'vitest'
|
|
2
|
+
import type { LikeC4Model } from '../model/LikeC4Model'
|
|
3
|
+
import type { ParsedLikeC4Model } from '../types'
|
|
4
|
+
import { Builder } from './Builder'
|
|
5
|
+
|
|
6
|
+
test('Builder types - style 1', () => {
|
|
7
|
+
const {
|
|
8
|
+
model: {
|
|
9
|
+
model,
|
|
10
|
+
actor,
|
|
11
|
+
system,
|
|
12
|
+
component,
|
|
13
|
+
relTo,
|
|
14
|
+
},
|
|
15
|
+
deployment: {
|
|
16
|
+
deployment,
|
|
17
|
+
instanceOf,
|
|
18
|
+
env,
|
|
19
|
+
vm,
|
|
20
|
+
},
|
|
21
|
+
views: {
|
|
22
|
+
deploymentView,
|
|
23
|
+
views,
|
|
24
|
+
view,
|
|
25
|
+
viewOf,
|
|
26
|
+
$rules,
|
|
27
|
+
$include,
|
|
28
|
+
},
|
|
29
|
+
builder,
|
|
30
|
+
} = Builder.forSpecification({
|
|
31
|
+
elements: {
|
|
32
|
+
actor: {
|
|
33
|
+
style: {
|
|
34
|
+
shape: 'person',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
system: {},
|
|
38
|
+
component: {},
|
|
39
|
+
},
|
|
40
|
+
deployments: {
|
|
41
|
+
env: {},
|
|
42
|
+
vm: {},
|
|
43
|
+
},
|
|
44
|
+
relationships: {
|
|
45
|
+
like: {},
|
|
46
|
+
dislike: {},
|
|
47
|
+
},
|
|
48
|
+
tags: ['tag1', 'tag2', 'tag1'],
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const m = builder
|
|
52
|
+
.with(
|
|
53
|
+
model(
|
|
54
|
+
actor('alice'),
|
|
55
|
+
actor('bob'),
|
|
56
|
+
system('cloud').with(
|
|
57
|
+
component('backend').with(
|
|
58
|
+
component('api'),
|
|
59
|
+
component('db'),
|
|
60
|
+
),
|
|
61
|
+
component('frontend').with(
|
|
62
|
+
relTo('cloud.backend.api'),
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
deployment(
|
|
67
|
+
env('prod').with(
|
|
68
|
+
vm('vm1'),
|
|
69
|
+
),
|
|
70
|
+
env('prod.vm2'),
|
|
71
|
+
env('dev').with(
|
|
72
|
+
vm('vm1'),
|
|
73
|
+
instanceOf('cloud.backend.api'),
|
|
74
|
+
instanceOf(
|
|
75
|
+
'wrong',
|
|
76
|
+
// @ts-expect-error
|
|
77
|
+
'non-existing',
|
|
78
|
+
),
|
|
79
|
+
vm('vm2'),
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
views(
|
|
83
|
+
view(
|
|
84
|
+
'view',
|
|
85
|
+
// @ts-expect-error
|
|
86
|
+
$include('wrong'),
|
|
87
|
+
), // rules inside
|
|
88
|
+
view(
|
|
89
|
+
'view',
|
|
90
|
+
// @ts-expect-error #tag22 is not defined
|
|
91
|
+
$include('cloud.backend', {
|
|
92
|
+
where: 'tag is #tag22',
|
|
93
|
+
}),
|
|
94
|
+
),
|
|
95
|
+
// using with
|
|
96
|
+
view('view').with(
|
|
97
|
+
// @ts-expect-error
|
|
98
|
+
$include('wrong'),
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
$style('wrong', { color: 'red' }),
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
views(
|
|
104
|
+
viewOf('view-of', 'cloud.backend.api'),
|
|
105
|
+
// @ts-expect-error
|
|
106
|
+
viewOf('view-of', 'wrong'),
|
|
107
|
+
viewOf(
|
|
108
|
+
'view-of',
|
|
109
|
+
'cloud.backend.api',
|
|
110
|
+
$rules(
|
|
111
|
+
$include('* -> *'),
|
|
112
|
+
// @ts-expect-error
|
|
113
|
+
$include('wrong'),
|
|
114
|
+
),
|
|
115
|
+
),
|
|
116
|
+
viewOf(
|
|
117
|
+
'view-of',
|
|
118
|
+
// @ts-expect-error
|
|
119
|
+
'-cloud.backend.api',
|
|
120
|
+
'Title',
|
|
121
|
+
),
|
|
122
|
+
viewOf(
|
|
123
|
+
'view-of',
|
|
124
|
+
// @ts-expect-error
|
|
125
|
+
'-cloud.backend.api',
|
|
126
|
+
$rules(),
|
|
127
|
+
),
|
|
128
|
+
viewOf(
|
|
129
|
+
'view-of',
|
|
130
|
+
'cloud.backend.api',
|
|
131
|
+
{ title: 'asdasd' },
|
|
132
|
+
$rules(
|
|
133
|
+
$include('* -> *'),
|
|
134
|
+
// @ts-expect-error
|
|
135
|
+
$include('wrong'),
|
|
136
|
+
),
|
|
137
|
+
),
|
|
138
|
+
),
|
|
139
|
+
views(
|
|
140
|
+
deploymentView(
|
|
141
|
+
'deployment',
|
|
142
|
+
$rules(
|
|
143
|
+
// @ts-expect-error
|
|
144
|
+
$include('pr'),
|
|
145
|
+
),
|
|
146
|
+
),
|
|
147
|
+
deploymentView(
|
|
148
|
+
'deployment',
|
|
149
|
+
'Title',
|
|
150
|
+
$rules(
|
|
151
|
+
// @ts-expect-error
|
|
152
|
+
$include('pr'),
|
|
153
|
+
),
|
|
154
|
+
),
|
|
155
|
+
deploymentView('deployment').with(
|
|
156
|
+
// @ts-expect-error
|
|
157
|
+
$include('pr'),
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
expectTypeOf(m.Types.Fqn).toEqualTypeOf(
|
|
163
|
+
'' as 'alice' | 'bob' | 'cloud' | 'cloud.backend' | 'cloud.backend.api' | 'cloud.backend.db' | 'cloud.frontend',
|
|
164
|
+
)
|
|
165
|
+
expectTypeOf(m.Types.ViewId).toEqualTypeOf(
|
|
166
|
+
'' as 'view' | 'view-of' | 'deployment',
|
|
167
|
+
)
|
|
168
|
+
expectTypeOf(m.Types.DeploymentFqn).toEqualTypeOf(
|
|
169
|
+
'' as 'prod' | 'dev' | 'prod.vm1' | 'prod.vm2' | 'dev.vm1' | 'dev.vm2' | 'dev.api' | 'dev.wrong',
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
expectTypeOf(m.build()).toEqualTypeOf(
|
|
173
|
+
{} as ParsedLikeC4Model<
|
|
174
|
+
'actor' | 'system' | 'component',
|
|
175
|
+
'like' | 'dislike',
|
|
176
|
+
'tag1' | 'tag2',
|
|
177
|
+
'alice' | 'bob' | 'cloud' | 'cloud.backend' | 'cloud.backend.api' | 'cloud.backend.db' | 'cloud.frontend',
|
|
178
|
+
'view' | 'view-of' | 'deployment',
|
|
179
|
+
'prod' | 'dev' | 'prod.vm1' | 'prod.vm2' | 'dev.vm1' | 'dev.vm2' | 'dev.api' | 'dev.wrong'
|
|
180
|
+
>,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
expectTypeOf(m.toLikeC4Model()).toEqualTypeOf(
|
|
184
|
+
{} as LikeC4Model.Computed<
|
|
185
|
+
'alice' | 'bob' | 'cloud' | 'cloud.backend' | 'cloud.backend.api' | 'cloud.backend.db' | 'cloud.frontend',
|
|
186
|
+
'prod' | 'dev' | 'prod.vm1' | 'prod.vm2' | 'dev.vm1' | 'dev.vm2' | 'dev.api' | 'dev.wrong',
|
|
187
|
+
'view' | 'view-of' | 'deployment'
|
|
188
|
+
>,
|
|
189
|
+
)
|
|
190
|
+
})
|