@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
|
@@ -11,32 +11,30 @@
|
|
|
11
11
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { dirname, join } from 'node:path';
|
|
15
15
|
import { mkdir } from 'node:fs/promises';
|
|
16
16
|
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from '
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} from './folder-resource.js';
|
|
17
|
+
import { DefaultContent } from './create-defaults.js';
|
|
18
|
+
import { FolderResource } from './folder-resource.js';
|
|
19
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
20
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
21
|
+
import { Template } from '../containers/template.js';
|
|
22
|
+
import { writeJsonFile } from '../utils/json.js';
|
|
23
|
+
|
|
24
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
25
|
+
import type { Operation } from './resource-object.js';
|
|
26
|
+
import type { Project } from '../containers/project.js';
|
|
27
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
29
28
|
import type {
|
|
30
29
|
TemplateConfiguration,
|
|
31
30
|
TemplateMetadata,
|
|
31
|
+
UpdateKey,
|
|
32
32
|
} from '../interfaces/resource-interfaces.js';
|
|
33
|
-
import { Template } from '../containers/template.js';
|
|
34
|
-
import { writeJsonFile } from '../utils/json.js';
|
|
35
33
|
|
|
36
34
|
/**
|
|
37
35
|
* Template resource class.
|
|
38
36
|
*/
|
|
39
|
-
export class TemplateResource extends FolderResource {
|
|
37
|
+
export class TemplateResource extends FolderResource<TemplateMetadata, never> {
|
|
40
38
|
private cardContainer: Template;
|
|
41
39
|
private cardsFolder = '';
|
|
42
40
|
private cardsSchema = super.contentSchemaContent('cardBaseSchema');
|
|
@@ -47,12 +45,12 @@ export class TemplateResource extends FolderResource {
|
|
|
47
45
|
this.contentSchemaId = 'templateSchema';
|
|
48
46
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
49
47
|
|
|
50
|
-
this.initialize();
|
|
51
48
|
this.cardsFolder = join(this.internalFolder, 'c');
|
|
52
49
|
|
|
53
50
|
// Each template resource contains a template card container (with template cards).
|
|
51
|
+
// todo: Fix Template constructor not to use Resource, but just this filename with path
|
|
54
52
|
this.cardContainer = new Template(this.project, {
|
|
55
|
-
name:
|
|
53
|
+
name: resourceNameToString(this.resourceName),
|
|
56
54
|
path: dirname(this.fileName),
|
|
57
55
|
});
|
|
58
56
|
}
|
|
@@ -86,17 +84,13 @@ export class TemplateResource extends FolderResource {
|
|
|
86
84
|
return super.create(newContent);
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
/**
|
|
90
|
-
* Returns content data.
|
|
91
|
-
*/
|
|
92
|
-
public get data(): TemplateMetadata {
|
|
93
|
-
return super.data as TemplateMetadata;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
87
|
/**
|
|
97
88
|
* Deletes file and folder that this resource is based on.
|
|
89
|
+
* Also removes template cards from the project's card cache.
|
|
98
90
|
*/
|
|
99
91
|
public async delete() {
|
|
92
|
+
const templateName = resourceNameToString(this.resourceName);
|
|
93
|
+
this.project.cardsCache.deleteCardsFromTemplate(templateName);
|
|
100
94
|
return super.delete();
|
|
101
95
|
}
|
|
102
96
|
|
|
@@ -114,8 +108,8 @@ export class TemplateResource extends FolderResource {
|
|
|
114
108
|
* Shows metadata of the resource.
|
|
115
109
|
* @returns template metadata.
|
|
116
110
|
*/
|
|
117
|
-
public
|
|
118
|
-
const templateMetadata =
|
|
111
|
+
public show(): TemplateConfiguration {
|
|
112
|
+
const templateMetadata = super.show();
|
|
119
113
|
const container = this.templateObject();
|
|
120
114
|
|
|
121
115
|
return {
|
|
@@ -124,7 +118,7 @@ export class TemplateResource extends FolderResource {
|
|
|
124
118
|
displayName: templateMetadata.displayName,
|
|
125
119
|
description: templateMetadata.description,
|
|
126
120
|
path: this.fileName,
|
|
127
|
-
numberOfCards:
|
|
121
|
+
numberOfCards: container.listCards().length,
|
|
128
122
|
};
|
|
129
123
|
}
|
|
130
124
|
|
|
@@ -138,20 +132,24 @@ export class TemplateResource extends FolderResource {
|
|
|
138
132
|
|
|
139
133
|
/**
|
|
140
134
|
* Updates template resource.
|
|
141
|
-
* @param
|
|
135
|
+
* @param updateKey Key to modify
|
|
142
136
|
* @param op Operation to perform on 'key'
|
|
143
137
|
* @throws if key is unknown.
|
|
144
138
|
*/
|
|
145
|
-
public async update<Type
|
|
139
|
+
public async update<Type, K extends string>(
|
|
140
|
+
updateKey: UpdateKey<K>,
|
|
141
|
+
op: Operation<Type>,
|
|
142
|
+
) {
|
|
143
|
+
const { key } = updateKey;
|
|
146
144
|
const nameChange = key === 'name';
|
|
147
145
|
const existingName = this.content.name;
|
|
148
146
|
|
|
149
147
|
// Only call super.update for keys that base class supports
|
|
150
148
|
if (key === 'name' || key === 'displayName' || key === 'description') {
|
|
151
|
-
await super.update(
|
|
149
|
+
await super.update(updateKey, op);
|
|
152
150
|
}
|
|
153
151
|
|
|
154
|
-
const content = structuredClone(this.content)
|
|
152
|
+
const content = structuredClone(this.content);
|
|
155
153
|
|
|
156
154
|
if (key === 'name') {
|
|
157
155
|
content.name = super.handleScalar(op) as string;
|
|
@@ -165,7 +163,7 @@ export class TemplateResource extends FolderResource {
|
|
|
165
163
|
throw new Error(`Unknown property '${key}' for Template`);
|
|
166
164
|
}
|
|
167
165
|
|
|
168
|
-
await super.postUpdate(content,
|
|
166
|
+
await super.postUpdate(content, updateKey, op);
|
|
169
167
|
|
|
170
168
|
// Renaming this template causes that references to its name must be updated.
|
|
171
169
|
if (nameChange) {
|
|
@@ -181,7 +179,7 @@ export class TemplateResource extends FolderResource {
|
|
|
181
179
|
* @returns array of card keys, and calculation filenames that refer this resource.
|
|
182
180
|
*/
|
|
183
181
|
public async usage(cards?: Card[]): Promise<string[]> {
|
|
184
|
-
const allCards = cards ??
|
|
182
|
+
const allCards = cards ?? super.cards();
|
|
185
183
|
const [relevantCards, calculations] = await Promise.all([
|
|
186
184
|
super.usage(allCards),
|
|
187
185
|
super.calculations(),
|
|
@@ -189,16 +187,6 @@ export class TemplateResource extends FolderResource {
|
|
|
189
187
|
return [...relevantCards.sort(sortCards), ...calculations];
|
|
190
188
|
}
|
|
191
189
|
|
|
192
|
-
/**
|
|
193
|
-
* Validates template.
|
|
194
|
-
* @throws when there are validation errors.
|
|
195
|
-
* @param content Content to be validated.
|
|
196
|
-
* @note If content is not provided, base class validation will use resource's current content.
|
|
197
|
-
*/
|
|
198
|
-
public async validate(content?: object) {
|
|
199
|
-
return super.validate(content);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
190
|
/**
|
|
203
191
|
* Create the template's cards folder.
|
|
204
192
|
*/
|
|
@@ -13,58 +13,43 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import type {
|
|
16
|
-
|
|
16
|
+
UpdateKey,
|
|
17
17
|
Workflow,
|
|
18
18
|
WorkflowState,
|
|
19
19
|
WorkflowTransition,
|
|
20
20
|
} from '../interfaces/resource-interfaces.js';
|
|
21
|
-
import {
|
|
21
|
+
import { DefaultContent } from './create-defaults.js';
|
|
22
|
+
import { FileResource } from './file-resource.js';
|
|
23
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
24
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
25
|
+
|
|
26
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
22
27
|
import type {
|
|
23
|
-
Card,
|
|
24
28
|
ChangeOperation,
|
|
25
29
|
Operation,
|
|
26
|
-
Project,
|
|
27
30
|
RemoveOperation,
|
|
28
|
-
|
|
29
|
-
} from '
|
|
30
|
-
import {
|
|
31
|
-
DefaultContent,
|
|
32
|
-
FileResource,
|
|
33
|
-
resourceNameToString,
|
|
34
|
-
sortCards,
|
|
35
|
-
} from './folder-resource.js';
|
|
36
|
-
import { ResourcesFrom } from '../containers/project.js';
|
|
37
|
-
import { resourceName } from './file-resource.js';
|
|
31
|
+
} from './resource-object.js';
|
|
32
|
+
import type { Project } from '../containers/project.js';
|
|
33
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
38
34
|
|
|
39
35
|
/**
|
|
40
36
|
* Workflow resource class.
|
|
41
37
|
*/
|
|
42
|
-
export class WorkflowResource extends FileResource {
|
|
38
|
+
export class WorkflowResource extends FileResource<Workflow> {
|
|
43
39
|
constructor(project: Project, name: ResourceName) {
|
|
44
40
|
super(project, name, 'workflows');
|
|
45
41
|
|
|
46
42
|
this.contentSchemaId = 'workflowSchema';
|
|
47
43
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
48
|
-
|
|
49
|
-
this.initialize();
|
|
50
44
|
}
|
|
51
45
|
|
|
52
46
|
// Collect all cards that use this workflow.
|
|
53
47
|
private async collectCardsUsingWorkflow(): Promise<Card[]> {
|
|
54
|
-
const cardTypes =
|
|
48
|
+
const cardTypes = this.project.resources.cardTypes();
|
|
55
49
|
const promises: Promise<Card[]>[] = [];
|
|
56
50
|
for (const cardType of cardTypes) {
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
resourceName(cardType.name),
|
|
60
|
-
);
|
|
61
|
-
if (
|
|
62
|
-
object.data &&
|
|
63
|
-
(object.data as CardType).workflow ===
|
|
64
|
-
resourceNameToString(this.resourceName)
|
|
65
|
-
) {
|
|
66
|
-
// fetch all cards with card type
|
|
67
|
-
promises.push(this.collectCards({ metadata: true }, cardType.name));
|
|
51
|
+
if (cardType.data?.workflow === resourceNameToString(this.resourceName)) {
|
|
52
|
+
promises.push(this.collectCards(cardType.data.name));
|
|
68
53
|
}
|
|
69
54
|
}
|
|
70
55
|
return (await Promise.all(promises)).flat();
|
|
@@ -82,7 +67,7 @@ export class WorkflowResource extends FileResource {
|
|
|
82
67
|
|
|
83
68
|
// Handle change of workflow state.
|
|
84
69
|
private async handleStateChange(op: ChangeOperation<WorkflowState>) {
|
|
85
|
-
const content = structuredClone(this.content)
|
|
70
|
+
const content = structuredClone(this.content);
|
|
86
71
|
const stateName = this.targetName(op) as string;
|
|
87
72
|
// Check that state can be changed to
|
|
88
73
|
content.transitions = content.transitions.filter(
|
|
@@ -107,7 +92,7 @@ export class WorkflowResource extends FileResource {
|
|
|
107
92
|
// Handle removal of workflow state.
|
|
108
93
|
// State can be removed with or without replacement.
|
|
109
94
|
private async handleStateRemoval(op: RemoveOperation<WorkflowState>) {
|
|
110
|
-
const content = structuredClone(this.content)
|
|
95
|
+
const content = structuredClone(this.content);
|
|
111
96
|
const stateName = this.targetName(op) as string;
|
|
112
97
|
|
|
113
98
|
// If there is no replacement value, remove all transitions "to" and "from" this state.
|
|
@@ -153,8 +138,8 @@ export class WorkflowResource extends FileResource {
|
|
|
153
138
|
}
|
|
154
139
|
|
|
155
140
|
// Potentially updates the changed transition with current properties.
|
|
156
|
-
private
|
|
157
|
-
const content = structuredClone(this.content)
|
|
141
|
+
private transitionObject(op: ChangeOperation<WorkflowTransition>) {
|
|
142
|
+
const content = structuredClone(this.content);
|
|
158
143
|
const targetTransitionName = this.targetName(op);
|
|
159
144
|
const currentTransition = content.transitions.filter(
|
|
160
145
|
(item) => item.name === targetTransitionName,
|
|
@@ -201,20 +186,19 @@ export class WorkflowResource extends FileResource {
|
|
|
201
186
|
|
|
202
187
|
// Update dependant card types.
|
|
203
188
|
private async updateCardTypes(oldName: string) {
|
|
204
|
-
const cardTypes =
|
|
189
|
+
const cardTypes = this.project.resources.cardTypes();
|
|
205
190
|
const op = {
|
|
206
191
|
name: 'change',
|
|
207
192
|
target: oldName,
|
|
208
193
|
to: this.content.name,
|
|
209
194
|
} as ChangeOperation<string>;
|
|
210
195
|
for (const cardType of cardTypes) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
196
|
+
await cardType.update(
|
|
197
|
+
{
|
|
198
|
+
key: 'workflow',
|
|
199
|
+
},
|
|
200
|
+
op,
|
|
214
201
|
);
|
|
215
|
-
if (object.data && (object.data as CardType).workflow === oldName) {
|
|
216
|
-
await object.update('workflow', op);
|
|
217
|
-
}
|
|
218
202
|
}
|
|
219
203
|
}
|
|
220
204
|
|
|
@@ -234,21 +218,6 @@ export class WorkflowResource extends FileResource {
|
|
|
234
218
|
return super.create(newContent);
|
|
235
219
|
}
|
|
236
220
|
|
|
237
|
-
/**
|
|
238
|
-
* Returns content data.
|
|
239
|
-
*/
|
|
240
|
-
public get data(): Workflow {
|
|
241
|
-
return super.data as Workflow;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Deletes file that this object is based on.
|
|
246
|
-
* If there are card types that depended on this workflow, they are now invalid.
|
|
247
|
-
*/
|
|
248
|
-
public async delete() {
|
|
249
|
-
return super.delete();
|
|
250
|
-
}
|
|
251
|
-
|
|
252
221
|
/**
|
|
253
222
|
* Renames the object and the file.
|
|
254
223
|
* @param newName New name for the resource.
|
|
@@ -259,25 +228,21 @@ export class WorkflowResource extends FileResource {
|
|
|
259
228
|
return this.handleNameChange(existingName);
|
|
260
229
|
}
|
|
261
230
|
|
|
262
|
-
/**
|
|
263
|
-
* Shows metadata of the resource.
|
|
264
|
-
* @returns workflow metadata.
|
|
265
|
-
*/
|
|
266
|
-
public async show(): Promise<Workflow> {
|
|
267
|
-
return super.show() as Promise<Workflow>;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
231
|
/**
|
|
271
232
|
* Updates workflow resource.
|
|
272
|
-
* @param
|
|
233
|
+
* @param updateKey Key to modify
|
|
273
234
|
* @param op Operation to perform on 'key'
|
|
274
235
|
* @throws if key is unknown.
|
|
275
236
|
*/
|
|
276
|
-
public async update<Type
|
|
237
|
+
public async update<Type, K extends string>(
|
|
238
|
+
updateKey: UpdateKey<K>,
|
|
239
|
+
op: Operation<Type>,
|
|
240
|
+
) {
|
|
241
|
+
const { key } = updateKey;
|
|
277
242
|
const nameChange = key === 'name';
|
|
278
243
|
const existingName = this.content.name;
|
|
279
244
|
|
|
280
|
-
await super.update(
|
|
245
|
+
await super.update(updateKey, op);
|
|
281
246
|
|
|
282
247
|
const content = structuredClone(this.content) as Workflow;
|
|
283
248
|
|
|
@@ -334,7 +299,7 @@ export class WorkflowResource extends FileResource {
|
|
|
334
299
|
// If workflow state is removed, remove all transitions "to" and "from" this state.
|
|
335
300
|
let removeOp: RemoveOperation<WorkflowState>;
|
|
336
301
|
if (this.isStringOperation(op)) {
|
|
337
|
-
const toBeRemovedState =
|
|
302
|
+
const toBeRemovedState = this.content.states.find(
|
|
338
303
|
(state) => state.name === op.target,
|
|
339
304
|
);
|
|
340
305
|
removeOp = {
|
|
@@ -349,7 +314,7 @@ export class WorkflowResource extends FileResource {
|
|
|
349
314
|
// If workflow state is renamed, replace all transitions "to" and "from" the old state with new state.
|
|
350
315
|
let changeOp: ChangeOperation<WorkflowState>;
|
|
351
316
|
if (this.isStringOperation(op)) {
|
|
352
|
-
const toBeChangedState =
|
|
317
|
+
const toBeChangedState = this.content.states.find(
|
|
353
318
|
(state) => state.name === op.target,
|
|
354
319
|
);
|
|
355
320
|
changeOp = {
|
|
@@ -363,7 +328,7 @@ export class WorkflowResource extends FileResource {
|
|
|
363
328
|
await this.handleStateChange(changeOp);
|
|
364
329
|
}
|
|
365
330
|
|
|
366
|
-
await super.postUpdate(content,
|
|
331
|
+
await super.postUpdate(content, updateKey, op);
|
|
367
332
|
|
|
368
333
|
// Renaming this workflow causes that references to its name must be updated.
|
|
369
334
|
if (nameChange) {
|
|
@@ -381,14 +346,14 @@ export class WorkflowResource extends FileResource {
|
|
|
381
346
|
*/
|
|
382
347
|
public async usage(cards?: Card[]): Promise<string[]> {
|
|
383
348
|
const resourceName = resourceNameToString(this.resourceName);
|
|
384
|
-
const allCards = cards ??
|
|
385
|
-
const cardTypes =
|
|
386
|
-
const cardTypeReferences =
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
349
|
+
const allCards = cards ?? super.cards();
|
|
350
|
+
const cardTypes = this.project.resources.cardTypes();
|
|
351
|
+
const cardTypeReferences = [];
|
|
352
|
+
for (const cardType of cardTypes) {
|
|
353
|
+
if (cardType.data?.workflow === resourceName) {
|
|
354
|
+
cardTypeReferences.push(cardType.data.name);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
392
357
|
|
|
393
358
|
const [relevantCards, calculations] = await Promise.all([
|
|
394
359
|
super.usage(allCards),
|
|
@@ -401,12 +366,4 @@ export class WorkflowResource extends FileResource {
|
|
|
401
366
|
...calculations,
|
|
402
367
|
];
|
|
403
368
|
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Validates workflow.
|
|
407
|
-
* @throws when there are validation errors.
|
|
408
|
-
*/
|
|
409
|
-
public validate(content?: object): Promise<void> {
|
|
410
|
-
return super.validate(content);
|
|
411
|
-
}
|
|
412
369
|
}
|