@likec4/core 1.17.1 → 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 +22 -0
- package/dist/compute-view/index.d.ts +22 -0
- package/dist/compute-view/index.js +78 -0
- package/dist/index.d.mts +10 -919
- package/dist/index.d.ts +10 -919
- package/dist/{index.mjs → index.js} +7 -1688
- package/dist/model/index.d.mts +254 -0
- package/dist/model/index.d.ts +254 -0
- 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.CoLQkcYL.d.cts → core.C05RDLhi.d.ts} +460 -362
- package/dist/shared/{core.CoLQkcYL.d.mts → core.CmYMqgha.d.mts} +460 -362
- 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/{core.BXTs-8n7.mjs → view.CyZrG8BJ.js} +108 -47
- package/dist/types/index.d.mts +71 -1
- package/dist/types/index.d.ts +71 -1
- 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 +59 -47
- 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 +224 -0
- package/src/builder/Builder.deploymentModel.ts +385 -0
- package/src/builder/Builder.element.ts +19 -19
- package/src/builder/Builder.model.ts +67 -42
- package/src/builder/Builder.ts +533 -367
- 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 +113 -18
- package/src/builder/index.ts +10 -4
- package/src/colors/index.ts +2 -2
- package/src/compute-view/compute-view.ts +83 -0
- package/src/compute-view/deployment-view/__test__/TestHelper.ts +236 -0
- package/src/compute-view/deployment-view/__test__/fixture.ts +198 -0
- package/src/compute-view/deployment-view/_types.ts +37 -0
- package/src/compute-view/deployment-view/clean-connections.ts +238 -0
- package/src/compute-view/deployment-view/compute.ts +125 -0
- 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 +237 -0
- package/src/compute-view/deployment-view/predicates/relation-in-out.ts +61 -0
- package/src/compute-view/deployment-view/predicates/relation-incoming.ts +95 -0
- package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +88 -0
- package/src/compute-view/deployment-view/predicates/wildcard.ts +29 -0
- 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 +276 -0
- package/src/compute-view/dynamic-view/__test__/fixture.ts +58 -0
- package/src/compute-view/dynamic-view/compute.ts +324 -0
- package/src/compute-view/element-view/__test__/TestHelper.ts +258 -0
- package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +458 -0
- package/src/compute-view/element-view/__test__/fixture.ts +675 -0
- 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 +315 -0
- 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 +4 -0
- 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/__snapshots__/sortNodes.spec.ts.snap +113 -0
- package/src/compute-view/utils/ancestorsOfNode.ts +19 -0
- package/src/compute-view/utils/applyCustomElementProperties.ts +66 -0
- package/src/compute-view/utils/applyCustomRelationProperties.ts +41 -0
- package/src/compute-view/utils/applyViewRuleStyles.ts +53 -0
- package/src/compute-view/utils/buildComputedNodes.ts +148 -0
- package/src/compute-view/utils/buildElementNotations.ts +63 -0
- package/src/compute-view/utils/elementExpressionToPredicate.ts +50 -0
- package/src/compute-view/utils/link-nodes-with-edges.ts +54 -0
- package/src/compute-view/utils/merge-props-from-relationships.ts +128 -0
- package/src/compute-view/utils/relationExpressionToPredicates.ts +55 -0
- package/src/compute-view/utils/resolve-extended-views.ts +69 -0
- package/src/compute-view/utils/resolve-global-rules.ts +83 -0
- package/src/compute-view/utils/topological-sort.ts +256 -0
- package/src/compute-view/utils/uniqueTags.test.ts +42 -0
- package/src/compute-view/utils/uniqueTags.ts +21 -0
- package/src/compute-view/utils/view-hash.ts +27 -0
- package/src/compute-view/utils/with-readable-edges.ts +36 -0
- package/src/index.ts +22 -12
- package/src/model/DeploymentElementModel.ts +599 -0
- package/src/model/DeploymentModel.ts +370 -0
- package/src/model/ElementModel.ts +221 -0
- package/src/model/LikeC4Model.test-d.ts +152 -0
- package/src/model/LikeC4Model.ts +336 -457
- package/src/model/RelationModel.ts +85 -0
- package/src/model/__test__/fixture.ts +149 -338
- package/src/model/connection/Connection.ts +72 -0
- package/src/model/connection/deployment/DeploymentConnectionModel.ts +178 -0
- package/src/model/connection/deployment/find.ts +120 -0
- 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/find.ts +117 -0
- 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 +46 -2
- package/src/model/types.ts +112 -15
- package/src/model/view/EdgeModel.ts +103 -0
- package/src/model/view/LikeC4ViewModel.ts +226 -0
- package/src/model/view/NodeModel.ts +229 -0
- package/src/types/_common.ts +55 -1
- package/src/types/deployments.ts +169 -0
- package/src/types/element.ts +9 -5
- package/src/types/expression-v2.ts +172 -0
- package/src/types/expression.ts +17 -11
- package/src/types/global.ts +3 -3
- package/src/types/index.ts +220 -12
- package/src/types/model.ts +75 -12
- package/src/types/operators.ts +1 -1
- package/src/types/overview-graph.ts +2 -2
- package/src/types/relation.ts +18 -14
- package/src/types/theme.ts +0 -1
- package/src/types/view-notation.ts +2 -2
- package/src/types/view.ts +117 -41
- package/src/utils/{commonHead.ts → common-head.ts} +2 -0
- package/src/utils/const.ts +1 -0
- package/src/utils/fqn.ts +203 -56
- package/src/utils/getOrCreate.ts +42 -0
- package/src/utils/graphlib.ts +10 -0
- package/src/utils/index.ts +74 -6
- 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/object-hash.ts +3 -0
- package/src/utils/relations.ts +3 -64
- package/src/utils/set.ts +78 -0
- package/src/utils/string-hash.ts +16 -0
- package/dist/index.cjs +0 -5452
- package/dist/index.d.cts +0 -1053
- package/dist/shared/core.CoLQkcYL.d.ts +0 -734
- package/dist/shared/core.DIYZvpVg.cjs +0 -353
- package/dist/types/index.cjs +0 -70
- package/dist/types/index.d.cts +0 -2
- package/dist/types/index.mjs +0 -1
- package/src/builder/Builder.test-d.ts +0 -69
- package/src/builder/Builder.view.ts +0 -358
- package/src/model/LikeC4DiagramModel.ts +0 -338
- package/src/model/LikeC4ViewModel.ts +0 -320
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IteratorLike } from '../../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns an iterable that yields only unique values.
|
|
5
|
+
* It uses a Set to keep track of the values.
|
|
6
|
+
*/
|
|
7
|
+
export function iunique(): <T>(iterable: Iterable<T>) => IteratorLike<T>
|
|
8
|
+
export function iunique<T>(iterable: Iterable<T>): IteratorLike<T>
|
|
9
|
+
|
|
10
|
+
export function iunique<T>(iterable?: Iterable<T>): IteratorLike<T> | ((iterable: Iterable<T>) => IteratorLike<T>) {
|
|
11
|
+
if (iterable) {
|
|
12
|
+
return (function*(): IteratorLike<T> {
|
|
13
|
+
yield* _iunique(iterable)
|
|
14
|
+
return
|
|
15
|
+
})()
|
|
16
|
+
}
|
|
17
|
+
return _iunique
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function* _iunique<T>(iterable: Iterable<T>): IteratorLike<T> {
|
|
21
|
+
const seen = new Set<T>()
|
|
22
|
+
for (const item of iterable) {
|
|
23
|
+
if (!seen.has(item)) {
|
|
24
|
+
seen.add(item)
|
|
25
|
+
yield item
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return
|
|
29
|
+
}
|
package/src/utils/relations.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { Fqn } from '../types'
|
|
2
2
|
import { commonAncestor, compareFqnHierarchically, isAncestor } from './fqn'
|
|
3
3
|
|
|
4
|
-
type Relation = {
|
|
4
|
+
export type Relation = {
|
|
5
5
|
source: string
|
|
6
6
|
target: string
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
type RelationPredicate = (rel: Relation) => boolean
|
|
9
|
+
export type RelationPredicate = (rel: Relation) => boolean
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Compares two relations hierarchically.
|
|
13
13
|
* From the most general (implicit) to the most specific.
|
|
14
14
|
*/
|
|
15
|
-
export const compareRelations = <T extends { source: string; target: string }>(a: T, b: T) => {
|
|
15
|
+
export const compareRelations = <T extends { source: string; target: string }>(a: T, b: T): number => {
|
|
16
16
|
const parentA = commonAncestor(a.source as Fqn, a.target as Fqn)
|
|
17
17
|
const parentB = commonAncestor(b.source as Fqn, b.target as Fqn)
|
|
18
18
|
if (parentA && !parentB) {
|
|
@@ -31,64 +31,3 @@ export const compareRelations = <T extends { source: string; target: string }>(a
|
|
|
31
31
|
}
|
|
32
32
|
return compareFqnHierarchically(a.target, b.target)
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
export const isInside = (parent: Fqn): RelationPredicate => {
|
|
36
|
-
const prefix = parent + '.'
|
|
37
|
-
return (rel: Relation) => {
|
|
38
|
-
return rel.source.startsWith(prefix) && rel.target.startsWith(prefix)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const isBetween = (source: Fqn, target: Fqn): RelationPredicate => {
|
|
43
|
-
const sourcePrefix = source + '.'
|
|
44
|
-
const targetPrefix = target + '.'
|
|
45
|
-
return (rel: Relation) => {
|
|
46
|
-
return (
|
|
47
|
-
(rel.source === source || (rel.source + '.').startsWith(sourcePrefix))
|
|
48
|
-
&& (rel.target === target || (rel.target + '.').startsWith(targetPrefix))
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const isAnyBetween = (source: Fqn, target: Fqn): RelationPredicate => {
|
|
54
|
-
const predicates = [isBetween(source, target), isBetween(target, source)]
|
|
55
|
-
return (rel) => predicates.some(p => p(rel))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const isIncoming = (target: Fqn): RelationPredicate => {
|
|
59
|
-
const targetPrefix = target + '.'
|
|
60
|
-
return (rel: Relation) => {
|
|
61
|
-
return (
|
|
62
|
-
!(rel.source + '.').startsWith(targetPrefix)
|
|
63
|
-
&& (rel.target === target || (rel.target + '.').startsWith(targetPrefix))
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const isOutgoing = (source: Fqn): RelationPredicate => {
|
|
69
|
-
const sourcePrefix = source + '.'
|
|
70
|
-
return (rel: Relation) => {
|
|
71
|
-
return (
|
|
72
|
-
(rel.source === source || (rel.source + '.').startsWith(sourcePrefix))
|
|
73
|
-
&& !(rel.target + '.').startsWith(sourcePrefix)
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const isAnyInOut = (source: Fqn): RelationPredicate => {
|
|
79
|
-
const predicates = [isIncoming(source), isOutgoing(source)]
|
|
80
|
-
return (rel: Relation) => {
|
|
81
|
-
return predicates.some(p => p(rel))
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const hasRelation = <R extends { source: Fqn; target: Fqn }>(rel: R) => {
|
|
86
|
-
return <E extends { id: Fqn }>(element: E) => {
|
|
87
|
-
return (
|
|
88
|
-
rel.source === element.id
|
|
89
|
-
|| rel.target === element.id
|
|
90
|
-
|| isAncestor(element.id, rel.source)
|
|
91
|
-
|| isAncestor(element.id, rel.target)
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
}
|
package/src/utils/set.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { intersection as _intersection, symmetricDifference as _symmetricDifference } from 'mnemonist/set'
|
|
2
|
+
import type { NonEmptyArray } from '../types/_common'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns new set as a union of given sets
|
|
6
|
+
* Keeps order of elements
|
|
7
|
+
*/
|
|
8
|
+
export function union<T>(...sets: ReadonlySet<T>[]): Set<T> {
|
|
9
|
+
let result = new Set<T>()
|
|
10
|
+
for (const set of sets) {
|
|
11
|
+
for (const value of set) {
|
|
12
|
+
result.add(value)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return result
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns new set as an intersection of all sets
|
|
20
|
+
* Keeps order from the first set
|
|
21
|
+
*/
|
|
22
|
+
export function intersection<T>(first: ReadonlySet<T>, ...sets: NonEmptyArray<ReadonlySet<NoInfer<T>>>): Set<T> {
|
|
23
|
+
let result = new Set<T>()
|
|
24
|
+
// If first set is empty, return empty set
|
|
25
|
+
if (first.size === 0) {
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
let other = sets.length > 1 ? _intersection(...sets as any) : sets[0]
|
|
29
|
+
if (other.size === 0) {
|
|
30
|
+
return result
|
|
31
|
+
}
|
|
32
|
+
for (const value of first) {
|
|
33
|
+
if (other.has(value)) {
|
|
34
|
+
result.add(value)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function difference<T>(a: ReadonlySet<T>, b: ReadonlySet<NoInfer<T>>): Set<T> {
|
|
41
|
+
if (a.size === 0) {
|
|
42
|
+
return new Set<T>()
|
|
43
|
+
}
|
|
44
|
+
if (b.size === 0) {
|
|
45
|
+
return new Set(a)
|
|
46
|
+
}
|
|
47
|
+
let result = new Set<T>()
|
|
48
|
+
for (const value of a) {
|
|
49
|
+
if (!b.has(value)) {
|
|
50
|
+
result.add(value)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return result
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function equals<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean {
|
|
57
|
+
return a.size === b.size && [...a].every(value => b.has(value))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function symmetricDifference<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): Set<T> {
|
|
61
|
+
return _symmetricDifference(a as Set<T>, b as Set<T>)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function hasIntersection<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean {
|
|
65
|
+
if (a.size === 0 || b.size === 0) {
|
|
66
|
+
return false
|
|
67
|
+
}
|
|
68
|
+
// Swap sets to iterate over smaller set
|
|
69
|
+
if (b.size < a.size) {
|
|
70
|
+
;[a, b] = [b, a]
|
|
71
|
+
}
|
|
72
|
+
for (const value of a) {
|
|
73
|
+
if (b.has(value)) {
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { invariant } from '../errors'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @see https://gist.github.com/victor-homyakov/bcb7d7911e4a388b1c810f8c3ce17bcf
|
|
5
|
+
*/
|
|
6
|
+
export function stringHash(str: string): string {
|
|
7
|
+
let hash = 5381
|
|
8
|
+
const len = str.length
|
|
9
|
+
invariant(len > 0, 'stringHash: empty string')
|
|
10
|
+
|
|
11
|
+
for (let i = 0; i < len; i++) {
|
|
12
|
+
hash = (hash * 33) ^ str.charCodeAt(i)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (hash >>> 0).toString(36)
|
|
16
|
+
}
|