@kapeta/local-cluster-service 0.41.0 → 0.41.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,11 @@
1
+ ## [0.41.1](https://github.com/kapetacom/local-cluster-service/compare/v0.41.0...v0.41.1) (2024-04-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * better missing file handling [CORE-2685] ([1baf002](https://github.com/kapetacom/local-cluster-service/commit/1baf002c18c6acc92a4f6ca1bff37cda9270e487))
7
+ * bump local-cluster-config w/ improved error handling ([f9a945f](https://github.com/kapetacom/local-cluster-service/commit/f9a945f7761e472e45bc55839b40e563c5298719))
8
+
1
9
  # [0.41.0](https://github.com/kapetacom/local-cluster-service/compare/v0.40.6...v0.41.0) (2024-04-12)
2
10
 
3
11
 
@@ -25,10 +25,17 @@ const node_os_1 = __importDefault(require("node:os"));
25
25
  const CACHE_TTL = 60 * 60 * 1000; // 1 hour
26
26
  const UPGRADE_CHECK_INTERVAL = 10 * 60 * 1000; // 10 minutes
27
27
  const toKey = (ref) => `assetManager:asset:${ref}`;
28
- function filterExists(asset) {
29
- return fs_extra_1.default.existsSync(asset.path) && fs_extra_1.default.existsSync(asset.ymlPath);
30
- }
31
28
  function enrichAsset(asset) {
29
+ let exists = true;
30
+ let path = asset.path;
31
+ let ymlPath = asset.ymlPath;
32
+ try {
33
+ path = fs_extra_1.default.realpathSync(path);
34
+ ymlPath = fs_extra_1.default.realpathSync(ymlPath);
35
+ }
36
+ catch (e) {
37
+ exists = false;
38
+ }
32
39
  return {
33
40
  ref: `kapeta://${asset.definition.metadata.name}:${asset.version}`,
34
41
  editable: asset.version === 'local', //Only local versions are editable
@@ -36,8 +43,8 @@ function enrichAsset(asset) {
36
43
  version: asset.version,
37
44
  kind: asset.definition.kind,
38
45
  data: asset.definition,
39
- path: fs_extra_1.default.realpathSync(asset.path),
40
- ymlPath: fs_extra_1.default.realpathSync(asset.ymlPath),
46
+ path,
47
+ ymlPath,
41
48
  };
42
49
  }
43
50
  function compareRefs(a, b) {
@@ -86,7 +93,7 @@ class AssetManager {
86
93
  assetKinds.push('core/plan');
87
94
  }
88
95
  const assets = await definitionsManager_1.definitionsManager.getDefinitions(assetKinds);
89
- return assets.filter(filterExists).map(enrichAsset);
96
+ return assets.map(enrichAsset).filter((a) => a.exists);
90
97
  }
91
98
  async getPlans() {
92
99
  return this.getAssets(['core/plan']);
@@ -124,9 +131,14 @@ class AssetManager {
124
131
  throw new Error('Asset not found: ' + ref);
125
132
  }
126
133
  if (definitionInfo) {
127
- const asset = enrichAsset(definitionInfo);
128
- cacheManager_1.cacheManager.set(cacheKey, asset, CACHE_TTL);
129
- return asset;
134
+ try {
135
+ const asset = enrichAsset(definitionInfo);
136
+ cacheManager_1.cacheManager.set(cacheKey, asset, CACHE_TTL);
137
+ return asset;
138
+ }
139
+ catch (e) {
140
+ console.error('Failed to enrich asset', e);
141
+ }
130
142
  }
131
143
  return undefined;
132
144
  }
@@ -25,10 +25,17 @@ const node_os_1 = __importDefault(require("node:os"));
25
25
  const CACHE_TTL = 60 * 60 * 1000; // 1 hour
26
26
  const UPGRADE_CHECK_INTERVAL = 10 * 60 * 1000; // 10 minutes
27
27
  const toKey = (ref) => `assetManager:asset:${ref}`;
28
- function filterExists(asset) {
29
- return fs_extra_1.default.existsSync(asset.path) && fs_extra_1.default.existsSync(asset.ymlPath);
30
- }
31
28
  function enrichAsset(asset) {
29
+ let exists = true;
30
+ let path = asset.path;
31
+ let ymlPath = asset.ymlPath;
32
+ try {
33
+ path = fs_extra_1.default.realpathSync(path);
34
+ ymlPath = fs_extra_1.default.realpathSync(ymlPath);
35
+ }
36
+ catch (e) {
37
+ exists = false;
38
+ }
32
39
  return {
33
40
  ref: `kapeta://${asset.definition.metadata.name}:${asset.version}`,
34
41
  editable: asset.version === 'local', //Only local versions are editable
@@ -36,8 +43,8 @@ function enrichAsset(asset) {
36
43
  version: asset.version,
37
44
  kind: asset.definition.kind,
38
45
  data: asset.definition,
39
- path: fs_extra_1.default.realpathSync(asset.path),
40
- ymlPath: fs_extra_1.default.realpathSync(asset.ymlPath),
46
+ path,
47
+ ymlPath,
41
48
  };
42
49
  }
43
50
  function compareRefs(a, b) {
@@ -86,7 +93,7 @@ class AssetManager {
86
93
  assetKinds.push('core/plan');
87
94
  }
88
95
  const assets = await definitionsManager_1.definitionsManager.getDefinitions(assetKinds);
89
- return assets.filter(filterExists).map(enrichAsset);
96
+ return assets.map(enrichAsset).filter((a) => a.exists);
90
97
  }
91
98
  async getPlans() {
92
99
  return this.getAssets(['core/plan']);
@@ -124,9 +131,14 @@ class AssetManager {
124
131
  throw new Error('Asset not found: ' + ref);
125
132
  }
126
133
  if (definitionInfo) {
127
- const asset = enrichAsset(definitionInfo);
128
- cacheManager_1.cacheManager.set(cacheKey, asset, CACHE_TTL);
129
- return asset;
134
+ try {
135
+ const asset = enrichAsset(definitionInfo);
136
+ cacheManager_1.cacheManager.set(cacheKey, asset, CACHE_TTL);
137
+ return asset;
138
+ }
139
+ catch (e) {
140
+ console.error('Failed to enrich asset', e);
141
+ }
130
142
  }
131
143
  return undefined;
132
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.41.0",
3
+ "version": "0.41.1",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -50,7 +50,7 @@
50
50
  "dependencies": {
51
51
  "@kapeta/codegen": "^1.3.0",
52
52
  "@kapeta/config-mapper": "^1.2.0",
53
- "@kapeta/local-cluster-config": "^0.4.1",
53
+ "@kapeta/local-cluster-config": "^0.4.2",
54
54
  "@kapeta/nodejs-api-client": ">=0.2.0 <2",
55
55
  "@kapeta/nodejs-process": "^1.2.0",
56
56
  "@kapeta/nodejs-registry-utils": ">=0.11.1 <2",
@@ -36,11 +36,16 @@ export interface EnrichedAsset {
36
36
  ymlPath: string;
37
37
  }
38
38
 
39
- function filterExists(asset: DefinitionInfo): boolean {
40
- return FS.existsSync(asset.path) && FS.existsSync(asset.ymlPath);
41
- }
42
-
43
39
  function enrichAsset(asset: DefinitionInfo): EnrichedAsset {
40
+ let exists = true;
41
+ let path = asset.path;
42
+ let ymlPath = asset.ymlPath;
43
+ try {
44
+ path = FS.realpathSync(path);
45
+ ymlPath = FS.realpathSync(ymlPath);
46
+ } catch (e) {
47
+ exists = false;
48
+ }
44
49
  return {
45
50
  ref: `kapeta://${asset.definition.metadata.name}:${asset.version}`,
46
51
  editable: asset.version === 'local', //Only local versions are editable
@@ -48,8 +53,8 @@ function enrichAsset(asset: DefinitionInfo): EnrichedAsset {
48
53
  version: asset.version,
49
54
  kind: asset.definition.kind,
50
55
  data: asset.definition,
51
- path: FS.realpathSync(asset.path),
52
- ymlPath: FS.realpathSync(asset.ymlPath),
56
+ path,
57
+ ymlPath,
53
58
  };
54
59
  }
55
60
 
@@ -106,7 +111,7 @@ class AssetManager {
106
111
 
107
112
  const assets = await definitionsManager.getDefinitions(assetKinds);
108
113
 
109
- return assets.filter(filterExists).map(enrichAsset);
114
+ return assets.map(enrichAsset).filter((a) => a.exists);
110
115
  }
111
116
 
112
117
  async getPlans(): Promise<EnrichedAsset[]> {
@@ -159,9 +164,13 @@ class AssetManager {
159
164
  }
160
165
 
161
166
  if (definitionInfo) {
162
- const asset = enrichAsset(definitionInfo);
163
- cacheManager.set(cacheKey, asset, CACHE_TTL);
164
- return asset;
167
+ try {
168
+ const asset = enrichAsset(definitionInfo);
169
+ cacheManager.set(cacheKey, asset, CACHE_TTL);
170
+ return asset;
171
+ } catch (e) {
172
+ console.error('Failed to enrich asset', e);
173
+ }
165
174
  }
166
175
 
167
176
  return undefined;