@kapeta/local-cluster-service 0.5.9 → 0.5.10

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,10 @@
1
+ ## [0.5.10](https://github.com/kapetacom/local-cluster-service/compare/v0.5.9...v0.5.10) (2023-06-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * delete asset via ref ([6b5a968](https://github.com/kapetacom/local-cluster-service/commit/6b5a968a029753baea3a651a0538468086cda665))
7
+
1
8
  ## [0.5.9](https://github.com/kapetacom/local-cluster-service/compare/v0.5.8...v0.5.9) (2023-06-18)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -1,14 +1,14 @@
1
- const Path = require("node:path");
1
+ const Path = require('node:path');
2
2
  const FS = require('node:fs');
3
3
  const FSExtra = require('fs-extra');
4
4
  const YAML = require('yaml');
5
5
  const ClusterConfiguration = require('@kapeta/local-cluster-config').default;
6
- const {Actions} = require('@kapeta/nodejs-registry-utils');
6
+ const { Actions } = require('@kapeta/nodejs-registry-utils');
7
7
  const codeGeneratorManager = require('./codeGeneratorManager');
8
8
  const progressListener = require('./progressListener');
9
- const {parseKapetaUri} = require("@kapeta/nodejs-utils");
10
- const repositoryManager = require("./repositoryManager");
11
- const NodeCache = require("node-cache");
9
+ const { parseKapetaUri } = require('@kapeta/nodejs-utils');
10
+ const repositoryManager = require('./repositoryManager');
11
+ const NodeCache = require('node-cache');
12
12
 
13
13
  function enrichAsset(asset) {
14
14
  return {
@@ -19,8 +19,8 @@ function enrichAsset(asset) {
19
19
  kind: asset.definition.kind,
20
20
  data: asset.definition,
21
21
  path: asset.path,
22
- ymlPath: asset.ymlPath
23
- }
22
+ ymlPath: asset.ymlPath,
23
+ };
24
24
  }
25
25
 
26
26
  function compareRefs(a, b) {
@@ -30,29 +30,21 @@ function compareRefs(a, b) {
30
30
  return aProtocol === bProtocol && aId === bId;
31
31
  }
32
32
  function parseRef(ref) {
33
- let out = ref.split(/:\/\//,2);
33
+ let out = ref.split(/:\/\//, 2);
34
34
 
35
35
  if (out.length === 1) {
36
- return [
37
- 'kapeta',
38
- ref.toLowerCase()
39
- ]
36
+ return ['kapeta', ref.toLowerCase()];
40
37
  }
41
- return [
42
- out[0].toLowerCase(),
43
- out[1].toLowerCase()
44
- ];
38
+ return [out[0].toLowerCase(), out[1].toLowerCase()];
45
39
  }
46
40
 
47
41
  class AssetManager {
48
-
49
42
  constructor() {
50
43
  this.cache = new NodeCache({
51
44
  stdTTL: 60 * 60, // 1 hour
52
- })
45
+ });
53
46
  }
54
47
 
55
-
56
48
  /**
57
49
  *
58
50
  * @param {string[]} [assetKinds]
@@ -62,10 +54,10 @@ class AssetManager {
62
54
  if (!assetKinds) {
63
55
  const blockTypeProviders = ClusterConfiguration.getDefinitions([
64
56
  'core/block-type',
65
- 'core/block-type-operator'
57
+ 'core/block-type-operator',
66
58
  ]);
67
- assetKinds = blockTypeProviders.map(p => {
68
- return `${p.definition.metadata.name}:${p.version}`
59
+ assetKinds = blockTypeProviders.map((p) => {
60
+ return `${p.definition.metadata.name}:${p.version}`;
69
61
  });
70
62
  assetKinds.push('core/plan');
71
63
  }
@@ -80,7 +72,6 @@ class AssetManager {
80
72
  }
81
73
 
82
74
  async getPlan(ref, noCache = false) {
83
-
84
75
  const asset = await this.getAsset(ref, noCache);
85
76
 
86
77
  if ('core/plan' !== asset.kind) {
@@ -100,7 +91,7 @@ class AssetManager {
100
91
 
101
92
  let asset = ClusterConfiguration.getDefinitions()
102
93
  .map(enrichAsset)
103
- .find(a => parseKapetaUri(a.ref).equals(uri));
94
+ .find((a) => parseKapetaUri(a.ref).equals(uri));
104
95
 
105
96
  if (!asset) {
106
97
  throw new Error('Asset not found: ' + ref);
@@ -149,7 +140,10 @@ class AssetManager {
149
140
  if (codeGeneratorManager.canGenerateCode(yaml)) {
150
141
  await codeGeneratorManager.generate(asset.ymlPath, yaml);
151
142
  } else {
152
- console.log('Could not generate code for %s', yaml.kind ? yaml.kind : 'unknown yaml');
143
+ console.log(
144
+ 'Could not generate code for %s',
145
+ yaml.kind ? yaml.kind : 'unknown yaml'
146
+ );
153
147
  }
154
148
  }
155
149
 
@@ -162,15 +156,20 @@ class AssetManager {
162
156
  throw new Error('File not found: ' + filePath);
163
157
  }
164
158
 
165
- const assetInfos = YAML.parseAllDocuments(FS.readFileSync(filePath).toString())
166
- .map(doc => doc.toJSON());
159
+ const assetInfos = YAML.parseAllDocuments(
160
+ FS.readFileSync(filePath).toString()
161
+ ).map((doc) => doc.toJSON());
167
162
 
168
163
  await Actions.link(progressListener, Path.dirname(filePath));
169
164
 
170
165
  const version = 'local';
171
- const refs = assetInfos.map(assetInfo => `kapeta://${assetInfo.metadata.name}:${version}`);
166
+ const refs = assetInfos.map(
167
+ (assetInfo) => `kapeta://${assetInfo.metadata.name}:${version}`
168
+ );
172
169
  this.cache.flushAll();
173
- return this.getAssets().filter(a => refs.some(ref => compareRefs(ref, a.ref)));
170
+ return this.getAssets().filter((a) =>
171
+ refs.some((ref) => compareRefs(ref, a.ref))
172
+ );
174
173
  }
175
174
 
176
175
  async unregisterAsset(ref) {
@@ -179,7 +178,7 @@ class AssetManager {
179
178
  throw new Error('Asset does not exists: ' + ref);
180
179
  }
181
180
  this.cache.flushAll();
182
- await Actions.uninstall(progressListener, asset.path);
181
+ await Actions.uninstall(progressListener, [asset.ref]);
183
182
  }
184
183
  }
185
184