@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
|
@@ -13,76 +13,40 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { basename, dirname, join, normalize } from 'node:path';
|
|
15
15
|
import { mkdir, readdir, readFile, rename, rm } from 'node:fs/promises';
|
|
16
|
-
import {
|
|
17
|
-
import { filename,
|
|
18
|
-
import {
|
|
16
|
+
import { isContentKey } from '../interfaces/resource-interfaces.js';
|
|
17
|
+
import { filename, contentPropertyName, } from '../interfaces/folder-content-interfaces.js';
|
|
18
|
+
import { formatJson } from '../utils/json.js';
|
|
19
19
|
import { VALID_FOLDER_RESOURCE_FILES } from '../utils/constants.js';
|
|
20
20
|
import { writeFileSafe } from '../utils/file-utils.js';
|
|
21
|
-
|
|
21
|
+
import { ResourceObject } from './resource-object.js';
|
|
22
|
+
import { resourceName } from '../utils/resource-utils.js';
|
|
22
23
|
/**
|
|
23
|
-
* Folder type resource class.
|
|
24
|
+
* Folder type resource class.
|
|
25
|
+
* These are resources that have their own folders for content.
|
|
24
26
|
*/
|
|
25
|
-
export class FolderResource extends
|
|
27
|
+
export class FolderResource extends ResourceObject {
|
|
26
28
|
internalFolder = '';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
resourceContent = {};
|
|
30
|
+
/**
|
|
31
|
+
* Constructs a FolderResource object.
|
|
32
|
+
* @param project Project in which this resource exists.
|
|
33
|
+
* @param name Name for the resource.
|
|
34
|
+
* @param type Type for this resource.
|
|
35
|
+
*/
|
|
29
36
|
constructor(project, name, type) {
|
|
30
37
|
super(project, name, type);
|
|
31
|
-
|
|
32
|
-
// Clears the content files cache.
|
|
33
|
-
clearContentCache() {
|
|
34
|
-
this.contentFilesCache.clear();
|
|
35
|
-
}
|
|
36
|
-
// Type guard to check if a key is a ContentUpdateKey
|
|
37
|
-
isContentUpdateKey(key) {
|
|
38
|
-
return typeof key === 'object' && key.key === 'content' && 'subKey' in key;
|
|
38
|
+
this.initialize();
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Creates a new folder type object. Base class writes the object to disk automatically.
|
|
42
42
|
* @param newContent Content for the type.
|
|
43
43
|
*/
|
|
44
44
|
async create(newContent) {
|
|
45
|
+
// Validate resource identifier before creating on disk
|
|
46
|
+
this.validateResourceIdentifier();
|
|
45
47
|
await super.create(newContent);
|
|
46
48
|
await mkdir(this.internalFolder, { recursive: true });
|
|
47
49
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Gets content of all files to properties.
|
|
50
|
-
* @returns object with property names as keys and file contents as values.
|
|
51
|
-
*/
|
|
52
|
-
async contentData() {
|
|
53
|
-
const fileNames = await this.showFileNames();
|
|
54
|
-
const content = {};
|
|
55
|
-
for (const fileName of fileNames) {
|
|
56
|
-
const name = propertyName(fileName);
|
|
57
|
-
if (name) {
|
|
58
|
-
const JSONFile = name === 'schema';
|
|
59
|
-
content[name] = await this.showFile(fileName, JSONFile);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return content;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Returns content data.
|
|
66
|
-
*/
|
|
67
|
-
get data() {
|
|
68
|
-
return super.data;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Deletes file(s) from disk and clears out the memory resident object.
|
|
72
|
-
*/
|
|
73
|
-
async delete() {
|
|
74
|
-
await super.delete();
|
|
75
|
-
await rm(this.internalFolder, { recursive: true, force: true });
|
|
76
|
-
this.clearContentCache();
|
|
77
|
-
}
|
|
78
|
-
// Get (resource folder) type name
|
|
79
|
-
get getType() {
|
|
80
|
-
return super.getType;
|
|
81
|
-
}
|
|
82
|
-
// Get logger instance
|
|
83
|
-
get logger() {
|
|
84
|
-
return super.getLogger(this.getType);
|
|
85
|
-
}
|
|
86
50
|
/**
|
|
87
51
|
* Initialize the resource item.
|
|
88
52
|
*/
|
|
@@ -91,69 +55,33 @@ export class FolderResource extends FileResource {
|
|
|
91
55
|
this.internalFolder = join(this.resourceFolder, this.resourceName.identifier);
|
|
92
56
|
}
|
|
93
57
|
/**
|
|
94
|
-
*
|
|
95
|
-
* @param newName New name for the resource.
|
|
96
|
-
*/
|
|
97
|
-
async rename(newName) {
|
|
98
|
-
return super.rename(newName);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Shows metadata of the resource.
|
|
102
|
-
* @returns resource type's metadata.
|
|
103
|
-
*/
|
|
104
|
-
async show() {
|
|
105
|
-
return super.show();
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* TODO: to be made protected - no direct access to files
|
|
109
|
-
* Shows the content of a file in the resource.
|
|
110
|
-
* @param fileName Name of the file to show.
|
|
111
|
-
* @param json Content is JSON file.
|
|
112
|
-
* @returns the content of the file.
|
|
113
|
-
*/
|
|
114
|
-
async showFile(fileName, json = false) {
|
|
115
|
-
// Always first check cache...
|
|
116
|
-
if (this.contentFilesCache.has(fileName)) {
|
|
117
|
-
const cached = this.contentFilesCache.get(fileName);
|
|
118
|
-
return json ? JSON.parse(cached) : cached;
|
|
119
|
-
}
|
|
120
|
-
// ...cache miss, read from filesystem
|
|
121
|
-
const filePath = join(this.internalFolder, fileName);
|
|
122
|
-
const content = json
|
|
123
|
-
? await readJsonFile(filePath)
|
|
124
|
-
: await readFile(filePath, 'utf8');
|
|
125
|
-
// Update cache
|
|
126
|
-
const contentStr = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
|
|
127
|
-
this.contentFilesCache.set(fileName, contentStr);
|
|
128
|
-
return json ? content : contentStr;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* TODO: to be made protected - no direct access to files
|
|
132
|
-
* Shows all file names in the resource.
|
|
133
|
-
* @returns all file names in the resource.
|
|
58
|
+
* Set content files. Should not be called by others than resource cache.
|
|
134
59
|
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// Update cache by reading all files. Each method call updates specific cache item.
|
|
144
|
-
for (const fileName of validFiles) {
|
|
145
|
-
await this.showFile(fileName);
|
|
60
|
+
setContentFiles(contentFiles) {
|
|
61
|
+
const content = {};
|
|
62
|
+
for (const [fileName, fileContent] of contentFiles.entries()) {
|
|
63
|
+
const key = contentPropertyName(fileName);
|
|
64
|
+
if (key) {
|
|
65
|
+
const isJson = key === 'schema';
|
|
66
|
+
content[key] = isJson ? JSON.parse(fileContent) : fileContent;
|
|
67
|
+
}
|
|
146
68
|
}
|
|
147
|
-
|
|
69
|
+
this.resourceContent = content;
|
|
148
70
|
}
|
|
149
71
|
/**
|
|
150
|
-
*
|
|
151
|
-
* @param contentFiles Object with file names as keys and file contents as values.
|
|
72
|
+
* Load all content files from the internal folder and set them.
|
|
152
73
|
*/
|
|
153
|
-
async
|
|
154
|
-
|
|
155
|
-
|
|
74
|
+
async loadContentFiles() {
|
|
75
|
+
const contentFiles = new Map();
|
|
76
|
+
const files = await readdir(this.internalFolder, { withFileTypes: true });
|
|
77
|
+
for (const file of files) {
|
|
78
|
+
if (file.isFile() && VALID_FOLDER_RESOURCE_FILES.includes(file.name)) {
|
|
79
|
+
const filePath = join(this.internalFolder, file.name);
|
|
80
|
+
const content = await readFile(filePath, 'utf-8');
|
|
81
|
+
contentFiles.set(file.name, content);
|
|
82
|
+
}
|
|
156
83
|
}
|
|
84
|
+
this.setContentFiles(contentFiles);
|
|
157
85
|
}
|
|
158
86
|
/**
|
|
159
87
|
* Updates a file in the resource.
|
|
@@ -174,28 +102,81 @@ export class FolderResource extends FileResource {
|
|
|
174
102
|
}
|
|
175
103
|
// check if the file is allow-listed
|
|
176
104
|
if (!VALID_FOLDER_RESOURCE_FILES.includes(fileName)) {
|
|
177
|
-
throw new Error(`File '${fileName}' is not allowed`);
|
|
105
|
+
throw new Error(`File '${fileName}' is not allowed to be updated`);
|
|
178
106
|
}
|
|
179
107
|
await writeFileSafe(filePath, changedContent, { flag: 'w' });
|
|
180
|
-
// Update
|
|
181
|
-
|
|
108
|
+
// Update this resource's content
|
|
109
|
+
const key = contentPropertyName(fileName);
|
|
110
|
+
if (key) {
|
|
111
|
+
const isJson = key === 'schema';
|
|
112
|
+
this.resourceContent[key] = isJson
|
|
113
|
+
? JSON.parse(changedContent)
|
|
114
|
+
: changedContent;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Writes resource content to disk.
|
|
119
|
+
*/
|
|
120
|
+
async write() {
|
|
121
|
+
const folderName = basename(this.internalFolder);
|
|
122
|
+
// Check if "name" has changed. Changing "name" means renaming the file.
|
|
123
|
+
const nameInContent = resourceName(this.content.name).identifier;
|
|
124
|
+
if (folderName !== nameInContent) {
|
|
125
|
+
const newFolderName = join(this.resourceFolder, nameInContent);
|
|
126
|
+
await rename(this.internalFolder, newFolderName);
|
|
127
|
+
this.internalFolder = newFolderName;
|
|
128
|
+
}
|
|
129
|
+
return super.write();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets content of all files to properties.
|
|
133
|
+
* @returns object with property names as keys and file contents as values.
|
|
134
|
+
*/
|
|
135
|
+
contentData() {
|
|
136
|
+
// TODO: Instead of casting, validate that content matches U
|
|
137
|
+
// This requires a runtime schema for U to be defined(via an abstract variable)
|
|
138
|
+
return this.resourceContent;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Deletes file and content folder from disk and clears out the memory resident object.
|
|
142
|
+
*/
|
|
143
|
+
async delete() {
|
|
144
|
+
await super.delete();
|
|
145
|
+
await rm(this.internalFolder, { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Shows metadata of the resource and content of the resource.
|
|
149
|
+
* @template T Resource type
|
|
150
|
+
* @template U Resource content
|
|
151
|
+
* @returns resource type's metadata and content.
|
|
152
|
+
*/
|
|
153
|
+
show() {
|
|
154
|
+
this.assertResourceExists();
|
|
155
|
+
return {
|
|
156
|
+
...this.content,
|
|
157
|
+
content: this.contentData(),
|
|
158
|
+
};
|
|
182
159
|
}
|
|
183
160
|
/**
|
|
184
161
|
* Updates resource.
|
|
185
|
-
* @param
|
|
162
|
+
* @param updateKey Key to modify
|
|
186
163
|
* @param op Operation to perform on 'key'
|
|
187
164
|
* @throws if key is unknown.
|
|
188
165
|
*/
|
|
189
|
-
async update(
|
|
190
|
-
|
|
191
|
-
|
|
166
|
+
async update(updateKey, op) {
|
|
167
|
+
const { key } = updateKey;
|
|
168
|
+
if (isContentKey(updateKey)) {
|
|
169
|
+
const fileName = filename(updateKey.subKey);
|
|
192
170
|
const fileContent = super.handleScalar(op);
|
|
193
|
-
|
|
171
|
+
const fileContentString = typeof fileContent === 'string'
|
|
172
|
+
? fileContent
|
|
173
|
+
: formatJson(fileContent); // TODO: Fix operation types. In practice, content files are either strings or objects
|
|
174
|
+
await this.updateFile(fileName, fileContentString);
|
|
194
175
|
return;
|
|
195
176
|
}
|
|
196
177
|
const nameChange = key === 'name';
|
|
197
178
|
const existingName = this.content.name;
|
|
198
|
-
await super.update(
|
|
179
|
+
await super.update(updateKey, op);
|
|
199
180
|
const content = structuredClone(this.content);
|
|
200
181
|
if (key === 'name') {
|
|
201
182
|
content.name = super.handleScalar(op);
|
|
@@ -209,38 +190,10 @@ export class FolderResource extends FileResource {
|
|
|
209
190
|
else {
|
|
210
191
|
throw new Error(`Unknown property '${key}' for folder resource`);
|
|
211
192
|
}
|
|
212
|
-
await super.postUpdate(content,
|
|
193
|
+
await super.postUpdate(content, updateKey, op);
|
|
213
194
|
if (nameChange) {
|
|
214
195
|
await this.onNameChange?.(existingName);
|
|
215
196
|
}
|
|
216
197
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Returns an array of card keys, and/or resource names where this resource is used.
|
|
219
|
-
* @param cards Optional. If defined, only these cards are checked.
|
|
220
|
-
* @returns an array of card keys, and/or resource names where this resource is used.
|
|
221
|
-
*/
|
|
222
|
-
async usage(cards) {
|
|
223
|
-
return super.usage(cards);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Writes resource content to disk.
|
|
227
|
-
*/
|
|
228
|
-
async write() {
|
|
229
|
-
const folderName = basename(this.internalFolder);
|
|
230
|
-
// Check if "name" has changed. Changing "name" means renaming the file.
|
|
231
|
-
const nameInContent = resourceName(this.content.name).identifier;
|
|
232
|
-
if (folderName !== nameInContent) {
|
|
233
|
-
const newFolderName = join(this.resourceFolder, nameInContent);
|
|
234
|
-
await rename(this.internalFolder, newFolderName);
|
|
235
|
-
this.internalFolder = newFolderName;
|
|
236
|
-
}
|
|
237
|
-
return super.write();
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Validates the resource. If object is invalid, throws.
|
|
241
|
-
*/
|
|
242
|
-
async validate(content) {
|
|
243
|
-
return super.validate(content);
|
|
244
|
-
}
|
|
245
198
|
}
|
|
246
199
|
//# sourceMappingURL=folder-resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"folder-resource.js","sourceRoot":"","sources":["../../src/resources/folder-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"folder-resource.js","sourceRoot":"","sources":["../../src/resources/folder-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO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AAqB,CAAC,CAAC,CAAC,sFAAsF;YAE/H,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;YACnD,OAAO;QACT,CAAC;QAED,MAAM,UAAU,GAAG,GAAG,KAAK,MAAM,CAAC;QAClC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QACvC,MAAM,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAClC,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE9C,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,EAAE,CAAW,CAAC;QAClD,CAAC;aAAM,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;YACjC,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,EAAE,CAAW,CAAC;QACzD,CAAC;aAAM,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;YACjC,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,EAAE,CAAW,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,uBAAuB,CAAC,CAAC;QACnE,CAAC;QAED,MAAM,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QAE/C,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC,YAAY,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -11,13 +11,17 @@
|
|
|
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 type { Card, Operation, Project, ResourceName } from './folder-resource.js';
|
|
15
14
|
import { FolderResource } from './folder-resource.js';
|
|
16
|
-
import type {
|
|
15
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
16
|
+
import type { GraphModelMetadata, UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
17
|
+
import type { GraphModelContent } from '../interfaces/folder-content-interfaces.js';
|
|
18
|
+
import type { Operation } from './resource-object.js';
|
|
19
|
+
import type { Project } from '../containers/project.js';
|
|
20
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
17
21
|
/**
|
|
18
22
|
* Graph model resource class.
|
|
19
23
|
*/
|
|
20
|
-
export declare class GraphModelResource extends FolderResource {
|
|
24
|
+
export declare class GraphModelResource extends FolderResource<GraphModelMetadata, GraphModelContent> {
|
|
21
25
|
constructor(project: Project, name: ResourceName);
|
|
22
26
|
/**
|
|
23
27
|
* Handle name changes for graph models
|
|
@@ -30,35 +34,17 @@ export declare class GraphModelResource extends FolderResource {
|
|
|
30
34
|
* @throws if 'newContent' is not valid.
|
|
31
35
|
*/
|
|
32
36
|
create(newContent?: GraphModelMetadata): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Returns resource content.
|
|
35
|
-
*/
|
|
36
|
-
get data(): GraphModel;
|
|
37
|
-
/**
|
|
38
|
-
* Deletes file and folder that this resource is based on.
|
|
39
|
-
*/
|
|
40
|
-
delete(): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Returns calculation file that this graph model has.
|
|
43
|
-
* @returns calculation file name that this graph model has.
|
|
44
|
-
*/
|
|
45
|
-
calculationFile(nameOnly?: boolean): Promise<string>;
|
|
46
37
|
/**
|
|
47
38
|
* Renames the object and the file.
|
|
48
39
|
* @param newName New name for the resource.
|
|
49
40
|
*/
|
|
50
41
|
rename(newName: ResourceName): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Shows metadata of the resource.
|
|
53
|
-
* @returns graph model metadata.
|
|
54
|
-
*/
|
|
55
|
-
show(): Promise<GraphModel>;
|
|
56
42
|
/**
|
|
57
43
|
* Updates graph model resource.
|
|
58
|
-
* @param
|
|
44
|
+
* @param updateKey Key to modify
|
|
59
45
|
* @param op Operation to perform on 'key'
|
|
60
46
|
*/
|
|
61
|
-
update<Type>(
|
|
47
|
+
update<Type, K extends string>(updateKey: UpdateKey<K>, op: Operation<Type>): Promise<void>;
|
|
62
48
|
/**
|
|
63
49
|
* List where this resource is used.
|
|
64
50
|
* Always returns card key references first, then calculation references.
|
|
@@ -67,15 +53,4 @@ export declare class GraphModelResource extends FolderResource {
|
|
|
67
53
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
68
54
|
*/
|
|
69
55
|
usage(cards?: Card[]): Promise<string[]>;
|
|
70
|
-
/**
|
|
71
|
-
* Validates graphModel.
|
|
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
|
-
/**
|
|
78
|
-
* Create the graph model's folder and calculation file.
|
|
79
|
-
*/
|
|
80
|
-
write(): Promise<void>;
|
|
81
56
|
}
|
|
@@ -11,10 +11,13 @@
|
|
|
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 {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { DefaultContent } from './create-defaults.js';
|
|
16
|
+
import { FolderResource } from './folder-resource.js';
|
|
17
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
18
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
17
19
|
import { writeFileSafe } from '../utils/file-utils.js';
|
|
20
|
+
import { CONTENT_FILES } from '../interfaces/folder-content-interfaces.js';
|
|
18
21
|
/**
|
|
19
22
|
* Graph model resource class.
|
|
20
23
|
*/
|
|
@@ -23,7 +26,6 @@ export class GraphModelResource extends FolderResource {
|
|
|
23
26
|
super(project, name, 'graphModels');
|
|
24
27
|
this.contentSchemaId = 'graphModelSchema';
|
|
25
28
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
26
|
-
this.initialize();
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Handle name changes for graph models
|
|
@@ -32,7 +34,7 @@ export class GraphModelResource extends FolderResource {
|
|
|
32
34
|
async onNameChange(existingName) {
|
|
33
35
|
await Promise.all([
|
|
34
36
|
super.updateHandleBars(existingName, this.content.name, [
|
|
35
|
-
|
|
37
|
+
join(this.internalFolder, CONTENT_FILES.model),
|
|
36
38
|
]),
|
|
37
39
|
super.updateCalculations(existingName, this.content.name),
|
|
38
40
|
]);
|
|
@@ -53,35 +55,13 @@ export class GraphModelResource extends FolderResource {
|
|
|
53
55
|
}
|
|
54
56
|
await super.create(newContent);
|
|
55
57
|
// Create the internal folder in 'create', instead of 'write'.
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
+
const modelContent = `% add your calculations here for '${this.resourceName.identifier}'`;
|
|
59
|
+
const modelFile = CONTENT_FILES.model;
|
|
60
|
+
const calculationsFile = join(this.internalFolder, modelFile);
|
|
61
|
+
await writeFileSafe(calculationsFile, modelContent, {
|
|
58
62
|
flag: 'wx',
|
|
59
63
|
});
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Returns resource content.
|
|
63
|
-
*/
|
|
64
|
-
get data() {
|
|
65
|
-
return super.data;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Deletes file and folder that this resource is based on.
|
|
69
|
-
*/
|
|
70
|
-
async delete() {
|
|
71
|
-
return super.delete();
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Returns calculation file that this graph model has.
|
|
75
|
-
* @returns calculation file name that this graph model has.
|
|
76
|
-
*/
|
|
77
|
-
async calculationFile(nameOnly = false) {
|
|
78
|
-
return (await readdir(this.internalFolder, {
|
|
79
|
-
withFileTypes: true,
|
|
80
|
-
recursive: true,
|
|
81
|
-
}))
|
|
82
|
-
.filter((dirent) => dirent.isFile() && extname(dirent.name) === '.lp')
|
|
83
|
-
.map((item) => (nameOnly ? item.name : join(item.parentPath, item.name)))
|
|
84
|
-
.at(0);
|
|
64
|
+
await this.loadContentFiles();
|
|
85
65
|
}
|
|
86
66
|
/**
|
|
87
67
|
* Renames the object and the file.
|
|
@@ -92,30 +72,19 @@ export class GraphModelResource extends FolderResource {
|
|
|
92
72
|
await super.rename(newName);
|
|
93
73
|
return this.onNameChange(existingName);
|
|
94
74
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Shows metadata of the resource.
|
|
97
|
-
* @returns graph model metadata.
|
|
98
|
-
*/
|
|
99
|
-
async show() {
|
|
100
|
-
const baseData = (await super.show());
|
|
101
|
-
return {
|
|
102
|
-
...baseData,
|
|
103
|
-
content: (await super.contentData()),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
75
|
/**
|
|
107
76
|
* Updates graph model resource.
|
|
108
|
-
* @param
|
|
77
|
+
* @param updateKey Key to modify
|
|
109
78
|
* @param op Operation to perform on 'key'
|
|
110
79
|
*/
|
|
111
|
-
async update(
|
|
112
|
-
if (key === 'category') {
|
|
80
|
+
async update(updateKey, op) {
|
|
81
|
+
if (updateKey.key === 'category') {
|
|
113
82
|
const content = structuredClone(this.content);
|
|
114
83
|
content.category = super.handleScalar(op);
|
|
115
|
-
await super.postUpdate(content,
|
|
84
|
+
await super.postUpdate(content, updateKey, op);
|
|
116
85
|
return;
|
|
117
86
|
}
|
|
118
|
-
await super.update(
|
|
87
|
+
await super.update(updateKey, op);
|
|
119
88
|
}
|
|
120
89
|
/**
|
|
121
90
|
* List where this resource is used.
|
|
@@ -125,27 +94,12 @@ export class GraphModelResource extends FolderResource {
|
|
|
125
94
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
126
95
|
*/
|
|
127
96
|
async usage(cards) {
|
|
128
|
-
const allCards = cards ??
|
|
97
|
+
const allCards = cards ?? super.cards();
|
|
129
98
|
const [relevantCards, calculations] = await Promise.all([
|
|
130
99
|
super.usage(allCards),
|
|
131
100
|
super.calculations(),
|
|
132
101
|
]);
|
|
133
102
|
return [...relevantCards.sort(sortCards), ...calculations];
|
|
134
103
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Validates graphModel.
|
|
137
|
-
* @throws when there are validation errors.
|
|
138
|
-
* @param content Content to be validated.
|
|
139
|
-
* @note If content is not provided, base class validation will use resource's current content.
|
|
140
|
-
*/
|
|
141
|
-
async validate(content) {
|
|
142
|
-
return super.validate(content);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Create the graph model's folder and calculation file.
|
|
146
|
-
*/
|
|
147
|
-
async write() {
|
|
148
|
-
await super.write();
|
|
149
|
-
}
|
|
150
104
|
}
|
|
151
105
|
//# sourceMappingURL=graph-model-resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-model-resource.js","sourceRoot":"","sources":["../../src/resources/graph-model-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"graph-model-resource.js","sourceRoot":"","sources":["../../src/resources/graph-model-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAY3E;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,cAGvC;IACC,YAAY,OAAgB,EAAE,IAAkB;QAC9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AI;SACX,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAChC,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,MAAM,CAAC,OAAqB;QACvC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QACvC,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CACjB,SAAuB,EACvB,EAAmB;QAEnB,IAAI,SAAS,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC9C,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,EAAE,CAAW,CAAC;YAEpD,MAAM,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;YAC/C,OAAO;QACT,CAAC;QAED,MAAM,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,KAAK,CAAC,KAAc;QAC/B,MAAM,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"}
|
|
@@ -11,13 +11,17 @@
|
|
|
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 type { Card, Operation, Project, ResourceName } from './folder-resource.js';
|
|
15
14
|
import { FolderResource } from './folder-resource.js';
|
|
16
|
-
import type {
|
|
15
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
16
|
+
import type { GraphViewContent } from '../interfaces/folder-content-interfaces.js';
|
|
17
|
+
import type { GraphViewMetadata, UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
18
|
+
import type { Operation } from './resource-object.js';
|
|
19
|
+
import type { Project } from '../containers/project.js';
|
|
20
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
17
21
|
/**
|
|
18
22
|
* Graph view resource class.
|
|
19
23
|
*/
|
|
20
|
-
export declare class GraphViewResource extends FolderResource {
|
|
24
|
+
export declare class GraphViewResource extends FolderResource<GraphViewMetadata, GraphViewContent> {
|
|
21
25
|
constructor(project: Project, name: ResourceName);
|
|
22
26
|
/**
|
|
23
27
|
* Handle name changes for graph views
|
|
@@ -30,14 +34,6 @@ export declare class GraphViewResource extends FolderResource {
|
|
|
30
34
|
* @throws if 'newContent' is not valid.
|
|
31
35
|
*/
|
|
32
36
|
create(newContent?: GraphViewMetadata): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Returns resource content.
|
|
35
|
-
*/
|
|
36
|
-
get data(): GraphView;
|
|
37
|
-
/**
|
|
38
|
-
* Deletes file and folder that this resource is based on.
|
|
39
|
-
*/
|
|
40
|
-
delete(): Promise<void>;
|
|
41
37
|
/**
|
|
42
38
|
* Returns handlebar filename that this graph view has.
|
|
43
39
|
* @returns handlebar filename that this graph view has.
|
|
@@ -48,17 +44,12 @@ export declare class GraphViewResource extends FolderResource {
|
|
|
48
44
|
* @param newName New name for the resource.
|
|
49
45
|
*/
|
|
50
46
|
rename(newName: ResourceName): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Shows metadata of the resource.
|
|
53
|
-
* @returns graph view metadata.
|
|
54
|
-
*/
|
|
55
|
-
show(): Promise<GraphView>;
|
|
56
47
|
/**
|
|
57
48
|
* Updates graph view resource.
|
|
58
|
-
* @param
|
|
49
|
+
* @param updateKey Key to modify
|
|
59
50
|
* @param op Operation to perform on 'key'
|
|
60
51
|
*/
|
|
61
|
-
update<Type>(
|
|
52
|
+
update<Type, K extends string>(updateKey: UpdateKey<K>, op: Operation<Type>): Promise<void>;
|
|
62
53
|
/**
|
|
63
54
|
* List where this resource is used.
|
|
64
55
|
* Always returns card key references first, then calculation references.
|
|
@@ -67,15 +58,4 @@ export declare class GraphViewResource extends FolderResource {
|
|
|
67
58
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
68
59
|
*/
|
|
69
60
|
usage(cards?: Card[]): Promise<string[]>;
|
|
70
|
-
/**
|
|
71
|
-
* Validates graph view.
|
|
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
|
-
/**
|
|
78
|
-
* Create the graph view's folder and handlebar file.
|
|
79
|
-
*/
|
|
80
|
-
write(): Promise<void>;
|
|
81
61
|
}
|