@cyberismo/data-handler 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/dist/card-metadata-updater.js +1 -3
  2. package/dist/card-metadata-updater.js.map +1 -1
  3. package/dist/command-handler.js +13 -17
  4. package/dist/command-handler.js.map +1 -1
  5. package/dist/command-manager.d.ts +1 -1
  6. package/dist/command-manager.js +4 -3
  7. package/dist/command-manager.js.map +1 -1
  8. package/dist/commands/create.d.ts +3 -3
  9. package/dist/commands/create.js +20 -81
  10. package/dist/commands/create.js.map +1 -1
  11. package/dist/commands/edit.d.ts +12 -25
  12. package/dist/commands/edit.js +25 -74
  13. package/dist/commands/edit.js.map +1 -1
  14. package/dist/commands/export.js +4 -17
  15. package/dist/commands/export.js.map +1 -1
  16. package/dist/commands/fetch.js +2 -1
  17. package/dist/commands/fetch.js.map +1 -1
  18. package/dist/commands/import.js +3 -5
  19. package/dist/commands/import.js.map +1 -1
  20. package/dist/commands/move.d.ts +1 -2
  21. package/dist/commands/move.js +108 -146
  22. package/dist/commands/move.js.map +1 -1
  23. package/dist/commands/remove.js +15 -49
  24. package/dist/commands/remove.js.map +1 -1
  25. package/dist/commands/rename.d.ts +1 -0
  26. package/dist/commands/rename.js +13 -7
  27. package/dist/commands/rename.js.map +1 -1
  28. package/dist/commands/show.d.ts +7 -25
  29. package/dist/commands/show.js +39 -113
  30. package/dist/commands/show.js.map +1 -1
  31. package/dist/commands/transition.js +27 -30
  32. package/dist/commands/transition.js.map +1 -1
  33. package/dist/commands/update.d.ts +5 -3
  34. package/dist/commands/update.js +19 -5
  35. package/dist/commands/update.js.map +1 -1
  36. package/dist/commands/validate.d.ts +3 -3
  37. package/dist/commands/validate.js +20 -27
  38. package/dist/commands/validate.js.map +1 -1
  39. package/dist/containers/card-container.d.ts +87 -24
  40. package/dist/containers/card-container.js +183 -279
  41. package/dist/containers/card-container.js.map +1 -1
  42. package/dist/containers/project/calculation-engine.d.ts +6 -0
  43. package/dist/containers/project/calculation-engine.js +36 -29
  44. package/dist/containers/project/calculation-engine.js.map +1 -1
  45. package/dist/containers/project/card-cache.d.ts +146 -0
  46. package/dist/containers/project/card-cache.js +411 -0
  47. package/dist/containers/project/card-cache.js.map +1 -0
  48. package/dist/containers/project/resource-collector.d.ts +24 -1
  49. package/dist/containers/project/resource-collector.js +8 -1
  50. package/dist/containers/project/resource-collector.js.map +1 -1
  51. package/dist/containers/project.d.ts +119 -84
  52. package/dist/containers/project.js +423 -253
  53. package/dist/containers/project.js.map +1 -1
  54. package/dist/containers/template.d.ts +15 -31
  55. package/dist/containers/template.js +97 -104
  56. package/dist/containers/template.js.map +1 -1
  57. package/dist/index.d.ts +1 -0
  58. package/dist/index.js +1 -0
  59. package/dist/index.js.map +1 -1
  60. package/dist/interfaces/folder-content-interfaces.d.ts +12 -5
  61. package/dist/interfaces/folder-content-interfaces.js +5 -3
  62. package/dist/interfaces/folder-content-interfaces.js.map +1 -1
  63. package/dist/interfaces/macros.d.ts +1 -0
  64. package/dist/interfaces/macros.js +1 -1
  65. package/dist/interfaces/macros.js.map +1 -1
  66. package/dist/interfaces/project-interfaces.d.ts +16 -10
  67. package/dist/interfaces/project-interfaces.js +10 -8
  68. package/dist/interfaces/project-interfaces.js.map +1 -1
  69. package/dist/interfaces/resource-interfaces.d.ts +21 -22
  70. package/dist/interfaces/resource-interfaces.js +3 -0
  71. package/dist/interfaces/resource-interfaces.js.map +1 -1
  72. package/dist/macros/common.d.ts +10 -10
  73. package/dist/macros/createCards/index.d.ts +0 -13
  74. package/dist/macros/createCards/index.js.map +1 -1
  75. package/dist/macros/createCards/types.d.ts +44 -0
  76. package/dist/macros/createCards/types.js +15 -0
  77. package/dist/macros/createCards/types.js.map +1 -0
  78. package/dist/macros/graph/index.d.ts +2 -6
  79. package/dist/macros/graph/index.js +2 -2
  80. package/dist/macros/graph/index.js.map +1 -1
  81. package/dist/macros/graph/types.d.ts +23 -0
  82. package/dist/macros/graph/types.js +15 -0
  83. package/dist/macros/graph/types.js.map +1 -0
  84. package/dist/macros/image/index.d.ts +8 -16
  85. package/dist/macros/image/index.js +36 -33
  86. package/dist/macros/image/index.js.map +1 -1
  87. package/dist/macros/image/types.d.ts +38 -0
  88. package/dist/macros/image/types.js +15 -0
  89. package/dist/macros/image/types.js.map +1 -0
  90. package/dist/macros/include/index.d.ts +1 -6
  91. package/dist/macros/include/index.js +4 -7
  92. package/dist/macros/include/index.js.map +1 -1
  93. package/dist/macros/include/types.d.ts +31 -0
  94. package/dist/macros/include/types.js +15 -0
  95. package/dist/macros/include/types.js.map +1 -0
  96. package/dist/macros/percentage/index.d.ts +0 -6
  97. package/dist/macros/percentage/index.js.map +1 -1
  98. package/dist/macros/percentage/types.d.ts +31 -0
  99. package/dist/macros/percentage/types.js +15 -0
  100. package/dist/macros/percentage/types.js.map +1 -0
  101. package/dist/macros/report/index.d.ts +0 -3
  102. package/dist/macros/report/index.js.map +1 -1
  103. package/dist/macros/report/types.d.ts +19 -0
  104. package/dist/macros/report/types.js +15 -0
  105. package/dist/macros/report/types.js.map +1 -0
  106. package/dist/macros/scoreCard/index.d.ts +0 -6
  107. package/dist/macros/scoreCard/index.js.map +1 -1
  108. package/dist/macros/scoreCard/types.d.ts +31 -0
  109. package/dist/macros/scoreCard/types.js +15 -0
  110. package/dist/macros/scoreCard/types.js.map +1 -0
  111. package/dist/macros/types.d.ts +25 -0
  112. package/dist/macros/types.js +2 -0
  113. package/dist/macros/types.js.map +1 -0
  114. package/dist/macros/vega/index.d.ts +0 -4
  115. package/dist/macros/vega/index.js.map +1 -1
  116. package/dist/macros/vega/types.d.ts +20 -0
  117. package/dist/macros/vega/types.js +2 -0
  118. package/dist/macros/vega/types.js.map +1 -0
  119. package/dist/macros/vegalite/index.d.ts +0 -4
  120. package/dist/macros/vegalite/index.js.map +1 -1
  121. package/dist/macros/vegalite/types.d.ts +20 -0
  122. package/dist/macros/vegalite/types.js +15 -0
  123. package/dist/macros/vegalite/types.js.map +1 -0
  124. package/dist/macros/xref/index.d.ts +0 -3
  125. package/dist/macros/xref/index.js +5 -14
  126. package/dist/macros/xref/index.js.map +1 -1
  127. package/dist/macros/xref/types.d.ts +19 -0
  128. package/dist/macros/xref/types.js +15 -0
  129. package/dist/macros/xref/types.js.map +1 -0
  130. package/dist/module-manager.js +4 -4
  131. package/dist/module-manager.js.map +1 -1
  132. package/dist/project-settings.js.map +1 -1
  133. package/dist/resources/calculation-resource.d.ts +43 -0
  134. package/dist/resources/calculation-resource.js +75 -0
  135. package/dist/resources/calculation-resource.js.map +1 -0
  136. package/dist/resources/card-type-resource.d.ts +4 -21
  137. package/dist/resources/card-type-resource.js +13 -44
  138. package/dist/resources/card-type-resource.js.map +1 -1
  139. package/dist/resources/create-defaults.d.ts +13 -6
  140. package/dist/resources/create-defaults.js +19 -5
  141. package/dist/resources/create-defaults.js.map +1 -1
  142. package/dist/resources/field-type-resource.d.ts +4 -21
  143. package/dist/resources/field-type-resource.js +14 -38
  144. package/dist/resources/field-type-resource.js.map +1 -1
  145. package/dist/resources/file-resource.d.ts +12 -29
  146. package/dist/resources/file-resource.js +19 -287
  147. package/dist/resources/file-resource.js.map +1 -1
  148. package/dist/resources/folder-resource.d.ts +32 -51
  149. package/dist/resources/folder-resource.js +68 -96
  150. package/dist/resources/folder-resource.js.map +1 -1
  151. package/dist/resources/graph-model-resource.d.ts +5 -33
  152. package/dist/resources/graph-model-resource.js +8 -61
  153. package/dist/resources/graph-model-resource.js.map +1 -1
  154. package/dist/resources/graph-view-resource.d.ts +5 -28
  155. package/dist/resources/graph-view-resource.js +6 -45
  156. package/dist/resources/graph-view-resource.js.map +1 -1
  157. package/dist/resources/link-type-resource.d.ts +4 -21
  158. package/dist/resources/link-type-resource.js +6 -31
  159. package/dist/resources/link-type-resource.js.map +1 -1
  160. package/dist/resources/report-resource.d.ts +5 -17
  161. package/dist/resources/report-resource.js +6 -44
  162. package/dist/resources/report-resource.js.map +1 -1
  163. package/dist/resources/resource-object.d.ts +58 -23
  164. package/dist/resources/resource-object.js +307 -26
  165. package/dist/resources/resource-object.js.map +1 -1
  166. package/dist/resources/template-resource.d.ts +4 -15
  167. package/dist/resources/template-resource.js +10 -25
  168. package/dist/resources/template-resource.js.map +1 -1
  169. package/dist/resources/workflow-resource.d.ts +4 -23
  170. package/dist/resources/workflow-resource.js +12 -38
  171. package/dist/resources/workflow-resource.js.map +1 -1
  172. package/dist/utils/card-utils.d.ts +69 -19
  173. package/dist/utils/card-utils.js +179 -30
  174. package/dist/utils/card-utils.js.map +1 -1
  175. package/dist/utils/clingo-facts.js +11 -3
  176. package/dist/utils/clingo-facts.js.map +1 -1
  177. package/dist/utils/clingo-parser.js +1 -1
  178. package/dist/utils/clingo-parser.js.map +1 -1
  179. package/dist/utils/constants.d.ts +2 -0
  180. package/dist/utils/constants.js +5 -0
  181. package/dist/utils/constants.js.map +1 -1
  182. package/dist/utils/csv.js +1 -1
  183. package/dist/utils/csv.js.map +1 -1
  184. package/dist/utils/error-utils.d.ts +34 -0
  185. package/dist/utils/error-utils.js +56 -0
  186. package/dist/utils/error-utils.js.map +1 -0
  187. package/dist/utils/log-utils.d.ts +0 -27
  188. package/dist/utils/log-utils.js +0 -58
  189. package/dist/utils/log-utils.js.map +1 -1
  190. package/dist/utils/user-preferences.js +6 -3
  191. package/dist/utils/user-preferences.js.map +1 -1
  192. package/package.json +5 -5
  193. package/src/card-metadata-updater.ts +3 -5
  194. package/src/command-handler.ts +14 -19
  195. package/src/command-manager.ts +4 -3
  196. package/src/commands/create.ts +28 -112
  197. package/src/commands/edit.ts +27 -118
  198. package/src/commands/export.ts +8 -29
  199. package/src/commands/fetch.ts +2 -1
  200. package/src/commands/import.ts +4 -6
  201. package/src/commands/move.ts +144 -179
  202. package/src/commands/remove.ts +12 -54
  203. package/src/commands/rename.ts +22 -7
  204. package/src/commands/show.ts +51 -156
  205. package/src/commands/transition.ts +30 -33
  206. package/src/commands/update.ts +27 -9
  207. package/src/commands/validate.ts +22 -37
  208. package/src/containers/card-container.ts +200 -360
  209. package/src/containers/project/calculation-engine.ts +43 -33
  210. package/src/containers/project/card-cache.ts +497 -0
  211. package/src/containers/project/resource-collector.ts +9 -1
  212. package/src/containers/project.ts +533 -328
  213. package/src/containers/template.ts +109 -127
  214. package/src/index.ts +1 -0
  215. package/src/interfaces/folder-content-interfaces.ts +23 -5
  216. package/src/interfaces/macros.ts +2 -0
  217. package/src/interfaces/project-interfaces.ts +19 -10
  218. package/src/interfaces/resource-interfaces.ts +22 -24
  219. package/src/macros/createCards/index.ts +1 -12
  220. package/src/macros/createCards/types.ts +46 -0
  221. package/src/macros/graph/index.ts +3 -7
  222. package/src/macros/graph/types.ts +24 -0
  223. package/src/macros/image/index.ts +50 -61
  224. package/src/macros/image/types.ts +39 -0
  225. package/src/macros/include/index.ts +6 -15
  226. package/src/macros/include/types.ts +32 -0
  227. package/src/macros/percentage/index.ts +1 -7
  228. package/src/macros/percentage/types.ts +32 -0
  229. package/src/macros/report/index.ts +1 -4
  230. package/src/macros/report/types.ts +20 -0
  231. package/src/macros/scoreCard/index.ts +1 -7
  232. package/src/macros/scoreCard/types.ts +32 -0
  233. package/src/macros/types.ts +48 -0
  234. package/src/macros/vega/index.ts +1 -4
  235. package/src/macros/vega/types.ts +21 -0
  236. package/src/macros/vegalite/index.ts +1 -4
  237. package/src/macros/vegalite/types.ts +22 -0
  238. package/src/macros/xref/index.ts +6 -20
  239. package/src/macros/xref/types.ts +20 -0
  240. package/src/module-manager.ts +5 -5
  241. package/src/project-settings.ts +1 -1
  242. package/src/resources/calculation-resource.ts +101 -0
  243. package/src/resources/card-type-resource.ts +24 -59
  244. package/src/resources/create-defaults.ts +21 -5
  245. package/src/resources/field-type-resource.ts +22 -51
  246. package/src/resources/file-resource.ts +27 -403
  247. package/src/resources/folder-resource.ts +99 -125
  248. package/src/resources/graph-model-resource.ts +17 -74
  249. package/src/resources/graph-view-resource.ts +14 -54
  250. package/src/resources/link-type-resource.ts +13 -40
  251. package/src/resources/report-resource.ts +17 -57
  252. package/src/resources/resource-object.ts +454 -39
  253. package/src/resources/template-resource.ts +16 -29
  254. package/src/resources/workflow-resource.ts +26 -50
  255. package/src/utils/card-utils.ts +217 -31
  256. package/src/utils/clingo-facts.ts +13 -3
  257. package/src/utils/clingo-parser.ts +1 -1
  258. package/src/utils/constants.ts +7 -0
  259. package/src/utils/csv.ts +1 -1
  260. package/src/utils/error-utils.ts +62 -0
  261. package/src/utils/log-utils.ts +0 -68
  262. package/src/utils/user-preferences.ts +7 -3
