@likec4/core 0.37.1 → 0.41.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.
Files changed (147) hide show
  1. package/README.md +2 -6
  2. package/dist/cjs/colors/element.d.ts +68 -0
  3. package/dist/{colors.js → cjs/colors/element.js} +24 -46
  4. package/dist/cjs/colors/index.d.ts +132 -0
  5. package/dist/cjs/colors/index.js +27 -0
  6. package/dist/cjs/colors/relationships.d.ts +57 -0
  7. package/dist/cjs/colors/relationships.js +76 -0
  8. package/dist/cjs/errors/index.d.ts +45 -0
  9. package/dist/cjs/errors/index.js +137 -0
  10. package/dist/{index.d.ts → cjs/index.d.ts} +3 -5
  11. package/dist/{index.cjs → cjs/index.js} +16 -38
  12. package/dist/{types → cjs/types}/computed-view.d.ts +11 -7
  13. package/dist/{types → cjs/types}/diagram.d.ts +15 -11
  14. package/dist/{types → cjs/types}/expression.d.ts +1 -1
  15. package/dist/{types/index.cjs → cjs/types/index.js} +10 -10
  16. package/dist/cjs/types/relation.d.ts +22 -0
  17. package/dist/cjs/types/relation.js +12 -0
  18. package/dist/{types → cjs/types}/theme.d.ts +10 -6
  19. package/dist/{types → cjs/types}/view.d.ts +22 -4
  20. package/dist/{types/view.cjs → cjs/types/view.js} +1 -1
  21. package/dist/{utils → cjs/utils}/fqn.d.ts +6 -1
  22. package/dist/{utils/fqn.cjs → cjs/utils/fqn.js} +18 -5
  23. package/dist/{utils → cjs/utils}/guards.d.ts +1 -2
  24. package/dist/cjs/utils/guards.js +20 -0
  25. package/dist/{utils → cjs/utils}/index.d.ts +0 -1
  26. package/dist/{utils/index.cjs → cjs/utils/index.js} +3 -14
  27. package/dist/{utils/relations.cjs → cjs/utils/relations.js} +1 -1
  28. package/dist/esm/colors/element.d.ts +68 -0
  29. package/dist/esm/colors/element.js +82 -0
  30. package/dist/esm/colors/index.d.ts +132 -0
  31. package/dist/esm/colors/index.js +9 -0
  32. package/dist/esm/colors/relationships.d.ts +57 -0
  33. package/dist/esm/colors/relationships.js +64 -0
  34. package/dist/esm/errors/index.d.ts +45 -0
  35. package/dist/esm/errors/index.js +97 -0
  36. package/dist/esm/index.d.ts +6 -0
  37. package/dist/esm/index.js +4 -0
  38. package/dist/esm/types/_common.d.ts +3 -0
  39. package/dist/esm/types/computed-view.d.ts +44 -0
  40. package/dist/esm/types/diagram.d.ts +41 -0
  41. package/dist/esm/types/element.d.ts +29 -0
  42. package/dist/esm/types/expression.d.ts +56 -0
  43. package/dist/esm/types/index.d.ts +11 -0
  44. package/dist/esm/types/model.d.ts +14 -0
  45. package/dist/esm/types/opaque.d.ts +102 -0
  46. package/dist/esm/types/relation.d.ts +22 -0
  47. package/dist/esm/types/relation.js +3 -0
  48. package/dist/esm/types/theme.d.ts +26 -0
  49. package/dist/esm/types/view.d.ts +61 -0
  50. package/dist/{types → esm/types}/view.js +1 -1
  51. package/dist/esm/utils/fqn.d.ts +33 -0
  52. package/dist/{utils → esm/utils}/fqn.js +16 -4
  53. package/dist/esm/utils/guards.d.ts +4 -0
  54. package/dist/esm/utils/guards.js +7 -0
  55. package/dist/esm/utils/index.d.ts +3 -0
  56. package/dist/{utils → esm/utils}/index.js +0 -1
  57. package/dist/esm/utils/relations.d.ts +25 -0
  58. package/package.json +44 -61
  59. package/dist/colors.cjs +0 -124
  60. package/dist/colors.d.ts +0 -148
  61. package/dist/compute-view/EdgeBuilder.cjs +0 -37
  62. package/dist/compute-view/EdgeBuilder.d.ts +0 -6
  63. package/dist/compute-view/EdgeBuilder.js +0 -30
  64. package/dist/compute-view/compute-ctx.cjs +0 -89
  65. package/dist/compute-view/compute-ctx.d.ts +0 -19
  66. package/dist/compute-view/compute-ctx.js +0 -98
  67. package/dist/compute-view/compute-element-view.cjs +0 -91
  68. package/dist/compute-view/compute-element-view.d.ts +0 -3
  69. package/dist/compute-view/compute-element-view.js +0 -86
  70. package/dist/compute-view/compute-predicates.cjs +0 -363
  71. package/dist/compute-view/compute-predicates.d.ts +0 -16
  72. package/dist/compute-view/compute-predicates.js +0 -324
  73. package/dist/compute-view/compute.cjs +0 -46
  74. package/dist/compute-view/compute.d.ts +0 -14
  75. package/dist/compute-view/compute.js +0 -36
  76. package/dist/compute-view/index.cjs +0 -38
  77. package/dist/compute-view/index.d.ts +0 -3
  78. package/dist/compute-view/index.js +0 -3
  79. package/dist/compute-view/resolve-extended-views.cjs +0 -50
  80. package/dist/compute-view/resolve-extended-views.d.ts +0 -6
  81. package/dist/compute-view/resolve-extended-views.js +0 -38
  82. package/dist/compute-view/utils/anyPossibleRelations.cjs +0 -18
  83. package/dist/compute-view/utils/anyPossibleRelations.d.ts +0 -2
  84. package/dist/compute-view/utils/anyPossibleRelations.js +0 -12
  85. package/dist/compute-view/utils/applyViewRuleStyles.cjs +0 -57
  86. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +0 -2
  87. package/dist/compute-view/utils/applyViewRuleStyles.js +0 -50
  88. package/dist/compute-view/utils/sortNodes.cjs +0 -50
  89. package/dist/compute-view/utils/sortNodes.d.ts +0 -2
  90. package/dist/compute-view/utils/sortNodes.js +0 -40
  91. package/dist/errors/_base.cjs +0 -62
  92. package/dist/errors/_base.d.ts +0 -26
  93. package/dist/errors/_base.js +0 -41
  94. package/dist/errors/index.cjs +0 -60
  95. package/dist/errors/index.d.ts +0 -5
  96. package/dist/errors/index.js +0 -5
  97. package/dist/errors/invariant.cjs +0 -23
  98. package/dist/errors/invariant.d.ts +0 -6
  99. package/dist/errors/invariant.js +0 -13
  100. package/dist/errors/model-index.cjs +0 -23
  101. package/dist/errors/model-index.d.ts +0 -6
  102. package/dist/errors/model-index.js +0 -13
  103. package/dist/errors/non-nullable.cjs +0 -23
  104. package/dist/errors/non-nullable.d.ts +0 -6
  105. package/dist/errors/non-nullable.js +0 -13
  106. package/dist/errors/nonexhaustive.cjs +0 -23
  107. package/dist/errors/nonexhaustive.d.ts +0 -6
  108. package/dist/errors/nonexhaustive.js +0 -12
  109. package/dist/index.js +0 -6
  110. package/dist/model-index/ModelIndex.cjs +0 -140
  111. package/dist/model-index/ModelIndex.d.ts +0 -27
  112. package/dist/model-index/ModelIndex.js +0 -128
  113. package/dist/model-index/index.cjs +0 -13
  114. package/dist/model-index/index.d.ts +0 -1
  115. package/dist/model-index/index.js +0 -1
  116. package/dist/types/relation.d.ts +0 -10
  117. package/dist/types/relation.js +0 -0
  118. package/dist/types/theme.cjs +0 -1
  119. package/dist/utils/compute-node-levels.cjs +0 -48
  120. package/dist/utils/compute-node-levels.d.ts +0 -7
  121. package/dist/utils/compute-node-levels.js +0 -31
  122. package/dist/utils/guards.cjs +0 -22
  123. package/dist/utils/guards.js +0 -13
  124. /package/dist/{types → cjs/types}/_common.d.ts +0 -0
  125. /package/dist/{types/_common.cjs → cjs/types/_common.js} +0 -0
  126. /package/dist/{types/computed-view.cjs → cjs/types/computed-view.js} +0 -0
  127. /package/dist/{types/diagram.cjs → cjs/types/diagram.js} +0 -0
  128. /package/dist/{types → cjs/types}/element.d.ts +0 -0
  129. /package/dist/{types/element.cjs → cjs/types/element.js} +0 -0
  130. /package/dist/{types/expression.cjs → cjs/types/expression.js} +0 -0
  131. /package/dist/{types → cjs/types}/index.d.ts +0 -0
  132. /package/dist/{types → cjs/types}/model.d.ts +0 -0
  133. /package/dist/{types/model.cjs → cjs/types/model.js} +0 -0
  134. /package/dist/{types → cjs/types}/opaque.d.ts +0 -0
  135. /package/dist/{types/opaque.cjs → cjs/types/opaque.js} +0 -0
  136. /package/dist/{types/relation.cjs → cjs/types/theme.js} +0 -0
  137. /package/dist/{utils → cjs/utils}/relations.d.ts +0 -0
  138. /package/dist/{types → esm/types}/_common.js +0 -0
  139. /package/dist/{types → esm/types}/computed-view.js +0 -0
  140. /package/dist/{types → esm/types}/diagram.js +0 -0
  141. /package/dist/{types → esm/types}/element.js +0 -0
  142. /package/dist/{types → esm/types}/expression.js +0 -0
  143. /package/dist/{types → esm/types}/index.js +0 -0
  144. /package/dist/{types → esm/types}/model.js +0 -0
  145. /package/dist/{types → esm/types}/opaque.js +0 -0
  146. /package/dist/{types → esm/types}/theme.js +0 -0
  147. /package/dist/{utils → esm/utils}/relations.js +0 -0
