@likec4/core 1.0.0-next.10 → 1.0.0-next.14

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 (112) hide show
  1. package/dist/{cjs/errors → errors}/index.d.ts +1 -1
  2. package/dist/types/{types/expression.d.ts → expression.d.ts} +7 -2
  3. package/dist/types/expression.js +8 -1
  4. package/dist/types/index.d.ts +11 -7
  5. package/dist/{cjs/utils → utils}/index.d.ts +1 -0
  6. package/dist/utils/index.js +1 -0
  7. package/dist/utils/promises.d.ts +1 -0
  8. package/dist/utils/promises.js +8 -0
  9. package/package.json +23 -38
  10. package/dist/cjs/colors/element.js +0 -82
  11. package/dist/cjs/colors/index.js +0 -27
  12. package/dist/cjs/colors/relationships.js +0 -76
  13. package/dist/cjs/errors/index.js +0 -118
  14. package/dist/cjs/index.js +0 -49
  15. package/dist/cjs/log.d.ts +0 -3
  16. package/dist/cjs/log.js +0 -10
  17. package/dist/cjs/reset.d.ts +0 -2
  18. package/dist/cjs/types/_common.js +0 -1
  19. package/dist/cjs/types/computed-view.js +0 -1
  20. package/dist/cjs/types/diagram.js +0 -1
  21. package/dist/cjs/types/element.js +0 -16
  22. package/dist/cjs/types/expression.d.ts +0 -71
  23. package/dist/cjs/types/expression.js +0 -49
  24. package/dist/cjs/types/index.d.ts +0 -11
  25. package/dist/cjs/types/index.js +0 -132
  26. package/dist/cjs/types/model.js +0 -1
  27. package/dist/cjs/types/opaque.js +0 -1
  28. package/dist/cjs/types/relation.js +0 -12
  29. package/dist/cjs/types/theme.js +0 -1
  30. package/dist/cjs/types/view.js +0 -25
  31. package/dist/cjs/utils/fqn.js +0 -101
  32. package/dist/cjs/utils/guards.js +0 -20
  33. package/dist/cjs/utils/index.js +0 -38
  34. package/dist/cjs/utils/relations.js +0 -77
  35. package/dist/esm/colors/element.d.ts +0 -68
  36. package/dist/esm/colors/element.js +0 -75
  37. package/dist/esm/colors/index.d.ts +0 -132
  38. package/dist/esm/colors/index.js +0 -9
  39. package/dist/esm/colors/relationships.d.ts +0 -57
  40. package/dist/esm/colors/relationships.js +0 -64
  41. package/dist/esm/errors/index.d.ts +0 -39
  42. package/dist/esm/errors/index.js +0 -82
  43. package/dist/esm/index.d.ts +0 -6
  44. package/dist/esm/index.js +0 -4
  45. package/dist/esm/log.d.ts +0 -3
  46. package/dist/esm/log.js +0 -5
  47. package/dist/esm/reset.d.ts +0 -2
  48. package/dist/esm/types/_common.d.ts +0 -3
  49. package/dist/esm/types/_common.js +0 -0
  50. package/dist/esm/types/computed-view.d.ts +0 -45
  51. package/dist/esm/types/computed-view.js +0 -0
  52. package/dist/esm/types/diagram.d.ts +0 -40
  53. package/dist/esm/types/diagram.js +0 -0
  54. package/dist/esm/types/element.d.ts +0 -30
  55. package/dist/esm/types/element.js +0 -14
  56. package/dist/esm/types/expression.d.ts +0 -71
  57. package/dist/esm/types/expression.js +0 -33
  58. package/dist/esm/types/index.d.ts +0 -11
  59. package/dist/esm/types/index.js +0 -11
  60. package/dist/esm/types/model.d.ts +0 -14
  61. package/dist/esm/types/model.js +0 -0
  62. package/dist/esm/types/opaque.d.ts +0 -102
  63. package/dist/esm/types/opaque.js +0 -0
  64. package/dist/esm/types/relation.d.ts +0 -24
  65. package/dist/esm/types/relation.js +0 -3
  66. package/dist/esm/types/theme.d.ts +0 -26
  67. package/dist/esm/types/theme.js +0 -0
  68. package/dist/esm/types/view.d.ts +0 -62
  69. package/dist/esm/types/view.js +0 -15
  70. package/dist/esm/utils/fqn.d.ts +0 -33
  71. package/dist/esm/utils/fqn.js +0 -83
  72. package/dist/esm/utils/guards.d.ts +0 -4
  73. package/dist/esm/utils/guards.js +0 -7
  74. package/dist/esm/utils/index.d.ts +0 -3
  75. package/dist/esm/utils/index.js +0 -3
  76. package/dist/esm/utils/relations.d.ts +0 -29
  77. package/dist/esm/utils/relations.js +0 -69
  78. package/dist/types/colors/element.d.ts +0 -69
  79. package/dist/types/colors/index.d.ts +0 -133
  80. package/dist/types/colors/relationships.d.ts +0 -58
  81. package/dist/types/errors/index.d.ts +0 -40
  82. package/dist/types/log.d.ts +0 -4
  83. package/dist/types/types/_common.d.ts +0 -4
  84. package/dist/types/types/computed-view.d.ts +0 -46
  85. package/dist/types/types/diagram.d.ts +0 -41
  86. package/dist/types/types/element.d.ts +0 -31
  87. package/dist/types/types/index.d.ts +0 -12
  88. package/dist/types/types/model.d.ts +0 -15
  89. package/dist/types/types/opaque.d.ts +0 -103
  90. package/dist/types/types/relation.d.ts +0 -25
  91. package/dist/types/types/theme.d.ts +0 -27
  92. package/dist/types/types/view.d.ts +0 -63
  93. package/dist/types/utils/fqn.d.ts +0 -34
  94. package/dist/types/utils/guards.d.ts +0 -5
  95. package/dist/types/utils/index.d.ts +0 -4
  96. package/dist/types/utils/relations.d.ts +0 -30
  97. /package/dist/{cjs/colors → colors}/element.d.ts +0 -0
  98. /package/dist/{cjs/colors → colors}/index.d.ts +0 -0
  99. /package/dist/{cjs/colors → colors}/relationships.d.ts +0 -0
  100. /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
  101. /package/dist/{cjs/types → types}/_common.d.ts +0 -0
  102. /package/dist/{cjs/types → types}/computed-view.d.ts +0 -0
  103. /package/dist/{cjs/types → types}/diagram.d.ts +0 -0
  104. /package/dist/{cjs/types → types}/element.d.ts +0 -0
  105. /package/dist/{cjs/types → types}/model.d.ts +0 -0
  106. /package/dist/{cjs/types → types}/opaque.d.ts +0 -0
  107. /package/dist/{cjs/types → types}/relation.d.ts +0 -0
  108. /package/dist/{cjs/types → types}/theme.d.ts +0 -0
  109. /package/dist/{cjs/types → types}/view.d.ts +0 -0
  110. /package/dist/{cjs/utils → utils}/fqn.d.ts +0 -0
  111. /package/dist/{cjs/utils → utils}/guards.d.ts +0 -0
  112. /package/dist/{cjs/utils → utils}/relations.d.ts +0 -0
