@likec4/core 0.60.2 → 1.0.0-next.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 (72) hide show
  1. package/dist/cjs/colors/relationships.js +1 -1
  2. package/dist/cjs/log.d.ts +3 -0
  3. package/dist/cjs/log.js +10 -0
  4. package/dist/cjs/reset.d.ts +2 -0
  5. package/dist/cjs/types/computed-view.d.ts +3 -3
  6. package/dist/cjs/types/diagram.d.ts +6 -8
  7. package/dist/cjs/types/element.d.ts +2 -1
  8. package/dist/cjs/types/element.js +3 -1
  9. package/dist/cjs/types/index.d.ts +6 -6
  10. package/dist/cjs/types/index.js +33 -33
  11. package/dist/cjs/types/model.d.ts +2 -2
  12. package/dist/cjs/types/view.d.ts +4 -3
  13. package/dist/cjs/utils/fqn.d.ts +2 -2
  14. package/dist/cjs/utils/fqn.js +1 -2
  15. package/dist/cjs/utils/relations.js +6 -3
  16. package/dist/colors/element.js +75 -0
  17. package/dist/colors/index.js +9 -0
  18. package/dist/colors/relationships.js +49 -0
  19. package/dist/errors/index.js +111 -0
  20. package/dist/esm/colors/relationships.js +1 -1
  21. package/dist/esm/log.d.ts +3 -0
  22. package/dist/esm/log.js +5 -0
  23. package/dist/esm/reset.d.ts +2 -0
  24. package/dist/esm/types/computed-view.d.ts +3 -3
  25. package/dist/esm/types/diagram.d.ts +6 -8
  26. package/dist/esm/types/element.d.ts +2 -1
  27. package/dist/esm/types/element.js +9 -0
  28. package/dist/esm/types/index.d.ts +6 -6
  29. package/dist/esm/types/index.js +6 -6
  30. package/dist/esm/types/model.d.ts +2 -2
  31. package/dist/esm/types/view.d.ts +4 -3
  32. package/dist/esm/utils/fqn.d.ts +2 -2
  33. package/dist/esm/utils/fqn.js +1 -2
  34. package/dist/esm/utils/relations.js +6 -3
  35. package/dist/index.js +4 -0
  36. package/dist/types/_common.js +1 -0
  37. package/dist/types/colors/element.d.ts +69 -0
  38. package/dist/types/colors/index.d.ts +133 -0
  39. package/dist/types/colors/relationships.d.ts +58 -0
  40. package/dist/types/computed-view.js +1 -0
  41. package/dist/types/diagram.js +1 -0
  42. package/dist/types/element.js +14 -0
  43. package/dist/types/errors/index.d.ts +40 -0
  44. package/dist/types/expression.js +45 -0
  45. package/dist/types/index.d.ts +7 -0
  46. package/dist/types/index.js +11 -0
  47. package/dist/types/log.d.ts +4 -0
  48. package/dist/types/model.js +1 -0
  49. package/dist/types/opaque.js +1 -0
  50. package/dist/types/relation.js +3 -0
  51. package/dist/types/theme.js +1 -0
  52. package/dist/types/types/_common.d.ts +4 -0
  53. package/dist/types/types/computed-view.d.ts +46 -0
  54. package/dist/types/types/diagram.d.ts +41 -0
  55. package/dist/types/types/element.d.ts +31 -0
  56. package/dist/types/types/expression.d.ts +72 -0
  57. package/dist/types/types/index.d.ts +12 -0
  58. package/dist/types/types/model.d.ts +15 -0
  59. package/dist/types/types/opaque.d.ts +103 -0
  60. package/dist/types/types/relation.d.ts +25 -0
  61. package/dist/types/types/theme.d.ts +27 -0
  62. package/dist/types/types/view.d.ts +63 -0
  63. package/dist/types/utils/fqn.d.ts +34 -0
  64. package/dist/types/utils/guards.d.ts +5 -0
  65. package/dist/types/utils/index.d.ts +4 -0
  66. package/dist/types/utils/relations.d.ts +30 -0
  67. package/dist/types/view.js +16 -0
  68. package/dist/utils/fqn.js +98 -0
  69. package/dist/utils/guards.js +7 -0
  70. package/dist/utils/index.js +3 -0
  71. package/dist/utils/relations.js +79 -0
  72. package/package.json +4 -7
