@kapeta/local-cluster-service 0.13.0 → 0.14.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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [0.14.1](https://github.com/kapetacom/local-cluster-service/compare/v0.14.0...v0.14.1) (2023-08-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Generate code in the background ([#57](https://github.com/kapetacom/local-cluster-service/issues/57)) ([2e14827](https://github.com/kapetacom/local-cluster-service/commit/2e1482713ee52a19aed8edb9810107f1f340537c))
7
+
8
+ # [0.14.0](https://github.com/kapetacom/local-cluster-service/compare/v0.13.0...v0.14.0) (2023-08-05)
9
+
10
+
11
+ ### Features
12
+
13
+ * Added api proxy for remote services ([#56](https://github.com/kapetacom/local-cluster-service/issues/56)) ([ea2cba8](https://github.com/kapetacom/local-cluster-service/commit/ea2cba8936b422e4b17197c35ef656b501b740a5))
14
+
1
15
  # [0.13.0](https://github.com/kapetacom/local-cluster-service/compare/v0.12.1...v0.13.0) (2023-08-03)
2
16
 
3
17
 
package/dist/cjs/index.js CHANGED
@@ -21,6 +21,7 @@ const routes_7 = __importDefault(require("./src/assets/routes"));
21
21
  const routes_8 = __importDefault(require("./src/providers/routes"));
22
22
  const routes_9 = __importDefault(require("./src/attachments/routes"));
23
23
  const routes_10 = __importDefault(require("./src/tasks/routes"));
24
+ const api_1 = __importDefault(require("./src/api"));
24
25
  const utils_1 = require("./src/utils/utils");
25
26
  const request_1 = __importDefault(require("request"));
26
27
  let currentServer = null;
@@ -36,6 +37,7 @@ function createServer() {
36
37
  app.use('/providers', routes_8.default);
37
38
  app.use('/attachments', routes_9.default);
38
39
  app.use('/tasks', routes_10.default);
40
+ app.use('/api', api_1.default);
39
41
  app.get('/status', async (req, res) => {
40
42
  res.send({
41
43
  ok: true,
@@ -0,0 +1,3 @@
1
+ /// <reference types="express" />
2
+ declare const router: import("express").Router;
3
+ export default router;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const express_promise_router_1 = __importDefault(require("express-promise-router"));
7
+ const cors_1 = require("./middleware/cors");
8
+ const nodejs_api_client_1 = require("@kapeta/nodejs-api-client");
9
+ const local_cluster_config_1 = __importDefault(require("@kapeta/local-cluster-config"));
10
+ const { createAPIRoute } = require('@kapeta/web-microfrontend/server');
11
+ const packageJson = require('../package.json');
12
+ const router = (0, express_promise_router_1.default)();
13
+ const remoteServices = local_cluster_config_1.default.getClusterConfig().remoteServices ?? {};
14
+ router.use('/', cors_1.corsHandler);
15
+ router.use('/registry', createAPIRoute(remoteServices.registry ?? 'https://registry.kapeta.com', {
16
+ nonce: false,
17
+ userAgent: `KapetaDesktopCluster/${packageJson.version}`,
18
+ tokenFetcher: () => {
19
+ return new nodejs_api_client_1.KapetaAPI().getAccessToken();
20
+ }
21
+ }));
22
+ exports.default = router;
@@ -25,6 +25,7 @@ declare class AssetManager {
25
25
  getAsset(ref: string, noCache?: boolean, autoFetch?: boolean): Promise<EnrichedAsset | undefined>;
26
26
  createAsset(path: string, yaml: BlockDefinition): Promise<EnrichedAsset[]>;
27
27
  updateAsset(ref: string, yaml: BlockDefinition): Promise<void>;
28
+ private maybeGenerateCode;
28
29
  importFile(filePath: string): Promise<EnrichedAsset[]>;
29
30
  unregisterAsset(ref: string): Promise<void>;
30
31
  installAsset(ref: string): Promise<import("./taskManager").Task<void>[] | undefined>;
@@ -16,6 +16,7 @@ const repositoryManager_1 = require("./repositoryManager");
16
16
  const nodejs_registry_utils_1 = require("@kapeta/nodejs-registry-utils");
17
17
  const definitionsManager_1 = require("./definitionsManager");
18
18
  const utils_1 = require("./utils/utils");
19
+ const taskManager_1 = require("./taskManager");
19
20
  function enrichAsset(asset) {
20
21
  return {
21
22
  ref: `kapeta://${asset.definition.metadata.name}:${asset.version}`,
@@ -109,16 +110,18 @@ class AssetManager {
109
110
  if (!node_fs_1.default.existsSync(dirName)) {
110
111
  fs_extra_1.default.mkdirpSync(dirName);
111
112
  }
113
+ console.log('Wrote to ' + path);
112
114
  node_fs_1.default.writeFileSync(path, yaml_1.default.stringify(yaml));
113
115
  const asset = await this.importFile(path);
114
- if (codeGeneratorManager_1.codeGeneratorManager.canGenerateCode(yaml)) {
115
- await codeGeneratorManager_1.codeGeneratorManager.generate(path, yaml);
116
- }
116
+ console.log('Imported');
117
117
  this.cache.flushAll();
118
+ definitionsManager_1.definitionsManager.clearCache();
119
+ const ref = `kapeta://${yaml.metadata.name}:local`;
120
+ this.maybeGenerateCode(ref, path, yaml);
118
121
  return asset;
119
122
  }
120
123
  async updateAsset(ref, yaml) {
121
- const asset = await this.getAsset(ref, true);
124
+ const asset = await this.getAsset(ref, true, false);
122
125
  if (!asset) {
123
126
  throw new Error('Attempted to update unknown asset: ' + ref);
124
127
  }
@@ -128,14 +131,24 @@ class AssetManager {
128
131
  if (!asset.ymlPath) {
129
132
  throw new Error('Attempted to update corrupted asset: ' + ref);
130
133
  }
134
+ console.log('Wrote to ' + asset.ymlPath);
131
135
  node_fs_1.default.writeFileSync(asset.ymlPath, yaml_1.default.stringify(yaml));
132
136
  this.cache.flushAll();
133
- if (codeGeneratorManager_1.codeGeneratorManager.canGenerateCode(yaml)) {
134
- await codeGeneratorManager_1.codeGeneratorManager.generate(asset.ymlPath, yaml);
135
- }
136
- else {
137
- console.log('Could not generate code for %s', yaml.kind ? yaml.kind : 'unknown yaml');
137
+ definitionsManager_1.definitionsManager.clearCache();
138
+ this.maybeGenerateCode(asset.ref, asset.ymlPath, yaml);
139
+ }
140
+ maybeGenerateCode(ref, ymlPath, block) {
141
+ ref = (0, utils_1.normalizeKapetaUri)(ref);
142
+ if (codeGeneratorManager_1.codeGeneratorManager.canGenerateCode(block)) {
143
+ const assetTitle = block.metadata.title ? block.metadata.title : (0, nodejs_utils_1.parseKapetaUri)(block.metadata.name).name;
144
+ taskManager_1.taskManager.add(`codegen:${ref}`, async () => {
145
+ await codeGeneratorManager_1.codeGeneratorManager.generate(ymlPath, block);
146
+ }, {
147
+ name: `Generating code for ${assetTitle}`,
148
+ });
149
+ return true;
138
150
  }
151
+ return false;
139
152
  }
140
153
  async importFile(filePath) {
141
154
  if (filePath.startsWith('file://')) {
@@ -29,7 +29,7 @@ router.use('/', stringBody_1.stringBody);
29
29
  * Get all local assets available
30
30
  */
31
31
  router.get('/', (req, res) => {
32
- res.send(assetManager_1.assetManager.getAssets());
32
+ res.send(assetManager_1.assetManager.getAssets([]));
33
33
  });
34
34
  /**
35
35
  * Get single asset
@@ -130,7 +130,6 @@ class TaskManager {
130
130
  if (task.metadata.group) {
131
131
  const existingTaskInGroup = this._tasks.find((t) => t.id !== task.id && t.metadata.group === task.metadata.group && t.status === TaskStatus.RUNNING);
132
132
  if (existingTaskInGroup) {
133
- console.log('existingTaskInGroup', existingTaskInGroup.toData());
134
133
  return;
135
134
  }
136
135
  }
@@ -154,7 +153,6 @@ class TaskManager {
154
153
  if (task.metadata.group) {
155
154
  const nextTaskInGroup = this._tasks.find((t) => t.id !== task.id && t.metadata.group === task.metadata.group && t.status === TaskStatus.PENDING);
156
155
  if (nextTaskInGroup) {
157
- console.log('nextTaskInGroup', nextTaskInGroup.toData());
158
156
  return this.invokeTask(nextTaskInGroup);
159
157
  }
160
158
  }
package/dist/esm/index.js CHANGED
@@ -16,6 +16,7 @@ import AssetsRoutes from './src/assets/routes';
16
16
  import ProviderRoutes from './src/providers/routes';
17
17
  import AttachmentRoutes from './src/attachments/routes';
18
18
  import TaskRoutes from './src/tasks/routes';
19
+ import APIRoutes from './src/api';
19
20
  import { getBindHost } from './src/utils/utils';
20
21
  import request from 'request';
21
22
  let currentServer = null;
@@ -31,6 +32,7 @@ function createServer() {
31
32
  app.use('/providers', ProviderRoutes);
32
33
  app.use('/attachments', AttachmentRoutes);
33
34
  app.use('/tasks', TaskRoutes);
35
+ app.use('/api', APIRoutes);
34
36
  app.get('/status', async (req, res) => {
35
37
  res.send({
36
38
  ok: true,
@@ -0,0 +1,3 @@
1
+ /// <reference types="express" />
2
+ declare const router: import("express").Router;
3
+ export default router;
@@ -0,0 +1,17 @@
1
+ import Router from 'express-promise-router';
2
+ import { corsHandler } from "./middleware/cors";
3
+ import { KapetaAPI } from "@kapeta/nodejs-api-client";
4
+ import ClusterConfiguration from '@kapeta/local-cluster-config';
5
+ const { createAPIRoute } = require('@kapeta/web-microfrontend/server');
6
+ const packageJson = require('../package.json');
7
+ const router = Router();
8
+ const remoteServices = ClusterConfiguration.getClusterConfig().remoteServices ?? {};
9
+ router.use('/', corsHandler);
10
+ router.use('/registry', createAPIRoute(remoteServices.registry ?? 'https://registry.kapeta.com', {
11
+ nonce: false,
12
+ userAgent: `KapetaDesktopCluster/${packageJson.version}`,
13
+ tokenFetcher: () => {
14
+ return new KapetaAPI().getAccessToken();
15
+ }
16
+ }));
17
+ export default router;
@@ -25,6 +25,7 @@ declare class AssetManager {
25
25
  getAsset(ref: string, noCache?: boolean, autoFetch?: boolean): Promise<EnrichedAsset | undefined>;
26
26
  createAsset(path: string, yaml: BlockDefinition): Promise<EnrichedAsset[]>;
27
27
  updateAsset(ref: string, yaml: BlockDefinition): Promise<void>;
28
+ private maybeGenerateCode;
28
29
  importFile(filePath: string): Promise<EnrichedAsset[]>;
29
30
  unregisterAsset(ref: string): Promise<void>;
30
31
  installAsset(ref: string): Promise<import("./taskManager").Task<void>[] | undefined>;
@@ -10,6 +10,7 @@ import { repositoryManager } from './repositoryManager';
10
10
  import { Actions } from '@kapeta/nodejs-registry-utils';
11
11
  import { definitionsManager } from './definitionsManager';
12
12
  import { normalizeKapetaUri } from './utils/utils';
13
+ import { taskManager } from "./taskManager";
13
14
  function enrichAsset(asset) {
14
15
  return {
15
16
  ref: `kapeta://${asset.definition.metadata.name}:${asset.version}`,
@@ -103,16 +104,18 @@ class AssetManager {
103
104
  if (!FS.existsSync(dirName)) {
104
105
  FSExtra.mkdirpSync(dirName);
105
106
  }
107
+ console.log('Wrote to ' + path);
106
108
  FS.writeFileSync(path, YAML.stringify(yaml));
107
109
  const asset = await this.importFile(path);
108
- if (codeGeneratorManager.canGenerateCode(yaml)) {
109
- await codeGeneratorManager.generate(path, yaml);
110
- }
110
+ console.log('Imported');
111
111
  this.cache.flushAll();
112
+ definitionsManager.clearCache();
113
+ const ref = `kapeta://${yaml.metadata.name}:local`;
114
+ this.maybeGenerateCode(ref, path, yaml);
112
115
  return asset;
113
116
  }
114
117
  async updateAsset(ref, yaml) {
115
- const asset = await this.getAsset(ref, true);
118
+ const asset = await this.getAsset(ref, true, false);
116
119
  if (!asset) {
117
120
  throw new Error('Attempted to update unknown asset: ' + ref);
118
121
  }
@@ -122,14 +125,24 @@ class AssetManager {
122
125
  if (!asset.ymlPath) {
123
126
  throw new Error('Attempted to update corrupted asset: ' + ref);
124
127
  }
128
+ console.log('Wrote to ' + asset.ymlPath);
125
129
  FS.writeFileSync(asset.ymlPath, YAML.stringify(yaml));
126
130
  this.cache.flushAll();
127
- if (codeGeneratorManager.canGenerateCode(yaml)) {
128
- await codeGeneratorManager.generate(asset.ymlPath, yaml);
129
- }
130
- else {
131
- console.log('Could not generate code for %s', yaml.kind ? yaml.kind : 'unknown yaml');
131
+ definitionsManager.clearCache();
132
+ this.maybeGenerateCode(asset.ref, asset.ymlPath, yaml);
133
+ }
134
+ maybeGenerateCode(ref, ymlPath, block) {
135
+ ref = normalizeKapetaUri(ref);
136
+ if (codeGeneratorManager.canGenerateCode(block)) {
137
+ const assetTitle = block.metadata.title ? block.metadata.title : parseKapetaUri(block.metadata.name).name;
138
+ taskManager.add(`codegen:${ref}`, async () => {
139
+ await codeGeneratorManager.generate(ymlPath, block);
140
+ }, {
141
+ name: `Generating code for ${assetTitle}`,
142
+ });
143
+ return true;
132
144
  }
145
+ return false;
133
146
  }
134
147
  async importFile(filePath) {
135
148
  if (filePath.startsWith('file://')) {
@@ -24,7 +24,7 @@ router.use('/', stringBody);
24
24
  * Get all local assets available
25
25
  */
26
26
  router.get('/', (req, res) => {
27
- res.send(assetManager.getAssets());
27
+ res.send(assetManager.getAssets([]));
28
28
  });
29
29
  /**
30
30
  * Get single asset
@@ -126,7 +126,6 @@ class TaskManager {
126
126
  if (task.metadata.group) {
127
127
  const existingTaskInGroup = this._tasks.find((t) => t.id !== task.id && t.metadata.group === task.metadata.group && t.status === TaskStatus.RUNNING);
128
128
  if (existingTaskInGroup) {
129
- console.log('existingTaskInGroup', existingTaskInGroup.toData());
130
129
  return;
131
130
  }
132
131
  }
@@ -150,7 +149,6 @@ class TaskManager {
150
149
  if (task.metadata.group) {
151
150
  const nextTaskInGroup = this._tasks.find((t) => t.id !== task.id && t.metadata.group === task.metadata.group && t.status === TaskStatus.PENDING);
152
151
  if (nextTaskInGroup) {
153
- console.log('nextTaskInGroup', nextTaskInGroup.toData());
154
152
  return this.invokeTask(nextTaskInGroup);
155
153
  }
156
154
  }
package/index.ts CHANGED
@@ -17,8 +17,13 @@ import AssetsRoutes from './src/assets/routes';
17
17
  import ProviderRoutes from './src/providers/routes';
18
18
  import AttachmentRoutes from './src/attachments/routes';
19
19
  import TaskRoutes from './src/tasks/routes';
20
+ import APIRoutes from './src/api';
20
21
  import { getBindHost } from './src/utils/utils';
21
22
  import request from 'request';
23
+ import ClusterConfiguration from "@kapeta/local-cluster-config";
24
+ import {KapetaAPI} from "@kapeta/nodejs-api-client";
25
+ import {corsHandler} from "./src/middleware/cors";
26
+
22
27
 
23
28
  export type LocalClusterService = HTTP.Server & { host?: string; port?: number };
24
29
 
@@ -38,6 +43,8 @@ function createServer() {
38
43
  app.use('/providers', ProviderRoutes);
39
44
  app.use('/attachments', AttachmentRoutes);
40
45
  app.use('/tasks', TaskRoutes);
46
+ app.use('/api', APIRoutes);
47
+
41
48
  app.get('/status', async (req, res) => {
42
49
  res.send({
43
50
  ok: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.13.0",
3
+ "version": "0.14.1",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -50,6 +50,7 @@
50
50
  "@kapeta/nodejs-utils": "<2",
51
51
  "@kapeta/schemas": "^0.0.58",
52
52
  "@kapeta/sdk-config": "<2",
53
+ "@kapeta/web-microfrontend": "^0.2.1",
53
54
  "async-lock": "^1.4.0",
54
55
  "express": "4.17.1",
55
56
  "express-promise-router": "^4.1.1",
package/src/api.ts ADDED
@@ -0,0 +1,21 @@
1
+ import Router from 'express-promise-router';
2
+ import {corsHandler} from "./middleware/cors";
3
+ import {KapetaAPI} from "@kapeta/nodejs-api-client";
4
+ import ClusterConfiguration from '@kapeta/local-cluster-config';
5
+ const { createAPIRoute } = require('@kapeta/web-microfrontend/server');
6
+ const packageJson = require('../package.json');
7
+
8
+ const router = Router();
9
+
10
+ const remoteServices = ClusterConfiguration.getClusterConfig().remoteServices ?? {};
11
+ router.use('/', corsHandler)
12
+
13
+ router.use('/registry', createAPIRoute(remoteServices.registry ?? 'https://registry.kapeta.com', {
14
+ nonce: false,
15
+ userAgent: `KapetaDesktopCluster/${packageJson.version}`,
16
+ tokenFetcher: () => {
17
+ return new KapetaAPI().getAccessToken();
18
+ }
19
+ }));
20
+
21
+ export default router;
@@ -12,6 +12,7 @@ import { BlockDefinition } from '@kapeta/schemas';
12
12
  import { Actions } from '@kapeta/nodejs-registry-utils';
13
13
  import { definitionsManager } from './definitionsManager';
14
14
  import { normalizeKapetaUri } from './utils/utils';
15
+ import {taskManager} from "./taskManager";
15
16
 
16
17
  export interface EnrichedAsset {
17
18
  ref: string;
@@ -141,19 +142,24 @@ class AssetManager {
141
142
  FSExtra.mkdirpSync(dirName);
142
143
  }
143
144
 
145
+ console.log('Wrote to ' + path);
144
146
  FS.writeFileSync(path, YAML.stringify(yaml));
145
147
 
146
148
  const asset = await this.importFile(path);
149
+ console.log('Imported');
147
150
 
148
- if (codeGeneratorManager.canGenerateCode(yaml)) {
149
- await codeGeneratorManager.generate(path, yaml);
150
- }
151
151
  this.cache.flushAll();
152
+ definitionsManager.clearCache();
153
+
154
+ const ref = `kapeta://${yaml.metadata.name}:local`;
155
+
156
+ this.maybeGenerateCode(ref, path, yaml);
157
+
152
158
  return asset;
153
159
  }
154
160
 
155
161
  async updateAsset(ref: string, yaml: BlockDefinition) {
156
- const asset = await this.getAsset(ref, true);
162
+ const asset = await this.getAsset(ref, true, false);
157
163
  if (!asset) {
158
164
  throw new Error('Attempted to update unknown asset: ' + ref);
159
165
  }
@@ -166,13 +172,26 @@ class AssetManager {
166
172
  throw new Error('Attempted to update corrupted asset: ' + ref);
167
173
  }
168
174
 
175
+ console.log('Wrote to ' + asset.ymlPath);
169
176
  FS.writeFileSync(asset.ymlPath, YAML.stringify(yaml));
170
177
  this.cache.flushAll();
171
- if (codeGeneratorManager.canGenerateCode(yaml)) {
172
- await codeGeneratorManager.generate(asset.ymlPath, yaml);
173
- } else {
174
- console.log('Could not generate code for %s', yaml.kind ? yaml.kind : 'unknown yaml');
178
+ definitionsManager.clearCache();
179
+
180
+ this.maybeGenerateCode(asset.ref, asset.ymlPath, yaml);
181
+ }
182
+
183
+ private maybeGenerateCode(ref:string, ymlPath:string, block: BlockDefinition) {
184
+ ref = normalizeKapetaUri(ref);
185
+ if (codeGeneratorManager.canGenerateCode(block)) {
186
+ const assetTitle = block.metadata.title ? block.metadata.title : parseKapetaUri(block.metadata.name).name;
187
+ taskManager.add(`codegen:${ref}`, async () => {
188
+ await codeGeneratorManager.generate(ymlPath, block);
189
+ },{
190
+ name: `Generating code for ${assetTitle}`,
191
+ });
192
+ return true;
175
193
  }
194
+ return false;
176
195
  }
177
196
 
178
197
  async importFile(filePath: string) {
@@ -32,7 +32,7 @@ router.use('/', stringBody);
32
32
  * Get all local assets available
33
33
  */
34
34
  router.get('/', (req: Request, res: Response) => {
35
- res.send(assetManager.getAssets());
35
+ res.send(assetManager.getAssets([]));
36
36
  });
37
37
 
38
38
  /**
@@ -189,7 +189,6 @@ class TaskManager {
189
189
  );
190
190
 
191
191
  if (existingTaskInGroup) {
192
- console.log('existingTaskInGroup', existingTaskInGroup.toData());
193
192
  return;
194
193
  }
195
194
  }
@@ -215,7 +214,6 @@ class TaskManager {
215
214
  (t) => t.id !== task.id && t.metadata.group === task.metadata.group && t.status === TaskStatus.PENDING
216
215
  );
217
216
  if (nextTaskInGroup) {
218
- console.log('nextTaskInGroup', nextTaskInGroup.toData());
219
217
  return this.invokeTask(nextTaskInGroup);
220
218
  }
221
219
  }