@likec4/core 1.8.0 → 1.9.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 (89) hide show
  1. package/dist/index.cjs +4368 -0
  2. package/dist/index.d.cts +781 -0
  3. package/dist/index.d.mts +781 -0
  4. package/dist/index.mjs +4296 -0
  5. package/dist/shared/core.9l7eW3pn.d.cts +817 -0
  6. package/dist/shared/core.9l7eW3pn.d.mts +817 -0
  7. package/dist/shared/core.DcPLm41i.cjs +304 -0
  8. package/dist/shared/core.DfUTsojZ.mjs +251 -0
  9. package/dist/types/index.cjs +53 -0
  10. package/dist/types/index.d.cts +1 -0
  11. package/dist/types/index.d.mts +1 -0
  12. package/dist/types/index.mjs +1 -0
  13. package/package.json +41 -33
  14. package/src/colors/index.ts +27 -1
  15. package/src/errors/index.ts +3 -95
  16. package/src/index.ts +5 -6
  17. package/src/model/LikeC4Model.ts +480 -0
  18. package/src/model/LikeC4ViewModel.ts +318 -0
  19. package/src/model/__test__/LikeC4Model.spec.ts +79 -0
  20. package/src/model/__test__/fixture.ts +333 -0
  21. package/src/model/index.ts +2 -0
  22. package/src/model/types.ts +10 -0
  23. package/src/types/_common.ts +4 -2
  24. package/src/types/element.ts +8 -8
  25. package/src/types/expression.ts +3 -3
  26. package/src/types/index.ts +0 -1
  27. package/src/types/model.ts +16 -6
  28. package/src/types/relation.ts +15 -5
  29. package/src/types/theme.ts +28 -12
  30. package/src/types/view-notation.ts +3 -4
  31. package/src/types/view.ts +14 -10
  32. package/src/utils/fqn.ts +7 -4
  33. package/src/utils/relations.spec.ts +1 -3
  34. package/src/utils/relations.ts +7 -17
  35. package/dist/colors/element.d.ts +0 -69
  36. package/dist/colors/element.js +0 -75
  37. package/dist/colors/index.d.ts +0 -133
  38. package/dist/colors/index.js +0 -9
  39. package/dist/colors/relationships.d.ts +0 -58
  40. package/dist/colors/relationships.js +0 -49
  41. package/dist/errors/errors.spec.d.ts +0 -2
  42. package/dist/errors/errors.spec.js +0 -69
  43. package/dist/errors/index.d.ts +0 -39
  44. package/dist/errors/index.js +0 -104
  45. package/dist/index.d.ts +0 -7
  46. package/dist/index.js +0 -4
  47. package/dist/types/_common.d.ts +0 -9
  48. package/dist/types/_common.js +0 -1
  49. package/dist/types/element.d.ts +0 -55
  50. package/dist/types/element.js +0 -15
  51. package/dist/types/expression.d.ts +0 -119
  52. package/dist/types/expression.js +0 -67
  53. package/dist/types/index.d.ts +0 -14
  54. package/dist/types/index.js +0 -14
  55. package/dist/types/model.d.ts +0 -14
  56. package/dist/types/model.js +0 -1
  57. package/dist/types/opaque.d.ts +0 -103
  58. package/dist/types/opaque.js +0 -1
  59. package/dist/types/operators.d.ts +0 -44
  60. package/dist/types/operators.js +0 -59
  61. package/dist/types/overview-graph.d.ts +0 -41
  62. package/dist/types/overview-graph.js +0 -1
  63. package/dist/types/relation.d.ts +0 -30
  64. package/dist/types/relation.js +0 -3
  65. package/dist/types/theme.d.ts +0 -27
  66. package/dist/types/theme.js +0 -1
  67. package/dist/types/view-changes.d.ts +0 -26
  68. package/dist/types/view-changes.js +0 -1
  69. package/dist/types/view-notation.d.ts +0 -9
  70. package/dist/types/view-notation.js +0 -1
  71. package/dist/types/view.d.ts +0 -243
  72. package/dist/types/view.js +0 -50
  73. package/dist/utils/fqn.d.ts +0 -39
  74. package/dist/utils/fqn.js +0 -102
  75. package/dist/utils/fqn.spec.d.ts +0 -2
  76. package/dist/utils/fqn.spec.js +0 -82
  77. package/dist/utils/guards.d.ts +0 -5
  78. package/dist/utils/guards.js +0 -7
  79. package/dist/utils/index.d.ts +0 -5
  80. package/dist/utils/index.js +0 -4
  81. package/dist/utils/promises.d.ts +0 -2
  82. package/dist/utils/promises.js +0 -8
  83. package/dist/utils/relations.d.ts +0 -30
  84. package/dist/utils/relations.js +0 -79
  85. package/dist/utils/relations.spec.d.ts +0 -2
  86. package/dist/utils/relations.spec.js +0 -210
  87. package/src/errors/errors.spec.ts +0 -88
  88. package/src/reset.d.ts +0 -2
  89. package/src/types/opaque.ts +0 -108
