@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
@@ -17,6 +17,7 @@ import type {
17
17
  GraphViewContent,
18
18
  ReportContent,
19
19
  } from './folder-content-interfaces.js';
20
+ import type { ResourceType } from './project-interfaces.js';
20
21
 
21
22
  /**
22
23
  * Each resource represents a file (or a folder in some cases) with metadata stored
@@ -46,12 +47,6 @@ export interface CardType extends ResourceBaseMetadata {
46
47
  optionallyVisibleFields: string[];
47
48
  }
48
49
 
49
- // Base content update key interface
50
- export interface ContentUpdateKey {
51
- key: 'content';
52
- subKey: string; // Resource-specific types should narrow this
53
- }
54
-
55
50
  // Custom field
56
51
  // todo: merge with FieldType.
57
52
  export interface CustomField {
@@ -95,11 +90,6 @@ export interface GraphModel extends GraphModelMetadata {
95
90
  content: GraphModelContent;
96
91
  }
97
92
  export type GraphModelContentPropertyName = 'model';
98
- export interface GraphModelContentUpdateKey {
99
- key: 'content';
100
- subKey: GraphModelContentPropertyName;
101
- }
102
- export type GraphModelUpdateKey = string | GraphModelContentUpdateKey;
103
93
 
104
94
  // Graph view content.
105
95
  export interface GraphViewMetadata extends ResourceBaseMetadata {
@@ -109,11 +99,6 @@ export type GraphViewContentPropertyName = 'viewTemplate';
109
99
  export interface GraphView extends GraphViewMetadata {
110
100
  content: GraphViewContent;
111
101
  }
112
- export interface GraphViewContentUpdateKey {
113
- key: 'content';
114
- subKey: GraphViewContentPropertyName;
115
- }
116
- export type GraphViewUpdateKey = string | GraphViewContentUpdateKey;
117
102
 
118
103
  // Link content.
119
104
  export interface Link {
@@ -132,7 +117,7 @@ export interface LinkType extends ResourceBaseMetadata {
132
117
  }
133
118
 
134
119
  // Report resource.
135
- export interface Report extends ResourceBaseMetadata {
120
+ export interface Report extends ReportMetadata {
136
121
  content: ReportContent;
137
122
  }
138
123
 
@@ -141,11 +126,6 @@ export type ReportContentPropertyName =
141
126
  | 'contentTemplate'
142
127
  | 'queryTemplate'
143
128
  | 'schema';
144
- export interface ReportContentUpdateKey {
145
- key: 'content';
146
- subKey: ReportContentPropertyName;
147
- }
148
- export type ReportUpdateKey = string | ReportContentUpdateKey;
149
129
 
150
130
  // Metadata for report
151
131
  export interface ReportMetadata extends ResourceBaseMetadata {
@@ -161,17 +141,31 @@ export interface ResourceBaseMetadata {
161
141
  }
162
142
 
163
143
  // All resources metadata content.
164
- export type ResourceContent =
165
- | CalculationMetadata
144
+ export type AnyResourceContent =
145
+ | Calculation
166
146
  | CardType
167
147
  | FieldType
168
148
  | GraphModel
169
149
  | GraphView
170
150
  | LinkType
171
- | ReportMetadata
151
+ | Report
172
152
  | TemplateMetadata
173
153
  | Workflow;
174
154
 
155
+ export type ResourceContent<T extends ResourceType> = ResourceContentMap[T];
156
+
157
+ export type ResourceContentMap = {
158
+ calculations: Calculation;
159
+ cardTypes: CardType;
160
+ fieldTypes: FieldType;
161
+ graphModels: GraphModel;
162
+ graphViews: GraphView;
163
+ linkTypes: LinkType;
164
+ reports: Report;
165
+ templates: TemplateMetadata;
166
+ workflows: Workflow;
167
+ };
168
+
175
169
  // Template configuration details.
176
170
  export interface TemplateConfiguration extends TemplateMetadata {
177
171
  path: string;
@@ -182,9 +176,18 @@ export interface TemplateConfiguration extends TemplateMetadata {
182
176
  export interface TemplateMetadata extends ResourceBaseMetadata {
183
177
  category?: string;
184
178
  }
179
+ type ContentUpdateKey = { key: 'content'; subKey: string };
180
+ type PropertyUpdateKey<K extends string = string> = {
181
+ key: Exclude<K, 'content'>;
182
+ };
183
+
184
+ export type UpdateKey<K extends string = string> =
185
+ | ContentUpdateKey
186
+ | PropertyUpdateKey<K>;
185
187
 
186
- // Generic update key
187
- export type UpdateKey = string | ContentUpdateKey;
188
+ export function isContentKey(key: UpdateKey): key is ContentUpdateKey {
189
+ return key.key === 'content';
190
+ }
188
191
 
189
192
  // Workflow's json file content.
190
193
  export interface Workflow extends ResourceBaseMetadata {
@@ -12,23 +12,12 @@
12
12
 
13
13
  import { createHtmlPlaceholder, validateMacroContent } from '../index.js';
14
14
 
15
+ import type { CreateCardsOptions } from './types.js';
15
16
  import type { MacroGenerationContext } from '../../interfaces/macros.js';
16
17
  import macroMetadata from './metadata.js';
17
18
  import BaseMacro from '../base-macro.js';
18
19
  import type TaskQueue from '../task-queue.js';
19
20
 
20
- export interface CreateCardsOptions {
21
- buttonLabel: string;
22
- template: string;
23
- cardKey?: string;
24
- link?: {
25
- linkType: string;
26
- direction: string;
27
- cardKey: string;
28
- };
29
- [key: string]: string | undefined | { [key: string]: string | undefined };
30
- }
31
-
32
21
  class CreateCardsMacro extends BaseMacro {
33
22
  constructor(tasksQueue: TaskQueue) {
34
23
  super(macroMetadata, tasksQueue);
@@ -0,0 +1,46 @@
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 CreateCardsOptions {
16
+ /**
17
+ * Label of the button
18
+ */
19
+ buttonLabel: string;
20
+ /**
21
+ * Template to create cards from
22
+ */
23
+ template: string;
24
+ /**
25
+ * Allows forcing card creation under a certain card
26
+ */
27
+ cardKey?: string;
28
+
29
+ /**
30
+ * Allows creating a link at the same time
31
+ */
32
+ link?: {
33
+ /**
34
+ * Type of the link to create
35
+ */
36
+ linkType: string;
37
+ /**
38
+ * Direction of the link to create
39
+ */
40
+ direction: string;
41
+ /**
42
+ * Card key of target card of the link
43
+ */
44
+ cardKey: string;
45
+ };
46
+ }
@@ -14,23 +14,14 @@
14
14
  import BaseMacro from '../base-macro.js';
