@cyberismo/data-handler 0.0.15 → 0.0.17
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 +22 -8
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +24 -1
- package/dist/command-manager.js +31 -7
- 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/fetch.d.ts +8 -0
- package/dist/commands/fetch.js +101 -23
- package/dist/commands/fetch.js.map +1 -1
- package/dist/commands/import.d.ts +14 -3
- package/dist/commands/import.js +27 -10
- 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 +11 -2
- package/dist/commands/remove.js +15 -5
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +4 -9
- package/dist/commands/rename.js +37 -101
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +20 -12
- package/dist/commands/show.js +79 -57
- 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 +94 -35
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/card-container.d.ts +7 -5
- package/dist/containers/card-container.js +30 -5
- package/dist/containers/card-container.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 +7 -4
- package/dist/containers/project/project-paths.js +22 -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 +509 -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 +46 -152
- package/dist/containers/project.js +179 -409
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +8 -2
- package/dist/containers/template.js +24 -19
- package/dist/containers/template.js.map +1 -1
- package/dist/interfaces/command-options.d.ts +3 -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 +7 -9
- 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 +21 -3
- package/dist/project-settings.js +91 -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 +94 -8
- package/dist/resources/resource-object.js +212 -109
- 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/configuration-logger.d.ts +91 -0
- package/dist/utils/configuration-logger.js +151 -0
- package/dist/utils/configuration-logger.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.js +5 -3
- package/dist/utils/constants.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 +9 -9
- package/src/card-metadata-updater.ts +6 -2
- package/src/command-handler.ts +39 -12
- package/src/command-manager.ts +33 -21
- package/src/commands/create.ts +43 -78
- package/src/commands/export.ts +63 -52
- package/src/commands/fetch.ts +143 -34
- package/src/commands/import.ts +37 -15
- package/src/commands/move.ts +0 -1
- package/src/commands/remove.ts +20 -7
- package/src/commands/rename.ts +58 -149
- package/src/commands/show.ts +123 -80
- package/src/commands/transition.ts +26 -28
- package/src/commands/update.ts +25 -22
- package/src/commands/validate.ts +104 -67
- package/src/containers/card-container.ts +37 -5
- package/src/containers/project/calculation-engine.ts +61 -93
- package/src/containers/project/project-paths.ts +29 -13
- package/src/containers/project/resource-cache.ts +651 -0
- package/src/containers/project/resource-handler.ts +265 -0
- package/src/containers/project.ts +250 -527
- package/src/containers/template.ts +28 -23
- package/src/interfaces/command-options.ts +3 -1
- package/src/interfaces/folder-content-interfaces.ts +7 -6
- package/src/interfaces/project-interfaces.ts +12 -11
- 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 +96 -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 +263 -149
- 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/configuration-logger.ts +206 -0
- package/src/utils/constants.ts +5 -3
- 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/show.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { join, resolve } from 'node:path';
|
|
|
18
18
|
import { spawn } from 'node:child_process';
|
|
19
19
|
import { writeFile } from 'node:fs/promises';
|
|
20
20
|
|
|
21
|
-
import { MODULE_LIST_FULL_PATH } from './fetch.js';
|
|
21
|
+
import { type Fetch, MODULE_LIST_FULL_PATH } from './fetch.js';
|
|
22
22
|
|
|
23
23
|
import type { attachmentPayload } from '../interfaces/request-status-interfaces.js';
|
|
24
24
|
import type {
|
|
@@ -34,47 +34,50 @@ 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(
|
|
78
|
+
private project: Project,
|
|
79
|
+
private fetchCmd: Fetch,
|
|
80
|
+
) {}
|
|
78
81
|
|
|
79
82
|
private get logger() {
|
|
80
83
|
return getChildLogger({
|
|
@@ -82,6 +85,29 @@ export class Show {
|
|
|
82
85
|
});
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
// Gets all template attachments
|
|
89
|
+
private async attachmentsFromTemplates() {
|
|
90
|
+
const templateAttachments: CardAttachment[] = [];
|
|
91
|
+
const templates = this.project.resources.templates();
|
|
92
|
+
for (const template of templates) {
|
|
93
|
+
const templateObject = template.templateObject();
|
|
94
|
+
if (templateObject) {
|
|
95
|
+
templateAttachments.push(...templateObject.attachments());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return templateAttachments;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Fetch resource names as a list
|
|
102
|
+
private resourceNames<T extends keyof ResourceMap>(
|
|
103
|
+
resourceType: T,
|
|
104
|
+
from?: ResourcesFrom,
|
|
105
|
+
): string[] {
|
|
106
|
+
return this.project.resources
|
|
107
|
+
.resourceTypes(resourceType, from)
|
|
108
|
+
.map((item) => item.data?.name || '');
|
|
109
|
+
}
|
|
110
|
+
|
|
85
111
|
// Collect all labels from cards.
|
|
86
112
|
private collectLabels = (cards: Card[]): string[] => {
|
|
87
113
|
return cards.reduce<string[]>((labels, card) => {
|
|
@@ -120,24 +146,19 @@ export class Show {
|
|
|
120
146
|
* Shows all template cards in a project.
|
|
121
147
|
* @returns all template cards in a project.
|
|
122
148
|
*/
|
|
123
|
-
public
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
name: template.name,
|
|
137
|
-
cards: buildCards,
|
|
138
|
-
};
|
|
139
|
-
}),
|
|
140
|
-
);
|
|
149
|
+
public showAllTemplateCards(): {
|
|
150
|
+
name: string;
|
|
151
|
+
cards: CardWithChildrenCards[];
|
|
152
|
+
}[] {
|
|
153
|
+
return this.project.resources.templates().map((template) => {
|
|
154
|
+
const cards = template.templateObject().listCards();
|
|
155
|
+
const buildCards = buildCardHierarchy(cards);
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
name: template.data?.name || '',
|
|
159
|
+
cards: buildCards,
|
|
160
|
+
};
|
|
161
|
+
});
|
|
141
162
|
}
|
|
142
163
|
|
|
143
164
|
/**
|
|
@@ -146,7 +167,7 @@ export class Show {
|
|
|
146
167
|
*/
|
|
147
168
|
public async showAttachments(): Promise<CardAttachment[]> {
|
|
148
169
|
const attachments = this.project.attachments();
|
|
149
|
-
const templateAttachments = await this.
|
|
170
|
+
const templateAttachments = await this.attachmentsFromTemplates();
|
|
150
171
|
attachments.push(...templateAttachments);
|
|
151
172
|
return attachments;
|
|
152
173
|
}
|
|
@@ -284,17 +305,13 @@ export class Show {
|
|
|
284
305
|
* @returns array of card type details
|
|
285
306
|
*/
|
|
286
307
|
public async showCardTypesWithDetails(): Promise<(CardType | undefined)[]> {
|
|
287
|
-
const
|
|
288
|
-
for (const cardType of
|
|
289
|
-
|
|
290
|
-
cardType.
|
|
291
|
-
);
|
|
292
|
-
if (cardTypeDetails) {
|
|
293
|
-
promiseContainer.push(cardTypeDetails);
|
|
308
|
+
const container = [];
|
|
309
|
+
for (const cardType of this.project.resources.cardTypes()) {
|
|
310
|
+
if (cardType.data) {
|
|
311
|
+
container.push(cardType.data);
|
|
294
312
|
}
|
|
295
313
|
}
|
|
296
|
-
|
|
297
|
-
return results.filter((item) => item);
|
|
314
|
+
return container;
|
|
298
315
|
}
|
|
299
316
|
|
|
300
317
|
/**
|
|
@@ -312,15 +329,18 @@ export class Show {
|
|
|
312
329
|
showDetails?: boolean,
|
|
313
330
|
): Promise<ModuleSettingFromHub[]> {
|
|
314
331
|
try {
|
|
332
|
+
// Ensure module list is up to date before showing
|
|
333
|
+
await this.fetchCmd.ensureModuleListUpToDate();
|
|
334
|
+
|
|
315
335
|
const moduleList = (
|
|
316
336
|
await readJsonFile(
|
|
317
337
|
resolve(this.project.basePath, MODULE_LIST_FULL_PATH),
|
|
318
338
|
)
|
|
319
339
|
).modules;
|
|
320
|
-
const currentModules =
|
|
340
|
+
const currentModules = this.project.resources.moduleNames();
|
|
321
341
|
const nonImportedModules = moduleList.filter(
|
|
322
342
|
(item: ModuleSettingFromHub) => {
|
|
323
|
-
return !currentModules.some((module) => item.name === module
|
|
343
|
+
return !currentModules.some((module) => item.name === module);
|
|
324
344
|
},
|
|
325
345
|
);
|
|
326
346
|
|
|
@@ -349,7 +369,10 @@ export class Show {
|
|
|
349
369
|
* @returns labels in a list
|
|
350
370
|
*/
|
|
351
371
|
public showLabels(): string[] {
|
|
352
|
-
const cards =
|
|
372
|
+
const cards = flattenCardArray(
|
|
373
|
+
this.project.showProjectCards(),
|
|
374
|
+
this.project,
|
|
375
|
+
);
|
|
353
376
|
const templateCards = this.project.allTemplateCards();
|
|
354
377
|
|
|
355
378
|
const labels = this.collectLabels([...cards, ...templateCards]);
|
|
@@ -382,7 +405,9 @@ export class Show {
|
|
|
382
405
|
* Shows hubs of the project.
|
|
383
406
|
* @returns list of hubs.
|
|
384
407
|
*/
|
|
385
|
-
public showHubs(): HubSetting[] {
|
|
408
|
+
public async showHubs(): Promise<HubSetting[]> {
|
|
409
|
+
// Ensure module list is up to date before showing
|
|
410
|
+
await this.fetchCmd.ensureModuleListUpToDate();
|
|
386
411
|
return this.project.configuration.hubs;
|
|
387
412
|
}
|
|
388
413
|
|
|
@@ -398,8 +423,8 @@ export class Show {
|
|
|
398
423
|
* Shows all modules (if any) in a project.
|
|
399
424
|
* @returns all modules in a project.
|
|
400
425
|
*/
|
|
401
|
-
public
|
|
402
|
-
return
|
|
426
|
+
public showModules(): string[] {
|
|
427
|
+
return this.project.resources.moduleNames().sort();
|
|
403
428
|
}
|
|
404
429
|
|
|
405
430
|
/**
|
|
@@ -415,6 +440,7 @@ export class Show {
|
|
|
415
440
|
* @param reportName Name of the report to show
|
|
416
441
|
* @param cardKey Card key to use for the report
|
|
417
442
|
* @param parameters Additional parameters for the report
|
|
443
|
+
* @param context Context for resource (includes a project instance)
|
|
418
444
|
* @param outputPath Optional output path for the report
|
|
419
445
|
* @returns Report results as a string
|
|
420
446
|
* @throws Error if the report does not exist
|
|
@@ -427,9 +453,9 @@ export class Show {
|
|
|
427
453
|
outputPath?: string,
|
|
428
454
|
): Promise<string> {
|
|
429
455
|
if (
|
|
430
|
-
!
|
|
431
|
-
(
|
|
432
|
-
|
|
456
|
+
!this.project.resources
|
|
457
|
+
.reports()
|
|
458
|
+
.some((report) => report.data?.name === reportName)
|
|
433
459
|
) {
|
|
434
460
|
throw new Error(`Report '${reportName}' does not exist`);
|
|
435
461
|
}
|
|
@@ -471,17 +497,35 @@ export class Show {
|
|
|
471
497
|
/**
|
|
472
498
|
* Shows details of certain resource.
|
|
473
499
|
* @param name Name of resource.
|
|
500
|
+
* @param showUse If true, shows also where resource is used.
|
|
501
|
+
* @param resourceType If specified, checks that the resource is given type.
|
|
474
502
|
* @returns resource metadata as JSON.
|
|
475
503
|
*/
|
|
476
504
|
public async showResource(
|
|
477
505
|
name: string,
|
|
478
|
-
showUse
|
|
479
|
-
): Promise<
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
506
|
+
showUse?: boolean,
|
|
507
|
+
): Promise<AnyResourceContent>;
|
|
508
|
+
public async showResource<T extends ResourceType>(
|
|
509
|
+
name: string,
|
|
510
|
+
resourceType: T,
|
|
511
|
+
showUse?: boolean,
|
|
512
|
+
): Promise<ResourceContent<T>>;
|
|
513
|
+
public async showResource(
|
|
514
|
+
name: string,
|
|
515
|
+
arg2?: boolean | ResourceType,
|
|
516
|
+
arg3?: boolean,
|
|
517
|
+
): Promise<AnyResourceContent> {
|
|
518
|
+
const hasResourceType = typeof arg2 === 'string';
|
|
519
|
+
const resourceType = hasResourceType ? arg2 : null;
|
|
520
|
+
const showUse = hasResourceType ? arg3 : arg2;
|
|
521
|
+
|
|
522
|
+
const type = this.project.resources.extractType(name);
|
|
523
|
+
if (resourceType !== null && resourceType !== type) {
|
|
524
|
+
throw new Error(
|
|
525
|
+
`While fetching '${name}': Expected type '${resourceType}', but got '${type}' instead`,
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
const resource = this.project.resources.byType(name, type);
|
|
485
529
|
const [details, usage] = await Promise.all([
|
|
486
530
|
resource?.show(),
|
|
487
531
|
showUse ? resource?.usage() : [],
|
|
@@ -502,9 +546,9 @@ export class Show {
|
|
|
502
546
|
* @returns sorted array of resources
|
|
503
547
|
*/
|
|
504
548
|
public async showResources(type: string): Promise<string[]> {
|
|
505
|
-
const func = this.
|
|
549
|
+
const func = this.resourceFunctions[type];
|
|
506
550
|
if (!func) return [];
|
|
507
|
-
return
|
|
551
|
+
return func().sort();
|
|
508
552
|
}
|
|
509
553
|
|
|
510
554
|
/**
|
|
@@ -512,23 +556,22 @@ export class Show {
|
|
|
512
556
|
* @returns all templates in a project.
|
|
513
557
|
*/
|
|
514
558
|
public async showTemplatesWithDetails(): Promise<TemplateConfiguration[]> {
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
return
|
|
559
|
+
const templates = [];
|
|
560
|
+
for (const template of this.project.resources.templates()) {
|
|
561
|
+
templates.push(template.show());
|
|
562
|
+
}
|
|
563
|
+
return templates;
|
|
520
564
|
}
|
|
521
565
|
|
|
522
566
|
/**
|
|
523
567
|
* Shows all workflows with full details in a project.
|
|
524
568
|
* @returns workflows with full details
|
|
525
569
|
*/
|
|
526
|
-
public
|
|
527
|
-
const
|
|
528
|
-
for (const workflow of
|
|
529
|
-
|
|
570
|
+
public showWorkflowsWithDetails(): (Workflow | undefined)[] {
|
|
571
|
+
const workflows = [];
|
|
572
|
+
for (const workflow of this.project.resources.workflows()) {
|
|
573
|
+
workflows.push(workflow.data);
|
|
530
574
|
}
|
|
531
|
-
|
|
532
|
-
return results.filter((item) => item);
|
|
575
|
+
return workflows;
|
|
533
576
|
}
|
|
534
577
|
}
|
|
@@ -12,17 +12,29 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { ActionGuard } from '../permissions/action-guard.js';
|
|
15
|
-
import type {
|
|
16
|
-
CardType,
|
|
17
|
-
Workflow,
|
|
18
|
-
WorkflowState,
|
|
19
|
-
} from '../interfaces/resource-interfaces.js';
|
|
20
15
|
import { CardMetadataUpdater } from '../card-metadata-updater.js';
|
|
21
16
|
import type { Project } from '../containers/project.js';
|
|
17
|
+
import type { WorkflowState } from '../interfaces/resource-interfaces.js';
|
|
22
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Handles transitions.
|
|
21
|
+
*/
|
|
23
22
|
export class Transition {
|
|
23
|
+
/**
|
|
24
|
+
* Creates an instance of Transition command.
|
|
25
|
+
* @param project Project to use.
|
|
26
|
+
*/
|
|
24
27
|
constructor(private project: Project) {}
|
|
25
28
|
|
|
29
|
+
// Wrapper to run onTransition query.
|
|
30
|
+
private async transitionChangesQuery(cardKey: string, transition: string) {
|
|
31
|
+
if (!cardKey || !transition) return undefined;
|
|
32
|
+
return this.project.calculationEngine.runQuery('onTransition', 'localApp', {
|
|
33
|
+
cardKey,
|
|
34
|
+
transition,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
/**
|
|
27
39
|
* Transitions a card from its current state to a new state.
|
|
28
40
|
* @param cardKey card key
|
|
@@ -31,23 +43,18 @@ export class Transition {
|
|
|
31
43
|
public async cardTransition(cardKey: string, transition: WorkflowState) {
|
|
32
44
|
const card = this.project.findCard(cardKey);
|
|
33
45
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
card.metadata?.cardType || '',
|
|
37
|
-
);
|
|
38
|
-
if (cardType === undefined) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`Card's card type '${card.metadata?.cardType}' does not exist in the project`,
|
|
41
|
-
);
|
|
46
|
+
if (!card.metadata?.cardType) {
|
|
47
|
+
throw new Error(`Card does not have card type`);
|
|
42
48
|
}
|
|
49
|
+
// Card type
|
|
50
|
+
const cardType = this.project.resources
|
|
51
|
+
.byType(card.metadata?.cardType, 'cardTypes')
|
|
52
|
+
.show();
|
|
43
53
|
|
|
44
54
|
// Workflow
|
|
45
|
-
const workflow =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
`Card's workflow '${cardType.workflow}' does not exist in the project`,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
55
|
+
const workflow = this.project.resources
|
|
56
|
+
.byType(cardType.workflow, 'workflows')
|
|
57
|
+
.show();
|
|
51
58
|
|
|
52
59
|
// Check that the state transition can be made "from".
|
|
53
60
|
const foundFrom = workflow.transitions.find(
|
|
@@ -108,13 +115,4 @@ export class Transition {
|
|
|
108
115
|
.catch((error) => console.error(error));
|
|
109
116
|
}
|
|
110
117
|
}
|
|
111
|
-
|
|
112
|
-
// Wrapper to run onTransition query.
|
|
113
|
-
private async transitionChangesQuery(cardKey: string, transition: string) {
|
|
114
|
-
if (!cardKey || !transition) return undefined;
|
|
115
|
-
return this.project.calculationEngine.runQuery('onTransition', 'localApp', {
|
|
116
|
-
cardKey,
|
|
117
|
-
transition,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
118
|
}
|
package/src/commands/update.ts
CHANGED
|
@@ -19,16 +19,39 @@ import type {
|
|
|
19
19
|
RemoveOperation,
|
|
20
20
|
UpdateOperations,
|
|
21
21
|
} from '../resources/resource-object.js';
|
|
22
|
-
import { Project } from '../containers/project.js';
|
|
23
|
-
import { resourceName } from '../utils/resource-utils.js';
|
|
22
|
+
import type { Project } from '../containers/project.js';
|
|
24
23
|
import type { UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* Class that handles 'update' commands.
|
|
28
27
|
*/
|
|
29
28
|
export class Update {
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of Update command.
|
|
31
|
+
* @param project Project to use.
|
|
32
|
+
*/
|
|
30
33
|
constructor(private project: Project) {}
|
|
31
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Update single resource property
|
|
37
|
+
* This is similar to updateValue, but allows the operation to be fully specified
|
|
38
|
+
* @param name Name of the resource to operate on.
|
|
39
|
+
* @param updateKey Property to change in resource or in resource content.
|
|
40
|
+
* @param operation The full operation object
|
|
41
|
+
* @template Type Type of the target of the operation
|
|
42
|
+
* @template T Type of operation ('add', 'remove', 'change', 'rank')
|
|
43
|
+
* @template K Type of the key to change
|
|
44
|
+
*/
|
|
45
|
+
public async applyResourceOperation<
|
|
46
|
+
Type,
|
|
47
|
+
T extends UpdateOperations,
|
|
48
|
+
K extends string,
|
|
49
|
+
>(name: string, updateKey: UpdateKey<K>, operation: OperationFor<Type, T>) {
|
|
50
|
+
const type = this.project.resources.extractType(name);
|
|
51
|
+
const resource = this.project.resources.byType(name, type);
|
|
52
|
+
await resource?.update(updateKey, operation);
|
|
53
|
+
}
|
|
54
|
+
|
|
32
55
|
/**
|
|
33
56
|
* Updates single resource property.
|
|
34
57
|
* @param name Name of the resource to operate on.
|
|
@@ -95,24 +118,4 @@ export class Update {
|
|
|
95
118
|
await this.applyResourceOperation(name, { key: parsedKey }, op);
|
|
96
119
|
}
|
|
97
120
|
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Update single resource property
|
|
101
|
-
* This is similar to updateValue, but allows the operation to be fully specified
|
|
102
|
-
* @param name Name of the resource to operate on.
|
|
103
|
-
* @param updateKey Property to change in resource or in resource content.
|
|
104
|
-
* @param operation The full operation object
|
|
105
|
-
* @template Type Type of the target of the operation
|
|
106
|
-
* @template T Type of operation ('add', 'remove', 'change', 'rank')
|
|
107
|
-
* @template K Type of the key to change
|
|
108
|
-
*/
|
|
109
|
-
public async applyResourceOperation<
|
|
110
|
-
Type,
|
|
111
|
-
T extends UpdateOperations,
|
|
112
|
-
K extends string,
|
|
113
|
-
>(name: string, updateKey: UpdateKey<K>, operation: OperationFor<Type, T>) {
|
|
114
|
-
const resource = Project.resourceObject(this.project, resourceName(name));
|
|
115
|
-
await resource?.update(updateKey, operation);
|
|
116
|
-
this.project.collectLocalResources();
|
|
117
|
-
}
|
|
118
121
|
}
|