@cyberismo/data-handler 0.0.2
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/LICENSE +702 -0
- package/dist/card-metadata-updater.d.ts +33 -0
- package/dist/card-metadata-updater.js +121 -0
- package/dist/card-metadata-updater.js.map +1 -0
- package/dist/command-handler.d.ts +96 -0
- package/dist/command-handler.js +557 -0
- package/dist/command-handler.js.map +1 -0
- package/dist/command-manager.d.ts +43 -0
- package/dist/command-manager.js +73 -0
- package/dist/command-manager.js.map +1 -0
- package/dist/commands/calculate.d.ts +86 -0
- package/dist/commands/calculate.js +444 -0
- package/dist/commands/calculate.js.map +1 -0
- package/dist/commands/create.d.ts +114 -0
- package/dist/commands/create.js +389 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/edit.d.ts +37 -0
- package/dist/commands/edit.js +99 -0
- package/dist/commands/edit.js.map +1 -0
- package/dist/commands/export-site.d.ts +45 -0
- package/dist/commands/export-site.js +301 -0
- package/dist/commands/export-site.js.map +1 -0
- package/dist/commands/export.d.ts +53 -0
- package/dist/commands/export.js +251 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/import.d.ts +53 -0
- package/dist/commands/import.js +133 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/index.d.ts +26 -0
- package/dist/commands/index.js +27 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/move.d.ts +55 -0
- package/dist/commands/move.js +341 -0
- package/dist/commands/move.js.map +1 -0
- package/dist/commands/remove.d.ts +38 -0
- package/dist/commands/remove.js +192 -0
- package/dist/commands/remove.js.map +1 -0
- package/dist/commands/rename.d.ts +46 -0
- package/dist/commands/rename.js +289 -0
- package/dist/commands/rename.js.map +1 -0
- package/dist/commands/show.d.ts +124 -0
- package/dist/commands/show.js +345 -0
- package/dist/commands/show.js.map +1 -0
- package/dist/commands/transition.d.ts +27 -0
- package/dist/commands/transition.js +92 -0
- package/dist/commands/transition.js.map +1 -0
- package/dist/commands/update.d.ts +29 -0
- package/dist/commands/update.js +64 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/validate.d.ts +143 -0
- package/dist/commands/validate.js +689 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/containers/card-container.d.ts +44 -0
- package/dist/containers/card-container.js +282 -0
- package/dist/containers/card-container.js.map +1 -0
- package/dist/containers/project/project-paths.d.ts +46 -0
- package/dist/containers/project/project-paths.js +105 -0
- package/dist/containers/project/project-paths.js.map +1 -0
- package/dist/containers/project/resource-collector.d.ts +86 -0
- package/dist/containers/project/resource-collector.js +331 -0
- package/dist/containers/project/resource-collector.js.map +1 -0
- package/dist/containers/project.d.ts +351 -0
- package/dist/containers/project.js +896 -0
- package/dist/containers/project.js.map +1 -0
- package/dist/containers/template.d.ts +108 -0
- package/dist/containers/template.js +433 -0
- package/dist/containers/template.js.map +1 -0
- package/dist/exceptions/index.d.ts +19 -0
- package/dist/exceptions/index.js +26 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/adoc.d.ts +12 -0
- package/dist/interfaces/adoc.js +13 -0
- package/dist/interfaces/adoc.js.map +1 -0
- package/dist/interfaces/macros.d.ts +45 -0
- package/dist/interfaces/macros.js +13 -0
- package/dist/interfaces/macros.js.map +1 -0
- package/dist/interfaces/project-interfaces.d.ts +121 -0
- package/dist/interfaces/project-interfaces.js +21 -0
- package/dist/interfaces/project-interfaces.js.map +1 -0
- package/dist/interfaces/request-status-interfaces.d.ts +28 -0
- package/dist/interfaces/request-status-interfaces.js +20 -0
- package/dist/interfaces/request-status-interfaces.js.map +1 -0
- package/dist/interfaces/resource-interfaces.d.ts +117 -0
- package/dist/interfaces/resource-interfaces.js +20 -0
- package/dist/interfaces/resource-interfaces.js.map +1 -0
- package/dist/macros/base-macro.d.ts +31 -0
- package/dist/macros/base-macro.js +126 -0
- package/dist/macros/base-macro.js.map +1 -0
- package/dist/macros/common.d.ts +17 -0
- package/dist/macros/common.js +23 -0
- package/dist/macros/common.js.map +1 -0
- package/dist/macros/createCards/index.d.ts +36 -0
- package/dist/macros/createCards/index.js +35 -0
- package/dist/macros/createCards/index.js.map +1 -0
- package/dist/macros/createCards/metadata.d.ts +14 -0
- package/dist/macros/createCards/metadata.js +18 -0
- package/dist/macros/createCards/metadata.js.map +1 -0
- package/dist/macros/graph/index.d.ts +29 -0
- package/dist/macros/graph/index.js +91 -0
- package/dist/macros/graph/index.js.map +1 -0
- package/dist/macros/graph/metadata.d.ts +14 -0
- package/dist/macros/graph/metadata.js +18 -0
- package/dist/macros/graph/metadata.js.map +1 -0
- package/dist/macros/index.d.ts +93 -0
- package/dist/macros/index.js +237 -0
- package/dist/macros/index.js.map +1 -0
- package/dist/macros/report/index.d.ts +26 -0
- package/dist/macros/report/index.js +70 -0
- package/dist/macros/report/index.js.map +1 -0
- package/dist/macros/report/metadata.d.ts +14 -0
- package/dist/macros/report/metadata.js +18 -0
- package/dist/macros/report/metadata.js.map +1 -0
- package/dist/macros/scoreCard/index.d.ts +30 -0
- package/dist/macros/scoreCard/index.js +38 -0
- package/dist/macros/scoreCard/index.js.map +1 -0
- package/dist/macros/scoreCard/metadata.d.ts +14 -0
- package/dist/macros/scoreCard/metadata.js +18 -0
- package/dist/macros/scoreCard/metadata.js.map +1 -0
- package/dist/macros/task-queue.d.ts +46 -0
- package/dist/macros/task-queue.js +69 -0
- package/dist/macros/task-queue.js.map +1 -0
- package/dist/module-manager.d.ts +62 -0
- package/dist/module-manager.js +350 -0
- package/dist/module-manager.js.map +1 -0
- package/dist/permissions/action-guard.d.ts +28 -0
- package/dist/permissions/action-guard.js +61 -0
- package/dist/permissions/action-guard.js.map +1 -0
- package/dist/project-settings.d.ts +42 -0
- package/dist/project-settings.js +120 -0
- package/dist/project-settings.js.map +1 -0
- package/dist/resources/array-handler.d.ts +28 -0
- package/dist/resources/array-handler.js +116 -0
- package/dist/resources/array-handler.js.map +1 -0
- package/dist/resources/card-type-resource.d.ts +72 -0
- package/dist/resources/card-type-resource.js +334 -0
- package/dist/resources/card-type-resource.js.map +1 -0
- package/dist/resources/create-defaults.d.ts +81 -0
- package/dist/resources/create-defaults.js +184 -0
- package/dist/resources/create-defaults.js.map +1 -0
- package/dist/resources/field-type-resource.d.ts +88 -0
- package/dist/resources/field-type-resource.js +411 -0
- package/dist/resources/field-type-resource.js.map +1 -0
- package/dist/resources/file-resource.d.ts +50 -0
- package/dist/resources/file-resource.js +301 -0
- package/dist/resources/file-resource.js.map +1 -0
- package/dist/resources/folder-resource.d.ts +66 -0
- package/dist/resources/folder-resource.js +100 -0
- package/dist/resources/folder-resource.js.map +1 -0
- package/dist/resources/graph-model-resource.d.ts +78 -0
- package/dist/resources/graph-model-resource.js +164 -0
- package/dist/resources/graph-model-resource.js.map +1 -0
- package/dist/resources/graph-view-resource.d.ts +78 -0
- package/dist/resources/graph-view-resource.js +163 -0
- package/dist/resources/graph-view-resource.js.map +1 -0
- package/dist/resources/link-type-resource.d.ts +62 -0
- package/dist/resources/link-type-resource.js +150 -0
- package/dist/resources/link-type-resource.js.map +1 -0
- package/dist/resources/report-resource.d.ts +77 -0
- package/dist/resources/report-resource.js +171 -0
- package/dist/resources/report-resource.js.map +1 -0
- package/dist/resources/resource-object.d.ts +108 -0
- package/dist/resources/resource-object.js +147 -0
- package/dist/resources/resource-object.js.map +1 -0
- package/dist/resources/template-resource.d.ts +82 -0
- package/dist/resources/template-resource.js +173 -0
- package/dist/resources/template-resource.js.map +1 -0
- package/dist/resources/workflow-resource.d.ts +67 -0
- package/dist/resources/workflow-resource.js +156 -0
- package/dist/resources/workflow-resource.js.map +1 -0
- package/dist/types/queries.d.ts +142 -0
- package/dist/types/queries.js +16 -0
- package/dist/types/queries.js.map +1 -0
- package/dist/utils/card-utils.d.ts +34 -0
- package/dist/utils/card-utils.js +78 -0
- package/dist/utils/card-utils.js.map +1 -0
- package/dist/utils/clingo-fact-builder.d.ts +58 -0
- package/dist/utils/clingo-fact-builder.js +126 -0
- package/dist/utils/clingo-fact-builder.js.map +1 -0
- package/dist/utils/clingo-facts.d.ts +97 -0
- package/dist/utils/clingo-facts.js +352 -0
- package/dist/utils/clingo-facts.js.map +1 -0
- package/dist/utils/clingo-parser.d.ts +59 -0
- package/dist/utils/clingo-parser.js +403 -0
- package/dist/utils/clingo-parser.js.map +1 -0
- package/dist/utils/clingo-program-builder.d.ts +39 -0
- package/dist/utils/clingo-program-builder.js +57 -0
- package/dist/utils/clingo-program-builder.js.map +1 -0
- package/dist/utils/common-utils.d.ts +24 -0
- package/dist/utils/common-utils.js +47 -0
- package/dist/utils/common-utils.js.map +1 -0
- package/dist/utils/constants.d.ts +18 -0
- package/dist/utils/constants.js +27 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/csv.d.ts +18 -0
- package/dist/utils/csv.js +45 -0
- package/dist/utils/csv.js.map +1 -0
- package/dist/utils/file-utils.d.ts +69 -0
- package/dist/utils/file-utils.js +158 -0
- package/dist/utils/file-utils.js.map +1 -0
- package/dist/utils/json.d.ts +61 -0
- package/dist/utils/json.js +108 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/lexorank.d.ts +59 -0
- package/dist/utils/lexorank.js +159 -0
- package/dist/utils/lexorank.js.map +1 -0
- package/dist/utils/log-utils.d.ts +40 -0
- package/dist/utils/log-utils.js +109 -0
- package/dist/utils/log-utils.js.map +1 -0
- package/dist/utils/random.d.ts +19 -0
- package/dist/utils/random.js +34 -0
- package/dist/utils/random.js.map +1 -0
- package/dist/utils/resource-utils.d.ts +45 -0
- package/dist/utils/resource-utils.js +137 -0
- package/dist/utils/resource-utils.js.map +1 -0
- package/dist/utils/sanitize-svg.d.ts +18 -0
- package/dist/utils/sanitize-svg.js +38 -0
- package/dist/utils/sanitize-svg.js.map +1 -0
- package/dist/utils/user-preferences.d.ts +64 -0
- package/dist/utils/user-preferences.js +106 -0
- package/dist/utils/user-preferences.js.map +1 -0
- package/dist/utils/validate.d.ts +26 -0
- package/dist/utils/validate.js +53 -0
- package/dist/utils/validate.js.map +1 -0
- package/dist/utils/value-utils.d.ts +58 -0
- package/dist/utils/value-utils.js +181 -0
- package/dist/utils/value-utils.js.map +1 -0
- package/package.json +67 -0
- package/src/card-metadata-updater.ts +182 -0
- package/src/command-handler.ts +686 -0
- package/src/command-manager.ts +99 -0
- package/src/commands/calculate.ts +591 -0
- package/src/commands/create.ts +559 -0
- package/src/commands/edit.ts +123 -0
- package/src/commands/export-site.ts +356 -0
- package/src/commands/export.ts +315 -0
- package/src/commands/import.ts +169 -0
- package/src/commands/index.ts +42 -0
- package/src/commands/move.ts +451 -0
- package/src/commands/remove.ts +244 -0
- package/src/commands/rename.ts +378 -0
- package/src/commands/show.ts +442 -0
- package/src/commands/transition.ts +127 -0
- package/src/commands/update.ts +76 -0
- package/src/commands/validate.ts +962 -0
- package/src/containers/card-container.ts +378 -0
- package/src/containers/project/project-paths.ts +127 -0
- package/src/containers/project/resource-collector.ts +379 -0
- package/src/containers/project.ts +1135 -0
- package/src/containers/template.ts +573 -0
- package/src/exceptions/index.ts +29 -0
- package/src/index.ts +33 -0
- package/src/interfaces/adoc.ts +18 -0
- package/src/interfaces/macros.ts +54 -0
- package/src/interfaces/project-interfaces.ts +208 -0
- package/src/interfaces/request-status-interfaces.ts +30 -0
- package/src/interfaces/resource-interfaces.ts +179 -0
- package/src/macros/base-macro.ts +176 -0
- package/src/macros/common.ts +24 -0
- package/src/macros/createCards/index.ts +57 -0
- package/src/macros/createCards/metadata.ts +21 -0
- package/src/macros/graph/index.ts +130 -0
- package/src/macros/graph/metadata.ts +21 -0
- package/src/macros/index.ts +321 -0
- package/src/macros/report/index.ts +88 -0
- package/src/macros/report/metadata.ts +21 -0
- package/src/macros/scoreCard/index.ts +55 -0
- package/src/macros/scoreCard/metadata.ts +21 -0
- package/src/macros/task-queue.ts +79 -0
- package/src/module-manager.ts +443 -0
- package/src/permissions/action-guard.ts +77 -0
- package/src/project-settings.ts +140 -0
- package/src/resources/array-handler.ts +141 -0
- package/src/resources/card-type-resource.ts +455 -0
- package/src/resources/create-defaults.ts +216 -0
- package/src/resources/field-type-resource.ts +533 -0
- package/src/resources/file-resource.ts +433 -0
- package/src/resources/folder-resource.ts +140 -0
- package/src/resources/graph-model-resource.ts +205 -0
- package/src/resources/graph-view-resource.ts +199 -0
- package/src/resources/link-type-resource.ts +191 -0
- package/src/resources/report-resource.ts +224 -0
- package/src/resources/resource-object.ts +246 -0
- package/src/resources/template-resource.ts +210 -0
- package/src/resources/workflow-resource.ts +205 -0
- package/src/types/queries.ts +149 -0
- package/src/utils/card-utils.ts +83 -0
- package/src/utils/clingo-fact-builder.ts +167 -0
- package/src/utils/clingo-facts.ts +550 -0
- package/src/utils/clingo-parser.ts +519 -0
- package/src/utils/clingo-program-builder.ts +71 -0
- package/src/utils/common-utils.ts +54 -0
- package/src/utils/constants.ts +32 -0
- package/src/utils/csv.ts +53 -0
- package/src/utils/file-utils.ts +182 -0
- package/src/utils/json.ts +118 -0
- package/src/utils/lexorank.ts +180 -0
- package/src/utils/log-utils.ts +127 -0
- package/src/utils/random.ts +37 -0
- package/src/utils/resource-utils.ts +180 -0
- package/src/utils/sanitize-svg.ts +46 -0
- package/src/utils/user-preferences.ts +126 -0
- package/src/utils/validate.ts +66 -0
- package/src/utils/value-utils.ts +189 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
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/>.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readdir } from 'node:fs/promises';
|
|
16
|
+
import { extname, join } from 'node:path';
|
|
17
|
+
|
|
18
|
+
import type {
|
|
19
|
+
Card,
|
|
20
|
+
Operation,
|
|
21
|
+
Project,
|
|
22
|
+
ResourceName,
|
|
23
|
+
} from './folder-resource.js';
|
|
24
|
+
import {
|
|
25
|
+
DefaultContent,
|
|
26
|
+
FolderResource,
|
|
27
|
+
resourceNameToString,
|
|
28
|
+
sortCards,
|
|
29
|
+
} from './folder-resource.js';
|
|
30
|
+
import type {
|
|
31
|
+
GraphModel,
|
|
32
|
+
GraphModelMetadata,
|
|
33
|
+
} from '../interfaces/resource-interfaces.js';
|
|
34
|
+
import { writeFileSafe } from '../utils/file-utils.js';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Graph model resource class.
|
|
38
|
+
*/
|
|
39
|
+
export class GraphModelResource extends FolderResource {
|
|
40
|
+
constructor(project: Project, name: ResourceName) {
|
|
41
|
+
super(project, name, 'graphModels');
|
|
42
|
+
|
|
43
|
+
this.contentSchemaId = 'graphModelSchema';
|
|
44
|
+
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
45
|
+
|
|
46
|
+
this.initialize();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// When resource name changes.
|
|
50
|
+
private async handleNameChange(existingName: string) {
|
|
51
|
+
await Promise.all([
|
|
52
|
+
super.updateHandleBars(existingName, this.content.name, [
|
|
53
|
+
await this.calculationFile(),
|
|
54
|
+
]),
|
|
55
|
+
super.updateCalculations(existingName, this.content.name),
|
|
56
|
+
]);
|
|
57
|
+
// Finally, write updated content.
|
|
58
|
+
await this.write();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Sets new metadata into the graph model object graph model.
|
|
63
|
+
* @param newContent metadata content for the graph model.
|
|
64
|
+
* @throws if 'newContent' is not valid.
|
|
65
|
+
*/
|
|
66
|
+
public async create(newContent?: GraphModelMetadata) {
|
|
67
|
+
if (!newContent) {
|
|
68
|
+
newContent = DefaultContent.graphModel(
|
|
69
|
+
resourceNameToString(this.resourceName),
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
await this.validate(newContent);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
await super.create(newContent);
|
|
76
|
+
|
|
77
|
+
// Create the internal folder in 'create', instead of 'write'.
|
|
78
|
+
const calculationsFile = join(this.internalFolder, 'model.lp');
|
|
79
|
+
await writeFileSafe(
|
|
80
|
+
calculationsFile,
|
|
81
|
+
`% add your calculations here for '${this.resourceName.identifier}'`,
|
|
82
|
+
{
|
|
83
|
+
flag: 'wx',
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Returns resource content.
|
|
90
|
+
*/
|
|
91
|
+
public get data(): GraphModel {
|
|
92
|
+
return super.data as GraphModel;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Deletes file and folder that this resource is based on.
|
|
97
|
+
*/
|
|
98
|
+
public async delete() {
|
|
99
|
+
return super.delete();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Returns calculation file that this graph model has.
|
|
104
|
+
* @returns calculation file name that this graph model has.
|
|
105
|
+
*/
|
|
106
|
+
public async calculationFile(nameOnly: boolean = false): Promise<string> {
|
|
107
|
+
return (
|
|
108
|
+
await readdir(this.internalFolder, {
|
|
109
|
+
withFileTypes: true,
|
|
110
|
+
recursive: true,
|
|
111
|
+
})
|
|
112
|
+
)
|
|
113
|
+
.filter((dirent) => dirent.isFile() && extname(dirent.name) === '.lp')
|
|
114
|
+
.map((item) => (nameOnly ? item.name : join(item.parentPath, item.name)))
|
|
115
|
+
.at(0)!;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Renames the object and the file.
|
|
120
|
+
* @param newName New name for the resource.
|
|
121
|
+
*/
|
|
122
|
+
public async rename(newName: ResourceName) {
|
|
123
|
+
const existingName = this.content.name;
|
|
124
|
+
await super.rename(newName);
|
|
125
|
+
return this.handleNameChange(existingName);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Shows metadata of the resource.
|
|
130
|
+
* @returns graph model metadata.
|
|
131
|
+
*/
|
|
132
|
+
public async show(): Promise<GraphModel> {
|
|
133
|
+
const showOnlyFileName = true;
|
|
134
|
+
const baseData = (await super.show()) as GraphModelMetadata;
|
|
135
|
+
return {
|
|
136
|
+
...baseData,
|
|
137
|
+
calculationFile: await this.calculationFile(showOnlyFileName),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Updates graph model resource.
|
|
143
|
+
* @param key Key to modify
|
|
144
|
+
* @param op Operation to perform on 'key'
|
|
145
|
+
* @throws if key is unknown.
|
|
146
|
+
*/
|
|
147
|
+
public async update<Type>(key: string, op: Operation<Type>) {
|
|
148
|
+
const nameChange = key === 'name';
|
|
149
|
+
const existingName = this.content.name;
|
|
150
|
+
|
|
151
|
+
await super.update(key, op);
|
|
152
|
+
|
|
153
|
+
const content = { ...(this.content as GraphModel) };
|
|
154
|
+
|
|
155
|
+
if (key === 'name') {
|
|
156
|
+
content.name = super.handleScalar(op) as string;
|
|
157
|
+
} else if (key === 'displayName') {
|
|
158
|
+
content.displayName = super.handleScalar(op) as string;
|
|
159
|
+
} else if (key === 'description') {
|
|
160
|
+
content.description = super.handleScalar(op) as string;
|
|
161
|
+
} else if (key === 'category') {
|
|
162
|
+
content.category = super.handleScalar(op) as string;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
await super.postUpdate(content, key, op);
|
|
166
|
+
|
|
167
|
+
// Renaming this graph model causes that references to its name must be updated.
|
|
168
|
+
if (nameChange) {
|
|
169
|
+
await this.handleNameChange(existingName);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* List where this resource is used.
|
|
175
|
+
* Always returns card key references first, then calculation references.
|
|
176
|
+
*
|
|
177
|
+
* @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
|
|
178
|
+
* @returns array of card keys and calculation filenames that refer this resource.
|
|
179
|
+
*/
|
|
180
|
+
public async usage(cards?: Card[]): Promise<string[]> {
|
|
181
|
+
const allCards = cards ?? (await super.cards());
|
|
182
|
+
const [relevantCards, calculations] = await Promise.all([
|
|
183
|
+
super.usage(allCards),
|
|
184
|
+
super.calculations(),
|
|
185
|
+
]);
|
|
186
|
+
return [...relevantCards.sort(sortCards), ...calculations];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Validates graphModel.
|
|
191
|
+
* @throws when there are validation errors.
|
|
192
|
+
* @param content Content to be validated.
|
|
193
|
+
* @note If content is not provided, base class validation will use resource's current content.
|
|
194
|
+
*/
|
|
195
|
+
public async validate(content?: object) {
|
|
196
|
+
return super.validate(content);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Create the graph model's folder and calculation file.
|
|
201
|
+
*/
|
|
202
|
+
public async write() {
|
|
203
|
+
await super.write();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
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/>.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readdir } from 'node:fs/promises';
|
|
16
|
+
import { extname, join } from 'node:path';
|
|
17
|
+
|
|
18
|
+
import type {
|
|
19
|
+
Card,
|
|
20
|
+
Operation,
|
|
21
|
+
Project,
|
|
22
|
+
ResourceName,
|
|
23
|
+
} from './folder-resource.js';
|
|
24
|
+
import {
|
|
25
|
+
DefaultContent,
|
|
26
|
+
FolderResource,
|
|
27
|
+
resourceNameToString,
|
|
28
|
+
sortCards,
|
|
29
|
+
} from './folder-resource.js';
|
|
30
|
+
import type {
|
|
31
|
+
GraphView,
|
|
32
|
+
GraphViewMetadata,
|
|
33
|
+
} from '../interfaces/resource-interfaces.js';
|
|
34
|
+
import { writeFileSafe } from '../utils/file-utils.js';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Graph view resource class.
|
|
38
|
+
*/
|
|
39
|
+
export class GraphViewResource extends FolderResource {
|
|
40
|
+
constructor(project: Project, name: ResourceName) {
|
|
41
|
+
super(project, name, 'graphViews');
|
|
42
|
+
|
|
43
|
+
this.contentSchemaId = 'graphViewSchema';
|
|
44
|
+
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
45
|
+
|
|
46
|
+
this.initialize();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// When resource name changes.
|
|
50
|
+
private async handleNameChange(existingName: string) {
|
|
51
|
+
await Promise.all([
|
|
52
|
+
super.updateHandleBars(existingName, this.content.name, [
|
|
53
|
+
await this.handleBarFile(),
|
|
54
|
+
]),
|
|
55
|
+
super.updateCalculations(existingName, this.content.name),
|
|
56
|
+
]);
|
|
57
|
+
// Finally, write updated content.
|
|
58
|
+
await this.write();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Sets new metadata into the graph view object.
|
|
63
|
+
* @param newContent metadata content for the graph view.
|
|
64
|
+
* @throws if 'newContent' is not valid.
|
|
65
|
+
*/
|
|
66
|
+
public async create(newContent?: GraphViewMetadata) {
|
|
67
|
+
if (!newContent) {
|
|
68
|
+
newContent = DefaultContent.graphView(
|
|
69
|
+
resourceNameToString(this.resourceName),
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
await this.validate(newContent);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
await super.create(newContent);
|
|
76
|
+
const handleBarFile = join(this.internalFolder, 'view.lp.hbs');
|
|
77
|
+
await writeFileSafe(handleBarFile, '', {
|
|
78
|
+
flag: 'wx',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Returns resource content.
|
|
84
|
+
*/
|
|
85
|
+
public get data(): GraphView {
|
|
86
|
+
return super.data as GraphView;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Deletes file and folder that this resource is based on.
|
|
91
|
+
*/
|
|
92
|
+
public async delete() {
|
|
93
|
+
return super.delete();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Returns handlebar filename that this graph view has.
|
|
98
|
+
* @returns handlebar filename that this graph view has.
|
|
99
|
+
*/
|
|
100
|
+
public async handleBarFile(nameOnly: boolean = false): Promise<string> {
|
|
101
|
+
return (
|
|
102
|
+
await readdir(this.internalFolder, {
|
|
103
|
+
withFileTypes: true,
|
|
104
|
+
recursive: true,
|
|
105
|
+
})
|
|
106
|
+
)
|
|
107
|
+
.filter((dirent) => dirent.isFile() && extname(dirent.name) === '.hbs')
|
|
108
|
+
.map((item) => (nameOnly ? item.name : join(item.parentPath, item.name)))
|
|
109
|
+
.at(0)!;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Renames the object and the file.
|
|
114
|
+
* @param newName New name for the resource.
|
|
115
|
+
*/
|
|
116
|
+
public async rename(newName: ResourceName) {
|
|
117
|
+
const existingName = this.content.name;
|
|
118
|
+
await super.rename(newName);
|
|
119
|
+
return this.handleNameChange(existingName);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Shows metadata of the resource.
|
|
124
|
+
* @returns graph view metadata.
|
|
125
|
+
*/
|
|
126
|
+
public async show(): Promise<GraphView> {
|
|
127
|
+
const showOnlyFileName = true;
|
|
128
|
+
const baseData = (await super.show()) as GraphViewMetadata;
|
|
129
|
+
return {
|
|
130
|
+
...baseData,
|
|
131
|
+
handleBarFile: await this.handleBarFile(showOnlyFileName),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Updates graph view resource.
|
|
137
|
+
* @param key Key to modify
|
|
138
|
+
* @param op Operation to perform on 'key'
|
|
139
|
+
* @throws if key is unknown.
|
|
140
|
+
*/
|
|
141
|
+
public async update<Type>(key: string, op: Operation<Type>) {
|
|
142
|
+
const nameChange = key === 'name';
|
|
143
|
+
const existingName = this.content.name;
|
|
144
|
+
|
|
145
|
+
await super.update(key, op);
|
|
146
|
+
|
|
147
|
+
const content = { ...(this.content as GraphView) };
|
|
148
|
+
|
|
149
|
+
if (key === 'name') {
|
|
150
|
+
content.name = super.handleScalar(op) as string;
|
|
151
|
+
} else if (key === 'displayName') {
|
|
152
|
+
content.displayName = super.handleScalar(op) as string;
|
|
153
|
+
} else if (key === 'description') {
|
|
154
|
+
content.description = super.handleScalar(op) as string;
|
|
155
|
+
} else if (key === 'category') {
|
|
156
|
+
content.category = super.handleScalar(op) as string;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
await super.postUpdate(content, key, op);
|
|
160
|
+
|
|
161
|
+
// Renaming this graph view causes that references to its name must be updated.
|
|
162
|
+
if (nameChange) {
|
|
163
|
+
await this.handleNameChange(existingName);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* List where this resource is used.
|
|
169
|
+
* Always returns card key references first, then calculation references.
|
|
170
|
+
*
|
|
171
|
+
* @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
|
|
172
|
+
* @returns array of card keys and calculation filenames that refer this resource.
|
|
173
|
+
*/
|
|
174
|
+
public async usage(cards?: Card[]): Promise<string[]> {
|
|
175
|
+
const allCards = cards ?? (await super.cards());
|
|
176
|
+
const [relevantCards, calculations] = await Promise.all([
|
|
177
|
+
super.usage(allCards),
|
|
178
|
+
super.calculations(),
|
|
179
|
+
]);
|
|
180
|
+
return [...relevantCards.sort(sortCards), ...calculations];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Validates graph view.
|
|
185
|
+
* @throws when there are validation errors.
|
|
186
|
+
* @param content Content to be validated.
|
|
187
|
+
* @note If content is not provided, base class validation will use resource's current content.
|
|
188
|
+
*/
|
|
189
|
+
public async validate(content?: object) {
|
|
190
|
+
return super.validate(content);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Create the graph view's folder and handlebar file.
|
|
195
|
+
*/
|
|
196
|
+
public async write() {
|
|
197
|
+
await super.write();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
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 the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
Card,
|
|
15
|
+
Operation,
|
|
16
|
+
Project,
|
|
17
|
+
ResourceName,
|
|
18
|
+
} from './file-resource.js';
|
|
19
|
+
import {
|
|
20
|
+
DefaultContent,
|
|
21
|
+
FileResource,
|
|
22
|
+
resourceNameToString,
|
|
23
|
+
sortCards,
|
|
24
|
+
} from './folder-resource.js';
|
|
25
|
+
import type { LinkType } from '../interfaces/resource-interfaces.js';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Link Type resource class.
|
|
29
|
+
*/
|
|
30
|
+
export class LinkTypeResource extends FileResource {
|
|
31
|
+
constructor(project: Project, name: ResourceName) {
|
|
32
|
+
super(project, name, 'linkTypes');
|
|
33
|
+
|
|
34
|
+
this.contentSchemaId = 'linkTypeSchema';
|
|
35
|
+
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
36
|
+
|
|
37
|
+
this.initialize();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// When resource name changes.
|
|
41
|
+
private async handleNameChange(existingName: string) {
|
|
42
|
+
const current = this.content as LinkType;
|
|
43
|
+
const prefixes = await this.project.projectPrefixes();
|
|
44
|
+
if (current.sourceCardTypes) {
|
|
45
|
+
current.sourceCardTypes = current.sourceCardTypes.map((item) =>
|
|
46
|
+
this.updatePrefixInResourceName(item, prefixes),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (current.destinationCardTypes) {
|
|
50
|
+
current.destinationCardTypes = current.destinationCardTypes.map((item) =>
|
|
51
|
+
this.updatePrefixInResourceName(item, prefixes),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
await Promise.all([
|
|
55
|
+
super.updateHandleBars(existingName, this.content.name),
|
|
56
|
+
super.updateCalculations(existingName, this.content.name),
|
|
57
|
+
]);
|
|
58
|
+
// Finally, write updated content.
|
|
59
|
+
await this.write();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new link type object. Base class writes the object to disk automatically.
|
|
64
|
+
* @param newContent Content for the link type.
|
|
65
|
+
*/
|
|
66
|
+
public async create(newContent?: LinkType) {
|
|
67
|
+
if (!newContent) {
|
|
68
|
+
newContent = DefaultContent.linkType(
|
|
69
|
+
resourceNameToString(this.resourceName),
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
await this.validate(newContent);
|
|
73
|
+
}
|
|
74
|
+
return super.create(newContent);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns content data.
|
|
79
|
+
*/
|
|
80
|
+
public get data() {
|
|
81
|
+
return super.data as LinkType;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Deletes file(s) from disk and clears out the memory resident object.
|
|
86
|
+
*/
|
|
87
|
+
public async delete() {
|
|
88
|
+
return super.delete();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Renames resource metadata file and renames memory resident object 'name'.
|
|
93
|
+
* @param newName New name for the resource.
|
|
94
|
+
*/
|
|
95
|
+
public async rename(newName: ResourceName) {
|
|
96
|
+
const existingName = this.content.name;
|
|
97
|
+
await super.rename(newName);
|
|
98
|
+
return this.handleNameChange(existingName);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Shows metadata of the resource.
|
|
103
|
+
* @returns link type metadata.
|
|
104
|
+
*/
|
|
105
|
+
public async show(): Promise<LinkType> {
|
|
106
|
+
return super.show() as Promise<LinkType>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Updates link type resource.
|
|
111
|
+
* @param key Key to modify
|
|
112
|
+
* @param op Operation to perform on 'key'
|
|
113
|
+
*/
|
|
114
|
+
public async update<Type>(key: string, op: Operation<Type>) {
|
|
115
|
+
const nameChange = key === 'name';
|
|
116
|
+
const existingName = this.content.name;
|
|
117
|
+
|
|
118
|
+
await super.update(key, op);
|
|
119
|
+
|
|
120
|
+
const content = this.content as LinkType;
|
|
121
|
+
if (key === 'name') {
|
|
122
|
+
content.name = super.handleScalar(op) as string;
|
|
123
|
+
} else if (key === 'destinationCardTypes') {
|
|
124
|
+
content.destinationCardTypes = super.handleArray(
|
|
125
|
+
op,
|
|
126
|
+
key,
|
|
127
|
+
content.destinationCardTypes as Type[],
|
|
128
|
+
) as string[];
|
|
129
|
+
} else if (key === 'enableLinkDescription') {
|
|
130
|
+
content.enableLinkDescription = super.handleScalar(op) as boolean;
|
|
131
|
+
} else if (key === 'inboundDisplayName') {
|
|
132
|
+
content.inboundDisplayName = super.handleScalar(op) as string;
|
|
133
|
+
} else if (key === 'outboundDisplayName') {
|
|
134
|
+
content.outboundDisplayName = super.handleScalar(op) as string;
|
|
135
|
+
} else if (key === 'sourceCardTypes') {
|
|
136
|
+
content.sourceCardTypes = super.handleArray(
|
|
137
|
+
op,
|
|
138
|
+
key,
|
|
139
|
+
content.sourceCardTypes as Type[],
|
|
140
|
+
) as string[];
|
|
141
|
+
} else {
|
|
142
|
+
throw new Error(`Unknown property '${key}' for FieldType`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
await super.postUpdate(content, key, op);
|
|
146
|
+
|
|
147
|
+
// Renaming this card type causes that references to its name must be updated.
|
|
148
|
+
if (nameChange) {
|
|
149
|
+
await this.handleNameChange(existingName);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* List where link type is used.
|
|
155
|
+
* Always returns card key references first, then calculation references.
|
|
156
|
+
*
|
|
157
|
+
* @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
|
|
158
|
+
* @returns array of card keys calculation filenames that refer this resource.
|
|
159
|
+
*/
|
|
160
|
+
public async usage(cards?: Card[]): Promise<string[]> {
|
|
161
|
+
const resourceName = resourceNameToString(this.resourceName);
|
|
162
|
+
const allCards = cards || (await super.cards());
|
|
163
|
+
|
|
164
|
+
const cardsThatUseLinkType = allCards
|
|
165
|
+
.filter((card) =>
|
|
166
|
+
card.metadata?.links.find((item) => item.linkType === resourceName),
|
|
167
|
+
)
|
|
168
|
+
.filter(Boolean)
|
|
169
|
+
.map((card) => card.key);
|
|
170
|
+
|
|
171
|
+
const [cardContentReferences, calculations] = await Promise.all([
|
|
172
|
+
super.usage(allCards),
|
|
173
|
+
super.calculations(),
|
|
174
|
+
]);
|
|
175
|
+
|
|
176
|
+
const cardReferences = [
|
|
177
|
+
...cardsThatUseLinkType,
|
|
178
|
+
...cardContentReferences,
|
|
179
|
+
].sort(sortCards);
|
|
180
|
+
|
|
181
|
+
// Using Set to avoid duplicate cards
|
|
182
|
+
return [...new Set([...cardReferences, ...calculations])];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Validates the resource. If object is invalid, throws.
|
|
187
|
+
*/
|
|
188
|
+
public async validate(content?: object) {
|
|
189
|
+
return super.validate(content);
|
|
190
|
+
}
|
|
191
|
+
}
|