15
15
  import { createImage, validateMacroContent } from '../index.js';
16
16
  import Handlebars from 'handlebars';
17
- import type { MacroGenerationContext } from '../../interfaces/macros.js';
18
17
  import macroMetadata from './metadata.js';
19
- import { pathExists } from '../../utils/file-utils.js';
20
- import { readFile } from 'node:fs/promises';
21
- import { readFileSync } from 'node:fs';
22
- import type { Schema } from 'jsonschema';
23
- import type TaskQueue from '../task-queue.js';
24
18
  import { ClingoError } from '@cyberismo/node-clingo';
25
- import { resourceFilePath } from '../../utils/resource-utils.js';
26
- import { resourceName } from '../../utils/resource-utils.js';
27
19
 
28
- export interface GraphOptions {
29
- model: string;
30
- view: string;
31
- }
20
+ import type { GraphOptions } from './types.js';
21
+ import type { MacroGenerationContext } from '../../interfaces/macros.js';
22
+ import type TaskQueue from '../task-queue.js';
32
23
 
33
- class ReportMacro extends BaseMacro {
24
+ class GraphMacro extends BaseMacro {
34
25
  constructor(tasksQueue: TaskQueue) {
35
26
  super(macroMetadata, tasksQueue);
36
27
  }
@@ -42,40 +33,35 @@ class ReportMacro extends BaseMacro {
42
33
  handleStatic = async (context: MacroGenerationContext, input: unknown) => {
43
34
  const options = this.parseOptions(input, context);
44
35
 
45
- const modelLocation = resourceFilePath(
46
- context.project,
47
- resourceName(options.model),
48
- 'model.lp',
49
- );
50
- const viewLocation = resourceFilePath(
51
- context.project,
52
- resourceName(options.view),
53
- 'view.lp.hbs',
36
+ const modelResource = context.project.resources.byType(
37
+ options.model,
38
+ 'graphModels',
54
39
  );
40
+ const modelContent = modelResource.contentData();
55
41
 
56
- if (!pathExists(modelLocation)) {
57
- throw new Error(`Graph: Model ${options.model} does not exist`);
42
+ const viewResource = context.project.resources.byType(
43
+ options.view,
44
+ 'graphViews',
45
+ );
46
+ const viewContent = viewResource.contentData();
47
+ if (!viewContent.viewTemplate) {
48
+ throw new Error(`Graph: View ${options.view} has no view template`);
58
49
  }
59
50
 
60
- let viewContent = '';
61
- try {
62
- viewContent = await readFile(viewLocation, { encoding: 'utf-8' });
63
- } catch {
64
- throw new Error(`Graph: View ${options.view} does not exist`);
65
- }
66
51
  const handlebarsContext = {
67
52
  cardKey: context.cardKey,
68
53
  ...options,
69
54
  };
70
55
 
71
56
  const handlebars = Handlebars.create();
72
- const view = handlebars.compile(viewContent)(handlebarsContext);
57
+ const view = handlebars.compile(viewContent.viewTemplate)(
58
+ handlebarsContext,
59
+ );
73
60
 
74
- const modelContent = await readFile(modelLocation, { encoding: 'utf-8' });
75
61
  let result: string;
76
62
  try {
77
63
  result = await context.project.calculationEngine.runGraph(
78
- modelContent,
64
+ modelContent.model,
79
65
  view,
80
66
  context.context,
81
67
  );
@@ -102,24 +88,13 @@ class ReportMacro extends BaseMacro {
102
88
  ): GraphOptions {
103
89
  const options = validateMacroContent<GraphOptions>(this.metadata, input);
104
90
 
105
- let schema: Schema | null = null;
106
- try {
107
- schema = JSON.parse(
108
- readFileSync(
109
- resourceFilePath(
110
- context.project,
111
- resourceName(options.view),
112
- 'parameterSchema.json',
113
- ),
114
- { encoding: 'utf-8' },
115
- ),
116
- );
117
- } catch (err) {
118
- this.logger.trace(
119
- err,
120
- 'Graph schema not found or failed to read, skipping validation',
121
- );
122
- }
91
+ // Get schema from view resource content if available
92
+ const resource = context.project.resources.byType(
93
+ options.view,
94
+ 'graphViews',
95
+ );
96
+ const content = resource.contentData();
97
+ const schema = content.schema;
123
98
 
124
99
  if (schema) {
125
100
  validateMacroContent(this.metadata, input, schema);
@@ -129,4 +104,4 @@ class ReportMacro extends BaseMacro {
129
104
  }
130
105
  }
131
106
 
132
- export default ReportMacro;
107
+ export default GraphMacro;
@@ -0,0 +1,24 @@
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 GraphOptions {
16
+ /**
17
+ * Reference to the model that defines graph
18
+ */
19
+ model: string;
20
+ /**
21
+ * Reference to the view that defines the graph
22
+ */
23
+ view: string;
24
+ }
@@ -11,39 +11,64 @@
11
11
  License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
12
  */
13
13
 
14
- import { existsSync, readFileSync } from 'node:fs';
14
+ import { readFileSync } from 'node:fs';
15
15
  import { join } from 'node:path';
16
- import mime from 'mime-types';
17
16
 
17
+ import BaseMacro from '../base-macro.js';
18
+ import macroMetadata from './metadata.js';
18
19
  import { validateMacroContent } from '../index.js';
19
20
 
21
+ import type { ImageMacroOptions } from './types.js';
20
22
  import type { MacroGenerationContext } from '../../interfaces/macros.js';
21
- import macroMetadata from './metadata.js';
22
- import BaseMacro from '../base-macro.js';
23
23
  import type TaskQueue from '../task-queue.js';
24
24
 
25
- /**
26
- * Options for the image macro.
27
- * @param fileName - Name of the file to include.
28
- * @param cardKey - Key of the card to include the file from.
29
- * @param alt - Alternative text for the image.
30
- * @param title - Title of the image.
31
- */
32
- export interface ImageMacroOptions {
33
- fileName: string;
34
- cardKey?: string;
35
- alt?: string;
36
- title?: string;
37
- }
38
-
39
25
  /**
40
26
  * Macro for including images in the content
41
27
  */
42
28
  export default class ImageMacro extends BaseMacro {
29
+ /**
30
+ * Constructs ImageMacro instance.
31
+ * @param tasksQueue Tasks queue
32
+ */
43
33
  constructor(tasksQueue: TaskQueue) {
44
34
  super(macroMetadata, tasksQueue);
45
35
  }
46
36
 
37
+ // Gets card attachment.
38
+ private attachment(
39
+ context: MacroGenerationContext,
40
+ cardKey: string,
41
+ filename: string,
42
+ ) {
43
+ const card = context.project.findCard(cardKey);
44
+ const attachment =
45
+ card.attachments?.find((a) => a.fileName === filename) ?? undefined;
46
+ if (!attachment) {
47
+ throw new Error(
48
+ `Attachment file '${filename}' not found in card '${cardKey}'`,
49
+ );
50
+ }
51
+ return attachment;
52
+ }
53
+
54
+ private buildImageAttributes(options: ImageMacroOptions): string {
55
+ const attributes: string[] = [];
56
+
57
+ if (options.alt !== undefined) {
58
+ attributes.push(`alt="${options.alt}"`);
59
+ }
60
+
61
+ if (options.title !== undefined) {
62
+ attributes.push(`title="${options.title}"`);
63
+ }
64
+
65
+ return attributes.join(',');
66
+ }
67
+
68
+ private validate(input: unknown): ImageMacroOptions {
69
+ return validateMacroContent<ImageMacroOptions>(this.metadata, input);
70
+ }
71
+
47
72
  handleValidate = (_: MacroGenerationContext, input: unknown) => {
48
73
  this.validate(input);
49
74
  };
@@ -55,45 +80,27 @@ export default class ImageMacro extends BaseMacro {
55
80
  const options = this.validate(input);
56
81
  const cardKey = options.cardKey || context.cardKey;
57
82
 
58
- // Get the attachment folder path
59
- const attachmentFolder =
60
- await context.project.cardAttachmentFolder(cardKey);
61
-
62
- // Read the file and convert to base64
63
- const attachmentPath = join(attachmentFolder, options.fileName);
64
- if (!existsSync(attachmentPath)) {
65
- throw new Error(
66
- `Attachment file '${options.fileName}' not found in card '${cardKey}'`,
67
- );
68
- }
83
+ // Get the attachment
84
+ const cardAttachment = this.attachment(context, cardKey, options.fileName);
69
85
 
86
+ // Convert to base64
87
+ const attachmentPath = join(cardAttachment?.path, cardAttachment?.fileName);
70
88
  const fileBuffer = readFileSync(attachmentPath);
71
89
  const base64Data = fileBuffer.toString('base64');
72
90
 
73
- // Get mime type
74
- const mimeType = mime.lookup(attachmentPath) || 'application/octet-stream';
75
-
76
91
  // Build image attributes
77
92
  const attributes = this.buildImageAttributes(options);
78
93
 
79
94
  // Return as data URI for static mode (for export/PDF generation)
80
- return `image::data:${mimeType};base64,${base64Data}[${attributes}]`;
95
+ return `image::data:${cardAttachment.mimeType};base64,${base64Data}[${attributes}]`;
81
96
  };
82
97
 
83
98
  handleInject = async (context: MacroGenerationContext, input: unknown) => {
84
99
  const options = this.validate(input);
85
100
  const cardKey = options.cardKey || context.cardKey;
86
101
 
87
- // Verify that the card and attachment folder exist
88
- const attachmentFolder =
89
- await context.project.cardAttachmentFolder(cardKey);
90
-
91
- const attachmentPath = join(attachmentFolder, options.fileName);
92
- if (!existsSync(attachmentPath)) {
93
- throw new Error(
94
- `Attachment file '${options.fileName}' not found in card '${cardKey}'`,
95
- );
96
- }
102
+ // Just verify that the attachment exists.
103
+ this.attachment(context, cardKey, options.fileName);
97
104
 
98
105
  // Build image attributes
99
106
  const attributes = this.buildImageAttributes(options);
@@ -101,22 +108,4 @@ export default class ImageMacro extends BaseMacro {
101
108
  // In inject mode, always use the API path for consistency
102
109
  return `image::/api/cards/${cardKey}/a/${options.fileName}[${attributes}]`;
103
110
  };
104
-
105
- private buildImageAttributes(options: ImageMacroOptions): string {
106
- const attributes: string[] = [];
107
-
108
- if (options.alt !== undefined) {
109
- attributes.push(`alt="${options.alt}"`);
110
- }
111
-
112
- if (options.title !== undefined) {
113
- attributes.push(`title="${options.title}"`);
114
- }
115
-
116
- return attributes.join(',');
117
- }
118
-
119
- private validate(input: unknown): ImageMacroOptions {
120
- return validateMacroContent<ImageMacroOptions>(this.metadata, input);
121
- }
122
111
  }
@@ -0,0 +1,39 @@
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
+ /**
16
+ * Options for the image macro.
17
+ * @param fileName - Name of the file to include.
18
+ * @param cardKey - Key of the card to include the file from.
19
+ * @param alt - Alternative text for the image.
20
+ * @param title - Title of the image.
21
+ */
22
+ export interface ImageMacroOptions {
23
+ /**
24
+ * Filename of the image
25
+ */
26
+ fileName: string;
27
+ /**
28
+ * By default, image is assumed to be under the current card. You can override this behaviour
29
+ */
30
+ cardKey?: string;
31
+ /**
32
+ * Alt text
33
+ */
34
+ alt?: string;
35
+ /**
36
+ * Title for the image
37
+ */
38
+ title?: string;
39
+ }
@@ -13,19 +13,13 @@
13
13
 
14
14
  import { evaluateMacros, validateMacroContent } from '../index.js';
15
15
 
16
+ import type { IncludeMacroOptions } from './types.js';
16
17
  import type { MacroGenerationContext } from '../../interfaces/macros.js';
17
18
  import macroMetadata from './metadata.js';
18
19
  import BaseMacro from '../base-macro.js';
19
20
  import type TaskQueue from '../task-queue.js';
20
21
  import { MAX_LEVEL_OFFSET } from '../../utils/constants.js';
21
22
 
22
- export interface IncludeMacroOptions {
23
- cardKey: string;
24
- levelOffset?: string;
25
- title?: 'include' | 'exclude' | 'only';
26
- pageTitles?: 'normal' | 'discrete';
27
- }
28
-
29
23
  export default class IncludeMacro extends BaseMacro {
30
24
  constructor(tasksQueue: TaskQueue) {
31
25
  super(macroMetadata, tasksQueue);
@@ -46,18 +40,11 @@ export default class IncludeMacro extends BaseMacro {
46
40
  if (!options.pageTitles) {
47
41
  options.pageTitles = 'normal';
48
42
  }
49
- const card = await context.project.cardDetailsById(options.cardKey, {
50
- content: true,
51
- metadata: true,
52
- });
53
- if (!card) {
54
- throw new Error(`Card key ${options.cardKey} not found`);
55
- }
56
43
  const newContext = {
57
44
  ...context,
58
45
  cardKey: options.cardKey,
59
46
  };
60
-
47
+ const card = this.getCard(options.cardKey, context);
61
48
  const anchor = this.generateAnchor(options);
62
49
  const title = this.generateTitle(options, card.metadata?.title);
63
50
  const cardContent = await this.generateCardContent(
@@ -118,6 +105,10 @@ export default class IncludeMacro extends BaseMacro {
118
105
  return '';
119
106
  }
120
107
 
108
+ private getCard(cardKey: string, context: MacroGenerationContext) {
109
+ return context.project.findCard(cardKey);
110
+ }
111
+
121
112
  // Adjust asciidoc titles to match the level offset
122
113
  private adjustTitles(
123
114
  content: string,
@@ -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 IncludeMacroOptions {
16
+ /**
17
+ * Card key of the card being included
18
+ */
19
+ cardKey: string;
20
+ /**
21
+ * A positive number wil increase the level of headings and a negative alue will the level of headings in the included content
22
+ */
23
+ levelOffset?: string;
24
+ /**
25
+ * Determines behaviour with the title that is in card metadata
26
+ * include --> includes the title
27
+ * exclude --> excludes the title
28
+ * only --> includes title but does not import content
29
+ */
30
+ title?: 'include' | 'exclude' | 'only';
31
+ pageTitles?: 'normal' | 'discrete';
32
+ }
@@ -186,7 +186,7 @@ export function validateMacroContent<T>(
186
186
  * @param tasks - Tasks to register
187
187
  * @returns macro instances
188
188
  */
189
- export function registerMacros(
189
+ export async function registerMacros(
190
190
  instance: typeof Handlebars,
191
191
  context: MacroGenerationContext,
192
192
  tasks: TaskQueue,
@@ -242,7 +242,7 @@ export async function evaluateMacros(
242
242
  ) {
243
243
  const handlebars = Handlebars.create();
244
244
  const tasks = new TaskQueue();
245
- registerMacros(handlebars, context, tasks);
245
+ await registerMacros(handlebars, context, tasks);
246
246
  let result = content;
247
247
  while ((context.maxTries ?? 10) > 0) {
248
248
  await tasks.reset();
@@ -15,17 +15,11 @@ import { createImage, validateMacroContent } from '../index.js';
15
15
 
16
16
  import type { MacroGenerationContext } from '../../interfaces/macros.js';
17
17
  import macroMetadata from './metadata.js';
18
+ import type { PercentageOptions } from './types.js';
18
19
  import BaseMacro from '../base-macro.js';
19
20
  import type TaskQueue from '../task-queue.js';
20
21
  import { percentage } from '../../svg/index.js';
21
22
 
22
- export interface PercentageOptions {
23
- title: string;
24
- value: number;
25
- legend: string;
26
- colour?: 'blue' | 'green' | 'yellow' | 'red' | 'orange' | 'purple';
27
- }
28
-
29
23
  class PercentageMacro extends BaseMacro {
30
24
  constructor(tasksQueue: TaskQueue) {
31
25
  super(macroMetadata, tasksQueue);