@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,127 @@
|
|
|
1
|
+
import { F as Fqn } from './core.D74xkKkG.js';
|
|
2
|
+
|
|
3
|
+
declare function parentFqn<E extends string>(fqn: E): E | null;
|
|
4
|
+
declare function nameFromFqn<E extends string>(fqn: E): string;
|
|
5
|
+
/**
|
|
6
|
+
* Check if one element is an ancestor of another
|
|
7
|
+
* Composable version
|
|
8
|
+
* @signature
|
|
9
|
+
* isAncestor(another)(ancestor)
|
|
10
|
+
*/
|
|
11
|
+
declare function isAncestor<A extends string | {
|
|
12
|
+
id: string;
|
|
13
|
+
}>(another: NoInfer<A>): (ancestor: A) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Check if one element is an ancestor of another
|
|
16
|
+
* @signature
|
|
17
|
+
* isAncestor(ancestor, another)
|
|
18
|
+
*/
|
|
19
|
+
declare function isAncestor<A extends string | {
|
|
20
|
+
id: string;
|
|
21
|
+
}>(ancestor: A, another: A): boolean;
|
|
22
|
+
declare function isSameHierarchy<T extends string>(one: NoInfer<T> | WithId<NoInfer<T>>): (another: T | WithId<T>) => boolean;
|
|
23
|
+
declare function isSameHierarchy<T extends string>(one: T | WithId<T>, another: T | WithId<T>): boolean;
|
|
24
|
+
type WithId<T> = {
|
|
25
|
+
id: T;
|
|
26
|
+
};
|
|
27
|
+
declare function isDescendantOf<T extends string>(ancestor: WithId<T>): (descedant: WithId<T>) => boolean;
|
|
28
|
+
declare function isDescendantOf<T extends string>(descedant: WithId<T>, ancestor: WithId<T>): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* How deep in the hierarchy the element is.
|
|
31
|
+
* Root element has depth 1
|
|
32
|
+
*/
|
|
33
|
+
declare function hierarchyLevel<E extends string | {
|
|
34
|
+
id: Fqn;
|
|
35
|
+
}>(elementOfFqn: E): number;
|
|
36
|
+
/**
|
|
37
|
+
* Calculate the distance as number of steps from one element to another, i.e.
|
|
38
|
+
* going up to the common ancestor, then going down to the other element.
|
|
39
|
+
* Sibling distance is always 1
|
|
40
|
+
*
|
|
41
|
+
* Can be used for hierarchical clustering
|
|
42
|
+
*/
|
|
43
|
+
declare function hierarchyDistance<E extends string | {
|
|
44
|
+
id: Fqn;
|
|
45
|
+
}>(one: E, another: E): number;
|
|
46
|
+
declare function commonAncestor<E extends string>(first: E, second: E): E | null;
|
|
47
|
+
/**
|
|
48
|
+
* Get all ancestor elements (i.e. parent, parent’s parent, etc.)
|
|
49
|
+
* going up from parent to the root
|
|
50
|
+
*/
|
|
51
|
+
declare function ancestorsFqn<Id extends string>(fqn: Id): Id[];
|
|
52
|
+
/**
|
|
53
|
+
* Compares two fully qualified names (fqns) hierarchically based on their depth.
|
|
54
|
+
* From parent nodes to leaves
|
|
55
|
+
*
|
|
56
|
+
* @param {string} a - The first fqn to compare.
|
|
57
|
+
* @param {string} b - The second fqn to compare.
|
|
58
|
+
* @returns {number} - 0 if the fqns have the same depth.
|
|
59
|
+
* - Positive number if a is deeper than b.
|
|
60
|
+
* - Negative number if b is deeper than a.
|
|
61
|
+
*/
|
|
62
|
+
declare function compareFqnHierarchically<T extends string = string>(a: T, b: T): -1 | 0 | 1;
|
|
63
|
+
declare function compareByFqnHierarchically<T extends {
|
|
64
|
+
id: string;
|
|
65
|
+
}>(a: T, b: T): -1 | 0 | 1;
|
|
66
|
+
type IterableContainer<T = unknown> = ReadonlyArray<T> | readonly [];
|
|
67
|
+
type ReorderedArray<T extends IterableContainer> = {
|
|
68
|
+
-readonly [P in keyof T]: T[number];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Sorts an array of objects hierarchically based on their fully qualified names (FQN).
|
|
72
|
+
* Objects are sorted by the number of segments in their FQN (defined by dot-separated ID).
|
|
73
|
+
*
|
|
74
|
+
* @typeParam T - Object type that contains an 'id' string property
|
|
75
|
+
* @typeParam A - Type extending IterableContainer of T
|
|
76
|
+
*
|
|
77
|
+
* @param array - Array of objects to be sorted
|
|
78
|
+
* @returns A new array with items sorted by their FQN hierarchy depth (number of segments)
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const items = [
|
|
83
|
+
* { id: "a.b.c" },
|
|
84
|
+
* { id: "a" },
|
|
85
|
+
* { id: "a.b" }
|
|
86
|
+
* ];
|
|
87
|
+
* sortByFqnHierarchically(items);
|
|
88
|
+
* // Result: [
|
|
89
|
+
* // { id: "a" },
|
|
90
|
+
* // { id: "a.b" },
|
|
91
|
+
* // { id: "a.b.c" }
|
|
92
|
+
* // ]
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function sortByFqnHierarchically<T extends {
|
|
96
|
+
id: string;
|
|
97
|
+
}, A extends IterableContainer<T>>(array: A): ReorderedArray<A>;
|
|
98
|
+
/**
|
|
99
|
+
* Keeps initial order of the elements, but ensures that parents are before children
|
|
100
|
+
*/
|
|
101
|
+
declare function sortParentsFirst<T extends {
|
|
102
|
+
id: string;
|
|
103
|
+
}, A extends IterableContainer<T>>(array: A): ReorderedArray<A>;
|
|
104
|
+
/**
|
|
105
|
+
* Sorts an array of objects naturally by their fully qualified name (FQN) identifier.
|
|
106
|
+
*
|
|
107
|
+
* @template T - Type of objects containing an 'id' string property
|
|
108
|
+
* @template A - Type extending IterableContainer of T
|
|
109
|
+
*
|
|
110
|
+
* @param first - Optional. Either the array to sort or the sort direction ('asc'|'desc')
|
|
111
|
+
* @param sort - Optional. The sort direction ('asc'|'desc'). Defaults to 'asc' if not specified
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* // As a function that returns a sorting function
|
|
115
|
+
* const sorted = sortNaturalByFqn('desc')(myArray);
|
|
116
|
+
*
|
|
117
|
+
* // Direct array sorting
|
|
118
|
+
* const sorted = sortNaturalByFqn(myArray, 'desc');
|
|
119
|
+
*/
|
|
120
|
+
declare function sortNaturalByFqn(sort?: 'asc' | 'desc'): <T extends {
|
|
121
|
+
id: string;
|
|
122
|
+
}, A extends IterableContainer<T>>(array: A) => ReorderedArray<A>;
|
|
123
|
+
declare function sortNaturalByFqn<T extends {
|
|
124
|
+
id: string;
|
|
125
|
+
}, A extends IterableContainer<T>>(array: A, sort?: 'asc' | 'desc'): ReorderedArray<A>;
|
|
126
|
+
|
|
127
|
+
export { type IterableContainer as I, type ReorderedArray as R, ancestorsFqn as a, compareByFqnHierarchically as b, commonAncestor as c, compareFqnHierarchically as d, hierarchyLevel as e, isDescendantOf as f, isSameHierarchy as g, hierarchyDistance as h, isAncestor as i, sortNaturalByFqn as j, sortParentsFirst as k, nameFromFqn as n, parentFqn as p, sortByFqnHierarchically as s };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { LiteralUnion, Tagged, Simplify, UnionToIntersection, TupleToUnion } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
declare const ThemeColors: readonly ["amber", "blue", "gray", "slate", "green", "indigo", "muted", "primary", "red", "secondary", "sky"];
|
|
4
|
+
type ThemeColor = typeof ThemeColors[number];
|
|
5
|
+
type HexColorLiteral = `#${string}`;
|
|
6
|
+
type ColorLiteral = HexColorLiteral;
|
|
7
|
+
type Color = LiteralUnion<ThemeColor, string>;
|
|
8
|
+
declare function isThemeColor(color: Color): color is ThemeColor;
|
|
9
|
+
interface ElementThemeColorValues {
|
|
10
|
+
fill: ColorLiteral;
|
|
11
|
+
stroke: ColorLiteral;
|
|
12
|
+
hiContrast: ColorLiteral;
|
|
13
|
+
loContrast: ColorLiteral;
|
|
14
|
+
}
|
|
15
|
+
type ElementThemeColors = {
|
|
16
|
+
[key in ThemeColor]: ElementThemeColorValues;
|
|
17
|
+
};
|
|
18
|
+
interface RelationshipThemeColorValues {
|
|
19
|
+
lineColor: ColorLiteral;
|
|
20
|
+
labelBgColor: ColorLiteral;
|
|
21
|
+
labelColor: ColorLiteral;
|
|
22
|
+
}
|
|
23
|
+
interface ThemeColorValues {
|
|
24
|
+
elements: ElementThemeColorValues;
|
|
25
|
+
relationships: RelationshipThemeColorValues;
|
|
26
|
+
}
|
|
27
|
+
type RelationshipThemeColors = {
|
|
28
|
+
[key in ThemeColor]: RelationshipThemeColorValues;
|
|
29
|
+
};
|
|
30
|
+
interface LikeC4Theme {
|
|
31
|
+
font: 'Arial';
|
|
32
|
+
shadow: ColorLiteral;
|
|
33
|
+
relationships: RelationshipThemeColors;
|
|
34
|
+
elements: ElementThemeColors;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
38
|
+
type NonEmptyReadonlyArray<T> = readonly [T, ...T[]];
|
|
39
|
+
type IconUrl = Tagged<string, 'IconUrl'> | 'none';
|
|
40
|
+
type CustomColor = string;
|
|
41
|
+
type Point = readonly [x: number, y: number];
|
|
42
|
+
interface XYPoint {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
}
|
|
46
|
+
type KeysOf<T> = keyof T extends infer K extends string ? K : never;
|
|
47
|
+
type AllNever<Expressions> = UnionToIntersection<{
|
|
48
|
+
[Name in keyof Expressions]: {
|
|
49
|
+
-readonly [Key in keyof Expressions[Name]]?: never;
|
|
50
|
+
};
|
|
51
|
+
}[keyof Expressions]>;
|
|
52
|
+
/**
|
|
53
|
+
* @example
|
|
54
|
+
* type Variant1 = {
|
|
55
|
+
* a: string
|
|
56
|
+
* }
|
|
57
|
+
* type Variant2 = {
|
|
58
|
+
* b: number
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* type Variants = ExclusiveUnion<{
|
|
62
|
+
* Variant1: Variant1,
|
|
63
|
+
* Variant2: Variant2
|
|
64
|
+
* }>
|
|
65
|
+
*
|
|
66
|
+
* Fail here
|
|
67
|
+
* const variant1: Variants = {
|
|
68
|
+
* a: 'one',
|
|
69
|
+
* b: 1
|
|
70
|
+
* }
|
|
71
|
+
*/
|
|
72
|
+
type ExclusiveUnion<Expressions> = Expressions extends object ? {
|
|
73
|
+
[Name in keyof Expressions]: Simplify<Omit<AllNever<Expressions>, keyof Expressions[Name]> & Expressions[Name]>;
|
|
74
|
+
}[keyof Expressions] : Expressions;
|
|
75
|
+
/**
|
|
76
|
+
* Copy from https://github.com/remeda/remeda/blob/main/src/internal/types/NTuple.ts
|
|
77
|
+
* An array with *exactly* N elements in it.
|
|
78
|
+
*
|
|
79
|
+
* Only literal N values are supported. For very large N the type might result
|
|
80
|
+
* in a recurse depth error. For negative N the type would result in an infinite
|
|
81
|
+
* recursion. None of these have protections because this is an internal type!
|
|
82
|
+
*/
|
|
83
|
+
type NTuple<T, N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : NTuple<T, N, [...Result, T]>;
|
|
84
|
+
type IteratorLike<T> = IteratorObject<T, BuiltinIteratorReturn>;
|
|
85
|
+
type Predicate<T> = (x: T) => boolean;
|
|
86
|
+
|
|
87
|
+
type Fqn<Id extends string = string> = Tagged<Id, 'Fqn'>;
|
|
88
|
+
declare function AsFqn(name: string, parent?: Fqn | null): Fqn;
|
|
89
|
+
declare const BorderStyles: readonly ["solid", "dashed", "dotted", "none"];
|
|
90
|
+
type BorderStyle = TupleToUnion<typeof BorderStyles>;
|
|
91
|
+
type ElementKind<Kinds extends string = string> = Tagged<Kinds, 'ElementKind'>;
|
|
92
|
+
declare namespace ElementKind {
|
|
93
|
+
const Group: ElementKind;
|
|
94
|
+
}
|
|
95
|
+
declare const ElementShapes: readonly ["rectangle", "person", "browser", "mobile", "cylinder", "storage", "queue"];
|
|
96
|
+
type ElementShape = TupleToUnion<typeof ElementShapes>;
|
|
97
|
+
declare const DefaultThemeColor: ThemeColor;
|
|
98
|
+
declare const DefaultElementShape: ElementShape;
|
|
99
|
+
interface ElementStyle {
|
|
100
|
+
readonly border?: BorderStyle;
|
|
101
|
+
/**
|
|
102
|
+
* In percentage 0-100, 0 is fully transparent
|
|
103
|
+
*
|
|
104
|
+
* @default 100
|
|
105
|
+
*/
|
|
106
|
+
readonly opacity?: number;
|
|
107
|
+
}
|
|
108
|
+
type Tag<Tags extends string = string> = Tagged<Tags, 'Tag'>;
|
|
109
|
+
interface TagSpec {
|
|
110
|
+
readonly id: Tag;
|
|
111
|
+
readonly style: ElementStyle;
|
|
112
|
+
}
|
|
113
|
+
interface Link {
|
|
114
|
+
readonly title?: string;
|
|
115
|
+
readonly url: string;
|
|
116
|
+
readonly relative?: string;
|
|
117
|
+
}
|
|
118
|
+
interface TypedElement<Ids extends string, Kinds extends string, Tags extends string, MetadataKeys extends string = never> {
|
|
119
|
+
readonly id: Fqn<Ids>;
|
|
120
|
+
readonly kind: ElementKind<Kinds>;
|
|
121
|
+
readonly title: string;
|
|
122
|
+
readonly description: string | null;
|
|
123
|
+
readonly technology: string | null;
|
|
124
|
+
readonly tags: NonEmptyArray<Tag<Tags>> | null;
|
|
125
|
+
readonly links: NonEmptyArray<Link> | null;
|
|
126
|
+
readonly icon?: IconUrl;
|
|
127
|
+
readonly shape?: ElementShape;
|
|
128
|
+
readonly color?: Color;
|
|
129
|
+
readonly style?: ElementStyle;
|
|
130
|
+
readonly notation?: string;
|
|
131
|
+
readonly metadata?: Record<MetadataKeys, string>;
|
|
132
|
+
}
|
|
133
|
+
interface Element extends TypedElement<string, string, string, string> {
|
|
134
|
+
}
|
|
135
|
+
interface ElementKindSpecificationStyle {
|
|
136
|
+
shape?: ElementShape;
|
|
137
|
+
icon?: IconUrl;
|
|
138
|
+
color?: Color;
|
|
139
|
+
border?: BorderStyle;
|
|
140
|
+
opacity?: number;
|
|
141
|
+
}
|
|
142
|
+
interface ElementKindSpecification {
|
|
143
|
+
readonly technology?: string;
|
|
144
|
+
readonly notation?: string;
|
|
145
|
+
readonly style: ElementKindSpecificationStyle;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { AsFqn as A, BorderStyles as B, type CustomColor as C, DefaultElementShape as D, type ExclusiveUnion as E, type Fqn as F, type HexColorLiteral as H, type IconUrl as I, type KeysOf as K, type LikeC4Theme as L, type NonEmptyArray as N, type Point as P, type RelationshipThemeColors as R, type ThemeColorValues as T, type XYPoint as X, type IteratorLike as a, type NonEmptyReadonlyArray as b, type NTuple as c, type Predicate as d, DefaultThemeColor as e, ElementKind as f, ElementShapes as g, type BorderStyle as h, type Element as i, type ElementKindSpecification as j, type ElementKindSpecificationStyle as k, type ElementShape as l, type ElementStyle as m, type Link as n, type Tag as o, type TagSpec as p, type TypedElement as q, isThemeColor as r, type Color as s, type ColorLiteral as t, type ElementThemeColors as u, type ElementThemeColorValues as v, type RelationshipThemeColorValues as w, type ThemeColor as x };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { LiteralUnion, Tagged, Simplify, UnionToIntersection, TupleToUnion } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
declare const ThemeColors: readonly ["amber", "blue", "gray", "slate", "green", "indigo", "muted", "primary", "red", "secondary", "sky"];
|
|
4
|
+
type ThemeColor = typeof ThemeColors[number];
|
|
5
|
+
type HexColorLiteral = `#${string}`;
|
|
6
|
+
type ColorLiteral = HexColorLiteral;
|
|
7
|
+
type Color = LiteralUnion<ThemeColor, string>;
|
|
8
|
+
declare function isThemeColor(color: Color): color is ThemeColor;
|
|
9
|
+
interface ElementThemeColorValues {
|
|
10
|
+
fill: ColorLiteral;
|
|
11
|
+
stroke: ColorLiteral;
|
|
12
|
+
hiContrast: ColorLiteral;
|
|
13
|
+
loContrast: ColorLiteral;
|
|
14
|
+
}
|
|
15
|
+
type ElementThemeColors = {
|
|
16
|
+
[key in ThemeColor]: ElementThemeColorValues;
|
|
17
|
+
};
|
|
18
|
+
interface RelationshipThemeColorValues {
|
|
19
|
+
lineColor: ColorLiteral;
|
|
20
|
+
labelBgColor: ColorLiteral;
|
|
21
|
+
labelColor: ColorLiteral;
|
|
22
|
+
}
|
|
23
|
+
interface ThemeColorValues {
|
|
24
|
+
elements: ElementThemeColorValues;
|
|
25
|
+
relationships: RelationshipThemeColorValues;
|
|
26
|
+
}
|
|
27
|
+
type RelationshipThemeColors = {
|
|
28
|
+
[key in ThemeColor]: RelationshipThemeColorValues;
|
|
29
|
+
};
|
|
30
|
+
interface LikeC4Theme {
|
|
31
|
+
font: 'Arial';
|
|
32
|
+
shadow: ColorLiteral;
|
|
33
|
+
relationships: RelationshipThemeColors;
|
|
34
|
+
elements: ElementThemeColors;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
38
|
+
type NonEmptyReadonlyArray<T> = readonly [T, ...T[]];
|
|
39
|
+
type IconUrl = Tagged<string, 'IconUrl'> | 'none';
|
|
40
|
+
type CustomColor = string;
|
|
41
|
+
type Point = readonly [x: number, y: number];
|
|
42
|
+
interface XYPoint {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
}
|
|
46
|
+
type KeysOf<T> = keyof T extends infer K extends string ? K : never;
|
|
47
|
+
type AllNever<Expressions> = UnionToIntersection<{
|
|
48
|
+
[Name in keyof Expressions]: {
|
|
49
|
+
-readonly [Key in keyof Expressions[Name]]?: never;
|
|
50
|
+
};
|
|
51
|
+
}[keyof Expressions]>;
|
|
52
|
+
/**
|
|
53
|
+
* @example
|
|
54
|
+
* type Variant1 = {
|
|
55
|
+
* a: string
|
|
56
|
+
* }
|
|
57
|
+
* type Variant2 = {
|
|
58
|
+
* b: number
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* type Variants = ExclusiveUnion<{
|
|
62
|
+
* Variant1: Variant1,
|
|
63
|
+
* Variant2: Variant2
|
|
64
|
+
* }>
|
|
65
|
+
*
|
|
66
|
+
* Fail here
|
|
67
|
+
* const variant1: Variants = {
|
|
68
|
+
* a: 'one',
|
|
69
|
+
* b: 1
|
|
70
|
+
* }
|
|
71
|
+
*/
|
|
72
|
+
type ExclusiveUnion<Expressions> = Expressions extends object ? {
|
|
73
|
+
[Name in keyof Expressions]: Simplify<Omit<AllNever<Expressions>, keyof Expressions[Name]> & Expressions[Name]>;
|
|
74
|
+
}[keyof Expressions] : Expressions;
|
|
75
|
+
/**
|
|
76
|
+
* Copy from https://github.com/remeda/remeda/blob/main/src/internal/types/NTuple.ts
|
|
77
|
+
* An array with *exactly* N elements in it.
|
|
78
|
+
*
|
|
79
|
+
* Only literal N values are supported. For very large N the type might result
|
|
80
|
+
* in a recurse depth error. For negative N the type would result in an infinite
|
|
81
|
+
* recursion. None of these have protections because this is an internal type!
|
|
82
|
+
*/
|
|
83
|
+
type NTuple<T, N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : NTuple<T, N, [...Result, T]>;
|
|
84
|
+
type IteratorLike<T> = IteratorObject<T, BuiltinIteratorReturn>;
|
|
85
|
+
type Predicate<T> = (x: T) => boolean;
|
|
86
|
+
|
|
87
|
+
type Fqn<Id extends string = string> = Tagged<Id, 'Fqn'>;
|
|
88
|
+
declare function AsFqn(name: string, parent?: Fqn | null): Fqn;
|
|
89
|
+
declare const BorderStyles: readonly ["solid", "dashed", "dotted", "none"];
|
|
90
|
+
type BorderStyle = TupleToUnion<typeof BorderStyles>;
|
|
91
|
+
type ElementKind<Kinds extends string = string> = Tagged<Kinds, 'ElementKind'>;
|
|
92
|
+
declare namespace ElementKind {
|
|
93
|
+
const Group: ElementKind;
|
|
94
|
+
}
|
|
95
|
+
declare const ElementShapes: readonly ["rectangle", "person", "browser", "mobile", "cylinder", "storage", "queue"];
|
|
96
|
+
type ElementShape = TupleToUnion<typeof ElementShapes>;
|
|
97
|
+
declare const DefaultThemeColor: ThemeColor;
|
|
98
|
+
declare const DefaultElementShape: ElementShape;
|
|
99
|
+
interface ElementStyle {
|
|
100
|
+
readonly border?: BorderStyle;
|
|
101
|
+
/**
|
|
102
|
+
* In percentage 0-100, 0 is fully transparent
|
|
103
|
+
*
|
|
104
|
+
* @default 100
|
|
105
|
+
*/
|
|
106
|
+
readonly opacity?: number;
|
|
107
|
+
}
|
|
108
|
+
type Tag<Tags extends string = string> = Tagged<Tags, 'Tag'>;
|
|
109
|
+
interface TagSpec {
|
|
110
|
+
readonly id: Tag;
|
|
111
|
+
readonly style: ElementStyle;
|
|
112
|
+
}
|
|
113
|
+
interface Link {
|
|
114
|
+
readonly title?: string;
|
|
115
|
+
readonly url: string;
|
|
116
|
+
readonly relative?: string;
|
|
117
|
+
}
|
|
118
|
+
interface TypedElement<Ids extends string, Kinds extends string, Tags extends string, MetadataKeys extends string = never> {
|
|
119
|
+
readonly id: Fqn<Ids>;
|
|
120
|
+
readonly kind: ElementKind<Kinds>;
|
|
121
|
+
readonly title: string;
|
|
122
|
+
readonly description: string | null;
|
|
123
|
+
readonly technology: string | null;
|
|
124
|
+
readonly tags: NonEmptyArray<Tag<Tags>> | null;
|
|
125
|
+
readonly links: NonEmptyArray<Link> | null;
|
|
126
|
+
readonly icon?: IconUrl;
|
|
127
|
+
readonly shape?: ElementShape;
|
|
128
|
+
readonly color?: Color;
|
|
129
|
+
readonly style?: ElementStyle;
|
|
130
|
+
readonly notation?: string;
|
|
131
|
+
readonly metadata?: Record<MetadataKeys, string>;
|
|
132
|
+
}
|
|
133
|
+
interface Element extends TypedElement<string, string, string, string> {
|
|
134
|
+
}
|
|
135
|
+
interface ElementKindSpecificationStyle {
|
|
136
|
+
shape?: ElementShape;
|
|
137
|
+
icon?: IconUrl;
|
|
138
|
+
color?: Color;
|
|
139
|
+
border?: BorderStyle;
|
|
140
|
+
opacity?: number;
|
|
141
|
+
}
|
|
142
|
+
interface ElementKindSpecification {
|
|
143
|
+
readonly technology?: string;
|
|
144
|
+
readonly notation?: string;
|
|
145
|
+
readonly style: ElementKindSpecificationStyle;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { AsFqn as A, BorderStyles as B, type CustomColor as C, DefaultElementShape as D, type ExclusiveUnion as E, type Fqn as F, type HexColorLiteral as H, type IconUrl as I, type KeysOf as K, type LikeC4Theme as L, type NonEmptyArray as N, type Point as P, type RelationshipThemeColors as R, type ThemeColorValues as T, type XYPoint as X, type IteratorLike as a, type NonEmptyReadonlyArray as b, type NTuple as c, type Predicate as d, DefaultThemeColor as e, ElementKind as f, ElementShapes as g, type BorderStyle as h, type Element as i, type ElementKindSpecification as j, type ElementKindSpecificationStyle as k, type ElementShape as l, type ElementStyle as m, type Link as n, type Tag as o, type TagSpec as p, type TypedElement as q, isThemeColor as r, type Color as s, type ColorLiteral as t, type ElementThemeColors as u, type ElementThemeColorValues as v, type RelationshipThemeColorValues as w, type ThemeColor as x };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { F as Fqn } from './core.D74xkKkG.mjs';
|
|
2
|
+
|
|
3
|
+
declare function parentFqn<E extends string>(fqn: E): E | null;
|
|
4
|
+
declare function nameFromFqn<E extends string>(fqn: E): string;
|
|
5
|
+
/**
|
|
6
|
+
* Check if one element is an ancestor of another
|
|
7
|
+
* Composable version
|
|
8
|
+
* @signature
|
|
9
|
+
* isAncestor(another)(ancestor)
|
|
10
|
+
*/
|
|
11
|
+
declare function isAncestor<A extends string | {
|
|
12
|
+
id: string;
|
|
13
|
+
}>(another: NoInfer<A>): (ancestor: A) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Check if one element is an ancestor of another
|
|
16
|
+
* @signature
|
|
17
|
+
* isAncestor(ancestor, another)
|
|
18
|
+
*/
|
|
19
|
+
declare function isAncestor<A extends string | {
|
|
20
|
+
id: string;
|
|
21
|
+
}>(ancestor: A, another: A): boolean;
|
|
22
|
+
declare function isSameHierarchy<T extends string>(one: NoInfer<T> | WithId<NoInfer<T>>): (another: T | WithId<T>) => boolean;
|
|
23
|
+
declare function isSameHierarchy<T extends string>(one: T | WithId<T>, another: T | WithId<T>): boolean;
|
|
24
|
+
type WithId<T> = {
|
|
25
|
+
id: T;
|
|
26
|
+
};
|
|
27
|
+
declare function isDescendantOf<T extends string>(ancestor: WithId<T>): (descedant: WithId<T>) => boolean;
|
|
28
|
+
declare function isDescendantOf<T extends string>(descedant: WithId<T>, ancestor: WithId<T>): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* How deep in the hierarchy the element is.
|
|
31
|
+
* Root element has depth 1
|
|
32
|
+
*/
|
|
33
|
+
declare function hierarchyLevel<E extends string | {
|
|
34
|
+
id: Fqn;
|
|
35
|
+
}>(elementOfFqn: E): number;
|
|
36
|
+
/**
|
|
37
|
+
* Calculate the distance as number of steps from one element to another, i.e.
|
|
38
|
+
* going up to the common ancestor, then going down to the other element.
|
|
39
|
+
* Sibling distance is always 1
|
|
40
|
+
*
|
|
41
|
+
* Can be used for hierarchical clustering
|
|
42
|
+
*/
|
|
43
|
+
declare function hierarchyDistance<E extends string | {
|
|
44
|
+
id: Fqn;
|
|
45
|
+
}>(one: E, another: E): number;
|
|
46
|
+
declare function commonAncestor<E extends string>(first: E, second: E): E | null;
|
|
47
|
+
/**
|
|
48
|
+
* Get all ancestor elements (i.e. parent, parent’s parent, etc.)
|
|
49
|
+
* going up from parent to the root
|
|
50
|
+
*/
|
|
51
|
+
declare function ancestorsFqn<Id extends string>(fqn: Id): Id[];
|
|
52
|
+
/**
|
|
53
|
+
* Compares two fully qualified names (fqns) hierarchically based on their depth.
|
|
54
|
+
* From parent nodes to leaves
|
|
55
|
+
*
|
|
56
|
+
* @param {string} a - The first fqn to compare.
|
|
57
|
+
* @param {string} b - The second fqn to compare.
|
|
58
|
+
* @returns {number} - 0 if the fqns have the same depth.
|
|
59
|
+
* - Positive number if a is deeper than b.
|
|
60
|
+
* - Negative number if b is deeper than a.
|
|
61
|
+
*/
|
|
62
|
+
declare function compareFqnHierarchically<T extends string = string>(a: T, b: T): -1 | 0 | 1;
|
|
63
|
+
declare function compareByFqnHierarchically<T extends {
|
|
64
|
+
id: string;
|
|
65
|
+
}>(a: T, b: T): -1 | 0 | 1;
|
|
66
|
+
type IterableContainer<T = unknown> = ReadonlyArray<T> | readonly [];
|
|
67
|
+
type ReorderedArray<T extends IterableContainer> = {
|
|
68
|
+
-readonly [P in keyof T]: T[number];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Sorts an array of objects hierarchically based on their fully qualified names (FQN).
|
|
72
|
+
* Objects are sorted by the number of segments in their FQN (defined by dot-separated ID).
|
|
73
|
+
*
|
|
74
|
+
* @typeParam T - Object type that contains an 'id' string property
|
|
75
|
+
* @typeParam A - Type extending IterableContainer of T
|
|
76
|
+
*
|
|
77
|
+
* @param array - Array of objects to be sorted
|
|
78
|
+
* @returns A new array with items sorted by their FQN hierarchy depth (number of segments)
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const items = [
|
|
83
|
+
* { id: "a.b.c" },
|
|
84
|
+
* { id: "a" },
|
|
85
|
+
* { id: "a.b" }
|
|
86
|
+
* ];
|
|
87
|
+
* sortByFqnHierarchically(items);
|
|
88
|
+
* // Result: [
|
|
89
|
+
* // { id: "a" },
|
|
90
|
+
* // { id: "a.b" },
|
|
91
|
+
* // { id: "a.b.c" }
|
|
92
|
+
* // ]
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function sortByFqnHierarchically<T extends {
|
|
96
|
+
id: string;
|
|
97
|
+
}, A extends IterableContainer<T>>(array: A): ReorderedArray<A>;
|
|
98
|
+
/**
|
|
99
|
+
* Keeps initial order of the elements, but ensures that parents are before children
|
|
100
|
+
*/
|
|
101
|
+
declare function sortParentsFirst<T extends {
|
|
102
|
+
id: string;
|
|
103
|
+
}, A extends IterableContainer<T>>(array: A): ReorderedArray<A>;
|
|
104
|
+
/**
|
|
105
|
+
* Sorts an array of objects naturally by their fully qualified name (FQN) identifier.
|
|
106
|
+
*
|
|
107
|
+
* @template T - Type of objects containing an 'id' string property
|
|
108
|
+
* @template A - Type extending IterableContainer of T
|
|
109
|
+
*
|
|
110
|
+
* @param first - Optional. Either the array to sort or the sort direction ('asc'|'desc')
|
|
111
|
+
* @param sort - Optional. The sort direction ('asc'|'desc'). Defaults to 'asc' if not specified
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* // As a function that returns a sorting function
|
|
115
|
+
* const sorted = sortNaturalByFqn('desc')(myArray);
|
|
116
|
+
*
|
|
117
|
+
* // Direct array sorting
|
|
118
|
+
* const sorted = sortNaturalByFqn(myArray, 'desc');
|
|
119
|
+
*/
|
|
120
|
+
declare function sortNaturalByFqn(sort?: 'asc' | 'desc'): <T extends {
|
|
121
|
+
id: string;
|
|
122
|
+
}, A extends IterableContainer<T>>(array: A) => ReorderedArray<A>;
|
|
123
|
+
declare function sortNaturalByFqn<T extends {
|
|
124
|
+
id: string;
|
|
125
|
+
}, A extends IterableContainer<T>>(array: A, sort?: 'asc' | 'desc'): ReorderedArray<A>;
|
|
126
|
+
|
|
127
|
+
export { type IterableContainer as I, type ReorderedArray as R, ancestorsFqn as a, compareByFqnHierarchically as b, commonAncestor as c, compareFqnHierarchically as d, hierarchyLevel as e, isDescendantOf as f, isSameHierarchy as g, hierarchyDistance as h, isAncestor as i, sortNaturalByFqn as j, sortParentsFirst as k, nameFromFqn as n, parentFqn as p, sortByFqnHierarchically as s };
|