@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.
Files changed (280) hide show
  1. package/dist/card-metadata-updater.js +8 -4
  2. package/dist/card-metadata-updater.js.map +1 -1
  3. package/dist/command-handler.d.ts +4 -0
  4. package/dist/command-handler.js +29 -19
  5. package/dist/command-handler.js.map +1 -1
  6. package/dist/command-manager.d.ts +25 -2
  7. package/dist/command-manager.js +30 -5
  8. package/dist/command-manager.js.map +1 -1
  9. package/dist/commands/create.d.ts +1 -1
  10. package/dist/commands/create.js +45 -93
  11. package/dist/commands/create.js.map +1 -1
  12. package/dist/commands/edit.d.ts +1 -15
  13. package/dist/commands/edit.js +15 -89
  14. package/dist/commands/edit.js.map +1 -1
  15. package/dist/commands/export.d.ts +11 -2
  16. package/dist/commands/export.js +58 -58
  17. package/dist/commands/export.js.map +1 -1
  18. package/dist/commands/import.d.ts +9 -1
  19. package/dist/commands/import.js +17 -11
  20. package/dist/commands/import.js.map +1 -1
  21. package/dist/commands/move.d.ts +1 -2
  22. package/dist/commands/move.js +107 -146
  23. package/dist/commands/move.js.map +1 -1
  24. package/dist/commands/remove.d.ts +8 -1
  25. package/dist/commands/remove.js +17 -48
  26. package/dist/commands/remove.js.map +1 -1
  27. package/dist/commands/rename.d.ts +4 -9
  28. package/dist/commands/rename.js +34 -108
  29. package/dist/commands/rename.js.map +1 -1
  30. package/dist/commands/show.d.ts +22 -34
  31. package/dist/commands/show.js +103 -151
  32. package/dist/commands/show.js.map +1 -1
  33. package/dist/commands/transition.d.ts +9 -2
  34. package/dist/commands/transition.js +49 -44
  35. package/dist/commands/transition.js.map +1 -1
  36. package/dist/commands/update.d.ts +18 -12
  37. package/dist/commands/update.js +34 -18
  38. package/dist/commands/update.js.map +1 -1
  39. package/dist/commands/validate.d.ts +18 -10
  40. package/dist/commands/validate.js +101 -47
  41. package/dist/commands/validate.js.map +1 -1
  42. package/dist/containers/card-container.d.ts +87 -24
  43. package/dist/containers/card-container.js +183 -279
  44. package/dist/containers/card-container.js.map +1 -1
  45. package/dist/containers/project/calculation-engine.d.ts +13 -4
  46. package/dist/containers/project/calculation-engine.js +79 -77
  47. package/dist/containers/project/calculation-engine.js.map +1 -1
  48. package/dist/containers/project/card-cache.d.ts +146 -0
  49. package/dist/containers/project/card-cache.js +411 -0
  50. package/dist/containers/project/card-cache.js.map +1 -0
  51. package/dist/containers/project/project-paths.d.ts +5 -4
  52. package/dist/containers/project/project-paths.js +16 -12
  53. package/dist/containers/project/project-paths.js.map +1 -1
  54. package/dist/containers/project/resource-cache.d.ts +169 -0
  55. package/dist/containers/project/resource-cache.js +507 -0
  56. package/dist/containers/project/resource-cache.js.map +1 -0
  57. package/dist/containers/project/resource-handler.d.ts +129 -0
  58. package/dist/containers/project/resource-handler.js +206 -0
  59. package/dist/containers/project/resource-handler.js.map +1 -0
  60. package/dist/containers/project.d.ts +114 -195
  61. package/dist/containers/project.js +425 -535
  62. package/dist/containers/project.js.map +1 -1
  63. package/dist/containers/template.d.ts +22 -32
  64. package/dist/containers/template.js +113 -115
  65. package/dist/containers/template.js.map +1 -1
  66. package/dist/index.d.ts +1 -0
  67. package/dist/index.js +1 -0
  68. package/dist/index.js.map +1 -1
  69. package/dist/interfaces/folder-content-interfaces.d.ts +7 -4
  70. package/dist/interfaces/folder-content-interfaces.js +3 -3
  71. package/dist/interfaces/folder-content-interfaces.js.map +1 -1
  72. package/dist/interfaces/macros.d.ts +1 -0
  73. package/dist/interfaces/macros.js +1 -1
  74. package/dist/interfaces/macros.js.map +1 -1
  75. package/dist/interfaces/project-interfaces.d.ts +7 -5
  76. package/dist/interfaces/project-interfaces.js.map +1 -1
  77. package/dist/interfaces/resource-interfaces.d.ts +25 -22
  78. package/dist/interfaces/resource-interfaces.js +3 -0
  79. package/dist/interfaces/resource-interfaces.js.map +1 -1
  80. package/dist/macros/common.d.ts +10 -10
  81. package/dist/macros/createCards/index.d.ts +0 -13
  82. package/dist/macros/createCards/index.js.map +1 -1
  83. package/dist/macros/createCards/types.d.ts +44 -0
  84. package/dist/macros/createCards/types.js +15 -0
  85. package/dist/macros/createCards/types.js.map +1 -0
  86. package/dist/macros/graph/index.d.ts +2 -6
  87. package/dist/macros/graph/index.js +14 -28
  88. package/dist/macros/graph/index.js.map +1 -1
  89. package/dist/macros/graph/types.d.ts +23 -0
  90. package/dist/macros/graph/types.js +15 -0
  91. package/dist/macros/graph/types.js.map +1 -0
  92. package/dist/macros/image/index.d.ts +8 -16
  93. package/dist/macros/image/index.js +36 -33
  94. package/dist/macros/image/index.js.map +1 -1
  95. package/dist/macros/image/types.d.ts +38 -0
  96. package/dist/macros/image/types.js +15 -0
  97. package/dist/macros/image/types.js.map +1 -0
  98. package/dist/macros/include/index.d.ts +1 -6
  99. package/dist/macros/include/index.js +4 -7
  100. package/dist/macros/include/index.js.map +1 -1
  101. package/dist/macros/include/types.d.ts +31 -0
  102. package/dist/macros/include/types.js +15 -0
  103. package/dist/macros/include/types.js.map +1 -0
  104. package/dist/macros/index.d.ts +1 -1
  105. package/dist/macros/index.js +2 -2
  106. package/dist/macros/index.js.map +1 -1
  107. package/dist/macros/percentage/index.d.ts +0 -6
  108. package/dist/macros/percentage/index.js.map +1 -1
  109. package/dist/macros/percentage/types.d.ts +31 -0
  110. package/dist/macros/percentage/types.js +15 -0
  111. package/dist/macros/percentage/types.js.map +1 -0
  112. package/dist/macros/report/index.d.ts +0 -3
  113. package/dist/macros/report/index.js +3 -6
  114. package/dist/macros/report/index.js.map +1 -1
  115. package/dist/macros/report/types.d.ts +19 -0
  116. package/dist/macros/report/types.js +15 -0
  117. package/dist/macros/report/types.js.map +1 -0
  118. package/dist/macros/scoreCard/index.d.ts +0 -6
  119. package/dist/macros/scoreCard/index.js.map +1 -1
  120. package/dist/macros/scoreCard/types.d.ts +31 -0
  121. package/dist/macros/scoreCard/types.js +15 -0
  122. package/dist/macros/scoreCard/types.js.map +1 -0
  123. package/dist/macros/types.d.ts +25 -0
  124. package/dist/macros/types.js +2 -0
  125. package/dist/macros/types.js.map +1 -0
  126. package/dist/macros/vega/index.d.ts +0 -4
  127. package/dist/macros/vega/index.js.map +1 -1
  128. package/dist/macros/vega/types.d.ts +20 -0
  129. package/dist/macros/vega/types.js +2 -0
  130. package/dist/macros/vega/types.js.map +1 -0
  131. package/dist/macros/vegalite/index.d.ts +0 -4
  132. package/dist/macros/vegalite/index.js.map +1 -1
  133. package/dist/macros/vegalite/types.d.ts +20 -0
  134. package/dist/macros/vegalite/types.js +15 -0
  135. package/dist/macros/vegalite/types.js.map +1 -0
  136. package/dist/macros/xref/index.d.ts +0 -3
  137. package/dist/macros/xref/index.js +5 -14
  138. package/dist/macros/xref/index.js.map +1 -1
  139. package/dist/macros/xref/types.d.ts +19 -0
  140. package/dist/macros/xref/types.js +15 -0
  141. package/dist/macros/xref/types.js.map +1 -0
  142. package/dist/module-manager.d.ts +16 -3
  143. package/dist/module-manager.js +55 -23
  144. package/dist/module-manager.js.map +1 -1
  145. package/dist/project-settings.d.ts +16 -3
  146. package/dist/project-settings.js +79 -14
  147. package/dist/project-settings.js.map +1 -1
  148. package/dist/resources/calculation-resource.d.ts +6 -33
  149. package/dist/resources/calculation-resource.js +11 -60
  150. package/dist/resources/calculation-resource.js.map +1 -1
  151. package/dist/resources/card-type-resource.d.ts +10 -22
  152. package/dist/resources/card-type-resource.js +46 -66
  153. package/dist/resources/card-type-resource.js.map +1 -1
  154. package/dist/resources/create-defaults.d.ts +3 -2
  155. package/dist/resources/create-defaults.js +3 -2
  156. package/dist/resources/create-defaults.js.map +1 -1
  157. package/dist/resources/field-type-resource.d.ts +8 -22
  158. package/dist/resources/field-type-resource.js +35 -60
  159. package/dist/resources/field-type-resource.js.map +1 -1
  160. package/dist/resources/file-resource.d.ts +14 -35
  161. package/dist/resources/file-resource.js +22 -301
  162. package/dist/resources/file-resource.js.map +1 -1
  163. package/dist/resources/folder-resource.d.ts +44 -66
  164. package/dist/resources/folder-resource.js +102 -149
  165. package/dist/resources/folder-resource.js.map +1 -1
  166. package/dist/resources/graph-model-resource.d.ts +9 -34
  167. package/dist/resources/graph-model-resource.js +18 -64
  168. package/dist/resources/graph-model-resource.js.map +1 -1
  169. package/dist/resources/graph-view-resource.d.ts +9 -29
  170. package/dist/resources/graph-view-resource.js +13 -48
  171. package/dist/resources/graph-view-resource.js.map +1 -1
  172. package/dist/resources/link-type-resource.d.ts +9 -23
  173. package/dist/resources/link-type-resource.js +11 -33
  174. package/dist/resources/link-type-resource.js.map +1 -1
  175. package/dist/resources/report-resource.d.ts +10 -23
  176. package/dist/resources/report-resource.js +20 -67
  177. package/dist/resources/report-resource.js.map +1 -1
  178. package/dist/resources/resource-object.d.ts +143 -23
  179. package/dist/resources/resource-object.js +369 -48
  180. package/dist/resources/resource-object.js.map +1 -1
  181. package/dist/resources/template-resource.d.ts +10 -17
  182. package/dist/resources/template-resource.js +19 -27
  183. package/dist/resources/template-resource.js.map +1 -1
  184. package/dist/resources/workflow-resource.d.ts +9 -25
  185. package/dist/resources/workflow-resource.js +25 -55
  186. package/dist/resources/workflow-resource.js.map +1 -1
  187. package/dist/utils/card-utils.d.ts +69 -19
  188. package/dist/utils/card-utils.js +179 -30
  189. package/dist/utils/card-utils.js.map +1 -1
  190. package/dist/utils/clingo-fact-builder.d.ts +25 -14
  191. package/dist/utils/clingo-fact-builder.js +27 -5
  192. package/dist/utils/clingo-fact-builder.js.map +1 -1
  193. package/dist/utils/clingo-facts.js +14 -7
  194. package/dist/utils/clingo-facts.js.map +1 -1
  195. package/dist/utils/clingo-parser.js +1 -1
  196. package/dist/utils/clingo-parser.js.map +1 -1
  197. package/dist/utils/constants.d.ts +2 -0
  198. package/dist/utils/constants.js +4 -0
  199. package/dist/utils/constants.js.map +1 -1
  200. package/dist/utils/csv.js +1 -1
  201. package/dist/utils/csv.js.map +1 -1
  202. package/dist/utils/resource-utils.d.ts +1 -0
  203. package/dist/utils/resource-utils.js +2 -1
  204. package/dist/utils/resource-utils.js.map +1 -1
  205. package/package.json +11 -11
  206. package/src/card-metadata-updater.ts +9 -7
  207. package/src/command-handler.ts +35 -23
  208. package/src/command-manager.ts +32 -19
  209. package/src/commands/create.ts +59 -160
  210. package/src/commands/edit.ts +16 -132
  211. package/src/commands/export.ts +71 -81
  212. package/src/commands/import.ts +26 -18
  213. package/src/commands/move.ts +143 -179
  214. package/src/commands/remove.ts +20 -59
  215. package/src/commands/rename.ts +45 -156
  216. package/src/commands/show.ts +153 -211
  217. package/src/commands/transition.ts +53 -58
  218. package/src/commands/update.ts +44 -23
  219. package/src/commands/validate.ts +108 -82
  220. package/src/containers/card-container.ts +200 -360
  221. package/src/containers/project/calculation-engine.ts +81 -105
  222. package/src/containers/project/card-cache.ts +497 -0
  223. package/src/containers/project/project-paths.ts +21 -13
  224. package/src/containers/project/resource-cache.ts +648 -0
  225. package/src/containers/project/resource-handler.ts +265 -0
  226. package/src/containers/project.ts +551 -693
  227. package/src/containers/template.ts +129 -142
  228. package/src/index.ts +1 -0
  229. package/src/interfaces/folder-content-interfaces.ts +14 -7
  230. package/src/interfaces/macros.ts +2 -0
  231. package/src/interfaces/project-interfaces.ts +14 -7
  232. package/src/interfaces/resource-interfaces.ts +30 -27
  233. package/src/macros/createCards/index.ts +1 -12
  234. package/src/macros/createCards/types.ts +46 -0
  235. package/src/macros/graph/index.ts +27 -52
  236. package/src/macros/graph/types.ts +24 -0
  237. package/src/macros/image/index.ts +50 -61
  238. package/src/macros/image/types.ts +39 -0
  239. package/src/macros/include/index.ts +6 -15
  240. package/src/macros/include/types.ts +32 -0
  241. package/src/macros/index.ts +2 -2
  242. package/src/macros/percentage/index.ts +1 -7
  243. package/src/macros/percentage/types.ts +32 -0
  244. package/src/macros/report/index.ts +4 -13
  245. package/src/macros/report/types.ts +20 -0
  246. package/src/macros/scoreCard/index.ts +1 -7
  247. package/src/macros/scoreCard/types.ts +32 -0
  248. package/src/macros/types.ts +48 -0
  249. package/src/macros/vega/index.ts +1 -4
  250. package/src/macros/vega/types.ts +21 -0
  251. package/src/macros/vegalite/index.ts +1 -4
  252. package/src/macros/vegalite/types.ts +22 -0
  253. package/src/macros/xref/index.ts +6 -20
  254. package/src/macros/xref/types.ts +20 -0
  255. package/src/module-manager.ts +79 -22
  256. package/src/project-settings.ts +84 -15
  257. package/src/resources/calculation-resource.ts +21 -91
  258. package/src/resources/card-type-resource.ts +74 -109
  259. package/src/resources/create-defaults.ts +3 -2
  260. package/src/resources/field-type-resource.ts +61 -104
  261. package/src/resources/file-resource.ts +33 -441
  262. package/src/resources/folder-resource.ts +130 -207
  263. package/src/resources/graph-model-resource.ts +36 -95
  264. package/src/resources/graph-view-resource.ts +28 -70
  265. package/src/resources/link-type-resource.ts +23 -53
  266. package/src/resources/report-resource.ts +34 -96
  267. package/src/resources/resource-object.ts +511 -66
  268. package/src/resources/template-resource.ts +32 -44
  269. package/src/resources/workflow-resource.ts +42 -85
  270. package/src/utils/card-utils.ts +217 -31
  271. package/src/utils/clingo-fact-builder.ts +28 -16
  272. package/src/utils/clingo-facts.ts +16 -7
  273. package/src/utils/clingo-parser.ts +1 -1
  274. package/src/utils/constants.ts +6 -0
  275. package/src/utils/csv.ts +1 -1
  276. package/src/utils/resource-utils.ts +2 -1
  277. package/dist/containers/project/resource-collector.d.ts +0 -87
  278. package/dist/containers/project/resource-collector.js +0 -337
  279. package/dist/containers/project/resource-collector.js.map +0 -1
  280. 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 { DefaultContent, FileResource, Project, resourceName, resourceNameToString, sortCards, } from './file-resource.js';
