@kapeta/local-cluster-service 0.54.12 → 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.
Files changed (42) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/definitions.d.ts +11 -0
  3. package/dist/cjs/src/storm/archetype.d.ts +12 -0
  4. package/dist/cjs/src/storm/archetype.js +98 -0
  5. package/dist/cjs/src/storm/codegen.d.ts +2 -0
  6. package/dist/cjs/src/storm/codegen.js +28 -4
  7. package/dist/cjs/src/storm/event-parser.d.ts +7 -4
  8. package/dist/cjs/src/storm/event-parser.js +190 -160
  9. package/dist/cjs/src/storm/events.d.ts +1 -0
  10. package/dist/cjs/src/storm/predefined.d.ts +27 -0
  11. package/dist/cjs/src/storm/predefined.js +64 -0
  12. package/dist/cjs/src/storm/routes.js +3 -3
  13. package/dist/cjs/test/storm/codegen.test.d.ts +5 -0
  14. package/dist/cjs/test/storm/codegen.test.js +41 -0
  15. package/dist/cjs/test/storm/event-parser.test.d.ts +25 -1
  16. package/dist/cjs/test/storm/event-parser.test.js +34 -15
  17. package/dist/cjs/test/storm/predefined-user-events.json +13 -0
  18. package/dist/esm/src/storm/archetype.d.ts +12 -0
  19. package/dist/esm/src/storm/archetype.js +98 -0
  20. package/dist/esm/src/storm/codegen.d.ts +2 -0
  21. package/dist/esm/src/storm/codegen.js +28 -4
  22. package/dist/esm/src/storm/event-parser.d.ts +7 -4
  23. package/dist/esm/src/storm/event-parser.js +190 -160
  24. package/dist/esm/src/storm/events.d.ts +1 -0
  25. package/dist/esm/src/storm/predefined.d.ts +27 -0
  26. package/dist/esm/src/storm/predefined.js +64 -0
  27. package/dist/esm/src/storm/routes.js +3 -3
  28. package/dist/esm/test/storm/codegen.test.d.ts +5 -0
  29. package/dist/esm/test/storm/codegen.test.js +41 -0
  30. package/dist/esm/test/storm/event-parser.test.d.ts +25 -1
  31. package/dist/esm/test/storm/event-parser.test.js +34 -15
  32. package/dist/esm/test/storm/predefined-user-events.json +13 -0
  33. package/package.json +6 -1
  34. package/src/storm/archetype.ts +85 -0
  35. package/src/storm/codegen.ts +34 -4
  36. package/src/storm/event-parser.ts +200 -159
  37. package/src/storm/events.ts +1 -0
  38. package/src/storm/predefined.ts +52 -0
  39. package/src/storm/routes.ts +3 -3
  40. package/test/storm/codegen.test.ts +46 -0
  41. package/test/storm/event-parser.test.ts +32 -10
  42. package/test/storm/predefined-user-events.json +13 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [0.55.0](https://github.com/kapetacom/local-cluster-service/compare/v0.54.12...v0.55.0) (2024-07-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * change test ([218f7d0](https://github.com/kapetacom/local-cluster-service/commit/218f7d0b485a5d045b59d52956fed9e09ed6e243))
7
+ * license ([0d3ff1b](https://github.com/kapetacom/local-cluster-service/commit/0d3ff1b4a6377fb874a1183465ff59bbca7ccae1))
8
+ * review comments ([094a5db](https://github.com/kapetacom/local-cluster-service/commit/094a5db73a70740cd7cddced0c9ff2094a723018))
9
+
10
+
11
+ ### Features
12
+
13
+ * support archetypes/predefined blocks in event parsing/codegen ([7929413](https://github.com/kapetacom/local-cluster-service/commit/7929413b90e901e7960be46efc5a1b3473935ddd))
14
+
1
15
  ## [0.54.12](https://github.com/kapetacom/local-cluster-service/compare/v0.54.11...v0.54.12) (2024-07-10)
2
16
 
3
17
 
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) {
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: file.name,
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);
79
+ }
80
+ }
81
+ }
82
+ await traverse(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
- return this.processBlockCode(block);
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
- const filesToBeFixed = serviceFiles.concat(contextFiles).concat(screenFilesConverted);
395
- const codeGenerator = new BlockCodeGenerator(blockDefinition);
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
  }
@@ -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).forEach(([, blockInfo]) => {
364
+ for (const [, blockInfo] of Object.entries(this.blocks)) {
360
365
  const blockRef = StormEventParser.toRef(handle, blockInfo.name);
361
- const blockDefinitionInfo = {
362
- uri: blockRef.toNormalizedString(),
363
- aiName: blockInfo.name,
364
- content: {
365
- kind: this.toBlockKind(blockInfo.type),
366
- metadata: {
367
- title: blockInfo.name,
368
- name: blockRef.fullName,
369
- description: blockInfo.description,
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
- spec: {
372
- entities: {
373
- types: [],
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
- target: this.toBlockTarget(handle, blockInfo.type),
381
- providers: [],
382
- consumers: [],
383
- },
384
- },
385
- };
386
- const blockSpec = blockDefinitionInfo.content.spec;
387
- const apiResources = {};
388
- let dbResource = undefined;
389
- (blockInfo.resources || []).forEach((resource) => {
390
- const port = {
391
- type: this.toPortType(resource.type),
392
- };
393
- switch (resource.type) {
394
- case 'API': {
395
- const apiResource = {
396
- kind: this.toResourceKind(resource.type),
397
- metadata: {
398
- name: resource.name,
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
- apiResources[resource.name] = apiResource;
412
- blockSpec.providers.push(apiResource);
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
- case 'CLIENT':
416
- blockSpec.consumers.push({
417
- kind: this.toResourceKind(resource.type),
418
- metadata: {
419
- name: resource.name,
420
- description: resource.description,
421
- },
422
- spec: {
423
- port,
424
- methods: {},
425
- source: {
426
- type: kaplang_core_1.KAPLANG_ID,
427
- version: kaplang_core_1.KAPLANG_VERSION,
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
- blockInfo.apis.forEach((api) => {
494
- const dslApi = kaplang_core_1.DSLAPIParser.parse(api, {
495
- ignoreSemantics: true,
496
- });
497
- let exactMatch = false;
498
- if (dslApi[0] && dslApi[0].type == kaplang_core_1.DSLEntityType.CONTROLLER) {
499
- const name = dslApi[0].name.toLowerCase();
500
- const apiResourceName = Object.keys(apiResources).find((key) => key.indexOf(name) > -1);
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
- if (!exactMatch) {
508
- // if we couldn't place the given api on the exact resource we just park it on the first
509
- // available rest resource
510
- const firstKey = Object.keys(apiResources)[0];
511
- const firstEntry = apiResources[firstKey];
512
- if (firstEntry) {
513
- firstEntry.spec.source.value += api + '\n\n';
514
- }
515
- else {
516
- console.warn('Unable to find resource for API', api);
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
- return result;
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;