@cyberismo/data-handler 0.0.6 → 0.0.8
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/README.md +1 -0
- package/dist/card-metadata-updater.d.ts +1 -0
- package/dist/card-metadata-updater.js +7 -2
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +6 -1
- package/dist/command-handler.js +16 -15
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +15 -4
- package/dist/command-manager.js +41 -9
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/calculate.d.ts +4 -10
- package/dist/commands/calculate.js +67 -78
- package/dist/commands/calculate.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +15 -10
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/export.js +3 -3
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +3 -8
- package/dist/commands/import.js +17 -15
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/index.d.ts +1 -2
- package/dist/commands/index.js +1 -2
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/remove.d.ts +1 -1
- package/dist/commands/remove.js +4 -10
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/show.d.ts +6 -3
- package/dist/commands/show.js +8 -5
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/validate.d.ts +0 -8
- package/dist/commands/validate.js +6 -36
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/project/project-content-watcher.d.ts +28 -0
- package/dist/containers/project/project-content-watcher.js +54 -0
- package/dist/containers/project/project-content-watcher.js.map +1 -0
- package/dist/containers/project/project-paths.js +1 -1
- package/dist/containers/project/project-paths.js.map +1 -1
- package/dist/containers/project/resource-collector.d.ts +2 -1
- package/dist/containers/project/resource-collector.js +33 -23
- package/dist/containers/project/resource-collector.js.map +1 -1
- package/dist/containers/project.d.ts +9 -7
- package/dist/containers/project.js +58 -18
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +1 -0
- package/dist/containers/template.js +7 -2
- package/dist/containers/template.js.map +1 -1
- package/dist/exceptions/index.d.ts +20 -0
- package/dist/exceptions/index.js +16 -0
- package/dist/exceptions/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/macros.d.ts +5 -1
- package/dist/interfaces/project-interfaces.d.ts +5 -0
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +14 -22
- package/dist/interfaces/resource-interfaces.js +10 -9
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/base-macro.d.ts +2 -0
- package/dist/macros/base-macro.js +66 -19
- package/dist/macros/base-macro.js.map +1 -1
- package/dist/macros/graph/index.d.ts +0 -1
- package/dist/macros/graph/index.js +16 -12
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/index.d.ts +30 -3
- package/dist/macros/index.js +36 -6
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/report/index.d.ts +13 -10
- package/dist/macros/report/index.js +35 -38
- package/dist/macros/report/index.js.map +1 -1
- package/dist/module-manager.d.ts +32 -11
- package/dist/module-manager.js +301 -147
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.js +8 -8
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/array-handler.js +6 -1
- package/dist/resources/array-handler.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +13 -9
- package/dist/resources/card-type-resource.js +47 -23
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.d.ts +10 -9
- package/dist/resources/create-defaults.js +15 -12
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +0 -1
- package/dist/resources/field-type-resource.js +2 -10
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +7 -7
- package/dist/resources/file-resource.js +32 -7
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +10 -9
- package/dist/resources/folder-resource.js +10 -9
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +5 -6
- package/dist/resources/report-resource.js +16 -7
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/template-resource.d.ts +5 -6
- package/dist/resources/template-resource.js +7 -6
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +15 -8
- package/dist/resources/workflow-resource.js +124 -8
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/types/queries.d.ts +11 -10
- package/dist/types/queries.js +10 -9
- package/dist/types/queries.js.map +1 -1
- package/dist/utils/clingo-fact-builder.d.ts +1 -0
- package/dist/utils/clingo-fact-builder.js +8 -3
- package/dist/utils/clingo-fact-builder.js.map +1 -1
- package/dist/utils/clingo-facts.js +15 -11
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/constants.d.ts +18 -12
- package/dist/utils/constants.js +18 -11
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/log-utils.d.ts +15 -2
- package/dist/utils/log-utils.js +20 -37
- package/dist/utils/log-utils.js.map +1 -1
- package/dist/utils/report.d.ts +27 -0
- package/dist/utils/report.js +60 -0
- package/dist/utils/report.js.map +1 -0
- package/dist/utils/resource-utils.js +3 -0
- package/dist/utils/resource-utils.js.map +1 -1
- package/dist/utils/sanitize-svg.d.ts +3 -4
- package/dist/utils/sanitize-svg.js +4 -7
- package/dist/utils/sanitize-svg.js.map +1 -1
- package/dist/utils/validate.js +2 -1
- package/dist/utils/validate.js.map +1 -1
- package/package.json +9 -11
- package/src/card-metadata-updater.ts +7 -2
- package/src/command-handler.ts +23 -13
- package/src/command-manager.ts +54 -13
- package/src/commands/calculate.ts +90 -106
- package/src/commands/create.ts +18 -10
- package/src/commands/export.ts +3 -2
- package/src/commands/import.ts +30 -17
- package/src/commands/index.ts +0 -2
- package/src/commands/remove.ts +7 -12
- package/src/commands/show.ts +13 -5
- package/src/commands/validate.ts +14 -44
- package/src/containers/project/project-content-watcher.ts +65 -0
- package/src/containers/project/project-paths.ts +1 -1
- package/src/containers/project/resource-collector.ts +33 -14
- package/src/containers/project.ts +96 -19
- package/src/containers/template.ts +7 -2
- package/src/exceptions/index.ts +36 -0
- package/src/index.ts +2 -0
- package/src/interfaces/macros.ts +5 -1
- package/src/interfaces/project-interfaces.ts +8 -0
- package/src/interfaces/resource-interfaces.ts +15 -22
- package/src/macros/base-macro.ts +89 -25
- package/src/macros/graph/index.ts +22 -12
- package/src/macros/index.ts +61 -8
- package/src/macros/report/index.ts +42 -43
- package/src/module-manager.ts +383 -177
- package/src/project-settings.ts +9 -11
- package/src/resources/array-handler.ts +7 -2
- package/src/resources/card-type-resource.ts +61 -46
- package/src/resources/create-defaults.ts +15 -12
- package/src/resources/field-type-resource.ts +2 -17
- package/src/resources/file-resource.ts +46 -8
- package/src/resources/folder-resource.ts +11 -10
- package/src/resources/report-resource.ts +19 -7
- package/src/resources/template-resource.ts +7 -6
- package/src/resources/workflow-resource.ts +155 -8
- package/src/types/queries.ts +11 -10
- package/src/utils/clingo-fact-builder.ts +8 -3
- package/src/utils/clingo-facts.ts +18 -12
- package/src/utils/constants.ts +20 -12
- package/src/utils/log-utils.ts +24 -45
- package/src/utils/report.ts +86 -0
- package/src/utils/resource-utils.ts +4 -0
- package/src/utils/sanitize-svg.ts +4 -9
- package/src/utils/validate.ts +3 -2
- package/dist/commands/export-site.d.ts +0 -45
- package/dist/commands/export-site.js +0 -301
- package/dist/commands/export-site.js.map +0 -1
- package/src/commands/export-site.ts +0 -356
package/src/project-settings.ts
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
|
|
14
14
|
import { writeJsonFile as atomicWrite } from 'write-json-file';
|
|
15
15
|
|
|
16
|
+
import { resolve } from 'path';
|
|
17
|
+
|
|
16
18
|
import type {
|
|
17
19
|
ModuleSetting,
|
|
18
20
|
ProjectSettings,
|
|
@@ -55,18 +57,9 @@ export class ProjectConfiguration implements ProjectSettings {
|
|
|
55
57
|
|
|
56
58
|
// Sets configuration values from file.
|
|
57
59
|
private readSettings() {
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
settings = readJsonFileSync(this.settingPath) as ProjectConfiguration;
|
|
61
|
-
} catch {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Invalid path '${this.settingPath}' to configuration file`,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
60
|
+
const settings = readJsonFileSync(this.settingPath) as ProjectConfiguration;
|
|
66
61
|
if (!settings) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`Invalid path '${this.settingPath}' to configuration file`,
|
|
69
|
-
);
|
|
62
|
+
throw new Error(`File at '${this.settingPath}' is not a valid JSON file`);
|
|
70
63
|
}
|
|
71
64
|
|
|
72
65
|
const valid =
|
|
@@ -103,6 +96,11 @@ export class ProjectConfiguration implements ProjectSettings {
|
|
|
103
96
|
if (exists) {
|
|
104
97
|
throw new Error(`Module '${module.name}' already imported`);
|
|
105
98
|
}
|
|
99
|
+
// Ensure that module file location is absolute
|
|
100
|
+
if (module.location && module.location.startsWith('file:')) {
|
|
101
|
+
const filePath = module.location.substring(5, module.location.length);
|
|
102
|
+
module.location = `file:${resolve(filePath)}`;
|
|
103
|
+
}
|
|
106
104
|
this.modules.push(module);
|
|
107
105
|
return this.save();
|
|
108
106
|
}
|
|
@@ -83,15 +83,20 @@ export class ArrayHandler<T> {
|
|
|
83
83
|
if (targetIndex === -1) {
|
|
84
84
|
throw new Error(`Item '${JSON.stringify(target)}' not found`);
|
|
85
85
|
}
|
|
86
|
+
const actualTarget = array[targetIndex];
|
|
86
87
|
const parsedTo = this.tryParseJSON(to);
|
|
87
88
|
|
|
88
89
|
if (typeof to === 'string' && (to.startsWith('[') || to.startsWith('{'))) {
|
|
89
90
|
return parsedTo as T[];
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
|
|
93
|
-
deepCompare(item as object,
|
|
93
|
+
const updatedArray = array.map((item) =>
|
|
94
|
+
deepCompare(item as object, actualTarget as object) ? parsedTo : item,
|
|
94
95
|
);
|
|
96
|
+
if (deepCompare(updatedArray, array)) {
|
|
97
|
+
throw new Error('Cannot change value. Target was not found.');
|
|
98
|
+
}
|
|
99
|
+
return updatedArray;
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
private handleRank(operation: RankOperation<T>, array: T[]): T[] {
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
|
+
the Free Software Foundation. This program is distributed in the hope that it
|
|
8
|
+
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
9
|
+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
10
|
+
See the GNU Affero General Public License for more details.
|
|
11
|
+
You should have received a copy of the GNU Affero General Public
|
|
12
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
13
|
*/
|
|
14
|
+
|
|
12
15
|
import type {
|
|
13
16
|
CardType,
|
|
14
17
|
CustomField,
|
|
15
18
|
LinkType,
|
|
19
|
+
Workflow,
|
|
16
20
|
} from '../interfaces/resource-interfaces.js';
|
|
17
21
|
import { FieldTypeResource } from './field-type-resource.js';
|
|
18
22
|
import {
|
|
@@ -31,7 +35,6 @@ import {
|
|
|
31
35
|
sortCards,
|
|
32
36
|
} from './file-resource.js';
|
|
33
37
|
import { LinkTypeResource } from './link-type-resource.js';
|
|
34
|
-
import { Template } from '../containers/template.js';
|
|
35
38
|
import { Validate } from '../commands/index.js';
|
|
36
39
|
|
|
37
40
|
/**
|
|
@@ -56,49 +59,26 @@ export class CardTypeResource extends FileResource {
|
|
|
56
59
|
.map((card) => card.key);
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
//
|
|
60
|
-
private async
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
): Promise<Card[]> {
|
|
65
|
-
const cards = await cardSource;
|
|
66
|
-
return cards.filter((card) => card.metadata?.cardType === cardTypeName);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Collect both project cards ...
|
|
70
|
-
const projectCardsPromise = filteredCards(
|
|
71
|
-
this.project.cards(this.project.paths.cardRootFolder, cardContent),
|
|
72
|
-
this.content.name,
|
|
73
|
-
);
|
|
74
|
-
// ... and cards from each template that would be affected.
|
|
75
|
-
const templates = await this.project.templates(ResourcesFrom.localOnly);
|
|
76
|
-
const templateCardsPromises = templates.map((template) => {
|
|
77
|
-
const templateObject = new Template(this.project, template);
|
|
78
|
-
return filteredCards(
|
|
79
|
-
templateObject.cards('', cardContent),
|
|
80
|
-
this.content.name,
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
// Return all affected cards
|
|
84
|
-
const cards = (
|
|
85
|
-
await Promise.all([projectCardsPromise, ...templateCardsPromises])
|
|
86
|
-
).reduce((accumulator, value) => accumulator.concat(value), []);
|
|
87
|
-
return cards;
|
|
62
|
+
// Checks if field type exists in the project.
|
|
63
|
+
private async fieldTypeExists(field: Partial<CustomField>) {
|
|
64
|
+
return field && field.name
|
|
65
|
+
? this.project.resourceExists('fieldTypes', field.name)
|
|
66
|
+
: false;
|
|
88
67
|
}
|
|
89
68
|
|
|
90
69
|
// If custom fields change, cards need to be updated.
|
|
91
70
|
// Rename change changes key names in cards.
|
|
92
71
|
private async handleCustomFieldsChange<Type>(op: Operation<Type>) {
|
|
93
|
-
const cardContent = {
|
|
94
|
-
metadata: true,
|
|
95
|
-
content: true,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
72
|
if (op && op.name === 'rank') return;
|
|
99
73
|
|
|
100
74
|
// Collect both project cards and template cards.
|
|
101
|
-
const cards = await this.collectCards(
|
|
75
|
+
const cards = await this.collectCards(
|
|
76
|
+
{
|
|
77
|
+
metadata: true,
|
|
78
|
+
content: true,
|
|
79
|
+
},
|
|
80
|
+
this.content.name,
|
|
81
|
+
);
|
|
102
82
|
|
|
103
83
|
if (op && op.name === 'change') {
|
|
104
84
|
const from = (op as ChangeOperation<string>).target;
|
|
@@ -173,6 +153,11 @@ export class CardTypeResource extends FileResource {
|
|
|
173
153
|
}
|
|
174
154
|
}
|
|
175
155
|
|
|
156
|
+
// Checks if field type exists in this card type.
|
|
157
|
+
private async hasFieldType(field: Partial<CustomField>): Promise<boolean> {
|
|
158
|
+
return this.data.customFields.some((item) => item.name === field.name);
|
|
159
|
+
}
|
|
160
|
+
|
|
176
161
|
// Remove value from array.
|
|
177
162
|
// todo: make it as generic and move to utils
|
|
178
163
|
private removeValue(array: string[], value: string) {
|
|
@@ -303,6 +288,33 @@ export class CardTypeResource extends FileResource {
|
|
|
303
288
|
}
|
|
304
289
|
}
|
|
305
290
|
|
|
291
|
+
// Checks that field type exists in the project and is defined in this card type.
|
|
292
|
+
private async validateFieldType<Type>(
|
|
293
|
+
key: string,
|
|
294
|
+
op: Operation<Type>,
|
|
295
|
+
): Promise<void> {
|
|
296
|
+
const field =
|
|
297
|
+
typeof op.target === 'object'
|
|
298
|
+
? (op.target as CustomField)
|
|
299
|
+
: { name: op.target as string };
|
|
300
|
+
// Check that field type exists in the project.
|
|
301
|
+
const exists = await this.fieldTypeExists(field);
|
|
302
|
+
if (!exists) {
|
|
303
|
+
throw new Error(
|
|
304
|
+
`Field type '${field.name}' does not exist in the project`,
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
// Check that field type is defined in card type.
|
|
308
|
+
if (key === 'alwaysVisibleFields' || key === 'optionallyVisibleFields') {
|
|
309
|
+
const hasField = await this.hasFieldType(field);
|
|
310
|
+
if (!hasField) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
`Field type '${field.name}' is not defined in card type '${this.content.name}'`,
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
306
318
|
/**
|
|
307
319
|
* Creates a new card type object. Base class writes the object to disk automatically.
|
|
308
320
|
* @param workflowName Workflow name that this card type uses.
|
|
@@ -318,7 +330,7 @@ export class CardTypeResource extends FileResource {
|
|
|
318
330
|
resourceNameToString(resourceName(workflowName)),
|
|
319
331
|
await this.project.projectPrefixes(),
|
|
320
332
|
);
|
|
321
|
-
const workflow = await this.project.resource(workflowName);
|
|
333
|
+
const workflow = await this.project.resource<Workflow>(workflowName);
|
|
322
334
|
if (!workflow) {
|
|
323
335
|
throw new Error(
|
|
324
336
|
`Workflow '${workflowName}' does not exist in the project`,
|
|
@@ -378,12 +390,14 @@ export class CardTypeResource extends FileResource {
|
|
|
378
390
|
if (key === 'name') {
|
|
379
391
|
content.name = super.handleScalar(op) as string;
|
|
380
392
|
} else if (key === 'alwaysVisibleFields') {
|
|
393
|
+
await this.validateFieldType(key, op);
|
|
381
394
|
content.alwaysVisibleFields = super.handleArray(
|
|
382
395
|
op,
|
|
383
396
|
key,
|
|
384
397
|
content.alwaysVisibleFields as Type[],
|
|
385
398
|
) as string[];
|
|
386
399
|
} else if (key === 'optionallyVisibleFields') {
|
|
400
|
+
await this.validateFieldType(key, op);
|
|
387
401
|
content.optionallyVisibleFields = super.handleArray(
|
|
388
402
|
op,
|
|
389
403
|
key,
|
|
@@ -392,6 +406,7 @@ export class CardTypeResource extends FileResource {
|
|
|
392
406
|
} else if (key === 'workflow') {
|
|
393
407
|
content.workflow = super.handleScalar(op) as string;
|
|
394
408
|
} else if (key === 'customFields') {
|
|
409
|
+
await this.validateFieldType(key, op);
|
|
395
410
|
content.customFields = super.handleArray(
|
|
396
411
|
op,
|
|
397
412
|
key,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
6
|
+
the Free Software Foundation.
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
8
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
9
|
+
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
10
|
+
details. You should have received a copy of the GNU Affero General Public
|
|
11
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import type { Card } from '../interfaces/project-interfaces.js';
|
|
@@ -78,6 +79,7 @@ export abstract class DefaultContent {
|
|
|
78
79
|
static cardType(cardTypeName: string, workflowName: string): CardType {
|
|
79
80
|
return {
|
|
80
81
|
name: cardTypeName,
|
|
82
|
+
displayName: '',
|
|
81
83
|
workflow: workflowName,
|
|
82
84
|
customFields: [],
|
|
83
85
|
alwaysVisibleFields: [],
|
|
@@ -94,6 +96,7 @@ export abstract class DefaultContent {
|
|
|
94
96
|
static fieldType(fieldTypeName: string, dataType: DataType): FieldType {
|
|
95
97
|
const value = {
|
|
96
98
|
name: fieldTypeName,
|
|
99
|
+
displayName: '',
|
|
97
100
|
dataType: dataType,
|
|
98
101
|
} as FieldType;
|
|
99
102
|
if (dataType === 'enum') {
|
|
@@ -111,7 +114,6 @@ export abstract class DefaultContent {
|
|
|
111
114
|
return {
|
|
112
115
|
name: graphModelName,
|
|
113
116
|
displayName: '',
|
|
114
|
-
description: '',
|
|
115
117
|
};
|
|
116
118
|
}
|
|
117
119
|
|
|
@@ -124,7 +126,6 @@ export abstract class DefaultContent {
|
|
|
124
126
|
return {
|
|
125
127
|
name: graphViewName,
|
|
126
128
|
displayName: '',
|
|
127
|
-
description: '',
|
|
128
129
|
};
|
|
129
130
|
}
|
|
130
131
|
|
|
@@ -149,6 +150,7 @@ export abstract class DefaultContent {
|
|
|
149
150
|
static linkType(linkTypeName: string): LinkType {
|
|
150
151
|
return {
|
|
151
152
|
name: linkTypeName,
|
|
153
|
+
displayName: '',
|
|
152
154
|
outboundDisplayName: linkTypeName,
|
|
153
155
|
inboundDisplayName: linkTypeName,
|
|
154
156
|
sourceCardTypes: [],
|
|
@@ -166,7 +168,6 @@ export abstract class DefaultContent {
|
|
|
166
168
|
return {
|
|
167
169
|
name: reportName,
|
|
168
170
|
displayName: '',
|
|
169
|
-
description: '',
|
|
170
171
|
category: 'Uncategorised report',
|
|
171
172
|
};
|
|
172
173
|
}
|
|
@@ -178,6 +179,7 @@ export abstract class DefaultContent {
|
|
|
178
179
|
public static template(templateName: string): TemplateMetadata {
|
|
179
180
|
return {
|
|
180
181
|
name: templateName,
|
|
182
|
+
displayName: '',
|
|
181
183
|
};
|
|
182
184
|
}
|
|
183
185
|
|
|
@@ -189,6 +191,7 @@ export abstract class DefaultContent {
|
|
|
189
191
|
public static workflow(workflowName: string): Workflow {
|
|
190
192
|
return {
|
|
191
193
|
name: workflowName,
|
|
194
|
+
displayName: '',
|
|
192
195
|
states: [
|
|
193
196
|
{ name: 'Draft', category: WorkflowCategory.initial },
|
|
194
197
|
{ name: 'Approved', category: WorkflowCategory.closed },
|
|
@@ -71,21 +71,6 @@ export class FieldTypeResource extends FileResource {
|
|
|
71
71
|
.map((card) => card.key);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
// Collects affected cards.
|
|
75
|
-
private async collectCards(cardContent: object, cardTypeName: string) {
|
|
76
|
-
async function filteredCards(
|
|
77
|
-
cardSource: Promise<Card[]>,
|
|
78
|
-
cardTypeName: string,
|
|
79
|
-
): Promise<Card[]> {
|
|
80
|
-
const cards = await cardSource;
|
|
81
|
-
return cards.filter((card) => card.metadata?.cardType === cardTypeName);
|
|
82
|
-
}
|
|
83
|
-
return filteredCards(
|
|
84
|
-
this.project.cards(this.project.paths.cardRootFolder, cardContent),
|
|
85
|
-
cardTypeName,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
74
|
// Converts values.
|
|
90
75
|
// The allowed conversions are:
|
|
91
76
|
// - shortText/longText --> person, if valid email
|
|
@@ -477,8 +462,8 @@ export class FieldTypeResource extends FileResource {
|
|
|
477
462
|
key,
|
|
478
463
|
content.enumValues as Type[],
|
|
479
464
|
) as EnumDefinition[];
|
|
480
|
-
} else if (key === '
|
|
481
|
-
content.
|
|
465
|
+
} else if (key === 'description') {
|
|
466
|
+
content.description = super.handleScalar(op) as string;
|
|
482
467
|
} else {
|
|
483
468
|
throw new Error(`Unknown property '${key}' for FieldType`);
|
|
484
469
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
Cyberismo
|
|
3
3
|
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
-
|
|
5
4
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
5
|
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
|
-
the Free Software Foundation.
|
|
8
|
-
|
|
9
|
-
of MERCHANTABILITY or FITNESS
|
|
10
|
-
See the GNU Affero General Public License for more
|
|
11
|
-
You should have received a copy of the GNU Affero General Public
|
|
6
|
+
the Free Software Foundation.
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
8
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
9
|
+
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
10
|
+
details. You should have received a copy of the GNU Affero General Public
|
|
12
11
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
12
|
*/
|
|
14
13
|
|
|
@@ -19,6 +18,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
19
18
|
|
|
20
19
|
import type {
|
|
21
20
|
Card,
|
|
21
|
+
FetchCardDetails,
|
|
22
22
|
ResourceFolderType,
|
|
23
23
|
} from '../interfaces/project-interfaces.js';
|
|
24
24
|
import {
|
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
} from '../utils/resource-utils.js';
|
|
49
49
|
import type { Resource } from '../interfaces/project-interfaces.js';
|
|
50
50
|
import { sortCards } from '../utils/card-utils.js';
|
|
51
|
+
import { Template } from '../containers/template.js';
|
|
51
52
|
import { Validate } from '../commands/index.js';
|
|
52
53
|
|
|
53
54
|
export {
|
|
@@ -70,7 +71,10 @@ export {
|
|
|
70
71
|
*/
|
|
71
72
|
export class FileResource extends ResourceObject {
|
|
72
73
|
public fileName: string = '';
|
|
73
|
-
protected content: ResourceBaseMetadata = {
|
|
74
|
+
protected content: ResourceBaseMetadata = {
|
|
75
|
+
name: '',
|
|
76
|
+
displayName: '',
|
|
77
|
+
};
|
|
74
78
|
private cache: Map<string, JSON>;
|
|
75
79
|
|
|
76
80
|
constructor(
|
|
@@ -102,6 +106,37 @@ export class FileResource extends ResourceObject {
|
|
|
102
106
|
);
|
|
103
107
|
}
|
|
104
108
|
|
|
109
|
+
// Collects cards that are using the 'cardTypeName'.
|
|
110
|
+
protected async collectCards(
|
|
111
|
+
cardContent: FetchCardDetails,
|
|
112
|
+
cardTypeName: string,
|
|
113
|
+
) {
|
|
114
|
+
async function filteredCards(
|
|
115
|
+
cardSource: Promise<Card[]>,
|
|
116
|
+
cardTypeName: string,
|
|
117
|
+
): Promise<Card[]> {
|
|
118
|
+
const cards = await cardSource;
|
|
119
|
+
return cards.filter((card) => card.metadata?.cardType === cardTypeName);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Collect both project cards ...
|
|
123
|
+
const projectCardsPromise = filteredCards(
|
|
124
|
+
this.project.cards(this.project.paths.cardRootFolder, cardContent),
|
|
125
|
+
cardTypeName,
|
|
126
|
+
);
|
|
127
|
+
// ... and cards from each template that would be affected.
|
|
128
|
+
const templates = await this.project.templates(ResourcesFrom.localOnly);
|
|
129
|
+
const templateCardsPromises = templates.map((template) => {
|
|
130
|
+
const templateObject = new Template(this.project, template);
|
|
131
|
+
return filteredCards(templateObject.cards('', cardContent), cardTypeName);
|
|
132
|
+
});
|
|
133
|
+
// Return all affected cards
|
|
134
|
+
const cards = (
|
|
135
|
+
await Promise.all([projectCardsPromise, ...templateCardsPromises])
|
|
136
|
+
).reduce((accumulator, value) => accumulator.concat(value), []);
|
|
137
|
+
return cards;
|
|
138
|
+
}
|
|
139
|
+
|
|
105
140
|
// Initialize the resource.
|
|
106
141
|
protected initialize() {
|
|
107
142
|
if (this.resourceName.type === '') {
|
|
@@ -163,8 +198,11 @@ export class FileResource extends ResourceObject {
|
|
|
163
198
|
|
|
164
199
|
let validContent = {} as ResourceContent;
|
|
165
200
|
if (newContent) {
|
|
166
|
-
validContent = newContent
|
|
201
|
+
validContent = newContent;
|
|
167
202
|
validContent.name = validName;
|
|
203
|
+
} else {
|
|
204
|
+
validContent.description = '';
|
|
205
|
+
validContent.displayName = '';
|
|
168
206
|
}
|
|
169
207
|
|
|
170
208
|
this.content = validContent;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
6
|
+
the Free Software Foundation.
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
8
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
9
|
+
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
10
|
+
details. You should have received a copy of the GNU Affero General Public
|
|
11
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import { basename, join } from 'node:path';
|
|
@@ -94,7 +95,7 @@ export class FolderResource extends FileResource {
|
|
|
94
95
|
* @returns resource type's metadata.
|
|
95
96
|
*/
|
|
96
97
|
protected async show(): Promise<ResourceContent> {
|
|
97
|
-
return super.show()
|
|
98
|
+
return super.show();
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
Cyberismo
|
|
3
3
|
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
-
|
|
5
4
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
5
|
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
|
-
the Free Software Foundation.
|
|
8
|
-
|
|
9
|
-
of MERCHANTABILITY or FITNESS
|
|
10
|
-
See the GNU Affero General Public License for more
|
|
11
|
-
You should have received a copy of the GNU Affero General Public
|
|
6
|
+
the Free Software Foundation.
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
8
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
9
|
+
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
10
|
+
details. You should have received a copy of the GNU Affero General Public
|
|
12
11
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
12
|
*/
|
|
14
13
|
|
|
@@ -34,11 +33,13 @@ import type {
|
|
|
34
33
|
ReportMetadata,
|
|
35
34
|
} from '../interfaces/resource-interfaces.js';
|
|
36
35
|
import type { Schema } from 'jsonschema';
|
|
37
|
-
import { getStaticDirectoryPath } from '@cyberismo/
|
|
36
|
+
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
37
|
+
import { Validate } from '../commands/validate.js';
|
|
38
38
|
|
|
39
39
|
const CARD_CONTENT_HANDLEBAR_FILE = 'index.adoc.hbs';
|
|
40
40
|
const QUERY_HANDLEBAR_FILE = 'query.lp.hbs';
|
|
41
41
|
const REPORT_SCHEMA_FILE = 'parameterSchema.json';
|
|
42
|
+
const PARAMETER_SCHEMA_ID = 'jsonSchema';
|
|
42
43
|
|
|
43
44
|
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
44
45
|
|
|
@@ -153,6 +154,8 @@ export class ReportResource extends FolderResource {
|
|
|
153
154
|
const reportMetadata = (await super.show()) as ReportMetadata;
|
|
154
155
|
return {
|
|
155
156
|
name: resourceNameToString(this.resourceName),
|
|
157
|
+
displayName: reportMetadata.displayName,
|
|
158
|
+
description: reportMetadata.description,
|
|
156
159
|
metadata: reportMetadata,
|
|
157
160
|
contentTemplate: (
|
|
158
161
|
await readFile(join(this.internalFolder, CARD_CONTENT_HANDLEBAR_FILE))
|
|
@@ -219,6 +222,15 @@ export class ReportResource extends FolderResource {
|
|
|
219
222
|
* @note If content is not provided, base class validation will use resource's current content.
|
|
220
223
|
*/
|
|
221
224
|
public async validate(content?: object) {
|
|
225
|
+
if (this.reportSchema) {
|
|
226
|
+
const errors = Validate.getInstance().validateJson(
|
|
227
|
+
this.reportSchema,
|
|
228
|
+
PARAMETER_SCHEMA_ID,
|
|
229
|
+
);
|
|
230
|
+
if (errors.length > 0) {
|
|
231
|
+
throw new Error(`Invalid parameter schema: ${errors}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
222
234
|
return super.validate(content);
|
|
223
235
|
}
|
|
224
236
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
Cyberismo
|
|
3
3
|
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
-
|
|
5
4
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
5
|
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
|
-
the Free Software Foundation.
|
|
8
|
-
|
|
9
|
-
of MERCHANTABILITY or FITNESS
|
|
10
|
-
See the GNU Affero General Public License for more
|
|
11
|
-
You should have received a copy of the GNU Affero General Public
|
|
6
|
+
the Free Software Foundation.
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
8
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
9
|
+
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
10
|
+
details. You should have received a copy of the GNU Affero General Public
|
|
12
11
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
12
|
*/
|
|
14
13
|
|
|
@@ -120,6 +119,8 @@ export class TemplateResource extends FolderResource {
|
|
|
120
119
|
return {
|
|
121
120
|
metadata: templateMetadata,
|
|
122
121
|
name: resourceNameToString(this.resourceName),
|
|
122
|
+
displayName: templateMetadata.displayName,
|
|
123
|
+
description: templateMetadata.description,
|
|
123
124
|
path: this.fileName,
|
|
124
125
|
numberOfCards: (await container.listCards()).length,
|
|
125
126
|
};
|