17
- import { filename, propertyName, } from '../interfaces/folder-content-interfaces.js';
18
- import { readJsonFile } from '../utils/json.js';
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
- export { DefaultContent, FileResource, Project, resourceNameToString, sortCards, };
21
+ import { ResourceObject } from './resource-object.js';
22
+ import { resourceName } from '../utils/resource-utils.js';
22
23
  /**
23
- * Folder type resource class. These are resources that have their own folders for content.
24
+ * Folder type resource class.
25
+ * These are resources that have their own folders for content.
24
26
  */
25
- export class FolderResource extends FileResource {
27
+ export class FolderResource extends ResourceObject {
26
28
  internalFolder = '';
27
- // Cache for content files to avoid repeated filesystem operations. Content is stored as string.
28
- contentFilesCache = new Map();
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
- * Renames resource metadata file and renames memory resident object 'name'.
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
- async showFileNames() {
136
- // Always first check cache...
137
- if (this.contentFilesCache.size > 0) {
138
- return Array.from(this.contentFilesCache.keys());
139
- }
140
- // ...cache miss, read from filesystem and populate cache
141
- const files = await readdir(this.internalFolder);
142
- const validFiles = files.filter((file) => VALID_FOLDER_RESOURCE_FILES.includes(file));
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
- return validFiles;
69
+ this.resourceContent = content;
148
70
  }
149
71
  /**
150
- * Updates content files from a content object.
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 updateContentFiles(contentFiles) {
154
- for (const [fileName, fileContent] of Object.entries(contentFiles)) {
155
- await this.updateFile(fileName, fileContent);
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 cache with new content
181
- this.contentFilesCache.set(fileName, changedContent);
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 key Key to modify
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(key, op) {
190
- if (this.isContentUpdateKey(key)) {
191
- const fileName = filename(key.subKey);
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
- await this.updateFile(fileName, fileContent);
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(key, op);
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, key, op);
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;AAWxE,OAAO,EACL,cAAc,EACd,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,oBAAoB,EACpB,SAAS,GACV,MAA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AAC,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 { GraphModel, GraphModelMetadata, GraphModelUpdateKey } from '../interfaces/resource-interfaces.js';
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 key Key to modify
44
+ * @param updateKey Key to modify
59
45
  * @param op Operation to perform on 'key'
60
46
  */
61
- update<Type>(key: GraphModelUpdateKey, op: Operation<Type>): Promise<void>;
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 { readdir } from 'node:fs/promises';
15
- import { extname, join } from 'node:path';
16
- import { DefaultContent, FolderResource, resourceNameToString, sortCards, } from './folder-resource.js';
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
- await this.calculationFile(),
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 calculationsFile = join(this.internalFolder, 'model.lp');
57
- await writeFileSafe(calculationsFile, `% add your calculations here for '${this.resourceName.identifier}'`, {
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 key Key to modify
77
+ * @param updateKey Key to modify
109
78
  * @param op Operation to perform on 'key'
110
79
  */
111
- async update(key, op) {
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, key, op);
84
+ await super.postUpdate(content, updateKey, op);
116
85
  return;
117
86
  }
118
- await super.update(key, op);
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 ?? (await super.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,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAQ1C,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAO9B,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD,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;QAEtE,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,YAAY,CAAC,YAAoB;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,KAAK,CAAC,gBAAgB,CAAC,YAA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,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 { GraphView, GraphViewMetadata, GraphViewUpdateKey } from '../interfaces/resource-interfaces.js';
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 key Key to modify
49
+ * @param updateKey Key to modify
59
50
  * @param op Operation to perform on 'key'
60
51
  */
61
- update<Type>(key: GraphViewUpdateKey, op: Operation<Type>): Promise<void>;
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
  }