@cyberismo/data-handler 0.0.13 → 0.0.15
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 +1 -3
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.js +13 -17
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +1 -1
- package/dist/command-manager.js +4 -3
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +3 -3
- package/dist/commands/create.js +20 -81
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/edit.d.ts +12 -25
- package/dist/commands/edit.js +25 -74
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/export.js +4 -17
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/fetch.js +2 -1
- package/dist/commands/fetch.js.map +1 -1
- package/dist/commands/import.js +3 -5
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.d.ts +1 -2
- package/dist/commands/move.js +108 -146
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.js +15 -49
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +1 -0
- package/dist/commands/rename.js +13 -7
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +7 -25
- package/dist/commands/show.js +39 -113
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.js +27 -30
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +5 -3
- package/dist/commands/update.js +19 -5
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +3 -3
- package/dist/commands/validate.js +20 -27
- 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 +6 -0
- package/dist/containers/project/calculation-engine.js +36 -29
- 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/resource-collector.d.ts +24 -1
- package/dist/containers/project/resource-collector.js +8 -1
- package/dist/containers/project/resource-collector.js.map +1 -1
- package/dist/containers/project.d.ts +119 -84
- package/dist/containers/project.js +423 -253
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +15 -31
- package/dist/containers/template.js +97 -104
- 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 +12 -5
- package/dist/interfaces/folder-content-interfaces.js +5 -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 +16 -10
- package/dist/interfaces/project-interfaces.js +10 -8
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +21 -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 +2 -2
- 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/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.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.js +4 -4
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/calculation-resource.d.ts +43 -0
- package/dist/resources/calculation-resource.js +75 -0
- package/dist/resources/calculation-resource.js.map +1 -0
- package/dist/resources/card-type-resource.d.ts +4 -21
- package/dist/resources/card-type-resource.js +13 -44
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.d.ts +13 -6
- package/dist/resources/create-defaults.js +19 -5
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +4 -21
- package/dist/resources/field-type-resource.js +14 -38
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +12 -29
- package/dist/resources/file-resource.js +19 -287
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +32 -51
- package/dist/resources/folder-resource.js +68 -96
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +5 -33
- package/dist/resources/graph-model-resource.js +8 -61
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +5 -28
- package/dist/resources/graph-view-resource.js +6 -45
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +4 -21
- package/dist/resources/link-type-resource.js +6 -31
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +5 -17
- package/dist/resources/report-resource.js +6 -44
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +58 -23
- package/dist/resources/resource-object.js +307 -26
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +4 -15
- package/dist/resources/template-resource.js +10 -25
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +4 -23
- package/dist/resources/workflow-resource.js +12 -38
- 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-facts.js +11 -3
- 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 +5 -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/error-utils.d.ts +34 -0
- package/dist/utils/error-utils.js +56 -0
- package/dist/utils/error-utils.js.map +1 -0
- package/dist/utils/log-utils.d.ts +0 -27
- package/dist/utils/log-utils.js +0 -58
- package/dist/utils/log-utils.js.map +1 -1
- package/dist/utils/user-preferences.js +6 -3
- package/dist/utils/user-preferences.js.map +1 -1
- package/package.json +5 -5
- package/src/card-metadata-updater.ts +3 -5
- package/src/command-handler.ts +14 -19
- package/src/command-manager.ts +4 -3
- package/src/commands/create.ts +28 -112
- package/src/commands/edit.ts +27 -118
- package/src/commands/export.ts +8 -29
- package/src/commands/fetch.ts +2 -1
- package/src/commands/import.ts +4 -6
- package/src/commands/move.ts +144 -179
- package/src/commands/remove.ts +12 -54
- package/src/commands/rename.ts +22 -7
- package/src/commands/show.ts +51 -156
- package/src/commands/transition.ts +30 -33
- package/src/commands/update.ts +27 -9
- package/src/commands/validate.ts +22 -37
- package/src/containers/card-container.ts +200 -360
- package/src/containers/project/calculation-engine.ts +43 -33
- package/src/containers/project/card-cache.ts +497 -0
- package/src/containers/project/resource-collector.ts +9 -1
- package/src/containers/project.ts +533 -328
- package/src/containers/template.ts +109 -127
- package/src/index.ts +1 -0
- package/src/interfaces/folder-content-interfaces.ts +23 -5
- package/src/interfaces/macros.ts +2 -0
- package/src/interfaces/project-interfaces.ts +19 -10
- package/src/interfaces/resource-interfaces.ts +22 -24
- package/src/macros/createCards/index.ts +1 -12
- package/src/macros/createCards/types.ts +46 -0
- package/src/macros/graph/index.ts +3 -7
- 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/percentage/index.ts +1 -7
- package/src/macros/percentage/types.ts +32 -0
- package/src/macros/report/index.ts +1 -4
- 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 +5 -5
- package/src/project-settings.ts +1 -1
- package/src/resources/calculation-resource.ts +101 -0
- package/src/resources/card-type-resource.ts +24 -59
- package/src/resources/create-defaults.ts +21 -5
- package/src/resources/field-type-resource.ts +22 -51
- package/src/resources/file-resource.ts +27 -403
- package/src/resources/folder-resource.ts +99 -125
- package/src/resources/graph-model-resource.ts +17 -74
- package/src/resources/graph-view-resource.ts +14 -54
- package/src/resources/link-type-resource.ts +13 -40
- package/src/resources/report-resource.ts +17 -57
- package/src/resources/resource-object.ts +454 -39
- package/src/resources/template-resource.ts +16 -29
- package/src/resources/workflow-resource.ts +26 -50
- package/src/utils/card-utils.ts +217 -31
- package/src/utils/clingo-facts.ts +13 -3
- package/src/utils/clingo-parser.ts +1 -1
- package/src/utils/constants.ts +7 -0
- package/src/utils/csv.ts +1 -1
- package/src/utils/error-utils.ts +62 -0
- package/src/utils/log-utils.ts +0 -68
- package/src/utils/user-preferences.ts +7 -3
|
@@ -13,30 +13,29 @@
|
|
|
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 { isContentKey, } from '../interfaces/resource-interfaces.js';
|
|
16
17
|
import { DefaultContent, FileResource, Project, resourceName, resourceNameToString, sortCards, } from './file-resource.js';
|
|
17
18
|
import { filename, propertyName, } from '../interfaces/folder-content-interfaces.js';
|
|
18
|
-
import { readJsonFile } from '../utils/json.js';
|
|
19
|
+
import { formatJson, readJsonFile } from '../utils/json.js';
|
|
19
20
|
import { VALID_FOLDER_RESOURCE_FILES } from '../utils/constants.js';
|
|
20
21
|
import { writeFileSafe } from '../utils/file-utils.js';
|
|
22
|
+
import { ResourceObject } from './resource-object.js';
|
|
21
23
|
export { DefaultContent, FileResource, Project, resourceNameToString, sortCards, };
|
|
22
24
|
/**
|
|
23
25
|
* Folder type resource class. 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
29
|
// Cache for content files to avoid repeated filesystem operations. Content is stored as string.
|
|
28
30
|
contentFilesCache = new Map();
|
|
29
31
|
constructor(project, name, type) {
|
|
30
32
|
super(project, name, type);
|
|
33
|
+
this.initialize();
|
|
31
34
|
}
|
|
32
35
|
// Clears the content files cache.
|
|
33
36
|
clearContentCache() {
|
|
34
37
|
this.contentFilesCache.clear();
|
|
35
38
|
}
|
|
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;
|
|
39
|
-
}
|
|
40
39
|
/**
|
|
41
40
|
* Creates a new folder type object. Base class writes the object to disk automatically.
|
|
42
41
|
* @param newContent Content for the type.
|
|
@@ -45,44 +44,6 @@ export class FolderResource extends FileResource {
|
|
|
45
44
|
await super.create(newContent);
|
|
46
45
|
await mkdir(this.internalFolder, { recursive: true });
|
|
47
46
|
}
|
|
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
47
|
/**
|
|
87
48
|
* Initialize the resource item.
|
|
88
49
|
*/
|
|
@@ -98,14 +59,6 @@ export class FolderResource extends FileResource {
|
|
|
98
59
|
return super.rename(newName);
|
|
99
60
|
}
|
|
100
61
|
/**
|
|
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
62
|
* Shows the content of a file in the resource.
|
|
110
63
|
* @param fileName Name of the file to show.
|
|
111
64
|
* @param json Content is JSON file.
|
|
@@ -123,12 +76,11 @@ export class FolderResource extends FileResource {
|
|
|
123
76
|
? await readJsonFile(filePath)
|
|
124
77
|
: await readFile(filePath, 'utf8');
|
|
125
78
|
// Update cache
|
|
126
|
-
const contentStr = typeof content === 'string' ? content :
|
|
79
|
+
const contentStr = typeof content === 'string' ? content : formatJson(content);
|
|
127
80
|
this.contentFilesCache.set(fileName, contentStr);
|
|
128
81
|
return json ? content : contentStr;
|
|
129
82
|
}
|
|
130
83
|
/**
|
|
131
|
-
* TODO: to be made protected - no direct access to files
|
|
132
84
|
* Shows all file names in the resource.
|
|
133
85
|
* @returns all file names in the resource.
|
|
134
86
|
*/
|
|
@@ -146,15 +98,6 @@ export class FolderResource extends FileResource {
|
|
|
146
98
|
}
|
|
147
99
|
return validFiles;
|
|
148
100
|
}
|
|
149
|
-
/**
|
|
150
|
-
* Updates content files from a content object.
|
|
151
|
-
* @param contentFiles Object with file names as keys and file contents as values.
|
|
152
|
-
*/
|
|
153
|
-
async updateContentFiles(contentFiles) {
|
|
154
|
-
for (const [fileName, fileContent] of Object.entries(contentFiles)) {
|
|
155
|
-
await this.updateFile(fileName, fileContent);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
101
|
/**
|
|
159
102
|
* Updates a file in the resource.
|
|
160
103
|
* @param fileName The name of the file to update.
|
|
@@ -174,28 +117,73 @@ export class FolderResource extends FileResource {
|
|
|
174
117
|
}
|
|
175
118
|
// check if the file is allow-listed
|
|
176
119
|
if (!VALID_FOLDER_RESOURCE_FILES.includes(fileName)) {
|
|
177
|
-
throw new Error(`File '${fileName}' is not allowed`);
|
|
120
|
+
throw new Error(`File '${fileName}' is not allowed to be updated`);
|
|
178
121
|
}
|
|
179
122
|
await writeFileSafe(filePath, changedContent, { flag: 'w' });
|
|
180
123
|
// Update cache with new content
|
|
181
124
|
this.contentFilesCache.set(fileName, changedContent);
|
|
182
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Writes resource content to disk.
|
|
128
|
+
*/
|
|
129
|
+
async write() {
|
|
130
|
+
const folderName = basename(this.internalFolder);
|
|
131
|
+
// Check if "name" has changed. Changing "name" means renaming the file.
|
|
132
|
+
const nameInContent = resourceName(this.content.name).identifier;
|
|
133
|
+
if (folderName !== nameInContent) {
|
|
134
|
+
const newFolderName = join(this.resourceFolder, nameInContent);
|
|
135
|
+
await rename(this.internalFolder, newFolderName);
|
|
136
|
+
this.internalFolder = newFolderName;
|
|
137
|
+
}
|
|
138
|
+
return super.write();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Gets content of all files to properties.
|
|
142
|
+
* @returns object with property names as keys and file contents as values.
|
|
143
|
+
*/
|
|
144
|
+
async contentData() {
|
|
145
|
+
const fileNames = await this.showFileNames();
|
|
146
|
+
const content = {};
|
|
147
|
+
for (const fileName of fileNames) {
|
|
148
|
+
const name = propertyName(fileName);
|
|
149
|
+
if (name) {
|
|
150
|
+
const JSONFile = name === 'schema';
|
|
151
|
+
content[name] = await this.showFile(fileName, JSONFile);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// TODO: Instead of casting, validate that content matches U
|
|
155
|
+
// This requires a runtime schema for U to be defined(via an abstract variable)
|
|
156
|
+
return content;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Deletes file and content folder from disk and clears out the memory resident object.
|
|
160
|
+
* @throws if resource is a module resource or does not exist or is used by other resources.
|
|
161
|
+
*/
|
|
162
|
+
async delete() {
|
|
163
|
+
await super.delete();
|
|
164
|
+
await rm(this.internalFolder, { recursive: true, force: true });
|
|
165
|
+
this.clearContentCache();
|
|
166
|
+
}
|
|
183
167
|
/**
|
|
184
168
|
* Updates resource.
|
|
185
|
-
* @param
|
|
169
|
+
* @param updateKey Key to modify
|
|
186
170
|
* @param op Operation to perform on 'key'
|
|
187
171
|
* @throws if key is unknown.
|
|
188
172
|
*/
|
|
189
|
-
async update(
|
|
190
|
-
|
|
191
|
-
|
|
173
|
+
async update(updateKey, op) {
|
|
174
|
+
const { key } = updateKey;
|
|
175
|
+
if (isContentKey(updateKey)) {
|
|
176
|
+
const fileName = filename(updateKey.subKey);
|
|
192
177
|
const fileContent = super.handleScalar(op);
|
|
193
|
-
|
|
178
|
+
const fileContentString = typeof fileContent === 'string'
|
|
179
|
+
? fileContent
|
|
180
|
+
: formatJson(fileContent); // TODO: Fix operation types. In practice, content files are either strings or objects
|
|
181
|
+
await this.updateFile(fileName, fileContentString);
|
|
194
182
|
return;
|
|
195
183
|
}
|
|
196
184
|
const nameChange = key === 'name';
|
|
197
185
|
const existingName = this.content.name;
|
|
198
|
-
await super.update(
|
|
186
|
+
await super.update(updateKey, op);
|
|
199
187
|
const content = structuredClone(this.content);
|
|
200
188
|
if (key === 'name') {
|
|
201
189
|
content.name = super.handleScalar(op);
|
|
@@ -209,38 +197,22 @@ export class FolderResource extends FileResource {
|
|
|
209
197
|
else {
|
|
210
198
|
throw new Error(`Unknown property '${key}' for folder resource`);
|
|
211
199
|
}
|
|
212
|
-
await super.postUpdate(content,
|
|
200
|
+
await super.postUpdate(content, updateKey, op);
|
|
213
201
|
if (nameChange) {
|
|
214
202
|
await this.onNameChange?.(existingName);
|
|
215
203
|
}
|
|
216
204
|
}
|
|
217
205
|
/**
|
|
218
|
-
*
|
|
219
|
-
* @
|
|
220
|
-
* @
|
|
221
|
-
*/
|
|
222
|
-
async usage(cards) {
|
|
223
|
-
return super.usage(cards);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Writes resource content to disk.
|
|
206
|
+
* Shows metadata of the resource and content of the resource.
|
|
207
|
+
* @returns resource type's metadata and content.
|
|
208
|
+
* @throws if resource does not exist.
|
|
227
209
|
*/
|
|
228
|
-
async
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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);
|
|
210
|
+
async show() {
|
|
211
|
+
this.assertResourceExists();
|
|
212
|
+
return {
|
|
213
|
+
...this.content,
|
|
214
|
+
content: await this.contentData(),
|
|
215
|
+
};
|
|
244
216
|
}
|
|
245
217
|
}
|
|
246
218
|
//# 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,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAIxE,OAAO,EACL,YAAY,GAEb,MAAM,sCAAsC,CAAC;AAG9C,OAAO,EACL,cAAc,EACd,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,oBAAoB,EACpB,SAAS,GACV,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,QAAQ,EACR,YAAY,GACb,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAEL,cAAc,EACd,YAAY,EAEZ,OAAO,EAEP,oBAAoB,EACpB,SAAS,GACV,CAAC;AAEF;;GAEG;AACH,MAAM,OAAg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WAAW,EAAE;SAClC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { Card, Operation, Project, ResourceName } from './folder-resource.js';
|
|
15
15
|
import { FolderResource } from './folder-resource.js';
|
|
16
|
-
import type {
|
|
16
|
+
import type { GraphModelMetadata, UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
17
|
+
import type { GraphModelContent } from '../interfaces/folder-content-interfaces.js';
|
|
17
18
|
/**
|
|
18
19
|
* Graph model resource class.
|
|
19
20
|
*/
|
|
20
|
-
export declare class GraphModelResource extends FolderResource {
|
|
21
|
+
export declare class GraphModelResource extends FolderResource<GraphModelMetadata, GraphModelContent> {
|
|
21
22
|
constructor(project: Project, name: ResourceName);
|
|
22
23
|
/**
|
|
23
24
|
* Handle name changes for graph models
|
|
@@ -30,35 +31,17 @@ export declare class GraphModelResource extends FolderResource {
|
|
|
30
31
|
* @throws if 'newContent' is not valid.
|
|
31
32
|
*/
|
|
32
33
|
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
34
|
/**
|
|
47
35
|
* Renames the object and the file.
|
|
48
36
|
* @param newName New name for the resource.
|
|
49
37
|
*/
|
|
50
38
|
rename(newName: ResourceName): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Shows metadata of the resource.
|
|
53
|
-
* @returns graph model metadata.
|
|
54
|
-
*/
|
|
55
|
-
show(): Promise<GraphModel>;
|
|
56
39
|
/**
|
|
57
40
|
* Updates graph model resource.
|
|
58
|
-
* @param
|
|
41
|
+
* @param updateKey Key to modify
|
|
59
42
|
* @param op Operation to perform on 'key'
|
|
60
43
|
*/
|
|
61
|
-
update<Type>(
|
|
44
|
+
update<Type, K extends string>(updateKey: UpdateKey<K>, op: Operation<Type>): Promise<void>;
|
|
62
45
|
/**
|
|
63
46
|
* List where this resource is used.
|
|
64
47
|
* Always returns card key references first, then calculation references.
|
|
@@ -67,15 +50,4 @@ export declare class GraphModelResource extends FolderResource {
|
|
|
67
50
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
68
51
|
*/
|
|
69
52
|
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
53
|
}
|
|
@@ -11,8 +11,7 @@
|
|
|
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 { extname, join } from 'node:path';
|
|
14
|
+
import { join } from 'node:path';
|
|
16
15
|
import { DefaultContent, FolderResource, resourceNameToString, sortCards, } from './folder-resource.js';
|
|
17
16
|
import { writeFileSafe } from '../utils/file-utils.js';
|
|
18
17
|
/**
|
|
@@ -23,7 +22,6 @@ export class GraphModelResource extends FolderResource {
|
|
|
23
22
|
super(project, name, 'graphModels');
|
|
24
23
|
this.contentSchemaId = 'graphModelSchema';
|
|
25
24
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
26
|
-
this.initialize();
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* Handle name changes for graph models
|
|
@@ -32,7 +30,7 @@ export class GraphModelResource extends FolderResource {
|
|
|
32
30
|
async onNameChange(existingName) {
|
|
33
31
|
await Promise.all([
|
|
34
32
|
super.updateHandleBars(existingName, this.content.name, [
|
|
35
|
-
|
|
33
|
+
join(this.internalFolder, 'model.lp'),
|
|
36
34
|
]),
|
|
37
35
|
super.updateCalculations(existingName, this.content.name),
|
|
38
36
|
]);
|
|
@@ -58,31 +56,6 @@ export class GraphModelResource extends FolderResource {
|
|
|
58
56
|
flag: 'wx',
|
|
59
57
|
});
|
|
60
58
|
}
|
|
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);
|
|
85
|
-
}
|
|
86
59
|
/**
|
|
87
60
|
* Renames the object and the file.
|
|
88
61
|
* @param newName New name for the resource.
|
|
@@ -92,30 +65,19 @@ export class GraphModelResource extends FolderResource {
|
|
|
92
65
|
await super.rename(newName);
|
|
93
66
|
return this.onNameChange(existingName);
|
|
94
67
|
}
|
|
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
68
|
/**
|
|
107
69
|
* Updates graph model resource.
|
|
108
|
-
* @param
|
|
70
|
+
* @param updateKey Key to modify
|
|
109
71
|
* @param op Operation to perform on 'key'
|
|
110
72
|
*/
|
|
111
|
-
async update(
|
|
112
|
-
if (key === 'category') {
|
|
73
|
+
async update(updateKey, op) {
|
|
74
|
+
if (updateKey.key === 'category') {
|
|
113
75
|
const content = structuredClone(this.content);
|
|
114
76
|
content.category = super.handleScalar(op);
|
|
115
|
-
await super.postUpdate(content,
|
|
77
|
+
await super.postUpdate(content, updateKey, op);
|
|
116
78
|
return;
|
|
117
79
|
}
|
|
118
|
-
await super.update(
|
|
80
|
+
await super.update(updateKey, op);
|
|
119
81
|
}
|
|
120
82
|
/**
|
|
121
83
|
* List where this resource is used.
|
|
@@ -125,27 +87,12 @@ export class GraphModelResource extends FolderResource {
|
|
|
125
87
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
126
88
|
*/
|
|
127
89
|
async usage(cards) {
|
|
128
|
-
const allCards = cards ??
|
|
90
|
+
const allCards = cards ?? super.cards();
|
|
129
91
|
const [relevantCards, calculations] = await Promise.all([
|
|
130
92
|
super.usage(allCards),
|
|
131
93
|
super.calculations(),
|
|
132
94
|
]);
|
|
133
95
|
return [...relevantCards.sort(sortCards), ...calculations];
|
|
134
96
|
}
|
|
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
97
|
}
|
|
151
98
|
//# 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;AAQjC,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,cAGvC;IACC,YAAY,OAAgB,EAAE,IAAkB;QAC9C,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;QAEpC,IAAI,CAAC,eAAe,GAAG,kBAAkB,CAAC;QAC1C,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACxE,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,YAAY,CAAC,YAAoB;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,KAAK,CAAC,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;gBACtD,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC;aACtC,CAAC;YACF,KAAK,CAAC,kBAAkB,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;SAC1D,CAAC,CAAC;QACH,kCAAkC;QAClC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED;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;;;;;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"}
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { Card, Operation, Project, ResourceName } from './folder-resource.js';
|
|
15
15
|
import { FolderResource } from './folder-resource.js';
|
|
16
|
-
import type {
|
|
16
|
+
import type { GraphViewMetadata, UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
17
|
+
import type { GraphViewContent } from '../interfaces/folder-content-interfaces.js';
|
|
17
18
|
/**
|
|
18
19
|
* Graph view resource class.
|
|
19
20
|
*/
|
|
20
|
-
export declare class GraphViewResource extends FolderResource {
|
|
21
|
+
export declare class GraphViewResource extends FolderResource<GraphViewMetadata, GraphViewContent> {
|
|
21
22
|
constructor(project: Project, name: ResourceName);
|
|
22
23
|
/**
|
|
23
24
|
* Handle name changes for graph views
|
|
@@ -30,14 +31,6 @@ export declare class GraphViewResource extends FolderResource {
|
|
|
30
31
|
* @throws if 'newContent' is not valid.
|
|
31
32
|
*/
|
|
32
33
|
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
34
|
/**
|
|
42
35
|
* Returns handlebar filename that this graph view has.
|
|
43
36
|
* @returns handlebar filename that this graph view has.
|
|
@@ -48,17 +41,12 @@ export declare class GraphViewResource extends FolderResource {
|
|
|
48
41
|
* @param newName New name for the resource.
|
|
49
42
|
*/
|
|
50
43
|
rename(newName: ResourceName): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Shows metadata of the resource.
|
|
53
|
-
* @returns graph view metadata.
|
|
54
|
-
*/
|
|
55
|
-
show(): Promise<GraphView>;
|
|
56
44
|
/**
|
|
57
45
|
* Updates graph view resource.
|
|
58
|
-
* @param
|
|
46
|
+
* @param updateKey Key to modify
|
|
59
47
|
* @param op Operation to perform on 'key'
|
|
60
48
|
*/
|
|
61
|
-
update<Type>(
|
|
49
|
+
update<Type, K extends string>(updateKey: UpdateKey<K>, op: Operation<Type>): Promise<void>;
|
|
62
50
|
/**
|
|
63
51
|
* List where this resource is used.
|
|
64
52
|
* Always returns card key references first, then calculation references.
|
|
@@ -67,15 +55,4 @@ export declare class GraphViewResource extends FolderResource {
|
|
|
67
55
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
68
56
|
*/
|
|
69
57
|
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
58
|
}
|
|
@@ -24,7 +24,6 @@ export class GraphViewResource extends FolderResource {
|
|
|
24
24
|
super(project, name, 'graphViews');
|
|
25
25
|
this.contentSchemaId = 'graphViewSchema';
|
|
26
26
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
27
|
-
this.initialize();
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
30
29
|
* Handle name changes for graph views
|
|
@@ -54,18 +53,6 @@ export class GraphViewResource extends FolderResource {
|
|
|
54
53
|
await super.create(newContent);
|
|
55
54
|
await copyDir(join(await getStaticDirectoryPath(), 'defaultGraphView'), this.internalFolder);
|
|
56
55
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Returns resource content.
|
|
59
|
-
*/
|
|
60
|
-
get data() {
|
|
61
|
-
return super.data;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Deletes file and folder that this resource is based on.
|
|
65
|
-
*/
|
|
66
|
-
async delete() {
|
|
67
|
-
return super.delete();
|
|
68
|
-
}
|
|
69
56
|
/**
|
|
70
57
|
* Returns handlebar filename that this graph view has.
|
|
71
58
|
* @returns handlebar filename that this graph view has.
|
|
@@ -88,30 +75,19 @@ export class GraphViewResource extends FolderResource {
|
|
|
88
75
|
await super.rename(newName);
|
|
89
76
|
return this.onNameChange(existingName);
|
|
90
77
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Shows metadata of the resource.
|
|
93
|
-
* @returns graph view metadata.
|
|
94
|
-
*/
|
|
95
|
-
async show() {
|
|
96
|
-
const baseData = (await super.show());
|
|
97
|
-
return {
|
|
98
|
-
...baseData,
|
|
99
|
-
content: (await super.contentData()),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
78
|
/**
|
|
103
79
|
* Updates graph view resource.
|
|
104
|
-
* @param
|
|
80
|
+
* @param updateKey Key to modify
|
|
105
81
|
* @param op Operation to perform on 'key'
|
|
106
82
|
*/
|
|
107
|
-
async update(
|
|
108
|
-
if (key === 'category') {
|
|
83
|
+
async update(updateKey, op) {
|
|
84
|
+
if (updateKey.key === 'category') {
|
|
109
85
|
const content = structuredClone(this.content);
|
|
110
86
|
content.category = super.handleScalar(op);
|
|
111
|
-
await super.postUpdate(content,
|
|
87
|
+
await super.postUpdate(content, updateKey, op);
|
|
112
88
|
return;
|
|
113
89
|
}
|
|
114
|
-
await super.update(
|
|
90
|
+
await super.update(updateKey, op);
|
|
115
91
|
}
|
|
116
92
|
/**
|
|
117
93
|
* List where this resource is used.
|
|
@@ -121,27 +97,12 @@ export class GraphViewResource extends FolderResource {
|
|
|
121
97
|
* @returns array of card keys and calculation filenames that refer this resource.
|
|
122
98
|
*/
|
|
123
99
|
async usage(cards) {
|
|
124
|
-
const allCards = cards ??
|
|
100
|
+
const allCards = cards ?? super.cards();
|
|
125
101
|
const [relevantCards, calculations] = await Promise.all([
|
|
126
102
|
super.usage(allCards),
|
|
127
103
|
super.calculations(),
|
|
128
104
|
]);
|
|
129
105
|
return [...relevantCards.sort(sortCards), ...calculations];
|
|
130
106
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Validates graph view.
|
|
133
|
-
* @throws when there are validation errors.
|
|
134
|
-
* @param content Content to be validated.
|
|
135
|
-
* @note If content is not provided, base class validation will use resource's current content.
|
|
136
|
-
*/
|
|
137
|
-
async validate(content) {
|
|
138
|
-
return super.validate(content);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Create the graph view's folder and handlebar file.
|
|
142
|
-
*/
|
|
143
|
-
async write() {
|
|
144
|
-
await super.write();
|
|
145
|
-
}
|
|
146
107
|
}
|
|
147
108
|
//# sourceMappingURL=graph-view-resource.js.map
|