@kapeta/local-cluster-service 0.46.0 → 0.47.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/CHANGELOG.md +14 -0
- package/dist/cjs/src/storm/codegen.js +16 -15
- package/dist/cjs/src/storm/event-parser.d.ts +4 -4
- package/dist/cjs/src/storm/event-parser.js +64 -18
- package/dist/cjs/src/storm/events.d.ts +9 -1
- package/dist/cjs/src/storm/events.js +0 -4
- package/dist/cjs/src/storm/routes.js +20 -7
- package/dist/cjs/src/storm/stormClient.js +3 -0
- package/dist/cjs/src/storm/stream.d.ts +1 -0
- package/dist/cjs/test/storm/event-parser.test.d.ts +5 -0
- package/dist/cjs/test/storm/event-parser.test.js +161 -0
- package/dist/esm/src/storm/codegen.js +16 -15
- package/dist/esm/src/storm/event-parser.d.ts +4 -4
- package/dist/esm/src/storm/event-parser.js +64 -18
- package/dist/esm/src/storm/events.d.ts +9 -1
- package/dist/esm/src/storm/events.js +0 -4
- package/dist/esm/src/storm/routes.js +20 -7
- package/dist/esm/src/storm/stormClient.js +3 -0
- package/dist/esm/src/storm/stream.d.ts +1 -0
- package/dist/esm/test/storm/event-parser.test.d.ts +5 -0
- package/dist/esm/test/storm/event-parser.test.js +161 -0
- package/package.json +3 -1
- package/src/storm/codegen.ts +23 -14
- package/src/storm/event-parser.ts +107 -28
- package/src/storm/events.ts +11 -1
- package/src/storm/routes.ts +33 -19
- package/src/storm/stormClient.ts +4 -0
- package/src/storm/stream.ts +1 -0
- package/test/storm/event-parser.test.ts +182 -0
@@ -0,0 +1,182 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright 2023 Kapeta Inc.
|
3
|
+
* SPDX-License-Identifier: BUSL-1.1
|
4
|
+
*/
|
5
|
+
|
6
|
+
import { StormEventParser } from '../../src/storm/event-parser';
|
7
|
+
import { StormEvent } from '../../src/storm/events';
|
8
|
+
|
9
|
+
const parserOptions = {
|
10
|
+
serviceKind: 'kapeta/block-service:local',
|
11
|
+
serviceLanguage: 'kapeta/language-target-nodejs-ts:local',
|
12
|
+
|
13
|
+
frontendKind: 'kapeta/block-type-frontend:local',
|
14
|
+
frontendLanguage: 'kapeta/language-target-react-ts:local',
|
15
|
+
|
16
|
+
cliKind: 'kapeta/block-type-cli:local',
|
17
|
+
cliLanguage: 'kapeta/language-target-nodejs-ts:local',
|
18
|
+
|
19
|
+
desktopKind: 'kapeta/block-type-desktop:local',
|
20
|
+
desktopLanguage: 'kapeta/language-target-electron-ts:local',
|
21
|
+
|
22
|
+
gatewayKind: 'kapeta/block-type-gateway:local',
|
23
|
+
|
24
|
+
mqKind: 'kapeta/block-type-mq:local',
|
25
|
+
exchangeKind: 'kapeta/resource-type-exchange:local',
|
26
|
+
queueKind: 'kapeta/resource-type-queue:local',
|
27
|
+
publisherKind: 'kapeta/resource-type-publisher:local',
|
28
|
+
subscriberKind: 'kapeta/resource-type-subscriber:local',
|
29
|
+
databaseKind: 'kapeta/block-type-database:local',
|
30
|
+
|
31
|
+
apiKind: 'kapeta/block-type-api:local',
|
32
|
+
clientKind: 'kapeta/block-type-client:local',
|
33
|
+
|
34
|
+
webPageKind: 'kapeta/block-type-web-page:local',
|
35
|
+
webFragmentKind: 'kapeta/block-type-web-fragment:local',
|
36
|
+
|
37
|
+
jwtProviderKind: 'kapeta/resource-type-jwt-provider:local',
|
38
|
+
jwtConsumerKind: 'kapeta/resource-type-jwt-consumer:local',
|
39
|
+
|
40
|
+
smtpKind: 'kapeta/resource-type-smtp:local',
|
41
|
+
externalApiKind: 'kapeta/resource-type-external-api:local',
|
42
|
+
};
|
43
|
+
|
44
|
+
const events: StormEvent[] = [
|
45
|
+
{
|
46
|
+
type: 'CREATE_PLAN_PROPERTIES',
|
47
|
+
created: Date.now(),
|
48
|
+
reason: 'create plan properties',
|
49
|
+
payload: {
|
50
|
+
name: 'my-plan',
|
51
|
+
description: 'my plan description',
|
52
|
+
},
|
53
|
+
},
|
54
|
+
{
|
55
|
+
type: 'CREATE_BLOCK',
|
56
|
+
reason: 'create backend',
|
57
|
+
created: Date.now(),
|
58
|
+
payload: {
|
59
|
+
name: 'service',
|
60
|
+
description: 'A service block',
|
61
|
+
type: 'BACKEND',
|
62
|
+
resources: [
|
63
|
+
{
|
64
|
+
name: 'entities',
|
65
|
+
type: 'DATABASE',
|
66
|
+
description: 'A database resource',
|
67
|
+
},
|
68
|
+
{
|
69
|
+
type: 'API',
|
70
|
+
name: 'entities',
|
71
|
+
description: 'An API resource',
|
72
|
+
},
|
73
|
+
],
|
74
|
+
},
|
75
|
+
},
|
76
|
+
{
|
77
|
+
type: 'CREATE_BLOCK',
|
78
|
+
reason: 'create frontend',
|
79
|
+
created: Date.now(),
|
80
|
+
payload: {
|
81
|
+
name: 'ui',
|
82
|
+
description: 'A frontend block',
|
83
|
+
type: 'FRONTEND',
|
84
|
+
resources: [
|
85
|
+
{
|
86
|
+
name: 'web',
|
87
|
+
type: 'WEBPAGE',
|
88
|
+
description: 'A web page',
|
89
|
+
},
|
90
|
+
{
|
91
|
+
type: 'CLIENT',
|
92
|
+
name: 'entities',
|
93
|
+
description: 'Client for backend',
|
94
|
+
},
|
95
|
+
],
|
96
|
+
},
|
97
|
+
},
|
98
|
+
{
|
99
|
+
type: 'CREATE_CONNECTION',
|
100
|
+
created: Date.now(),
|
101
|
+
reason: 'connect service to ui',
|
102
|
+
payload: {
|
103
|
+
fromComponent: 'service',
|
104
|
+
fromResource: 'entities',
|
105
|
+
fromResourceType: 'API',
|
106
|
+
toComponent: 'ui',
|
107
|
+
toResource: 'entities',
|
108
|
+
toResourceType: 'CLIENT',
|
109
|
+
},
|
110
|
+
},
|
111
|
+
{
|
112
|
+
type: 'CREATE_API',
|
113
|
+
reason: 'create api',
|
114
|
+
created: Date.now(),
|
115
|
+
payload: {
|
116
|
+
blockName: 'service',
|
117
|
+
content: `controller Entities('/entities') {
|
118
|
+
@GET('/')
|
119
|
+
list(): string[]
|
120
|
+
}`,
|
121
|
+
},
|
122
|
+
},
|
123
|
+
{
|
124
|
+
type: 'CREATE_MODEL',
|
125
|
+
created: Date.now(),
|
126
|
+
reason: 'create model',
|
127
|
+
payload: {
|
128
|
+
blockName: 'service',
|
129
|
+
content: `type Entity {
|
130
|
+
@Id
|
131
|
+
id: string
|
132
|
+
|
133
|
+
name: string
|
134
|
+
}`,
|
135
|
+
},
|
136
|
+
},
|
137
|
+
];
|
138
|
+
|
139
|
+
describe('event-parser', () => {
|
140
|
+
it('it can parse events into a plan and blocks with proper layout', () => {
|
141
|
+
const parser = new StormEventParser(parserOptions);
|
142
|
+
events.forEach((event) => parser.addEvent('kapeta', event));
|
143
|
+
|
144
|
+
const result = parser.toResult('kapeta');
|
145
|
+
|
146
|
+
expect(result.plan.metadata.name).toBe('kapeta/my-plan');
|
147
|
+
expect(result.plan.metadata.description).toBe('my plan description');
|
148
|
+
expect(result.blocks.length).toBe(2);
|
149
|
+
expect(result.blocks[0].content.metadata.name).toBe('kapeta/service');
|
150
|
+
expect(result.blocks[1].content.metadata.name).toBe('kapeta/ui');
|
151
|
+
|
152
|
+
const dbResource = result.blocks[0].content.spec.consumers?.[0];
|
153
|
+
const apiResource = result.blocks[0].content.spec.providers?.[0];
|
154
|
+
const clientResource = result.blocks[1].content.spec.consumers?.[0];
|
155
|
+
const pageResource = result.blocks[1].content.spec.providers?.[0];
|
156
|
+
|
157
|
+
expect(apiResource).toBeDefined();
|
158
|
+
expect(clientResource).toBeDefined();
|
159
|
+
expect(dbResource).toBeDefined();
|
160
|
+
expect(pageResource).toBeDefined();
|
161
|
+
|
162
|
+
expect(apiResource?.kind).toBe(parserOptions.apiKind);
|
163
|
+
expect(clientResource?.kind).toBe(parserOptions.clientKind);
|
164
|
+
expect(dbResource?.kind).toBe(parserOptions.databaseKind);
|
165
|
+
expect(pageResource?.kind).toBe(parserOptions.webPageKind);
|
166
|
+
|
167
|
+
expect(apiResource?.spec).toEqual(clientResource?.spec);
|
168
|
+
expect(dbResource?.spec.source.value).toContain('type Entity');
|
169
|
+
|
170
|
+
const serviceBlockInstance = result.plan.spec.blocks[0];
|
171
|
+
expect(serviceBlockInstance.name).toBe('service');
|
172
|
+
|
173
|
+
const uiBlockInstance = result.plan.spec.blocks[1];
|
174
|
+
expect(uiBlockInstance.name).toBe('ui');
|
175
|
+
|
176
|
+
expect(result.plan.spec.connections.length).toBe(1);
|
177
|
+
expect(result.plan.spec.connections[0].consumer.blockId).toBe(uiBlockInstance.id);
|
178
|
+
expect(result.plan.spec.connections[0].consumer.resourceName).toBe(clientResource?.metadata.name);
|
179
|
+
expect(result.plan.spec.connections[0].provider.blockId).toBe(serviceBlockInstance.id);
|
180
|
+
expect(result.plan.spec.connections[0].provider.resourceName).toBe(apiResource?.metadata.name);
|
181
|
+
});
|
182
|
+
});
|