@cyberismo/data-handler 0.0.15 → 0.0.16
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/dist/card-metadata-updater.js +7 -1
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +4 -0
- package/dist/command-handler.js +19 -3
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +24 -1
- package/dist/command-manager.js +27 -3
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +34 -36
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/export.d.ts +11 -2
- package/dist/commands/export.js +54 -41
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +9 -1
- package/dist/commands/import.js +15 -7
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.js +0 -1
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +8 -1
- package/dist/commands/remove.js +8 -4
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +4 -9
- package/dist/commands/rename.js +32 -101
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +16 -10
- package/dist/commands/show.js +71 -55
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.d.ts +9 -2
- package/dist/commands/transition.js +25 -17
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +16 -12
- package/dist/commands/update.js +19 -17
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +17 -9
- package/dist/commands/validate.js +96 -35
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +7 -4
- package/dist/containers/project/calculation-engine.js +61 -66
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project/project-paths.d.ts +5 -4
- package/dist/containers/project/project-paths.js +16 -12
- package/dist/containers/project/project-paths.js.map +1 -1
- package/dist/containers/project/resource-cache.d.ts +169 -0
- package/dist/containers/project/resource-cache.js +507 -0
- package/dist/containers/project/resource-cache.js.map +1 -0
- package/dist/containers/project/resource-handler.d.ts +129 -0
- package/dist/containers/project/resource-handler.js +206 -0
- package/dist/containers/project/resource-handler.js.map +1 -0
- package/dist/containers/project.d.ts +38 -153
- package/dist/containers/project.js +129 -405
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +8 -2
- package/dist/containers/template.js +20 -15
- package/dist/containers/template.js.map +1 -1
- package/dist/interfaces/folder-content-interfaces.d.ts +5 -3
- package/dist/interfaces/folder-content-interfaces.js +3 -3
- package/dist/interfaces/folder-content-interfaces.js.map +1 -1
- package/dist/interfaces/project-interfaces.d.ts +2 -4
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +14 -1
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/graph/index.js +12 -26
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/index.d.ts +1 -1
- package/dist/macros/index.js +2 -2
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/report/index.js +3 -6
- package/dist/macros/report/index.js.map +1 -1
- package/dist/module-manager.d.ts +16 -3
- package/dist/module-manager.js +51 -19
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.d.ts +16 -3
- package/dist/project-settings.js +79 -14
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/calculation-resource.d.ts +4 -3
- package/dist/resources/calculation-resource.js +11 -5
- package/dist/resources/calculation-resource.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +6 -1
- package/dist/resources/card-type-resource.js +34 -23
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.d.ts +3 -2
- package/dist/resources/create-defaults.js +3 -2
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +4 -1
- package/dist/resources/field-type-resource.js +22 -23
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +5 -9
- package/dist/resources/file-resource.js +6 -11
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +29 -32
- package/dist/resources/folder-resource.js +59 -78
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +4 -1
- package/dist/resources/graph-model-resource.js +11 -4
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +5 -2
- package/dist/resources/graph-view-resource.js +7 -3
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +5 -2
- package/dist/resources/link-type-resource.js +5 -2
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +6 -7
- package/dist/resources/report-resource.js +14 -23
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +93 -8
- package/dist/resources/resource-object.js +162 -110
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +7 -3
- package/dist/resources/template-resource.js +10 -3
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +5 -2
- package/dist/resources/workflow-resource.js +18 -22
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/card-utils.d.ts +2 -2
- package/dist/utils/card-utils.js +1 -1
- package/dist/utils/clingo-fact-builder.d.ts +25 -14
- package/dist/utils/clingo-fact-builder.js +27 -5
- package/dist/utils/clingo-fact-builder.js.map +1 -1
- package/dist/utils/clingo-facts.js +3 -4
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/resource-utils.d.ts +1 -0
- package/dist/utils/resource-utils.js +2 -1
- package/dist/utils/resource-utils.js.map +1 -1
- package/package.json +8 -8
- package/src/card-metadata-updater.ts +6 -2
- package/src/command-handler.ts +24 -5
- package/src/command-manager.ts +29 -17
- package/src/commands/create.ts +43 -78
- package/src/commands/export.ts +63 -52
- package/src/commands/import.ts +24 -14
- package/src/commands/move.ts +0 -1
- package/src/commands/remove.ts +11 -7
- package/src/commands/rename.ts +43 -149
- package/src/commands/show.ts +113 -78
- package/src/commands/transition.ts +26 -28
- package/src/commands/update.ts +25 -22
- package/src/commands/validate.ts +108 -67
- package/src/containers/project/calculation-engine.ts +61 -93
- package/src/containers/project/project-paths.ts +21 -13
- package/src/containers/project/resource-cache.ts +648 -0
- package/src/containers/project/resource-handler.ts +265 -0
- package/src/containers/project.ts +178 -522
- package/src/containers/template.ts +24 -19
- package/src/interfaces/folder-content-interfaces.ts +7 -6
- package/src/interfaces/project-interfaces.ts +7 -6
- package/src/interfaces/resource-interfaces.ts +18 -3
- package/src/macros/graph/index.ts +26 -47
- package/src/macros/index.ts +2 -2
- package/src/macros/report/index.ts +3 -9
- package/src/module-manager.ts +74 -17
- package/src/project-settings.ts +83 -14
- package/src/resources/calculation-resource.ts +18 -18
- package/src/resources/card-type-resource.ts +50 -50
- package/src/resources/create-defaults.ts +3 -2
- package/src/resources/field-type-resource.ts +41 -55
- package/src/resources/file-resource.ts +10 -36
- package/src/resources/folder-resource.ts +69 -120
- package/src/resources/graph-model-resource.ts +20 -22
- package/src/resources/graph-view-resource.ts +15 -17
- package/src/resources/link-type-resource.ts +10 -13
- package/src/resources/report-resource.ts +21 -43
- package/src/resources/resource-object.ts +194 -152
- package/src/resources/template-resource.ts +17 -16
- package/src/resources/workflow-resource.ts +25 -44
- package/src/utils/card-utils.ts +2 -2
- package/src/utils/clingo-fact-builder.ts +28 -16
- package/src/utils/clingo-facts.ts +3 -4
- package/src/utils/resource-utils.ts +2 -1
- package/dist/containers/project/resource-collector.d.ts +0 -110
- package/dist/containers/project/resource-collector.js +0 -344
- package/dist/containers/project/resource-collector.js.map +0 -1
- package/src/containers/project/resource-collector.ts +0 -404
package/src/commands/remove.ts
CHANGED
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
import { ActionGuard } from '../permissions/action-guard.js';
|
|
15
15
|
import { isModuleCard } from '../utils/card-utils.js';
|
|
16
16
|
import { ModuleManager } from '../module-manager.js';
|
|
17
|
-
import { Project } from '../containers/project.js';
|
|
17
|
+
import type { Project } from '../containers/project.js';
|
|
18
18
|
import type { RemovableResourceTypes } from '../interfaces/project-interfaces.js';
|
|
19
|
-
import { resourceName } from '../utils/resource-utils.js';
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* Remove command.
|
|
23
22
|
*/
|
|
24
23
|
export class Remove {
|
|
25
24
|
private moduleManager: ModuleManager;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new instance of Remove command.
|
|
27
|
+
* @param project Project instance to use
|
|
28
|
+
*/
|
|
26
29
|
constructor(private project: Project) {
|
|
27
30
|
this.moduleManager = new ModuleManager(this.project);
|
|
28
31
|
}
|
|
@@ -152,14 +155,15 @@ export class Remove {
|
|
|
152
155
|
* @param rest Additional arguments
|
|
153
156
|
* @note removing attachment requires card id and attachment filename
|
|
154
157
|
* @note removing link requires card ids of source card, and optionally link type and link description
|
|
158
|
+
* @throws when removing an attachment, but attachment parameter is missing, or
|
|
159
|
+
* when removing link, some of the mandatory parameters are missing, or
|
|
160
|
+
* when trying to remove unknown type
|
|
155
161
|
*/
|
|
156
162
|
public async remove(
|
|
157
163
|
type: RemovableResourceTypes,
|
|
158
164
|
targetName: string,
|
|
159
165
|
...rest: any[] // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
160
166
|
) {
|
|
161
|
-
const strictNameCheck = true;
|
|
162
|
-
|
|
163
167
|
if (type === 'attachment' && rest.length !== 1 && !rest[0]) {
|
|
164
168
|
throw new Error(
|
|
165
169
|
`Input validation error: must pass argument 'detail' if requesting to remove attachment`,
|
|
@@ -177,9 +181,9 @@ export class Remove {
|
|
|
177
181
|
);
|
|
178
182
|
}
|
|
179
183
|
if (this.projectResource(type)) {
|
|
180
|
-
const resource =
|
|
181
|
-
|
|
182
|
-
|
|
184
|
+
const resource = this.project.resources.byType(
|
|
185
|
+
targetName,
|
|
186
|
+
this.project.resources.resourceTypeFromSingularType(type),
|
|
183
187
|
);
|
|
184
188
|
return resource?.delete();
|
|
185
189
|
} else {
|
package/src/commands/rename.ts
CHANGED
|
@@ -20,17 +20,6 @@ import type { Card } from '../interfaces/project-interfaces.js';
|
|
|
20
20
|
import { isTemplateCard } from '../utils/card-utils.js';
|
|
21
21
|
import { type Project, ResourcesFrom } from '../containers/project.js';
|
|
22
22
|
import { resourceName } from '../utils/resource-utils.js';
|
|
23
|
-
import { Template } from '../containers/template.js';
|
|
24
|
-
|
|
25
|
-
import { CalculationResource } from '../resources/calculation-resource.js';
|
|
26
|
-
import { CardTypeResource } from '../resources/card-type-resource.js';
|
|
27
|
-
import { FieldTypeResource } from '../resources/field-type-resource.js';
|
|
28
|
-
import { GraphModelResource } from '../resources/graph-model-resource.js';
|
|
29
|
-
import { GraphViewResource } from '../resources/graph-view-resource.js';
|
|
30
|
-
import { LinkTypeResource } from '../resources/link-type-resource.js';
|
|
31
|
-
import { ReportResource } from '../resources/report-resource.js';
|
|
32
|
-
import { TemplateResource } from '../resources/template-resource.js';
|
|
33
|
-
import { WorkflowResource } from '../resources/workflow-resource.js';
|
|
34
23
|
|
|
35
24
|
const FILE_TYPES_WITH_PREFIX_REFERENCES = ['adoc', 'hbs', 'json', 'lp'];
|
|
36
25
|
|
|
@@ -41,6 +30,10 @@ export class Rename {
|
|
|
41
30
|
private from: string = '';
|
|
42
31
|
private to: string = '';
|
|
43
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Creates an instance of Rename command.
|
|
35
|
+
* @param project Project instance to use.
|
|
36
|
+
*/
|
|
44
37
|
constructor(private project: Project) {}
|
|
45
38
|
|
|
46
39
|
// Renames a card and all of its attachments (if it is a project card).
|
|
@@ -183,93 +176,6 @@ export class Rename {
|
|
|
183
176
|
: name;
|
|
184
177
|
}
|
|
185
178
|
|
|
186
|
-
// @todo: merge all update-functions
|
|
187
|
-
// Updates card type's metadata.
|
|
188
|
-
private async updateCardTypeMetadata(cardTypeName: string) {
|
|
189
|
-
const cardType = new CardTypeResource(
|
|
190
|
-
this.project,
|
|
191
|
-
resourceName(cardTypeName),
|
|
192
|
-
);
|
|
193
|
-
return cardType.rename(resourceName(this.updateResourceName(cardTypeName)));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Rename calculations.
|
|
197
|
-
private async updateCalculation(calculationName: string) {
|
|
198
|
-
const calculation = new CalculationResource(
|
|
199
|
-
this.project,
|
|
200
|
-
resourceName(calculationName),
|
|
201
|
-
);
|
|
202
|
-
return calculation.rename(
|
|
203
|
-
resourceName(this.updateResourceName(calculationName)),
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Updates field type's metadata.
|
|
208
|
-
private async updateFieldTypeMetadata(fieldTypeName: string) {
|
|
209
|
-
const fieldType = new FieldTypeResource(
|
|
210
|
-
this.project,
|
|
211
|
-
resourceName(fieldTypeName),
|
|
212
|
-
);
|
|
213
|
-
return fieldType.rename(
|
|
214
|
-
resourceName(this.updateResourceName(fieldTypeName)),
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Updates graph model's metadata.
|
|
219
|
-
private async updateGraphModelMetadata(graphModelName: string) {
|
|
220
|
-
const graphModel = new GraphModelResource(
|
|
221
|
-
this.project,
|
|
222
|
-
resourceName(graphModelName),
|
|
223
|
-
);
|
|
224
|
-
return graphModel.rename(
|
|
225
|
-
resourceName(this.updateResourceName(graphModelName)),
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Updates graph view's metadata.
|
|
230
|
-
private async updateGraphViewMetadata(graphViewName: string) {
|
|
231
|
-
const graphView = new GraphViewResource(
|
|
232
|
-
this.project,
|
|
233
|
-
resourceName(graphViewName),
|
|
234
|
-
);
|
|
235
|
-
return graphView.rename(
|
|
236
|
-
resourceName(this.updateResourceName(graphViewName)),
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Updates link type's metadata.
|
|
241
|
-
private async updateLinkTypeMetadata(linkTypeName: string) {
|
|
242
|
-
const linkType = new LinkTypeResource(
|
|
243
|
-
this.project,
|
|
244
|
-
resourceName(linkTypeName),
|
|
245
|
-
);
|
|
246
|
-
return linkType.rename(resourceName(this.updateResourceName(linkTypeName)));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Updates reports' metadata.
|
|
250
|
-
private async updateReport(reportName: string) {
|
|
251
|
-
const report = new ReportResource(this.project, resourceName(reportName));
|
|
252
|
-
return report.rename(resourceName(this.updateResourceName(reportName)));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Rename templates.
|
|
256
|
-
private async updateTemplate(templateName: string) {
|
|
257
|
-
const template = new TemplateResource(
|
|
258
|
-
this.project,
|
|
259
|
-
resourceName(templateName),
|
|
260
|
-
);
|
|
261
|
-
return template.rename(resourceName(this.updateResourceName(templateName)));
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Rename workflows.
|
|
265
|
-
private async updateWorkflowMetadata(workflowName: string) {
|
|
266
|
-
const workflow = new WorkflowResource(
|
|
267
|
-
this.project,
|
|
268
|
-
resourceName(workflowName),
|
|
269
|
-
);
|
|
270
|
-
return workflow.rename(resourceName(this.updateResourceName(workflowName)));
|
|
271
|
-
}
|
|
272
|
-
|
|
273
179
|
/**
|
|
274
180
|
* Renames project prefix.
|
|
275
181
|
* @throws if trying to use empty 'to'
|
|
@@ -294,72 +200,60 @@ export class Rename {
|
|
|
294
200
|
await this.project.configuration.setCardPrefix(to);
|
|
295
201
|
console.info(`Rename: New prefix: '${this.project.projectPrefix}'`);
|
|
296
202
|
// Update the resources collection, since project prefix has changed.
|
|
297
|
-
this.project.
|
|
203
|
+
this.project.resources.changed();
|
|
298
204
|
|
|
299
205
|
// Rename local resources.
|
|
300
|
-
// It is better to rename the resources in this order: card types, field types, then
|
|
206
|
+
// It is better to rename the resources in this order: card types, workflows, field types, then the rest
|
|
301
207
|
|
|
302
208
|
// Rename all card types and custom fields in them.
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
209
|
+
for (const cardType of this.project.resources.cardTypes(
|
|
210
|
+
ResourcesFrom.localOnly,
|
|
211
|
+
)) {
|
|
212
|
+
const name = this.updateResourceName(cardType.data?.name || '');
|
|
213
|
+
await cardType.rename(resourceName(name));
|
|
306
214
|
}
|
|
307
215
|
console.info('Updated card types');
|
|
308
216
|
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
217
|
+
for (const workflow of this.project.resources.workflows(
|
|
218
|
+
ResourcesFrom.localOnly,
|
|
219
|
+
)) {
|
|
220
|
+
const name = this.updateResourceName(workflow.data?.name || '');
|
|
221
|
+
await workflow.rename(resourceName(name));
|
|
312
222
|
}
|
|
313
223
|
console.info('Updated workflows');
|
|
314
224
|
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
225
|
+
for (const fieldType of this.project.resources.fieldTypes(
|
|
226
|
+
ResourcesFrom.localOnly,
|
|
227
|
+
)) {
|
|
228
|
+
const name = this.updateResourceName(fieldType.data?.name || '');
|
|
229
|
+
await fieldType.rename(resourceName(name));
|
|
318
230
|
}
|
|
319
231
|
console.info('Updated field types');
|
|
320
232
|
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const reports = await this.project.reports(ResourcesFrom.localOnly);
|
|
340
|
-
for (const report of reports) {
|
|
341
|
-
await this.updateReport(report.name);
|
|
342
|
-
}
|
|
343
|
-
console.info('Updated reports');
|
|
344
|
-
|
|
345
|
-
let templates = await this.project.templates(ResourcesFrom.localOnly);
|
|
346
|
-
for (const template of templates) {
|
|
347
|
-
await this.updateTemplate(template.name);
|
|
233
|
+
const restOfResourceTypes = [
|
|
234
|
+
'graphModels',
|
|
235
|
+
'graphViews',
|
|
236
|
+
'linkTypes',
|
|
237
|
+
'reports',
|
|
238
|
+
'templates',
|
|
239
|
+
'calculations',
|
|
240
|
+
] as const;
|
|
241
|
+
|
|
242
|
+
for (const resourceType of restOfResourceTypes) {
|
|
243
|
+
for (const resource of this.project.resources.resourceTypes(
|
|
244
|
+
resourceType,
|
|
245
|
+
ResourcesFrom.localOnly,
|
|
246
|
+
)) {
|
|
247
|
+
const name = this.updateResourceName(resource.data?.name || '');
|
|
248
|
+
await resource.rename(resourceName(name));
|
|
249
|
+
}
|
|
348
250
|
}
|
|
349
|
-
console.info('Updated templates');
|
|
350
251
|
|
|
351
|
-
|
|
252
|
+
// Rename all local template cards. This must be done after calculations have been renamed.
|
|
253
|
+
for (const template of this.project.resources.templates(
|
|
352
254
|
ResourcesFrom.localOnly,
|
|
353
|
-
)
|
|
354
|
-
|
|
355
|
-
await this.updateCalculation(calculation.name);
|
|
356
|
-
}
|
|
357
|
-
console.info('Updated calculations');
|
|
358
|
-
|
|
359
|
-
// Rename all local template cards.
|
|
360
|
-
templates = await this.project.templates(ResourcesFrom.localOnly);
|
|
361
|
-
for (const template of templates) {
|
|
362
|
-
const templateObject = new Template(this.project, template);
|
|
255
|
+
)) {
|
|
256
|
+
const templateObject = template.templateObject();
|
|
363
257
|
await this.renameCards(templateObject.cards());
|
|
364
258
|
}
|
|
365
259
|
console.info('Renamed template cards and updated the content');
|
|
@@ -376,7 +270,7 @@ export class Rename {
|
|
|
376
270
|
console.info('Renamed all remaining references in .cards folder');
|
|
377
271
|
|
|
378
272
|
// It is best that the resources are re-collected after all the renaming has occurred.
|
|
379
|
-
this.project.
|
|
273
|
+
this.project.resources.changed();
|
|
380
274
|
console.info('Collected renamed resources');
|
|
381
275
|
|
|
382
276
|
return this.project.calculationEngine.generate();
|
package/src/commands/show.ts
CHANGED
|
@@ -34,47 +34,47 @@ import type {
|
|
|
34
34
|
ModuleContent,
|
|
35
35
|
ModuleSettingFromHub,
|
|
36
36
|
ProjectMetadata,
|
|
37
|
-
|
|
37
|
+
ResourceType,
|
|
38
38
|
} from '../interfaces/project-interfaces.js';
|
|
39
39
|
import type {
|
|
40
|
+
AnyResourceContent,
|
|
40
41
|
CardType,
|
|
41
42
|
ResourceContent,
|
|
42
43
|
TemplateConfiguration,
|
|
43
44
|
Workflow,
|
|
44
45
|
} from '../interfaces/resource-interfaces.js';
|
|
45
|
-
import { Project,
|
|
46
|
-
import {
|
|
47
|
-
import {
|
|
48
|
-
import { UserPreferences } from '../utils/user-preferences.js';
|
|
46
|
+
import type { Project, ResourcesFrom } from '../containers/project.js';
|
|
47
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
48
|
+
import type { ResourceMap } from '../containers/project/resource-cache.js';
|
|
49
49
|
|
|
50
|
+
import { UserPreferences } from '../utils/user-preferences.js';
|
|
50
51
|
import ReportMacro from '../macros/report/index.js';
|
|
51
52
|
import TaskQueue from '../macros/task-queue.js';
|
|
52
53
|
import { evaluateMacros } from '../macros/index.js';
|
|
53
54
|
import { readJsonFile } from '../utils/json.js';
|
|
54
55
|
import { getChildLogger } from '../utils/log-utils.js';
|
|
55
|
-
import { buildCardHierarchy } from '../utils/card-utils.js';
|
|
56
|
+
import { buildCardHierarchy, flattenCardArray } from '../utils/card-utils.js';
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* Show command.
|
|
59
60
|
*/
|
|
60
61
|
export class Show {
|
|
61
|
-
private
|
|
62
|
+
private readonly resourceFunctions: Record<
|
|
62
63
|
string,
|
|
63
|
-
(from?: ResourcesFrom) =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
64
|
+
(from?: ResourcesFrom) => string[]
|
|
65
|
+
> = {
|
|
66
|
+
calculations: (from) => this.resourceNames('calculations', from),
|
|
67
|
+
cardTypes: (from) => this.resourceNames('cardTypes', from),
|
|
68
|
+
fieldTypes: (from) => this.resourceNames('fieldTypes', from),
|
|
69
|
+
graphModels: (from) => this.resourceNames('graphModels', from),
|
|
70
|
+
graphViews: (from) => this.resourceNames('graphViews', from),
|
|
71
|
+
linkTypes: (from) => this.resourceNames('linkTypes', from),
|
|
72
|
+
reports: (from) => this.resourceNames('reports', from),
|
|
73
|
+
templates: (from) => this.resourceNames('templates', from),
|
|
74
|
+
workflows: (from) => this.resourceNames('workflows', from),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
constructor(private project: Project) {}
|
|
78
78
|
|
|
79
79
|
private get logger() {
|
|
80
80
|
return getChildLogger({
|
|
@@ -82,6 +82,29 @@ export class Show {
|
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// Gets all template attachments
|
|
86
|
+
private async attachmentsFromTemplates() {
|
|
87
|
+
const templateAttachments: CardAttachment[] = [];
|
|
88
|
+
const templates = this.project.resources.templates();
|
|
89
|
+
for (const template of templates) {
|
|
90
|
+
const templateObject = template.templateObject();
|
|
91
|
+
if (templateObject) {
|
|
92
|
+
templateAttachments.push(...templateObject.attachments());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return templateAttachments;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Fetch resource names as a list
|
|
99
|
+
private resourceNames<T extends keyof ResourceMap>(
|
|
100
|
+
resourceType: T,
|
|
101
|
+
from?: ResourcesFrom,
|
|
102
|
+
): string[] {
|
|
103
|
+
return this.project.resources
|
|
104
|
+
.resourceTypes(resourceType, from)
|
|
105
|
+
.map((item) => item.data?.name || '');
|
|
106
|
+
}
|
|
107
|
+
|
|
85
108
|
// Collect all labels from cards.
|
|
86
109
|
private collectLabels = (cards: Card[]): string[] => {
|
|
87
110
|
return cards.reduce<string[]>((labels, card) => {
|
|
@@ -120,24 +143,19 @@ export class Show {
|
|
|
120
143
|
* Shows all template cards in a project.
|
|
121
144
|
* @returns all template cards in a project.
|
|
122
145
|
*/
|
|
123
|
-
public
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
name: template.name,
|
|
137
|
-
cards: buildCards,
|
|
138
|
-
};
|
|
139
|
-
}),
|
|
140
|
-
);
|
|
146
|
+
public showAllTemplateCards(): {
|
|
147
|
+
name: string;
|
|
148
|
+
cards: CardWithChildrenCards[];
|
|
149
|
+
}[] {
|
|
150
|
+
return this.project.resources.templates().map((template) => {
|
|
151
|
+
const cards = template.templateObject().listCards();
|
|
152
|
+
const buildCards = buildCardHierarchy(cards);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
name: template.data?.name || '',
|
|
156
|
+
cards: buildCards,
|
|
157
|
+
};
|
|
158
|
+
});
|
|
141
159
|
}
|
|
142
160
|
|
|
143
161
|
/**
|
|
@@ -146,7 +164,7 @@ export class Show {
|
|
|
146
164
|
*/
|
|
147
165
|
public async showAttachments(): Promise<CardAttachment[]> {
|
|
148
166
|
const attachments = this.project.attachments();
|
|
149
|
-
const templateAttachments = await this.
|
|
167
|
+
const templateAttachments = await this.attachmentsFromTemplates();
|
|
150
168
|
attachments.push(...templateAttachments);
|
|
151
169
|
return attachments;
|
|
152
170
|
}
|
|
@@ -284,17 +302,13 @@ export class Show {
|
|
|
284
302
|
* @returns array of card type details
|
|
285
303
|
*/
|
|
286
304
|
public async showCardTypesWithDetails(): Promise<(CardType | undefined)[]> {
|
|
287
|
-
const
|
|
288
|
-
for (const cardType of
|
|
289
|
-
|
|
290
|
-
cardType.
|
|
291
|
-
);
|
|
292
|
-
if (cardTypeDetails) {
|
|
293
|
-
promiseContainer.push(cardTypeDetails);
|
|
305
|
+
const container = [];
|
|
306
|
+
for (const cardType of this.project.resources.cardTypes()) {
|
|
307
|
+
if (cardType.data) {
|
|
308
|
+
container.push(cardType.data);
|
|
294
309
|
}
|
|
295
310
|
}
|
|
296
|
-
|
|
297
|
-
return results.filter((item) => item);
|
|
311
|
+
return container;
|
|
298
312
|
}
|
|
299
313
|
|
|
300
314
|
/**
|
|
@@ -317,10 +331,10 @@ export class Show {
|
|
|
317
331
|
resolve(this.project.basePath, MODULE_LIST_FULL_PATH),
|
|
318
332
|
)
|
|
319
333
|
).modules;
|
|
320
|
-
const currentModules =
|
|
334
|
+
const currentModules = this.project.resources.moduleNames();
|
|
321
335
|
const nonImportedModules = moduleList.filter(
|
|
322
336
|
(item: ModuleSettingFromHub) => {
|
|
323
|
-
return !currentModules.some((module) => item.name === module
|
|
337
|
+
return !currentModules.some((module) => item.name === module);
|
|
324
338
|
},
|
|
325
339
|
);
|
|
326
340
|
|
|
@@ -349,7 +363,10 @@ export class Show {
|
|
|
349
363
|
* @returns labels in a list
|
|
350
364
|
*/
|
|
351
365
|
public showLabels(): string[] {
|
|
352
|
-
const cards =
|
|
366
|
+
const cards = flattenCardArray(
|
|
367
|
+
this.project.showProjectCards(),
|
|
368
|
+
this.project,
|
|
369
|
+
);
|
|
353
370
|
const templateCards = this.project.allTemplateCards();
|
|
354
371
|
|
|
355
372
|
const labels = this.collectLabels([...cards, ...templateCards]);
|
|
@@ -398,8 +415,8 @@ export class Show {
|
|
|
398
415
|
* Shows all modules (if any) in a project.
|
|
399
416
|
* @returns all modules in a project.
|
|
400
417
|
*/
|
|
401
|
-
public
|
|
402
|
-
return
|
|
418
|
+
public showModules(): string[] {
|
|
419
|
+
return this.project.resources.moduleNames().sort();
|
|
403
420
|
}
|
|
404
421
|
|
|
405
422
|
/**
|
|
@@ -415,6 +432,7 @@ export class Show {
|
|
|
415
432
|
* @param reportName Name of the report to show
|
|
416
433
|
* @param cardKey Card key to use for the report
|
|
417
434
|
* @param parameters Additional parameters for the report
|
|
435
|
+
* @param context Context for resource (includes a project instance)
|
|
418
436
|
* @param outputPath Optional output path for the report
|
|
419
437
|
* @returns Report results as a string
|
|
420
438
|
* @throws Error if the report does not exist
|
|
@@ -427,9 +445,9 @@ export class Show {
|
|
|
427
445
|
outputPath?: string,
|
|
428
446
|
): Promise<string> {
|
|
429
447
|
if (
|
|
430
|
-
!
|
|
431
|
-
(
|
|
432
|
-
|
|
448
|
+
!this.project.resources
|
|
449
|
+
.reports()
|
|
450
|
+
.some((report) => report.data?.name === reportName)
|
|
433
451
|
) {
|
|
434
452
|
throw new Error(`Report '${reportName}' does not exist`);
|
|
435
453
|
}
|
|
@@ -471,17 +489,35 @@ export class Show {
|
|
|
471
489
|
/**
|
|
472
490
|
* Shows details of certain resource.
|
|
473
491
|
* @param name Name of resource.
|
|
492
|
+
* @param showUse If true, shows also where resource is used.
|
|
493
|
+
* @param resourceType If specified, checks that the resource is given type.
|
|
474
494
|
* @returns resource metadata as JSON.
|
|
475
495
|
*/
|
|
476
496
|
public async showResource(
|
|
477
497
|
name: string,
|
|
478
|
-
showUse
|
|
479
|
-
): Promise<
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
498
|
+
showUse?: boolean,
|
|
499
|
+
): Promise<AnyResourceContent>;
|
|
500
|
+
public async showResource<T extends ResourceType>(
|
|
501
|
+
name: string,
|
|
502
|
+
resourceType: T,
|
|
503
|
+
showUse?: boolean,
|
|
504
|
+
): Promise<ResourceContent<T>>;
|
|
505
|
+
public async showResource(
|
|
506
|
+
name: string,
|
|
507
|
+
arg2?: boolean | ResourceType,
|
|
508
|
+
arg3?: boolean,
|
|
509
|
+
): Promise<AnyResourceContent> {
|
|
510
|
+
const hasResourceType = typeof arg2 === 'string';
|
|
511
|
+
const resourceType = hasResourceType ? arg2 : null;
|
|
512
|
+
const showUse = hasResourceType ? arg3 : arg2;
|
|
513
|
+
|
|
514
|
+
const type = this.project.resources.extractType(name);
|
|
515
|
+
if (resourceType !== null && resourceType !== type) {
|
|
516
|
+
throw new Error(
|
|
517
|
+
`While fetching '${name}': Expected type '${resourceType}', but got '${type}' instead`,
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
const resource = this.project.resources.byType(name, type);
|
|
485
521
|
const [details, usage] = await Promise.all([
|
|
486
522
|
resource?.show(),
|
|
487
523
|
showUse ? resource?.usage() : [],
|
|
@@ -502,9 +538,9 @@ export class Show {
|
|
|
502
538
|
* @returns sorted array of resources
|
|
503
539
|
*/
|
|
504
540
|
public async showResources(type: string): Promise<string[]> {
|
|
505
|
-
const func = this.
|
|
541
|
+
const func = this.resourceFunctions[type];
|
|
506
542
|
if (!func) return [];
|
|
507
|
-
return
|
|
543
|
+
return func().sort();
|
|
508
544
|
}
|
|
509
545
|
|
|
510
546
|
/**
|
|
@@ -512,23 +548,22 @@ export class Show {
|
|
|
512
548
|
* @returns all templates in a project.
|
|
513
549
|
*/
|
|
514
550
|
public async showTemplatesWithDetails(): Promise<TemplateConfiguration[]> {
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
return
|
|
551
|
+
const templates = [];
|
|
552
|
+
for (const template of this.project.resources.templates()) {
|
|
553
|
+
templates.push(template.show());
|
|
554
|
+
}
|
|
555
|
+
return templates;
|
|
520
556
|
}
|
|
521
557
|
|
|
522
558
|
/**
|
|
523
559
|
* Shows all workflows with full details in a project.
|
|
524
560
|
* @returns workflows with full details
|
|
525
561
|
*/
|
|
526
|
-
public
|
|
527
|
-
const
|
|
528
|
-
for (const workflow of
|
|
529
|
-
|
|
562
|
+
public showWorkflowsWithDetails(): (Workflow | undefined)[] {
|
|
563
|
+
const workflows = [];
|
|
564
|
+
for (const workflow of this.project.resources.workflows()) {
|
|
565
|
+
workflows.push(workflow.data);
|
|
530
566
|
}
|
|
531
|
-
|
|
532
|
-
return results.filter((item) => item);
|
|
567
|
+
return workflows;
|
|
533
568
|
}
|
|
534
569
|
}
|