@@ -0,0 +1,11 @@
1
+ export * from './opaque';
2
+ export * from './_common';
3
+ export * from './theme';
4
+ export * from './element';
5
+ export * from './relation';
6
+ export * from './model';
7
+ export * from './view';
8
+ export * from './expression';
9
+ export * from './computed-view';
10
+ export * from './diagram';
11
+ export * as Expr from './expression';
@@ -0,0 +1,14 @@
1
+ import type { ComputedView } from './computed-view';
2
+ import type { Element, Fqn } from './element';
3
+ import type { Relation, RelationID } from './relation';
4
+ import type { ElementView, ViewID } from './view';
5
+ export interface LikeC4RawModel {
6
+ elements: Record<Fqn, Element>;
7
+ relations: Record<RelationID, Relation>;
8
+ views: Record<ViewID, ElementView>;
9
+ }
10
+ export interface LikeC4Model {
11
+ elements: Record<Fqn, Element>;
12
+ relations: Record<RelationID, Relation>;
13
+ views: Record<ViewID, ComputedView>;
14
+ }
@@ -0,0 +1,102 @@
1
+ declare const tag: unique symbol;
2
+ type Tagged<Token> = {
3
+ readonly [tag]: Token;
4
+ };
5
+ /**
6
+ Create an opaque type, which hides its internal details from the public, and can only be created by being used explicitly.
7
+
8
+ The generic type parameter can be anything. It doesn't have to be an object.
9
+
10
+ [Read more about opaque types.](https://codemix.com/opaque-types-in-javascript/)
11
+
12
+ There have been several discussions about adding this feature to TypeScript via the `opaque type` operator, similar to how Flow does it. Unfortunately, nothing has (yet) moved forward:
13
+ - [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
14
+ - [Microsoft/TypeScript#15408](https://github.com/Microsoft/TypeScript/issues/15408)
15
+ - [Microsoft/TypeScript#15807](https://github.com/Microsoft/TypeScript/issues/15807)
16
+
17
+ @example
18
+ ```
19
+ import type {Opaque} from 'type-fest';
20
+
21
+ type AccountNumber = Opaque<number, 'AccountNumber'>;
22
+ type AccountBalance = Opaque<number, 'AccountBalance'>;
23
+
24
+ // The `Token` parameter allows the compiler to differentiate between types, whereas "unknown" will not. For example, consider the following structures:
25
+ type ThingOne = Opaque<string>;
26
+ type ThingTwo = Opaque<string>;
27
+
28
+ // To the compiler, these types are allowed to be cast to each other as they have the same underlying type. They are both `string & { __opaque__: unknown }`.
29
+ // To avoid this behaviour, you would instead pass the "Token" parameter, like so.
30
+ type NewThingOne = Opaque<string, 'ThingOne'>;
31
+ type NewThingTwo = Opaque<string, 'ThingTwo'>;
32
+
33
+ // Now they're completely separate types, so the following will fail to compile.
34
+ function createNewThingOne (): NewThingOne {
35
+ // As you can see, casting from a string is still allowed. However, you may not cast NewThingOne to NewThingTwo, and vice versa.
36
+ return 'new thing one' as NewThingOne;
37
+ }
38
+
39
+ // This will fail to compile, as they are fundamentally different types.
40
+ const thingTwo = createNewThingOne() as NewThingTwo;
41
+
42
+ // Here's another example of opaque typing.
43
+ function createAccountNumber(): AccountNumber {
44
+ return 2 as AccountNumber;
45
+ }
46
+
47
+ function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance {
48
+ return 4 as AccountBalance;
49
+ }
50
+
51
+ // This will compile successfully.
52
+ getMoneyForAccount(createAccountNumber());
53
+
54
+ // But this won't, because it has to be explicitly passed as an `AccountNumber` type.
55
+ getMoneyForAccount(2);
56
+
57
+ // You can use opaque values like they aren't opaque too.
58
+ const accountNumber = createAccountNumber();
59
+
60
+ // This will not compile successfully.
61
+ const newAccountNumber = accountNumber + 2;
62
+
63
+ // As a side note, you can (and should) use recursive types for your opaque types to make them stronger and hopefully easier to type.
64
+ type Person = {
65
+ id: Opaque<number, Person>;
66
+ name: string;
67
+ };
68
+ ```
69
+
70
+ @category Type
71
+ */
72
+ export type Opaque<Type, Token = unknown> = Type & Tagged<Token>;
73
+ /**
74
+ Revert an opaque type back to its original type by removing the readonly `[tag]`.
75
+
76
+ Why is this necessary?
77
+
78
+ 1. Use an `Opaque` type as object keys
79
+ 2. Prevent TS4058 error: "Return type of exported function has or is using name X from external module Y but cannot be named"
80
+
81
+ @example
82
+ ```
83
+ import type {Opaque, UnwrapOpaque} from 'type-fest';
84
+
85
+ type AccountType = Opaque<'SAVINGS' | 'CHECKING', 'AccountType'>;
86
+
87
+ const moneyByAccountType: Record<UnwrapOpaque<AccountType>, number> = {
88
+ SAVINGS: 99,
89
+ CHECKING: 0.1
90
+ };
91
+
92
+ // Without UnwrapOpaque, the following expression would throw a type error.
93
+ const money = moneyByAccountType.SAVINGS; // TS error: Property 'SAVINGS' does not exist
94
+
95
+ // Attempting to pass an non-Opaque type to UnwrapOpaque will raise a type error.
96
+ type WontWork = UnwrapOpaque<string>;
97
+ ```
98
+
99
+ @category Type
100
+ */
101
+ export type UnwrapOpaque<OpaqueType extends Tagged<unknown>> = OpaqueType extends Opaque<infer Type, OpaqueType[typeof tag]> ? Type : OpaqueType;
102
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { Opaque } from './opaque';
2
+ import type { Fqn, Tag } from './element';
3
+ import type { ThemeColor } from './theme';
4
+ export type RelationID = Opaque<string, 'RelationID'>;
5
+ export type RelationshipKind = Opaque<string, 'RelationshipKind'>;
6
+ export type RelationshipLineType = 'dashed' | 'solid' | 'dotted';
7
+ export type RelationshipArrowType = 'none' | 'normal' | 'onormal' | 'diamond' | 'odiamond' | 'crow' | 'open' | 'vee';
8
+ export declare const DefaultLineStyle = "dashed";
9
+ export declare const DefaultArrowType = "normal";
10
+ export declare const DefaultRelationshipColor = "gray";
11
+ export interface Relation {
12
+ readonly id: RelationID;
13
+ readonly source: Fqn;
14
+ readonly target: Fqn;
15
+ readonly title: string;
16
+ readonly tags?: Tag[];
17
+ readonly kind?: RelationshipKind;
18
+ readonly color?: ThemeColor;
19
+ readonly line?: RelationshipLineType;
20
+ readonly head?: RelationshipArrowType;
21
+ readonly tail?: RelationshipArrowType;
22
+ }
@@ -0,0 +1,3 @@
1
+ export const DefaultLineStyle = "dashed";
2
+ export const DefaultArrowType = "normal";
3
+ export const DefaultRelationshipColor = "gray";
@@ -0,0 +1,26 @@
1
+ export type ThemeColor = 'amber' | 'blue' | 'gray' | 'slate' | 'green' | 'indigo' | 'muted' | 'primary' | 'red' | 'secondary' | 'sky';
2
+ export type HexColorLiteral = `#${string}`;
3
+ export type ColorLiteral = HexColorLiteral;
4
+ export interface ElementThemeColorValues {
5
+ fill: ColorLiteral;
6
+ stroke: ColorLiteral;
7
+ hiContrast: ColorLiteral;
8
+ loContrast: ColorLiteral;
9
+ }
10
+ export type ElementThemeColors = {
11
+ [key in ThemeColor]: ElementThemeColorValues;
12
+ };
13
+ export interface RelationshipThemeColorValues {
14
+ lineColor: ColorLiteral;
15
+ labelBgColor: ColorLiteral;
16
+ labelColor: ColorLiteral;
17
+ }
18
+ export type RelationshipThemeColors = {
19
+ [key in ThemeColor]: RelationshipThemeColorValues;
20
+ };
21
+ export interface LikeC4Theme {
22
+ font: 'Helvetica';
23
+ shadow: ColorLiteral;
24
+ relationships: RelationshipThemeColors;
25
+ elements: ElementThemeColors;
26
+ }
@@ -0,0 +1,61 @@
1
+ import type { Opaque } from './opaque';
2
+ import type { ElementShape, Fqn, Tag } from './element';
3
+ import type { ElementExpression, Expression } from './expression';
4
+ import type { IconUrl, NonEmptyArray } from './_common';
5
+ import type { ThemeColor } from './theme';
6
+ export type ViewID = Opaque<string, 'ViewID'>;
7
+ export type ViewRuleExpression = {
8
+ include: Expression[];
9
+ exclude?: never;
10
+ } | {
11
+ include?: never;
12
+ exclude: Expression[];
13
+ };
14
+ export declare function isViewRuleExpression(rule: ViewRule): rule is ViewRuleExpression;
15
+ export interface ViewRuleStyle {
16
+ targets: ElementExpression[];
17
+ style: {
18
+ color?: ThemeColor;
19
+ shape?: ElementShape;
20
+ icon?: IconUrl;
21
+ };
22
+ }
23
+ export declare function isViewRuleStyle(rule: ViewRule): rule is ViewRuleStyle;
24
+ export interface ViewRuleAutoLayout {
25
+ autoLayout: 'TB' | 'BT' | 'LR' | 'RL';
26
+ }
27
+ export declare function isViewRuleAutoLayout(rule: ViewRule): rule is ViewRuleAutoLayout;
28
+ export type ViewRule = ViewRuleExpression | ViewRuleStyle | ViewRuleAutoLayout;
29
+ export interface BasicElementView {
30
+ readonly id: ViewID;
31
+ readonly viewOf?: Fqn;
32
+ readonly title: string | null;
33
+ readonly description: string | null;
34
+ readonly tags: NonEmptyArray<Tag> | null;
35
+ readonly links: NonEmptyArray<string> | null;
36
+ readonly rules: ViewRule[];
37
+ /**
38
+ * URI to the source file of this view.
39
+ * Undefined if the view is auto-generated.
40
+ */
41
+ readonly docUri?: string;
42
+ /**
43
+ * For all views we find common ancestor path.
44
+ * This is used to generate relative paths, i.e.:
45
+ * - "" for views in the common ancestor directory (or root)
46
+ * - "subdir" for views in "<root>/subdir"
47
+ * - "subdir/subdir1" for views in "<root>/subdir/subdir1"
48
+ *
49
+ * Undefined if the view is auto-generated.
50
+ */
51
+ readonly relativePath?: string;
52
+ }
53
+ export interface StrictElementView extends BasicElementView {
54
+ readonly viewOf: Fqn;
55
+ }
56
+ export declare function isStrictElementView(view: ElementView): view is StrictElementView;
57
+ export interface ExtendsElementView extends BasicElementView {
58
+ readonly extends: ViewID;
59
+ }
60
+ export declare function isExtendsElementView(view: ElementView): view is ExtendsElementView;
61
+ export type ElementView = StrictElementView | ExtendsElementView | BasicElementView;
@@ -1,5 +1,5 @@
1
1
  export function isViewRuleExpression(rule) {
2
- return "exprs" in rule && "isInclude" in rule;
2
+ return "include" in rule && Array.isArray(rule.include) || "exclude" in rule && Array.isArray(rule.exclude);
3
3
  }
