@kapeta/local-cluster-service 0.54.11 → 0.55.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/CHANGELOG.md +21 -0
- package/definitions.d.ts +11 -0
- package/dist/cjs/src/storm/archetype.d.ts +12 -0
- package/dist/cjs/src/storm/archetype.js +98 -0
- package/dist/cjs/src/storm/codegen.d.ts +2 -0
- package/dist/cjs/src/storm/codegen.js +28 -4
- package/dist/cjs/src/storm/event-parser.d.ts +7 -4
- package/dist/cjs/src/storm/event-parser.js +190 -160
- package/dist/cjs/src/storm/events.d.ts +1 -0
- package/dist/cjs/src/storm/predefined.d.ts +27 -0
- package/dist/cjs/src/storm/predefined.js +64 -0
- package/dist/cjs/src/storm/routes.js +23 -15
- package/dist/cjs/test/storm/codegen.test.d.ts +5 -0
- package/dist/cjs/test/storm/codegen.test.js +41 -0
- package/dist/cjs/test/storm/event-parser.test.d.ts +25 -1
- package/dist/cjs/test/storm/event-parser.test.js +34 -15
- package/dist/cjs/test/storm/predefined-user-events.json +13 -0
- package/dist/esm/src/storm/archetype.d.ts +12 -0
- package/dist/esm/src/storm/archetype.js +98 -0
- package/dist/esm/src/storm/codegen.d.ts +2 -0
- package/dist/esm/src/storm/codegen.js +28 -4
- package/dist/esm/src/storm/event-parser.d.ts +7 -4
- package/dist/esm/src/storm/event-parser.js +190 -160
- package/dist/esm/src/storm/events.d.ts +1 -0
- package/dist/esm/src/storm/predefined.d.ts +27 -0
- package/dist/esm/src/storm/predefined.js +64 -0
- package/dist/esm/src/storm/routes.js +23 -15
- package/dist/esm/test/storm/codegen.test.d.ts +5 -0
- package/dist/esm/test/storm/codegen.test.js +41 -0
- package/dist/esm/test/storm/event-parser.test.d.ts +25 -1
- package/dist/esm/test/storm/event-parser.test.js +34 -15
- package/dist/esm/test/storm/predefined-user-events.json +13 -0
- package/package.json +6 -1
- package/src/storm/archetype.ts +85 -0
- package/src/storm/codegen.ts +34 -4
- package/src/storm/event-parser.ts +200 -159
- package/src/storm/events.ts +1 -0
- package/src/storm/predefined.ts +52 -0
- package/src/storm/routes.ts +25 -18
- package/test/storm/codegen.test.ts +46 -0
- package/test/storm/event-parser.test.ts +32 -10
- package/test/storm/predefined-user-events.json +13 -0
@@ -3,12 +3,17 @@
|
|
3
3
|
* Copyright 2023 Kapeta Inc.
|
4
4
|
* SPDX-License-Identifier: BUSL-1.1
|
5
5
|
*/
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
8
|
+
};
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
7
10
|
exports.StormEventParser = exports.resolveOptions = exports.createPhaseEvent = exports.createPhaseEndEvent = exports.createPhaseStartEvent = void 0;
|
8
11
|
const nodejs_utils_1 = require("@kapeta/nodejs-utils");
|
9
12
|
const kaplang_core_1 = require("@kapeta/kaplang-core");
|
10
13
|
const uuid_1 = require("uuid");
|
11
14
|
const definitionsManager_1 = require("../definitionsManager");
|
15
|
+
const predefined_1 = require("./predefined");
|
16
|
+
const lodash_1 = __importDefault(require("lodash"));
|
12
17
|
function prettifyKaplang(source) {
|
13
18
|
if (!source || !source.trim()) {
|
14
19
|
return '';
|
@@ -156,7 +161,7 @@ class StormEventParser {
|
|
156
161
|
/**
|
157
162
|
* Builds plan and block definitions - and enriches events with relevant refs and ids
|
158
163
|
*/
|
159
|
-
processEvent(handle, evt) {
|
164
|
+
async processEvent(handle, evt) {
|
160
165
|
let blockInfo;
|
161
166
|
this.events.push(evt);
|
162
167
|
switch (evt.type) {
|
@@ -222,7 +227,7 @@ class StormEventParser {
|
|
222
227
|
});
|
223
228
|
break;
|
224
229
|
}
|
225
|
-
return this.toResult(handle);
|
230
|
+
return await this.toResult(handle);
|
226
231
|
}
|
227
232
|
getEvents() {
|
228
233
|
return this.events;
|
@@ -236,9 +241,9 @@ class StormEventParser {
|
|
236
241
|
getError() {
|
237
242
|
return this.error;
|
238
243
|
}
|
239
|
-
toResult(handle) {
|
244
|
+
async toResult(handle) {
|
240
245
|
const planRef = StormEventParser.toRef(handle, this.planName || 'undefined');
|
241
|
-
const blockDefinitions = this.toBlockDefinitions(handle);
|
246
|
+
const blockDefinitions = await this.toBlockDefinitions(handle);
|
242
247
|
const refIdMap = {};
|
243
248
|
const blocks = Object.entries(blockDefinitions).map(([ref, block]) => {
|
244
249
|
// Create a deterministic uuid
|
@@ -354,180 +359,190 @@ class StormEventParser {
|
|
354
359
|
blocks: Object.values(blockDefinitions),
|
355
360
|
};
|
356
361
|
}
|
357
|
-
toBlockDefinitions(handle) {
|
362
|
+
async toBlockDefinitions(handle) {
|
358
363
|
const result = {};
|
359
|
-
Object.entries(this.blocks)
|
364
|
+
for (const [, blockInfo] of Object.entries(this.blocks)) {
|
360
365
|
const blockRef = StormEventParser.toRef(handle, blockInfo.name);
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
366
|
+
let blockDefinitionInfo;
|
367
|
+
if (blockInfo.archetype) {
|
368
|
+
blockDefinitionInfo = await this.resolveArchetypeBlockDefinition(blockRef, blockInfo);
|
369
|
+
}
|
370
|
+
else {
|
371
|
+
blockDefinitionInfo = this.createBlockDefinitionInfo(blockRef, blockInfo, handle);
|
372
|
+
}
|
373
|
+
result[blockRef.toNormalizedString()] = blockDefinitionInfo;
|
374
|
+
}
|
375
|
+
return result;
|
376
|
+
}
|
377
|
+
createBlockDefinitionInfo(blockRef, blockInfo, handle) {
|
378
|
+
const blockDefinitionInfo = {
|
379
|
+
uri: blockRef.toNormalizedString(),
|
380
|
+
aiName: blockInfo.name,
|
381
|
+
content: {
|
382
|
+
kind: this.toBlockKind(blockInfo.type),
|
383
|
+
metadata: {
|
384
|
+
title: blockInfo.name,
|
385
|
+
name: blockRef.fullName,
|
386
|
+
description: blockInfo.description,
|
387
|
+
},
|
388
|
+
spec: {
|
389
|
+
entities: {
|
390
|
+
types: [],
|
391
|
+
source: {
|
392
|
+
type: kaplang_core_1.KAPLANG_ID,
|
393
|
+
version: kaplang_core_1.KAPLANG_VERSION,
|
394
|
+
value: '',
|
395
|
+
},
|
370
396
|
},
|
371
|
-
|
372
|
-
|
373
|
-
|
397
|
+
target: this.toBlockTarget(handle, blockInfo.type),
|
398
|
+
providers: [],
|
399
|
+
consumers: [],
|
400
|
+
},
|
401
|
+
},
|
402
|
+
};
|
403
|
+
const blockSpec = blockDefinitionInfo.content.spec;
|
404
|
+
const apiResources = {};
|
405
|
+
let dbResource = undefined;
|
406
|
+
(blockInfo.resources || []).forEach((resource) => {
|
407
|
+
const port = {
|
408
|
+
type: this.toPortType(resource.type),
|
409
|
+
};
|
410
|
+
switch (resource.type) {
|
411
|
+
case 'API': {
|
412
|
+
const apiResource = {
|
413
|
+
kind: this.toResourceKind(resource.type),
|
414
|
+
metadata: {
|
415
|
+
name: resource.name,
|
416
|
+
description: resource.description,
|
417
|
+
},
|
418
|
+
spec: {
|
419
|
+
port,
|
420
|
+
methods: {},
|
374
421
|
source: {
|
375
422
|
type: kaplang_core_1.KAPLANG_ID,
|
376
423
|
version: kaplang_core_1.KAPLANG_VERSION,
|
377
424
|
value: '',
|
378
425
|
},
|
379
426
|
},
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
}
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
description: resource.description,
|
400
|
-
},
|
401
|
-
spec: {
|
402
|
-
port,
|
403
|
-
methods: {},
|
404
|
-
source: {
|
405
|
-
type: kaplang_core_1.KAPLANG_ID,
|
406
|
-
version: kaplang_core_1.KAPLANG_VERSION,
|
407
|
-
value: '',
|
408
|
-
},
|
427
|
+
};
|
428
|
+
apiResources[resource.name] = apiResource;
|
429
|
+
blockSpec.providers.push(apiResource);
|
430
|
+
break;
|
431
|
+
}
|
432
|
+
case 'CLIENT':
|
433
|
+
blockSpec.consumers.push({
|
434
|
+
kind: this.toResourceKind(resource.type),
|
435
|
+
metadata: {
|
436
|
+
name: resource.name,
|
437
|
+
description: resource.description,
|
438
|
+
},
|
439
|
+
spec: {
|
440
|
+
port,
|
441
|
+
methods: {},
|
442
|
+
source: {
|
443
|
+
type: kaplang_core_1.KAPLANG_ID,
|
444
|
+
version: kaplang_core_1.KAPLANG_VERSION,
|
445
|
+
value: '',
|
409
446
|
},
|
410
|
-
}
|
411
|
-
|
412
|
-
|
447
|
+
},
|
448
|
+
});
|
449
|
+
break;
|
450
|
+
case 'EXTERNAL_API':
|
451
|
+
break;
|
452
|
+
case 'EXCHANGE':
|
453
|
+
break;
|
454
|
+
case 'PUBLISHER':
|
455
|
+
break;
|
456
|
+
case 'QUEUE':
|
457
|
+
break;
|
458
|
+
case 'SUBSCRIBER':
|
459
|
+
break;
|
460
|
+
case 'JWTPROVIDER':
|
461
|
+
case 'WEBPAGE':
|
462
|
+
blockSpec.providers.push({
|
463
|
+
kind: this.toResourceKind(resource.type),
|
464
|
+
metadata: {
|
465
|
+
name: resource.name,
|
466
|
+
description: resource.description,
|
467
|
+
},
|
468
|
+
spec: {
|
469
|
+
port,
|
470
|
+
},
|
471
|
+
});
|
472
|
+
break;
|
473
|
+
case 'DATABASE':
|
474
|
+
if (dbResource) {
|
413
475
|
break;
|
414
476
|
}
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
value: '',
|
429
|
-
},
|
430
|
-
},
|
431
|
-
});
|
432
|
-
break;
|
433
|
-
case 'EXTERNAL_API':
|
434
|
-
break;
|
435
|
-
case 'EXCHANGE':
|
436
|
-
break;
|
437
|
-
case 'PUBLISHER':
|
438
|
-
break;
|
439
|
-
case 'QUEUE':
|
440
|
-
break;
|
441
|
-
case 'SUBSCRIBER':
|
442
|
-
break;
|
443
|
-
case 'JWTPROVIDER':
|
444
|
-
case 'WEBPAGE':
|
445
|
-
blockSpec.providers.push({
|
446
|
-
kind: this.toResourceKind(resource.type),
|
447
|
-
metadata: {
|
448
|
-
name: resource.name,
|
449
|
-
description: resource.description,
|
450
|
-
},
|
451
|
-
spec: {
|
452
|
-
port,
|
453
|
-
},
|
454
|
-
});
|
455
|
-
break;
|
456
|
-
case 'DATABASE':
|
457
|
-
if (dbResource) {
|
458
|
-
break;
|
459
|
-
}
|
460
|
-
dbResource = {
|
461
|
-
kind: this.toResourceKind(resource.type),
|
462
|
-
metadata: {
|
463
|
-
name: resource.name,
|
464
|
-
description: resource.description,
|
465
|
-
},
|
466
|
-
spec: {
|
467
|
-
port,
|
468
|
-
models: [],
|
469
|
-
source: {
|
470
|
-
type: kaplang_core_1.KAPLANG_ID,
|
471
|
-
version: kaplang_core_1.KAPLANG_VERSION,
|
472
|
-
value: '',
|
473
|
-
},
|
474
|
-
},
|
475
|
-
};
|
476
|
-
blockSpec.consumers.push(dbResource);
|
477
|
-
break;
|
478
|
-
case 'JWTCONSUMER':
|
479
|
-
case 'WEBFRAGMENT':
|
480
|
-
case 'SMTPCLIENT':
|
481
|
-
blockSpec.consumers.push({
|
482
|
-
kind: this.toResourceKind(resource.type),
|
483
|
-
metadata: {
|
484
|
-
name: resource.name,
|
485
|
-
description: resource.description,
|
486
|
-
},
|
487
|
-
spec: {
|
488
|
-
port,
|
477
|
+
dbResource = {
|
478
|
+
kind: this.toResourceKind(resource.type),
|
479
|
+
metadata: {
|
480
|
+
name: resource.name,
|
481
|
+
description: resource.description,
|
482
|
+
},
|
483
|
+
spec: {
|
484
|
+
port,
|
485
|
+
models: [],
|
486
|
+
source: {
|
487
|
+
type: kaplang_core_1.KAPLANG_ID,
|
488
|
+
version: kaplang_core_1.KAPLANG_VERSION,
|
489
|
+
value: '',
|
489
490
|
},
|
490
|
-
}
|
491
|
-
|
491
|
+
},
|
492
|
+
};
|
493
|
+
blockSpec.consumers.push(dbResource);
|
494
|
+
break;
|
495
|
+
case 'JWTCONSUMER':
|
496
|
+
case 'WEBFRAGMENT':
|
497
|
+
case 'SMTPCLIENT':
|
498
|
+
blockSpec.consumers.push({
|
499
|
+
kind: this.toResourceKind(resource.type),
|
500
|
+
metadata: {
|
501
|
+
name: resource.name,
|
502
|
+
description: resource.description,
|
503
|
+
},
|
504
|
+
spec: {
|
505
|
+
port,
|
506
|
+
},
|
507
|
+
});
|
508
|
+
}
|
509
|
+
});
|
510
|
+
blockInfo.apis.forEach((api) => {
|
511
|
+
const dslApi = kaplang_core_1.DSLAPIParser.parse(api, {
|
512
|
+
ignoreSemantics: true,
|
492
513
|
});
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
if (apiResourceName) {
|
502
|
-
const exactResource = apiResources[apiResourceName];
|
503
|
-
exactResource.spec.source.value += api + '\n\n';
|
504
|
-
exactMatch = true;
|
505
|
-
}
|
514
|
+
let exactMatch = false;
|
515
|
+
if (dslApi[0] && dslApi[0].type == kaplang_core_1.DSLEntityType.CONTROLLER) {
|
516
|
+
const name = dslApi[0].name.toLowerCase();
|
517
|
+
const apiResourceName = Object.keys(apiResources).find((key) => key.indexOf(name) > -1);
|
518
|
+
if (apiResourceName) {
|
519
|
+
const exactResource = apiResources[apiResourceName];
|
520
|
+
exactResource.spec.source.value += api + '\n\n';
|
521
|
+
exactMatch = true;
|
506
522
|
}
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
523
|
+
}
|
524
|
+
if (!exactMatch) {
|
525
|
+
// if we couldn't place the given api on the exact resource we just park it on the first
|
526
|
+
// available rest resource
|
527
|
+
const firstKey = Object.keys(apiResources)[0];
|
528
|
+
const firstEntry = apiResources[firstKey];
|
529
|
+
if (firstEntry) {
|
530
|
+
firstEntry.spec.source.value += api + '\n\n';
|
531
|
+
}
|
532
|
+
else {
|
533
|
+
console.warn('Unable to find resource for API', api);
|
518
534
|
}
|
519
|
-
});
|
520
|
-
blockInfo.types.forEach((type) => {
|
521
|
-
blockSpec.entities.source.value += type + '\n';
|
522
|
-
});
|
523
|
-
if (dbResource) {
|
524
|
-
blockInfo.models.forEach((model) => {
|
525
|
-
dbResource.spec.source.value += model + '\n';
|
526
|
-
});
|
527
535
|
}
|
528
|
-
result[blockRef.toNormalizedString()] = blockDefinitionInfo;
|
529
536
|
});
|
530
|
-
|
537
|
+
blockInfo.types.forEach((type) => {
|
538
|
+
blockSpec.entities.source.value += type + '\n';
|
539
|
+
});
|
540
|
+
if (dbResource) {
|
541
|
+
blockInfo.models.forEach((model) => {
|
542
|
+
dbResource.spec.source.value += model + '\n';
|
543
|
+
});
|
544
|
+
}
|
545
|
+
return blockDefinitionInfo;
|
531
546
|
}
|
532
547
|
toResourceKind(type) {
|
533
548
|
//TODO: Handle support for multiple resource types and versions
|
@@ -663,5 +678,20 @@ class StormEventParser {
|
|
663
678
|
}
|
664
679
|
return undefined;
|
665
680
|
}
|
681
|
+
async resolveArchetypeBlockDefinition(blockRef, blockInfo) {
|
682
|
+
const predefinedBlock = predefined_1.PREDEFINED_BLOCKS.get(blockInfo.archetype);
|
683
|
+
if (!predefinedBlock) {
|
684
|
+
throw new Error('Predefined block not found for archetype [' + blockInfo.archetype + ']');
|
685
|
+
}
|
686
|
+
const blockDefinition = await predefinedBlock.getBlockDefinition();
|
687
|
+
lodash_1.default.set(blockDefinition, ['metadata', 'name'], blockRef.fullName);
|
688
|
+
lodash_1.default.set(blockDefinition, ['metadata', 'title'], blockRef.name);
|
689
|
+
return {
|
690
|
+
uri: blockRef.toNormalizedString(),
|
691
|
+
aiName: blockInfo.name,
|
692
|
+
content: blockDefinition,
|
693
|
+
archetype: blockInfo.archetype,
|
694
|
+
};
|
695
|
+
}
|
666
696
|
}
|
667
697
|
exports.StormEventParser = StormEventParser;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright 2023 Kapeta Inc.
|
3
|
+
* SPDX-License-Identifier: BUSL-1.1
|
4
|
+
*/
|
5
|
+
import { BlockDefinition } from '@kapeta/schemas';
|
6
|
+
export declare class PredefinedBlock {
|
7
|
+
archetype: string;
|
8
|
+
kapetaYml: string;
|
9
|
+
gitRepo: {
|
10
|
+
owner: string;
|
11
|
+
repo: string;
|
12
|
+
path: string;
|
13
|
+
};
|
14
|
+
constructor(archetype: string, kapetaYml: string, gitRepo: {
|
15
|
+
owner: string;
|
16
|
+
repo: string;
|
17
|
+
path: string;
|
18
|
+
});
|
19
|
+
getGitRepo(): {
|
20
|
+
owner: string;
|
21
|
+
repo: string;
|
22
|
+
path: string;
|
23
|
+
};
|
24
|
+
private getKapetaYML;
|
25
|
+
getBlockDefinition(): Promise<BlockDefinition>;
|
26
|
+
}
|
27
|
+
export declare const PREDEFINED_BLOCKS: Map<string, PredefinedBlock>;
|
@@ -0,0 +1,64 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* Copyright 2023 Kapeta Inc.
|
4
|
+
* SPDX-License-Identifier: BUSL-1.1
|
5
|
+
*/
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
7
|
+
if (k2 === undefined) k2 = k;
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
11
|
+
}
|
12
|
+
Object.defineProperty(o, k2, desc);
|
13
|
+
}) : (function(o, m, k, k2) {
|
14
|
+
if (k2 === undefined) k2 = k;
|
15
|
+
o[k2] = m[k];
|
16
|
+
}));
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
19
|
+
}) : function(o, v) {
|
20
|
+
o["default"] = v;
|
21
|
+
});
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
23
|
+
if (mod && mod.__esModule) return mod;
|
24
|
+
var result = {};
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
26
|
+
__setModuleDefault(result, mod);
|
27
|
+
return result;
|
28
|
+
};
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
30
|
+
exports.PREDEFINED_BLOCKS = exports.PredefinedBlock = void 0;
|
31
|
+
const yaml = __importStar(require("js-yaml"));
|
32
|
+
class PredefinedBlock {
|
33
|
+
archetype;
|
34
|
+
kapetaYml;
|
35
|
+
gitRepo;
|
36
|
+
constructor(archetype, kapetaYml, gitRepo) {
|
37
|
+
this.archetype = archetype;
|
38
|
+
this.kapetaYml = kapetaYml;
|
39
|
+
this.gitRepo = gitRepo;
|
40
|
+
}
|
41
|
+
getGitRepo() {
|
42
|
+
return this.gitRepo;
|
43
|
+
}
|
44
|
+
async getKapetaYML() {
|
45
|
+
const response = await fetch(this.kapetaYml);
|
46
|
+
if (!response.ok) {
|
47
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
48
|
+
}
|
49
|
+
return await response.text();
|
50
|
+
}
|
51
|
+
async getBlockDefinition() {
|
52
|
+
const kapetaYml = await this.getKapetaYML();
|
53
|
+
return yaml.load(kapetaYml);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
exports.PredefinedBlock = PredefinedBlock;
|
57
|
+
const predefinedBlocks = [
|
58
|
+
new PredefinedBlock('USER_SERVICE', 'https://raw.githubusercontent.com/kapetacom/everything/master/blocks/everything-user/kapeta.yml', {
|
59
|
+
owner: 'kapetacom',
|
60
|
+
repo: 'everything',
|
61
|
+
path: 'blocks/everything-user',
|
62
|
+
}),
|
63
|
+
];
|
64
|
+
exports.PREDEFINED_BLOCKS = new Map(predefinedBlocks.map((block) => [block.archetype, block]));
|
@@ -17,6 +17,7 @@ const event_parser_1 = require("./event-parser");
|
|
17
17
|
const codegen_1 = require("./codegen");
|
18
18
|
const assetManager_1 = require("../assetManager");
|
19
19
|
const path_1 = __importDefault(require("path"));
|
20
|
+
const lodash_1 = __importDefault(require("lodash"));
|
20
21
|
const router = (0, express_promise_router_1.default)();
|
21
22
|
router.use('/', cors_1.corsHandler);
|
22
23
|
router.use('/', stringBody_1.stringBody);
|
@@ -35,21 +36,28 @@ router.post('/:handle/all', async (req, res) => {
|
|
35
36
|
res.set('Access-Control-Expose-Headers', stormClient_1.ConversationIdHeader);
|
36
37
|
res.set(stormClient_1.ConversationIdHeader, metaStream.getConversationId());
|
37
38
|
let currentPhase = events_1.StormEventPhaseType.META;
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
// Helper to avoid sending the plan multiple times in a row
|
40
|
+
const sendUpdatedPlan = lodash_1.default.debounce(sendDefinitions, 50, { maxWait: 200 });
|
41
|
+
metaStream.on('data', async (data) => {
|
42
|
+
try {
|
43
|
+
const result = await eventParser.processEvent(handle, data);
|
44
|
+
switch (data.type) {
|
45
|
+
case 'CREATE_API':
|
46
|
+
case 'CREATE_MODEL':
|
47
|
+
case 'CREATE_TYPE':
|
48
|
+
if (currentPhase !== events_1.StormEventPhaseType.DEFINITIONS) {
|
49
|
+
sendEvent(res, (0, event_parser_1.createPhaseEndEvent)(events_1.StormEventPhaseType.META));
|
50
|
+
currentPhase = events_1.StormEventPhaseType.DEFINITIONS;
|
51
|
+
sendEvent(res, (0, event_parser_1.createPhaseStartEvent)(events_1.StormEventPhaseType.DEFINITIONS));
|
52
|
+
}
|
53
|
+
break;
|
54
|
+
}
|
55
|
+
sendEvent(res, data);
|
56
|
+
sendUpdatedPlan(res, result);
|
57
|
+
}
|
58
|
+
catch (e) {
|
59
|
+
console.error('Failed to process event', e);
|
50
60
|
}
|
51
|
-
sendEvent(res, data);
|
52
|
-
sendDefinitions(res, result);
|
53
61
|
});
|
54
62
|
try {
|
55
63
|
sendEvent(res, (0, event_parser_1.createPhaseStartEvent)(events_1.StormEventPhaseType.META));
|
@@ -74,7 +82,7 @@ router.post('/:handle/all', async (req, res) => {
|
|
74
82
|
res.end();
|
75
83
|
return;
|
76
84
|
}
|
77
|
-
const result = eventParser.toResult(handle);
|
85
|
+
const result = await eventParser.toResult(handle);
|
78
86
|
if (metaStream.isAborted()) {
|
79
87
|
return;
|
80
88
|
}
|
@@ -0,0 +1,41 @@
|
|
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
|
+
const predefined_user_events_json_1 = __importDefault(require("./predefined-user-events.json"));
|
11
|
+
const event_parser_1 = require("../../src/storm/event-parser");
|
12
|
+
const event_parser_test_1 = require("./event-parser.test");
|
13
|
+
const codegen_1 = require("../../src/storm/codegen");
|
14
|
+
const node_uuid_1 = __importDefault(require("node-uuid"));
|
15
|
+
describe('codegen', () => {
|
16
|
+
it('predefined components', async () => {
|
17
|
+
const events = predefined_user_events_json_1.default;
|
18
|
+
const parser = new event_parser_1.StormEventParser(event_parser_test_1.parserOptions);
|
19
|
+
for (const event of events) {
|
20
|
+
await parser.processEvent('kapeta', event);
|
21
|
+
}
|
22
|
+
const result = await parser.toResult('kapeta');
|
23
|
+
const conversationId = node_uuid_1.default.v4().toString();
|
24
|
+
let codegen = new codegen_1.StormCodegen(conversationId, '', result.blocks, parser.getEvents());
|
25
|
+
let codegenPromise = consumeStream(codegen.getStream());
|
26
|
+
await codegen.process();
|
27
|
+
const stormEvents = await codegenPromise;
|
28
|
+
expect(stormEvents[0].type).toBe('FILE_DONE');
|
29
|
+
expect(stormEvents[stormEvents.length - 1].type).toBe('BLOCK_READY');
|
30
|
+
});
|
31
|
+
});
|
32
|
+
async function consumeStream(stream) {
|
33
|
+
const events = [];
|
34
|
+
return new Promise((resolve) => {
|
35
|
+
stream.on('data', (data) => {
|
36
|
+
events.push(data);
|
37
|
+
});
|
38
|
+
stream.waitForDone();
|
39
|
+
resolve(events);
|
40
|
+
});
|
41
|
+
}
|
@@ -2,4 +2,28 @@
|
|
2
2
|
* Copyright 2023 Kapeta Inc.
|
3
3
|
* SPDX-License-Identifier: BUSL-1.1
|
4
4
|
*/
|
5
|
-
export {
|
5
|
+
export declare const parserOptions: {
|
6
|
+
serviceKind: string;
|
7
|
+
serviceLanguage: string;
|
8
|
+
frontendKind: string;
|
9
|
+
frontendLanguage: string;
|
10
|
+
cliKind: string;
|
11
|
+
cliLanguage: string;
|
12
|
+
desktopKind: string;
|
13
|
+
desktopLanguage: string;
|
14
|
+
gatewayKind: string;
|
15
|
+
mqKind: string;
|
16
|
+
exchangeKind: string;
|
17
|
+
queueKind: string;
|
18
|
+
publisherKind: string;
|
19
|
+
subscriberKind: string;
|
20
|
+
databaseKind: string;
|
21
|
+
apiKind: string;
|
22
|
+
clientKind: string;
|
23
|
+
webPageKind: string;
|
24
|
+
webFragmentKind: string;
|
25
|
+
jwtProviderKind: string;
|
26
|
+
jwtConsumerKind: string;
|
27
|
+
smtpKind: string;
|
28
|
+
externalApiKind: string;
|
29
|
+
};
|