package/src/utils/fqn.ts CHANGED
@@ -61,7 +61,7 @@ export function commonAncestor(first: Fqn, second: Fqn) {
61
61
  export function parentFqn(fqn: Fqn): Fqn | null {
62
62
  const lastDot = fqn.lastIndexOf('.')
63
63
  if (lastDot > 0) {
64
- return fqn.substring(0, lastDot) as Fqn
64
+ return fqn.slice(0, lastDot) as Fqn
65
65
  }
66
66
  return null
67
67
  }
@@ -81,9 +81,12 @@ export function ancestorsFqn(fqn: Fqn): Fqn[] {
81
81
  if (path.length === 0) {
82
82
  return []
83
83
  }
84
- return path.reduce((acc, _, idx) => {
85
- const ancestor = path.slice(0, idx + 1).join('.')
86
- acc.unshift(ancestor as Fqn)
84
+ return path.reduce((acc, part, idx) => {
85
+ if (idx === 0) {
86
+ acc.push(part as Fqn)
87
+ return acc
88
+ }
89
+ acc.unshift(`${acc[0]}.${part}` as Fqn)
87
90
  return acc
88
91
  }, [] as Fqn[])
89
92
  }
@@ -1,8 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest'
2
2
  import type { Fqn, Relation, RelationID } from '../types'
3
- import { compareRelations, Relations } from './relations'
4
-
5
- const { isAnyBetween, isAnyInOut, isBetween, isIncoming, isInside, isOutgoing } = Relations
3
+ import { compareRelations, isAnyBetween, isAnyInOut, isBetween, isIncoming, isInside, isOutgoing } from './relations'
6
4
 
7
5
  const relations = [
8
6
  {
@@ -32,14 +32,14 @@ export const compareRelations = <T extends { source: string; target: string }>(a
32
32
  return compareParents
33
33
  }
34
34
 
35
- const isInside = (parent: Fqn): RelationPredicate => {
35
+ export const isInside = (parent: Fqn): RelationPredicate => {
36
36
  const prefix = parent + '.'
37
37
  return (rel: Relation) => {
38
38
  return rel.source.startsWith(prefix) && rel.target.startsWith(prefix)
39
39
  }
40
40
  }
41
41
 
42
- const isBetween = (source: Fqn, target: Fqn): RelationPredicate => {
42
+ export const isBetween = (source: Fqn, target: Fqn): RelationPredicate => {
43
43
  const sourcePrefix = source + '.'
44
44
  const targetPrefix = target + '.'
45
45
  return (rel: Relation) => {
@@ -50,12 +50,12 @@ const isBetween = (source: Fqn, target: Fqn): RelationPredicate => {
50
50
  }
51
51
  }
52
52
 
53
- const isAnyBetween = (source: Fqn, target: Fqn): RelationPredicate => {
53
+ export const isAnyBetween = (source: Fqn, target: Fqn): RelationPredicate => {
54
54
  const predicates = [isBetween(source, target), isBetween(target, source)]
55
55
  return (rel) => predicates.some(p => p(rel))
56
56
  }
57
57
 
58
- const isIncoming = (target: Fqn): RelationPredicate => {
58
+ export const isIncoming = (target: Fqn): RelationPredicate => {
59
59
  const targetPrefix = target + '.'
60
60
  return (rel: Relation) => {
61
61
  return (
@@ -65,7 +65,7 @@ const isIncoming = (target: Fqn): RelationPredicate => {
65
65
  }
66
66
  }
67
67
 
68
- const isOutgoing = (source: Fqn): RelationPredicate => {
68
+ export const isOutgoing = (source: Fqn): RelationPredicate => {
69
69
  const sourcePrefix = source + '.'
70
70
  return (rel: Relation) => {
71
71
  return (
@@ -75,14 +75,14 @@ const isOutgoing = (source: Fqn): RelationPredicate => {
75
75
  }
76
76
  }
77
77
 
78
- const isAnyInOut = (source: Fqn): RelationPredicate => {
78
+ export const isAnyInOut = (source: Fqn): RelationPredicate => {
79
79
  const predicates = [isIncoming(source), isOutgoing(source)]
80
80
  return (rel: Relation) => {
81
81
  return predicates.some(p => p(rel))
82
82
  }
83
83
  }
84
84
 
85
- const hasRelation = <R extends { source: Fqn; target: Fqn }>(rel: R) => {
85
+ export const hasRelation = <R extends { source: Fqn; target: Fqn }>(rel: R) => {
86
86
  return <E extends { id: Fqn }>(element: E) => {
87
87
  return (
88
88
  rel.source === element.id
@@ -92,13 +92,3 @@ const hasRelation = <R extends { source: Fqn; target: Fqn }>(rel: R) => {
92
92
  )
93
93
  }
94
94
  }
95
-
96
- export const Relations = {
97
- isInside,
98
- isBetween,
99
- isAnyBetween,
100
- isIncoming,
101
- isOutgoing,
102
- isAnyInOut,
103
- hasRelation
104
- } as const
@@ -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: "#f5b2a3";
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: "#f9b27c";
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,75 +0,0 @@
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: '#f5b2a3'
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: '#f9b27c'
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
- };
@@ -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: "#f5b2a3";
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: "#f9b27c";
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: "#f5b2a3";
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: "Arial";
130
- shadow: "#0a0a0a";
131
- };
132
- export { ElementColors, RelationshipColors };
133
- //# sourceMappingURL=index.d.ts.map
@@ -1,9 +0,0 @@
1
- import { ElementColors } from './element';
2
- import { RelationshipColors } from './relationships';
3
- export const defaultTheme = {
4
- elements: ElementColors,
5
- relationships: RelationshipColors,
6
- font: 'Arial',
7
- shadow: '#0a0a0a'
8
- };
9
- export { ElementColors, RelationshipColors };
@@ -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: "#f5b2a3";
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,49 +0,0 @@
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: '#f5b2a3'
45
- },
46
- secondary: sky,
47
- sky,
48
- slate
49
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=errors.spec.d.ts.map
@@ -1,69 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { BaseError, InvalidArgError, InvalidModelError, invariant, InvariantError, NonExhaustiveError, normalizeError, NullableError, RelationRefError, UnknownError } from './index';
3
- describe('errors', () => {
4
- describe('normalizeError', () => {
5
- it.each([
6
- { error: new BaseError('BaseError') },
7
- { error: new RelationRefError('RelationRefError') },
8
- { error: new UnknownError('UnknownError') },
9
- { error: new InvariantError('InvariantError') },
10
- { error: new NonExhaustiveError('NonExhaustiveError') },
11
- { error: new InvalidModelError('InvalidModelError') },
12
- { error: new NullableError('NullableError') },
13
- { error: new InvalidArgError('InvalidArgError') }
14
- ])('should return $error.name as-is', ({ error }) => {
15
- expect(normalizeError(error)).toBe(error);
16
- });
17
- it.skip('should wrap an error', () => {
18
- const cause = new Error('original test');
19
- const error = normalizeError(cause);
20
- expect(error).toBeInstanceOf(UnknownError);
21
- expect(error).to.include({
22
- name: 'UnknownError',
23
- message: 'original test'
24
- });
25
- expect(error).to.have.property('cause').that.eq(cause);
26
- expect(error)
27
- .to.have.property('stack')
28
- .that.is.a('string')
29
- .and.includes('UnknownError: original test');
30
- });
31
- it('should wrap a string', () => {
32
- const cause = 'error string';
33
- const error = normalizeError(cause);
34
- expect(error).toBeInstanceOf(UnknownError);
35
- expect(error).to.include({
36
- name: 'UnknownError',
37
- message: cause
38
- });
39
- expect(error).not.to.have.property('cause');
40
- expect(error).to.have.property('stack').that.is.a('string');
41
- });
42
- // Fails on serializiation of AST
43
- it.skip('should wrap an object', () => {
44
- const cause = { foo: 'bar' };
45
- const error = normalizeError(cause);
46
- expect(error).toBeInstanceOf(UnknownError);
47
- expect(error).to.include({
48
- name: 'UnknownError',
49
- message: '{"foo":"bar"}'
50
- });
51
- expect(error).not.to.have.property('cause');
52
- expect(error).to.have.property('stack').that.is.a('string');
53
- });
54
- });
55
- });
56
- describe('invariant', () => {
57
- it('should throw an error if the condition fails', () => {
58
- expect(() => invariant(false)).toThrow('Invariant failed');
59
- });
60
- it('should throw an error if the condition is null', () => {
61
- expect(() => invariant(null)).toThrow(InvariantError);
62
- });
63
- it('should not throw an error if the condition passes', () => {
64
- expect(() => invariant(true)).not.toThrow();
65
- });
66
- it('should throw an error with the provided message if the condition fails', () => {
67
- expect(() => invariant(false, 'test')).toThrow('test');
68
- });
69
- });
@@ -1,39 +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): NonNullable<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
- //# sourceMappingURL=index.d.ts.map