@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
|
@@ -12,42 +12,38 @@
|
|
|
12
12
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { readdir } from 'node:fs/promises';
|
|
16
15
|
import { extname, join } from 'node:path';
|
|
16
|
+
import { readdir } from 'node:fs/promises';
|
|
17
17
|
|
|
18
|
+
import { copyDir } from '../utils/file-utils.js';
|
|
19
|
+
import { DefaultContent } from './create-defaults.js';
|
|
20
|
+
import { FolderResource } from './folder-resource.js';
|
|
21
|
+
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
22
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
23
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
24
|
+
|
|
25
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
26
|
+
import type { GraphViewContent } from '../interfaces/folder-content-interfaces.js';
|
|
18
27
|
import type {
|
|
19
|
-
Card,
|
|
20
|
-
Operation,
|
|
21
|
-
Project,
|
|
22
|
-
ResourceName,
|
|
23
|
-
} from './folder-resource.js';
|
|
24
|
-
import {
|
|
25
|
-
DefaultContent,
|
|
26
|
-
FolderResource,
|
|
27
|
-
resourceNameToString,
|
|
28
|
-
sortCards,
|
|
29
|
-
} from './folder-resource.js';
|
|
30
|
-
import type {
|
|
31
|
-
GraphView,
|
|
32
28
|
GraphViewMetadata,
|
|
33
|
-
|
|
29
|
+
UpdateKey,
|
|
34
30
|
} from '../interfaces/resource-interfaces.js';
|
|
35
|
-
import type {
|
|
36
|
-
|
|
37
|
-
import {
|
|
38
|
-
import { copyDir } from '../utils/file-utils.js';
|
|
31
|
+
import type { Operation } from './resource-object.js';
|
|
32
|
+
import type { Project } from '../containers/project.js';
|
|
33
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
39
34
|
|
|
40
35
|
/**
|
|
41
36
|
* Graph view resource class.
|
|
42
37
|
*/
|
|
43
|
-
export class GraphViewResource extends FolderResource
|
|
38
|
+
export class GraphViewResource extends FolderResource<
|
|
39
|
+
GraphViewMetadata,
|
|
40
|
+
GraphViewContent
|
|
41
|
+
> {
|
|
44
42
|
constructor(project: Project, name: ResourceName) {
|
|
45
43
|
super(project, name, 'graphViews');
|
|
46
44
|
|
|
47
45
|
this.contentSchemaId = 'graphViewSchema';
|
|
48
46
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
49
|
-
|
|
50
|
-
this.initialize();
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
/**
|
|
@@ -83,20 +79,8 @@ export class GraphViewResource extends FolderResource {
|
|
|
83
79
|
join(await getStaticDirectoryPath(), 'defaultGraphView'),
|
|
84
80
|
this.internalFolder,
|
|
85
81
|
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Returns resource content.
|
|
90
|
-
*/
|
|
91
|
-
public get data(): GraphView {
|
|
92
|
-
return super.data as GraphView;
|
|
93
|
-
}
|
|
94
82
|
|
|
95
|
-
|
|
96
|
-
* Deletes file and folder that this resource is based on.
|
|
97
|
-
*/
|
|
98
|
-
public async delete() {
|
|
99
|
-
return super.delete();
|
|
83
|
+
await this.loadContentFiles();
|
|
100
84
|
}
|
|
101
85
|
|
|
102
86
|
/**
|
|
@@ -125,33 +109,24 @@ export class GraphViewResource extends FolderResource {
|
|
|
125
109
|
return this.onNameChange(existingName);
|
|
126
110
|
}
|
|
127
111
|
|
|
128
|
-
/**
|
|
129
|
-
* Shows metadata of the resource.
|
|
130
|
-
* @returns graph view metadata.
|
|
131
|
-
*/
|
|
132
|
-
public async show(): Promise<GraphView> {
|
|
133
|
-
const baseData = (await super.show()) as GraphViewMetadata;
|
|
134
|
-
return {
|
|
135
|
-
...baseData,
|
|
136
|
-
content: (await super.contentData()) as GraphViewContent,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
112
|
/**
|
|
141
113
|
* Updates graph view resource.
|
|
142
|
-
* @param
|
|
114
|
+
* @param updateKey Key to modify
|
|
143
115
|
* @param op Operation to perform on 'key'
|
|
144
116
|
*/
|
|
145
|
-
public async update<Type
|
|
146
|
-
|
|
117
|
+
public async update<Type, K extends string>(
|
|
118
|
+
updateKey: UpdateKey<K>,
|
|
119
|
+
op: Operation<Type>,
|
|
120
|
+
) {
|
|
121
|
+
if (updateKey.key === 'category') {
|
|
147
122
|
const content = structuredClone(this.content) as GraphViewMetadata;
|
|
148
123
|
content.category = super.handleScalar(op) as string;
|
|
149
124
|
|
|
150
|
-
await super.postUpdate(content,
|
|
125
|
+
await super.postUpdate(content, updateKey, op);
|
|
151
126
|
return;
|
|
152
127
|
}
|
|
153
128
|
|
|
154
|
-
await super.update(
|
|
129
|
+
await super.update(updateKey, op);
|
|
155
130
|
}
|
|
156
131
|
|
|
157
132
|
/**
|
|
@@ -162,28 +137,11 @@ export class GraphViewResource extends FolderResource {
|
|
|
162
137
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
163
138
|
*/
|
|
164
139
|
public async usage(cards?: Card[]): Promise<string[]> {
|
|
165
|
-
const allCards = cards ??
|
|
140
|
+
const allCards = cards ?? super.cards();
|
|
166
141
|
const [relevantCards, calculations] = await Promise.all([
|
|
167
142
|
super.usage(allCards),
|
|
168
143
|
super.calculations(),
|
|
169
144
|
]);
|
|
170
145
|
return [...relevantCards.sort(sortCards), ...calculations];
|
|
171
146
|
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Validates graph view.
|
|
175
|
-
* @throws when there are validation errors.
|
|
176
|
-
* @param content Content to be validated.
|
|
177
|
-
* @note If content is not provided, base class validation will use resource's current content.
|
|
178
|
-
*/
|
|
179
|
-
public async validate(content?: object) {
|
|
180
|
-
return super.validate(content);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Create the graph view's folder and handlebar file.
|
|
185
|
-
*/
|
|
186
|
-
public async write() {
|
|
187
|
-
await super.write();
|
|
188
|
-
}
|
|
189
147
|
}
|
|
@@ -10,37 +10,32 @@
|
|
|
10
10
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from '
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
sortCards,
|
|
24
|
-
} from './folder-resource.js';
|
|
25
|
-
import type { LinkType } from '../interfaces/resource-interfaces.js';
|
|
13
|
+
import { DefaultContent } from './create-defaults.js';
|
|
14
|
+
import { FileResource } from './file-resource.js';
|
|
15
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
16
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
17
|
+
|
|
18
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
19
|
+
import type { LinkType, UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
20
|
+
import type { Operation } from './resource-object.js';
|
|
21
|
+
import type { Project } from '../containers/project.js';
|
|
22
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
26
23
|
|
|
27
24
|
/**
|
|
28
25
|
* Link Type resource class.
|
|
29
26
|
*/
|
|
30
|
-
export class LinkTypeResource extends FileResource {
|
|
27
|
+
export class LinkTypeResource extends FileResource<LinkType> {
|
|
31
28
|
constructor(project: Project, name: ResourceName) {
|
|
32
29
|
super(project, name, 'linkTypes');
|
|
33
30
|
|
|
34
31
|
this.contentSchemaId = 'linkTypeSchema';
|
|
35
32
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
36
|
-
|
|
37
|
-
this.initialize();
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
// When resource name changes.
|
|
41
36
|
private async handleNameChange(existingName: string) {
|
|
42
|
-
const current = this.content
|
|
43
|
-
const prefixes =
|
|
37
|
+
const current = this.content;
|
|
38
|
+
const prefixes = this.project.projectPrefixes();
|
|
44
39
|
if (current.sourceCardTypes) {
|
|
45
40
|
current.sourceCardTypes = current.sourceCardTypes.map((item) =>
|
|
46
41
|
this.updatePrefixInResourceName(item, prefixes),
|
|
@@ -74,20 +69,6 @@ export class LinkTypeResource extends FileResource {
|
|
|
74
69
|
return super.create(newContent);
|
|
75
70
|
}
|
|
76
71
|
|
|
77
|
-
/**
|
|
78
|
-
* Returns content data.
|
|
79
|
-
*/
|
|
80
|
-
public get data() {
|
|
81
|
-
return super.data as LinkType;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Deletes file(s) from disk and clears out the memory resident object.
|
|
86
|
-
*/
|
|
87
|
-
public async delete() {
|
|
88
|
-
return super.delete();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
72
|
/**
|
|
92
73
|
* Renames resource metadata file and renames memory resident object 'name'.
|
|
93
74
|
* @param newName New name for the resource.
|
|
@@ -98,26 +79,22 @@ export class LinkTypeResource extends FileResource {
|
|
|
98
79
|
return this.handleNameChange(existingName);
|
|
99
80
|
}
|
|
100
81
|
|
|
101
|
-
/**
|
|
102
|
-
* Shows metadata of the resource.
|
|
103
|
-
* @returns link type metadata.
|
|
104
|
-
*/
|
|
105
|
-
public async show(): Promise<LinkType> {
|
|
106
|
-
return super.show() as Promise<LinkType>;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
82
|
/**
|
|
110
83
|
* Updates link type resource.
|
|
111
|
-
* @param
|
|
84
|
+
* @param updateKey Key to modify
|
|
112
85
|
* @param op Operation to perform on 'key'
|
|
113
86
|
*/
|
|
114
|
-
public async update<Type
|
|
87
|
+
public async update<Type, K extends string>(
|
|
88
|
+
updateKey: UpdateKey<K>,
|
|
89
|
+
op: Operation<Type>,
|
|
90
|
+
) {
|
|
91
|
+
const { key } = updateKey;
|
|
115
92
|
const nameChange = key === 'name';
|
|
116
93
|
const existingName = this.content.name;
|
|
117
94
|
|
|
118
|
-
await super.update(
|
|
95
|
+
await super.update(updateKey, op);
|
|
119
96
|
|
|
120
|
-
const content = structuredClone(this.content)
|
|
97
|
+
const content = structuredClone(this.content);
|
|
121
98
|
if (key === 'name') {
|
|
122
99
|
content.name = super.handleScalar(op) as string;
|
|
123
100
|
} else if (key === 'destinationCardTypes') {
|
|
@@ -142,7 +119,7 @@ export class LinkTypeResource extends FileResource {
|
|
|
142
119
|
throw new Error(`Unknown property '${key}' for FieldType`);
|
|
143
120
|
}
|
|
144
121
|
|
|
145
|
-
await super.postUpdate(content,
|
|
122
|
+
await super.postUpdate(content, updateKey, op);
|
|
146
123
|
|
|
147
124
|
// Renaming this card type causes that references to its name must be updated.
|
|
148
125
|
if (nameChange) {
|
|
@@ -159,7 +136,7 @@ export class LinkTypeResource extends FileResource {
|
|
|
159
136
|
*/
|
|
160
137
|
public async usage(cards?: Card[]): Promise<string[]> {
|
|
161
138
|
const resourceName = resourceNameToString(this.resourceName);
|
|
162
|
-
const allCards = cards ||
|
|
139
|
+
const allCards = cards || super.cards();
|
|
163
140
|
|
|
164
141
|
const cardsThatUseLinkType = allCards
|
|
165
142
|
.filter((card) =>
|
|
@@ -181,11 +158,4 @@ export class LinkTypeResource extends FileResource {
|
|
|
181
158
|
// Using Set to avoid duplicate cards
|
|
182
159
|
return [...new Set([...cardReferences, ...calculations])];
|
|
183
160
|
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Validates the resource. If object is invalid, throws.
|
|
187
|
-
*/
|
|
188
|
-
public async validate(content?: object) {
|
|
189
|
-
return super.validate(content);
|
|
190
|
-
}
|
|
191
161
|
}
|
|
@@ -12,72 +12,48 @@
|
|
|
12
12
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { readdir } from 'node:fs/promises';
|
|
16
|
-
import { readFileSync } from 'node:fs';
|
|
17
15
|
import { extname, join } from 'node:path';
|
|
16
|
+
import { readdir } from 'node:fs/promises';
|
|
18
17
|
|
|
19
18
|
import { copyDir } from '../utils/file-utils.js';
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
FolderResource,
|
|
23
|
-
resourceNameToString,
|
|
24
|
-
sortCards,
|
|
25
|
-
} from './folder-resource.js';
|
|
19
|
+
import { DefaultContent } from './create-defaults.js';
|
|
20
|
+
import { FolderResource } from './folder-resource.js';
|
|
26
21
|
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
27
|
-
import {
|
|
22
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
23
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
28
24
|
import { Validate } from '../commands/validate.js';
|
|
29
25
|
|
|
26
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
27
|
+
import type { Operation } from './resource-object.js';
|
|
28
|
+
import type { Project } from '../containers/project.js';
|
|
29
|
+
import type { ReportContent } from '../interfaces/folder-content-interfaces.js';
|
|
30
30
|
import type {
|
|
31
|
-
Card,
|
|
32
|
-
Operation,
|
|
33
|
-
Project,
|
|
34
|
-
ResourceName,
|
|
35
|
-
} from './folder-resource.js';
|
|
36
|
-
import type {
|
|
37
|
-
Report,
|
|
38
31
|
ReportMetadata,
|
|
39
|
-
|
|
32
|
+
UpdateKey,
|
|
40
33
|
} from '../interfaces/resource-interfaces.js';
|
|
41
|
-
import type {
|
|
42
|
-
import type { Schema } from 'jsonschema';
|
|
34
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
43
35
|
|
|
44
|
-
const REPORT_SCHEMA_FILE = 'parameterSchema.json';
|
|
45
36
|
const PARAMETER_SCHEMA_ID = 'jsonSchema';
|
|
46
37
|
|
|
47
|
-
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
48
|
-
|
|
49
38
|
/**
|
|
50
39
|
* Report resource class.
|
|
51
40
|
*/
|
|
52
|
-
export class ReportResource extends FolderResource
|
|
53
|
-
|
|
41
|
+
export class ReportResource extends FolderResource<
|
|
42
|
+
ReportMetadata,
|
|
43
|
+
ReportContent
|
|
44
|
+
> {
|
|
54
45
|
constructor(project: Project, name: ResourceName) {
|
|
55
46
|
super(project, name, 'reports');
|
|
56
47
|
|
|
57
48
|
this.contentSchemaId = 'reportSchema';
|
|
58
49
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
59
|
-
|
|
60
|
-
this.initialize();
|
|
61
|
-
|
|
62
|
-
const schemaPath = join(this.internalFolder, REPORT_SCHEMA_FILE);
|
|
63
|
-
this.reportSchema = this.readSchemaFile(schemaPath);
|
|
64
50
|
}
|
|
65
51
|
|
|
66
52
|
// Path to content folder.
|
|
67
53
|
// @todo: create the files' content dynamically.
|
|
68
|
-
private
|
|
69
|
-
staticDirectoryPath
|
|
70
|
-
'defaultReport'
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Try to read schema file content
|
|
74
|
-
private readSchemaFile(path: string) {
|
|
75
|
-
try {
|
|
76
|
-
const schema = readFileSync(path);
|
|
77
|
-
return JSON.parse(schema.toString());
|
|
78
|
-
} catch {
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
54
|
+
private async getDefaultReportLocation(): Promise<string> {
|
|
55
|
+
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
56
|
+
return join(staticDirectoryPath, 'defaultReport');
|
|
81
57
|
}
|
|
82
58
|
|
|
83
59
|
/**
|
|
@@ -99,8 +75,6 @@ export class ReportResource extends FolderResource {
|
|
|
99
75
|
|
|
100
76
|
/**
|
|
101
77
|
* Sets new metadata into the report object.
|
|
102
|
-
* @param newContent metadata content for the report.
|
|
103
|
-
* @throws if 'newContent' is not valid.
|
|
104
78
|
*/
|
|
105
79
|
public async createReport() {
|
|
106
80
|
const defaultContent = DefaultContent.report(
|
|
@@ -110,21 +84,9 @@ export class ReportResource extends FolderResource {
|
|
|
110
84
|
await super.create(defaultContent);
|
|
111
85
|
|
|
112
86
|
// Copy report default structure to destination.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Returns resource content.
|
|
118
|
-
*/
|
|
119
|
-
public get data(): ReportMetadata {
|
|
120
|
-
return super.data as ReportMetadata;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Deletes file and folder that this resource is based on.
|
|
125
|
-
*/
|
|
126
|
-
public async delete() {
|
|
127
|
-
return super.delete();
|
|
87
|
+
const defaultReportLocation = await this.getDefaultReportLocation();
|
|
88
|
+
await copyDir(defaultReportLocation, this.internalFolder);
|
|
89
|
+
await this.loadContentFiles();
|
|
128
90
|
}
|
|
129
91
|
|
|
130
92
|
/**
|
|
@@ -152,49 +114,24 @@ export class ReportResource extends FolderResource {
|
|
|
152
114
|
return this.onNameChange(existingName);
|
|
153
115
|
}
|
|
154
116
|
|
|
155
|
-
/**
|
|
156
|
-
* Shows metadata of the resource.
|
|
157
|
-
* @returns report metadata.
|
|
158
|
-
*/
|
|
159
|
-
public async show(): Promise<Report> {
|
|
160
|
-
const baseData = (await super.show()) as ReportMetadata;
|
|
161
|
-
const fileContents = await super.contentData();
|
|
162
|
-
const content: ReportContent = {
|
|
163
|
-
contentTemplate: fileContents.contentTemplate as string,
|
|
164
|
-
queryTemplate: fileContents.queryTemplate as string,
|
|
165
|
-
schema: fileContents.schema ? (fileContents.schema as Schema) : undefined,
|
|
166
|
-
};
|
|
167
|
-
return {
|
|
168
|
-
...baseData,
|
|
169
|
-
content: content,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
117
|
/**
|
|
174
118
|
* Updates report resource.
|
|
175
|
-
* @param
|
|
119
|
+
* @param updateKey Key to modify
|
|
176
120
|
* @param op Operation to perform on 'key'
|
|
177
121
|
*/
|
|
178
|
-
public async update<Type
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const fileContent = JSON.stringify(super.handleScalar(op), null, 2);
|
|
185
|
-
await this.updateFile(filename(key.subKey)!, fileContent);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (key === 'category') {
|
|
190
|
-
const content = structuredClone(this.content) as ReportMetadata;
|
|
122
|
+
public async update<Type, K extends string>(
|
|
123
|
+
updateKey: UpdateKey<K>,
|
|
124
|
+
op: Operation<Type>,
|
|
125
|
+
) {
|
|
126
|
+
if (updateKey.key === 'category') {
|
|
127
|
+
const content = structuredClone(this.content);
|
|
191
128
|
content.category = super.handleScalar(op) as string;
|
|
192
129
|
|
|
193
|
-
await super.postUpdate(content,
|
|
130
|
+
await super.postUpdate(content, updateKey, op);
|
|
194
131
|
return;
|
|
195
132
|
}
|
|
196
133
|
|
|
197
|
-
await super.update(
|
|
134
|
+
await super.update(updateKey, op);
|
|
198
135
|
}
|
|
199
136
|
|
|
200
137
|
/**
|
|
@@ -205,7 +142,7 @@ export class ReportResource extends FolderResource {
|
|
|
205
142
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
206
143
|
*/
|
|
207
144
|
public async usage(cards?: Card[]): Promise<string[]> {
|
|
208
|
-
const allCards = cards ??
|
|
145
|
+
const allCards = cards ?? super.cards();
|
|
209
146
|
const [relevantCards, calculations] = await Promise.all([
|
|
210
147
|
super.usage(allCards),
|
|
211
148
|
super.calculations(),
|
|
@@ -220,9 +157,10 @@ export class ReportResource extends FolderResource {
|
|
|
220
157
|
* @note If content is not provided, base class validation will use resource's current content.
|
|
221
158
|
*/
|
|
222
159
|
public async validate(content?: object) {
|
|
223
|
-
|
|
160
|
+
const resourceContent = this.contentData();
|
|
161
|
+
if (resourceContent.schema) {
|
|
224
162
|
const errors = Validate.getInstance().validateJson(
|
|
225
|
-
|
|
163
|
+
resourceContent.schema,
|
|
226
164
|
PARAMETER_SCHEMA_ID,
|
|
227
165
|
);
|
|
228
166
|
if (errors.length > 0) {
|