@likec4/generators 1.38.1 → 1.39.1
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/model/generate-aux.js +1 -1
- package/dist/react/generate-react-types.js +1 -1
- package/package.json +9 -5
- package/src/model/generate-aux.ts +2 -2
- package/src/react/generate-react-types.ts +1 -1
- package/src/__mocks__/data.ts +0 -463
- package/src/d2/__snapshots__/generate-d2.spec.ts.snap +0 -169
- package/src/d2/generate-d2.spec.ts +0 -102
- package/src/mmd/__snapshots__/generate-mmd.spec.ts.snap +0 -55
- package/src/mmd/generate-mmd.spec.ts +0 -23
- package/src/model/__snapshots__/_aux.generate-valid-code.snap +0 -56
- package/src/model/__snapshots__/likec4.computed-model.snap +0 -1150
- package/src/model/__snapshots__/likec4.parsed-model.snap +0 -654
- package/src/model/generate-aux.spec.ts +0 -65
- package/src/model/generate-likec4-model.spec.ts +0 -184
- package/src/puml/__snapshots__/generate-puml.spec.ts.snap +0 -184
- package/src/puml/generate-puml.spec.ts +0 -26
- package/src/react/__snapshots__/valid-code.snap +0 -111
- package/src/react/generate-react-types.spec.ts +0 -67
- package/src/views-data-ts/__snapshots__/generate-views-data.spec.ts.snap +0 -83
- package/src/views-data-ts/generate-views-data.spec.ts +0 -15
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { Builder } from '@likec4/core/builder'
|
|
2
|
-
import { computeParsedModelData, viewsWithReadableEdges } from '@likec4/core/compute-view'
|
|
3
|
-
import { LikeC4Model } from '@likec4/core/model'
|
|
4
|
-
import { describe, it } from 'vitest'
|
|
5
|
-
import { generateLikeC4Model } from './generate-likec4-model'
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
builder: b,
|
|
9
|
-
model: {
|
|
10
|
-
model,
|
|
11
|
-
person,
|
|
12
|
-
system,
|
|
13
|
-
component,
|
|
14
|
-
webapp,
|
|
15
|
-
mobile,
|
|
16
|
-
...$m
|
|
17
|
-
},
|
|
18
|
-
deployment: {
|
|
19
|
-
deployment,
|
|
20
|
-
env,
|
|
21
|
-
node,
|
|
22
|
-
zone,
|
|
23
|
-
instanceOf,
|
|
24
|
-
...$d
|
|
25
|
-
},
|
|
26
|
-
views: {
|
|
27
|
-
view,
|
|
28
|
-
views,
|
|
29
|
-
viewOf,
|
|
30
|
-
deploymentView,
|
|
31
|
-
$rules,
|
|
32
|
-
$include,
|
|
33
|
-
$exclude,
|
|
34
|
-
$style,
|
|
35
|
-
},
|
|
36
|
-
} = Builder.forSpecification({
|
|
37
|
-
elements: {
|
|
38
|
-
person: {
|
|
39
|
-
style: {
|
|
40
|
-
shape: 'person',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
system: {},
|
|
44
|
-
component: {},
|
|
45
|
-
webapp: {
|
|
46
|
-
style: {
|
|
47
|
-
shape: 'browser',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
mobile: {
|
|
51
|
-
style: {
|
|
52
|
-
shape: 'mobile',
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
tags: {
|
|
57
|
-
internal: {},
|
|
58
|
-
external: {},
|
|
59
|
-
},
|
|
60
|
-
metadataKeys: ['key1'],
|
|
61
|
-
deployments: {
|
|
62
|
-
env: {},
|
|
63
|
-
zone: {},
|
|
64
|
-
node: {},
|
|
65
|
-
},
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
const builder = b
|
|
69
|
-
.with(
|
|
70
|
-
model(
|
|
71
|
-
person('customer'),
|
|
72
|
-
system('cloud').with(
|
|
73
|
-
component('frontend').with(
|
|
74
|
-
webapp('dashboard'),
|
|
75
|
-
mobile('mobile'),
|
|
76
|
-
),
|
|
77
|
-
component('auth'),
|
|
78
|
-
component('backend', {
|
|
79
|
-
metadata: {
|
|
80
|
-
key1: 'value1',
|
|
81
|
-
},
|
|
82
|
-
tags: ['external'],
|
|
83
|
-
}).with(
|
|
84
|
-
component('api'),
|
|
85
|
-
component('graphql'),
|
|
86
|
-
),
|
|
87
|
-
component('media', {
|
|
88
|
-
tags: ['internal'],
|
|
89
|
-
shape: 'storage',
|
|
90
|
-
}),
|
|
91
|
-
),
|
|
92
|
-
system('aws').with(
|
|
93
|
-
component('rds', {
|
|
94
|
-
shape: 'storage',
|
|
95
|
-
}),
|
|
96
|
-
component('s3', {
|
|
97
|
-
metadata: {
|
|
98
|
-
key1: 'value2',
|
|
99
|
-
},
|
|
100
|
-
shape: 'storage',
|
|
101
|
-
}),
|
|
102
|
-
),
|
|
103
|
-
system('email'),
|
|
104
|
-
),
|
|
105
|
-
model(
|
|
106
|
-
$m.rel('customer', 'cloud', 'uses services'),
|
|
107
|
-
$m.rel('customer', 'cloud.frontend.mobile', 'opens mobile app'),
|
|
108
|
-
$m.rel('customer', 'cloud.frontend.dashboard', 'opens in browser'),
|
|
109
|
-
$m.rel('cloud.frontend.dashboard', 'cloud.auth', 'authenticates'),
|
|
110
|
-
$m.rel('cloud.frontend.dashboard', 'cloud.backend.api', 'fetches data'),
|
|
111
|
-
$m.rel('cloud.frontend.dashboard', 'cloud.media', 'fetches media'),
|
|
112
|
-
$m.rel('cloud.frontend.mobile', 'cloud.auth', 'authenticates'),
|
|
113
|
-
$m.rel('cloud.frontend.mobile', 'cloud.backend.api', 'fetches data'),
|
|
114
|
-
$m.rel('cloud.frontend.mobile', 'cloud.media', 'fetches media'),
|
|
115
|
-
$m.rel('cloud.backend.api', 'cloud.auth', 'authorizes'),
|
|
116
|
-
$m.rel('cloud.backend.api', 'cloud.media', 'uploads media'),
|
|
117
|
-
$m.rel('cloud.backend.api', 'aws.rds', 'reads/writes'),
|
|
118
|
-
$m.rel('cloud.backend.api', 'email', 'sends emails'),
|
|
119
|
-
$m.rel('cloud.media', 'aws.s3', 'uploads'),
|
|
120
|
-
$m.rel('email', 'customer', {
|
|
121
|
-
tags: ['external'],
|
|
122
|
-
title: 'sends emails',
|
|
123
|
-
metadata: {
|
|
124
|
-
key1: 'value3',
|
|
125
|
-
},
|
|
126
|
-
}),
|
|
127
|
-
),
|
|
128
|
-
deployment(
|
|
129
|
-
node('customer').with(
|
|
130
|
-
instanceOf('instance', 'customer'),
|
|
131
|
-
),
|
|
132
|
-
env('prod').with(
|
|
133
|
-
zone('eu').with(
|
|
134
|
-
zone('zone1').with(
|
|
135
|
-
instanceOf('ui', 'cloud.frontend.dashboard'),
|
|
136
|
-
instanceOf('api', 'cloud.backend.api'),
|
|
137
|
-
),
|
|
138
|
-
zone('zone2').with(
|
|
139
|
-
instanceOf('ui', 'cloud.frontend.dashboard'),
|
|
140
|
-
instanceOf('api', 'cloud.backend.api'),
|
|
141
|
-
),
|
|
142
|
-
instanceOf('media', 'cloud.media'),
|
|
143
|
-
instanceOf('db', 'aws.rds'),
|
|
144
|
-
),
|
|
145
|
-
zone('us').with(
|
|
146
|
-
instanceOf('db', 'aws.rds'),
|
|
147
|
-
),
|
|
148
|
-
),
|
|
149
|
-
$d.rel('prod.eu.db', 'prod.us.db', 'replicates'),
|
|
150
|
-
),
|
|
151
|
-
views(
|
|
152
|
-
view('index', $include('*')),
|
|
153
|
-
viewOf(
|
|
154
|
-
'cloud',
|
|
155
|
-
'cloud',
|
|
156
|
-
$rules(
|
|
157
|
-
$include('*'),
|
|
158
|
-
$include('cloud.frontend.dashboard'),
|
|
159
|
-
),
|
|
160
|
-
),
|
|
161
|
-
deploymentView(
|
|
162
|
-
'prod',
|
|
163
|
-
'prod',
|
|
164
|
-
$rules(
|
|
165
|
-
$include('customer.instance'),
|
|
166
|
-
$include('prod.eu.zone1.ui'),
|
|
167
|
-
),
|
|
168
|
-
),
|
|
169
|
-
),
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
describe('generateLikeC4Model', () => {
|
|
173
|
-
it('parsed-model', async ({ expect }) => {
|
|
174
|
-
const parsed = builder.build()
|
|
175
|
-
const m = LikeC4Model.create(parsed)
|
|
176
|
-
await expect(generateLikeC4Model(m)).toMatchFileSnapshot('__snapshots__/likec4.parsed-model.snap')
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('computed-model', async ({ expect }) => {
|
|
180
|
-
const computed = viewsWithReadableEdges(computeParsedModelData(builder.build()))
|
|
181
|
-
const m = LikeC4Model.create(computed)
|
|
182
|
-
await expect(generateLikeC4Model(m)).toMatchFileSnapshot('__snapshots__/likec4.computed-model.snap')
|
|
183
|
-
})
|
|
184
|
-
})
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`generate puml - fakeComputedView 3 Levels 1`] = `
|
|
4
|
-
"@startuml
|
|
5
|
-
title "Context: Cloud"
|
|
6
|
-
top to bottom direction
|
|
7
|
-
|
|
8
|
-
hide stereotype
|
|
9
|
-
skinparam ranksep 60
|
|
10
|
-
skinparam nodesep 30
|
|
11
|
-
skinparam {
|
|
12
|
-
arrowFontSize 10
|
|
13
|
-
defaultTextAlignment center
|
|
14
|
-
wrapWidth 200
|
|
15
|
-
maxMessageSize 100
|
|
16
|
-
shadowing false
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
skinparam rectangle<<Amazon>>{
|
|
20
|
-
BackgroundColor #3b82f6
|
|
21
|
-
FontColor #FFFFFF
|
|
22
|
-
BorderColor #3b82f6
|
|
23
|
-
}
|
|
24
|
-
skinparam rectangle<<Customer>>{
|
|
25
|
-
BackgroundColor #3b82f6
|
|
26
|
-
FontColor #FFFFFF
|
|
27
|
-
BorderColor #3b82f6
|
|
28
|
-
}
|
|
29
|
-
skinparam rectangle<<Support>>{
|
|
30
|
-
BackgroundColor #3b82f6
|
|
31
|
-
FontColor #FFFFFF
|
|
32
|
-
BorderColor #3b82f6
|
|
33
|
-
}
|
|
34
|
-
skinparam rectangle<<CloudBackendGraphql>>{
|
|
35
|
-
BackgroundColor #3b82f6
|
|
36
|
-
FontColor #FFFFFF
|
|
37
|
-
BorderColor #3b82f6
|
|
38
|
-
}
|
|
39
|
-
skinparam rectangle<<CloudBackendStorage>>{
|
|
40
|
-
BackgroundColor #3b82f6
|
|
41
|
-
FontColor #FFFFFF
|
|
42
|
-
BorderColor #3b82f6
|
|
43
|
-
}
|
|
44
|
-
skinparam rectangle<<CloudFrontendAdminPanel>>{
|
|
45
|
-
BackgroundColor #3b82f6
|
|
46
|
-
FontColor #FFFFFF
|
|
47
|
-
BorderColor #3b82f6
|
|
48
|
-
}
|
|
49
|
-
skinparam rectangle<<CloudFrontendDashboard>>{
|
|
50
|
-
BackgroundColor #3b82f6
|
|
51
|
-
FontColor #FFFFFF
|
|
52
|
-
BorderColor #3b82f6
|
|
53
|
-
}
|
|
54
|
-
rectangle "==amazon" <<Amazon>> as Amazon
|
|
55
|
-
rectangle "cloud" <<Cloud>> as Cloud {
|
|
56
|
-
skinparam RectangleBorderColor<<Cloud>> #3b82f6
|
|
57
|
-
skinparam RectangleFontColor<<Cloud>> #3b82f6
|
|
58
|
-
skinparam RectangleBorderStyle<<Cloud>> dashed
|
|
59
|
-
|
|
60
|
-
rectangle "backend" <<CloudBackend>> as CloudBackend {
|
|
61
|
-
skinparam RectangleBorderColor<<CloudBackend>> #3b82f6
|
|
62
|
-
skinparam RectangleFontColor<<CloudBackend>> #3b82f6
|
|
63
|
-
skinparam RectangleBorderStyle<<CloudBackend>> dashed
|
|
64
|
-
|
|
65
|
-
rectangle "==graphql" <<CloudBackendGraphql>> as CloudBackendGraphql
|
|
66
|
-
rectangle "==storage" <<CloudBackendStorage>> as CloudBackendStorage
|
|
67
|
-
}
|
|
68
|
-
rectangle "==adminPanel" <<CloudFrontendAdminPanel>> as CloudFrontendAdminPanel
|
|
69
|
-
rectangle "==dashboard" <<CloudFrontendDashboard>> as CloudFrontendDashboard
|
|
70
|
-
}
|
|
71
|
-
rectangle "==customer" <<Customer>> as Customer
|
|
72
|
-
rectangle "==support" <<Support>> as Support
|
|
73
|
-
|
|
74
|
-
CloudFrontendDashboard .[#777777,thickness=2].> CloudBackendGraphql
|
|
75
|
-
CloudFrontendAdminPanel .[#777777,thickness=2].> CloudBackendGraphql
|
|
76
|
-
CloudBackendStorage .[#777777,thickness=2].> Amazon
|
|
77
|
-
CloudBackendGraphql .[#777777,thickness=2].> CloudBackendStorage
|
|
78
|
-
Support .[#777777,thickness=2].> CloudFrontendAdminPanel
|
|
79
|
-
Customer .[#777777,thickness=2].> CloudFrontendDashboard
|
|
80
|
-
@enduml
|
|
81
|
-
"
|
|
82
|
-
`;
|
|
83
|
-
|
|
84
|
-
exports[`generate puml - fakeDiagram 1`] = `
|
|
85
|
-
"@startuml
|
|
86
|
-
title "fakeView"
|
|
87
|
-
top to bottom direction
|
|
88
|
-
|
|
89
|
-
hide stereotype
|
|
90
|
-
skinparam ranksep 60
|
|
91
|
-
skinparam nodesep 30
|
|
92
|
-
skinparam {
|
|
93
|
-
arrowFontSize 10
|
|
94
|
-
defaultTextAlignment center
|
|
95
|
-
wrapWidth 200
|
|
96
|
-
maxMessageSize 100
|
|
97
|
-
shadowing false
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
skinparam rectangle<<Amazon>>{
|
|
101
|
-
BackgroundColor #3b82f6
|
|
102
|
-
FontColor #FFFFFF
|
|
103
|
-
BorderColor #3b82f6
|
|
104
|
-
}
|
|
105
|
-
skinparam rectangle<<Customer>>{
|
|
106
|
-
BackgroundColor #3b82f6
|
|
107
|
-
FontColor #FFFFFF
|
|
108
|
-
BorderColor #3b82f6
|
|
109
|
-
}
|
|
110
|
-
skinparam rectangle<<Support>>{
|
|
111
|
-
BackgroundColor #3b82f6
|
|
112
|
-
FontColor #FFFFFF
|
|
113
|
-
BorderColor #3b82f6
|
|
114
|
-
}
|
|
115
|
-
skinparam rectangle<<CloudBackend>>{
|
|
116
|
-
BackgroundColor #3b82f6
|
|
117
|
-
FontColor #FFFFFF
|
|
118
|
-
BorderColor #3b82f6
|
|
119
|
-
}
|
|
120
|
-
skinparam rectangle<<CloudFrontend>>{
|
|
121
|
-
BackgroundColor #3b82f6
|
|
122
|
-
FontColor #FFFFFF
|
|
123
|
-
BorderColor #3b82f6
|
|
124
|
-
}
|
|
125
|
-
rectangle "==amazon" <<Amazon>> as Amazon
|
|
126
|
-
rectangle "cloud" <<Cloud>> as Cloud {
|
|
127
|
-
skinparam RectangleBorderColor<<Cloud>> #3b82f6
|
|
128
|
-
skinparam RectangleFontColor<<Cloud>> #3b82f6
|
|
129
|
-
skinparam RectangleBorderStyle<<Cloud>> dashed
|
|
130
|
-
|
|
131
|
-
rectangle "==backend" <<CloudBackend>> as CloudBackend
|
|
132
|
-
rectangle "==frontend" <<CloudFrontend>> as CloudFrontend
|
|
133
|
-
}
|
|
134
|
-
rectangle "==customer" <<Customer>> as Customer
|
|
135
|
-
rectangle "==support" <<Support>> as Support
|
|
136
|
-
|
|
137
|
-
CloudFrontend .[#777777,thickness=2].> CloudBackend : "<color:#777777>requests<color:#777777>"
|
|
138
|
-
CloudBackend .[#777777,thickness=2].> Amazon
|
|
139
|
-
Support .[#777777,thickness=2].> CloudFrontend
|
|
140
|
-
Customer .[#777777,thickness=2].> CloudFrontend : "<color:#777777>opens<color:#777777>"
|
|
141
|
-
@enduml
|
|
142
|
-
"
|
|
143
|
-
`;
|
|
144
|
-
|
|
145
|
-
exports[`generate puml - fakeDiagram2 1`] = `
|
|
146
|
-
"@startuml
|
|
147
|
-
title "frontend"
|
|
148
|
-
top to bottom direction
|
|
149
|
-
|
|
150
|
-
hide stereotype
|
|
151
|
-
skinparam ranksep 60
|
|
152
|
-
skinparam nodesep 30
|
|
153
|
-
skinparam {
|
|
154
|
-
arrowFontSize 10
|
|
155
|
-
defaultTextAlignment center
|
|
156
|
-
wrapWidth 200
|
|
157
|
-
maxMessageSize 100
|
|
158
|
-
shadowing false
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
skinparam rectangle<<Client>>{
|
|
162
|
-
BackgroundColor #3b82f6
|
|
163
|
-
FontColor #FFFFFF
|
|
164
|
-
BorderColor #3b82f6
|
|
165
|
-
}
|
|
166
|
-
skinparam rectangle<<SystemBackend>>{
|
|
167
|
-
BackgroundColor #3b82f6
|
|
168
|
-
FontColor #FFFFFF
|
|
169
|
-
BorderColor #3b82f6
|
|
170
|
-
}
|
|
171
|
-
skinparam rectangle<<SystemFrontend>>{
|
|
172
|
-
BackgroundColor #3b82f6
|
|
173
|
-
FontColor #FFFFFF
|
|
174
|
-
BorderColor #3b82f6
|
|
175
|
-
}
|
|
176
|
-
rectangle "==client" <<Client>> as Client
|
|
177
|
-
rectangle "==backend" <<SystemBackend>> as SystemBackend
|
|
178
|
-
rectangle "==frontend" <<SystemFrontend>> as SystemFrontend
|
|
179
|
-
|
|
180
|
-
SystemFrontend .[#777777,thickness=2].> SystemBackend : "<color:#777777>requests<color:#777777>"
|
|
181
|
-
Client .[#777777,thickness=2].> SystemFrontend : "<color:#777777>opens<color:#777777>"
|
|
182
|
-
@enduml
|
|
183
|
-
"
|
|
184
|
-
`;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { LikeC4ViewModel } from '@likec4/core/model'
|
|
2
|
-
import type { aux, ProcessedView } from '@likec4/core/types'
|
|
3
|
-
import { expect, test, vi } from 'vitest'
|
|
4
|
-
import { fakeComputedView3Levels, fakeDiagram, fakeDiagram2 } from '../__mocks__/data'
|
|
5
|
-
import { generatePuml } from './generate-puml'
|
|
6
|
-
|
|
7
|
-
const mockViewModel = vi.fn(function($view: ProcessedView) {
|
|
8
|
-
return {
|
|
9
|
-
$view,
|
|
10
|
-
$model: {
|
|
11
|
-
specification: {},
|
|
12
|
-
},
|
|
13
|
-
} as unknown as LikeC4ViewModel<aux.Unknown>
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
test('generate puml - fakeDiagram', () => {
|
|
17
|
-
expect(generatePuml(mockViewModel(fakeDiagram))).toMatchSnapshot()
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
test('generate puml - fakeDiagram2', () => {
|
|
21
|
-
expect(generatePuml(mockViewModel(fakeDiagram2))).toMatchSnapshot()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('generate puml - fakeComputedView 3 Levels', () => {
|
|
25
|
-
expect(generatePuml(mockViewModel(fakeComputedView3Levels))).toMatchSnapshot()
|
|
26
|
-
})
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/* prettier-ignore-start */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
/******************************************************************************
|
|
5
|
-
* This file was generated
|
|
6
|
-
* DO NOT EDIT MANUALLY!
|
|
7
|
-
******************************************************************************/
|
|
8
|
-
|
|
9
|
-
import type { PropsWithChildren } from 'react'
|
|
10
|
-
import type { JSX } from 'react/jsx-runtime'
|
|
11
|
-
import type { LikeC4Model } from '@likec4/core/model'
|
|
12
|
-
import type { DiagramView } from '@likec4/core/types'
|
|
13
|
-
import type {
|
|
14
|
-
LikeC4ViewProps as GenericLikeC4ViewProps,
|
|
15
|
-
ReactLikeC4Props as GenericReactLikeC4Props
|
|
16
|
-
} from 'likec4/react'
|
|
17
|
-
|
|
18
|
-
import type { Aux, SpecAux } from '@likec4/core/types';
|
|
19
|
-
|
|
20
|
-
export type $Specs = SpecAux<
|
|
21
|
-
// Element kinds
|
|
22
|
-
| "actor"
|
|
23
|
-
| "component"
|
|
24
|
-
| "system",
|
|
25
|
-
// Deployment kinds
|
|
26
|
-
| "env"
|
|
27
|
-
| "vm",
|
|
28
|
-
// Relationship kinds
|
|
29
|
-
| "dislike"
|
|
30
|
-
| "like",
|
|
31
|
-
// Tags
|
|
32
|
-
| "tag1"
|
|
33
|
-
| "tag2",
|
|
34
|
-
// Metadata keys
|
|
35
|
-
| "key1"
|
|
36
|
-
| "key2"
|
|
37
|
-
>
|
|
38
|
-
|
|
39
|
-
export type $Aux = Aux<
|
|
40
|
-
"computed",
|
|
41
|
-
// Elements
|
|
42
|
-
| "alice"
|
|
43
|
-
| "bob"
|
|
44
|
-
| "cloud"
|
|
45
|
-
| "cloud.backend"
|
|
46
|
-
| "cloud.frontend"
|
|
47
|
-
| "cloud.backend.api"
|
|
48
|
-
| "cloud.backend.db",
|
|
49
|
-
// Deployments
|
|
50
|
-
| "dev"
|
|
51
|
-
| "prod"
|
|
52
|
-
| "dev.api"
|
|
53
|
-
| "dev.vm1"
|
|
54
|
-
| "prod.vm1"
|
|
55
|
-
| "prod.vm2",
|
|
56
|
-
// Views
|
|
57
|
-
| "view1"
|
|
58
|
-
| "view2",
|
|
59
|
-
// Project ID
|
|
60
|
-
"from-builder",
|
|
61
|
-
$Specs
|
|
62
|
-
>
|
|
63
|
-
|
|
64
|
-
export type $ElementId = $Aux['ElementId']
|
|
65
|
-
export type $DeploymentId = $Aux['DeploymentId']
|
|
66
|
-
export type $ViewId = $Aux['ViewId']
|
|
67
|
-
|
|
68
|
-
export type $ElementKind = $Aux['ElementKind']
|
|
69
|
-
export type $RelationKind = $Aux['RelationKind']
|
|
70
|
-
export type $DeploymentKind = $Aux['DeploymentKind']
|
|
71
|
-
export type $Tag = $Aux['Tag']
|
|
72
|
-
export type $Tags = readonly $Aux['Tag'][]
|
|
73
|
-
export type $MetadataKey = $Aux['MetadataKey']
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
declare function isLikeC4ViewId(value: unknown): value is $ViewId;
|
|
77
|
-
|
|
78
|
-
declare const likec4model: LikeC4Model<$Aux>;
|
|
79
|
-
declare function useLikeC4Model(): LikeC4Model<$Aux>;
|
|
80
|
-
declare function useLikeC4View(viewId: $ViewId): DiagramView<$Aux>;
|
|
81
|
-
|
|
82
|
-
declare function LikeC4ModelProvider(props: PropsWithChildren): JSX.Element;
|
|
83
|
-
|
|
84
|
-
type IconRendererProps = {
|
|
85
|
-
node: {
|
|
86
|
-
id: string
|
|
87
|
-
title: string
|
|
88
|
-
icon?: string | undefined
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
declare function RenderIcon(props: IconRendererProps): JSX.Element;
|
|
92
|
-
|
|
93
|
-
type LikeC4ViewProps = GenericLikeC4ViewProps<$Aux>;
|
|
94
|
-
declare function LikeC4View({viewId, ...props}: LikeC4ViewProps): JSX.Element;
|
|
95
|
-
|
|
96
|
-
type ReactLikeC4Props = GenericReactLikeC4Props<$Aux>
|
|
97
|
-
declare function ReactLikeC4({viewId, ...props}: ReactLikeC4Props): JSX.Element;
|
|
98
|
-
|
|
99
|
-
export {
|
|
100
|
-
type LikeC4ViewProps,
|
|
101
|
-
type ReactLikeC4Props,
|
|
102
|
-
isLikeC4ViewId,
|
|
103
|
-
useLikeC4Model,
|
|
104
|
-
useLikeC4View,
|
|
105
|
-
likec4model,
|
|
106
|
-
LikeC4ModelProvider,
|
|
107
|
-
LikeC4View,
|
|
108
|
-
RenderIcon,
|
|
109
|
-
ReactLikeC4
|
|
110
|
-
}
|
|
111
|
-
/* prettier-ignore-end */
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Builder } from '@likec4/core/builder'
|
|
2
|
-
import { describe, it } from 'vitest'
|
|
3
|
-
import { generateReactTypes } from './generate-react-types'
|
|
4
|
-
|
|
5
|
-
describe('generateReactTypes', () => {
|
|
6
|
-
const m = Builder
|
|
7
|
-
.specification({
|
|
8
|
-
elements: {
|
|
9
|
-
actor: {},
|
|
10
|
-
system: {},
|
|
11
|
-
component: {},
|
|
12
|
-
},
|
|
13
|
-
deployments: {
|
|
14
|
-
env: {},
|
|
15
|
-
vm: {},
|
|
16
|
-
},
|
|
17
|
-
relationships: {
|
|
18
|
-
like: {},
|
|
19
|
-
dislike: {},
|
|
20
|
-
},
|
|
21
|
-
tags: {
|
|
22
|
-
tag1: {},
|
|
23
|
-
tag2: {},
|
|
24
|
-
},
|
|
25
|
-
metadataKeys: ['key1', 'key2'],
|
|
26
|
-
})
|
|
27
|
-
.model(({ actor, system, component, relTo }, _) =>
|
|
28
|
-
_(
|
|
29
|
-
actor('alice'),
|
|
30
|
-
actor('bob'),
|
|
31
|
-
system('cloud').with(
|
|
32
|
-
component('backend').with(
|
|
33
|
-
component('api'),
|
|
34
|
-
component('db', {
|
|
35
|
-
tags: ['tag2'],
|
|
36
|
-
}),
|
|
37
|
-
),
|
|
38
|
-
component('frontend'),
|
|
39
|
-
),
|
|
40
|
-
)
|
|
41
|
-
)
|
|
42
|
-
.deployment(({ env, vm, instanceOf }, _) =>
|
|
43
|
-
_(
|
|
44
|
-
env('prod').with(
|
|
45
|
-
vm('vm1'),
|
|
46
|
-
vm('vm2'),
|
|
47
|
-
),
|
|
48
|
-
env('dev').with(
|
|
49
|
-
vm('vm1'),
|
|
50
|
-
instanceOf('cloud.backend.api'),
|
|
51
|
-
),
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
// Test Element View
|
|
55
|
-
.views(({ view, $include }, _) =>
|
|
56
|
-
_(
|
|
57
|
-
// rules inside
|
|
58
|
-
view('view1', $include('cloud.backend')),
|
|
59
|
-
view('view2', $include('cloud.*')),
|
|
60
|
-
)
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
it('generate valid code', async ({ expect }) => {
|
|
64
|
-
const aux = generateReactTypes(m.toLikeC4Model())
|
|
65
|
-
await expect(aux).toMatchFileSnapshot('__snapshots__/valid-code.snap')
|
|
66
|
-
})
|
|
67
|
-
})
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`generate generateViewsDataDTs 1`] = `
|
|
4
|
-
"/******************************************************************************
|
|
5
|
-
* This file was generated
|
|
6
|
-
* DO NOT EDIT MANUALLY!
|
|
7
|
-
******************************************************************************/
|
|
8
|
-
/* prettier-ignore-start */
|
|
9
|
-
/* eslint-disable */
|
|
10
|
-
|
|
11
|
-
import type { DiagramView } from 'likec4'
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export type LikeC4ViewId = 'fakeView' | '74f5364fa4b';
|
|
15
|
-
export type LikeC4Views = Record<LikeC4ViewId, DiagramView>
|
|
16
|
-
|
|
17
|
-
export declare const LikeC4Views: LikeC4Views
|
|
18
|
-
export declare function isLikeC4ViewId(value: unknown): value is LikeC4ViewId
|
|
19
|
-
|
|
20
|
-
/* prettier-ignore-end */
|
|
21
|
-
"
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
exports[`generate generateViewsDataJs 1`] = `
|
|
25
|
-
"/******************************************************************************
|
|
26
|
-
* This file was generated
|
|
27
|
-
* DO NOT EDIT MANUALLY!
|
|
28
|
-
******************************************************************************/
|
|
29
|
-
/* prettier-ignore-start */
|
|
30
|
-
/* eslint-disable */
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export const LikeC4Views = {
|
|
35
|
-
'fakeView': {edges:[{headArrow:[[294,487],[291,496],[288,487]],id:'cloud.frontend:cloud.backend',label:'requests',labelBox:{align:'left',width:62,x:295,y:459},points:[[291,406],[291,432],[291,461],[291,487]],relations:['cloud.frontend.dashboard:cloud.backend.graphql','cloud.frontend.adminPanel:cloud.backend.graphql'],source:'cloud.frontend',target:'cloud.backend'},{headArrow:[[294,701],[291,711],[288,701]],id:'cloud.backend:amazon',label:null,labelBox:null,points:[[291,641],[291,660],[291,681],[291,702]],relations:['cloud.backend.storage:amazon.s3'],source:'cloud.backend',target:'amazon'},{headArrow:[[344,257],[336,263],[338,253]],id:'support:cloud.frontend',label:null,labelBox:null,points:[[413,141],[391,176],[364,218],[342,255]],relations:['support:cloud.frontend.adminPanel'],source:'support',target:'cloud.frontend'},{headArrow:[[244,253],[246,263],[239,257]],id:'customer:cloud.frontend',label:'opens',labelBox:{align:'left',width:44,x:208,y:193},points:[[169,141],[191,176],[218,218],[241,255]],relations:['customer:cloud.frontend.dashboard'],source:'customer',target:'cloud.frontend'}],height:855,id:'fakeView',nodes:[{children:[],color:'primary',id:'amazon',parent:null,position:[165,715],relative:[165,715],shape:'rectangle',size:{height:140,width:251},title:'amazon'},{children:['cloud.backend','cloud.frontend'],color:'primary',id:'cloud',parent:null,position:[139,210],relative:[139,210],shape:'rectangle',size:{height:457,width:304},title:'cloud'},{children:[],color:'primary',id:'customer',parent:null,position:[0,0],relative:[0,0],shape:'rectangle',size:{height:140,width:251},title:'customer'},{children:[],color:'primary',id:'support',parent:null,position:[330,0],relative:[330,0],shape:'rectangle',size:{height:140,width:251},title:'support'},{children:[],color:'primary',id:'cloud.backend',parent:'cloud',position:[165,500],relative:[26,290],shape:'rectangle',size:{height:140,width:251},title:'backend'},{children:[],color:'primary',id:'cloud.frontend',parent:'cloud',position:[165,266],relative:[26,56],shape:'rectangle',size:{height:140,width:251},title:'frontend'}],autoLayout:{direction:'TB'},rules:[{exprs:[{wildcard:true}],isInclude:true}],title:'',viewOf:'cloud',width:582},
|
|
36
|
-
'74f5364fa4b': {edges:[{headArrow:[[129,456],[126,465],[123,456]],id:'system.frontend:system.backend',label:'requests',labelBox:{align:'left',width:62,x:130,y:428},points:[[126,375],[126,400],[126,429],[126,456]],relations:['671e3db5eb605d5f245f247d95925bd0953e0e4c'],source:'system.frontend',target:'system.backend'},{headArrow:[[129,221],[126,231],[123,221]],id:'client:system.frontend',label:'opens',labelBox:{align:'left',width:44,x:130,y:193},points:[[126,141],[126,166],[126,195],[126,221]],relations:['99bffdfd5c78e024393e6223cd9b19225321a5e3'],source:'client',target:'system.frontend'}],height:609,id:'74f5364fa4b',nodes:[{children:[],color:'primary',id:'client',parent:null,position:[0,0],relative:[0,0],shape:'rectangle',size:{height:140,width:251},title:'client'},{children:[],color:'primary',id:'system.backend',parent:null,position:[0,469],relative:[0,469],shape:'rectangle',size:{height:140,width:251},title:'backend'},{children:[],color:'primary',id:'system.frontend',parent:null,position:[0,235],relative:[0,235],shape:'rectangle',size:{height:140,width:251},title:'frontend'}],autoLayout:{direction:'TB'},rules:[{exprs:[{wildcard:true}],isInclude:true}],title:'frontend',viewOf:'system.frontend',width:251}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export function isLikeC4ViewId(value) {
|
|
41
|
-
return (
|
|
42
|
-
value != null &&
|
|
43
|
-
typeof value === 'string' &&
|
|
44
|
-
!!LikeC4Views[value]
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/* prettier-ignore-end */
|
|
49
|
-
"
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
|
-
exports[`generate generateViewsDataTs 1`] = `
|
|
53
|
-
"/******************************************************************************
|
|
54
|
-
* This file was generated
|
|
55
|
-
* DO NOT EDIT MANUALLY!
|
|
56
|
-
******************************************************************************/
|
|
57
|
-
/* prettier-ignore-start */
|
|
58
|
-
/* eslint-disable */
|
|
59
|
-
|
|
60
|
-
// @ts-nocheck
|
|
61
|
-
|
|
62
|
-
import type { DiagramView } from 'likec4'
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export type LikeC4ViewId = 'fakeView' | '74f5364fa4b';
|
|
66
|
-
export const LikeC4Views = {
|
|
67
|
-
'fakeView': ({edges:[{headArrow:[[294,487],[291,496],[288,487]],id:'cloud.frontend:cloud.backend',label:'requests',labelBox:{align:'left',width:62,x:295,y:459},points:[[291,406],[291,432],[291,461],[291,487]],relations:['cloud.frontend.dashboard:cloud.backend.graphql','cloud.frontend.adminPanel:cloud.backend.graphql'],source:'cloud.frontend',target:'cloud.backend'},{headArrow:[[294,701],[291,711],[288,701]],id:'cloud.backend:amazon',label:null,labelBox:null,points:[[291,641],[291,660],[291,681],[291,702]],relations:['cloud.backend.storage:amazon.s3'],source:'cloud.backend',target:'amazon'},{headArrow:[[344,257],[336,263],[338,253]],id:'support:cloud.frontend',label:null,labelBox:null,points:[[413,141],[391,176],[364,218],[342,255]],relations:['support:cloud.frontend.adminPanel'],source:'support',target:'cloud.frontend'},{headArrow:[[244,253],[246,263],[239,257]],id:'customer:cloud.frontend',label:'opens',labelBox:{align:'left',width:44,x:208,y:193},points:[[169,141],[191,176],[218,218],[241,255]],relations:['customer:cloud.frontend.dashboard'],source:'customer',target:'cloud.frontend'}],height:855,id:'fakeView',nodes:[{children:[],color:'primary',id:'amazon',parent:null,position:[165,715],relative:[165,715],shape:'rectangle',size:{height:140,width:251},title:'amazon'},{children:['cloud.backend','cloud.frontend'],color:'primary',id:'cloud',parent:null,position:[139,210],relative:[139,210],shape:'rectangle',size:{height:457,width:304},title:'cloud'},{children:[],color:'primary',id:'customer',parent:null,position:[0,0],relative:[0,0],shape:'rectangle',size:{height:140,width:251},title:'customer'},{children:[],color:'primary',id:'support',parent:null,position:[330,0],relative:[330,0],shape:'rectangle',size:{height:140,width:251},title:'support'},{children:[],color:'primary',id:'cloud.backend',parent:'cloud',position:[165,500],relative:[26,290],shape:'rectangle',size:{height:140,width:251},title:'backend'},{children:[],color:'primary',id:'cloud.frontend',parent:'cloud',position:[165,266],relative:[26,56],shape:'rectangle',size:{height:140,width:251},title:'frontend'}],autoLayout:{direction:'TB'},rules:[{exprs:[{wildcard:true}],isInclude:true}],title:'',viewOf:'cloud',width:582} as unknown) as DiagramView,
|
|
68
|
-
'74f5364fa4b': ({edges:[{headArrow:[[129,456],[126,465],[123,456]],id:'system.frontend:system.backend',label:'requests',labelBox:{align:'left',width:62,x:130,y:428},points:[[126,375],[126,400],[126,429],[126,456]],relations:['671e3db5eb605d5f245f247d95925bd0953e0e4c'],source:'system.frontend',target:'system.backend'},{headArrow:[[129,221],[126,231],[123,221]],id:'client:system.frontend',label:'opens',labelBox:{align:'left',width:44,x:130,y:193},points:[[126,141],[126,166],[126,195],[126,221]],relations:['99bffdfd5c78e024393e6223cd9b19225321a5e3'],source:'client',target:'system.frontend'}],height:609,id:'74f5364fa4b',nodes:[{children:[],color:'primary',id:'client',parent:null,position:[0,0],relative:[0,0],shape:'rectangle',size:{height:140,width:251},title:'client'},{children:[],color:'primary',id:'system.backend',parent:null,position:[0,469],relative:[0,469],shape:'rectangle',size:{height:140,width:251},title:'backend'},{children:[],color:'primary',id:'system.frontend',parent:null,position:[0,235],relative:[0,235],shape:'rectangle',size:{height:140,width:251},title:'frontend'}],autoLayout:{direction:'TB'},rules:[{exprs:[{wildcard:true}],isInclude:true}],title:'frontend',viewOf:'system.frontend',width:251} as unknown) as DiagramView
|
|
69
|
-
} as const satisfies Record<LikeC4ViewId, DiagramView>
|
|
70
|
-
|
|
71
|
-
export type LikeC4Views = typeof LikeC4Views
|
|
72
|
-
|
|
73
|
-
export function isLikeC4ViewId(value: unknown): value is LikeC4ViewId {
|
|
74
|
-
return (
|
|
75
|
-
value != null &&
|
|
76
|
-
typeof value === 'string' &&
|
|
77
|
-
!!LikeC4Views[value]
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/* prettier-ignore-end */
|
|
82
|
-
"
|
|
83
|
-
`;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest'
|
|
2
|
-
import { fakeDiagram, fakeDiagram2 } from '../__mocks__/data'
|
|
3
|
-
import { generateViewsDataDTs, generateViewsDataJs, generateViewsDataTs } from './generate-views-data'
|
|
4
|
-
|
|
5
|
-
test('generate generateViewsDataJs', () => {
|
|
6
|
-
expect(generateViewsDataJs([fakeDiagram, fakeDiagram2])).toMatchSnapshot()
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
test('generate generateViewsDataTs', () => {
|
|
10
|
-
expect(generateViewsDataTs([fakeDiagram, fakeDiagram2])).toMatchSnapshot()
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('generate generateViewsDataDTs', () => {
|
|
14
|
-
expect(generateViewsDataDTs([fakeDiagram, fakeDiagram2])).toMatchSnapshot()
|
|
15
|
-
})
|