@cyberismo/data-handler 0.0.14 → 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 +8 -4
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +4 -0
- package/dist/command-handler.js +29 -19
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +25 -2
- package/dist/command-manager.js +30 -5
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +45 -93
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/edit.d.ts +1 -15
- package/dist/commands/edit.js +15 -89
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/export.d.ts +11 -2
- package/dist/commands/export.js +58 -58
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +9 -1
- package/dist/commands/import.js +17 -11
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.d.ts +1 -2
- package/dist/commands/move.js +107 -146
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +8 -1
- package/dist/commands/remove.js +17 -48
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +4 -9
- package/dist/commands/rename.js +34 -108
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +22 -34
- package/dist/commands/show.js +103 -151
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.d.ts +9 -2
- package/dist/commands/transition.js +49 -44
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +18 -12
- package/dist/commands/update.js +34 -18
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +18 -10
- package/dist/commands/validate.js +101 -47
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/card-container.d.ts +87 -24
- package/dist/containers/card-container.js +183 -279
- package/dist/containers/card-container.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +13 -4
- package/dist/containers/project/calculation-engine.js +79 -77
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project/card-cache.d.ts +146 -0
- package/dist/containers/project/card-cache.js +411 -0
- package/dist/containers/project/card-cache.js.map +1 -0
- 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 +114 -195
- package/dist/containers/project.js +425 -535
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +22 -32
- package/dist/containers/template.js +113 -115
- package/dist/containers/template.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/folder-content-interfaces.d.ts +7 -4
- package/dist/interfaces/folder-content-interfaces.js +3 -3
- package/dist/interfaces/folder-content-interfaces.js.map +1 -1
- package/dist/interfaces/macros.d.ts +1 -0
- package/dist/interfaces/macros.js +1 -1
- package/dist/interfaces/macros.js.map +1 -1
- package/dist/interfaces/project-interfaces.d.ts +7 -5
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +25 -22
- package/dist/interfaces/resource-interfaces.js +3 -0
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/common.d.ts +10 -10
- package/dist/macros/createCards/index.d.ts +0 -13
- package/dist/macros/createCards/index.js.map +1 -1
- package/dist/macros/createCards/types.d.ts +44 -0
- package/dist/macros/createCards/types.js +15 -0
- package/dist/macros/createCards/types.js.map +1 -0
- package/dist/macros/graph/index.d.ts +2 -6
- package/dist/macros/graph/index.js +14 -28
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/graph/types.d.ts +23 -0
- package/dist/macros/graph/types.js +15 -0
- package/dist/macros/graph/types.js.map +1 -0
- package/dist/macros/image/index.d.ts +8 -16
- package/dist/macros/image/index.js +36 -33
- package/dist/macros/image/index.js.map +1 -1
- package/dist/macros/image/types.d.ts +38 -0
- package/dist/macros/image/types.js +15 -0
- package/dist/macros/image/types.js.map +1 -0
- package/dist/macros/include/index.d.ts +1 -6
- package/dist/macros/include/index.js +4 -7
- package/dist/macros/include/index.js.map +1 -1
- package/dist/macros/include/types.d.ts +31 -0
- package/dist/macros/include/types.js +15 -0
- package/dist/macros/include/types.js.map +1 -0
- 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/percentage/index.d.ts +0 -6
- package/dist/macros/percentage/index.js.map +1 -1
- package/dist/macros/percentage/types.d.ts +31 -0
- package/dist/macros/percentage/types.js +15 -0
- package/dist/macros/percentage/types.js.map +1 -0
- package/dist/macros/report/index.d.ts +0 -3
- package/dist/macros/report/index.js +3 -6
- package/dist/macros/report/index.js.map +1 -1
- package/dist/macros/report/types.d.ts +19 -0
- package/dist/macros/report/types.js +15 -0
- package/dist/macros/report/types.js.map +1 -0
- package/dist/macros/scoreCard/index.d.ts +0 -6
- package/dist/macros/scoreCard/index.js.map +1 -1
- package/dist/macros/scoreCard/types.d.ts +31 -0
- package/dist/macros/scoreCard/types.js +15 -0
- package/dist/macros/scoreCard/types.js.map +1 -0
- package/dist/macros/types.d.ts +25 -0
- package/dist/macros/types.js +2 -0
- package/dist/macros/types.js.map +1 -0
- package/dist/macros/vega/index.d.ts +0 -4
- package/dist/macros/vega/index.js.map +1 -1
- package/dist/macros/vega/types.d.ts +20 -0
- package/dist/macros/vega/types.js +2 -0
- package/dist/macros/vega/types.js.map +1 -0
- package/dist/macros/vegalite/index.d.ts +0 -4
- package/dist/macros/vegalite/index.js.map +1 -1
- package/dist/macros/vegalite/types.d.ts +20 -0
- package/dist/macros/vegalite/types.js +15 -0
- package/dist/macros/vegalite/types.js.map +1 -0
- package/dist/macros/xref/index.d.ts +0 -3
- package/dist/macros/xref/index.js +5 -14
- package/dist/macros/xref/index.js.map +1 -1
- package/dist/macros/xref/types.d.ts +19 -0
- package/dist/macros/xref/types.js +15 -0
- package/dist/macros/xref/types.js.map +1 -0
- package/dist/module-manager.d.ts +16 -3
- package/dist/module-manager.js +55 -23
- 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 +6 -33
- package/dist/resources/calculation-resource.js +11 -60
- package/dist/resources/calculation-resource.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +10 -22
- package/dist/resources/card-type-resource.js +46 -66
- 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 +8 -22
- package/dist/resources/field-type-resource.js +35 -60
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +14 -35
- package/dist/resources/file-resource.js +22 -301
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +44 -66
- package/dist/resources/folder-resource.js +102 -149
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +9 -34
- package/dist/resources/graph-model-resource.js +18 -64
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +9 -29
- package/dist/resources/graph-view-resource.js +13 -48
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +9 -23
- package/dist/resources/link-type-resource.js +11 -33
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +10 -23
- package/dist/resources/report-resource.js +20 -67
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +143 -23
- package/dist/resources/resource-object.js +369 -48
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +10 -17
- package/dist/resources/template-resource.js +19 -27
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +9 -25
- package/dist/resources/workflow-resource.js +25 -55
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/card-utils.d.ts +69 -19
- package/dist/utils/card-utils.js +179 -30
- package/dist/utils/card-utils.js.map +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 +14 -7
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/clingo-parser.js +1 -1
- package/dist/utils/clingo-parser.js.map +1 -1
- package/dist/utils/constants.d.ts +2 -0
- package/dist/utils/constants.js +4 -0
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/csv.js +1 -1
- package/dist/utils/csv.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 +11 -11
- package/src/card-metadata-updater.ts +9 -7
- package/src/command-handler.ts +35 -23
- package/src/command-manager.ts +32 -19
- package/src/commands/create.ts +59 -160
- package/src/commands/edit.ts +16 -132
- package/src/commands/export.ts +71 -81
- package/src/commands/import.ts +26 -18
- package/src/commands/move.ts +143 -179
- package/src/commands/remove.ts +20 -59
- package/src/commands/rename.ts +45 -156
- package/src/commands/show.ts +153 -211
- package/src/commands/transition.ts +53 -58
- package/src/commands/update.ts +44 -23
- package/src/commands/validate.ts +108 -82
- package/src/containers/card-container.ts +200 -360
- package/src/containers/project/calculation-engine.ts +81 -105
- package/src/containers/project/card-cache.ts +497 -0
- 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 +551 -693
- package/src/containers/template.ts +129 -142
- package/src/index.ts +1 -0
- package/src/interfaces/folder-content-interfaces.ts +14 -7
- package/src/interfaces/macros.ts +2 -0
- package/src/interfaces/project-interfaces.ts +14 -7
- package/src/interfaces/resource-interfaces.ts +30 -27
- package/src/macros/createCards/index.ts +1 -12
- package/src/macros/createCards/types.ts +46 -0
- package/src/macros/graph/index.ts +27 -52
- package/src/macros/graph/types.ts +24 -0
- package/src/macros/image/index.ts +50 -61
- package/src/macros/image/types.ts +39 -0
- package/src/macros/include/index.ts +6 -15
- package/src/macros/include/types.ts +32 -0
- package/src/macros/index.ts +2 -2
- package/src/macros/percentage/index.ts +1 -7
- package/src/macros/percentage/types.ts +32 -0
- package/src/macros/report/index.ts +4 -13
- package/src/macros/report/types.ts +20 -0
- package/src/macros/scoreCard/index.ts +1 -7
- package/src/macros/scoreCard/types.ts +32 -0
- package/src/macros/types.ts +48 -0
- package/src/macros/vega/index.ts +1 -4
- package/src/macros/vega/types.ts +21 -0
- package/src/macros/vegalite/index.ts +1 -4
- package/src/macros/vegalite/types.ts +22 -0
- package/src/macros/xref/index.ts +6 -20
- package/src/macros/xref/types.ts +20 -0
- package/src/module-manager.ts +79 -22
- package/src/project-settings.ts +84 -15
- package/src/resources/calculation-resource.ts +21 -91
- package/src/resources/card-type-resource.ts +74 -109
- package/src/resources/create-defaults.ts +3 -2
- package/src/resources/field-type-resource.ts +61 -104
- package/src/resources/file-resource.ts +33 -441
- package/src/resources/folder-resource.ts +130 -207
- package/src/resources/graph-model-resource.ts +36 -95
- package/src/resources/graph-view-resource.ts +28 -70
- package/src/resources/link-type-resource.ts +23 -53
- package/src/resources/report-resource.ts +34 -96
- package/src/resources/resource-object.ts +511 -66
- package/src/resources/template-resource.ts +32 -44
- package/src/resources/workflow-resource.ts +42 -85
- package/src/utils/card-utils.ts +217 -31
- package/src/utils/clingo-fact-builder.ts +28 -16
- package/src/utils/clingo-facts.ts +16 -7
- package/src/utils/clingo-parser.ts +1 -1
- package/src/utils/constants.ts +6 -0
- package/src/utils/csv.ts +1 -1
- package/src/utils/resource-utils.ts +2 -1
- package/dist/containers/project/resource-collector.d.ts +0 -87
- package/dist/containers/project/resource-collector.js +0 -337
- package/dist/containers/project/resource-collector.js.map +0 -1
- package/src/containers/project/resource-collector.ts +0 -396
package/src/commands/show.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
// node
|
|
15
|
-
import {
|
|
15
|
+
import { readFileSync } from 'node:fs';
|
|
16
16
|
import { homedir } from 'node:os';
|
|
17
17
|
import { join, resolve } from 'node:path';
|
|
18
18
|
import { spawn } from 'node:child_process';
|
|
@@ -20,66 +20,61 @@ import { writeFile } from 'node:fs/promises';
|
|
|
20
20
|
|
|
21
21
|
import { MODULE_LIST_FULL_PATH } from './fetch.js';
|
|
22
22
|
|
|
23
|
-
import mime from 'mime-types';
|
|
24
|
-
|
|
25
23
|
import type { attachmentPayload } from '../interfaces/request-status-interfaces.js';
|
|
26
24
|
import type {
|
|
27
|
-
CardAttachment,
|
|
28
25
|
Card,
|
|
26
|
+
CardAttachment,
|
|
29
27
|
CardListContainer,
|
|
30
|
-
|
|
28
|
+
CardLocation,
|
|
29
|
+
CardWithChildrenCards,
|
|
30
|
+
Context,
|
|
31
|
+
FetchCardDetails,
|
|
32
|
+
FileContentType,
|
|
31
33
|
HubSetting,
|
|
34
|
+
ModuleContent,
|
|
32
35
|
ModuleSettingFromHub,
|
|
33
|
-
ProjectFetchCardDetails,
|
|
34
36
|
ProjectMetadata,
|
|
35
|
-
|
|
36
|
-
CardLocation,
|
|
37
|
-
Context,
|
|
38
|
-
ResourceFolderType,
|
|
37
|
+
ResourceType,
|
|
39
38
|
} from '../interfaces/project-interfaces.js';
|
|
40
39
|
import type {
|
|
40
|
+
AnyResourceContent,
|
|
41
41
|
CardType,
|
|
42
42
|
ResourceContent,
|
|
43
43
|
TemplateConfiguration,
|
|
44
44
|
Workflow,
|
|
45
45
|
} from '../interfaces/resource-interfaces.js';
|
|
46
|
-
import { Project,
|
|
47
|
-
import {
|
|
48
|
-
|
|
49
|
-
resourceName,
|
|
50
|
-
resourceNameToString,
|
|
51
|
-
} from '../utils/resource-utils.js';
|
|
52
|
-
import { TemplateResource } from '../resources/template-resource.js';
|
|
53
|
-
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';
|
|
54
49
|
|
|
50
|
+
import { UserPreferences } from '../utils/user-preferences.js';
|
|
55
51
|
import ReportMacro from '../macros/report/index.js';
|
|
56
52
|
import TaskQueue from '../macros/task-queue.js';
|
|
57
53
|
import { evaluateMacros } from '../macros/index.js';
|
|
58
|
-
import { FolderResource } from '../resources/folder-resource.js';
|
|
59
54
|
import { readJsonFile } from '../utils/json.js';
|
|
60
55
|
import { getChildLogger } from '../utils/log-utils.js';
|
|
56
|
+
import { buildCardHierarchy, flattenCardArray } from '../utils/card-utils.js';
|
|
61
57
|
|
|
62
58
|
/**
|
|
63
59
|
* Show command.
|
|
64
60
|
*/
|
|
65
61
|
export class Show {
|
|
66
|
-
private
|
|
62
|
+
private readonly resourceFunctions: Record<
|
|
67
63
|
string,
|
|
68
|
-
(from?: ResourcesFrom) =>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
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) {}
|
|
83
78
|
|
|
84
79
|
private get logger() {
|
|
85
80
|
return getChildLogger({
|
|
@@ -87,6 +82,29 @@ export class Show {
|
|
|
87
82
|
});
|
|
88
83
|
}
|
|
89
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
|
+
|
|
90
108
|
// Collect all labels from cards.
|
|
91
109
|
private collectLabels = (cards: Card[]): string[] => {
|
|
92
110
|
return cards.reduce<string[]>((labels, card) => {
|
|
@@ -94,28 +112,13 @@ export class Show {
|
|
|
94
112
|
if (card.metadata?.labels) {
|
|
95
113
|
labels.push(...card.metadata.labels);
|
|
96
114
|
}
|
|
97
|
-
// Recursively collect labels from subcards, if they exist
|
|
98
|
-
if (card.children) {
|
|
99
|
-
labels.push(...this.collectLabels(card.children));
|
|
100
|
-
}
|
|
101
115
|
return labels;
|
|
102
116
|
}, []);
|
|
103
117
|
};
|
|
104
118
|
|
|
105
119
|
// Returns attachment details
|
|
106
|
-
private
|
|
107
|
-
const
|
|
108
|
-
content: false,
|
|
109
|
-
metadata: true,
|
|
110
|
-
children: false,
|
|
111
|
-
parent: false,
|
|
112
|
-
attachments: true,
|
|
113
|
-
};
|
|
114
|
-
const card = await this.project.cardDetailsById(cardKey, details);
|
|
115
|
-
if (card === undefined) {
|
|
116
|
-
throw new Error(`Card '${cardKey}' does not exist in the project`);
|
|
117
|
-
}
|
|
118
|
-
|
|
120
|
+
private getAttachment(cardKey: string, filename: string) {
|
|
121
|
+
const card = this.project.findCard(cardKey);
|
|
119
122
|
const attachment =
|
|
120
123
|
card.attachments?.find((a) => a.fileName === filename) ?? undefined;
|
|
121
124
|
return attachment;
|
|
@@ -140,21 +143,19 @@ export class Show {
|
|
|
140
143
|
* Shows all template cards in a project.
|
|
141
144
|
* @returns all template cards in a project.
|
|
142
145
|
*/
|
|
143
|
-
public
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}),
|
|
157
|
-
);
|
|
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
|
+
});
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
/**
|
|
@@ -162,20 +163,8 @@ export class Show {
|
|
|
162
163
|
* @returns array of card attachments
|
|
163
164
|
*/
|
|
164
165
|
public async showAttachments(): Promise<CardAttachment[]> {
|
|
165
|
-
const attachments
|
|
166
|
-
const templateAttachments
|
|
167
|
-
const templates = await this.project.templates();
|
|
168
|
-
for (const template of templates) {
|
|
169
|
-
const templateResource = new TemplateResource(
|
|
170
|
-
this.project,
|
|
171
|
-
resourceName(template.name),
|
|
172
|
-
);
|
|
173
|
-
const templateObject = templateResource.templateObject();
|
|
174
|
-
if (templateObject) {
|
|
175
|
-
templateAttachments.push(...(await templateObject.attachments()));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
166
|
+
const attachments = this.project.attachments();
|
|
167
|
+
const templateAttachments = await this.attachmentsFromTemplates();
|
|
179
168
|
attachments.push(...templateAttachments);
|
|
180
169
|
return attachments;
|
|
181
170
|
}
|
|
@@ -186,32 +175,22 @@ export class Show {
|
|
|
186
175
|
* @param filename attachment filename
|
|
187
176
|
* @returns attachment details
|
|
188
177
|
*/
|
|
189
|
-
public
|
|
190
|
-
cardKey: string,
|
|
191
|
-
filename: string,
|
|
192
|
-
): Promise<attachmentPayload> {
|
|
178
|
+
public showAttachment(cardKey: string, filename: string): attachmentPayload {
|
|
193
179
|
if (!cardKey) {
|
|
194
180
|
throw new Error(`Mandatory parameter 'cardKey' missing`);
|
|
195
181
|
}
|
|
196
182
|
|
|
197
|
-
const attachment =
|
|
198
|
-
|
|
199
|
-
let attachmentPath: string = '';
|
|
200
|
-
if (attachment) {
|
|
201
|
-
attachmentPath = `${attachment.path}/${attachment.fileName}`;
|
|
202
|
-
}
|
|
183
|
+
const attachment = this.getAttachment(cardKey, filename);
|
|
203
184
|
|
|
204
|
-
if (!attachment
|
|
185
|
+
if (!attachment) {
|
|
205
186
|
throw new Error(`Attachment '${filename}' not found for card ${cardKey}`);
|
|
206
|
-
} else {
|
|
207
|
-
const fileBuffer = readFileSync(attachmentPath);
|
|
208
|
-
let mimeType = mime.lookup(attachmentPath);
|
|
209
|
-
if (mimeType === false) {
|
|
210
|
-
mimeType = 'application/octet-stream';
|
|
211
|
-
}
|
|
212
|
-
const payload: attachmentPayload = { fileBuffer, mimeType };
|
|
213
|
-
return payload;
|
|
214
187
|
}
|
|
188
|
+
|
|
189
|
+
const attachmentPath = `${attachment.path}/${attachment.fileName}`;
|
|
190
|
+
const fileBuffer = readFileSync(attachmentPath);
|
|
191
|
+
const mimeType = attachment.mimeType || 'application/octet-stream';
|
|
192
|
+
const payload: attachmentPayload = { fileBuffer, mimeType };
|
|
193
|
+
return payload;
|
|
215
194
|
}
|
|
216
195
|
|
|
217
196
|
/**
|
|
@@ -226,7 +205,7 @@ export class Show {
|
|
|
226
205
|
filename: string,
|
|
227
206
|
waitDelay: number = 1000,
|
|
228
207
|
) {
|
|
229
|
-
const attachment =
|
|
208
|
+
const attachment = this.getAttachment(cardKey, filename);
|
|
230
209
|
|
|
231
210
|
if (!attachment) {
|
|
232
211
|
throw new Error(`Attachment '${filename}' not found for card ${cardKey}`);
|
|
@@ -273,22 +252,29 @@ export class Show {
|
|
|
273
252
|
/**
|
|
274
253
|
* Shows details of a particular card (template card, or project card)
|
|
275
254
|
* @note Note that parameter 'cardKey' is optional due to technical limitations of class calling this class. It must be defined to get valid results.
|
|
276
|
-
* @param details card details to show
|
|
277
255
|
* @param cardKey card key to find
|
|
256
|
+
* @param contentType Content format in which content is to be shown
|
|
278
257
|
* @returns card details
|
|
279
258
|
*/
|
|
280
|
-
public
|
|
281
|
-
details: ProjectFetchCardDetails,
|
|
259
|
+
public showCardDetails(
|
|
282
260
|
cardKey?: string,
|
|
283
|
-
|
|
261
|
+
contentType?: FileContentType,
|
|
262
|
+
): Card {
|
|
284
263
|
if (!cardKey) {
|
|
285
264
|
throw new Error(`Mandatory parameter 'cardKey' missing`);
|
|
286
265
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
266
|
+
// todo: Make a constant about this
|
|
267
|
+
const details: FetchCardDetails = {
|
|
268
|
+
parent: true,
|
|
269
|
+
metadata: true,
|
|
270
|
+
children: true,
|
|
271
|
+
attachments: true,
|
|
272
|
+
content: true,
|
|
273
|
+
};
|
|
274
|
+
if (contentType) {
|
|
275
|
+
details.contentType = contentType;
|
|
290
276
|
}
|
|
291
|
-
return
|
|
277
|
+
return this.project.findCard(cardKey, details);
|
|
292
278
|
}
|
|
293
279
|
|
|
294
280
|
/**
|
|
@@ -316,73 +302,13 @@ export class Show {
|
|
|
316
302
|
* @returns array of card type details
|
|
317
303
|
*/
|
|
318
304
|
public async showCardTypesWithDetails(): Promise<(CardType | undefined)[]> {
|
|
319
|
-
const
|
|
320
|
-
for (const cardType of
|
|
321
|
-
|
|
322
|
-
cardType.
|
|
323
|
-
);
|
|
324
|
-
if (cardTypeDetails) {
|
|
325
|
-
promiseContainer.push(cardTypeDetails);
|
|
305
|
+
const container = [];
|
|
306
|
+
for (const cardType of this.project.resources.cardTypes()) {
|
|
307
|
+
if (cardType.data) {
|
|
308
|
+
container.push(cardType.data);
|
|
326
309
|
}
|
|
327
310
|
}
|
|
328
|
-
|
|
329
|
-
return results.filter((item) => item);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Shows the content of a file in a resource.
|
|
334
|
-
* TODO: To be removed
|
|
335
|
-
* @deprecated
|
|
336
|
-
* @param resourceName Name of the resource.
|
|
337
|
-
* @param fileName Name of the file to show.
|
|
338
|
-
* @returns the content of the file.
|
|
339
|
-
*/
|
|
340
|
-
public async showFile(
|
|
341
|
-
resourceName: ResourceName,
|
|
342
|
-
fileName: string,
|
|
343
|
-
): Promise<string> {
|
|
344
|
-
const resourceNameStr = resourceNameToString(resourceName);
|
|
345
|
-
if (
|
|
346
|
-
!(await this.project.resourceExists(
|
|
347
|
-
resourceName.type as ResourceFolderType,
|
|
348
|
-
resourceNameStr,
|
|
349
|
-
))
|
|
350
|
-
) {
|
|
351
|
-
throw new Error(
|
|
352
|
-
`Resource '${resourceNameStr}' does not exist in the project`,
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
const resource = Project.resourceObject(this.project, resourceName);
|
|
356
|
-
if (!(resource instanceof FolderResource)) {
|
|
357
|
-
throw new Error(`Resource '${resourceNameStr}' is not a folder resource`);
|
|
358
|
-
}
|
|
359
|
-
return resource.showFile(fileName);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Shows all file names in a folder resource.
|
|
364
|
-
* TODO: To be removed
|
|
365
|
-
* @deprecated
|
|
366
|
-
* @param resourceName Name of the resource.
|
|
367
|
-
* @returns all file names in the resource.
|
|
368
|
-
*/
|
|
369
|
-
public async showFileNames(resourceName: ResourceName): Promise<string[]> {
|
|
370
|
-
const resourceNameStr = resourceNameToString(resourceName);
|
|
371
|
-
if (
|
|
372
|
-
!(await this.project.resourceExists(
|
|
373
|
-
resourceName.type as ResourceFolderType,
|
|
374
|
-
resourceNameStr,
|
|
375
|
-
))
|
|
376
|
-
) {
|
|
377
|
-
throw new Error(
|
|
378
|
-
`Resource '${resourceNameStr}' does not exist in the project`,
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
const resource = Project.resourceObject(this.project, resourceName);
|
|
382
|
-
if (!(resource instanceof FolderResource)) {
|
|
383
|
-
throw new Error(`Resource '${resourceNameStr}' is not a folder resource`);
|
|
384
|
-
}
|
|
385
|
-
return resource.showFileNames();
|
|
311
|
+
return container;
|
|
386
312
|
}
|
|
387
313
|
|
|
388
314
|
/**
|
|
@@ -405,10 +331,10 @@ export class Show {
|
|
|
405
331
|
resolve(this.project.basePath, MODULE_LIST_FULL_PATH),
|
|
406
332
|
)
|
|
407
333
|
).modules;
|
|
408
|
-
const currentModules =
|
|
334
|
+
const currentModules = this.project.resources.moduleNames();
|
|
409
335
|
const nonImportedModules = moduleList.filter(
|
|
410
336
|
(item: ModuleSettingFromHub) => {
|
|
411
|
-
return !currentModules.some((module) => item.name === module
|
|
337
|
+
return !currentModules.some((module) => item.name === module);
|
|
412
338
|
},
|
|
413
339
|
);
|
|
414
340
|
|
|
@@ -436,12 +362,12 @@ export class Show {
|
|
|
436
362
|
* Returns all unique labels in a project
|
|
437
363
|
* @returns labels in a list
|
|
438
364
|
*/
|
|
439
|
-
public
|
|
440
|
-
const cards =
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
365
|
+
public showLabels(): string[] {
|
|
366
|
+
const cards = flattenCardArray(
|
|
367
|
+
this.project.showProjectCards(),
|
|
368
|
+
this.project,
|
|
369
|
+
);
|
|
370
|
+
const templateCards = this.project.allTemplateCards();
|
|
445
371
|
|
|
446
372
|
const labels = this.collectLabels([...cards, ...templateCards]);
|
|
447
373
|
return Array.from(new Set(labels));
|
|
@@ -479,20 +405,18 @@ export class Show {
|
|
|
479
405
|
|
|
480
406
|
/**
|
|
481
407
|
* Returns all project cards in the project. Cards don't have content and nor metadata.
|
|
482
|
-
* @note AppUi uses this method.
|
|
483
408
|
* @returns array of cards
|
|
484
409
|
*/
|
|
485
|
-
public
|
|
486
|
-
|
|
487
|
-
return projectCards;
|
|
410
|
+
public showProjectCards(): Card[] {
|
|
411
|
+
return this.project.showProjectCards();
|
|
488
412
|
}
|
|
489
413
|
|
|
490
414
|
/**
|
|
491
415
|
* Shows all modules (if any) in a project.
|
|
492
416
|
* @returns all modules in a project.
|
|
493
417
|
*/
|
|
494
|
-
public
|
|
495
|
-
return
|
|
418
|
+
public showModules(): string[] {
|
|
419
|
+
return this.project.resources.moduleNames().sort();
|
|
496
420
|
}
|
|
497
421
|
|
|
498
422
|
/**
|
|
@@ -508,6 +432,7 @@ export class Show {
|
|
|
508
432
|
* @param reportName Name of the report to show
|
|
509
433
|
* @param cardKey Card key to use for the report
|
|
510
434
|
* @param parameters Additional parameters for the report
|
|
435
|
+
* @param context Context for resource (includes a project instance)
|
|
511
436
|
* @param outputPath Optional output path for the report
|
|
512
437
|
* @returns Report results as a string
|
|
513
438
|
* @throws Error if the report does not exist
|
|
@@ -520,9 +445,9 @@ export class Show {
|
|
|
520
445
|
outputPath?: string,
|
|
521
446
|
): Promise<string> {
|
|
522
447
|
if (
|
|
523
|
-
!
|
|
524
|
-
(
|
|
525
|
-
|
|
448
|
+
!this.project.resources
|
|
449
|
+
.reports()
|
|
450
|
+
.some((report) => report.data?.name === reportName)
|
|
526
451
|
) {
|
|
527
452
|
throw new Error(`Report '${reportName}' does not exist`);
|
|
528
453
|
}
|
|
@@ -564,17 +489,35 @@ export class Show {
|
|
|
564
489
|
/**
|
|
565
490
|
* Shows details of certain resource.
|
|
566
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.
|
|
567
494
|
* @returns resource metadata as JSON.
|
|
568
495
|
*/
|
|
569
496
|
public async showResource(
|
|
570
497
|
name: string,
|
|
571
|
-
showUse
|
|
572
|
-
): Promise<
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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);
|
|
578
521
|
const [details, usage] = await Promise.all([
|
|
579
522
|
resource?.show(),
|
|
580
523
|
showUse ? resource?.usage() : [],
|
|
@@ -595,9 +538,9 @@ export class Show {
|
|
|
595
538
|
* @returns sorted array of resources
|
|
596
539
|
*/
|
|
597
540
|
public async showResources(type: string): Promise<string[]> {
|
|
598
|
-
const func = this.
|
|
541
|
+
const func = this.resourceFunctions[type];
|
|
599
542
|
if (!func) return [];
|
|
600
|
-
return
|
|
543
|
+
return func().sort();
|
|
601
544
|
}
|
|
602
545
|
|
|
603
546
|
/**
|
|
@@ -605,23 +548,22 @@ export class Show {
|
|
|
605
548
|
* @returns all templates in a project.
|
|
606
549
|
*/
|
|
607
550
|
public async showTemplatesWithDetails(): Promise<TemplateConfiguration[]> {
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
return
|
|
551
|
+
const templates = [];
|
|
552
|
+
for (const template of this.project.resources.templates()) {
|
|
553
|
+
templates.push(template.show());
|
|
554
|
+
}
|
|
555
|
+
return templates;
|
|
613
556
|
}
|
|
614
557
|
|
|
615
558
|
/**
|
|
616
559
|
* Shows all workflows with full details in a project.
|
|
617
560
|
* @returns workflows with full details
|
|
618
561
|
*/
|
|
619
|
-
public
|
|
620
|
-
const
|
|
621
|
-
for (const workflow of
|
|
622
|
-
|
|
562
|
+
public showWorkflowsWithDetails(): (Workflow | undefined)[] {
|
|
563
|
+
const workflows = [];
|
|
564
|
+
for (const workflow of this.project.resources.workflows()) {
|
|
565
|
+
workflows.push(workflow.data);
|
|
623
566
|
}
|
|
624
|
-
|
|
625
|
-
return results.filter((item) => item);
|
|
567
|
+
return workflows;
|
|
626
568
|
}
|
|
627
569
|
}
|