@@ -48,7 +48,7 @@ const RelationshipColors = {
48
48
  lineColor: "#15803d",
49
49
  // 700
50
50
  labelBgColor: "#052e16",
51
- //950
51
+ // 950
52
52
  labelColor: "#22c55e"
53
53
  // 500
54
54
  },
@@ -0,0 +1,3 @@
1
+ export declare const likec4log: import("roarr").Logger<Error | import("roarr/dist/types").JsonObject | {
2
+ error?: Error | undefined;
3
+ }>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.likec4log = void 0;
7
+ var _roarr = require("roarr");
8
+ const likec4log = _roarr.Roarr.child(msg => msg);
9
+ exports.likec4log = likec4log;
10
+ likec4log.error(new Error(), "This is an error message");
@@ -0,0 +1,2 @@
1
+ // Do not add any other lines of code to this file!
2
+ import '@total-typescript/ts-reset'
@@ -1,9 +1,9 @@
1
- import type { Opaque } from './opaque';
1
+ import type { IconUrl, NonEmptyArray } from './_common';
2
2
  import type { ElementKind, ElementShape, Fqn, Tag } from './element';
3
+ import type { Opaque } from './opaque';
3
4
  import type { RelationID, RelationshipArrowType, RelationshipLineType } from './relation';
4
- import type { BasicElementView, ViewID, ViewRuleAutoLayout } from './view';
5
- import type { IconUrl, NonEmptyArray } from './_common';
6
5
  import type { ThemeColor } from './theme';
6
+ import type { BasicElementView, ViewID, ViewRuleAutoLayout } from './view';
7
7
  export type NodeId = Fqn;
8
8
  export type EdgeId = Opaque<string, 'EdgeId'>;
