@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,77 @@
|
|
|
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
|
|
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
|
+
import type { Card, Operation, Project, ResourceName } from './folder-resource.js';
|
|
15
|
+
import { FolderResource } from './folder-resource.js';
|
|
16
|
+
import type { Report, ReportMetadata } from '../interfaces/resource-interfaces.js';
|
|
17
|
+
/**
|
|
18
|
+
* Report resource class.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ReportResource extends FolderResource {
|
|
21
|
+
private reportSchema;
|
|
22
|
+
constructor(project: Project, name: ResourceName);
|
|
23
|
+
private defaultReportLocation;
|
|
24
|
+
private handleNameChange;
|
|
25
|
+
private readSchemaFile;
|
|
26
|
+
/**
|
|
27
|
+
* Sets new metadata into the report object.
|
|
28
|
+
* @param newContent metadata content for the report.
|
|
29
|
+
* @throws if 'newContent' is not valid.
|
|
30
|
+
*/
|
|
31
|
+
createReport(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Returns resource content.
|
|
34
|
+
*/
|
|
35
|
+
get data(): ReportMetadata;
|
|
36
|
+
/**
|
|
37
|
+
* Deletes file and folder that this resource is based on.
|
|
38
|
+
*/
|
|
39
|
+
delete(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Returns list of handlebar filenames that this report has.
|
|
42
|
+
* @returns list of handlebar filenames that this report has.
|
|
43
|
+
*/
|
|
44
|
+
handleBarFiles(): Promise<string[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Renames the object and the file.
|
|
47
|
+
* @param newName New name for the resource.
|
|
48
|
+
*/
|
|
49
|
+
rename(newName: ResourceName): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Shows metadata of the resource.
|
|
52
|
+
* @returns report metadata.
|
|
53
|
+
*/
|
|
54
|
+
show(): Promise<Report>;
|
|
55
|
+
/**
|
|
56
|
+
* Updates report resource.
|
|
57
|
+
* @param key Key to modify
|
|
58
|
+
* @param op Operation to perform on 'key'
|
|
59
|
+
* @throws if key is unknown.
|
|
60
|
+
*/
|
|
61
|
+
update<Type>(key: string, op: Operation<Type>): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* List where this resource is used.
|
|
64
|
+
* Always returns card key references first, then calculation references.
|
|
65
|
+
*
|
|
66
|
+
* @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
|
|
67
|
+
* @returns array of card keys and calculation filenames that refer this resource.
|
|
68
|
+
*/
|
|
69
|
+
usage(cards?: Card[]): Promise<string[]>;
|
|
70
|
+
/**
|
|
71
|
+
* Validates report.
|
|
72
|
+
* @throws when there are validation errors.
|
|
73
|
+
* @param content Content to be validated.
|
|
74
|
+
* @note If content is not provided, base class validation will use resource's current content.
|
|
75
|
+
*/
|
|
76
|
+
validate(content?: object): Promise<void>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
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
|
|
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
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
15
|
+
import { readFileSync } from 'node:fs';
|
|
16
|
+
import { extname, join } from 'node:path';
|
|
17
|
+
import { copyDir } from '../utils/file-utils.js';
|
|
18
|
+
import { DefaultContent, FolderResource, resourceNameToString, sortCards, } from './folder-resource.js';
|
|
19
|
+
import { getStaticDirectoryPath } from '@cyberismocom/resources';
|
|
20
|
+
const CARD_CONTENT_HANDLEBAR_FILE = 'index.adoc.hbs';
|
|
21
|
+
const QUERY_HANDLEBAR_FILE = 'query.lp.hbs';
|
|
22
|
+
const REPORT_SCHEMA_FILE = 'parameterSchema.json';
|
|
23
|
+
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
24
|
+
/**
|
|
25
|
+
* Report resource class.
|
|
26
|
+
*/
|
|
27
|
+
export class ReportResource extends FolderResource {
|
|
28
|
+
reportSchema;
|
|
29
|
+
constructor(project, name) {
|
|
30
|
+
super(project, name, 'reports');
|
|
31
|
+
this.contentSchemaId = 'reportSchema';
|
|
32
|
+
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
33
|
+
this.initialize();
|
|
34
|
+
const schemaPath = join(this.internalFolder, REPORT_SCHEMA_FILE);
|
|
35
|
+
this.reportSchema = this.readSchemaFile(schemaPath);
|
|
36
|
+
}
|
|
37
|
+
// Path to content folder.
|
|
38
|
+
// @todo: create the files' content dynamically.
|
|
39
|
+
defaultReportLocation = join(staticDirectoryPath, 'defaultReport');
|
|
40
|
+
// When resource name changes.
|
|
41
|
+
async handleNameChange(existingName) {
|
|
42
|
+
await Promise.all([
|
|
43
|
+
super.updateHandleBars(existingName, this.content.name, await this.handleBarFiles()),
|
|
44
|
+
super.updateCalculations(existingName, this.content.name),
|
|
45
|
+
]);
|
|
46
|
+
// Finally, write updated content.
|
|
47
|
+
await this.write();
|
|
48
|
+
}
|
|
49
|
+
// Try to read schema file content
|
|
50
|
+
readSchemaFile(path) {
|
|
51
|
+
try {
|
|
52
|
+
const schema = readFileSync(path);
|
|
53
|
+
return JSON.parse(schema.toString());
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Sets new metadata into the report object.
|
|
61
|
+
* @param newContent metadata content for the report.
|
|
62
|
+
* @throws if 'newContent' is not valid.
|
|
63
|
+
*/
|
|
64
|
+
async createReport() {
|
|
65
|
+
const defaultContent = DefaultContent.report(resourceNameToString(this.resourceName));
|
|
66
|
+
await super.create(defaultContent);
|
|
67
|
+
// Copy report default structure to destination.
|
|
68
|
+
await copyDir(this.defaultReportLocation, this.internalFolder);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns resource content.
|
|
72
|
+
*/
|
|
73
|
+
get data() {
|
|
74
|
+
return super.data;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Deletes file and folder that this resource is based on.
|
|
78
|
+
*/
|
|
79
|
+
async delete() {
|
|
80
|
+
return super.delete();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns list of handlebar filenames that this report has.
|
|
84
|
+
* @returns list of handlebar filenames that this report has.
|
|
85
|
+
*/
|
|
86
|
+
async handleBarFiles() {
|
|
87
|
+
return (await readdir(this.internalFolder, {
|
|
88
|
+
withFileTypes: true,
|
|
89
|
+
recursive: true,
|
|
90
|
+
}))
|
|
91
|
+
.filter((dirent) => dirent.isFile() && extname(dirent.name) === '.hbs')
|
|
92
|
+
.map((item) => join(item.parentPath, item.name));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Renames the object and the file.
|
|
96
|
+
* @param newName New name for the resource.
|
|
97
|
+
*/
|
|
98
|
+
async rename(newName) {
|
|
99
|
+
const existingName = this.content.name;
|
|
100
|
+
await super.rename(newName);
|
|
101
|
+
return this.handleNameChange(existingName);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Shows metadata of the resource.
|
|
105
|
+
* @returns report metadata.
|
|
106
|
+
*/
|
|
107
|
+
async show() {
|
|
108
|
+
const reportMetadata = (await super.show());
|
|
109
|
+
return {
|
|
110
|
+
name: resourceNameToString(this.resourceName),
|
|
111
|
+
metadata: reportMetadata,
|
|
112
|
+
contentTemplate: (await readFile(join(this.internalFolder, CARD_CONTENT_HANDLEBAR_FILE))).toString(),
|
|
113
|
+
queryTemplate: (await readFile(join(this.internalFolder, QUERY_HANDLEBAR_FILE))).toString(),
|
|
114
|
+
schema: this.reportSchema,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Updates report resource.
|
|
119
|
+
* @param key Key to modify
|
|
120
|
+
* @param op Operation to perform on 'key'
|
|
121
|
+
* @throws if key is unknown.
|
|
122
|
+
*/
|
|
123
|
+
async update(key, op) {
|
|
124
|
+
const nameChange = key === 'name';
|
|
125
|
+
const existingName = this.content.name;
|
|
126
|
+
await super.update(key, op);
|
|
127
|
+
const content = { ...this.content };
|
|
128
|
+
if (key === 'name') {
|
|
129
|
+
content.name = super.handleScalar(op);
|
|
130
|
+
}
|
|
131
|
+
else if (key === 'displayName') {
|
|
132
|
+
content.displayName = super.handleScalar(op);
|
|
133
|
+
}
|
|
134
|
+
else if (key === 'description') {
|
|
135
|
+
content.description = super.handleScalar(op);
|
|
136
|
+
}
|
|
137
|
+
else if (key === 'category') {
|
|
138
|
+
content.category = super.handleScalar(op);
|
|
139
|
+
}
|
|
140
|
+
await super.postUpdate(content, key, op);
|
|
141
|
+
// Renaming this report causes that references to its name must be updated.
|
|
142
|
+
if (nameChange) {
|
|
143
|
+
await this.handleNameChange(existingName);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* List where this resource is used.
|
|
148
|
+
* Always returns card key references first, then calculation references.
|
|
149
|
+
*
|
|
150
|
+
* @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
|
|
151
|
+
* @returns array of card keys and calculation filenames that refer this resource.
|
|
152
|
+
*/
|
|
153
|
+
async usage(cards) {
|
|
154
|
+
const allCards = cards ?? (await super.cards());
|
|
155
|
+
const [relevantCards, calculations] = await Promise.all([
|
|
156
|
+
super.usage(allCards),
|
|
157
|
+
super.calculations(),
|
|
158
|
+
]);
|
|
159
|
+
return [...relevantCards.sort(sortCards), ...calculations];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Validates report.
|
|
163
|
+
* @throws when there are validation errors.
|
|
164
|
+
* @param content Content to be validated.
|
|
165
|
+
* @note If content is not provided, base class validation will use resource's current content.
|
|
166
|
+
*/
|
|
167
|
+
async validate(content) {
|
|
168
|
+
return super.validate(content);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=report-resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-resource.js","sourceRoot":"","sources":["../../src/resources/report-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAOjD,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,2BAA2B,GAAG,gBAAgB,CAAC;AACrD,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAC5C,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAElD,MAAM,mBAAmB,GAAG,MAAM,sBAAsB,EAAE,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,cAAc;IACxC,YAAY,CAAS;IAC7B,YAAY,OAAgB,EAAE,IAAkB;QAC9C,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QAEhC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAEtE,IAAI,CAAC,UAAU,EAAE,CAAC;QAElB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAA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AAO,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;IAED;;;;;OAKG;IACI,KAAK,CAAC,QAAQ,CAAC,OAAgB;QACpC,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
import type { Card, ResourceFolderType } from '../interfaces/project-interfaces.js';
|
|
13
|
+
import { type Project } from '../containers/project.js';
|
|
14
|
+
import type { ResourceContent } from '../interfaces/resource-interfaces.js';
|
|
15
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
16
|
+
export type UpdateOperations = 'add' | 'change' | 'rank' | 'remove';
|
|
17
|
+
type BaseOperation<T> = {
|
|
18
|
+
name: 'add' | 'change' | 'rank' | 'remove';
|
|
19
|
+
target: T;
|
|
20
|
+
};
|
|
21
|
+
export type AddOperation<T> = BaseOperation<T> & {
|
|
22
|
+
name: 'add';
|
|
23
|
+
};
|
|
24
|
+
export type ChangeOperation<T> = BaseOperation<T> & {
|
|
25
|
+
name: 'change';
|
|
26
|
+
to: T;
|
|
27
|
+
};
|
|
28
|
+
export type RankOperation<T> = BaseOperation<T> & {
|
|
29
|
+
name: 'rank';
|
|
30
|
+
newIndex: number;
|
|
31
|
+
};
|
|
32
|
+
export type RemoveOperation<T> = BaseOperation<T> & {
|
|
33
|
+
name: 'remove';
|
|
34
|
+
replacementValue?: T;
|
|
35
|
+
};
|
|
36
|
+
export type Operation<T> = AddOperation<T> | ChangeOperation<T> | RankOperation<T> | RemoveOperation<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Abstract class for resources.
|
|
39
|
+
*/
|
|
40
|
+
export declare abstract class AbstractResource {
|
|
41
|
+
protected abstract calculate(): Promise<void>;
|
|
42
|
+
protected abstract create(content?: ResourceContent): Promise<void>;
|
|
43
|
+
protected abstract delete(): Promise<void>;
|
|
44
|
+
protected abstract read(): Promise<void>;
|
|
45
|
+
protected abstract rename(newName: ResourceName): Promise<void>;
|
|
46
|
+
protected abstract show(): Promise<ResourceContent>;
|
|
47
|
+
protected abstract update<Type>(key: string, operation: Operation<Type>): Promise<void>;
|
|
48
|
+
protected abstract usage(cards?: Card[]): Promise<string[]>;
|
|
49
|
+
protected abstract validate(content?: object): Promise<void>;
|
|
50
|
+
protected abstract write(): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Base class for all resources.
|
|
54
|
+
*/
|
|
55
|
+
export declare class ResourceObject extends AbstractResource {
|
|
56
|
+
protected project: Project;
|
|
57
|
+
protected resourceName: ResourceName;
|
|
58
|
+
protected moduleResource: boolean;
|
|
59
|
+
protected contentSchema: JSON;
|
|
60
|
+
protected contentSchemaId: string;
|
|
61
|
+
protected type: ResourceFolderType;
|
|
62
|
+
protected resourceFolder: string;
|
|
63
|
+
constructor(project: Project, resourceName: ResourceName);
|
|
64
|
+
protected calculate(): Promise<void>;
|
|
65
|
+
protected create(_content?: ResourceContent): Promise<void>;
|
|
66
|
+
protected delete(): Promise<void>;
|
|
67
|
+
protected read(): Promise<void>;
|
|
68
|
+
protected rename(_name: ResourceName): Promise<void>;
|
|
69
|
+
protected show(): Promise<ResourceContent>;
|
|
70
|
+
protected update<Type>(_key: string, _op: Operation<Type>): Promise<void>;
|
|
71
|
+
protected usage(_cards?: Card[]): Promise<string[]>;
|
|
72
|
+
protected validate(_content?: object): Promise<void>;
|
|
73
|
+
protected write(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Returns .schema content file.
|
|
76
|
+
* @param schemaId schema id
|
|
77
|
+
* @returns .schema content.
|
|
78
|
+
*/
|
|
79
|
+
protected contentSchemaContent(schemaId: string): JSON;
|
|
80
|
+
/**
|
|
81
|
+
* Handles operation to an array.
|
|
82
|
+
* @param operation Operation to perform on array.
|
|
83
|
+
* @param arrayName Name of the array, for error messages.
|
|
84
|
+
* @param array Array to be updated.
|
|
85
|
+
* @returns Changed array after the operation.
|
|
86
|
+
*/
|
|
87
|
+
protected handleArray<Type>(operation: Operation<Type>, arrayName: string, array: Type[]): Type[];
|
|
88
|
+
/**
|
|
89
|
+
* Updates scalar value. The only accepted operation is 'change'
|
|
90
|
+
* @param operation Operation to perform on scalar.
|
|
91
|
+
* @returns What the scalar should be changed to.
|
|
92
|
+
*/
|
|
93
|
+
protected handleScalar<Type>(operation: Operation<Type>): Type;
|
|
94
|
+
/**
|
|
95
|
+
* Update calculation files.
|
|
96
|
+
* @param from Resource name to update
|
|
97
|
+
* @param to New name for resource
|
|
98
|
+
*/
|
|
99
|
+
protected updateCalculations(from: string, to: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Update references in handlebars.
|
|
102
|
+
* @param from Resource name to update
|
|
103
|
+
* @param to New name for resource
|
|
104
|
+
* @param handleBarFiles Optional. List of handlebar files. If omitted, affects all handlebar files in the project.
|
|
105
|
+
*/
|
|
106
|
+
protected updateHandleBars(from: string, to: string, handleBarFiles?: string[]): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
13
|
+
// node
|
|
14
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { basename, join } from 'node:path';
|
|
16
|
+
import { ArrayHandler } from './array-handler.js';
|
|
17
|
+
import { ResourcesFrom } from '../containers/project.js';
|
|
18
|
+
/**
|
|
19
|
+
* Abstract class for resources.
|
|
20
|
+
*/
|
|
21
|
+
export class AbstractResource {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Base class for all resources.
|
|
25
|
+
*/
|
|
26
|
+
export class ResourceObject extends AbstractResource {
|
|
27
|
+
project;
|
|
28
|
+
resourceName;
|
|
29
|
+
moduleResource;
|
|
30
|
+
contentSchema = {};
|
|
31
|
+
contentSchemaId = '';
|
|
32
|
+
type = '';
|
|
33
|
+
resourceFolder = '';
|
|
34
|
+
constructor(project, resourceName) {
|
|
35
|
+
super();
|
|
36
|
+
this.project = project;
|
|
37
|
+
this.resourceName = resourceName;
|
|
38
|
+
this.moduleResource =
|
|
39
|
+
this.resourceName.prefix !== this.project.projectPrefix;
|
|
40
|
+
}
|
|
41
|
+
async calculate() { }
|
|
42
|
+
async create(_content) { }
|
|
43
|
+
async delete() { }
|
|
44
|
+
async read() { }
|
|
45
|
+
async rename(_name) { }
|
|
46
|
+
async show() {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
async update(_key, _op) { }
|
|
50
|
+
async usage(_cards) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
async validate(_content) { }
|
|
54
|
+
async write() { }
|
|
55
|
+
/**
|
|
56
|
+
* Returns .schema content file.
|
|
57
|
+
* @param schemaId schema id
|
|
58
|
+
* @returns .schema content.
|
|
59
|
+
*/
|
|
60
|
+
contentSchemaContent(schemaId) {
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
id: schemaId,
|
|
64
|
+
version: 1,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handles operation to an array.
|
|
70
|
+
* @param operation Operation to perform on array.
|
|
71
|
+
* @param arrayName Name of the array, for error messages.
|
|
72
|
+
* @param array Array to be updated.
|
|
73
|
+
* @returns Changed array after the operation.
|
|
74
|
+
*/
|
|
75
|
+
handleArray(operation, arrayName, array) {
|
|
76
|
+
const handler = new ArrayHandler();
|
|
77
|
+
let result = [];
|
|
78
|
+
try {
|
|
79
|
+
result = handler.handleArray(operation, array);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (error instanceof Error) {
|
|
83
|
+
throw new Error(`Cannot perform operation on '${arrayName}'. ${error.message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Updates scalar value. The only accepted operation is 'change'
|
|
90
|
+
* @param operation Operation to perform on scalar.
|
|
91
|
+
* @returns What the scalar should be changed to.
|
|
92
|
+
*/
|
|
93
|
+
handleScalar(operation) {
|
|
94
|
+
if (operation.name === 'add' ||
|
|
95
|
+
operation.name === 'rank' ||
|
|
96
|
+
operation.name === 'remove') {
|
|
97
|
+
throw new Error(`Cannot do operation ${operation.name} on scalar value`);
|
|
98
|
+
}
|
|
99
|
+
return operation.to;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Update calculation files.
|
|
103
|
+
* @param from Resource name to update
|
|
104
|
+
* @param to New name for resource
|
|
105
|
+
*/
|
|
106
|
+
async updateCalculations(from, to) {
|
|
107
|
+
if (!from.trim() || !to.trim()) {
|
|
108
|
+
throw new Error('updateCalculations: "from" and "to" parameters must not be empty');
|
|
109
|
+
}
|
|
110
|
+
const calculations = await this.project.calculations(ResourcesFrom.localOnly);
|
|
111
|
+
await Promise.all(calculations.map(async (calculation) => {
|
|
112
|
+
if (!calculation.path) {
|
|
113
|
+
throw new Error(`Calculation file's '${calculation.name}' path is not defined`);
|
|
114
|
+
}
|
|
115
|
+
const filename = join(calculation.path, basename(calculation.name));
|
|
116
|
+
try {
|
|
117
|
+
const content = await readFile(filename, 'utf-8');
|
|
118
|
+
const updatedContent = content.replaceAll(from, to);
|
|
119
|
+
await writeFile(filename, updatedContent);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
throw new Error(`Failed to process file ${filename}: ${error.message}`);
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Update references in handlebars.
|
|
128
|
+
* @param from Resource name to update
|
|
129
|
+
* @param to New name for resource
|
|
130
|
+
* @param handleBarFiles Optional. List of handlebar files. If omitted, affects all handlebar files in the project.
|
|
131
|
+
*/
|
|
132
|
+
async updateHandleBars(from, to, handleBarFiles) {
|
|
133
|
+
if (!from.trim() || !to.trim()) {
|
|
134
|
+
throw new Error('updateHandleBars: "from" and "to" parameters must not be empty');
|
|
135
|
+
}
|
|
136
|
+
if (!handleBarFiles) {
|
|
137
|
+
handleBarFiles = await this.project.reportHandlerBarFiles(ResourcesFrom.localOnly);
|
|
138
|
+
}
|
|
139
|
+
// Process all files in parallel.
|
|
140
|
+
await Promise.all(handleBarFiles.map(async (handleBarFile) => {
|
|
141
|
+
const content = await readFile(handleBarFile);
|
|
142
|
+
const updatedContent = content.toString().replaceAll(from, to);
|
|
143
|
+
await writeFile(handleBarFile, Buffer.from(updatedContent));
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=resource-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-object.js","sourceRoot":"","sources":["../../src/resources/resource-object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,sDAAsD;AAEtD,OAAO;AACP,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,OAAO,EAAgB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AA2CvE;;GAEG;AACH,MAAM,OAAgB,gBAAgB;CAcrC;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,gBAAgB;IAQtC;IACA;IARF,cAAc,CAAU;IACxB,aAAa,GAAS,EAAU,CAAC;IACjC,eAAe,GAAW,EAAE,CAAC;IAC7B,IAAI,GAAuB,EAAwB,CAAC;IACpD,cAAc,GAAW,EAAE,CAAC;IAEtC,YACY,OAAgB,EAChB,YAA0B;QAEpC,KAAK,EAAE,CAAC;QAHE,YAAO,GAAP,OAAO,CAAS;QAChB,iBAAY,GAAZ,YAAY,CAAc;QAGpC,IAAI,CAAC,cAAc;YACjB,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;IAC5D,CAAC;IAES,KAAK,CAAC,SAAS,KAAI,CAAC;IACpB,KAAK,CAAC,MAAM,CAAC,QAA0B,IAAG,CAAC;IAC3C,KAAK,CAAC,MAAM,KAAI,CAAC;IACjB,KAAK,CAAC,IAAI,KAAI,CAAC;IACf,KAAK,CAAC,MAAM,CAAC,KAAmB,IAAG,CAAC;IACpC,KAAK,CAAC,IAAI;QAClB,OA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I,CAAC,cAAc,EAAE,CAAC;YACpB,cAAc,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,qBAAqB,CACvD,aAAa,CAAC,SAAS,CACxB,CAAC;QACJ,CAAC;QAED,iCAAiC;QACjC,MAAM,OAAO,CAAC,GAAG,CACf,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;YACzC,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC9C,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC/D,MAAM,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;QAC9D,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
|
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
|
+
import type { Card, Operation, Project, ResourceName } from './folder-resource.js';
|
|
15
|
+
import { FolderResource } from './folder-resource.js';
|
|
16
|
+
import type { TemplateConfiguration, TemplateMetadata } from '../interfaces/resource-interfaces.js';
|
|
17
|
+
import { Template } from '../containers/template.js';
|
|
18
|
+
/**
|
|
19
|
+
* Template resource class.
|
|
20
|
+
*/
|
|
21
|
+
export declare class TemplateResource extends FolderResource {
|
|
22
|
+
private cardContainer;
|
|
23
|
+
private cardsFolder;
|
|
24
|
+
private cardsSchema;
|
|
25
|
+
constructor(project: Project, name: ResourceName);
|
|
26
|
+
private handleNameChange;
|
|
27
|
+
/**
|
|
28
|
+
* Sets new metadata into the template object.
|
|
29
|
+
* @param newContent metadata content for the template.
|
|
30
|
+
* @throws if 'newContent' is not valid.
|
|
31
|
+
*/
|
|
32
|
+
create(newContent?: TemplateMetadata): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns content data.
|
|
35
|
+
*/
|
|
36
|
+
get data(): TemplateMetadata;
|
|
37
|
+
/**
|
|
38
|
+
* Deletes file and folder that this resource is based on.
|
|
39
|
+
*/
|
|
40
|
+
delete(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Renames the object and the file.
|
|
43
|
+
* @param newName New name for the resource.
|
|
44
|
+
*/
|
|
45
|
+
rename(newName: ResourceName): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Shows metadata of the resource.
|
|
48
|
+
* @returns template metadata.
|
|
49
|
+
*/
|
|
50
|
+
show(): Promise<TemplateConfiguration>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns template card container object.
|
|
53
|
+
* @returns template container object
|
|
54
|
+
*/
|
|
55
|
+
templateObject(): Template;
|
|
56
|
+
/**
|
|
57
|
+
* Updates template resource.
|
|
58
|
+
* @param key Key to modify
|
|
59
|
+
* @param op Operation to perform on 'key'
|
|
60
|
+
* @throws if key is unknown.
|
|
61
|
+
*/
|
|
62
|
+
update<Type>(key: string, op: Operation<Type>): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* List where template is used.
|
|
65
|
+
* Always returns card key references first, then calculation references.
|
|
66
|
+
*
|
|
67
|
+
* @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
|
|
68
|
+
* @returns array of card keys, and calculation filenames that refer this resource.
|
|
69
|
+
*/
|
|
70
|
+
usage(cards?: Card[]): Promise<string[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Validates template.
|
|
73
|
+
* @throws when there are validation errors.
|
|
74
|
+
* @param content Content to be validated.
|
|
75
|
+
* @note If content is not provided, base class validation will use resource's current content.
|
|
76
|
+
*/
|
|
77
|
+
validate(content?: object): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Create the template's cards folder.
|
|
80
|
+
*/
|
|
81
|
+
write(): Promise<void>;
|
|
82
|
+
}
|