@likec4/core 1.8.1 → 1.10.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 (94) hide show
  1. package/dist/index.cjs +4467 -0
  2. package/dist/index.d.cts +793 -0
  3. package/dist/index.d.mts +793 -0
  4. package/dist/index.d.ts +793 -7
  5. package/dist/index.mjs +4390 -0
  6. package/dist/shared/core.CpR2fq5B.d.cts +833 -0
  7. package/dist/shared/core.CpR2fq5B.d.mts +833 -0
  8. package/dist/shared/core.CpR2fq5B.d.ts +833 -0
  9. package/dist/shared/core.Db3ntVII.cjs +318 -0
  10. package/dist/shared/core.DeifT5lC.mjs +263 -0
  11. package/dist/types/index.cjs +55 -0
  12. package/dist/types/index.d.cts +1 -0
  13. package/dist/types/index.d.mts +1 -0
  14. package/dist/types/index.d.ts +1 -14
  15. package/dist/types/index.mjs +1 -0
  16. package/package.json +43 -33
  17. package/src/colors/index.ts +27 -1
  18. package/src/errors/index.ts +3 -95
  19. package/src/index.ts +6 -6
  20. package/src/model/LikeC4Model.ts +480 -0
  21. package/src/model/LikeC4ViewModel.ts +318 -0
  22. package/src/model/__test__/LikeC4Model.spec.ts +79 -0
  23. package/src/model/__test__/fixture.ts +333 -0
  24. package/src/model/index.ts +2 -0
  25. package/src/model/types.ts +10 -0
  26. package/src/types/_common.ts +4 -2
  27. package/src/types/element.ts +11 -8
  28. package/src/types/expression.ts +7 -3
  29. package/src/types/index.ts +0 -1
  30. package/src/types/model.ts +16 -6
  31. package/src/types/relation.ts +18 -5
  32. package/src/types/theme.ts +28 -12
  33. package/src/types/view-notation.ts +3 -4
  34. package/src/types/view.ts +51 -16
  35. package/src/utils/compare-natural.spec.ts +37 -0
  36. package/src/utils/compare-natural.ts +14 -0
  37. package/src/utils/fqn.spec.ts +99 -2
  38. package/src/utils/fqn.ts +45 -5
  39. package/src/utils/index.ts +1 -0
  40. package/src/utils/relations.spec.ts +2 -4
  41. package/src/utils/relations.ts +14 -24
  42. package/dist/colors/element.d.ts +0 -69
  43. package/dist/colors/element.js +0 -75
  44. package/dist/colors/index.d.ts +0 -133
  45. package/dist/colors/index.js +0 -9
  46. package/dist/colors/relationships.d.ts +0 -58
  47. package/dist/colors/relationships.js +0 -49
  48. package/dist/errors/errors.spec.d.ts +0 -2
  49. package/dist/errors/errors.spec.js +0 -69
  50. package/dist/errors/index.d.ts +0 -39
  51. package/dist/errors/index.js +0 -104
  52. package/dist/index.js +0 -4
  53. package/dist/types/_common.d.ts +0 -9
  54. package/dist/types/_common.js +0 -1
  55. package/dist/types/element.d.ts +0 -55
  56. package/dist/types/element.js +0 -15
  57. package/dist/types/expression.d.ts +0 -119
  58. package/dist/types/expression.js +0 -67
  59. package/dist/types/index.js +0 -14
  60. package/dist/types/model.d.ts +0 -14
  61. package/dist/types/model.js +0 -1
  62. package/dist/types/opaque.d.ts +0 -103
  63. package/dist/types/opaque.js +0 -1
  64. package/dist/types/operators.d.ts +0 -44
  65. package/dist/types/operators.js +0 -59
  66. package/dist/types/overview-graph.d.ts +0 -41
  67. package/dist/types/overview-graph.js +0 -1
  68. package/dist/types/relation.d.ts +0 -30
  69. package/dist/types/relation.js +0 -3
  70. package/dist/types/theme.d.ts +0 -27
  71. package/dist/types/theme.js +0 -1
  72. package/dist/types/view-changes.d.ts +0 -26
  73. package/dist/types/view-changes.js +0 -1
  74. package/dist/types/view-notation.d.ts +0 -9
  75. package/dist/types/view-notation.js +0 -1
  76. package/dist/types/view.d.ts +0 -243
  77. package/dist/types/view.js +0 -50
  78. package/dist/utils/fqn.d.ts +0 -39
  79. package/dist/utils/fqn.js +0 -102
  80. package/dist/utils/fqn.spec.d.ts +0 -2
  81. package/dist/utils/fqn.spec.js +0 -82
  82. package/dist/utils/guards.d.ts +0 -5
  83. package/dist/utils/guards.js +0 -7
  84. package/dist/utils/index.d.ts +0 -5
  85. package/dist/utils/index.js +0 -4
  86. package/dist/utils/promises.d.ts +0 -2
  87. package/dist/utils/promises.js +0 -8
  88. package/dist/utils/relations.d.ts +0 -30
  89. package/dist/utils/relations.js +0 -79
  90. package/dist/utils/relations.spec.d.ts +0 -2
  91. package/dist/utils/relations.spec.js +0 -210
  92. package/src/errors/errors.spec.ts +0 -88
  93. package/src/reset.d.ts +0 -2
  94. package/src/types/opaque.ts +0 -108