9
9
  export interface ComputedNode {
@@ -1,7 +1,7 @@
1
- import type { ColorLiteral } from './theme';
2
- import type { ComputedEdge, ComputedNode, ComputedView } from './computed-view';
3
1
  import type { NonEmptyArray } from './_common';
4
- export type Point = [x: number, y: number];
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
5
  export type BBox = {
6
6
  x: number;
7
7
  y: number;
@@ -18,12 +18,10 @@ export interface DiagramLabel {
18
18
  text: string;
19
19
  }
20
20
  export interface DiagramNode extends ComputedNode {
21
- size: {
22
- width: number;
23
- height: number;
24
- };
25
- labels: DiagramLabel[];
21
+ width: number;
22
+ height: number;
26
23
  position: Point;
24
+ labels: DiagramLabel[];
27
25
  }
28
26
  export interface DiagramEdge extends ComputedEdge {
29
27
  points: NonEmptyArray<Point>;
@@ -4,7 +4,8 @@ import type { ThemeColor } from './theme';
4
4
  export type Fqn = Opaque<string, 'Fqn'>;
5
5
  export declare function AsFqn(name: string, parent?: Fqn | null): Fqn;
6
6
  export type ElementKind = Opaque<string, 'ElementKind'>;
7
- export type ElementShape = 'rectangle' | 'person' | 'browser' | 'mobile' | 'cylinder' | 'storage' | 'queue';
7
+ export declare const ElementShapes: readonly ["rectangle", "person", "browser", "mobile", "cylinder", "storage", "queue"];
8
+ export type ElementShape = typeof ElementShapes[number];
8
9
  export declare const DefaultThemeColor = "primary";
9
10
  export declare const DefaultElementShape = "rectangle";
10
11
  export interface ElementStyle {
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AsFqn = AsFqn;
7
- exports.DefaultThemeColor = exports.DefaultElementShape = void 0;
7
+ exports.ElementShapes = exports.DefaultThemeColor = exports.DefaultElementShape = void 0;
8
8
  function AsFqn(name, parent) {
9
9
  return parent ? parent + "." + name : name;
10
10
  }
11
+ const ElementShapes = ["rectangle", "person", "browser", "mobile", "cylinder", "storage", "queue"];
12
+ exports.ElementShapes = ElementShapes;
11
13
  const DefaultThemeColor = "primary";
12
14
  exports.DefaultThemeColor = DefaultThemeColor;
13
15
  const DefaultElementShape = "rectangle";
@@ -1,11 +1,11 @@
1
- export * from './opaque';
2
1
  export * from './_common';
3
- export * from './theme';
2
+ export * from './computed-view';
3
+ export * from './diagram';
4
4
  export * from './element';
5
- export * from './relation';
5
+ export * from './expression';
6
6
  export * from './model';
7
+ export * from './opaque';
8
+ export * from './relation';
9
+ export * from './theme';
7
10
  export * from './view';
8
- export * from './expression';
9
- export * from './computed-view';
10
- export * from './diagram';
11
11
  export * as Expr from './expression';
@@ -7,39 +7,39 @@ var _exportNames = {
7
7
  Expr: true
8
8
  };
9
9
  exports.Expr = void 0;
10
- var _opaque = require("./opaque");
11
- Object.keys(_opaque).forEach(function (key) {
10
+ var _common = require("./_common");
11
+ Object.keys(_common).forEach(function (key) {
12
12
  if (key === "default" || key === "__esModule") return;
13
13
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
14
- if (key in exports && exports[key] === _opaque[key]) return;
14
+ if (key in exports && exports[key] === _common[key]) return;
15
15
  Object.defineProperty(exports, key, {
16
16
  enumerable: true,
17
17
  get: function () {
18
- return _opaque[key];
18
+ return _common[key];
19
19
  }
20
20
  });
21
21
  });
22
- var _common = require("./_common");
23
- Object.keys(_common).forEach(function (key) {
22
+ var _computedView = require("./computed-view");
23
+ Object.keys(_computedView).forEach(function (key) {
24
24
  if (key === "default" || key === "__esModule") return;
25
25
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
26
- if (key in exports && exports[key] === _common[key]) return;
26
+ if (key in exports && exports[key] === _computedView[key]) return;
27
27
  Object.defineProperty(exports, key, {
28
28
  enumerable: true,
29
29
  get: function () {
30
- return _common[key];
30
+ return _computedView[key];
31
31
  }
32
32
  });
33
33
  });
34
- var _theme = require("./theme");
35
- Object.keys(_theme).forEach(function (key) {
34
+ var _diagram = require("./diagram");
35
+ Object.keys(_diagram).forEach(function (key) {
36
36
  if (key === "default" || key === "__esModule") return;
37
37
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
38
- if (key in exports && exports[key] === _theme[key]) return;
38
+ if (key in exports && exports[key] === _diagram[key]) return;
39
39
  Object.defineProperty(exports, key, {
40
40
  enumerable: true,
41
41
  get: function () {
42
- return _theme[key];
42
+ return _diagram[key];
43
43
  }
44
44
  });
45
45
  });
@@ -55,15 +55,16 @@ Object.keys(_element).forEach(function (key) {
55
55
  }
56
56
  });
57
57
  });
58
- var _relation = require("./relation");
59
- Object.keys(_relation).forEach(function (key) {
58
+ var _Expr = _interopRequireWildcard(require("./expression"));
59
+ exports.Expr = _Expr;
60
+ Object.keys(_Expr).forEach(function (key) {
60
61
  if (key === "default" || key === "__esModule") return;
61
62
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
62
- if (key in exports && exports[key] === _relation[key]) return;
63
+ if (key in exports && exports[key] === _Expr[key]) return;
63
64
  Object.defineProperty(exports, key, {
64
65
  enumerable: true,
65
66
  get: function () {
66
- return _relation[key];
67
+ return _Expr[key];
67
68
  }
68
69
  });
69
70
  });
@@ -79,52 +80,51 @@ Object.keys(_model).forEach(function (key) {
79
80
  }
80
81
  });
81
82
  });
82
- var _view = require("./view");
83
- Object.keys(_view).forEach(function (key) {
83
+ var _opaque = require("./opaque");
84
+ Object.keys(_opaque).forEach(function (key) {
84
85
  if (key === "default" || key === "__esModule") return;
85
86
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
86
- if (key in exports && exports[key] === _view[key]) return;
87
+ if (key in exports && exports[key] === _opaque[key]) return;
87
88
  Object.defineProperty(exports, key, {
88
89
  enumerable: true,
89
90
  get: function () {
90
- return _view[key];
91
+ return _opaque[key];
91
92
  }
92
93
  });
93
94
  });
94
- var _Expr = _interopRequireWildcard(require("./expression"));
95
- exports.Expr = _Expr;
96
- Object.keys(_Expr).forEach(function (key) {
95
+ var _relation = require("./relation");
96
+ Object.keys(_relation).forEach(function (key) {
97
97
  if (key === "default" || key === "__esModule") return;
98
98
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
99
- if (key in exports && exports[key] === _Expr[key]) return;
99
+ if (key in exports && exports[key] === _relation[key]) return;
100
100
  Object.defineProperty(exports, key, {
101
101
  enumerable: true,
102
102
  get: function () {
103
- return _Expr[key];
103
+ return _relation[key];
104
104
  }
105
105
  });
106
106
  });
107
- var _computedView = require("./computed-view");
108
- Object.keys(_computedView).forEach(function (key) {
107
+ var _theme = require("./theme");
108
+ Object.keys(_theme).forEach(function (key) {
109
109
  if (key === "default" || key === "__esModule") return;
110
110
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
111
- if (key in exports && exports[key] === _computedView[key]) return;
111
+ if (key in exports && exports[key] === _theme[key]) return;
112
112
  Object.defineProperty(exports, key, {
113
113
  enumerable: true,
114
114
  get: function () {
115
- return _computedView[key];
115
+ return _theme[key];
116
116
  }
117
117
  });
118
118
  });
119
- var _diagram = require("./diagram");
120
- Object.keys(_diagram).forEach(function (key) {
119
+ var _view = require("./view");
120
+ Object.keys(_view).forEach(function (key) {
121
121
  if (key === "default" || key === "__esModule") return;
122
122
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
123
- if (key in exports && exports[key] === _diagram[key]) return;
123
+ if (key in exports && exports[key] === _view[key]) return;
124
124
  Object.defineProperty(exports, key, {
125
125
  enumerable: true,
126
126
  get: function () {
127
- return _diagram[key];
127
+ return _view[key];
128
128
  }
129
129
  });
130
130
  });
@@ -2,12 +2,12 @@ import type { ComputedView } from './computed-view';
2
2
  import type { Element, Fqn } from './element';
3
3
  import type { Relation, RelationID } from './relation';
4
4
  import type { ElementView, ViewID } from './view';
5
- export interface LikeC4RawModel {
5
+ export interface LikeC4Model {
6
6
  elements: Record<Fqn, Element>;
7
7
  relations: Record<RelationID, Relation>;
8
8
  views: Record<ViewID, ElementView>;
9
9
  }
10
- export interface LikeC4Model {
10
+ export interface LikeC4ComputedModel {
11
11
  elements: Record<Fqn, Element>;
12
12
  relations: Record<RelationID, Relation>;
13
13
  views: Record<ViewID, ComputedView>;
@@ -1,7 +1,7 @@
1
- import type { Opaque } from './opaque';
1
+ import type { IconUrl, NonEmptyArray } from './_common';
2
2
  import type { ElementShape, Fqn, Tag } from './element';
3
3
  import type { ElementExpression, Expression } from './expression';
4
- import type { IconUrl, NonEmptyArray } from './_common';
4
+ import type { Opaque } from './opaque';
5
5
  import type { ThemeColor } from './theme';
6
6
  export type ViewID = Opaque<string, 'ViewID'>;
7
7
  export type ViewRuleExpression = {
@@ -21,8 +21,9 @@ export interface ViewRuleStyle {
21
21
  };
22
22
  }
23
23
  export declare function isViewRuleStyle(rule: ViewRule): rule is ViewRuleStyle;
24
+ export type AutoLayoutDirection = 'TB' | 'BT' | 'LR' | 'RL';
24
25
  export interface ViewRuleAutoLayout {
25
- autoLayout: 'TB' | 'BT' | 'LR' | 'RL';
26
+ autoLayout: AutoLayoutDirection;
26
27
  }
27
28
  export declare function isViewRuleAutoLayout(rule: ViewRule): rule is ViewRuleAutoLayout;
28
29
  export type ViewRule = ViewRuleExpression | ViewRuleStyle | ViewRuleAutoLayout;
@@ -2,7 +2,7 @@ import type { Element, Fqn } from '../types';
2
2
  export declare function nameFromFqn(fqn: Fqn): string;
3
3
  export declare function isAncestor<E extends {
4
4
  id: Fqn;
5
- }>(...args: [ancestor: Fqn, another: Fqn] | [ancestor: E, another: E]): boolean;
5
+ }>(...args: [ancestor: string, another: string] | [ancestor: E, another: E]): boolean;
6
6
  export declare function isSameHierarchy<E extends {
7
7
  id: Fqn;
8
8
  }>(one: E | Fqn, another: E | Fqn): boolean;
@@ -29,5 +29,5 @@ export declare function ancestorsFqn(fqn: Fqn): Fqn[];
29
29
  */
30
30
  export declare function compareFqnHierarchically<T extends string = string>(a: T, b: T): number;
31
31
  export declare function compareByFqnHierarchically<T extends {
32
- id: Fqn;
32
+ id: string;
33
33
  }>(a: T, b: T): number;
@@ -13,7 +13,6 @@ exports.isSameHierarchy = isSameHierarchy;
13
13
  exports.nameFromFqn = nameFromFqn;
14
14
  exports.notDescendantOf = notDescendantOf;
15
15
  exports.parentFqn = parentFqn;
16
- var _remeda = require("remeda");
17
16
  var _guards = require("./guards");
18
17
  function nameFromFqn(fqn) {
19
18
  const lastDot = fqn.lastIndexOf(".");
@@ -35,7 +34,7 @@ function isSameHierarchy(one, another) {
35
34
  }
36
35
  function isDescendantOf(ancestors) {
37
36
  const predicates = ancestors.flatMap(a => [e => e.id === a.id, e => isAncestor(a, e)]);
38
- return (0, _remeda.anyPass)(predicates);
37
+ return e => predicates.some(p => p(e));
39
38
  }
40
39
  function notDescendantOf(ancestors) {
41
40
  const isDescendant = isDescendantOf(ancestors);
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.compareRelations = exports.Relations = void 0;
7
7
  var _fqn = require("./fqn");
8
- var _rambdax = require("rambdax");
9
8
  const compareRelations = (a, b) => {
10
9
  const parentA = (0, _fqn.commonAncestor)(a.source, a.target);
11
10
  const parentB = (0, _fqn.commonAncestor)(b.source, b.target);
@@ -40,7 +39,8 @@ const isBetween = (source, target) => {
40
39
  };
41
40
  };
42
41
  const isAnyBetween = (source, target) => {
43
- return (0, _rambdax.either)(isBetween(source, target), isBetween(target, source));
42
+ const predicates = [isBetween(source, target), isBetween(target, source)];
43
+ return rel => predicates.some(p => p(rel));
44
44
  };
45
45
  const isIncoming = target => {
46
46
  const targetPrefix = target + ".";
@@ -55,7 +55,10 @@ const isOutgoing = source => {
55
55
  };
56
56
  };
57
57
  const isAnyInOut = source => {
58
- return (0, _rambdax.either)(isIncoming(source), isOutgoing(source));
58
+ const predicates = [isIncoming(source), isOutgoing(source)];
59
+ return rel => {
60
+ return predicates.some(p => p(rel));
61
+ };
59
62
  };
60
63
  const hasRelation = rel => {
61
64
  return element => {
@@ -0,0 +1,75 @@
1
+ const blue = {
2
+ fill: '#3b82f6',
3
+ stroke: '#2563eb',
4
+ hiContrast: '#eff6ff',
5
+ loContrast: '#bfdbfe'
6
+ };
7
+ const sky = {
8
+ fill: '#0284c7',
9
+ stroke: '#0369a1',
10
+ hiContrast: '#f0f9ff',
11
+ loContrast: '#B6ECF7'
12
+ };
13
+ const slate = {
14
+ fill: '#64748b',
15
+ stroke: '#475569',
16
+ hiContrast: '#f8fafc',
17
+ loContrast: '#cbd5e1'
18
+ };
19
+ export const ElementColors = {
20
+ primary: blue,
21
+ blue,
22
+ secondary: sky,
23
+ sky,
24
+ muted: slate,
25
+ slate,
26
+ gray: {
27
+ // fill: colors.neutral[500],
28
+ // stroke: colors.neutral[600],
29
+ // hiContrast: colors.neutral[50],
30
+ // loContrast: colors.neutral[200],
31
+ fill: '#737373',
32
+ stroke: '#525252',
33
+ hiContrast: '#fafafa',
34
+ loContrast: '#d4d4d4'
35
+ },
36
+ red: {
37
+ // fill: colors.red[500],
38
+ // stroke: colors.red[600],
39
+ // hiContrast: colors.red[50],
40
+ // loContrast: colors.red[200],
41
+ fill: '#AC4D39',
42
+ // fill: '#b54548',
43
+ stroke: '#853A2D',
44
+ // hiContrast: '#fef2f2',
45
+ // loContrast: '#fecaca',
46
+ // hiContrast: '#191111', // colors.gray[900],
47
+ // loContrast: '#3b1219' // colors.gray[800],
48
+ hiContrast: '#FBD3CB',
49
+ // hiContrast: '#f8fafc',
50
+ // loContrast: '#fdd8d8' // radix black red 12
51
+ loContrast: '#FF977D'
52
+ },
53
+ green: {
54
+ fill: '#428a4f',
55
+ stroke: '#2d5d39',
56
+ hiContrast: '#f8fafc',
57
+ loContrast: '#c2f0c2'
58
+ },
59
+ amber: {
60
+ fill: '#A35829',
61
+ stroke: '#7E451D',
62
+ hiContrast: '#FFE0C2',
63
+ loContrast: '#FFA057'
64
+ },
65
+ indigo: {
66
+ // fill: colors.indigo[500],
67
+ // stroke: colors.indigo[600],
68
+ // hiContrast: colors.indigo[50],
69
+ // loContrast: colors.indigo[200],
70
+ fill: '#6366f1',
71
+ stroke: '#4f46e5',
72
+ hiContrast: '#eef2ff',
73
+ loContrast: '#c7d2fe'
74
+ }
75
+ };
@@ -0,0 +1,9 @@
1
+ import { ElementColors } from './element';
2
+ import { RelationshipColors } from './relationships';
3
+ export const defaultTheme = {
4
+ elements: ElementColors,
5
+ relationships: RelationshipColors,
6
+ font: 'Helvetica',
7
+ shadow: '#0a0a0a'
8
+ };
9
+ export { ElementColors, RelationshipColors };
@@ -0,0 +1,49 @@
1
+ const gray = {
2
+ lineColor: '#6E6E6E',
3
+ labelBgColor: '#18191b',
4
+ labelColor: '#C6C6C6'
5
+ };
6
+ const slate = {
7
+ lineColor: '#64748b', // 500
8
+ labelBgColor: '#0f172a', // 900
9
+ labelColor: '#cbd5e1' // 300
10
+ };
11
+ const blue = {
12
+ lineColor: '#3b82f6', // 500
13
+ labelBgColor: '#172554', // 950
14
+ labelColor: '#60a5fa' // 400
15
+ };
16
+ const sky = {
17
+ lineColor: '#0ea5e9', // 500
18
+ labelBgColor: '#082f49', // 950
19
+ labelColor: '#38bdf8' // 400
20
+ };
21
+ export const RelationshipColors = {
22
+ amber: {
23
+ lineColor: '#b45309',
24
+ labelBgColor: '#78350f',
25
+ labelColor: '#FFE0C2'
26
+ },
27
+ blue,
28
+ gray,
29
+ green: {
30
+ lineColor: '#15803d', // 700
31
+ labelBgColor: '#052e16', // 950
32
+ labelColor: '#22c55e' // 500
33
+ },
34
+ indigo: {
35
+ lineColor: '#6366f1', // 500
36
+ labelBgColor: '#1e1b4b', // 950
37
+ labelColor: '#818cf8' // 400
38
+ },
39
+ muted: slate,
40
+ primary: blue,
41
+ red: {
42
+ lineColor: '#AC4D39',
43
+ labelBgColor: '#b91c1c',
44
+ labelColor: '#FF977D'
45
+ },
46
+ secondary: sky,
47
+ sky,
48
+ slate
49
+ };
@@ -0,0 +1,111 @@
1
+ import stringify from 'safe-stable-stringify';
2
+ import { CustomError } from 'ts-custom-error';
3
+ import { isString } from '../utils/guards';
4
+ /**
5
+ * Base class for all errors in the LikeC4 library.
6
+ */
7
+ export class BaseError extends CustomError {
8
+ constructor(message, options) {
9
+ super(message, options);
10
+ // Set name explicitly as minification can mangle class names
11
+ Object.defineProperty(this, 'name', { value: 'BaseError' });
12
+ }
13
+ }
14
+ export class InvalidArgError extends BaseError {
15
+ constructor(message, options) {
16
+ super(message, options);
17
+ // Set name explicitly as minification can mangle class names
18
+ Object.defineProperty(this, 'name', { value: 'InvalidArgError' });
19
+ }
20
+ }
21
+ /**
22
+ * Unknown error, mosly probably a bug, unhandled case or coming from a third-party library.
23
+ */
24
+ export class UnknownError extends BaseError {
25
+ constructor(message, options) {
26
+ super(message, options);
27
+ // Set name explicitly as minification can mangle class names
28
+ Object.defineProperty(this, 'name', { value: 'UnknownError' });
29
+ }
30
+ }
31
+ export class NullableError extends BaseError {
32
+ constructor(message, options) {
33
+ super(message, options);
34
+ // Set name explicitly as minification can mangle class names
35
+ Object.defineProperty(this, 'name', { value: 'NullableError' });
36
+ }
37
+ }
38
+ export class InvariantError extends BaseError {
39
+ constructor(message, options) {
40
+ super(message, options);
41
+ // Set name explicitly as minification can mangle class names
42
+ Object.defineProperty(this, 'name', { value: 'InvariantError' });
43
+ }
44
+ }
45
+ // Ensure that the value is NonNullable
46
+ // Mostly as safer `value!`
47
+ // eslint-disable-next-line @typescript-eslint/ban-types
48
+ export function nonNullable(value, message) {
49
+ if (typeof value === 'undefined' || value == null) {
50
+ throw new NullableError(message ?? `Expected defined value, but received ${value}`);
51
+ }
52
+ return value;
53
+ }
54
+ export class RelationRefError extends BaseError {
55
+ constructor(message, options) {
56
+ super(message, options);
57
+ // Set name explicitly as minification can mangle class names
58
+ Object.defineProperty(this, 'name', { value: 'RelationRefError' });
59
+ }
60
+ }
61
+ export function normalizeError(e) {
62
+ if (e instanceof BaseError || e instanceof Error) {
63
+ return e;
64
+ }
65
+ const message = isString(e) ? e : stringify(e);
66
+ const error = new UnknownError(message);
67
+ Error.captureStackTrace(error, normalizeError);
68
+ return error;
69
+ }
70
+ // Throw an error if the condition fails
71
+ // > Not providing an inline default argument for message as the result is smaller
72
+ export function invariant(
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ condition,
75
+ // Can provide a string, or a function that returns a string for cases where
76
+ // the message takes a fair amount of effort to compute
77
+ message) {
78
+ if (condition) {
79
+ return;
80
+ }
81
+ throw new InvariantError(message ?? 'Invariant failed');
82
+ }
83
+ export class NonExhaustiveError extends BaseError {
84
+ constructor(message, options) {
85
+ super(message, options);
86
+ // Set name explicitly as minification can mangle class names
87
+ Object.defineProperty(this, 'name', { value: 'NonExhaustiveError' });
88
+ }
89
+ }
90
+ export function nonexhaustive(value) {
91
+ const val = typeof value === 'string' ? value : stringify(value);
92
+ throw new NonExhaustiveError(`NonExhaustive value: ${val}`);
93
+ }
94
+ export class InvalidModelError extends BaseError {
95
+ constructor(message, options) {
96
+ super(message, options);
97
+ // Set name explicitly as minification can mangle class names
98
+ Object.defineProperty(this, 'name', { value: 'InvalidModelError' });
99
+ }
100
+ }
101
+ export function ensureModel(
102
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
+ condition,
104
+ // Can provide a string, or a function that returns a string for cases where
105
+ // the message takes a fair amount of effort to compute
106
+ message) {
107
+ if (condition) {
108
+ return;
109
+ }
110
+ throw new InvalidModelError(message ?? 'ModelIndex Invariant failed');
111
+ }
@@ -39,7 +39,7 @@ export const RelationshipColors = {
39
39
  lineColor: "#15803d",
40
40
  // 700
41
41
  labelBgColor: "#052e16",
42
- //950
42
+ // 950
43
43
  labelColor: "#22c55e"
44
44
  // 500
45
45
  },
@@ -0,0 +1,3 @@
1
+ export declare const likec4log: import("roarr").Logger<Error | import("roarr/dist/types").JsonObject | {
2
+ error?: Error | undefined;
3
+ }>;
@@ -0,0 +1,5 @@
1
+ import {
2
+ Roarr
3
+ } from "roarr";
4
+ export const likec4log = Roarr.child((msg) => msg);
5
+ likec4log.error(new Error(), "This is an error message");
@@ -0,0 +1,2 @@
1
+ // Do not add any other lines of code to this file!
2
+ import '@total-typescript/ts-reset'
@@ -1,9 +1,9 @@
1
- import type { Opaque } from './opaque';
1
+ import type { IconUrl, NonEmptyArray } from './_common';
2
2
  import type { ElementKind, ElementShape, Fqn, Tag } from './element';
3
+ import type { Opaque } from './opaque';
3
4
  import type { RelationID, RelationshipArrowType, RelationshipLineType } from './relation';
4
- import type { BasicElementView, ViewID, ViewRuleAutoLayout } from './view';
5
- import type { IconUrl, NonEmptyArray } from './_common';
6
5
  import type { ThemeColor } from './theme';
6
+ import type { BasicElementView, ViewID, ViewRuleAutoLayout } from './view';
7
7
  export type NodeId = Fqn;
8
8
  export type EdgeId = Opaque<string, 'EdgeId'>;
9
9
  export interface ComputedNode {