@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.
- package/dist/index.cjs +4368 -0
- package/dist/index.d.cts +781 -0
- package/dist/index.d.mts +781 -0
- package/dist/index.mjs +4296 -0
- package/dist/shared/core.9l7eW3pn.d.cts +817 -0
- package/dist/shared/core.9l7eW3pn.d.mts +817 -0
- package/dist/shared/core.DcPLm41i.cjs +304 -0
- package/dist/shared/core.DfUTsojZ.mjs +251 -0
- package/dist/types/index.cjs +53 -0
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.mjs +1 -0
- package/package.json +41 -33
- package/src/colors/index.ts +27 -1
- package/src/errors/index.ts +3 -95
- package/src/index.ts +5 -6
- package/src/model/LikeC4Model.ts +480 -0
- package/src/model/LikeC4ViewModel.ts +318 -0
- package/src/model/__test__/LikeC4Model.spec.ts +79 -0
- package/src/model/__test__/fixture.ts +333 -0
- package/src/model/index.ts +2 -0
- package/src/model/types.ts +10 -0
- package/src/types/_common.ts +4 -2
- package/src/types/element.ts +8 -8
- package/src/types/expression.ts +3 -3
- package/src/types/index.ts +0 -1
- package/src/types/model.ts +16 -6
- package/src/types/relation.ts +15 -5
- package/src/types/theme.ts +28 -12
- package/src/types/view-notation.ts +3 -4
- package/src/types/view.ts +14 -10
- package/src/utils/fqn.ts +7 -4
- package/src/utils/relations.spec.ts +1 -3
- package/src/utils/relations.ts +7 -17
- package/dist/colors/element.d.ts +0 -69
- package/dist/colors/element.js +0 -75
- package/dist/colors/index.d.ts +0 -133
- package/dist/colors/index.js +0 -9
- package/dist/colors/relationships.d.ts +0 -58
- package/dist/colors/relationships.js +0 -49
- package/dist/errors/errors.spec.d.ts +0 -2
- package/dist/errors/errors.spec.js +0 -69
- package/dist/errors/index.d.ts +0 -39
- package/dist/errors/index.js +0 -104
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -4
- package/dist/types/_common.d.ts +0 -9
- package/dist/types/_common.js +0 -1
- package/dist/types/element.d.ts +0 -55
- package/dist/types/element.js +0 -15
- package/dist/types/expression.d.ts +0 -119
- package/dist/types/expression.js +0 -67
- package/dist/types/index.d.ts +0 -14
- package/dist/types/index.js +0 -14
- package/dist/types/model.d.ts +0 -14
- package/dist/types/model.js +0 -1
- package/dist/types/opaque.d.ts +0 -103
- package/dist/types/opaque.js +0 -1
- package/dist/types/operators.d.ts +0 -44
- package/dist/types/operators.js +0 -59
- package/dist/types/overview-graph.d.ts +0 -41
- package/dist/types/overview-graph.js +0 -1
- package/dist/types/relation.d.ts +0 -30
- package/dist/types/relation.js +0 -3
- package/dist/types/theme.d.ts +0 -27
- package/dist/types/theme.js +0 -1
- package/dist/types/view-changes.d.ts +0 -26
- package/dist/types/view-changes.js +0 -1
- package/dist/types/view-notation.d.ts +0 -9
- package/dist/types/view-notation.js +0 -1
- package/dist/types/view.d.ts +0 -243
- package/dist/types/view.js +0 -50
- package/dist/utils/fqn.d.ts +0 -39
- package/dist/utils/fqn.js +0 -102
- package/dist/utils/fqn.spec.d.ts +0 -2
- package/dist/utils/fqn.spec.js +0 -82
- package/dist/utils/guards.d.ts +0 -5
- package/dist/utils/guards.js +0 -7
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/index.js +0 -4
- package/dist/utils/promises.d.ts +0 -2
- package/dist/utils/promises.js +0 -8
- package/dist/utils/relations.d.ts +0 -30
- package/dist/utils/relations.js +0 -79
- package/dist/utils/relations.spec.d.ts +0 -2
- package/dist/utils/relations.spec.js +0 -210
- package/src/errors/errors.spec.ts +0 -88
- package/src/reset.d.ts +0 -2
- package/src/types/opaque.ts +0 -108
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://likec4.dev",
|
|
6
6
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
13
13
|
"scripts": {
|
|
14
14
|
"typecheck": "tsc --noEmit",
|
|
15
|
-
"
|
|
15
|
+
"build": "unbuild",
|
|
16
16
|
"lint": "run -T eslint src/ --fix",
|
|
17
17
|
"test": "vitest run --no-isolate",
|
|
18
18
|
"test:watch": "vitest",
|
|
@@ -27,20 +27,24 @@
|
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/index.d.mts",
|
|
32
|
+
"default": "./dist/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/index.d.cts",
|
|
36
|
+
"default": "./dist/index.cjs"
|
|
37
|
+
}
|
|
36
38
|
},
|
|
37
39
|
"./types": {
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/types/index.d.mts",
|
|
42
|
+
"default": "./dist/types/index.mjs"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/types/index.d.cts",
|
|
46
|
+
"default": "./dist/types/index.cjs"
|
|
47
|
+
}
|
|
44
48
|
}
|
|
45
49
|
},
|
|
46
50
|
"publishConfig": {
|
|
@@ -48,33 +52,37 @@
|
|
|
48
52
|
"access": "public",
|
|
49
53
|
"exports": {
|
|
50
54
|
".": {
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
55
|
+
"import": {
|
|
56
|
+
"types": "./dist/index.d.mts",
|
|
57
|
+
"default": "./dist/index.mjs"
|
|
58
|
+
},
|
|
59
|
+
"require": {
|
|
60
|
+
"types": "./dist/index.d.cts",
|
|
61
|
+
"default": "./dist/index.cjs"
|
|
62
|
+
}
|
|
57
63
|
},
|
|
58
64
|
"./types": {
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
+
"import": {
|
|
66
|
+
"types": "./dist/types/index.d.mts",
|
|
67
|
+
"default": "./dist/types/index.mjs"
|
|
68
|
+
},
|
|
69
|
+
"require": {
|
|
70
|
+
"types": "./dist/types/index.d.cts",
|
|
71
|
+
"default": "./dist/types/index.cjs"
|
|
72
|
+
}
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
},
|
|
68
|
-
"dependencies": {
|
|
69
|
-
"remeda": "^2.11.0",
|
|
70
|
-
"ts-custom-error": "^3.3.1",
|
|
71
|
-
"type-fest": "^4.21.0"
|
|
72
|
-
},
|
|
73
76
|
"devDependencies": {
|
|
74
|
-
"@likec4/tsconfig": "1.
|
|
75
|
-
"@
|
|
77
|
+
"@likec4/tsconfig": "1.9.0",
|
|
78
|
+
"@mantine/colors-generator": "^7.12.2",
|
|
79
|
+
"chroma-js": "^3.0.0",
|
|
76
80
|
"execa": "^9.3.1",
|
|
81
|
+
"remeda": "^2.11.0",
|
|
82
|
+
"turbo": "^2.1.1",
|
|
83
|
+
"type-fest": "^4.26.0",
|
|
77
84
|
"typescript": "^5.5.4",
|
|
85
|
+
"unbuild": "^3.0.0-rc.7",
|
|
78
86
|
"vitest": "~2.0.5"
|
|
79
87
|
},
|
|
80
88
|
"packageManager": "yarn@4.3.1"
|
package/src/colors/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { generateColors } from '@mantine/colors-generator'
|
|
2
|
+
import type { HexColorLiteral, LikeC4Theme, ThemeColorValues } from '../types/theme'
|
|
2
3
|
import { ElementColors } from './element'
|
|
3
4
|
import { RelationshipColors } from './relationships'
|
|
4
5
|
|
|
@@ -9,4 +10,29 @@ export const defaultTheme = {
|
|
|
9
10
|
shadow: '#0a0a0a'
|
|
10
11
|
} satisfies LikeC4Theme
|
|
11
12
|
|
|
13
|
+
export function computeColorValues(color: HexColorLiteral): ThemeColorValues {
|
|
14
|
+
if (color.match(/^#([0-9a-f]{3}){1,2}$/i)) {
|
|
15
|
+
const colors = generateColors(color)
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
elements: {
|
|
19
|
+
fill: colors[6] as HexColorLiteral,
|
|
20
|
+
stroke: colors[7] as HexColorLiteral,
|
|
21
|
+
hiContrast: colors[0] as HexColorLiteral,
|
|
22
|
+
loContrast: colors[1] as HexColorLiteral
|
|
23
|
+
},
|
|
24
|
+
relationships: {
|
|
25
|
+
lineColor: colors[4] as HexColorLiteral,
|
|
26
|
+
labelColor: colors[3] as HexColorLiteral,
|
|
27
|
+
labelBgColor: colors[9] as HexColorLiteral
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
return {
|
|
32
|
+
elements: defaultTheme.elements['primary'],
|
|
33
|
+
relationships: defaultTheme.relationships['primary']
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
12
38
|
export { ElementColors, RelationshipColors }
|
package/src/errors/index.ts
CHANGED
|
@@ -1,89 +1,13 @@
|
|
|
1
|
-
import { CustomError } from 'ts-custom-error'
|
|
2
|
-
import { isString } from '../utils/guards'
|
|
3
|
-
|
|
4
|
-
export interface BaseErrorOptions {
|
|
5
|
-
cause?: unknown
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Base class for all errors in the LikeC4 library.
|
|
10
|
-
*/
|
|
11
|
-
export class BaseError extends CustomError {
|
|
12
|
-
constructor(message: string, options?: BaseErrorOptions) {
|
|
13
|
-
super(message, options)
|
|
14
|
-
// Set name explicitly as minification can mangle class names
|
|
15
|
-
Object.defineProperty(this, 'name', { value: 'BaseError' })
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class InvalidArgError extends BaseError {
|
|
20
|
-
constructor(message: string, options?: BaseErrorOptions) {
|
|
21
|
-
super(message, options)
|
|
22
|
-
// Set name explicitly as minification can mangle class names
|
|
23
|
-
Object.defineProperty(this, 'name', { value: 'InvalidArgError' })
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Unknown error, mosly probably a bug, unhandled case or coming from a third-party library.
|
|
29
|
-
*/
|
|
30
|
-
export class UnknownError extends BaseError {
|
|
31
|
-
constructor(message: string, options?: BaseErrorOptions) {
|
|
32
|
-
super(message, options)
|
|
33
|
-
// Set name explicitly as minification can mangle class names
|
|
34
|
-
Object.defineProperty(this, 'name', { value: 'UnknownError' })
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class NullableError extends BaseError {
|
|
39
|
-
public constructor(message: string, options?: BaseErrorOptions) {
|
|
40
|
-
super(message, options)
|
|
41
|
-
// Set name explicitly as minification can mangle class names
|
|
42
|
-
Object.defineProperty(this, 'name', { value: 'NullableError' })
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export class InvariantError extends BaseError {
|
|
47
|
-
public constructor(message: string, options?: BaseErrorOptions) {
|
|
48
|
-
super(message, options)
|
|
49
|
-
// Set name explicitly as minification can mangle class names
|
|
50
|
-
Object.defineProperty(this, 'name', { value: 'InvariantError' })
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
1
|
// Ensure that the value is NonNullable
|
|
55
2
|
// Mostly as safer `value!`
|
|
56
3
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
57
4
|
export function nonNullable<T>(value: T, message?: string): NonNullable<T> {
|
|
58
5
|
if (typeof value === 'undefined' || value == null) {
|
|
59
|
-
throw new
|
|
6
|
+
throw new Error(message ?? `Expected defined value, but received ${value}`)
|
|
60
7
|
}
|
|
61
8
|
return value
|
|
62
9
|
}
|
|
63
10
|
|
|
64
|
-
export class RelationRefError extends BaseError {
|
|
65
|
-
public constructor(message: string, options?: BaseErrorOptions) {
|
|
66
|
-
super(message, options)
|
|
67
|
-
// Set name explicitly as minification can mangle class names
|
|
68
|
-
Object.defineProperty(this, 'name', { value: 'RelationRefError' })
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function normalizeError(e: unknown): Error {
|
|
73
|
-
if (e instanceof BaseError || e instanceof Error) {
|
|
74
|
-
return e
|
|
75
|
-
}
|
|
76
|
-
const message = isString(e) ? e : String(e)
|
|
77
|
-
const error = new UnknownError(message)
|
|
78
|
-
try {
|
|
79
|
-
// @ts-ignore
|
|
80
|
-
Error.captureStackTrace(error, normalizeError)
|
|
81
|
-
} catch {
|
|
82
|
-
// Ignore
|
|
83
|
-
}
|
|
84
|
-
return error
|
|
85
|
-
}
|
|
86
|
-
|
|
87
11
|
// Throw an error if the condition fails
|
|
88
12
|
// > Not providing an inline default argument for message as the result is smaller
|
|
89
13
|
export function invariant(
|
|
@@ -96,25 +20,9 @@ export function invariant(
|
|
|
96
20
|
if (condition) {
|
|
97
21
|
return
|
|
98
22
|
}
|
|
99
|
-
throw new
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export class NonExhaustiveError extends BaseError {
|
|
103
|
-
public constructor(message: string, options?: BaseErrorOptions) {
|
|
104
|
-
super(message, options)
|
|
105
|
-
// Set name explicitly as minification can mangle class names
|
|
106
|
-
Object.defineProperty(this, 'name', { value: 'NonExhaustiveError' })
|
|
107
|
-
}
|
|
23
|
+
throw new Error(message ?? 'Invariant failed')
|
|
108
24
|
}
|
|
109
25
|
|
|
110
26
|
export function nonexhaustive(value: never): never {
|
|
111
|
-
throw new
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export class InvalidModelError extends BaseError {
|
|
115
|
-
public constructor(message: string, options?: BaseErrorOptions) {
|
|
116
|
-
super(message, options)
|
|
117
|
-
// Set name explicitly as minification can mangle class names
|
|
118
|
-
Object.defineProperty(this, 'name', { value: 'InvalidModelError' })
|
|
119
|
-
}
|
|
27
|
+
throw new Error(`NonExhaustive value: ${value}`)
|
|
120
28
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export * from './colors'
|
|
2
2
|
export * from './errors'
|
|
3
|
+
export * from './model'
|
|
3
4
|
export * from './types'
|
|
4
|
-
export * from './utils'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
// Type aliases 2
|
|
9
|
-
export type * as c4 from './types'
|
|
5
|
+
export * from './utils/fqn'
|
|
6
|
+
export * from './utils/guards'
|
|
7
|
+
export * from './utils/promises'
|
|
8
|
+
export { compareRelations } from './utils/relations'
|