@@ -1,67 +0,0 @@
1
- export function isElementRef(expr) {
2
- return 'element' in expr;
3
- }
4
- export function isExpandedElementExpr(expr) {
5
- return 'expanded' in expr;
6
- }
7
- export function isCustomElement(expr) {
8
- return 'custom' in expr && (isElement(expr.custom.expr) || isElementWhere(expr.custom.expr));
9
- }
10
- export function isWildcard(expr) {
11
- return 'wildcard' in expr;
12
- }
13
- export function isElementKindExpr(expr) {
14
- return 'elementKind' in expr && 'isEqual' in expr;
15
- }
16
- export function isElementTagExpr(expr) {
17
- return 'elementTag' in expr && 'isEqual' in expr;
18
- }
19
- export function isElement(expr) {
20
- return isElementRef(expr)
21
- || isWildcard(expr)
22
- || isElementKindExpr(expr)
23
- || isElementTagExpr(expr)
24
- || isExpandedElementExpr(expr);
25
- }
26
- export function isElementWhere(expr) {
27
- return 'where' in expr && isElement(expr.where.expr);
28
- }
29
- export function isElementPredicateExpr(expr) {
30
- return isElement(expr) || isElementWhere(expr) || isCustomElement(expr);
31
- }
32
- export function isRelation(expr) {
33
- return 'source' in expr && 'target' in expr;
34
- }
35
- export function isInOut(expr) {
36
- return 'inout' in expr;
37
- }
38
- export function isIncoming(expr) {
39
- return 'incoming' in expr;
40
- }
41
- export function isOutgoing(expr) {
42
- return 'outgoing' in expr;
43
- }
44
- export function isRelationExpression(expr) {
45
- return isRelation(expr) || isInOut(expr) || isIncoming(expr) || isOutgoing(expr);
46
- }
47
- export function isRelationWhere(expr) {
48
- return 'where' in expr && isRelationExpression(expr.where.expr);
49
- }
50
- export function isCustomRelationExpr(expr) {
51
- return 'customRelation' in expr;
52
- }
53
- export function isRelationPredicateExpr(expr) {
54
- return isRelationExpression(expr) || isRelationWhere(expr) || isCustomRelationExpr(expr);
55
- }
56
- // export const Expr = {
57
- // isElementRef,
58
- // isWildcard,
59
- // isElementKindExpr,
60
- // isElementTagExpr,
61
- // isElement,
62
- // isRelation,
63
- // isInOut,
64
- // isIncoming,
65
- // isOutgoing,
66
- // isAnyRelation,
67
- // }
@@ -1,14 +0,0 @@
1
- export * from './_common';
2
- export * from './element';
3
- export * from './expression';
4
- export * from './model';
5
- export * from './opaque';
6
- export * from './operators';
7
- export * from './overview-graph';
8
- export * from './relation';
9
- export * from './theme';
10
- export * from './view';
11
- export * from './view-changes';
12
- export * from './view-notation';
13
- import * as Expr_1 from './expression';
14
- export { Expr_1 as Expr };
@@ -1,14 +0,0 @@
1
- import type { Element, Fqn } from './element';
2
- import type { Relation, RelationID } from './relation';
3
- import type { ComputedView, LikeC4View, ViewID } from './view';
4
- export interface LikeC4Model {
5
- elements: Record<Fqn, Element>;
6
- relations: Record<RelationID, Relation>;
7
- views: Record<ViewID, LikeC4View>;
8
- }
9
- export interface LikeC4ComputedModel {
10
- elements: Record<Fqn, Element>;
11
- relations: Record<RelationID, Relation>;
12
- views: Record<ViewID, ComputedView>;
13
- }
14
- //# sourceMappingURL=model.d.ts.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,103 +0,0 @@
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 {};
103
- //# sourceMappingURL=opaque.d.ts.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,44 +0,0 @@
1
- import type { NonEmptyArray } from './_common';
2
- export type EqualOperator<V> = {
3
- eq: V;
4
- neq?: never;
5
- } | {
6
- eq?: never;
7
- neq: V;
8
- };
9
- type AllNever = {
10
- not?: never;
11
- and?: never;
12
- or?: never;
13
- tag?: never;
14
- kind?: never;
15
- };
16
- export type TagEqual<Tag> = Omit<AllNever, 'tag'> & {
17
- tag: EqualOperator<Tag>;
18
- };
19
- export declare const isTagEqual: <Tag>(operator: WhereOperator<Tag, any>) => operator is TagEqual<Tag>;
20
- export type KindEqual<Kind> = Omit<AllNever, 'kind'> & {
21
- kind: EqualOperator<Kind>;
22
- };
23
- export declare const isKindEqual: <Kind>(operator: WhereOperator<any, Kind>) => operator is KindEqual<Kind>;
24
- export type NotOperator<Tag, Kind> = Omit<AllNever, 'not'> & {
25
- not: WhereOperator<Tag, Kind>;
26
- };
27
- export declare const isNotOperator: <Tag, Kind>(operator: WhereOperator<Tag, Kind>) => operator is NotOperator<Tag, Kind>;
28
- export type AndOperator<Tag, Kind> = Omit<AllNever, 'and'> & {
29
- and: NonEmptyArray<WhereOperator<Tag, Kind>>;
30
- };
31
- export declare const isAndOperator: <Tag, Kind>(operator: WhereOperator<Tag, Kind>) => operator is AndOperator<Tag, Kind>;
32
- export type OrOperator<Tag, Kind> = Omit<AllNever, 'or'> & {
33
- or: NonEmptyArray<WhereOperator<Tag, Kind>>;
34
- };
35
- export declare const isOrOperator: <Tag, Kind>(operator: WhereOperator<Tag, Kind>) => operator is OrOperator<Tag, Kind>;
36
- export type WhereOperator<Tag, Kind> = TagEqual<Tag> | KindEqual<Kind> | NotOperator<Tag, Kind> | AndOperator<Tag, Kind> | OrOperator<Tag, Kind>;
37
- type Filterable<FTag extends string = string, FKind extends string = string> = {
38
- tags?: FTag[] | null;
39
- kind?: FKind;
40
- };
41
- type OperatorPredicate<V extends Filterable> = (value: V) => boolean;
42
- export declare function whereOperatorAsPredicate<FTag extends string = string, FKind extends string = string>(operator: WhereOperator<FTag, FKind>): OperatorPredicate<Filterable<FTag, FKind>>;
43
- export {};
44
- //# sourceMappingURL=operators.d.ts.map
@@ -1,59 +0,0 @@
1
- import { allPass, anyPass, isNot, isNullish } from 'remeda';
2
- import { nonexhaustive } from '../errors';
3
- export const isTagEqual = (operator) => {
4
- return 'tag' in operator;
5
- };
6
- export const isKindEqual = (operator) => {
7
- return 'kind' in operator;
8
- };
9
- export const isNotOperator = (operator) => {
10
- return 'not' in operator;
11
- };
12
- export const isAndOperator = (operator) => {
13
- return 'and' in operator;
14
- };
15
- export const isOrOperator = (operator) => {
16
- return 'or' in operator;
17
- };
18
- export function whereOperatorAsPredicate(operator) {
19
- switch (true) {
20
- case isTagEqual(operator): {
21
- if ('eq' in operator.tag) {
22
- const tag = operator.tag.eq;
23
- return (value) => {
24
- return Array.isArray(value.tags) && value.tags.includes(tag);
25
- };
26
- }
27
- const tag = operator.tag.neq;
28
- return (value) => {
29
- return !Array.isArray(value.tags) || !value.tags.includes(tag);
30
- };
31
- }
32
- case isKindEqual(operator): {
33
- if ('eq' in operator.kind) {
34
- const kind = operator.kind.eq;
35
- return (value) => {
36
- return value.kind === kind;
37
- };
38
- }
39
- const kind = operator.kind.neq;
40
- return (value) => {
41
- return isNullish(value.kind) || value.kind !== kind;
42
- };
43
- }
44
- case isNotOperator(operator): {
45
- const predicate = whereOperatorAsPredicate(operator.not);
46
- return isNot(predicate);
47
- }
48
- case isAndOperator(operator): {
49
- const predicates = operator.and.map(whereOperatorAsPredicate);
50
- return allPass(predicates);
51
- }
52
- case isOrOperator(operator): {
53
- const predicates = operator.or.map(whereOperatorAsPredicate);
54
- return anyPass(predicates);
55
- }
56
- default:
57
- nonexhaustive(operator);
58
- }
59
- }
@@ -1,41 +0,0 @@
1
- import type { NonEmptyArray, Point, XYPoint } from './_common';
2
- import type { BBox, ViewID } from './view';
3
- /**
4
- * OverviewGraph is a graph representation of all views in a model
5
- */
6
- export declare namespace OverviewGraph {
7
- type Node = {
8
- id: string;
9
- type: 'folder' | 'file';
10
- path: string;
11
- label: string;
12
- parentId: string | null;
13
- position: XYPoint;
14
- width: number;
15
- height: number;
16
- } | {
17
- id: string;
18
- type: 'view';
19
- viewId: ViewID;
20
- label: string;
21
- parentId: string | null;
22
- position: XYPoint;
23
- width: number;
24
- height: number;
25
- };
26
- /**
27
- * Edge represents a navigational link from one view to another
28
- */
29
- type Edge = {
30
- id: string;
31
- source: string;
32
- target: string;
33
- points: NonEmptyArray<Point>;
34
- };
35
- }
36
- export interface OverviewGraph {
37
- nodes: OverviewGraph.Node[];
38
- edges: OverviewGraph.Edge[];
39
- bounds: BBox;
40
- }
41
- //# sourceMappingURL=overview-graph.d.ts.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- import type { NonEmptyArray } from './_common';
2
- import type { Fqn, Link, Tag } from './element';
3
- import type { Opaque } from './opaque';
4
- import type { ThemeColor } from './theme';
5
- export type RelationID = Opaque<string, 'RelationID'>;
6
- export type RelationshipKind = Opaque<string, 'RelationshipKind'>;
7
- export type RelationshipLineType = 'dashed' | 'solid' | 'dotted';
8
- export type RelationshipArrowType = 'none' | 'normal' | 'onormal' | 'dot' | 'odot' | 'diamond' | 'odiamond' | 'crow' | 'open' | 'vee';
9
- export declare const DefaultLineStyle = "dashed";
10
- export declare const DefaultArrowType = "normal";
11
- export declare const DefaultRelationshipColor = "gray";
12
- export interface Relation {
13
- readonly id: RelationID;
14
- readonly source: Fqn;
15
- readonly target: Fqn;
16
- readonly title: string;
17
- readonly description?: string;
18
- readonly technology?: string;
19
- readonly tags?: NonEmptyArray<Tag>;
20
- readonly kind?: RelationshipKind;
21
- readonly color?: ThemeColor;
22
- readonly line?: RelationshipLineType;
23
- readonly head?: RelationshipArrowType;
24
- readonly tail?: RelationshipArrowType;
25
- readonly links?: NonEmptyArray<Link>;
26
- readonly metadata?: {
27
- [key: string]: string;
28
- };
29
- }
30
- //# sourceMappingURL=relation.d.ts.map
@@ -1,3 +0,0 @@
1
- export const DefaultLineStyle = 'dashed';
2
- export const DefaultArrowType = 'normal';
3
- export const DefaultRelationshipColor = 'gray';
@@ -1,27 +0,0 @@
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: 'Arial';
23
- shadow: ColorLiteral;
24
- relationships: RelationshipThemeColors;
25
- elements: ElementThemeColors;
26
- }
27
- //# sourceMappingURL=theme.d.ts.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- import type { NonEmptyArray } from './_common';
2
- import type { BorderStyle, ElementShape, Fqn } from './element';
3
- import type { ThemeColor } from './theme';
4
- import type { AutoLayoutDirection, ViewManualLayout } from './view';
5
- export declare namespace ViewChange {
6
- interface ChangeElementStyle {
7
- op: 'change-element-style';
8
- style: {
9
- border?: BorderStyle;
10
- opacity?: number;
11
- shape?: ElementShape;
12
- color?: ThemeColor;
13
- };
14
- targets: NonEmptyArray<Fqn>;
15
- }
16
- interface SaveManualLayout {
17
- op: 'save-manual-layout';
18
- layout: ViewManualLayout;
19
- }
20
- interface ChangeAutoLayout {
21
- op: 'change-autolayout';
22
- layout: AutoLayoutDirection;
23
- }
24
- }
25
- export type ViewChange = ViewChange.ChangeElementStyle | ViewChange.SaveManualLayout | ViewChange.ChangeAutoLayout;
26
- //# sourceMappingURL=view-changes.d.ts.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- import type { ElementKind, ElementShape } from './element';
2
- import type { ThemeColor } from './theme';
3
- export type ElementNotation = {
4
- kinds: ElementKind[];
5
- shape: ElementShape;
6
- color: ThemeColor;
7
- title: string;
8
- };
9
- //# sourceMappingURL=view-notation.d.ts.map
@@ -1 +0,0 @@
1
- export {};