@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,11 +11,14 @@
|
|
|
11
11
|
You should have received a copy of the GNU Affero General Public
|
|
12
12
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
13
|
*/
|
|
14
|
-
import { readdir } from 'node:fs/promises';
|
|
15
14
|
import { extname, join } from 'node:path';
|
|
16
|
-
import {
|
|
17
|
-
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
15
|
+
import { readdir } from 'node:fs/promises';
|
|
18
16
|
import { copyDir } from '../utils/file-utils.js';
|
|
17
|
+
import { DefaultContent } from './create-defaults.js';
|
|
18
|
+
import { FolderResource } from './folder-resource.js';
|
|
19
|
+
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
20
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
21
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
19
22
|
/**
|
|
20
23
|
* Graph view resource class.
|
|
21
24
|
*/
|
|
@@ -24,7 +27,6 @@ export class GraphViewResource extends FolderResource {
|
|
|
24
27
|
super(project, name, 'graphViews');
|
|
25
28
|
this.contentSchemaId = 'graphViewSchema';
|
|
26
29
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
27
|
-
this.initialize();
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Handle name changes for graph views
|
|
@@ -53,18 +55,7 @@ export class GraphViewResource extends FolderResource {
|
|
|
53
55
|
}
|
|
54
56
|
await super.create(newContent);
|
|
55
57
|
await copyDir(join(await getStaticDirectoryPath(), 'defaultGraphView'), this.internalFolder);
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns resource content.
|
|
59
|
-
*/
|
|
60
|
-
get data() {
|
|
61
|
-
return super.data;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Deletes file and folder that this resource is based on.
|
|
65
|
-
*/
|
|
66
|
-
async delete() {
|
|
67
|
-
return super.delete();
|
|
58
|
+
await this.loadContentFiles();
|
|
68
59
|
}
|
|
69
60
|
/**
|
|
70
61
|
* Returns handlebar filename that this graph view has.
|
|
@@ -88,30 +79,19 @@ export class GraphViewResource extends FolderResource {
|
|
|
88
79
|
await super.rename(newName);
|
|
89
80
|
return this.onNameChange(existingName);
|
|
90
81
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Shows metadata of the resource.
|
|
93
|
-
* @returns graph view metadata.
|
|
94
|
-
*/
|
|
95
|
-
async show() {
|
|
96
|
-
const baseData = (await super.show());
|
|
97
|
-
return {
|
|
98
|
-
...baseData,
|
|
99
|
-
content: (await super.contentData()),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
82
|
/**
|
|
103
83
|
* Updates graph view resource.
|
|
104
|
-
* @param
|
|
84
|
+
* @param updateKey Key to modify
|
|
105
85
|
* @param op Operation to perform on 'key'
|
|
106
86
|
*/
|
|
107
|
-
async update(
|
|
108
|
-
if (key === 'category') {
|
|
87
|
+
async update(updateKey, op) {
|
|
88
|
+
if (updateKey.key === 'category') {
|
|
109
89
|
const content = structuredClone(this.content);
|
|
110
90
|
content.category = super.handleScalar(op);
|
|
111
|
-
await super.postUpdate(content,
|
|
91
|
+
await super.postUpdate(content, updateKey, op);
|
|
112
92
|
return;
|
|
113
93
|
}
|
|
114
|
-
await super.update(
|
|
94
|
+
await super.update(updateKey, op);
|
|
115
95
|
}
|
|
116
96
|
/**
|
|
117
97
|
* List where this resource is used.
|
|
@@ -121,27 +101,12 @@ export class GraphViewResource extends FolderResource {
|
|
|
121
101
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
122
102
|
*/
|
|
123
103
|
async usage(cards) {
|
|
124
|
-
const allCards = cards ??
|
|
104
|
+
const allCards = cards ?? super.cards();
|
|
125
105
|
const [relevantCards, calculations] = await Promise.all([
|
|
126
106
|
super.usage(allCards),
|
|
127
107
|
super.calculations(),
|
|
128
108
|
]);
|
|
129
109
|
return [...relevantCards.sort(sortCards), ...calculations];
|
|
130
110
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Validates graph view.
|
|
133
|
-
* @throws when there are validation errors.
|
|
134
|
-
* @param content Content to be validated.
|
|
135
|
-
* @note If content is not provided, base class validation will use resource's current content.
|
|
136
|
-
*/
|
|
137
|
-
async validate(content) {
|
|
138
|
-
return super.validate(content);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Create the graph view's folder and handlebar file.
|
|
142
|
-
*/
|
|
143
|
-
async write() {
|
|
144
|
-
await super.write();
|
|
145
|
-
}
|
|
146
111
|
}
|
|
147
112
|
//# sourceMappingURL=graph-view-resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-view-resource.js","sourceRoot":"","sources":["../../src/resources/graph-view-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"graph-view-resource.js","sourceRoot":"","sources":["../../src/resources/graph-view-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,S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M,QAAQ,GAAG,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QACxC,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACtD,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC;YACrB,KAAK,CAAC,YAAY,EAAE;SACrB,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC;IAC7D,CAAC;CACF"}
|
|
@@ -9,13 +9,16 @@
|
|
|
9
9
|
You should have received a copy of the GNU Affero General Public
|
|
10
10
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
11
|
*/
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import type { LinkType } from '../interfaces/resource-interfaces.js';
|
|
12
|
+
import { FileResource } from './file-resource.js';
|
|
13
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
14
|
+
import type { LinkType, UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
15
|
+
import type { Operation } from './resource-object.js';
|
|
16
|
+
import type { Project } from '../containers/project.js';
|
|
17
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
15
18
|
/**
|
|
16
19
|
* Link Type resource class.
|
|
17
20
|
*/
|
|
18
|
-
export declare class LinkTypeResource extends FileResource {
|
|
21
|
+
export declare class LinkTypeResource extends FileResource<LinkType> {
|
|
19
22
|
constructor(project: Project, name: ResourceName);
|
|
20
23
|
private handleNameChange;
|
|
21
24
|
/**
|
|
@@ -23,30 +26,17 @@ export declare class LinkTypeResource extends FileResource {
|
|
|
23
26
|
* @param newContent Content for the link type.
|
|
24
27
|
*/
|
|
25
28
|
create(newContent?: LinkType): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Returns content data.
|
|
28
|
-
*/
|
|
29
|
-
get data(): LinkType;
|
|
30
|
-
/**
|
|
31
|
-
* Deletes file(s) from disk and clears out the memory resident object.
|
|
32
|
-
*/
|
|
33
|
-
delete(): Promise<void>;
|
|
34
29
|
/**
|
|
35
30
|
* Renames resource metadata file and renames memory resident object 'name'.
|
|
36
31
|
* @param newName New name for the resource.
|
|
37
32
|
*/
|
|
38
33
|
rename(newName: ResourceName): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Shows metadata of the resource.
|
|
41
|
-
* @returns link type metadata.
|
|
42
|
-
*/
|
|
43
|
-
show(): Promise<LinkType>;
|
|
44
34
|
/**
|
|
45
35
|
* Updates link type resource.
|
|
46
|
-
* @param
|
|
36
|
+
* @param updateKey Key to modify
|
|
47
37
|
* @param op Operation to perform on 'key'
|
|
48
38
|
*/
|
|
49
|
-
update<Type>(
|
|
39
|
+
update<Type, K extends string>(updateKey: UpdateKey<K>, op: Operation<Type>): Promise<void>;
|
|
50
40
|
/**
|
|
51
41
|
* List where link type is used.
|
|
52
42
|
* Always returns card key references first, then calculation references.
|
|
@@ -55,8 +45,4 @@ export declare class LinkTypeResource extends FileResource {
|
|
|
55
45
|
* @returns array of card keys calculation filenames that refer this resource.
|
|
56
46
|
*/
|
|
57
47
|
usage(cards?: Card[]): Promise<string[]>;
|
|
58
|
-
/**
|
|
59
|
-
* Validates the resource. If object is invalid, throws.
|
|
60
|
-
*/
|
|
61
|
-
validate(content?: object): Promise<void>;
|
|
62
48
|
}
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
You should have received a copy of the GNU Affero General Public
|
|
10
10
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
11
|
*/
|
|
12
|
-
import { DefaultContent
|
|
12
|
+
import { DefaultContent } from './create-defaults.js';
|
|
13
|
+
import { FileResource } from './file-resource.js';
|
|
14
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
15
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
13
16
|
/**
|
|
14
17
|
* Link Type resource class.
|
|
15
18
|
*/
|
|
@@ -18,12 +21,11 @@ export class LinkTypeResource extends FileResource {
|
|
|
18
21
|
super(project, name, 'linkTypes');
|
|
19
22
|
this.contentSchemaId = 'linkTypeSchema';
|
|
20
23
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
21
|
-
this.initialize();
|
|
22
24
|
}
|
|
23
25
|
// When resource name changes.
|
|
24
26
|
async handleNameChange(existingName) {
|
|
25
27
|
const current = this.content;
|
|
26
|
-
const prefixes =
|
|
28
|
+
const prefixes = this.project.projectPrefixes();
|
|
27
29
|
if (current.sourceCardTypes) {
|
|
28
30
|
current.sourceCardTypes = current.sourceCardTypes.map((item) => this.updatePrefixInResourceName(item, prefixes));
|
|
29
31
|
}
|
|
@@ -50,18 +52,6 @@ export class LinkTypeResource extends FileResource {
|
|
|
50
52
|
}
|
|
51
53
|
return super.create(newContent);
|
|
52
54
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Returns content data.
|
|
55
|
-
*/
|
|
56
|
-
get data() {
|
|
57
|
-
return super.data;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Deletes file(s) from disk and clears out the memory resident object.
|
|
61
|
-
*/
|
|
62
|
-
async delete() {
|
|
63
|
-
return super.delete();
|
|
64
|
-
}
|
|
65
55
|
/**
|
|
66
56
|
* Renames resource metadata file and renames memory resident object 'name'.
|
|
67
57
|
* @param newName New name for the resource.
|
|
@@ -71,22 +61,16 @@ export class LinkTypeResource extends FileResource {
|
|
|
71
61
|
await super.rename(newName);
|
|
72
62
|
return this.handleNameChange(existingName);
|
|
73
63
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Shows metadata of the resource.
|
|
76
|
-
* @returns link type metadata.
|
|
77
|
-
*/
|
|
78
|
-
async show() {
|
|
79
|
-
return super.show();
|
|
80
|
-
}
|
|
81
64
|
/**
|
|
82
65
|
* Updates link type resource.
|
|
83
|
-
* @param
|
|
66
|
+
* @param updateKey Key to modify
|
|
84
67
|
* @param op Operation to perform on 'key'
|
|
85
68
|
*/
|
|
86
|
-
async update(
|
|
69
|
+
async update(updateKey, op) {
|
|
70
|
+
const { key } = updateKey;
|
|
87
71
|
const nameChange = key === 'name';
|
|
88
72
|
const existingName = this.content.name;
|
|
89
|
-
await super.update(
|
|
73
|
+
await super.update(updateKey, op);
|
|
90
74
|
const content = structuredClone(this.content);
|
|
91
75
|
if (key === 'name') {
|
|
92
76
|
content.name = super.handleScalar(op);
|
|
@@ -109,7 +93,7 @@ export class LinkTypeResource extends FileResource {
|
|
|
109
93
|
else {
|
|
110
94
|
throw new Error(`Unknown property '${key}' for FieldType`);
|
|
111
95
|
}
|
|
112
|
-
await super.postUpdate(content,
|
|
96
|
+
await super.postUpdate(content, updateKey, op);
|
|
113
97
|
// Renaming this card type causes that references to its name must be updated.
|
|
114
98
|
if (nameChange) {
|
|
115
99
|
await this.handleNameChange(existingName);
|
|
@@ -124,7 +108,7 @@ export class LinkTypeResource extends FileResource {
|
|
|
124
108
|
*/
|
|
125
109
|
async usage(cards) {
|
|
126
110
|
const resourceName = resourceNameToString(this.resourceName);
|
|
127
|
-
const allCards = cards ||
|
|
111
|
+
const allCards = cards || super.cards();
|
|
128
112
|
const cardsThatUseLinkType = allCards
|
|
129
113
|
.filter((card) => card.metadata?.links.find((item) => item.linkType === resourceName))
|
|
130
114
|
.filter(Boolean)
|
|
@@ -140,11 +124,5 @@ export class LinkTypeResource extends FileResource {
|
|
|
140
124
|
// Using Set to avoid duplicate cards
|
|
141
125
|
return [...new Set([...cardReferences, ...calculations])];
|
|
142
126
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Validates the resource. If object is invalid, throws.
|
|
145
|
-
*/
|
|
146
|
-
async validate(content) {
|
|
147
|
-
return super.validate(content);
|
|
148
|
-
}
|
|
149
127
|
}
|
|
150
128
|
//# sourceMappingURL=link-type-resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-type-resource.js","sourceRoot":"","sources":["../../src/resources/link-type-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;
|
|
1
|
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AQ,GAAG,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAExC,MAAM,oBAAoB,GAAG,QAAQ;aAClC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CACf,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,YAAY,CAAC,CACpE;aACA,MAAM,CAAC,OAAO,CAAC;aACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE3B,MAAM,CAAC,qBAAqB,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC9D,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC;YACrB,KAAK,CAAC,YAAY,EAAE;SACrB,CAAC,CAAC;QAEH,MAAM,cAAc,GAAG;YACrB,GAAG,oBAAoB;YACvB,GAAG,qBAAqB;SACzB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAElB,qCAAqC;QACrC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,cAAc,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF"}
|
|
@@ -12,16 +12,18 @@
|
|
|
12
12
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
13
|
*/
|
|
14
14
|
import { FolderResource } from './folder-resource.js';
|
|
15
|
-
import type { Card
|
|
16
|
-
import type {
|
|
15
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
16
|
+
import type { Operation } from './resource-object.js';
|
|
17
|
+
import type { Project } from '../containers/project.js';
|
|
18
|
+
import type { ReportContent } from '../interfaces/folder-content-interfaces.js';
|
|
19
|
+
import type { ReportMetadata, UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
20
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
17
21
|
/**
|
|
18
22
|
* Report resource class.
|
|
19
23
|
*/
|
|
20
|
-
export declare class ReportResource extends FolderResource {
|
|
21
|
-
private reportSchema;
|
|
24
|
+
export declare class ReportResource extends FolderResource<ReportMetadata, ReportContent> {
|
|
22
25
|
constructor(project: Project, name: ResourceName);
|
|
23
|
-
private
|
|
24
|
-
private readSchemaFile;
|
|
26
|
+
private getDefaultReportLocation;
|
|
25
27
|
/**
|
|
26
28
|
* Handle name changes for reports
|
|
27
29
|
* @param existingName The previous name before the change
|
|
@@ -29,18 +31,8 @@ export declare class ReportResource extends FolderResource {
|
|
|
29
31
|
protected onNameChange(existingName: string): Promise<void>;
|
|
30
32
|
/**
|
|
31
33
|
* Sets new metadata into the report object.
|
|
32
|
-
* @param newContent metadata content for the report.
|
|
33
|
-
* @throws if 'newContent' is not valid.
|
|
34
34
|
*/
|
|
35
35
|
createReport(): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Returns resource content.
|
|
38
|
-
*/
|
|
39
|
-
get data(): ReportMetadata;
|
|
40
|
-
/**
|
|
41
|
-
* Deletes file and folder that this resource is based on.
|
|
42
|
-
*/
|
|
43
|
-
delete(): Promise<void>;
|
|
44
36
|
/**
|
|
45
37
|
* Returns list of handlebar filenames that this report has.
|
|
46
38
|
* @returns list of handlebar filenames that this report has.
|
|
@@ -51,17 +43,12 @@ export declare class ReportResource extends FolderResource {
|
|
|
51
43
|
* @param newName New name for the resource.
|
|
52
44
|
*/
|
|
53
45
|
rename(newName: ResourceName): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Shows metadata of the resource.
|
|
56
|
-
* @returns report metadata.
|
|
57
|
-
*/
|
|
58
|
-
show(): Promise<Report>;
|
|
59
46
|
/**
|
|
60
47
|
* Updates report resource.
|
|
61
|
-
* @param
|
|
48
|
+
* @param updateKey Key to modify
|
|
62
49
|
* @param op Operation to perform on 'key'
|
|
63
50
|
*/
|
|
64
|
-
update<Type>(
|
|
51
|
+
update<Type, K extends string>(updateKey: UpdateKey<K>, op: Operation<Type>): Promise<void>;
|
|
65
52
|
/**
|
|
66
53
|
* List where this resource is used.
|
|
67
54
|
* Always returns card key references first, then calculation references.
|
|
@@ -11,42 +11,30 @@
|
|
|
11
11
|
You should have received a copy of the GNU Affero General Public
|
|
12
12
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
13
|
*/
|
|
14
|
-
import { readdir } from 'node:fs/promises';
|
|
15
|
-
import { readFileSync } from 'node:fs';
|
|
16
14
|
import { extname, join } from 'node:path';
|
|
15
|
+
import { readdir } from 'node:fs/promises';
|
|
17
16
|
import { copyDir } from '../utils/file-utils.js';
|
|
18
|
-
import { DefaultContent
|
|
17
|
+
import { DefaultContent } from './create-defaults.js';
|
|
18
|
+
import { FolderResource } from './folder-resource.js';
|
|
19
19
|
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
20
|
-
import {
|
|
20
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
21
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
21
22
|
import { Validate } from '../commands/validate.js';
|
|
22
|
-
const REPORT_SCHEMA_FILE = 'parameterSchema.json';
|
|
23
23
|
const PARAMETER_SCHEMA_ID = 'jsonSchema';
|
|
24
|
-
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
25
24
|
/**
|
|
26
25
|
* Report resource class.
|
|
27
26
|
*/
|
|
28
27
|
export class ReportResource extends FolderResource {
|
|
29
|
-
reportSchema;
|
|
30
28
|
constructor(project, name) {
|
|
31
29
|
super(project, name, 'reports');
|
|
32
30
|
this.contentSchemaId = 'reportSchema';
|
|
33
31
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
34
|
-
this.initialize();
|
|
35
|
-
const schemaPath = join(this.internalFolder, REPORT_SCHEMA_FILE);
|
|
36
|
-
this.reportSchema = this.readSchemaFile(schemaPath);
|
|
37
32
|
}
|
|
38
33
|
// Path to content folder.
|
|
39
34
|
// @todo: create the files' content dynamically.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const schema = readFileSync(path);
|
|
45
|
-
return JSON.parse(schema.toString());
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
35
|
+
async getDefaultReportLocation() {
|
|
36
|
+
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
37
|
+
return join(staticDirectoryPath, 'defaultReport');
|
|
50
38
|
}
|
|
51
39
|
/**
|
|
52
40
|
* Handle name changes for reports
|
|
@@ -62,26 +50,14 @@ export class ReportResource extends FolderResource {
|
|
|
62
50
|
}
|
|
63
51
|
/**
|
|
64
52
|
* Sets new metadata into the report object.
|
|
65
|
-
* @param newContent metadata content for the report.
|
|
66
|
-
* @throws if 'newContent' is not valid.
|
|
67
53
|
*/
|
|
68
54
|
async createReport() {
|
|
69
55
|
const defaultContent = DefaultContent.report(resourceNameToString(this.resourceName));
|
|
70
56
|
await super.create(defaultContent);
|
|
71
57
|
// Copy report default structure to destination.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* Returns resource content.
|
|
76
|
-
*/
|
|
77
|
-
get data() {
|
|
78
|
-
return super.data;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Deletes file and folder that this resource is based on.
|
|
82
|
-
*/
|
|
83
|
-
async delete() {
|
|
84
|
-
return super.delete();
|
|
58
|
+
const defaultReportLocation = await this.getDefaultReportLocation();
|
|
59
|
+
await copyDir(defaultReportLocation, this.internalFolder);
|
|
60
|
+
await this.loadContentFiles();
|
|
85
61
|
}
|
|
86
62
|
/**
|
|
87
63
|
* Returns list of handlebar filenames that this report has.
|
|
@@ -104,43 +80,19 @@ export class ReportResource extends FolderResource {
|
|
|
104
80
|
await super.rename(newName);
|
|
105
81
|
return this.onNameChange(existingName);
|
|
106
82
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Shows metadata of the resource.
|
|
109
|
-
* @returns report metadata.
|
|
110
|
-
*/
|
|
111
|
-
async show() {
|
|
112
|
-
const baseData = (await super.show());
|
|
113
|
-
const fileContents = await super.contentData();
|
|
114
|
-
const content = {
|
|
115
|
-
contentTemplate: fileContents.contentTemplate,
|
|
116
|
-
queryTemplate: fileContents.queryTemplate,
|
|
117
|
-
schema: fileContents.schema ? fileContents.schema : undefined,
|
|
118
|
-
};
|
|
119
|
-
return {
|
|
120
|
-
...baseData,
|
|
121
|
-
content: content,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
83
|
/**
|
|
125
84
|
* Updates report resource.
|
|
126
|
-
* @param
|
|
85
|
+
* @param updateKey Key to modify
|
|
127
86
|
* @param op Operation to perform on 'key'
|
|
128
87
|
*/
|
|
129
|
-
async update(
|
|
130
|
-
if (
|
|
131
|
-
key.key === 'content' &&
|
|
132
|
-
key.subKey === 'schema') {
|
|
133
|
-
const fileContent = JSON.stringify(super.handleScalar(op), null, 2);
|
|
134
|
-
await this.updateFile(filename(key.subKey), fileContent);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (key === 'category') {
|
|
88
|
+
async update(updateKey, op) {
|
|
89
|
+
if (updateKey.key === 'category') {
|
|
138
90
|
const content = structuredClone(this.content);
|
|
139
91
|
content.category = super.handleScalar(op);
|
|
140
|
-
await super.postUpdate(content,
|
|
92
|
+
await super.postUpdate(content, updateKey, op);
|
|
141
93
|
return;
|
|
142
94
|
}
|
|
143
|
-
await super.update(
|
|
95
|
+
await super.update(updateKey, op);
|
|
144
96
|
}
|
|
145
97
|
/**
|
|
146
98
|
* List where this resource is used.
|
|
@@ -150,7 +102,7 @@ export class ReportResource extends FolderResource {
|
|
|
150
102
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
151
103
|
*/
|
|
152
104
|
async usage(cards) {
|
|
153
|
-
const allCards = cards ??
|
|
105
|
+
const allCards = cards ?? super.cards();
|
|
154
106
|
const [relevantCards, calculations] = await Promise.all([
|
|
155
107
|
super.usage(allCards),
|
|
156
108
|
super.calculations(),
|
|
@@ -164,8 +116,9 @@ export class ReportResource extends FolderResource {
|
|
|
164
116
|
* @note If content is not provided, base class validation will use resource's current content.
|
|
165
117
|
*/
|
|
166
118
|
async validate(content) {
|
|
167
|
-
|
|
168
|
-
|
|
119
|
+
const resourceContent = this.contentData();
|
|
120
|
+
if (resourceContent.schema) {
|
|
121
|
+
const errors = Validate.getInstance().validateJson(resourceContent.schema, PARAMETER_SCHEMA_ID);
|
|
169
122
|
if (errors.length > 0) {
|
|
170
123
|
throw new Error(`Invalid parameter schema: ${errors}`);
|
|
171
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report-resource.js","sourceRoot":"","sources":["../../src/resources/report-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"report-resource.js","sourceRoot":"","sources":["../../src/resources/report-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAYnD,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,cAGnC;IACC,YAAY,OAAgB,EAAE,IAAkB;QAC9C,KAAK,CAAC,OAAO,EAAE,IAAI,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