@kapeta/local-cluster-service 0.24.1 → 0.24.3
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 +14 -0
- package/dist/cjs/src/RepositoryWatcher.d.ts +1 -0
- package/dist/cjs/src/RepositoryWatcher.js +23 -5
- package/dist/cjs/src/assetManager.d.ts +1 -1
- package/dist/cjs/src/assetManager.js +1 -1
- package/dist/cjs/src/codeGeneratorManager.d.ts +3 -3
- package/dist/esm/src/RepositoryWatcher.d.ts +1 -0
- package/dist/esm/src/RepositoryWatcher.js +23 -5
- package/dist/esm/src/assetManager.d.ts +1 -1
- package/dist/esm/src/assetManager.js +1 -1
- package/dist/esm/src/codeGeneratorManager.d.ts +3 -3
- package/package.json +1 -1
- package/src/RepositoryWatcher.ts +29 -13
- package/src/assetManager.ts +3 -3
- package/src/codeGeneratorManager.ts +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [0.24.3](https://github.com/kapetacom/local-cluster-service/compare/v0.24.2...v0.24.3) (2023-10-28)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Handle renaming of local assets ([#92](https://github.com/kapetacom/local-cluster-service/issues/92)) ([2a8d278](https://github.com/kapetacom/local-cluster-service/commit/2a8d2785ae45f548333d6a177ed6b6096fa39c3c))
|
7
|
+
|
8
|
+
## [0.24.2](https://github.com/kapetacom/local-cluster-service/compare/v0.24.1...v0.24.2) (2023-10-27)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* Do not ensure when unregistering ([#91](https://github.com/kapetacom/local-cluster-service/issues/91)) ([3957d51](https://github.com/kapetacom/local-cluster-service/commit/3957d513ce3fd9064a36cea438967ae5a0a50720))
|
14
|
+
|
1
15
|
## [0.24.1](https://github.com/kapetacom/local-cluster-service/compare/v0.24.0...v0.24.1) (2023-10-27)
|
2
16
|
|
3
17
|
|
@@ -14,6 +14,7 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
14
14
|
const socketManager_1 = require("./socketManager");
|
15
15
|
const cacheManager_1 = require("./cacheManager");
|
16
16
|
const node_events_1 = require("node:events");
|
17
|
+
const assetManager_1 = require("./assetManager");
|
17
18
|
const KAPETA_YML_RX = /^kapeta.ya?ml$/;
|
18
19
|
class RepositoryWatcher extends node_events_1.EventEmitter {
|
19
20
|
watcher;
|
@@ -134,11 +135,11 @@ class RepositoryWatcher extends node_events_1.EventEmitter {
|
|
134
135
|
if (!path) {
|
135
136
|
return;
|
136
137
|
}
|
137
|
-
|
138
|
-
if (!assetIdentity) {
|
138
|
+
if (this.disabled) {
|
139
139
|
return;
|
140
140
|
}
|
141
|
-
|
141
|
+
const assetIdentity = await this.getAssetIdentity(path);
|
142
|
+
if (!assetIdentity) {
|
142
143
|
return;
|
143
144
|
}
|
144
145
|
// If this is false it's because we're watching a symlink target
|
@@ -156,13 +157,31 @@ class RepositoryWatcher extends node_events_1.EventEmitter {
|
|
156
157
|
await this.updateSymlinkTarget(path);
|
157
158
|
}
|
158
159
|
}
|
160
|
+
const repoPath = this.getRepositoryPath(assetIdentity);
|
161
|
+
if (eventName === 'change' &&
|
162
|
+
!withinRepo &&
|
163
|
+
assetIdentity.version === 'local' &&
|
164
|
+
node_path_1.default.basename(path) === 'kapeta.yml' &&
|
165
|
+
(await this.exists(path)) &&
|
166
|
+
!(await this.exists(repoPath))) {
|
167
|
+
// This happens when a local asset is renamed
|
168
|
+
const oldPath = lodash_1.default.findKey(this.symbolicLinks, (link) => link === path);
|
169
|
+
if (oldPath) {
|
170
|
+
await fs_extra_1.default.unlink(oldPath);
|
171
|
+
await assetManager_1.assetManager.importFile(path);
|
172
|
+
return;
|
173
|
+
}
|
174
|
+
}
|
159
175
|
const sourceOfChange = this.sourceOfChange.get(path) ?? 'filesystem';
|
160
176
|
await this.checkForChange(assetIdentity, sourceOfChange);
|
161
177
|
// We consume the sourceOfChange when the file is changed
|
162
178
|
this.sourceOfChange.delete(path);
|
163
179
|
}
|
180
|
+
getRepositoryPath(assetIdentity) {
|
181
|
+
return node_path_1.default.join(this.baseDir, assetIdentity.handle, assetIdentity.name, assetIdentity.version);
|
182
|
+
}
|
164
183
|
async checkForChange(assetIdentity, sourceOfChange) {
|
165
|
-
const ymlPath = node_path_1.default.join(this.
|
184
|
+
const ymlPath = node_path_1.default.join(this.getRepositoryPath(assetIdentity), 'kapeta.yml');
|
166
185
|
const newDefinitions = local_cluster_config_1.default.getDefinitions();
|
167
186
|
const newDefinition = newDefinitions.find((d) => d.ymlPath === ymlPath);
|
168
187
|
let currentDefinition = this.allDefinitions.find((d) => d.ymlPath === ymlPath);
|
@@ -187,7 +206,6 @@ class RepositoryWatcher extends node_events_1.EventEmitter {
|
|
187
206
|
}
|
188
207
|
else {
|
189
208
|
if (currentDefinition) {
|
190
|
-
const ref = (0, nodejs_utils_1.parseKapetaUri)(`${currentDefinition.definition.metadata.name}:${currentDefinition.version}`).id;
|
191
209
|
//Something was removed
|
192
210
|
type = 'removed';
|
193
211
|
}
|
@@ -23,7 +23,7 @@ declare class AssetManager {
|
|
23
23
|
getBlockInstance(systemId: string, instanceId: string): Promise<BlockInstance>;
|
24
24
|
getAsset(ref: string, noCache?: boolean, autoFetch?: boolean): Promise<EnrichedAsset | undefined>;
|
25
25
|
createAsset(path: string, yaml: BlockDefinition, sourceOfChange?: SourceOfChange): Promise<EnrichedAsset[]>;
|
26
|
-
updateAsset(ref: string, yaml:
|
26
|
+
updateAsset(ref: string, yaml: Definition, sourceOfChange?: SourceOfChange): Promise<void>;
|
27
27
|
importFile(filePath: string): Promise<EnrichedAsset[]>;
|
28
28
|
unregisterAsset(ref: string): Promise<void>;
|
29
29
|
installAsset(ref: string, wait?: boolean): Promise<import("./taskManager").Task<void>[] | undefined>;
|
@@ -166,7 +166,7 @@ class AssetManager {
|
|
166
166
|
return assets.filter((a) => refs.some((ref) => compareRefs(ref, a.ref)));
|
167
167
|
}
|
168
168
|
async unregisterAsset(ref) {
|
169
|
-
const asset = await this.getAsset(ref, true);
|
169
|
+
const asset = await this.getAsset(ref, true, false);
|
170
170
|
if (!asset) {
|
171
171
|
throw new Error('Asset does not exists: ' + ref);
|
172
172
|
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import { Definition } from '@kapeta/local-cluster-config';
|
2
2
|
declare class CodeGeneratorManager {
|
3
3
|
private ensureLanguageTargetInRegistry;
|
4
4
|
reload(): Promise<void>;
|
5
5
|
initialize(): Promise<void>;
|
6
|
-
canGenerateCode(yamlContent:
|
7
|
-
generate(yamlFile: string, yamlContent:
|
6
|
+
canGenerateCode(yamlContent: Definition): Promise<boolean>;
|
7
|
+
generate(yamlFile: string, yamlContent: Definition): Promise<void>;
|
8
8
|
}
|
9
9
|
export declare const codeGeneratorManager: CodeGeneratorManager;
|
10
10
|
export {};
|
@@ -14,6 +14,7 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
14
14
|
const socketManager_1 = require("./socketManager");
|
15
15
|
const cacheManager_1 = require("./cacheManager");
|
16
16
|
const node_events_1 = require("node:events");
|
17
|
+
const assetManager_1 = require("./assetManager");
|
17
18
|
const KAPETA_YML_RX = /^kapeta.ya?ml$/;
|
18
19
|
class RepositoryWatcher extends node_events_1.EventEmitter {
|
19
20
|
watcher;
|
@@ -134,11 +135,11 @@ class RepositoryWatcher extends node_events_1.EventEmitter {
|
|
134
135
|
if (!path) {
|
135
136
|
return;
|
136
137
|
}
|
137
|
-
|
138
|
-
if (!assetIdentity) {
|
138
|
+
if (this.disabled) {
|
139
139
|
return;
|
140
140
|
}
|
141
|
-
|
141
|
+
const assetIdentity = await this.getAssetIdentity(path);
|
142
|
+
if (!assetIdentity) {
|
142
143
|
return;
|
143
144
|
}
|
144
145
|
// If this is false it's because we're watching a symlink target
|
@@ -156,13 +157,31 @@ class RepositoryWatcher extends node_events_1.EventEmitter {
|
|
156
157
|
await this.updateSymlinkTarget(path);
|
157
158
|
}
|
158
159
|
}
|
160
|
+
const repoPath = this.getRepositoryPath(assetIdentity);
|
161
|
+
if (eventName === 'change' &&
|
162
|
+
!withinRepo &&
|
163
|
+
assetIdentity.version === 'local' &&
|
164
|
+
node_path_1.default.basename(path) === 'kapeta.yml' &&
|
165
|
+
(await this.exists(path)) &&
|
166
|
+
!(await this.exists(repoPath))) {
|
167
|
+
// This happens when a local asset is renamed
|
168
|
+
const oldPath = lodash_1.default.findKey(this.symbolicLinks, (link) => link === path);
|
169
|
+
if (oldPath) {
|
170
|
+
await fs_extra_1.default.unlink(oldPath);
|
171
|
+
await assetManager_1.assetManager.importFile(path);
|
172
|
+
return;
|
173
|
+
}
|
174
|
+
}
|
159
175
|
const sourceOfChange = this.sourceOfChange.get(path) ?? 'filesystem';
|
160
176
|
await this.checkForChange(assetIdentity, sourceOfChange);
|
161
177
|
// We consume the sourceOfChange when the file is changed
|
162
178
|
this.sourceOfChange.delete(path);
|
163
179
|
}
|
180
|
+
getRepositoryPath(assetIdentity) {
|
181
|
+
return node_path_1.default.join(this.baseDir, assetIdentity.handle, assetIdentity.name, assetIdentity.version);
|
182
|
+
}
|
164
183
|
async checkForChange(assetIdentity, sourceOfChange) {
|
165
|
-
const ymlPath = node_path_1.default.join(this.
|
184
|
+
const ymlPath = node_path_1.default.join(this.getRepositoryPath(assetIdentity), 'kapeta.yml');
|
166
185
|
const newDefinitions = local_cluster_config_1.default.getDefinitions();
|
167
186
|
const newDefinition = newDefinitions.find((d) => d.ymlPath === ymlPath);
|
168
187
|
let currentDefinition = this.allDefinitions.find((d) => d.ymlPath === ymlPath);
|
@@ -187,7 +206,6 @@ class RepositoryWatcher extends node_events_1.EventEmitter {
|
|
187
206
|
}
|
188
207
|
else {
|
189
208
|
if (currentDefinition) {
|
190
|
-
const ref = (0, nodejs_utils_1.parseKapetaUri)(`${currentDefinition.definition.metadata.name}:${currentDefinition.version}`).id;
|
191
209
|
//Something was removed
|
192
210
|
type = 'removed';
|
193
211
|
}
|
@@ -23,7 +23,7 @@ declare class AssetManager {
|
|
23
23
|
getBlockInstance(systemId: string, instanceId: string): Promise<BlockInstance>;
|
24
24
|
getAsset(ref: string, noCache?: boolean, autoFetch?: boolean): Promise<EnrichedAsset | undefined>;
|
25
25
|
createAsset(path: string, yaml: BlockDefinition, sourceOfChange?: SourceOfChange): Promise<EnrichedAsset[]>;
|
26
|
-
updateAsset(ref: string, yaml:
|
26
|
+
updateAsset(ref: string, yaml: Definition, sourceOfChange?: SourceOfChange): Promise<void>;
|
27
27
|
importFile(filePath: string): Promise<EnrichedAsset[]>;
|
28
28
|
unregisterAsset(ref: string): Promise<void>;
|
29
29
|
installAsset(ref: string, wait?: boolean): Promise<import("./taskManager").Task<void>[] | undefined>;
|
@@ -166,7 +166,7 @@ class AssetManager {
|
|
166
166
|
return assets.filter((a) => refs.some((ref) => compareRefs(ref, a.ref)));
|
167
167
|
}
|
168
168
|
async unregisterAsset(ref) {
|
169
|
-
const asset = await this.getAsset(ref, true);
|
169
|
+
const asset = await this.getAsset(ref, true, false);
|
170
170
|
if (!asset) {
|
171
171
|
throw new Error('Asset does not exists: ' + ref);
|
172
172
|
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import { Definition } from '@kapeta/local-cluster-config';
|
2
2
|
declare class CodeGeneratorManager {
|
3
3
|
private ensureLanguageTargetInRegistry;
|
4
4
|
reload(): Promise<void>;
|
5
5
|
initialize(): Promise<void>;
|
6
|
-
canGenerateCode(yamlContent:
|
7
|
-
generate(yamlFile: string, yamlContent:
|
6
|
+
canGenerateCode(yamlContent: Definition): Promise<boolean>;
|
7
|
+
generate(yamlFile: string, yamlContent: Definition): Promise<void>;
|
8
8
|
}
|
9
9
|
export declare const codeGeneratorManager: CodeGeneratorManager;
|
10
10
|
export {};
|
package/package.json
CHANGED
package/src/RepositoryWatcher.ts
CHANGED
@@ -9,6 +9,7 @@ import { socketManager } from './socketManager';
|
|
9
9
|
import { SourceOfChange, WatchEventName } from './types';
|
10
10
|
import { cacheManager } from './cacheManager';
|
11
11
|
import { EventEmitter } from 'node:events';
|
12
|
+
import { assetManager } from './assetManager';
|
12
13
|
|
13
14
|
interface AssetIdentity {
|
14
15
|
handle: string;
|
@@ -143,12 +144,12 @@ export class RepositoryWatcher extends EventEmitter {
|
|
143
144
|
return;
|
144
145
|
}
|
145
146
|
|
146
|
-
|
147
|
-
if (!assetIdentity) {
|
147
|
+
if (this.disabled) {
|
148
148
|
return;
|
149
149
|
}
|
150
150
|
|
151
|
-
|
151
|
+
const assetIdentity = await this.getAssetIdentity(path);
|
152
|
+
if (!assetIdentity) {
|
152
153
|
return;
|
153
154
|
}
|
154
155
|
|
@@ -170,6 +171,25 @@ export class RepositoryWatcher extends EventEmitter {
|
|
170
171
|
}
|
171
172
|
}
|
172
173
|
|
174
|
+
const repoPath = this.getRepositoryPath(assetIdentity);
|
175
|
+
|
176
|
+
if (
|
177
|
+
eventName === 'change' &&
|
178
|
+
!withinRepo &&
|
179
|
+
assetIdentity.version === 'local' &&
|
180
|
+
Path.basename(path) === 'kapeta.yml' &&
|
181
|
+
(await this.exists(path)) &&
|
182
|
+
!(await this.exists(repoPath))
|
183
|
+
) {
|
184
|
+
// This happens when a local asset is renamed
|
185
|
+
const oldPath = _.findKey(this.symbolicLinks, (link) => link === path);
|
186
|
+
if (oldPath) {
|
187
|
+
await FS.unlink(oldPath);
|
188
|
+
await assetManager.importFile(path);
|
189
|
+
return;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
173
193
|
const sourceOfChange = this.sourceOfChange.get(path) ?? 'filesystem';
|
174
194
|
await this.checkForChange(assetIdentity, sourceOfChange);
|
175
195
|
|
@@ -177,18 +197,17 @@ export class RepositoryWatcher extends EventEmitter {
|
|
177
197
|
this.sourceOfChange.delete(path);
|
178
198
|
}
|
179
199
|
|
200
|
+
private getRepositoryPath(assetIdentity: AssetIdentity) {
|
201
|
+
return Path.join(this.baseDir, assetIdentity.handle, assetIdentity.name, assetIdentity.version);
|
202
|
+
}
|
203
|
+
|
180
204
|
private async checkForChange(assetIdentity: AssetIdentity, sourceOfChange: SourceOfChange) {
|
181
|
-
const ymlPath = Path.join(
|
182
|
-
this.baseDir,
|
183
|
-
assetIdentity.handle,
|
184
|
-
assetIdentity.name,
|
185
|
-
assetIdentity.version,
|
186
|
-
'kapeta.yml'
|
187
|
-
);
|
205
|
+
const ymlPath = Path.join(this.getRepositoryPath(assetIdentity), 'kapeta.yml');
|
188
206
|
const newDefinitions = ClusterConfiguration.getDefinitions();
|
189
207
|
const newDefinition = newDefinitions.find((d) => d.ymlPath === ymlPath);
|
190
208
|
let currentDefinition = this.allDefinitions.find((d) => d.ymlPath === ymlPath);
|
191
209
|
const ymlExists = await this.exists(ymlPath);
|
210
|
+
|
192
211
|
let type;
|
193
212
|
if (ymlExists) {
|
194
213
|
if (currentDefinition) {
|
@@ -206,9 +225,6 @@ export class RepositoryWatcher extends EventEmitter {
|
|
206
225
|
}
|
207
226
|
} else {
|
208
227
|
if (currentDefinition) {
|
209
|
-
const ref = parseKapetaUri(
|
210
|
-
`${currentDefinition.definition.metadata.name}:${currentDefinition.version}`
|
211
|
-
).id;
|
212
228
|
//Something was removed
|
213
229
|
type = 'removed';
|
214
230
|
} else {
|
package/src/assetManager.ts
CHANGED
@@ -171,7 +171,7 @@ class AssetManager {
|
|
171
171
|
return asset;
|
172
172
|
}
|
173
173
|
|
174
|
-
async updateAsset(ref: string, yaml:
|
174
|
+
async updateAsset(ref: string, yaml: Definition, sourceOfChange: SourceOfChange = 'filesystem') {
|
175
175
|
ref = normalizeKapetaUri(ref);
|
176
176
|
const asset = await this.getAsset(ref, true, false);
|
177
177
|
if (!asset) {
|
@@ -227,7 +227,7 @@ class AssetManager {
|
|
227
227
|
}
|
228
228
|
|
229
229
|
async unregisterAsset(ref: string) {
|
230
|
-
const asset = await this.getAsset(ref, true);
|
230
|
+
const asset = await this.getAsset(ref, true, false);
|
231
231
|
if (!asset) {
|
232
232
|
throw new Error('Asset does not exists: ' + ref);
|
233
233
|
}
|
@@ -253,7 +253,7 @@ class AssetManager {
|
|
253
253
|
return await repositoryManager.ensureAsset(uri.handle, uri.name, uri.version, wait);
|
254
254
|
}
|
255
255
|
|
256
|
-
private async maybeGenerateCode(ref: string, ymlPath: string, block:
|
256
|
+
private async maybeGenerateCode(ref: string, ymlPath: string, block: Definition) {
|
257
257
|
ref = normalizeKapetaUri(ref);
|
258
258
|
if (await codeGeneratorManager.canGenerateCode(block)) {
|
259
259
|
const assetTitle = block.metadata.title ? block.metadata.title : parseKapetaUri(block.metadata.name).name;
|
@@ -55,7 +55,7 @@ class CodeGeneratorManager {
|
|
55
55
|
});
|
56
56
|
}
|
57
57
|
|
58
|
-
async canGenerateCode(yamlContent:
|
58
|
+
async canGenerateCode(yamlContent: Definition): Promise<boolean> {
|
59
59
|
if (!yamlContent.spec.target?.kind) {
|
60
60
|
//Not all block types have targets
|
61
61
|
return false;
|
@@ -68,7 +68,7 @@ class CodeGeneratorManager {
|
|
68
68
|
return !!(yamlContent && yamlContent.kind && blockTypeKinds.indexOf(yamlContent.kind.toLowerCase()) > -1);
|
69
69
|
}
|
70
70
|
|
71
|
-
async generate(yamlFile: string, yamlContent:
|
71
|
+
async generate(yamlFile: string, yamlContent: Definition) {
|
72
72
|
if (!yamlContent.spec.target?.kind) {
|
73
73
|
//Not all block types have targets
|
74
74
|
return;
|
@@ -87,7 +87,7 @@ class CodeGeneratorManager {
|
|
87
87
|
await this.ensureLanguageTargetInRegistry(targetAsset?.path, targetAsset?.version, targetAsset?.data);
|
88
88
|
const baseDir = Path.dirname(yamlFile);
|
89
89
|
console.log('Generating code for path: %s', baseDir);
|
90
|
-
const codeGenerator = new BlockCodeGenerator(yamlContent);
|
90
|
+
const codeGenerator = new BlockCodeGenerator(yamlContent as BlockDefinition);
|
91
91
|
|
92
92
|
const output = await codeGenerator.generate();
|
93
93
|
const writer = new CodeWriter(baseDir, {});
|