@kapeta/local-cluster-service 0.43.3 → 0.45.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 (63) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/index.js +2 -0
  3. package/dist/cjs/src/codeGeneratorManager.d.ts +1 -0
  4. package/dist/cjs/src/codeGeneratorManager.js +12 -6
  5. package/dist/cjs/src/middleware/cors.d.ts +1 -0
  6. package/dist/cjs/src/middleware/kapeta.d.ts +1 -0
  7. package/dist/cjs/src/middleware/stringBody.d.ts +1 -0
  8. package/dist/cjs/src/proxy/routes.js +19 -19
  9. package/dist/cjs/src/proxy/types/rest.d.ts +2 -4
  10. package/dist/cjs/src/proxy/types/rest.js +45 -6
  11. package/dist/cjs/src/proxy/types/web.d.ts +2 -4
  12. package/dist/cjs/src/proxy/types/web.js +2 -2
  13. package/dist/cjs/src/storm/codegen.d.ts +36 -0
  14. package/dist/cjs/src/storm/codegen.js +160 -0
  15. package/dist/cjs/src/storm/event-parser.d.ts +70 -0
  16. package/dist/cjs/src/storm/event-parser.js +543 -0
  17. package/dist/cjs/src/storm/events.d.ts +127 -0
  18. package/dist/cjs/src/storm/events.js +6 -0
  19. package/dist/cjs/src/storm/routes.d.ts +7 -0
  20. package/dist/cjs/src/storm/routes.js +109 -0
  21. package/dist/cjs/src/storm/stormClient.d.ts +13 -0
  22. package/dist/cjs/src/storm/stormClient.js +87 -0
  23. package/dist/cjs/src/storm/stream.d.ts +38 -0
  24. package/dist/cjs/src/storm/stream.js +57 -0
  25. package/dist/cjs/src/types.d.ts +5 -2
  26. package/dist/esm/index.js +2 -0
  27. package/dist/esm/src/codeGeneratorManager.d.ts +1 -0
  28. package/dist/esm/src/codeGeneratorManager.js +12 -6
  29. package/dist/esm/src/middleware/cors.d.ts +1 -0
  30. package/dist/esm/src/middleware/kapeta.d.ts +1 -0
  31. package/dist/esm/src/middleware/stringBody.d.ts +1 -0
  32. package/dist/esm/src/proxy/routes.js +19 -19
  33. package/dist/esm/src/proxy/types/rest.d.ts +2 -4
  34. package/dist/esm/src/proxy/types/rest.js +45 -6
  35. package/dist/esm/src/proxy/types/web.d.ts +2 -4
  36. package/dist/esm/src/proxy/types/web.js +2 -2
  37. package/dist/esm/src/storm/codegen.d.ts +36 -0
  38. package/dist/esm/src/storm/codegen.js +160 -0
  39. package/dist/esm/src/storm/event-parser.d.ts +70 -0
  40. package/dist/esm/src/storm/event-parser.js +543 -0
  41. package/dist/esm/src/storm/events.d.ts +127 -0
  42. package/dist/esm/src/storm/events.js +6 -0
  43. package/dist/esm/src/storm/routes.d.ts +7 -0
  44. package/dist/esm/src/storm/routes.js +109 -0
  45. package/dist/esm/src/storm/stormClient.d.ts +13 -0
  46. package/dist/esm/src/storm/stormClient.js +87 -0
  47. package/dist/esm/src/storm/stream.d.ts +38 -0
  48. package/dist/esm/src/storm/stream.js +57 -0
  49. package/dist/esm/src/types.d.ts +5 -2
  50. package/index.ts +2 -0
  51. package/package.json +6 -3
  52. package/src/codeGeneratorManager.ts +17 -8
  53. package/src/proxy/routes.ts +26 -20
  54. package/src/proxy/types/rest.ts +73 -11
  55. package/src/proxy/types/web.ts +3 -5
  56. package/src/storm/codegen.ts +210 -0
  57. package/src/storm/event-parser.ts +688 -0
  58. package/src/storm/events.ts +169 -0
  59. package/src/storm/routes.ts +143 -0
  60. package/src/storm/stormClient.ts +114 -0
  61. package/src/storm/stream.ts +88 -0
  62. package/src/types.ts +5 -2
  63. package/src/utils/BlockInstanceRunner.ts +4 -2