@@ -1,69 +0,0 @@
1
- export declare const ElementColors: {
2
- readonly primary: {
3
- fill: "#3b82f6";
4
- stroke: "#2563eb";
5
- hiContrast: "#eff6ff";
6
- loContrast: "#bfdbfe";
7
- };
8
- readonly blue: {
9
- fill: "#3b82f6";
10
- stroke: "#2563eb";
11
- hiContrast: "#eff6ff";
12
- loContrast: "#bfdbfe";
13
- };
14
- readonly secondary: {
15
- fill: "#0284c7";
16
- stroke: "#0369a1";
17
- hiContrast: "#f0f9ff";
18
- loContrast: "#B6ECF7";
19
- };
20
- readonly sky: {
21
- fill: "#0284c7";
22
- stroke: "#0369a1";
23
- hiContrast: "#f0f9ff";
24
- loContrast: "#B6ECF7";
25
- };
26
- readonly muted: {
27
- fill: "#64748b";
28
- stroke: "#475569";
29
- hiContrast: "#f8fafc";
30
- loContrast: "#cbd5e1";
31
- };
32
- readonly slate: {
33
- fill: "#64748b";
34
- stroke: "#475569";
35
- hiContrast: "#f8fafc";
36
- loContrast: "#cbd5e1";
37
- };
38
- readonly gray: {
39
- readonly fill: "#737373";
40
- readonly stroke: "#525252";
41
- readonly hiContrast: "#fafafa";
42
- readonly loContrast: "#d4d4d4";
43
- };
44
- readonly red: {
45
- readonly fill: "#AC4D39";
46
- readonly stroke: "#853A2D";
47
- readonly hiContrast: "#FBD3CB";
48
- readonly loContrast: "#FF977D";
49
- };
50
- readonly green: {
51
- readonly fill: "#428a4f";
52
- readonly stroke: "#2d5d39";
53
- readonly hiContrast: "#f8fafc";
54
- readonly loContrast: "#c2f0c2";
55
- };
56
- readonly amber: {
57
- readonly fill: "#A35829";
58
- readonly stroke: "#7E451D";
59
- readonly hiContrast: "#FFE0C2";
60
- readonly loContrast: "#FFA057";
61
- };
62
- readonly indigo: {
63
- readonly fill: "#6366f1";
64
- readonly stroke: "#4f46e5";
65
- readonly hiContrast: "#eef2ff";
66
- readonly loContrast: "#c7d2fe";
67
- };
68
- };
69
- //# sourceMappingURL=element.d.ts.map
@@ -1,133 +0,0 @@
1
- import { ElementColors } from './element';
2
- import { RelationshipColors } from './relationships';
3
- export declare const defaultTheme: {
4
- elements: {
5
- readonly primary: {
6
- fill: "#3b82f6";
7
- stroke: "#2563eb";
8
- hiContrast: "#eff6ff";
9
- loContrast: "#bfdbfe";
10
- };
11
- readonly blue: {
12
- fill: "#3b82f6";
13
- stroke: "#2563eb";
14
- hiContrast: "#eff6ff";
15
- loContrast: "#bfdbfe";
16
- };
17
- readonly secondary: {
18
- fill: "#0284c7";
19
- stroke: "#0369a1";
20
- hiContrast: "#f0f9ff";
21
- loContrast: "#B6ECF7";
22
- };
23
- readonly sky: {
24
- fill: "#0284c7";
25
- stroke: "#0369a1";
26
- hiContrast: "#f0f9ff";
27
- loContrast: "#B6ECF7";
28
- };
29
- readonly muted: {
30
- fill: "#64748b";
31
- stroke: "#475569";
32
- hiContrast: "#f8fafc";
33
- loContrast: "#cbd5e1";
34
- };
35
- readonly slate: {
36
- fill: "#64748b";
37
- stroke: "#475569";
38
- hiContrast: "#f8fafc";
39
- loContrast: "#cbd5e1";
40
- };
41
- readonly gray: {
42
- readonly fill: "#737373";
43
- readonly stroke: "#525252";
44
- readonly hiContrast: "#fafafa";
45
- readonly loContrast: "#d4d4d4";
46
- };
47
- readonly red: {
48
- readonly fill: "#AC4D39";
49
- readonly stroke: "#853A2D";
50
- readonly hiContrast: "#FBD3CB";
51
- readonly loContrast: "#FF977D";
52
- };
53
- readonly green: {
54
- readonly fill: "#428a4f";
55
- readonly stroke: "#2d5d39";
56
- readonly hiContrast: "#f8fafc";
57
- readonly loContrast: "#c2f0c2";
58
- };
59
- readonly amber: {
60
- readonly fill: "#A35829";
61
- readonly stroke: "#7E451D";
62
- readonly hiContrast: "#FFE0C2";
63
- readonly loContrast: "#FFA057";
64
- };
65
- readonly indigo: {
66
- readonly fill: "#6366f1";
67
- readonly stroke: "#4f46e5";
68
- readonly hiContrast: "#eef2ff";
69
- readonly loContrast: "#c7d2fe";
70
- };
71
- };
72
- relationships: {
73
- amber: {
74
- lineColor: "#b45309";
75
- labelBgColor: "#78350f";
76
- labelColor: "#FFE0C2";
77
- };
78
- blue: {
79
- lineColor: "#3b82f6";
80
- labelBgColor: "#172554";
81
- labelColor: "#60a5fa";
82
- };
83
- gray: {
84
- lineColor: "#6E6E6E";
85
- labelBgColor: "#18191b";
86
- labelColor: "#C6C6C6";
87
- };
88
- green: {
89
- lineColor: "#15803d";
90
- labelBgColor: "#052e16";
91
- labelColor: "#22c55e";
92
- };
93
- indigo: {
94
- lineColor: "#6366f1";
95
- labelBgColor: "#1e1b4b";
96
- labelColor: "#818cf8";
97
- };
98
- muted: {
99
- lineColor: "#64748b";
100
- labelBgColor: "#0f172a";
101
- labelColor: "#cbd5e1";
102
- };
103
- primary: {
104
- lineColor: "#3b82f6";
105
- labelBgColor: "#172554";
106
- labelColor: "#60a5fa";
107
- };
108
- red: {
109
- lineColor: "#AC4D39";
110
- labelBgColor: "#b91c1c";
111
- labelColor: "#FF977D";
112
- };
113
- secondary: {
114
- lineColor: "#0ea5e9";
115
- labelBgColor: "#082f49";
116
- labelColor: "#38bdf8";
117
- };
118
- sky: {
119
- lineColor: "#0ea5e9";
120
- labelBgColor: "#082f49";
121
- labelColor: "#38bdf8";
122
- };
123
- slate: {
124
- lineColor: "#64748b";
125
- labelBgColor: "#0f172a";
126
- labelColor: "#cbd5e1";
127
- };
128
- };
129
- font: "Helvetica";
130
- shadow: "#0a0a0a";
131
- };
132
- export { ElementColors, RelationshipColors };
133
- //# sourceMappingURL=index.d.ts.map
@@ -1,58 +0,0 @@
1
- export declare const RelationshipColors: {
2
- amber: {
3
- lineColor: "#b45309";
4
- labelBgColor: "#78350f";
5
- labelColor: "#FFE0C2";
6
- };
7
- blue: {
8
- lineColor: "#3b82f6";
9
- labelBgColor: "#172554";
10
- labelColor: "#60a5fa";
11
- };
12
- gray: {
13
- lineColor: "#6E6E6E";
14
- labelBgColor: "#18191b";
15
- labelColor: "#C6C6C6";
16
- };
17
- green: {
18
- lineColor: "#15803d";
19
- labelBgColor: "#052e16";
20
- labelColor: "#22c55e";
21
- };
22
- indigo: {
23
- lineColor: "#6366f1";
24
- labelBgColor: "#1e1b4b";
25
- labelColor: "#818cf8";
26
- };
27
- muted: {
28
- lineColor: "#64748b";
29
- labelBgColor: "#0f172a";
30
- labelColor: "#cbd5e1";
31
- };
32
- primary: {
33
- lineColor: "#3b82f6";
34
- labelBgColor: "#172554";
35
- labelColor: "#60a5fa";
36
- };
37
- red: {
38
- lineColor: "#AC4D39";
39
- labelBgColor: "#b91c1c";
40
- labelColor: "#FF977D";
41
- };
42
- secondary: {
43
- lineColor: "#0ea5e9";
44
- labelBgColor: "#082f49";
45
- labelColor: "#38bdf8";
46
- };
47
- sky: {
48
- lineColor: "#0ea5e9";
49
- labelBgColor: "#082f49";
50
- labelColor: "#38bdf8";
51
- };
52
- slate: {
53
- lineColor: "#64748b";
54
- labelBgColor: "#0f172a";
55
- labelColor: "#cbd5e1";
56
- };
57
- };
58
- //# sourceMappingURL=relationships.d.ts.map
@@ -1,40 +0,0 @@
1
- import { CustomError } from 'ts-custom-error';
2
- export interface BaseErrorOptions {
3
- cause?: unknown;
4
- }
5
- /**
6
- * Base class for all errors in the LikeC4 library.
7
- */
8
- export declare class BaseError extends CustomError {
9
- constructor(message: string, options?: BaseErrorOptions);
10
- }
11
- export declare class InvalidArgError extends BaseError {
12
- constructor(message: string, options?: BaseErrorOptions);
13
- }
14
- /**
15
- * Unknown error, mosly probably a bug, unhandled case or coming from a third-party library.
16
- */
17
- export declare class UnknownError extends BaseError {
18
- constructor(message: string, options?: BaseErrorOptions);
19
- }
20
- export declare class NullableError extends BaseError {
21
- constructor(message: string, options?: BaseErrorOptions);
22
- }
23
- export declare class InvariantError extends BaseError {
24
- constructor(message: string, options?: BaseErrorOptions);
25
- }
26
- export declare function nonNullable<T>(value: T, message?: string): T & {};
27
- export declare class RelationRefError extends BaseError {
28
- constructor(message: string, options?: BaseErrorOptions);
29
- }
30
- export declare function normalizeError(e: unknown): Error;
31
- export declare function invariant(condition: any, message?: string): asserts condition;
32
- export declare class NonExhaustiveError extends BaseError {
33
- constructor(message: string, options?: BaseErrorOptions);
34
- }
35
- export declare function nonexhaustive(value: never): never;
36
- export declare class InvalidModelError extends BaseError {
37
- constructor(message: string, options?: BaseErrorOptions);
38
- }
39
- export declare function ensureModel(condition: any, message?: string): asserts condition;
40
- //# sourceMappingURL=index.d.ts.map
@@ -1,4 +0,0 @@
1
- export declare const likec4log: import("roarr").Logger<Error | import("roarr/dist/types").JsonObject | {
2
- error?: Error;
3
- }>;
4
- //# sourceMappingURL=log.d.ts.map
@@ -1,4 +0,0 @@
1
- import type { Opaque } from './opaque';
2
- export type NonEmptyArray<T> = [T, ...T[]] | [...T[], T];
3
- export type IconUrl = Opaque<string, 'IconUrl'>;
4
- //# sourceMappingURL=_common.d.ts.map
@@ -1,46 +0,0 @@
1
- import type { IconUrl, NonEmptyArray } from './_common';
2
- import type { ElementKind, ElementShape, Fqn, Tag } from './element';
3
- import type { Opaque } from './opaque';
4
- import type { RelationID, RelationshipArrowType, RelationshipLineType } from './relation';
5
- import type { ThemeColor } from './theme';
6
- import type { BasicElementView, ViewID, ViewRuleAutoLayout } from './view';
7
- export type NodeId = Fqn;
8
- export type EdgeId = Opaque<string, 'EdgeId'>;
9
- export interface ComputedNode {
10
- id: NodeId;
11
- kind: ElementKind;
12
- parent: NodeId | null;
13
- title: string;
14
- description: string | null;
15
- technology: string | null;
16
- tags: NonEmptyArray<Tag> | null;
17
- links: NonEmptyArray<string> | null;
18
- children: NodeId[];
19
- inEdges: EdgeId[];
20
- outEdges: EdgeId[];
21
- shape: ElementShape;
22
- color: ThemeColor;
23
- icon?: IconUrl;
24
- navigateTo?: ViewID;
25
- level: number;
26
- depth?: number;
27
- }
28
- export interface ComputedEdge {
29
- id: EdgeId;
30
- parent: NodeId | null;
31
- source: NodeId;
32
- target: NodeId;
33
- label: string | null;
34
- relations: RelationID[];
35
- color?: ThemeColor;
36
- line?: RelationshipLineType;
37
- head?: RelationshipArrowType;
38
- tail?: RelationshipArrowType;
39
- }
40
- export interface ComputedView extends Omit<BasicElementView, 'rules'> {
41
- readonly extends?: ViewID;
42
- readonly autoLayout: ViewRuleAutoLayout['autoLayout'];
43
- readonly nodes: ComputedNode[];
44
- readonly edges: ComputedEdge[];
45
- }
46
- //# sourceMappingURL=computed-view.d.ts.map
@@ -1,41 +0,0 @@
1
- import type { NonEmptyArray } from './_common';
2
- import type { ComputedEdge, ComputedNode, ComputedView } from './computed-view';
3
- import type { ColorLiteral } from './theme';
4
- export type Point = readonly [x: number, y: number];
5
- export type BBox = {
6
- x: number;
7
- y: number;
8
- width: number;
9
- height: number;
10
- };
11
- export interface DiagramLabel {
12
- align: 'left' | 'right' | 'center';
13
- fontStyle?: 'bold' | 'normal';
14
- color?: ColorLiteral;
15
- fontSize: number;
16
- pt: Point;
17
- width: number;
18
- text: string;
19
- }
20
- export interface DiagramNode extends ComputedNode {
21
- width: number;
22
- height: number;
23
- position: Point;
24
- labels: DiagramLabel[];
25
- }
26
- export interface DiagramEdge extends ComputedEdge {
27
- points: NonEmptyArray<Point>;
28
- headArrow?: NonEmptyArray<Point>;
29
- headArrowPoint?: Point;
30
- tailArrow?: NonEmptyArray<Point>;
31
- tailArrowPoint?: Point;
32
- labels?: NonEmptyArray<DiagramLabel>;
33
- labelBBox?: BBox;
34
- }
35
- export interface DiagramView extends Omit<ComputedView, 'nodes' | 'edges'> {
36
- readonly nodes: DiagramNode[];
37
- readonly edges: DiagramEdge[];
38
- readonly width: number;
39
- readonly height: number;
40
- }
41
- //# sourceMappingURL=diagram.d.ts.map
@@ -1,31 +0,0 @@
1
- import type { IconUrl, NonEmptyArray } from './_common';
2
- import type { Opaque } from './opaque';
3
- import type { ThemeColor } from './theme';
4
- export type Fqn = Opaque<string, 'Fqn'>;
5
- export declare function AsFqn(name: string, parent?: Fqn | null): Fqn;
6
- export type ElementKind = Opaque<string, 'ElementKind'>;
7
- export declare const ElementShapes: readonly ["rectangle", "person", "browser", "mobile", "cylinder", "storage", "queue"];
8
- export type ElementShape = typeof ElementShapes[number];
9
- export declare const DefaultThemeColor = "primary";
10
- export declare const DefaultElementShape = "rectangle";
11
- export interface ElementStyle {
12
- shape?: ElementShape;
13
- }
14
- export type Tag = Opaque<string, 'Tag'>;
15
- export interface TagSpec {
16
- readonly id: Tag;
17
- readonly style: ElementStyle;
18
- }
19
- export interface Element {
20
- readonly id: Fqn;
21
- readonly kind: ElementKind;
22
- readonly title: string;
23
- readonly description: string | null;
24
- readonly technology: string | null;
25
- readonly tags: NonEmptyArray<Tag> | null;
26
- readonly links: NonEmptyArray<string> | null;
27
- readonly icon?: IconUrl;
28
- readonly shape?: ElementShape;
29
- readonly color?: ThemeColor;
30
- }
31
- //# sourceMappingURL=element.d.ts.map
@@ -1,12 +0,0 @@
1
- export * from './_common';
2
- export * from './computed-view';
3
- export * from './diagram';
4
- export * from './element';
5
- export * from './expression';
6
- export * from './model';
7
- export * from './opaque';
8
- export * from './relation';
9
- export * from './theme';
10
- export * from './view';
11
- export * as Expr from './expression';
12
- //# sourceMappingURL=index.d.ts.map
@@ -1,15 +0,0 @@
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 LikeC4Model {
6
- elements: Record<Fqn, Element>;
7
- relations: Record<RelationID, Relation>;
8
- views: Record<ViewID, ElementView>;
9
- }
10
- export interface LikeC4ComputedModel {
11
- elements: Record<Fqn, Element>;
12
- relations: Record<RelationID, Relation>;
13
- views: Record<ViewID, ComputedView>;
14
- }
15
- //# sourceMappingURL=model.d.ts.map
@@ -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,25 +0,0 @@
1
- import type { NonEmptyArray } from './_common';
2
- import type { Fqn, 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' | '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 tags?: NonEmptyArray<Tag>;
18
- readonly kind?: RelationshipKind;
19
- readonly color?: ThemeColor;
20
- readonly line?: RelationshipLineType;
21
- readonly head?: RelationshipArrowType;
22
- readonly tail?: RelationshipArrowType;
23
- readonly links?: NonEmptyArray<string>;
24
- }
25
- //# sourceMappingURL=relation.d.ts.map
@@ -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: 'Helvetica';
23
- shadow: ColorLiteral;
24
- relationships: RelationshipThemeColors;
25
- elements: ElementThemeColors;
26
- }
27
- //# sourceMappingURL=theme.d.ts.map
@@ -1,63 +0,0 @@
1
- import type { IconUrl, NonEmptyArray } from './_common';
2
- import type { ElementShape, Fqn, Tag } from './element';
3
- import type { ElementExpression, Expression } from './expression';
4
- import type { Opaque } from './opaque';
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 type AutoLayoutDirection = 'TB' | 'BT' | 'LR' | 'RL';
25
- export interface ViewRuleAutoLayout {
26
- autoLayout: AutoLayoutDirection;
27
- }
28
- export declare function isViewRuleAutoLayout(rule: ViewRule): rule is ViewRuleAutoLayout;
29
- export type ViewRule = ViewRuleExpression | ViewRuleStyle | ViewRuleAutoLayout;
30
- export interface BasicElementView {
31
- readonly id: ViewID;
32
- readonly viewOf?: Fqn;
33
- readonly title: string | null;
34
- readonly description: string | null;
35
- readonly tags: NonEmptyArray<Tag> | null;
36
- readonly links: NonEmptyArray<string> | null;
37
- readonly rules: ViewRule[];
38
- /**
39
- * URI to the source file of this view.
40
- * Undefined if the view is auto-generated.
41
- */
42
- readonly docUri?: string;
43
- /**
44
- * For all views we find common ancestor path.
45
- * This is used to generate relative paths, i.e.:
46
- * - "" for views in the common ancestor directory (or root)
47
- * - "subdir" for views in "<root>/subdir"
48
- * - "subdir/subdir1" for views in "<root>/subdir/subdir1"
49
- *
50
- * Undefined if the view is auto-generated.
51
- */
52
- readonly relativePath?: string;
53
- }
54
- export interface StrictElementView extends BasicElementView {
55
- readonly viewOf: Fqn;
56
- }
57
- export declare function isStrictElementView(view: ElementView): view is StrictElementView;
58
- export interface ExtendsElementView extends BasicElementView {
59
- readonly extends: ViewID;
60
- }
61
- export declare function isExtendsElementView(view: ElementView): view is ExtendsElementView;
62
- export type ElementView = StrictElementView | ExtendsElementView | BasicElementView;
63
- //# sourceMappingURL=view.d.ts.map