@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
@@ -0,0 +1,32 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+
15
+ export interface PercentageOptions {
16
+ /**
17
+ * Title of percentage macro
18
+ */
19
+ title: string;
20
+ /**
21
+ * Percentage value
22
+ */
23
+ value: number;
24
+ /**
25
+ * Legend text below the macro
26
+ */
27
+ legend: string;
28
+ /**
29
+ * Color of the bar the represents the percentage
30
+ */
31
+ colour?: 'blue' | 'green' | 'yellow' | 'red' | 'orange' | 'purple';
32
+ }
@@ -18,14 +18,9 @@ import macroMetadata from './metadata.js';
18
18
  import BaseMacro from '../base-macro.js';
19
19
  import { validateJson } from '../../utils/validate.js';
20
20
  import type TaskQueue from '../task-queue.js';
21
- import { ReportResource } from '../../resources/report-resource.js';
22
- import { resourceName } from '../../utils/resource-utils.js';
23
21
  import { generateReportContent } from '../../utils/report.js';
24
22
  import { ClingoError } from '@cyberismo/node-clingo';
25
-
26
- export interface ReportOptions {
27
- name: string;
28
- }
23
+ import type { ReportOptions } from './types.js';
29
24
 
30
25
  class ReportMacro extends BaseMacro {
31
26
  constructor(tasks: TaskQueue) {
@@ -37,13 +32,9 @@ class ReportMacro extends BaseMacro {
37
32
 
38
33
  handleStatic = async (context: MacroGenerationContext, data: unknown) => {
39
34
  const options = this.validate(data);
40
- const resource = new ReportResource(
41
- context.project,
42
- resourceName(options.name),
43
- );
44
- const report = await resource.show();
45
-
46
- if (!report) throw new Error(`Report ${options.name} does not exist`);
35
+ const report = context.project.resources
36
+ .byType(options.name, 'reports')
37
+ .show();
47
38
 
48
39
  if (report.content.schema) {
49
40
  validateJson(options, {
@@ -0,0 +1,20 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+
15
+ export interface ReportOptions {
16
+ /**
17
+ * Name of the report
18
+ */
19
+ name: string;
20
+ }
@@ -19,13 +19,7 @@ import macroMetadata from './metadata.js';
19
19
  import BaseMacro from '../base-macro.js';
20
20
  import type TaskQueue from '../task-queue.js';
21
21
  import { scoreCard } from '../../svg/index.js';
22
-
23
- export interface ScoreCardOptions {
24
- value: number;
25
- legend?: string;
26
- title?: string;
27
- unit?: string;
28
- }
22
+ import type { ScoreCardOptions } from './types.js';
29
23
 
30
24
  class ScoreCardMacro extends BaseMacro {
31
25
  constructor(tasksQueue: TaskQueue) {
@@ -0,0 +1,32 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+
15
+ export interface ScoreCardOptions {
16
+ /**
17
+ * Value shown in score card
18
+ */
19
+ value: number;
20
+ /**
21
+ * Optional legend text
22
+ */
23
+ legend?: string;
24
+ /**
25
+ * Option title text
26
+ */
27
+ title?: string;
28
+ /**
29
+ * Option unit that is next to the value
30
+ */
31
+ unit?: string;
32
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+ import { CreateCardsOptions } from './createCards/types.js';
15
+ import { GraphOptions } from './graph/types.js';
16
+ import { ImageMacroOptions } from './image/types.js';
17
+ import { IncludeMacroOptions } from './include/types.js';
18
+ import { PercentageOptions } from './percentage/types.js';
19
+ import { ReportOptions } from './report/types.js';
20
+ import { ScoreCardOptions } from './scoreCard/types.js';
21
+ import { VegaMacroInput } from './vega/types.js';
22
+ import { VegaLiteMacroInput } from './vegalite/types.js';
23
+ import { XrefMacroOptions } from './xref/types.js';
24
+
25
+ export type AnyMacroOption =
26
+ | CreateCardsOptions
27
+ | GraphOptions
28
+ | ImageMacroOptions
29
+ | IncludeMacroOptions
30
+ | PercentageOptions
31
+ | ReportOptions
32
+ | ScoreCardOptions
33
+ | VegaMacroInput
34
+ | VegaLiteMacroInput
35
+ | XrefMacroOptions;
36
+
37
+ export {
38
+ CreateCardsOptions,
39
+ GraphOptions,
40
+ ImageMacroOptions,
41
+ IncludeMacroOptions,
42
+ PercentageOptions,
43
+ ReportOptions,
44
+ ScoreCardOptions,
45
+ VegaMacroInput,
46
+ VegaLiteMacroInput,
47
+ XrefMacroOptions,
48
+ };
@@ -21,10 +21,7 @@ import {
21
21
  validateMacroContent,
22
22
  } from '../index.js';
23
23
  import * as vega from 'vega';
24
-
25
- export interface VegaMacroInput {
26
- spec: vega.Spec;
27
- }
24
+ import type { VegaMacroInput } from './types.js';
28
25
 
29
26
  class VegaMacro extends BaseMacro {
30
27
  constructor(tasksQueue: TaskQueue) {
@@ -0,0 +1,21 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+ import type { Spec } from 'vega';
15
+
16
+ export interface VegaMacroInput {
17
+ /**
18
+ * Defines spec for vega
19
+ */
20
+ spec: Spec;
21
+ }
@@ -16,10 +16,7 @@ import macroMetadata from './metadata.js';
16
16
  import type TaskQueue from '../task-queue.js';
17
17
  import * as vegaLite from 'vega-lite';
18
18
  import { createMacro, validateMacroContent } from '../index.js';
19
-
20
- export interface VegaLiteMacroInput {
21
- spec: vegaLite.TopLevelSpec;
22
- }
19
+ import type { VegaLiteMacroInput } from './types.js';
23
20
 
24
21
  class VegaLiteMacro extends BaseMacro {
25
22
  constructor(tasksQueue: TaskQueue) {
@@ -0,0 +1,22 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+
15
+ import type { TopLevelSpec } from 'vega-lite';
16
+
17
+ export interface VegaLiteMacroInput {
18
+ /**
19
+ * Defines spec for vega-lite
20
+ */
21
+ spec: TopLevelSpec;
22
+ }
@@ -17,10 +17,7 @@ import type { MacroGenerationContext } from '../../interfaces/macros.js';
17
17
  import macroMetadata from './metadata.js';
18
18
  import BaseMacro from '../base-macro.js';
19
19
  import type TaskQueue from '../task-queue.js';
20
-
21
- export interface XrefMacroOptions {
22
- cardKey: string;
23
- }
20
+ import type { XrefMacroOptions } from './types.js';
24
21
 
25
22
  export default class XrefMacro extends BaseMacro {
26
23
  constructor(tasksQueue: TaskQueue) {
@@ -36,7 +33,7 @@ export default class XrefMacro extends BaseMacro {
36
33
  input: unknown,
37
34
  ): Promise<string> => {
38
35
  const options = this.validate(input);
39
- const card = await this.getCard(options.cardKey, context);
36
+ const card = this.getCard(options.cardKey, context);
40
37
 
41
38
  if (!card || !card.metadata) {
42
39
  throw new Error(`Card key ${options.cardKey} not found`);
@@ -48,23 +45,12 @@ export default class XrefMacro extends BaseMacro {
48
45
 
49
46
  handleInject = async (context: MacroGenerationContext, input: unknown) => {
50
47
  const options = this.validate(input);
51
- const card = await this.getCard(options.cardKey, context);
52
-
53
- if (!card || !card.metadata) {
54
- throw new Error(`Card key ${options.cardKey} not found`);
55
- }
56
-
57
- return `xref:${options.cardKey}.adoc[${card.metadata.title}]`;
48
+ const card = this.getCard(options.cardKey, context);
49
+ return `xref:${options.cardKey}.adoc[${card?.metadata?.title}]`;
58
50
  };
59
51
 
60
- private async getCard(cardKey: string, context: MacroGenerationContext) {
61
- const card = await context.project.cardDetailsById(cardKey, {
62
- metadata: true,
63
- });
64
- if (!card || !card.metadata) {
65
- throw new Error(`Card key ${cardKey} not found`);
66
- }
67
- return card;
52
+ private getCard(cardKey: string, context: MacroGenerationContext) {
53
+ return context.project.findCard(cardKey);
68
54
  }
69
55
 
70
56
  private validate(input: unknown): XrefMacroOptions {
@@ -0,0 +1,20 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+
15
+ export interface XrefMacroOptions {
16
+ /**
17
+ * Card of the card being referenced
18
+ */
19
+ cardKey: string;
20
+ }
@@ -26,7 +26,7 @@ import { Project } from './containers/project.js';
26
26
  import type { ProjectConfiguration } from './project-settings.js';
27
27
  import { ProjectPaths } from './containers/project/project-paths.js';
28
28
  import { readJsonFile } from './utils/json.js';
29
- import { Validate } from './commands/index.js';
29
+ import { Validate } from './commands/validate.js';
30
30
 
31
31
  const FILE_PROTOCOL = 'file:';
32
32
  const HTTPS_PROTOCOL = 'https:';
@@ -54,7 +54,7 @@ export class ModuleManager {
54
54
  await copyDir(sourcePath, destinationPath);
55
55
 
56
56
  // Update the resources.
57
- await this.project.collectModuleResources();
57
+ this.project.resources.changedModules();
58
58
  }
59
59
 
60
60
  // Creates a map of what dependencies each module depend from.
@@ -213,13 +213,11 @@ export class ModuleManager {
213
213
 
214
214
  // Fetches direct dependencies of a module.
215
215
  private async dependencies(moduleName: string): Promise<Set<string>> {
216
- const allModules = await this.project.modules();
217
- if (!allModules) return new Set();
218
- const module = allModules.find((m) => m.name === moduleName);
216
+ const module = await this.project.module(moduleName);
219
217
  if (!module) {
220
218
  throw new Error(`Module '${moduleName}' not found`);
221
219
  }
222
- const modulePath = join(module.path, module.name, 'cardsConfig.json');
220
+ const modulePath = join(module.path, 'cardsConfig.json');
223
221
  const moduleConfiguration = (await readJsonFile(
224
222
  modulePath,
225
223
  )) as ProjectConfiguration;
@@ -287,7 +285,7 @@ export class ModuleManager {
287
285
 
288
286
  // Imports from a given folder. Is used both for .temp/<module name> and file locations.
289
287
  private async importFromFolder(path: string, name: string) {
290
- await this.importFileModule(path);
288
+ await this.importFileModule(path, undefined, true); // Skip validation during updates
291
289
  console.log(
292
290
  `... Imported module '${name}' to '${this.project.configuration.name}'`,
293
291
  );
@@ -309,10 +307,10 @@ export class ModuleManager {
309
307
 
310
308
  // Collect modules that could be removed from .cards/modules when
311
309
  // 'moduleName' is removed.
312
- private async orphanedModules(
310
+ private orphanedModules(
313
311
  dependencies: DependencyGraph,
314
312
  moduleName: string,
315
- ): Promise<string[]> {
313
+ ): string[] {
316
314
  const projectModules = this.project.configuration.modules;
317
315
  const removableTransientModules: string[] = [];
318
316
  if (dependencies.has(moduleName)) {
@@ -361,6 +359,9 @@ export class ModuleManager {
361
359
  try {
362
360
  await this.removeModuleFiles(module.name);
363
361
  console.log(`... Removed imported module '${module.name}'`);
362
+
363
+ // Refresh module resources in cache after filesystem removal to avoid stale prefixes
364
+ this.project.resources.changedModules();
364
365
  } catch (error) {
365
366
  if (error instanceof Error)
366
367
  console.error(
@@ -479,7 +480,11 @@ export class ModuleManager {
479
480
  }
480
481
 
481
482
  // Updates modules in the project.
482
- private async update(module?: ModuleSetting, credentials?: Credentials) {
483
+ private async update(
484
+ module?: ModuleSetting,
485
+ credentials?: Credentials,
486
+ skipModules?: Set<string>,
487
+ ) {
483
488
  // Prints dots every half second so that user knows that something is ongoing
484
489
  function start() {
485
490
  console.log('... Collecting unique modules. This takes a moment.');
@@ -514,22 +519,46 @@ export class ModuleManager {
514
519
  uniqueModules.map((item) => item.name),
515
520
  );
516
521
 
522
+ // Filter out modules that are already imported
523
+ const modulesToImport = skipModules
524
+ ? uniqueModules.filter((module) => !skipModules.has(module.name))
525
+ : uniqueModules;
526
+
527
+ if (
528
+ skipModules &&
529
+ skipModules.size > 0 &&
530
+ modulesToImport.length < uniqueModules.length
531
+ ) {
532
+ const skippedModules = uniqueModules
533
+ .filter((module) => skipModules.has(module.name))
534
+ .map((m) => m.name)
535
+ .join(', ');
536
+ console.log(
537
+ `... Skipping already imported module(s): ${skippedModules}`,
538
+ );
539
+ }
540
+
517
541
  // Update modules parallel.
518
542
  const promises: Promise<void>[] = [];
519
- uniqueModules.forEach((module) =>
543
+ modulesToImport.forEach((module) =>
520
544
  promises.push(this.handleModule(module)),
521
545
  );
522
546
  await Promise.all(promises);
523
547
  await deleteDir(this.tempModulesDir);
524
- await this.project.collectModuleResources();
548
+ this.project.resources.changedModules();
525
549
  }
526
550
  }
527
551
 
528
552
  // Checks that module prefix is not in use in the project
529
- private async validatePrefix(modulePrefix: string) {
553
+ // Optionally skip check for modules that are already imported (during updates)
554
+ private validatePrefix(modulePrefix: string, skipIfExists = false) {
530
555
  // Do not allow modules with same prefixes.
531
- const currentlyUsedPrefixes = await this.project.projectPrefixes();
556
+ const currentlyUsedPrefixes = this.project.projectPrefixes();
532
557
  if (currentlyUsedPrefixes.includes(modulePrefix)) {
558
+ // If skipIfExists is true, allow re-importing modules that are already present
559
+ if (skipIfExists) {
560
+ return;
561
+ }
533
562
  throw new Error(
534
563
  `Imported project has a prefix '${modulePrefix}' that is already used in the project. Cannot import from module.`,
535
564
  );
@@ -540,8 +569,14 @@ export class ModuleManager {
540
569
  * Imports module from local file path.
541
570
  * @param source Path to import from.
542
571
  * @param destination is this really needed???
572
+ * @param skipValidation Skip prefix validation (used during updates)
573
+ * @returns Module prefix of the imported module.
543
574
  */
544
- public async importFileModule(source: string, destination?: string) {
575
+ public async importFileModule(
576
+ source: string,
577
+ destination?: string,
578
+ skipValidation = false,
579
+ ) {
545
580
  if (!Validate.validateFolder(source)) {
546
581
  throw new Error(
547
582
  `Input validation error: folder name is invalid '${source}'`,
@@ -558,6 +593,7 @@ export class ModuleManager {
558
593
  );
559
594
  }
560
595
  const sourceProject = new Project(source);
596
+ await sourceProject.populateCaches();
561
597
  const modulePrefix = sourceProject.projectPrefix;
562
598
  const destinationPath = join(
563
599
  this.project.paths.modulesFolder,
@@ -565,7 +601,7 @@ export class ModuleManager {
565
601
  );
566
602
  const sourcePath = sourceProject.paths.resourcesFolder;
567
603
 
568
- await this.validatePrefix(modulePrefix);
604
+ this.validatePrefix(modulePrefix, skipValidation);
569
605
 
570
606
  // Copy files.
571
607
  await this.addFileContents(sourcePath, destinationPath);
@@ -577,12 +613,14 @@ export class ModuleManager {
577
613
  * @param source Git URL to import from.
578
614
  * @param options Modules setting options.
579
615
  * @param credentials Credentials for private repositories.
616
+ * @param skipValidation Skip prefix validation (used during updates)
580
617
  * @returns module prefix as defined in its CardsConfig.json
581
618
  */
582
619
  public async importGitModule(
583
620
  source: string,
584
621
  options?: ModuleSettingOptions,
585
622
  credentials?: Credentials,
623
+ skipValidation = false,
586
624
  ) {
587
625
  const clonedName = await this.clone(
588
626
  {
@@ -595,7 +633,7 @@ export class ModuleManager {
595
633
  );
596
634
  const clonePath = join(this.tempModulesDir, clonedName);
597
635
  const modulePrefix = (await this.configuration(clonePath)).cardKeyPrefix;
598
- await this.validatePrefix(modulePrefix);
636
+ this.validatePrefix(modulePrefix, skipValidation);
599
637
 
600
638
  const sourcePath = new ProjectPaths(clonePath).resourcesFolder;
601
639
  const destinationPath = join(
@@ -611,6 +649,7 @@ export class ModuleManager {
611
649
  * If module is not used by any other modules, then will remove the module from disk as well.
612
650
  * Otherwise, only updates project configuration.
613
651
  * @param moduleName Name of the module to remove
652
+ * @throws If module was not found.
614
653
  */
615
654
  public async removeModule(moduleName: string) {
616
655
  const projectModules = this.project.configuration.modules;
@@ -625,7 +664,7 @@ export class ModuleManager {
625
664
  // but modules under .cards/modules must be checked not to be used by
626
665
  // other modules.
627
666
  if (this.canBeRemoved(dependencies, moduleName)) {
628
- const orphans = await this.orphanedModules(dependencies, moduleName);
667
+ const orphans = this.orphanedModules(dependencies, moduleName);
629
668
  await deleteDir(module.path);
630
669
  for (const moduleToDelete of orphans) {
631
670
  const modulePath = join(
@@ -634,19 +673,37 @@ export class ModuleManager {
634
673
  );
635
674
  await deleteDir(modulePath);
636
675
  }
637
- await this.project.collectModuleResources();
638
676
  }
639
- await this.project.configuration.removeModule(moduleName);
677
+ await this.project.removeModule(moduleName);
678
+ }
679
+
680
+ /**
681
+ * Updates dependencies for a module without re-importing the module itself.
682
+ * Used during module import to fetch dependencies after the main module is already imported.
683
+ * @param module Module whose dependencies should be updated.
684
+ * @param credentials Optional credentials for private repositories.
685
+ * @returns Module prefix as defined in its CardsConfig.json
686
+ */
687
+ public async updateDependencies(
688
+ module: ModuleSetting,
689
+ credentials?: Credentials,
690
+ ) {
691
+ return this.update(module, credentials, new Set([module.name]));
640
692
  }
641
693
 
642
694
  /**
643
695
  * Imports module from a local file path or a git URL.
644
696
  * @param module Module to update. If not provided, updates all modules.
645
697
  * @param credentials Optional credentials for private repositories.
698
+ * @param skipModules Optional set of module names to skip during import.
646
699
  * @returns Module prefix as defined in its CardsConfig.json
647
700
  */
648
- public async updateModule(module: ModuleSetting, credentials?: Credentials) {
649
- return this.update(module, credentials);
701
+ public async updateModule(
702
+ module: ModuleSetting,
703
+ credentials?: Credentials,
704
+ skipModules?: Set<string>,
705
+ ) {
706
+ return this.update(module, credentials, skipModules);
650
707
  }
651
708
 
652
709
  /**