@cyberismo/data-handler 0.0.15 → 0.0.17
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 +7 -1
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +4 -0
- package/dist/command-handler.js +22 -8
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +24 -1
- package/dist/command-manager.js +31 -7
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +34 -36
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/export.d.ts +11 -2
- package/dist/commands/export.js +54 -41
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/fetch.d.ts +8 -0
- package/dist/commands/fetch.js +101 -23
- package/dist/commands/fetch.js.map +1 -1
- package/dist/commands/import.d.ts +14 -3
- package/dist/commands/import.js +27 -10
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.js +0 -1
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +11 -2
- package/dist/commands/remove.js +15 -5
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +4 -9
- package/dist/commands/rename.js +37 -101
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +20 -12
- package/dist/commands/show.js +79 -57
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.d.ts +9 -2
- package/dist/commands/transition.js +25 -17
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +16 -12
- package/dist/commands/update.js +19 -17
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +17 -9
- package/dist/commands/validate.js +94 -35
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/card-container.d.ts +7 -5
- package/dist/containers/card-container.js +30 -5
- package/dist/containers/card-container.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +7 -4
- package/dist/containers/project/calculation-engine.js +61 -66
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project/project-paths.d.ts +7 -4
- package/dist/containers/project/project-paths.js +22 -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 +509 -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 +46 -152
- package/dist/containers/project.js +179 -409
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +8 -2
- package/dist/containers/template.js +24 -19
- package/dist/containers/template.js.map +1 -1
- package/dist/interfaces/command-options.d.ts +3 -1
- package/dist/interfaces/folder-content-interfaces.d.ts +5 -3
- package/dist/interfaces/folder-content-interfaces.js +3 -3
- package/dist/interfaces/folder-content-interfaces.js.map +1 -1
- package/dist/interfaces/project-interfaces.d.ts +7 -9
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +14 -1
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/graph/index.js +12 -26
- package/dist/macros/graph/index.js.map +1 -1
- 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/report/index.js +3 -6
- package/dist/macros/report/index.js.map +1 -1
- package/dist/module-manager.d.ts +16 -3
- package/dist/module-manager.js +51 -19
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.d.ts +21 -3
- package/dist/project-settings.js +91 -14
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/calculation-resource.d.ts +4 -3
- package/dist/resources/calculation-resource.js +11 -5
- package/dist/resources/calculation-resource.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +6 -1
- package/dist/resources/card-type-resource.js +34 -23
- 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 +4 -1
- package/dist/resources/field-type-resource.js +22 -23
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +5 -9
- package/dist/resources/file-resource.js +6 -11
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +29 -32
- package/dist/resources/folder-resource.js +59 -78
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +4 -1
- package/dist/resources/graph-model-resource.js +11 -4
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +5 -2
- package/dist/resources/graph-view-resource.js +7 -3
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +5 -2
- package/dist/resources/link-type-resource.js +5 -2
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +6 -7
- package/dist/resources/report-resource.js +14 -23
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +94 -8
- package/dist/resources/resource-object.js +212 -109
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +7 -3
- package/dist/resources/template-resource.js +10 -3
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +5 -2
- package/dist/resources/workflow-resource.js +18 -22
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/card-utils.d.ts +2 -2
- package/dist/utils/card-utils.js +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 +3 -4
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/configuration-logger.d.ts +91 -0
- package/dist/utils/configuration-logger.js +151 -0
- package/dist/utils/configuration-logger.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.js +5 -3
- package/dist/utils/constants.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 +9 -9
- package/src/card-metadata-updater.ts +6 -2
- package/src/command-handler.ts +39 -12
- package/src/command-manager.ts +33 -21
- package/src/commands/create.ts +43 -78
- package/src/commands/export.ts +63 -52
- package/src/commands/fetch.ts +143 -34
- package/src/commands/import.ts +37 -15
- package/src/commands/move.ts +0 -1
- package/src/commands/remove.ts +20 -7
- package/src/commands/rename.ts +58 -149
- package/src/commands/show.ts +123 -80
- package/src/commands/transition.ts +26 -28
- package/src/commands/update.ts +25 -22
- package/src/commands/validate.ts +104 -67
- package/src/containers/card-container.ts +37 -5
- package/src/containers/project/calculation-engine.ts +61 -93
- package/src/containers/project/project-paths.ts +29 -13
- package/src/containers/project/resource-cache.ts +651 -0
- package/src/containers/project/resource-handler.ts +265 -0
- package/src/containers/project.ts +250 -527
- package/src/containers/template.ts +28 -23
- package/src/interfaces/command-options.ts +3 -1
- package/src/interfaces/folder-content-interfaces.ts +7 -6
- package/src/interfaces/project-interfaces.ts +12 -11
- package/src/interfaces/resource-interfaces.ts +18 -3
- package/src/macros/graph/index.ts +26 -47
- package/src/macros/index.ts +2 -2
- package/src/macros/report/index.ts +3 -9
- package/src/module-manager.ts +74 -17
- package/src/project-settings.ts +96 -14
- package/src/resources/calculation-resource.ts +18 -18
- package/src/resources/card-type-resource.ts +50 -50
- package/src/resources/create-defaults.ts +3 -2
- package/src/resources/field-type-resource.ts +41 -55
- package/src/resources/file-resource.ts +10 -36
- package/src/resources/folder-resource.ts +69 -120
- package/src/resources/graph-model-resource.ts +20 -22
- package/src/resources/graph-view-resource.ts +15 -17
- package/src/resources/link-type-resource.ts +10 -13
- package/src/resources/report-resource.ts +21 -43
- package/src/resources/resource-object.ts +263 -149
- package/src/resources/template-resource.ts +17 -16
- package/src/resources/workflow-resource.ts +25 -44
- package/src/utils/card-utils.ts +2 -2
- package/src/utils/clingo-fact-builder.ts +28 -16
- package/src/utils/clingo-facts.ts +3 -4
- package/src/utils/configuration-logger.ts +206 -0
- package/src/utils/constants.ts +5 -3
- package/src/utils/resource-utils.ts +2 -1
- package/dist/containers/project/resource-collector.d.ts +0 -110
- package/dist/containers/project/resource-collector.js +0 -344
- package/dist/containers/project/resource-collector.js.map +0 -1
- package/src/containers/project/resource-collector.ts +0 -404
|
@@ -15,71 +15,55 @@
|
|
|
15
15
|
import { basename, dirname, join, normalize } from 'node:path';
|
|
16
16
|
import { mkdir, readdir, readFile, rename, rm } from 'node:fs/promises';
|
|
17
17
|
|
|
18
|
-
import
|
|
19
|
-
import type { ResourceBaseMetadata } from '../interfaces/resource-interfaces.js';
|
|
20
|
-
import {
|
|
21
|
-
isContentKey,
|
|
22
|
-
type UpdateKey,
|
|
23
|
-
} from '../interfaces/resource-interfaces.js';
|
|
24
|
-
import type { ResourceFolderType } from '../interfaces/project-interfaces.js';
|
|
25
|
-
|
|
26
|
-
import {
|
|
27
|
-
DefaultContent,
|
|
28
|
-
FileResource,
|
|
29
|
-
Project,
|
|
30
|
-
resourceName,
|
|
31
|
-
resourceNameToString,
|
|
32
|
-
sortCards,
|
|
33
|
-
} from './file-resource.js';
|
|
34
|
-
import type { FolderResourceContent } from '../interfaces/folder-content-interfaces.js';
|
|
18
|
+
import { isContentKey } from '../interfaces/resource-interfaces.js';
|
|
35
19
|
import {
|
|
36
20
|
filename,
|
|
37
|
-
|
|
21
|
+
contentPropertyName,
|
|
38
22
|
} from '../interfaces/folder-content-interfaces.js';
|
|
39
|
-
import { formatJson
|
|
23
|
+
import { formatJson } from '../utils/json.js';
|
|
40
24
|
import { VALID_FOLDER_RESOURCE_FILES } from '../utils/constants.js';
|
|
41
25
|
import { writeFileSafe } from '../utils/file-utils.js';
|
|
42
|
-
import type { ShowReturnType } from './resource-object.js';
|
|
43
26
|
import { ResourceObject } from './resource-object.js';
|
|
27
|
+
import { resourceName } from '../utils/resource-utils.js';
|
|
44
28
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
sortCards,
|
|
54
|
-
};
|
|
29
|
+
import type { UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
30
|
+
import type { FolderResourceContent } from '../interfaces/folder-content-interfaces.js';
|
|
31
|
+
import type { Operation } from './resource-object.js';
|
|
32
|
+
import type { Project } from '../containers/project.js';
|
|
33
|
+
import type { ResourceFolderType } from '../interfaces/project-interfaces.js';
|
|
34
|
+
import type { ResourceBaseMetadata } from '../interfaces/resource-interfaces.js';
|
|
35
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
36
|
+
import type { ShowReturnType } from './resource-object.js';
|
|
55
37
|
|
|
56
38
|
/**
|
|
57
|
-
* Folder type resource class.
|
|
39
|
+
* Folder type resource class.
|
|
40
|
+
* These are resources that have their own folders for content.
|
|
58
41
|
*/
|
|
59
42
|
export abstract class FolderResource<
|
|
60
43
|
T extends ResourceBaseMetadata,
|
|
61
44
|
U extends FolderResourceContent,
|
|
62
45
|
> extends ResourceObject<T, U> {
|
|
63
46
|
protected internalFolder: string = '';
|
|
47
|
+
private resourceContent: U = {} as U;
|
|
64
48
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Constructs a FolderResource object.
|
|
51
|
+
* @param project Project in which this resource exists.
|
|
52
|
+
* @param name Name for the resource.
|
|
53
|
+
* @param type Type for this resource.
|
|
54
|
+
*/
|
|
68
55
|
constructor(project: Project, name: ResourceName, type: ResourceFolderType) {
|
|
69
56
|
super(project, name, type);
|
|
70
57
|
this.initialize();
|
|
71
58
|
}
|
|
72
59
|
|
|
73
|
-
// Clears the content files cache.
|
|
74
|
-
private clearContentCache() {
|
|
75
|
-
this.contentFilesCache.clear();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
60
|
/**
|
|
79
61
|
* Creates a new folder type object. Base class writes the object to disk automatically.
|
|
80
62
|
* @param newContent Content for the type.
|
|
81
63
|
*/
|
|
82
64
|
protected async create(newContent?: T) {
|
|
65
|
+
// Validate resource identifier before creating on disk
|
|
66
|
+
this.validateResourceIdentifier();
|
|
83
67
|
await super.create(newContent);
|
|
84
68
|
await mkdir(this.internalFolder, { recursive: true });
|
|
85
69
|
}
|
|
@@ -103,65 +87,36 @@ export abstract class FolderResource<
|
|
|
103
87
|
protected abstract onNameChange?(previousName: string): Promise<void>;
|
|
104
88
|
|
|
105
89
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @param newName New name for the resource.
|
|
90
|
+
* Set content files. Should not be called by others than resource cache.
|
|
108
91
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
92
|
+
public setContentFiles(contentFiles: Map<string, string>) {
|
|
93
|
+
const content = {} as Record<string, unknown>;
|
|
112
94
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
protected async showFile(
|
|
120
|
-
fileName: string,
|
|
121
|
-
json: boolean = false,
|
|
122
|
-
): Promise<string> {
|
|
123
|
-
// Always first check cache...
|
|
124
|
-
if (this.contentFilesCache.has(fileName)) {
|
|
125
|
-
const cached = this.contentFilesCache.get(fileName)!;
|
|
126
|
-
return json ? JSON.parse(cached) : cached;
|
|
95
|
+
for (const [fileName, fileContent] of contentFiles.entries()) {
|
|
96
|
+
const key = contentPropertyName(fileName);
|
|
97
|
+
if (key) {
|
|
98
|
+
const isJson = key === 'schema';
|
|
99
|
+
content[key] = isJson ? JSON.parse(fileContent) : fileContent;
|
|
100
|
+
}
|
|
127
101
|
}
|
|
128
102
|
|
|
129
|
-
|
|
130
|
-
const filePath = join(this.internalFolder, fileName);
|
|
131
|
-
const content = json
|
|
132
|
-
? await readJsonFile(filePath)
|
|
133
|
-
: await readFile(filePath, 'utf8');
|
|
134
|
-
|
|
135
|
-
// Update cache
|
|
136
|
-
const contentStr =
|
|
137
|
-
typeof content === 'string' ? content : formatJson(content);
|
|
138
|
-
this.contentFilesCache.set(fileName, contentStr);
|
|
139
|
-
|
|
140
|
-
return json ? content : contentStr;
|
|
103
|
+
this.resourceContent = content as U;
|
|
141
104
|
}
|
|
142
105
|
|
|
143
106
|
/**
|
|
144
|
-
*
|
|
145
|
-
* @returns all file names in the resource.
|
|
107
|
+
* Load all content files from the internal folder and set them.
|
|
146
108
|
*/
|
|
147
|
-
protected async
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
VALID_FOLDER_RESOURCE_FILES.includes(file),
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
// Update cache by reading all files. Each method call updates specific cache item.
|
|
160
|
-
for (const fileName of validFiles) {
|
|
161
|
-
await this.showFile(fileName);
|
|
109
|
+
protected async loadContentFiles() {
|
|
110
|
+
const contentFiles = new Map<string, string>();
|
|
111
|
+
const files = await readdir(this.internalFolder, { withFileTypes: true });
|
|
112
|
+
for (const file of files) {
|
|
113
|
+
if (file.isFile() && VALID_FOLDER_RESOURCE_FILES.includes(file.name)) {
|
|
114
|
+
const filePath = join(this.internalFolder, file.name);
|
|
115
|
+
const content = await readFile(filePath, 'utf-8');
|
|
116
|
+
contentFiles.set(file.name, content);
|
|
117
|
+
}
|
|
162
118
|
}
|
|
163
|
-
|
|
164
|
-
return validFiles;
|
|
119
|
+
this.setContentFiles(contentFiles);
|
|
165
120
|
}
|
|
166
121
|
|
|
167
122
|
/**
|
|
@@ -169,7 +124,7 @@ export abstract class FolderResource<
|
|
|
169
124
|
* @param fileName The name of the file to update.
|
|
170
125
|
* @param changedContent The new content for the file.
|
|
171
126
|
*/
|
|
172
|
-
|
|
127
|
+
public async updateFile(fileName: string, changedContent: string) {
|
|
173
128
|
const filePath = join(this.internalFolder, fileName);
|
|
174
129
|
|
|
175
130
|
// Do not allow updating file in other directories
|
|
@@ -190,8 +145,14 @@ export abstract class FolderResource<
|
|
|
190
145
|
|
|
191
146
|
await writeFileSafe(filePath, changedContent, { flag: 'w' });
|
|
192
147
|
|
|
193
|
-
// Update
|
|
194
|
-
|
|
148
|
+
// Update this resource's content
|
|
149
|
+
const key = contentPropertyName(fileName);
|
|
150
|
+
if (key) {
|
|
151
|
+
const isJson = key === 'schema';
|
|
152
|
+
(this.resourceContent as Record<string, unknown>)[key] = isJson
|
|
153
|
+
? JSON.parse(changedContent)
|
|
154
|
+
: changedContent;
|
|
155
|
+
}
|
|
195
156
|
}
|
|
196
157
|
|
|
197
158
|
/**
|
|
@@ -214,32 +175,33 @@ export abstract class FolderResource<
|
|
|
214
175
|
* Gets content of all files to properties.
|
|
215
176
|
* @returns object with property names as keys and file contents as values.
|
|
216
177
|
*/
|
|
217
|
-
public
|
|
218
|
-
const fileNames = await this.showFileNames();
|
|
219
|
-
const content = {} as Record<string, unknown>;
|
|
220
|
-
|
|
221
|
-
for (const fileName of fileNames) {
|
|
222
|
-
const name = propertyName(fileName);
|
|
223
|
-
if (name) {
|
|
224
|
-
const JSONFile = name === 'schema';
|
|
225
|
-
content[name] = await this.showFile(fileName, JSONFile);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
178
|
+
public contentData(): U {
|
|
229
179
|
// TODO: Instead of casting, validate that content matches U
|
|
230
180
|
// This requires a runtime schema for U to be defined(via an abstract variable)
|
|
231
181
|
|
|
232
|
-
return
|
|
182
|
+
return this.resourceContent;
|
|
233
183
|
}
|
|
234
184
|
|
|
235
185
|
/**
|
|
236
186
|
* Deletes file and content folder from disk and clears out the memory resident object.
|
|
237
|
-
* @throws if resource is a module resource or does not exist or is used by other resources.
|
|
238
187
|
*/
|
|
239
188
|
public async delete() {
|
|
240
189
|
await super.delete();
|
|
241
190
|
await rm(this.internalFolder, { recursive: true, force: true });
|
|
242
|
-
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Shows metadata of the resource and content of the resource.
|
|
195
|
+
* @template T Resource type
|
|
196
|
+
* @template U Resource content
|
|
197
|
+
* @returns resource type's metadata and content.
|
|
198
|
+
*/
|
|
199
|
+
public show(): ShowReturnType<T, U> {
|
|
200
|
+
this.assertResourceExists();
|
|
201
|
+
return {
|
|
202
|
+
...this.content,
|
|
203
|
+
content: this.contentData(),
|
|
204
|
+
};
|
|
243
205
|
}
|
|
244
206
|
|
|
245
207
|
/**
|
|
@@ -286,17 +248,4 @@ export abstract class FolderResource<
|
|
|
286
248
|
await this.onNameChange?.(existingName);
|
|
287
249
|
}
|
|
288
250
|
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Shows metadata of the resource and content of the resource.
|
|
292
|
-
* @returns resource type's metadata and content.
|
|
293
|
-
* @throws if resource does not exist.
|
|
294
|
-
*/
|
|
295
|
-
public async show(): Promise<ShowReturnType<T, U>> {
|
|
296
|
-
this.assertResourceExists();
|
|
297
|
-
return {
|
|
298
|
-
...this.content,
|
|
299
|
-
content: await this.contentData(),
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
251
|
}
|
|
@@ -14,24 +14,22 @@
|
|
|
14
14
|
|
|
15
15
|
import { join } from 'node:path';
|
|
16
16
|
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from '
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
FolderResource,
|
|
26
|
-
resourceNameToString,
|
|
27
|
-
sortCards,
|
|
28
|
-
} from './folder-resource.js';
|
|
17
|
+
import { DefaultContent } from './create-defaults.js';
|
|
18
|
+
import { FolderResource } from './folder-resource.js';
|
|
19
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
20
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
21
|
+
import { writeFileSafe } from '../utils/file-utils.js';
|
|
22
|
+
import { CONTENT_FILES } from '../interfaces/folder-content-interfaces.js';
|
|
23
|
+
|
|
24
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
29
25
|
import type {
|
|
30
26
|
GraphModelMetadata,
|
|
31
27
|
UpdateKey,
|
|
32
28
|
} from '../interfaces/resource-interfaces.js';
|
|
33
29
|
import type { GraphModelContent } from '../interfaces/folder-content-interfaces.js';
|
|
34
|
-
import {
|
|
30
|
+
import type { Operation } from './resource-object.js';
|
|
31
|
+
import type { Project } from '../containers/project.js';
|
|
32
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
35
33
|
|
|
36
34
|
/**
|
|
37
35
|
* Graph model resource class.
|
|
@@ -54,7 +52,7 @@ export class GraphModelResource extends FolderResource<
|
|
|
54
52
|
protected async onNameChange(existingName: string): Promise<void> {
|
|
55
53
|
await Promise.all([
|
|
56
54
|
super.updateHandleBars(existingName, this.content.name, [
|
|
57
|
-
join(this.internalFolder,
|
|
55
|
+
join(this.internalFolder, CONTENT_FILES.model),
|
|
58
56
|
]),
|
|
59
57
|
super.updateCalculations(existingName, this.content.name),
|
|
60
58
|
]);
|
|
@@ -79,14 +77,14 @@ export class GraphModelResource extends FolderResource<
|
|
|
79
77
|
await super.create(newContent);
|
|
80
78
|
|
|
81
79
|
// Create the internal folder in 'create', instead of 'write'.
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
);
|
|
80
|
+
const modelContent = `% add your calculations here for '${this.resourceName.identifier}'`;
|
|
81
|
+
const modelFile = CONTENT_FILES.model;
|
|
82
|
+
const calculationsFile = join(this.internalFolder, modelFile);
|
|
83
|
+
await writeFileSafe(calculationsFile, modelContent, {
|
|
84
|
+
flag: 'wx',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await this.loadContentFiles();
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
/**
|
|
@@ -12,29 +12,25 @@
|
|
|
12
12
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { readdir } from 'node:fs/promises';
|
|
16
15
|
import { extname, join } from 'node:path';
|
|
16
|
+
import { readdir } from 'node:fs/promises';
|
|
17
17
|
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from '
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
resourceNameToString,
|
|
28
|
-
sortCards,
|
|
29
|
-
} from './folder-resource.js';
|
|
18
|
+
import { copyDir } from '../utils/file-utils.js';
|
|
19
|
+
import { DefaultContent } from './create-defaults.js';
|
|
20
|
+
import { FolderResource } from './folder-resource.js';
|
|
21
|
+
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
22
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
23
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
24
|
+
|
|
25
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
26
|
+
import type { GraphViewContent } from '../interfaces/folder-content-interfaces.js';
|
|
30
27
|
import type {
|
|
31
28
|
GraphViewMetadata,
|
|
32
29
|
UpdateKey,
|
|
33
30
|
} from '../interfaces/resource-interfaces.js';
|
|
34
|
-
import type {
|
|
35
|
-
|
|
36
|
-
import {
|
|
37
|
-
import { copyDir } from '../utils/file-utils.js';
|
|
31
|
+
import type { Operation } from './resource-object.js';
|
|
32
|
+
import type { Project } from '../containers/project.js';
|
|
33
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
38
34
|
|
|
39
35
|
/**
|
|
40
36
|
* Graph view resource class.
|
|
@@ -83,6 +79,8 @@ export class GraphViewResource extends FolderResource<
|
|
|
83
79
|
join(await getStaticDirectoryPath(), 'defaultGraphView'),
|
|
84
80
|
this.internalFolder,
|
|
85
81
|
);
|
|
82
|
+
|
|
83
|
+
await this.loadContentFiles();
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
/**
|
|
@@ -10,19 +10,16 @@
|
|
|
10
10
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from '
|
|
19
|
-
import {
|
|
20
|
-
DefaultContent,
|
|
21
|
-
FileResource,
|
|
22
|
-
resourceNameToString,
|
|
23
|
-
sortCards,
|
|
24
|
-
} from './folder-resource.js';
|
|
13
|
+
import { DefaultContent } from './create-defaults.js';
|
|
14
|
+
import { FileResource } from './file-resource.js';
|
|
15
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
16
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
17
|
+
|
|
18
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
25
19
|
import type { LinkType, UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
20
|
+
import type { Operation } from './resource-object.js';
|
|
21
|
+
import type { Project } from '../containers/project.js';
|
|
22
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
26
23
|
|
|
27
24
|
/**
|
|
28
25
|
* Link Type resource class.
|
|
@@ -38,7 +35,7 @@ export class LinkTypeResource extends FileResource<LinkType> {
|
|
|
38
35
|
// When resource name changes.
|
|
39
36
|
private async handleNameChange(existingName: string) {
|
|
40
37
|
const current = this.content;
|
|
41
|
-
const prefixes =
|
|
38
|
+
const prefixes = this.project.projectPrefixes();
|
|
42
39
|
if (current.sourceCardTypes) {
|
|
43
40
|
current.sourceCardTypes = current.sourceCardTypes.map((item) =>
|
|
44
41
|
this.updatePrefixInResourceName(item, prefixes),
|
|
@@ -12,38 +12,29 @@
|
|
|
12
12
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { readdir } from 'node:fs/promises';
|
|
16
|
-
import { readFileSync } from 'node:fs';
|
|
17
15
|
import { extname, join } from 'node:path';
|
|
16
|
+
import { readdir } from 'node:fs/promises';
|
|
18
17
|
|
|
19
18
|
import { copyDir } from '../utils/file-utils.js';
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
FolderResource,
|
|
23
|
-
resourceNameToString,
|
|
24
|
-
sortCards,
|
|
25
|
-
} from './folder-resource.js';
|
|
19
|
+
import { DefaultContent } from './create-defaults.js';
|
|
20
|
+
import { FolderResource } from './folder-resource.js';
|
|
26
21
|
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
22
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
23
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
27
24
|
import { Validate } from '../commands/validate.js';
|
|
28
25
|
|
|
26
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
27
|
+
import type { Operation } from './resource-object.js';
|
|
28
|
+
import type { Project } from '../containers/project.js';
|
|
29
|
+
import type { ReportContent } from '../interfaces/folder-content-interfaces.js';
|
|
29
30
|
import type {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Project,
|
|
33
|
-
ResourceName,
|
|
34
|
-
} from './folder-resource.js';
|
|
35
|
-
import {
|
|
36
|
-
type ReportMetadata,
|
|
37
|
-
type UpdateKey,
|
|
31
|
+
ReportMetadata,
|
|
32
|
+
UpdateKey,
|
|
38
33
|
} from '../interfaces/resource-interfaces.js';
|
|
39
|
-
import type {
|
|
40
|
-
import type { Schema } from 'jsonschema';
|
|
34
|
+
import type { ResourceName } from '../utils/resource-utils.js';
|
|
41
35
|
|
|
42
|
-
const REPORT_SCHEMA_FILE = 'parameterSchema.json';
|
|
43
36
|
const PARAMETER_SCHEMA_ID = 'jsonSchema';
|
|
44
37
|
|
|
45
|
-
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
46
|
-
|
|
47
38
|
/**
|
|
48
39
|
* Report resource class.
|
|
49
40
|
*/
|
|
@@ -51,32 +42,18 @@ export class ReportResource extends FolderResource<
|
|
|
51
42
|
ReportMetadata,
|
|
52
43
|
ReportContent
|
|
53
44
|
> {
|
|
54
|
-
private reportSchema: Schema;
|
|
55
45
|
constructor(project: Project, name: ResourceName) {
|
|
56
46
|
super(project, name, 'reports');
|
|
57
47
|
|
|
58
48
|
this.contentSchemaId = 'reportSchema';
|
|
59
49
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
60
|
-
|
|
61
|
-
const schemaPath = join(this.internalFolder, REPORT_SCHEMA_FILE);
|
|
62
|
-
this.reportSchema = this.readSchemaFile(schemaPath);
|
|
63
50
|
}
|
|
64
51
|
|
|
65
52
|
// Path to content folder.
|
|
66
53
|
// @todo: create the files' content dynamically.
|
|
67
|
-
private
|
|
68
|
-
staticDirectoryPath
|
|
69
|
-
'defaultReport'
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
// Try to read schema file content
|
|
73
|
-
private readSchemaFile(path: string) {
|
|
74
|
-
try {
|
|
75
|
-
const schema = readFileSync(path);
|
|
76
|
-
return JSON.parse(schema.toString());
|
|
77
|
-
} catch {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
54
|
+
private async getDefaultReportLocation(): Promise<string> {
|
|
55
|
+
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
56
|
+
return join(staticDirectoryPath, 'defaultReport');
|
|
80
57
|
}
|
|
81
58
|
|
|
82
59
|
/**
|
|
@@ -98,8 +75,6 @@ export class ReportResource extends FolderResource<
|
|
|
98
75
|
|
|
99
76
|
/**
|
|
100
77
|
* Sets new metadata into the report object.
|
|
101
|
-
* @param newContent metadata content for the report.
|
|
102
|
-
* @throws if 'newContent' is not valid.
|
|
103
78
|
*/
|
|
104
79
|
public async createReport() {
|
|
105
80
|
const defaultContent = DefaultContent.report(
|
|
@@ -109,7 +84,9 @@ export class ReportResource extends FolderResource<
|
|
|
109
84
|
await super.create(defaultContent);
|
|
110
85
|
|
|
111
86
|
// Copy report default structure to destination.
|
|
112
|
-
|
|
87
|
+
const defaultReportLocation = await this.getDefaultReportLocation();
|
|
88
|
+
await copyDir(defaultReportLocation, this.internalFolder);
|
|
89
|
+
await this.loadContentFiles();
|
|
113
90
|
}
|
|
114
91
|
|
|
115
92
|
/**
|
|
@@ -180,9 +157,10 @@ export class ReportResource extends FolderResource<
|
|
|
180
157
|
* @note If content is not provided, base class validation will use resource's current content.
|
|
181
158
|
*/
|
|
182
159
|
public async validate(content?: object) {
|
|
183
|
-
|
|
160
|
+
const resourceContent = this.contentData();
|
|
161
|
+
if (resourceContent.schema) {
|
|
184
162
|
const errors = Validate.getInstance().validateJson(
|
|
185
|
-
|
|
163
|
+
resourceContent.schema,
|
|
186
164
|
PARAMETER_SCHEMA_ID,
|
|
187
165
|
);
|
|
188
166
|
if (errors.length > 0) {
|