@kapeta/local-cluster-service 0.55.1 → 0.55.3
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/definitions.d.ts +1 -1
- package/dist/cjs/src/storm/event-parser.d.ts +2 -1
- package/dist/cjs/src/storm/event-parser.js +43 -12
- package/dist/cjs/src/storm/routes.js +1 -1
- package/dist/cjs/test/storm/blog-events.json +860 -0
- package/dist/cjs/test/storm/codegen.test.js +2 -2
- package/dist/cjs/test/storm/event-parser.test.js +25 -7
- package/dist/cjs/test/storm/predefined-user-events.json +9 -0
- package/dist/esm/src/storm/event-parser.d.ts +2 -1
- package/dist/esm/src/storm/event-parser.js +43 -12
- package/dist/esm/src/storm/routes.js +1 -1
- package/dist/esm/test/storm/blog-events.json +860 -0
- package/dist/esm/test/storm/codegen.test.js +2 -2
- package/dist/esm/test/storm/event-parser.test.js +25 -7
- package/dist/esm/test/storm/predefined-user-events.json +9 -0
- package/package.json +1 -1
- package/src/storm/event-parser.ts +76 -37
- package/src/storm/routes.ts +1 -1
- package/test/storm/blog-events.json +860 -0
- package/test/storm/codegen.test.ts +4 -2
- package/test/storm/event-parser.test.ts +27 -7
- package/test/storm/predefined-user-events.json +9 -0
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [0.55.3](https://github.com/kapetacom/local-cluster-service/compare/v0.55.2...v0.55.3) (2024-07-12)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* ensure versions on predefined blocks are the latest ([0a841bc](https://github.com/kapetacom/local-cluster-service/commit/0a841bc221cfac09cac41992a06385be1da24197))
|
7
|
+
|
8
|
+
## [0.55.2](https://github.com/kapetacom/local-cluster-service/compare/v0.55.1...v0.55.2) (2024-07-12)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* recurring create-block events will not overwrite types, apis or models ([f07b2da](https://github.com/kapetacom/local-cluster-service/commit/f07b2da0e0fc286e3eb06af2efcd1746808f2ba9))
|
14
|
+
|
1
15
|
## [0.55.1](https://github.com/kapetacom/local-cluster-service/compare/v0.55.0...v0.55.1) (2024-07-12)
|
2
16
|
|
3
17
|
|
package/definitions.d.ts
CHANGED
@@ -39,6 +39,7 @@ export interface StormOptions {
|
|
39
39
|
desktopKind: string;
|
40
40
|
desktopLanguage: string;
|
41
41
|
gatewayKind: string;
|
42
|
+
[key: string]: string;
|
42
43
|
}
|
43
44
|
export declare function createPhaseStartEvent(type: StormEventPhaseType): StormEventPhases;
|
44
45
|
export declare function createPhaseEndEvent(type: StormEventPhaseType): StormEventPhases;
|
@@ -66,7 +67,7 @@ export declare class StormEventParser {
|
|
66
67
|
getEvents(): StormEvent[];
|
67
68
|
isValid(): boolean;
|
68
69
|
getError(): string;
|
69
|
-
toResult(handle: string): Promise<StormDefinitions>;
|
70
|
+
toResult(handle: string, warn?: boolean): Promise<StormDefinitions>;
|
70
71
|
toBlockDefinitions(handle: string): Promise<{
|
71
72
|
[key: string]: BlockDefinitionInfo;
|
72
73
|
}>;
|
@@ -170,11 +170,14 @@ class StormEventParser {
|
|
170
170
|
this.planDescription = evt.payload.description;
|
171
171
|
break;
|
172
172
|
case 'CREATE_BLOCK':
|
173
|
+
const apis = this.blocks[evt.payload.name]?.apis;
|
174
|
+
const models = this.blocks[evt.payload.name]?.models;
|
175
|
+
const types = this.blocks[evt.payload.name]?.types;
|
173
176
|
this.blocks[evt.payload.name] = {
|
174
177
|
...evt.payload,
|
175
|
-
apis: [],
|
176
|
-
models: [],
|
177
|
-
types: [],
|
178
|
+
apis: apis ?? [],
|
179
|
+
models: models ?? [],
|
180
|
+
types: types ?? [],
|
178
181
|
};
|
179
182
|
evt.payload.blockRef = StormEventParser.toRef(handle, evt.payload.name).toNormalizedString();
|
180
183
|
evt.payload.instanceId = StormEventParser.toInstanceIdFromRef(evt.payload.blockRef);
|
@@ -241,7 +244,7 @@ class StormEventParser {
|
|
241
244
|
getError() {
|
242
245
|
return this.error;
|
243
246
|
}
|
244
|
-
async toResult(handle) {
|
247
|
+
async toResult(handle, warn = false) {
|
245
248
|
const planRef = StormEventParser.toRef(handle, this.planName || 'undefined');
|
246
249
|
const blockDefinitions = await this.toBlockDefinitions(handle);
|
247
250
|
const refIdMap = {};
|
@@ -281,7 +284,9 @@ class StormEventParser {
|
|
281
284
|
}
|
282
285
|
const apiResource = apiProviderBlock.content.spec.providers?.find((p) => p.kind === this.options.apiKind && p.metadata.name === apiConnection.fromResource);
|
283
286
|
if (!apiResource) {
|
284
|
-
|
287
|
+
if (warn) {
|
288
|
+
console.warn('API resource not found: %s on %s', apiConnection.fromResource, apiProviderRef.toNormalizedString(), apiConnection);
|
289
|
+
}
|
285
290
|
return;
|
286
291
|
}
|
287
292
|
const clientResource = clientConsumerBlock.content.spec.consumers?.find((clientResource) => {
|
@@ -292,7 +297,9 @@ class StormEventParser {
|
|
292
297
|
return clientResource.metadata.name === apiConnection.toResource;
|
293
298
|
});
|
294
299
|
if (!clientResource) {
|
295
|
-
|
300
|
+
if (warn) {
|
301
|
+
console.warn('Client resource not found: %s on %s', apiConnection.toResource, clientConsumerRef.toNormalizedString(), apiConnection);
|
302
|
+
}
|
296
303
|
return;
|
297
304
|
}
|
298
305
|
if (apiProviderBlock.content.spec.entities?.source?.value) {
|
@@ -337,7 +344,7 @@ class StormEventParser {
|
|
337
344
|
blockId: refIdMap[fromRef.toNormalizedString()],
|
338
345
|
resourceName: connection.fromResource,
|
339
346
|
},
|
340
|
-
mapping: this.toConnectionMapping(handle, connection, blockDefinitions),
|
347
|
+
mapping: this.toConnectionMapping(handle, connection, blockDefinitions, warn),
|
341
348
|
};
|
342
349
|
});
|
343
350
|
const plan = {
|
@@ -365,7 +372,7 @@ class StormEventParser {
|
|
365
372
|
const blockRef = StormEventParser.toRef(handle, blockInfo.name);
|
366
373
|
let blockDefinitionInfo;
|
367
374
|
if (blockInfo.archetype) {
|
368
|
-
blockDefinitionInfo = await this.resolveArchetypeBlockDefinition(blockRef, blockInfo);
|
375
|
+
blockDefinitionInfo = await this.resolveArchetypeBlockDefinition(blockRef, blockInfo, handle);
|
369
376
|
}
|
370
377
|
else {
|
371
378
|
blockDefinitionInfo = this.createBlockDefinitionInfo(blockRef, blockInfo, handle);
|
@@ -530,7 +537,7 @@ class StormEventParser {
|
|
530
537
|
firstEntry.spec.source.value += api + '\n\n';
|
531
538
|
}
|
532
539
|
else {
|
533
|
-
|
540
|
+
// this might be ok as we might receive api and types before resources from the ai-service
|
534
541
|
}
|
535
542
|
}
|
536
543
|
});
|
@@ -593,7 +600,7 @@ class StormEventParser {
|
|
593
600
|
}
|
594
601
|
return '';
|
595
602
|
}
|
596
|
-
toConnectionMapping(handle, connection, blockDefinitions) {
|
603
|
+
toConnectionMapping(handle, connection, blockDefinitions, warn) {
|
597
604
|
if (connection.fromResourceType !== 'API') {
|
598
605
|
return;
|
599
606
|
}
|
@@ -605,7 +612,9 @@ class StormEventParser {
|
|
605
612
|
}
|
606
613
|
const apiResource = apiProviderBlock.content.spec.providers?.find((p) => p.kind === this.options.apiKind && p.metadata.name === connection.fromResource);
|
607
614
|
if (!apiResource) {
|
608
|
-
|
615
|
+
if (warn) {
|
616
|
+
console.warn('API resource not found: %s on %s', connection.fromResource, fromRef.toNormalizedString(), connection);
|
617
|
+
}
|
609
618
|
return;
|
610
619
|
}
|
611
620
|
const apiMethods = kaplang_core_1.DSLConverters.toSchemaMethods(kaplang_core_1.DSLAPIParser.parse(apiResource.spec?.source?.value ?? '', {
|
@@ -678,14 +687,36 @@ class StormEventParser {
|
|
678
687
|
}
|
679
688
|
return undefined;
|
680
689
|
}
|
681
|
-
async resolveArchetypeBlockDefinition(blockRef, blockInfo) {
|
690
|
+
async resolveArchetypeBlockDefinition(blockRef, blockInfo, handle) {
|
682
691
|
const predefinedBlock = predefined_1.PREDEFINED_BLOCKS.get(blockInfo.archetype);
|
683
692
|
if (!predefinedBlock) {
|
684
693
|
throw new Error('Predefined block not found for archetype [' + blockInfo.archetype + ']');
|
685
694
|
}
|
695
|
+
const target = this.toBlockTarget(handle, blockInfo.type);
|
686
696
|
const blockDefinition = await predefinedBlock.getBlockDefinition();
|
687
697
|
lodash_1.default.set(blockDefinition, ['metadata', 'name'], blockRef.fullName);
|
688
698
|
lodash_1.default.set(blockDefinition, ['metadata', 'title'], blockRef.name);
|
699
|
+
lodash_1.default.set(blockDefinition, ['spec', 'target', 'options'], target?.options);
|
700
|
+
const options = this.options;
|
701
|
+
function getKind(kind) {
|
702
|
+
for (const prop in options) {
|
703
|
+
if (options.hasOwnProperty(prop)) {
|
704
|
+
const value = options[prop];
|
705
|
+
if (value.startsWith(kind)) {
|
706
|
+
return value;
|
707
|
+
}
|
708
|
+
}
|
709
|
+
}
|
710
|
+
}
|
711
|
+
blockDefinition.kind = getKind((0, nodejs_utils_1.parseKapetaUri)(blockDefinition.kind).fullName) ?? blockDefinition.kind;
|
712
|
+
for (const provider of blockDefinition.spec.providers ?? []) {
|
713
|
+
provider.kind = getKind((0, nodejs_utils_1.parseKapetaUri)(provider.kind).fullName) ?? provider.kind;
|
714
|
+
}
|
715
|
+
for (const consumer of blockDefinition.spec.consumers ?? []) {
|
716
|
+
consumer.kind = getKind((0, nodejs_utils_1.parseKapetaUri)(consumer.kind).fullName) ?? consumer.kind;
|
717
|
+
}
|
718
|
+
blockDefinition.spec.target.kind =
|
719
|
+
getKind((0, nodejs_utils_1.parseKapetaUri)(blockDefinition.spec.target.kind).fullName) ?? blockDefinition.spec.target.kind;
|
689
720
|
return {
|
690
721
|
uri: blockRef.toNormalizedString(),
|
691
722
|
aiName: blockInfo.name,
|