4
4
  export function isViewRuleStyle(rule) {
5
5
  return "style" in rule && "targets" in rule;
@@ -0,0 +1,33 @@
1
+ import type { Element, Fqn } from '../types';
2
+ export declare function nameFromFqn(fqn: Fqn): string;
3
+ export declare function isAncestor<E extends {
4
+ id: Fqn;
5
+ }>(...args: [ancestor: Fqn, another: Fqn] | [ancestor: E, another: E]): boolean;
6
+ export declare function isSameHierarchy<E extends {
7
+ id: Fqn;
8
+ }>(one: E | Fqn, another: E | Fqn): boolean;
9
+ export declare function isDescendantOf<E extends {
10
+ id: Fqn;
11
+ }>(ancestors: E[]): (e: E) => boolean;
12
+ export declare function notDescendantOf(ancestors: Element[]): (e: Element) => boolean;
13
+ export declare function commonAncestor(first: Fqn, second: Fqn): Fqn | null;
14
+ export declare function parentFqn(fqn: Fqn): Fqn | null;
15
+ /**
16
+ * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
17
+ * (from closest to root)
18
+ */
19
+ export declare function ancestorsFqn(fqn: Fqn): Fqn[];
20
+ /**
21
+ * Compares two fully qualified names (fqns) hierarchically based on their depth.
22
+ * From parent nodes to leaves
23
+ *
24
+ * @param {string} a - The first fqn to compare.
25
+ * @param {string} b - The second fqn to compare.
26
+ * @returns {number} - 0 if the fqns have the same depth.
27
+ * - Positive number if a is deeper than b.
28
+ * - Negative number if b is deeper than a.
29
+ */
30
+ export declare function compareFqnHierarchically(a: string, b: string): number;
31
+ export declare function compareByFqnHierarchically<T extends {
32
+ id: Fqn;
33
+ }>(a: T, b: T): number;
@@ -13,10 +13,10 @@ export function isAncestor(...args) {
13
13
  const another = isString(args[1]) ? args[1] : args[1].id;
14
14
  return another.startsWith(ancestor + ".");
15
15
  }
16
- export function isSameHierarchy(...args) {
17
- const one = isString(args[0]) ? args[0] : args[0].id;
18
- const another = isString(args[1]) ? args[1] : args[1].id;
19
- return one === another || another.startsWith(one + ".") || one.startsWith(another + ".");
16
+ export function isSameHierarchy(one, another) {
17
+ const first = isString(one) ? one : one.id;
18
+ const second = isString(another) ? another : another.id;
19
+ return first === second || second.startsWith(first + ".") || first.startsWith(second + ".");
20
20
  }
21
21
  export function isDescendantOf(ancestors) {
22
22
  const predicates = ancestors.flatMap((a) => [(e) => e.id === a.id, (e) => isAncestor(a, e)]);
@@ -52,6 +52,18 @@ export function parentFqn(fqn) {
52
52
  }
53
53
  return null;
54
54
  }
55
+ export function ancestorsFqn(fqn) {
56
+ const path = fqn.split(".");
57
+ path.pop();
58
+ if (path.length === 0) {
59
+ return [];
60
+ }
61
+ return path.reduce((acc, _, idx) => {
62
+ const ancestor = path.slice(0, idx + 1).join(".");
63
+ acc.unshift(ancestor);
64
+ return acc;
65
+ }, []);
66
+ }
55
67
  export function compareFqnHierarchically(a, b) {
56
68
  const depthA = a.split(".").length;
57
69
  const depthB = b.split(".").length;
@@ -0,0 +1,4 @@
1
+ import type { NonEmptyArray } from '../types';
2
+ export { hasAtLeast } from 'remeda';
3
+ export declare function isString(value: unknown): value is string;
4
+ export declare function isNonEmptyArray<A>(arr: ArrayLike<A>): arr is NonEmptyArray<A>;
@@ -0,0 +1,7 @@
1
+ export { hasAtLeast } from "remeda";
2
+ export function isString(value) {
3
+ return value != null && typeof value === "string";
4
+ }
5
+ export function isNonEmptyArray(arr) {
6
+ return arr.length > 0;
7
+ }
@@ -0,0 +1,3 @@
1
+ export * from './fqn';
2
+ export * from './guards';
3
+ export * from './relations';
@@ -1,4 +1,3 @@
1
1
  export * from "./fqn.js";
2
2
  export * from "./guards.js";
3
- export * from "./compute-node-levels.js";
4
3
  export * from "./relations.js";
@@ -0,0 +1,25 @@
1
+ import type { Fqn } from '../types';
2
+ type Relation = {
3
+ source: string;
4
+ target: string;
5
+ };
6
+ type RelationPredicate = (rel: Relation) => boolean;
7
+ export declare const compareRelations: <T extends {
8
+ source: string;
9
+ target: string;
10
+ }>(a: T, b: T) => number;
11
+ export declare const Relations: {
12
+ readonly isInside: (parent: Fqn) => RelationPredicate;
13
+ readonly isBetween: (source: Fqn, target: Fqn) => RelationPredicate;
14
+ readonly isAnyBetween: (source: Fqn, target: Fqn) => RelationPredicate;
15
+ readonly isIncoming: (target: Fqn) => RelationPredicate;
16
+ readonly isOutgoing: (source: Fqn) => RelationPredicate;
17
+ readonly isAnyInOut: (source: Fqn) => RelationPredicate;
18
+ readonly hasRelation: <R extends {
19
+ source: Fqn;
20
+ target: Fqn;
21
+ }>(rel: R) => <E extends {
22
+ id: Fqn;
23
+ }>(element: E) => boolean;
24
+ };
25
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likec4/core",
3
- "version": "0.37.1",
3
+ "version": "0.41.0",
4
4
  "license": "MIT",
5
5
  "homepage": "https://likec4.dev",
6
6
  "author": "Denis Davydkov <denis@davydkov.com>",
@@ -11,105 +11,88 @@
11
11
  },
12
12
  "bugs": "https://github.com/likec4/likec4/issues",
13
13
  "scripts": {
14
- "compile": "tsc --noEmit",
15
- "build": "tsc",
16
- "prepack": "unbuild",
17
- "dev": "tsc --watch",
14
+ "typecheck": "tsc --noEmit",
15
+ "build": "unbuild",
16
+ "prepack": "run clean && run build",
18
17
  "lint": "run -T eslint src/ --fix",
19
18
  "test": "run -T vitest run",
20
- "test:watch": "run -T vitest",
21
19
  "clean": "run -T rimraf dist"
22
20
  },
23
21
  "files": [
24
- "dist"
22
+ "dist",
23
+ "!**/*.spec.*",
24
+ "!**/*.map"
25
25
  ],
26
26
  "type": "module",
27
27
  "sideEffects": false,
28
- "main": "./dist/index.cjs",
29
- "module": "./dist/index.js",
30
- "types": "./dist/index.d.ts",
31
28
  "exports": {
32
29
  ".": {
33
- "types": "./dist/index.d.ts",
34
- "import": "./dist/index.js",
35
- "require": "./dist/index.cjs"
36
- },
37
- "./types": {
38
30
  "types": "./dist/types/index.d.ts",
39
- "import": "./dist/types/index.js",
40
- "require": "./dist/types/index.cjs"
31
+ "import": "./dist/esm/index.js",
32
+ "require": "./dist/cjs/index.js"
41
33
  },
42
34
  "./colors": {
43
- "types": "./dist/colors.d.ts",
44
- "import": "./dist/colors.js",
45
- "require": "./dist/colors.cjs"
35
+ "types": "./dist/types/colors/index.d.ts",
36
+ "import": "./dist/esm/colors/index.js",
37
+ "require": "./dist/cjs/colors/index.js"
46
38
  },
47
- "./errors": {
48
- "types": "./dist/errors/index.d.ts",
49
- "import": "./dist/errors/index.js",
50
- "require": "./dist/errors/index.cjs"
39
+ "./types": {
40
+ "types": "./dist/types/types/index.d.ts",
41
+ "import": "./dist/esm/types/index.js",
42
+ "require": "./dist/cjs/types/index.js"
51
43
  },
52
44
  "./utils": {
53
- "types": "./dist/utils/index.d.ts",
54
- "import": "./dist/utils/index.js",
55
- "require": "./dist/utils/index.cjs"
56
- },
57
- "./compute-view": {
58
- "types": "./dist/compute-view/index.d.ts",
59
- "import": "./dist/compute-view/index.js",
60
- "require": "./dist/compute-view/index.cjs"
45
+ "types": "./dist/types/utils/index.d.ts",
46
+ "import": "./dist/esm/utils/index.js",
47
+ "require": "./dist/cjs/utils/index.js"
61
48
  }
62
49
  },
63
50
  "publishConfig": {
64
51
  "registry": "https://registry.npmjs.org",
65
52
  "access": "public",
66
- "main": "./dist/index.cjs",
67
- "module": "./dist/index.js",
68
- "types": "./dist/index.d.ts",
53
+ "main": "./dist/cjs/index.js",
54
+ "module": "./dist/esm/index.js",
55
+ "types": "./dist/types/index.d.ts",
69
56
  "exports": {
70
57
  ".": {
71
- "types": "./dist/index.d.ts",
72
- "import": "./dist/index.js",
73
- "require": "./dist/index.cjs"
74
- },
75
- "./types": {
76
58
  "types": "./dist/types/index.d.ts",
77
- "import": "./dist/types/index.js",
78
- "require": "./dist/types/index.cjs"
59
+ "import": "./dist/esm/index.js",
60
+ "require": "./dist/cjs/index.js"
79
61
  },
80
62
  "./colors": {
81
- "types": "./dist/colors.d.ts",
82
- "import": "./dist/colors.js",
83
- "require": "./dist/colors.cjs"
63
+ "types": "./dist/types/colors/index.d.ts",
64
+ "import": "./dist/esm/colors/index.js",
65
+ "require": "./dist/cjs/colors/index.js"
84
66
  },
85
- "./errors": {
86
- "types": "./dist/errors/index.d.ts",
87
- "import": "./dist/errors/index.js",
88
- "require": "./dist/errors/index.cjs"
67
+ "./types": {
68
+ "types": "./dist/types/types/index.d.ts",
69
+ "import": "./dist/esm/types/index.js",
70
+ "require": "./dist/cjs/types/index.js"
89
71
  },
90
72
  "./utils": {
91
- "types": "./dist/utils/index.d.ts",
92
- "import": "./dist/utils/index.js",
93
- "require": "./dist/utils/index.cjs"
94
- },
95
- "./compute-view": {
96
- "types": "./dist/compute-view/index.d.ts",
97
- "import": "./dist/compute-view/index.js",
98
- "require": "./dist/compute-view/index.cjs"
73
+ "types": "./dist/types/utils/index.d.ts",
74
+ "import": "./dist/esm/utils/index.js",
75
+ "require": "./dist/cjs/utils/index.js"
99
76
  }
100
77
  }
101
78
  },
102
79
  "dependencies": {
103
- "@dagrejs/graphlib": "^2.1.13",
104
80
  "rambdax": "^9.1.1",
105
- "remeda": "^1.24.0",
81
+ "remeda": "^1.27.1",
106
82
  "safe-stable-stringify": "^2.4.3",
107
83
  "ts-custom-error": "^3.3.1"
108
84
  },
109
85
  "devDependencies": {
86
+ "execa": "^8.0.1",
110
87
  "typescript": "^5.2.2",
111
88
  "unbuild": "^2.0.0",
112
- "vitest": "^0.34.4"
89
+ "vitest": "^0.34.6"
90
+ },
91
+ "packageManager": "yarn@3.6.4",
92
+ "volta": {
93
+ "extends": "../../package.json"
113
94
  },
114
- "packageManager": "yarn@3.6.3"
95
+ "main": "./dist/cjs/index.js",
96
+ "module": "./dist/esm/index.js",
97
+ "types": "./dist/types/index.d.ts"
115
98
  }
package/dist/colors.cjs DELETED
@@ -1,124 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.defaultTheme = exports.RelationColors = exports.Colors = void 0;
7
- const blue = {
8
- // fill: colors.blue[500],
9
- // stroke: colors.blue[600],
10
- // hiContrast: colors.blue[50],
11
- // loContrast: colors.blue[100],
12
- fill: "#3b82f6",
13
- stroke: "#2563eb",
14
- hiContrast: "#eff6ff",
15
- loContrast: "#dbeafe"
16
- };
17
- const sky = {
18
- // fill: colors.sky[600],
19
- // stroke: colors.sky[700],
20
- // hiContrast: colors.sky[50],
21
- // loContrast: colors.sky[100],
22
- fill: "#0284c7",
23
- stroke: "#0369a1",
24
- hiContrast: "#f0f9ff",
25
- loContrast: "#e0f2fe"
26
- };
27
- const slate = {
28
- // fill: colors.slate[500],
29
- // stroke: colors.slate[600],
30
- // hiContrast: colors.slate[50],
31
- // loContrast: colors.slate[200],
32
- fill: "#64748b",
33
- stroke: "#475569",
34
- hiContrast: "#f8fafc",
35
- loContrast: "#e2e8f0"
36
- };
37
- const RelationColors = {
38
- // lineColor: colors.neutral[400],
39
- // labelColor: colors.neutral[300],
40
- lineColor: "#a3a3a3",
41
- labelColor: "#d4d4d4"
42
- };
43
- exports.RelationColors = RelationColors;
44
- const Colors = {
45
- primary: blue,
46
- blue,
47
- secondary: sky,
48
- sky,
49
- muted: slate,
50
- slate,
51
- gray: {
52
- // fill: colors.neutral[500],
53
- // stroke: colors.neutral[600],
54
- // hiContrast: colors.neutral[50],
55
- // loContrast: colors.neutral[200],
56
- fill: "#737373",
57
- stroke: "#525252",
58
- hiContrast: "#fafafa",
59
- loContrast: "#e5e5e5"
60
- },
61
- red: {
62
- // fill: colors.red[500],
63
- // stroke: colors.red[600],
64
- // hiContrast: colors.red[50],
65
- // loContrast: colors.red[200],
66
- fill: "#ef4444",
67
- stroke: "#dc2626",
68
- // hiContrast: '#fef2f2',
69
- // loContrast: '#fecaca',
70
- hiContrast: "#111827",
71
- // colors.gray[900],
72
- loContrast: "#1f2937"
73
- // colors.gray[800],
74
- },
75
-
76
- green: {
77
- // fill: colors.green[600],
78
- // stroke: colors.green[700],
79
- // hiContrast: colors.green[50],
80
- // loContrast: colors.green[200],
81
- fill: "#16a34a",
82
- stroke: "#15803d",
83
- hiContrast: "#111827",
84
- // colors.gray[900],
85
- // hiContrast: '#f0fdf4',
86
- loContrast: "#1f2937"
87
- // colors.gray[800],
88
- // loContrast: '#bbf7d0'
89
- },
90
-
91
- amber: {
92
- // fill: colors.amber[600],
93
- // stroke: colors.amber[700],
94
- // hiContrast: colors.amber[50],
95
- // loContrast: colors.amber[200],
96
- fill: "#d97706",
97
- stroke: "#b45309",
98
- // hiContrast: '#fffbeb',
99
- // loContrast: '#fde68a',
100
- hiContrast: "#111827",
101
- // colors.gray[900],
102
- loContrast: "#1f2937"
103
- // colors.gray[800],
104
- },
105
-
106
- indigo: {
107
- // fill: colors.indigo[500],
108
- // stroke: colors.indigo[600],
109
- // hiContrast: colors.indigo[50],
110
- // loContrast: colors.indigo[200],
111
- fill: "#6366f1",
112
- stroke: "#4f46e5",
113
- hiContrast: "#eef2ff",
114
- loContrast: "#c7d2fe"
115
- }
116
- };
117
- exports.Colors = Colors;
118
- const defaultTheme = {
119
- font: "Helvetica",
120
- shadow: "#0a0a0a",
121
- relation: RelationColors,
122
- colors: Colors
123
- };
124
- exports.defaultTheme = defaultTheme;