@@ -0,0 +1,543 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2023 Kapeta Inc.
4
+ * SPDX-License-Identifier: BUSL-1.1
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.StormEventParser = exports.resolveOptions = void 0;
11
+ const nodejs_utils_1 = require("@kapeta/nodejs-utils");
12
+ const kaplang_core_1 = require("@kapeta/kaplang-core");
13
+ const node_uuid_1 = __importDefault(require("node-uuid"));
14
+ const definitionsManager_1 = require("../definitionsManager");
15
+ async function resolveOptions() {
16
+ // Predefined types for now - TODO: Allow user to select / change
17
+ const blockTypeService = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/block-type-service');
18
+ const blockTypeFrontend = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/block-type-frontend');
19
+ const blockTypeDesktop = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/block-type-desktop');
20
+ const blockTypeCli = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/block-type-cli');
21
+ const blockTypeGateway = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/block-type-gateway-http');
22
+ const postgresResource = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-postgresql');
23
+ const webPageResource = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-web-page');
24
+ const webFragmentResource = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-web-fragment');
25
+ const restApiResource = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-rest-api');
26
+ const restClientResource = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-rest-client');
27
+ const javaLanguage = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/language-target-java-spring-boot');
28
+ const reactLanguage = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/language-target-react-ts');
29
+ const nodejsLanguage = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/language-target-nodejs');
30
+ const blockTypePubsub = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/block-type-pubsub');
31
+ const resourceTypePubsubSubscriber = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-pubsub-subscriber');
32
+ const resourceTypePubsubSubscription = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-pubsub-subscription');
33
+ const resourceTypePubsubTopic = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-pubsub-topic');
34
+ const resourceTypePubsubPublisher = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-pubsub-publisher');
35
+ const jwtProvider = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-auth-jwt-provider');
36
+ const jwtConsumer = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-auth-jwt-consumer');
37
+ const smtpClient = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-smtp-client');
38
+ const externalService = await definitionsManager_1.definitionsManager.getLatestDefinition('kapeta/resource-type-external-services');
39
+ if (!blockTypeService ||
40
+ !blockTypeFrontend ||
41
+ !blockTypeDesktop ||
42
+ !blockTypeGateway ||
43
+ !postgresResource ||
44
+ !javaLanguage ||
45
+ !reactLanguage ||
46
+ !webPageResource ||
47
+ !restApiResource ||
48
+ !restClientResource ||
49
+ !webFragmentResource ||
50
+ !blockTypePubsub ||
51
+ !resourceTypePubsubSubscriber ||
52
+ !resourceTypePubsubSubscription ||
53
+ !resourceTypePubsubTopic ||
54
+ !resourceTypePubsubPublisher ||
55
+ !jwtProvider ||
56
+ !jwtConsumer ||
57
+ !smtpClient ||
58
+ !externalService ||
59
+ !blockTypeCli ||
60
+ !nodejsLanguage) {
61
+ throw new Error('Missing definitions');
62
+ }
63
+ return {
64
+ serviceKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${blockTypeService.definition.metadata.name}:${blockTypeService.version}`),
65
+ serviceLanguage: (0, nodejs_utils_1.normalizeKapetaUri)('kapeta/language-target-java-spring-boot:local'), //normalizeKapetaUri(`${javaLanguage.definition.metadata.name}:${javaLanguage.version}`),
66
+ frontendKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${blockTypeFrontend.definition.metadata.name}:${blockTypeFrontend.version}`),
67
+ frontendLanguage: (0, nodejs_utils_1.normalizeKapetaUri)('kapeta/language-target-react-ts:local'), // normalizeKapetaUri(`${reactLanguage.definition.metadata.name}:${reactLanguage.version}`),
68
+ cliKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${blockTypeCli.definition.metadata.name}:${blockTypeCli.version}`),
69
+ cliLanguage: (0, nodejs_utils_1.normalizeKapetaUri)(`${nodejsLanguage.definition.metadata.name}:${nodejsLanguage.version}`),
70
+ desktopKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${blockTypeDesktop.definition.metadata.name}:${blockTypeDesktop.version}`),
71
+ desktopLanguage: (0, nodejs_utils_1.normalizeKapetaUri)(`${reactLanguage.definition.metadata.name}:${reactLanguage.version}`),
72
+ gatewayKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${blockTypeGateway.definition.metadata.name}:${blockTypeGateway.version}`),
73
+ mqKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${blockTypePubsub.definition.metadata.name}:${blockTypePubsub.version}`),
74
+ exchangeKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${resourceTypePubsubTopic.definition.metadata.name}:${resourceTypePubsubTopic.version}`),
75
+ queueKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${resourceTypePubsubSubscription.definition.metadata.name}:${resourceTypePubsubSubscription.version}`),
76
+ publisherKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${resourceTypePubsubPublisher.definition.metadata.name}:${resourceTypePubsubPublisher.version}`),
77
+ subscriberKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${resourceTypePubsubSubscriber.definition.metadata.name}:${resourceTypePubsubSubscriber.version}`),
78
+ databaseKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${postgresResource.definition.metadata.name}:${postgresResource.version}`),
79
+ apiKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${restApiResource.definition.metadata.name}:${restApiResource.version}`),
80
+ clientKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${restClientResource.definition.metadata.name}:${restClientResource.version}`),
81
+ webPageKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${webPageResource.definition.metadata.name}:${webPageResource.version}`),
82
+ webFragmentKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${webFragmentResource.definition.metadata.name}:${webFragmentResource.version}`),
83
+ jwtProviderKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${jwtProvider.definition.metadata.name}:${jwtProvider.version}`),
84
+ jwtConsumerKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${jwtConsumer.definition.metadata.name}:${jwtConsumer.version}`),
85
+ smtpKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${smtpClient.definition.metadata.name}:${smtpClient.version}`),
86
+ externalApiKind: (0, nodejs_utils_1.normalizeKapetaUri)(`${externalService.definition.metadata.name}:${externalService.version}`),
87
+ };
88
+ }
89
+ exports.resolveOptions = resolveOptions;
90
+ class StormEventParser {
91
+ events = [];
92
+ planName = '';
93
+ planDescription = '';
94
+ blocks = {};
95
+ connections = [];
96
+ failed = false;
97
+ error = '';
98
+ options;
99
+ constructor(options) {
100
+ this.options = options;
101
+ }
102
+ reset() {
103
+ this.planDescription = '';
104
+ this.planName = '';
105
+ this.blocks = {};
106
+ this.connections = [];
107
+ }
108
+ addEvent(evt) {
109
+ console.log('Processing storm event', evt);
110
+ this.events.push(evt);
111
+ switch (evt.type) {
112
+ case 'CREATE_PLAN_PROPERTIES':
113
+ this.planName = evt.payload.name;
114
+ this.planDescription = evt.payload.description;
115
+ break;
116
+ case 'CREATE_BLOCK':
117
+ this.blocks[evt.payload.name] = {
118
+ ...evt.payload,
119
+ apis: [],
120
+ models: [],
121
+ types: [],
122
+ screens: [],
123
+ };
124
+ break;
125
+ case 'PLAN_RETRY':
126
+ this.reset();
127
+ break;
128
+ case 'PLAN_RETRY_FAILED':
129
+ this.failed = true;
130
+ this.error = evt.payload.error;
131
+ break;
132
+ case 'CREATE_API':
133
+ this.blocks[evt.payload.blockName].apis.push(evt.payload.content);
134
+ break;
135
+ case 'CREATE_TYPE':
136
+ this.blocks[evt.payload.blockName].types.push(evt.payload.content);
137
+ break;
138
+ case 'CREATE_MODEL':
139
+ this.blocks[evt.payload.blockName].models.push(evt.payload.content);
140
+ break;
141
+ case 'CREATE_CONNECTION':
142
+ this.connections.push(evt.payload);
143
+ break;
144
+ case 'SCREEN':
145
+ this.blocks[evt.payload.blockName].screens.push({
146
+ name: evt.payload.name,
147
+ description: evt.payload.description,
148
+ url: evt.payload.url,
149
+ template: evt.payload.template,
150
+ });
151
+ break;
152
+ default:
153
+ case 'SCREEN_CANDIDATE':
154
+ case 'FILE':
155
+ console.warn('Unhandled event: %s', evt.type, evt);
156
+ break;
157
+ }
158
+ }
159
+ getEvents() {
160
+ return this.events;
161
+ }
162
+ isValid() {
163
+ return !this.failed;
164
+ }
165
+ getError() {
166
+ return this.error;
167
+ }
168
+ applyLayoutToBlocks(result) {
169
+ return result;
170
+ }
171
+ toResult(handle) {
172
+ const planRef = this.toRef(handle, this.planName);
173
+ const blockDefinitions = this.toBlockDefinitions(handle);
174
+ const refIdMap = {};
175
+ const screens = {};
176
+ const blocks = Object.entries(blockDefinitions).map(([ref, block]) => {
177
+ const id = node_uuid_1.default.v4();
178
+ refIdMap[ref] = id;
179
+ return {
180
+ id,
181
+ block: {
182
+ ref,
183
+ },
184
+ name: block.content.metadata.title ?? block.content.metadata.name,
185
+ dimensions: {
186
+ left: 0,
187
+ top: 0,
188
+ width: 200,
189
+ height: 200,
190
+ },
191
+ };
192
+ });
193
+ Object.values(this.blocks).forEach((blockInfo) => {
194
+ const blockRef = this.toRef(handle, blockInfo.name);
195
+ const block = blockDefinitions[blockRef.toNormalizedString()];
196
+ if (!block) {
197
+ console.warn('Block not found: %s', blockInfo.name);
198
+ return;
199
+ }
200
+ screens[blockRef.fullName] = blockInfo.screens;
201
+ });
202
+ // Copy API methods from API provider to CLIENT consumer
203
+ this.connections
204
+ .filter((connection) => connection.fromResourceType === 'API' && connection.toResourceType === 'CLIENT')
205
+ .forEach((apiConnection) => {
206
+ const apiProviderRef = this.toRef(handle, apiConnection.fromComponent);
207
+ const clientConsumerRef = this.toRef(handle, apiConnection.toComponent);
208
+ const apiProviderBlock = blockDefinitions[apiProviderRef.toNormalizedString()];
209
+ if (!apiProviderBlock) {
210
+ console.warn('API provider not found: %s', apiConnection.fromComponent);
211
+ return;
212
+ }
213
+ const clientConsumerBlock = blockDefinitions[clientConsumerRef.toNormalizedString()];
214
+ if (!clientConsumerBlock) {
215
+ console.warn('Client consumer not found: %s', apiConnection.toComponent);
216
+ return;
217
+ }
218
+ const apiResource = apiProviderBlock.content.spec.providers?.find((p) => p.kind === this.options.apiKind && p.metadata.name === apiConnection.fromResource);
219
+ if (!apiResource) {
220
+ console.warn('API resource not found: %s on %s', apiConnection.fromResource, apiProviderRef.toNormalizedString());
221
+ return;
222
+ }
223
+ const clientResource = clientConsumerBlock.content.spec.consumers?.find((clientResource) => {
224
+ if (clientResource.kind !== this.options.clientKind) {
225
+ return;
226
+ }
227
+ if (clientResource.metadata.name !== apiConnection.toResource) {
228
+ return;
229
+ }
230
+ });
231
+ if (!clientResource) {
232
+ console.warn('Client resource not found: %s on %s', apiConnection.toResource, clientConsumerRef.toNormalizedString());
233
+ return;
234
+ }
235
+ clientResource.spec.methods = apiResource.spec.methods;
236
+ clientResource.spec.source = apiResource.spec.source;
237
+ });
238
+ const connections = this.connections.map((connection) => {
239
+ const fromRef = this.toRef(handle, connection.fromComponent);
240
+ const toRef = this.toRef(handle, connection.toComponent);
241
+ return {
242
+ port: {
243
+ type: this.toPortType(connection.fromResourceType),
244
+ },
245
+ consumer: {
246
+ blockId: refIdMap[toRef.toNormalizedString()],
247
+ resourceName: connection.toResource,
248
+ },
249
+ provider: {
250
+ blockId: refIdMap[fromRef.toNormalizedString()],
251
+ resourceName: connection.fromResource,
252
+ },
253
+ mapping: {
254
+ //TODO: Add mapping
255
+ },
256
+ };
257
+ });
258
+ const plan = {
259
+ kind: 'core/plan',
260
+ metadata: {
261
+ name: planRef.fullName,
262
+ title: this.planName,
263
+ description: this.planDescription,
264
+ },
265
+ spec: {
266
+ blocks,
267
+ connections,
268
+ },
269
+ };
270
+ return this.applyLayoutToBlocks({
271
+ plan,
272
+ blocks: Object.values(blockDefinitions),
273
+ });
274
+ }
275
+ toSafeName(name) {
276
+ return name.toLowerCase().replace(/[^0-9a-z-]/gi, '');
277
+ }
278
+ toRef(handle, name) {
279
+ return (0, nodejs_utils_1.parseKapetaUri)(handle + '/' + this.toSafeName(name) + ':local');
280
+ }
281
+ toBlockDefinitions(handle) {
282
+ const result = {};
283
+ Object.entries(this.blocks).forEach(([, blockInfo]) => {
284
+ const blockRef = this.toRef(handle, blockInfo.name);
285
+ const blockDefinitionInfo = {
286
+ uri: blockRef,
287
+ content: {
288
+ kind: this.toBlockKind(blockInfo.type),
289
+ metadata: {
290
+ title: blockInfo.name,
291
+ name: blockRef.fullName,
292
+ description: blockInfo.description,
293
+ },
294
+ spec: {
295
+ entities: {
296
+ types: [],
297
+ source: {
298
+ type: kaplang_core_1.KAPLANG_ID,
299
+ version: kaplang_core_1.KAPLANG_VERSION,
300
+ value: '',
301
+ },
302
+ },
303
+ target: this.toBlockTarget(handle, blockInfo.type),
304
+ providers: [],
305
+ consumers: [],
306
+ },
307
+ },
308
+ screens: blockInfo.screens,
309
+ };
310
+ const blockSpec = blockDefinitionInfo.content.spec;
311
+ let apiResource = undefined;
312
+ let dbResource = undefined;
313
+ blockInfo.resources.forEach((resource) => {
314
+ const port = {
315
+ type: this.toPortType(resource.type),
316
+ };
317
+ switch (resource.type) {
318
+ case 'API':
319
+ if (apiResource) {
320
+ break;
321
+ }
322
+ apiResource = {
323
+ kind: this.toResourceKind(resource.type),
324
+ metadata: {
325
+ name: resource.name,
326
+ description: resource.description,
327
+ },
328
+ spec: {
329
+ port,
330
+ methods: {},
331
+ source: {
332
+ type: kaplang_core_1.KAPLANG_ID,
333
+ version: kaplang_core_1.KAPLANG_VERSION,
334
+ value: '',
335
+ },
336
+ },
337
+ };
338
+ blockSpec.providers.push(apiResource);
339
+ break;
340
+ case 'CLIENT':
341
+ blockSpec.consumers.push({
342
+ kind: this.toResourceKind(resource.type),
343
+ metadata: {
344
+ name: resource.name,
345
+ description: resource.description,
346
+ },
347
+ spec: {
348
+ port,
349
+ methods: {},
350
+ source: {
351
+ type: kaplang_core_1.KAPLANG_ID,
352
+ version: kaplang_core_1.KAPLANG_VERSION,
353
+ value: '',
354
+ },
355
+ },
356
+ });
357
+ break;
358
+ case 'EXTERNAL_API':
359
+ break;
360
+ case 'EXCHANGE':
361
+ break;
362
+ case 'PUBLISHER':
363
+ break;
364
+ case 'QUEUE':
365
+ break;
366
+ case 'SUBSCRIBER':
367
+ break;
368
+ case 'JWTPROVIDER':
369
+ case 'WEBPAGE':
370
+ blockSpec.providers.push({
371
+ kind: this.toResourceKind(resource.type),
372
+ metadata: {
373
+ name: resource.name,
374
+ description: resource.description,
375
+ },
376
+ spec: {
377
+ port,
378
+ },
379
+ });
380
+ break;
381
+ case 'DATABASE':
382
+ if (dbResource) {
383
+ break;
384
+ }
385
+ dbResource = {
386
+ kind: this.toResourceKind(resource.type),
387
+ metadata: {
388
+ name: resource.name,
389
+ description: resource.description,
390
+ },
391
+ spec: {
392
+ port,
393
+ models: [],
394
+ source: {
395
+ type: kaplang_core_1.KAPLANG_ID,
396
+ version: kaplang_core_1.KAPLANG_VERSION,
397
+ value: '',
398
+ },
399
+ },
400
+ };
401
+ blockSpec.providers.push(dbResource);
402
+ break;
403
+ case 'JWTCONSUMER':
404
+ case 'WEBFRAGMENT':
405
+ case 'SMTPCLIENT':
406
+ blockSpec.consumers.push({
407
+ kind: this.toResourceKind(resource.type),
408
+ metadata: {
409
+ name: resource.name,
410
+ description: resource.description,
411
+ },
412
+ spec: {
413
+ port,
414
+ },
415
+ });
416
+ }
417
+ });
418
+ if (apiResource) {
419
+ blockInfo.apis.forEach((api) => {
420
+ apiResource.spec.source.value += api + '\n\n';
421
+ });
422
+ }
423
+ blockInfo.types.forEach((type) => {
424
+ blockSpec.entities.source.value += type + '\n';
425
+ });
426
+ if (dbResource) {
427
+ blockInfo.models.forEach((model) => {
428
+ dbResource.spec.source.value += model + '\n';
429
+ });
430
+ }
431
+ result[blockRef.toNormalizedString()] = blockDefinitionInfo;
432
+ });
433
+ return result;
434
+ }
435
+ toResourceKind(type) {
436
+ //TODO: Handle support for multiple resource types and versions
437
+ switch (type) {
438
+ case 'API':
439
+ return this.options.apiKind;
440
+ case 'CLIENT':
441
+ return this.options.clientKind;
442
+ case 'DATABASE':
443
+ return this.options.databaseKind;
444
+ case 'JWTPROVIDER':
445
+ return this.options.jwtProviderKind;
446
+ case 'JWTCONSUMER':
447
+ return this.options.jwtConsumerKind;
448
+ case 'WEBFRAGMENT':
449
+ return this.options.webFragmentKind;
450
+ case 'WEBPAGE':
451
+ return this.options.webPageKind;
452
+ case 'SMTPCLIENT':
453
+ return this.options.smtpKind;
454
+ case 'EXTERNAL_API':
455
+ return this.options.externalApiKind;
456
+ case 'SUBSCRIBER':
457
+ return this.options.subscriberKind;
458
+ case 'PUBLISHER':
459
+ return this.options.publisherKind;
460
+ case 'QUEUE':
461
+ return this.options.queueKind;
462
+ case 'EXCHANGE':
463
+ return this.options.exchangeKind;
464
+ }
465
+ return '';
466
+ }
467
+ toBlockKind(type) {
468
+ switch (type) {
469
+ case 'BACKEND':
470
+ return this.options.serviceKind;
471
+ case 'FRONTEND':
472
+ return this.options.frontendKind;
473
+ case 'CLI':
474
+ return this.options.cliKind;
475
+ case 'DESKTOP':
476
+ return this.options.desktopKind;
477
+ case 'GATEWAY':
478
+ return this.options.gatewayKind;
479
+ case 'MQ':
480
+ return this.options.mqKind;
481
+ }
482
+ return '';
483
+ }
484
+ toPortType(type) {
485
+ switch (type) {
486
+ case 'API':
487
+ case 'CLIENT':
488
+ return 'rest';
489
+ case 'JWTPROVIDER':
490
+ case 'JWTCONSUMER':
491
+ return 'http';
492
+ case 'WEBFRAGMENT':
493
+ case 'WEBPAGE':
494
+ return 'web';
495
+ case 'SUBSCRIBER':
496
+ case 'PUBLISHER':
497
+ case 'QUEUE':
498
+ case 'EXCHANGE':
499
+ // PubSub uses http. TODO: Handle support for multiple MQ types
500
+ return 'http';
501
+ case 'SMTPCLIENT':
502
+ return 'smtp';
503
+ case 'DATABASE':
504
+ //TODO: Handle support for multiple DB types
505
+ return 'postgres';
506
+ }
507
+ return 'http';
508
+ }
509
+ toBlockTarget(handle, type) {
510
+ const kind = this.toBlockTargetKind(type);
511
+ if (!kind) {
512
+ return undefined;
513
+ }
514
+ let options = {};
515
+ if (kind.includes('java')) {
516
+ const groupId = `ai.${this.toSafeName(handle)}`;
517
+ const artifactId = this.toSafeName(this.planName);
518
+ options = {
519
+ groupId,
520
+ artifactId,
521
+ basePackage: `${groupId}.${artifactId}`,
522
+ };
523
+ }
524
+ return {
525
+ kind,
526
+ options,
527
+ };
528
+ }
529
+ toBlockTargetKind(type) {
530
+ switch (type) {
531
+ case 'BACKEND':
532
+ return this.options.serviceLanguage;
533
+ case 'CLI':
534
+ return this.options.cliLanguage;
535
+ case 'FRONTEND':
536
+ return this.options.frontendLanguage;
537
+ case 'DESKTOP':
538
+ return this.options.desktopLanguage;
539
+ }
540
+ return undefined;
541
+ }
542
+ }
543
+ exports.StormEventParser = StormEventParser;
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Copyright 2023 Kapeta Inc.
3
+ * SPDX-License-Identifier: BUSL-1.1
4
+ */
5
+ export type StormResourceType = 'API' | 'DATABASE' | 'CLIENT' | 'JWTPROVIDER' | 'JWTCONSUMER' | 'WEBFRAGMENT' | 'WEBPAGE' | 'SMTPCLIENT' | 'EXTERNAL_API' | 'SUBSCRIBER' | 'PUBLISHER' | 'QUEUE' | 'EXCHANGE';
6
+ export type StormBlockType = 'BACKEND' | 'FRONTEND' | 'GATEWAY' | 'MQ' | 'CLI' | 'DESKTOP';
7
+ export interface StormBlockInfo {
8
+ type: StormBlockType;
9
+ name: string;
10
+ description: string;
11
+ resources: {
12
+ type: StormResourceType;
13
+ name: string;
14
+ description: string;
15
+ }[];
16
+ }
17
+ export interface StormBlockInfoFilled extends StormBlockInfo {
18
+ apis: string[];
19
+ types: string[];
20
+ models: string[];
21
+ screens: ScreenTemplate[];
22
+ }
23
+ export interface StormEventCreateBlock {
24
+ type: 'CREATE_BLOCK';
25
+ reason: string;
26
+ created: number;
27
+ payload: StormBlockInfo;
28
+ }
29
+ export interface StormConnection {
30
+ fromComponent: string;
31
+ fromResource: string;
32
+ fromResourceType: StormResourceType;
33
+ toComponent: string;
34
+ toResource: string;
35
+ toResourceType: StormResourceType;
36
+ }
37
+ export interface StormEventCreateConnection {
38
+ type: 'CREATE_CONNECTION';
39
+ reason: string;
40
+ created: number;
41
+ payload: StormConnection;
42
+ }
43
+ export interface StormEventCreatePlanProperties {
44
+ type: 'CREATE_PLAN_PROPERTIES';
45
+ reason: string;
46
+ created: number;
47
+ payload: {
48
+ name: string;
49
+ description: string;
50
+ };
51
+ }
52
+ export interface StormEventInvalidResponse {
53
+ type: 'INVALID_RESPONSE';
54
+ reason: string;
55
+ created: number;
56
+ payload: {
57
+ error: string;
58
+ };
59
+ }
60
+ export interface StormEventPlanRetry {
61
+ type: 'PLAN_RETRY' | 'PLAN_RETRY_FAILED';
62
+ reason: string;
63
+ created: number;
64
+ payload: {
65
+ error: string;
66
+ };
67
+ }
68
+ export interface StormEventCreateDSL {
69
+ type: 'CREATE_API' | 'CREATE_TYPE' | 'CREATE_MODEL';
70
+ reason: string;
71
+ created: number;
72
+ payload: {
73
+ blockName: string;
74
+ content: string;
75
+ };
76
+ }
77
+ export interface StormEventError {
78
+ type: 'INVALID_RESPONSE' | 'ERROR_INTERNAL';
79
+ reason: string;
80
+ created: number;
81
+ payload: {
82
+ error: string;
83
+ };
84
+ }
85
+ export interface ScreenTemplate {
86
+ name: string;
87
+ template: string;
88
+ description: string;
89
+ url: string;
90
+ }
91
+ export interface StormEventScreen {
92
+ type: 'SCREEN';
93
+ reason: string;
94
+ created: number;
95
+ payload: {
96
+ blockName: string;
97
+ name: string;
98
+ template: string;
99
+ description: string;
100
+ url: string;
101
+ };
102
+ }
103
+ export interface StormEventScreenCandidate {
104
+ type: 'SCREEN_CANDIDATE';
105
+ reason: string;
106
+ created: number;
107
+ payload: {
108
+ name: string;
109
+ description: string;
110
+ url: string;
111
+ };
112
+ }
113
+ export interface StormEventFile {
114
+ type: 'FILE';
115
+ reason: string;
116
+ created: number;
117
+ payload: {
118
+ filename: string;
119
+ content: string;
120
+ blockRef: string;
121
+ };
122
+ }
123
+ export interface StormEventDone {
124
+ type: 'DONE';
125
+ created: number;
126
+ }
127
+ export type StormEvent = StormEventCreateBlock | StormEventCreateConnection | StormEventCreatePlanProperties | StormEventInvalidResponse | StormEventPlanRetry | StormEventCreateDSL | StormEventError | StormEventScreen | StormEventScreenCandidate | StormEventFile | StormEventDone;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2023 Kapeta Inc.
4
+ * SPDX-License-Identifier: BUSL-1.1
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright 2023 Kapeta Inc.
3
+ * SPDX-License-Identifier: BUSL-1.1
4
+ */
5
+ /// <reference types="express" />
6
+ declare const router: import("express").Router;
7
+ export default router;