@@ -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
+ }
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import BaseMacro from '../base-macro.js';
15
+ import type { GraphOptions } from './types.js';
15
16
  import { createImage, validateMacroContent } from '../index.js';
16
17
  import Handlebars from 'handlebars';
17
18
  import type { MacroGenerationContext } from '../../interfaces/macros.js';
@@ -25,12 +26,7 @@ import { ClingoError } from '@cyberismo/node-clingo';
25
26
  import { resourceFilePath } from '../../utils/resource-utils.js';
26
27
  import { resourceName } from '../../utils/resource-utils.js';
27
28
 
28
- export interface GraphOptions {
29
- model: string;
30
- view: string;
31
- }
32
-
33
- class ReportMacro extends BaseMacro {
29
+ class GraphMacro extends BaseMacro {
34
30
  constructor(tasksQueue: TaskQueue) {
35
31
  super(macroMetadata, tasksQueue);
36
32
  }
@@ -129,4 +125,4 @@ class ReportMacro extends BaseMacro {
129
125
  }
130
126
  }
131
127
 
132
- export default ReportMacro;
128
+ 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
+ }
@@ -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);
@@ -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
+ }
@@ -22,10 +22,7 @@ import { ReportResource } from '../../resources/report-resource.js';
22
22
  import { resourceName } from '../../utils/resource-utils.js';
23
23
  import { generateReportContent } from '../../utils/report.js';
24
24
  import { ClingoError } from '@cyberismo/node-clingo';
25
-
26
- export interface ReportOptions {
27
- name: string;
28
- }
25
+ import type { ReportOptions } from './types.js';
29
26
 
30
27
  class ReportMacro extends BaseMacro {
31
28
  constructor(tasks: TaskQueue) {
@@ -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
+ }