@kapeta/local-cluster-service 0.54.12 → 0.55.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 +22 -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 +3 -3
- package/dist/cjs/test/storm/codegen.test.d.ts +5 -0
- package/dist/cjs/test/storm/codegen.test.js +43 -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 +3 -3
- package/dist/esm/test/storm/codegen.test.d.ts +5 -0
- package/dist/esm/test/storm/codegen.test.js +43 -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 +3 -3
- package/test/storm/codegen.test.ts +48 -0
- package/test/storm/event-parser.test.ts +32 -10
- package/test/storm/predefined-user-events.json +13 -0
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## [0.55.1](https://github.com/kapetacom/local-cluster-service/compare/v0.55.0...v0.55.1) (2024-07-12)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* include full path for files in cloned predefined source ([dba3151](https://github.com/kapetacom/local-cluster-service/commit/dba3151ab365281396ee8b3c9e0dd1f44f88b3f6))
|
7
|
+
* more tests ([6c61030](https://github.com/kapetacom/local-cluster-service/commit/6c61030c243dc2d23da257b587ab4dfe2e2966f4))
|
8
|
+
|
9
|
+
# [0.55.0](https://github.com/kapetacom/local-cluster-service/compare/v0.54.12...v0.55.0) (2024-07-11)
|
10
|
+
|
11
|
+
|
12
|
+
### Bug Fixes
|
13
|
+
|
14
|
+
* change test ([218f7d0](https://github.com/kapetacom/local-cluster-service/commit/218f7d0b485a5d045b59d52956fed9e09ed6e243))
|
15
|
+
* license ([0d3ff1b](https://github.com/kapetacom/local-cluster-service/commit/0d3ff1b4a6377fb874a1183465ff59bbca7ccae1))
|
16
|
+
* review comments ([094a5db](https://github.com/kapetacom/local-cluster-service/commit/094a5db73a70740cd7cddced0c9ff2094a723018))
|
17
|
+
|
18
|
+
|
19
|
+
### Features
|
20
|
+
|
21
|
+
* support archetypes/predefined blocks in event parsing/codegen ([7929413](https://github.com/kapetacom/local-cluster-service/commit/7929413b90e901e7960be46efc5a1b3473935ddd))
|
22
|
+
|
1
23
|
## [0.54.12](https://github.com/kapetacom/local-cluster-service/compare/v0.54.11...v0.54.12) (2024-07-10)
|
2
24
|
|
3
25
|
|
package/definitions.d.ts
CHANGED
@@ -37,3 +37,14 @@ declare module '@kapeta/nodejs-registry-utils' {
|
|
37
37
|
YAMLHandler: ArtifactHandlerFactory;
|
38
38
|
};
|
39
39
|
}
|
40
|
+
|
41
|
+
declare module 'download-git-repo' {
|
42
|
+
function download(
|
43
|
+
url: string,
|
44
|
+
dest: string,
|
45
|
+
opts?: RequestOptions & { clone?: boolean },
|
46
|
+
callback?: RequestCallback
|
47
|
+
): void;
|
48
|
+
|
49
|
+
export = download;
|
50
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright 2023 Kapeta Inc.
|
3
|
+
* SPDX-License-Identifier: BUSL-1.1
|
4
|
+
*/
|
5
|
+
import { PredefinedBlock } from './predefined';
|
6
|
+
import { GeneratedResult } from '@kapeta/codegen';
|
7
|
+
export declare class Archetype {
|
8
|
+
cloneRepository(predefinedBlock: PredefinedBlock, targetDir: string, basePath: string): Promise<GeneratedResult>;
|
9
|
+
private copyToBasePathAndRemoveDownload;
|
10
|
+
private convertToGeneratedResult;
|
11
|
+
private downloadRepo;
|
12
|
+
}
|
@@ -0,0 +1,98 @@
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
30
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
31
|
+
};
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
33
|
+
exports.Archetype = void 0;
|
34
|
+
const download_git_repo_1 = __importDefault(require("download-git-repo"));
|
35
|
+
const fs = __importStar(require("node:fs"));
|
36
|
+
const path_1 = __importDefault(require("path"));
|
37
|
+
class Archetype {
|
38
|
+
async cloneRepository(predefinedBlock, targetDir, basePath) {
|
39
|
+
const downloadDirectory = `${targetDir}/download`;
|
40
|
+
await this.downloadRepo(predefinedBlock.getGitRepo().owner + '/' + predefinedBlock.getGitRepo().repo, downloadDirectory);
|
41
|
+
await this.copyToBasePathAndRemoveDownload(downloadDirectory, predefinedBlock.getGitRepo().path, basePath);
|
42
|
+
return this.convertToGeneratedResult(basePath);
|
43
|
+
}
|
44
|
+
async copyToBasePathAndRemoveDownload(downloadDirectory, subPath, targetDir) {
|
45
|
+
const fullSourcePath = path_1.default.resolve(`${downloadDirectory}/${subPath}`);
|
46
|
+
const fullDestinationPath = path_1.default.resolve(targetDir);
|
47
|
+
try {
|
48
|
+
await fs.promises.cp(fullSourcePath, fullDestinationPath, { recursive: true });
|
49
|
+
console.log(`Directory copied: ${fullSourcePath} -> ${fullDestinationPath}`);
|
50
|
+
}
|
51
|
+
catch (err) {
|
52
|
+
console.error(`Error copying directory: ${err}`);
|
53
|
+
}
|
54
|
+
finally {
|
55
|
+
await fs.promises.rm(downloadDirectory, { recursive: true, force: true });
|
56
|
+
}
|
57
|
+
}
|
58
|
+
async convertToGeneratedResult(basePath) {
|
59
|
+
const generatedFiles = [];
|
60
|
+
async function traverse(currentPath, basePath) {
|
61
|
+
const files = await fs.promises.readdir(currentPath, { withFileTypes: true });
|
62
|
+
for (const file of files) {
|
63
|
+
const fullPath = path_1.default.join(currentPath, file.name);
|
64
|
+
if (file.isFile()) {
|
65
|
+
const stats = await fs.promises.stat(fullPath);
|
66
|
+
const mode = stats.mode.toString(8);
|
67
|
+
const permissions = stats.mode.toString(8).slice(-3);
|
68
|
+
const content = await fs.promises.readFile(fullPath);
|
69
|
+
const generatedFile = {
|
70
|
+
filename: fullPath.replace(basePath + '/', ''),
|
71
|
+
content: content.toString(),
|
72
|
+
mode: mode,
|
73
|
+
permissions: permissions,
|
74
|
+
};
|
75
|
+
generatedFiles.push(generatedFile);
|
76
|
+
}
|
77
|
+
else if (file.isDirectory()) {
|
78
|
+
await traverse(fullPath, basePath);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
await traverse(basePath, basePath);
|
83
|
+
return { files: generatedFiles };
|
84
|
+
}
|
85
|
+
downloadRepo(url, dest) {
|
86
|
+
return new Promise((resolve, reject) => {
|
87
|
+
(0, download_git_repo_1.default)(url, dest, function (err) {
|
88
|
+
if (err) {
|
89
|
+
reject(err);
|
90
|
+
}
|
91
|
+
else {
|
92
|
+
resolve();
|
93
|
+
}
|
94
|
+
});
|
95
|
+
});
|
96
|
+
}
|
97
|
+
}
|
98
|
+
exports.Archetype = Archetype;
|
@@ -26,6 +26,7 @@ export declare class StormCodegen {
|
|
26
26
|
* Generates the code for a block and sends it to the AI
|
27
27
|
*/
|
28
28
|
private processBlockCode;
|
29
|
+
private emitBlockStatusDone;
|
29
30
|
private emitBlockStatus;
|
30
31
|
private verifyAndFixCode;
|
31
32
|
private tryToFixFile;
|
@@ -55,5 +56,6 @@ export declare class StormCodegen {
|
|
55
56
|
* Generates the code using codegen for a given block.
|
56
57
|
*/
|
57
58
|
private generateBlock;
|
59
|
+
private cloneArchetype;
|
58
60
|
abort(): void;
|
59
61
|
}
|
@@ -44,6 +44,9 @@ const path_2 = __importStar(require("path"));
|
|
44
44
|
const node_os_1 = __importDefault(require("node:os"));
|
45
45
|
const fs_1 = require("fs");
|
46
46
|
const yaml_1 = __importDefault(require("yaml"));
|
47
|
+
const predefined_1 = require("./predefined");
|
48
|
+
const archetype_1 = require("./archetype");
|
49
|
+
const lodash_1 = __importDefault(require("lodash"));
|
47
50
|
const SIMULATED_DELAY = 1000;
|
48
51
|
const ENABLE_SIMULATED_DELAY = false;
|
49
52
|
class SimulatedFileDelay {
|
@@ -106,7 +109,12 @@ class StormCodegen {
|
|
106
109
|
}
|
107
110
|
async process() {
|
108
111
|
const promises = this.blocks.map((block) => {
|
109
|
-
|
112
|
+
if (block.archetype) {
|
113
|
+
return this.cloneArchetype(block);
|
114
|
+
}
|
115
|
+
else {
|
116
|
+
return this.processBlockCode(block);
|
117
|
+
}
|
110
118
|
});
|
111
119
|
await Promise.all(promises);
|
112
120
|
this.out.end();
|
@@ -391,11 +399,14 @@ class StormCodegen {
|
|
391
399
|
const blockRef = block.uri;
|
392
400
|
this.emitBlockStatus(blockUri, block.aiName, events_1.StormEventBlockStatusType.QA);
|
393
401
|
/* TODO: temporarily disabled - enable again when codegen is more stable
|
394
|
-
|
395
|
-
|
396
|
-
|
402
|
+
const filesToBeFixed = serviceFiles.concat(contextFiles).concat(screenFilesConverted);
|
403
|
+
const codeGenerator = new BlockCodeGenerator(blockDefinition);
|
404
|
+
*/
|
397
405
|
this.emitBlockStatus(blockUri, block.aiName, events_1.StormEventBlockStatusType.BUILDING);
|
398
406
|
// await this.verifyAndFixCode(blockUri, block.aiName, codeGenerator, basePath, filesToBeFixed, allFiles);
|
407
|
+
this.emitBlockStatusDone(basePath, block, blockRef);
|
408
|
+
}
|
409
|
+
emitBlockStatusDone(basePath, block, blockRef) {
|
399
410
|
this.out.emit('data', {
|
400
411
|
type: 'BLOCK_READY',
|
401
412
|
reason: 'Block ready',
|
@@ -784,6 +795,19 @@ class StormCodegen {
|
|
784
795
|
new codegen_1.CodeWriter(basePath).write(generatedResult);
|
785
796
|
return generatedResult;
|
786
797
|
}
|
798
|
+
async cloneArchetype(block) {
|
799
|
+
const predefinedBlock = predefined_1.PREDEFINED_BLOCKS.get(block.archetype);
|
800
|
+
let blockDefinition = await predefinedBlock.getBlockDefinition();
|
801
|
+
const kapetaURI = new nodejs_utils_1.KapetaURI(block.uri);
|
802
|
+
lodash_1.default.set(blockDefinition, ['metadata', 'name'], kapetaURI.fullName);
|
803
|
+
lodash_1.default.set(blockDefinition, ['metadata', 'title'], kapetaURI.name);
|
804
|
+
const basePath = this.getBasePath(blockDefinition.metadata.name);
|
805
|
+
let archetype = new archetype_1.Archetype();
|
806
|
+
const generatedResult = await archetype.cloneRepository(predefinedBlock, this.tmpDir, basePath);
|
807
|
+
await this.emitStaticFiles(kapetaURI, block.aiName, this.toStormFiles(generatedResult));
|
808
|
+
const blockRef = block.uri;
|
809
|
+
this.emitBlockStatusDone(basePath, block, blockRef);
|
810
|
+
}
|
787
811
|
abort() {
|
788
812
|
this.out.abort();
|
789
813
|
}
|
@@ -9,6 +9,7 @@ export interface BlockDefinitionInfo {
|
|
9
9
|
uri: string;
|
10
10
|
content: BlockDefinition;
|
11
11
|
aiName: string;
|
12
|
+
archetype?: string;
|
12
13
|
}
|
13
14
|
export interface StormDefinitions {
|
14
15
|
plan: Plan;
|
@@ -61,18 +62,20 @@ export declare class StormEventParser {
|
|
61
62
|
/**
|
62
63
|
* Builds plan and block definitions - and enriches events with relevant refs and ids
|
63
64
|
*/
|
64
|
-
processEvent(handle: string, evt: StormEvent): StormDefinitions
|
65
|
+
processEvent(handle: string, evt: StormEvent): Promise<StormDefinitions>;
|
65
66
|
getEvents(): StormEvent[];
|
66
67
|
isValid(): boolean;
|
67
68
|
getError(): string;
|
68
|
-
toResult(handle: string): StormDefinitions
|
69
|
-
toBlockDefinitions(handle: string): {
|
69
|
+
toResult(handle: string): Promise<StormDefinitions>;
|
70
|
+
toBlockDefinitions(handle: string): Promise<{
|
70
71
|
[key: string]: BlockDefinitionInfo;
|
71
|
-
}
|
72
|
+
}>;
|
73
|
+
private createBlockDefinitionInfo;
|
72
74
|
private toResourceKind;
|
73
75
|
private toBlockKind;
|
74
76
|
private toConnectionMapping;
|
75
77
|
private toPortType;
|
76
78
|
private toBlockTarget;
|
77
79
|
private toBlockTargetKind;
|
80
|
+
private resolveArchetypeBlockDefinition;
|
78
81
|
}
|