@cyberismo/data-handler 0.0.7 → 0.0.9

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 (265) hide show
  1. package/dist/command-handler.d.ts +11 -2
  2. package/dist/command-handler.js +61 -18
  3. package/dist/command-handler.js.map +1 -1
  4. package/dist/command-manager.js +8 -8
  5. package/dist/command-manager.js.map +1 -1
  6. package/dist/commands/calculate.d.ts +7 -44
  7. package/dist/commands/calculate.js +8 -389
  8. package/dist/commands/calculate.js.map +1 -1
  9. package/dist/commands/create.d.ts +7 -4
  10. package/dist/commands/create.js +42 -15
  11. package/dist/commands/create.js.map +1 -1
  12. package/dist/commands/edit.d.ts +9 -3
  13. package/dist/commands/edit.js +33 -9
  14. package/dist/commands/edit.js.map +1 -1
  15. package/dist/commands/export.d.ts +13 -11
  16. package/dist/commands/export.js +80 -28
  17. package/dist/commands/export.js.map +1 -1
  18. package/dist/commands/import.d.ts +7 -0
  19. package/dist/commands/import.js +21 -2
  20. package/dist/commands/import.js.map +1 -1
  21. package/dist/commands/move.d.ts +11 -12
  22. package/dist/commands/move.js +12 -13
  23. package/dist/commands/move.js.map +1 -1
  24. package/dist/commands/remove.d.ts +2 -4
  25. package/dist/commands/remove.js +8 -16
  26. package/dist/commands/remove.js.map +1 -1
  27. package/dist/commands/rename.d.ts +1 -3
  28. package/dist/commands/rename.js +3 -6
  29. package/dist/commands/rename.js.map +1 -1
  30. package/dist/commands/show.d.ts +37 -5
  31. package/dist/commands/show.js +85 -7
  32. package/dist/commands/show.js.map +1 -1
  33. package/dist/commands/transition.d.ts +1 -3
  34. package/dist/commands/transition.js +3 -5
  35. package/dist/commands/transition.js.map +1 -1
  36. package/dist/commands/update.d.ts +5 -1
  37. package/dist/commands/update.js +7 -1
  38. package/dist/commands/update.js.map +1 -1
  39. package/dist/commands/validate.d.ts +7 -8
  40. package/dist/commands/validate.js +30 -35
  41. package/dist/commands/validate.js.map +1 -1
  42. package/dist/containers/card-container.d.ts +6 -0
  43. package/dist/containers/card-container.js +61 -0
  44. package/dist/containers/card-container.js.map +1 -1
  45. package/dist/containers/project/calculation-engine.d.ts +90 -0
  46. package/dist/containers/project/calculation-engine.js +402 -0
  47. package/dist/containers/project/calculation-engine.js.map +1 -0
  48. package/dist/containers/project/resource-collector.d.ts +2 -1
  49. package/dist/containers/project/resource-collector.js +41 -33
  50. package/dist/containers/project/resource-collector.js.map +1 -1
  51. package/dist/containers/project.d.ts +18 -6
  52. package/dist/containers/project.js +37 -72
  53. package/dist/containers/project.js.map +1 -1
  54. package/dist/containers/template.d.ts +5 -0
  55. package/dist/containers/template.js +9 -0
  56. package/dist/containers/template.js.map +1 -1
  57. package/dist/exceptions/index.d.ts +20 -0
  58. package/dist/exceptions/index.js +16 -0
  59. package/dist/exceptions/index.js.map +1 -1
  60. package/dist/index.d.ts +5 -2
  61. package/dist/index.js +5 -1
  62. package/dist/index.js.map +1 -1
  63. package/dist/interfaces/macros.d.ts +7 -2
  64. package/dist/interfaces/project-interfaces.d.ts +21 -0
  65. package/dist/interfaces/project-interfaces.js +4 -0
  66. package/dist/interfaces/project-interfaces.js.map +1 -1
  67. package/dist/interfaces/resource-interfaces.d.ts +1 -1
  68. package/dist/interfaces/resource-interfaces.js.map +1 -1
  69. package/dist/macros/base-macro.d.ts +2 -0
  70. package/dist/macros/base-macro.js +66 -19
  71. package/dist/macros/base-macro.js.map +1 -1
  72. package/dist/macros/common.d.ts +16 -9
  73. package/dist/macros/common.js +22 -9
  74. package/dist/macros/common.js.map +1 -1
  75. package/dist/macros/createCards/index.d.ts +1 -2
  76. package/dist/macros/createCards/index.js.map +1 -1
  77. package/dist/macros/graph/index.d.ts +1 -3
  78. package/dist/macros/graph/index.js +11 -9
  79. package/dist/macros/graph/index.js.map +1 -1
  80. package/dist/macros/image/index.d.ts +39 -0
  81. package/dist/macros/image/index.js +78 -0
  82. package/dist/macros/image/index.js.map +1 -0
  83. package/dist/macros/image/metadata.d.ts +18 -0
  84. package/dist/macros/image/metadata.js +22 -0
  85. package/dist/macros/image/metadata.js.map +1 -0
  86. package/dist/macros/include/index.d.ts +32 -0
  87. package/dist/macros/include/index.js +97 -0
  88. package/dist/macros/include/index.js.map +1 -0
  89. package/dist/macros/include/metadata.d.ts +15 -0
  90. package/dist/macros/include/metadata.js +19 -0
  91. package/dist/macros/include/metadata.js.map +1 -0
  92. package/dist/macros/index.d.ts +39 -31
  93. package/dist/macros/index.js +167 -73
  94. package/dist/macros/index.js.map +1 -1
  95. package/dist/macros/percentage/index.d.ts +29 -0
  96. package/dist/macros/percentage/index.js +36 -0
  97. package/dist/macros/percentage/index.js.map +1 -0
  98. package/dist/macros/percentage/metadata.d.ts +15 -0
  99. package/dist/macros/percentage/metadata.js +19 -0
  100. package/dist/macros/percentage/metadata.js.map +1 -0
  101. package/dist/macros/report/index.d.ts +2 -5
  102. package/dist/macros/report/index.js +20 -12
  103. package/dist/macros/report/index.js.map +1 -1
  104. package/dist/macros/scoreCard/index.d.ts +15 -15
  105. package/dist/macros/scoreCard/index.js +16 -17
  106. package/dist/macros/scoreCard/index.js.map +1 -1
  107. package/dist/macros/vega/index.d.ts +28 -0
  108. package/dist/macros/vega/index.js +27 -0
  109. package/dist/macros/vega/index.js.map +1 -0
  110. package/dist/macros/vega/metadata.d.ts +15 -0
  111. package/dist/macros/vega/metadata.js +7 -0
  112. package/dist/macros/vega/metadata.js.map +1 -0
  113. package/dist/macros/vegalite/index.d.ts +27 -0
  114. package/dist/macros/vegalite/index.js +27 -0
  115. package/dist/macros/vegalite/index.js.map +1 -0
  116. package/dist/macros/vegalite/metadata.d.ts +15 -0
  117. package/dist/macros/vegalite/metadata.js +7 -0
  118. package/dist/macros/vegalite/metadata.js.map +1 -0
  119. package/dist/macros/xref/index.d.ts +26 -0
  120. package/dist/macros/xref/index.js +53 -0
  121. package/dist/macros/xref/index.js.map +1 -0
  122. package/dist/macros/xref/metadata.d.ts +15 -0
  123. package/dist/macros/xref/metadata.js +19 -0
  124. package/dist/macros/xref/metadata.js.map +1 -0
  125. package/dist/module-manager.d.ts +17 -4
  126. package/dist/module-manager.js +192 -58
  127. package/dist/module-manager.js.map +1 -1
  128. package/dist/permissions/action-guard.d.ts +2 -2
  129. package/dist/permissions/action-guard.js +1 -1
  130. package/dist/permissions/action-guard.js.map +1 -1
  131. package/dist/project-settings.js +2 -8
  132. package/dist/project-settings.js.map +1 -1
  133. package/dist/resources/card-type-resource.d.ts +2 -0
  134. package/dist/resources/card-type-resource.js +63 -0
  135. package/dist/resources/card-type-resource.js.map +1 -1
  136. package/dist/resources/file-resource.d.ts +2 -0
  137. package/dist/resources/file-resource.js +12 -4
  138. package/dist/resources/file-resource.js.map +1 -1
  139. package/dist/resources/folder-resource.d.ts +19 -0
  140. package/dist/resources/folder-resource.js +51 -2
  141. package/dist/resources/folder-resource.js.map +1 -1
  142. package/dist/resources/graph-model-resource.js +1 -1
  143. package/dist/resources/graph-model-resource.js.map +1 -1
  144. package/dist/resources/graph-view-resource.js +1 -1
  145. package/dist/resources/graph-view-resource.js.map +1 -1
  146. package/dist/resources/report-resource.js +1 -1
  147. package/dist/resources/report-resource.js.map +1 -1
  148. package/dist/resources/resource-object.d.ts +8 -0
  149. package/dist/resources/resource-object.js +9 -0
  150. package/dist/resources/resource-object.js.map +1 -1
  151. package/dist/resources/template-resource.js +1 -1
  152. package/dist/resources/template-resource.js.map +1 -1
  153. package/dist/resources/workflow-resource.d.ts +2 -0
  154. package/dist/resources/workflow-resource.js +53 -9
  155. package/dist/resources/workflow-resource.js.map +1 -1
  156. package/dist/svg/index.d.ts +15 -0
  157. package/dist/svg/index.js +16 -0
  158. package/dist/svg/index.js.map +1 -0
  159. package/dist/svg/lib.d.ts +9 -0
  160. package/dist/svg/lib.js +26 -0
  161. package/dist/svg/lib.js.map +1 -0
  162. package/dist/svg/percentage.d.ts +25 -0
  163. package/dist/svg/percentage.js +90 -0
  164. package/dist/svg/percentage.js.map +1 -0
  165. package/dist/svg/scoreCard.d.ts +19 -0
  166. package/dist/svg/scoreCard.js +55 -0
  167. package/dist/svg/scoreCard.js.map +1 -0
  168. package/dist/types/queries.d.ts +8 -7
  169. package/dist/types/queries.js.map +1 -1
  170. package/dist/utils/card-utils.d.ts +6 -0
  171. package/dist/utils/card-utils.js +12 -0
  172. package/dist/utils/card-utils.js.map +1 -1
  173. package/dist/utils/clingo-facts.d.ts +2 -1
  174. package/dist/utils/clingo-facts.js +19 -2
  175. package/dist/utils/clingo-facts.js.map +1 -1
  176. package/dist/utils/clingo-parser.d.ts +1 -0
  177. package/dist/utils/clingo-parser.js +22 -100
  178. package/dist/utils/clingo-parser.js.map +1 -1
  179. package/dist/utils/constants.d.ts +7 -0
  180. package/dist/utils/constants.js +14 -0
  181. package/dist/utils/constants.js.map +1 -1
  182. package/dist/utils/csv.js.map +1 -1
  183. package/dist/utils/report.d.ts +17 -3
  184. package/dist/utils/report.js +38 -2
  185. package/dist/utils/report.js.map +1 -1
  186. package/dist/utils/resource-utils.d.ts +1 -0
  187. package/dist/utils/resource-utils.js +9 -0
  188. package/dist/utils/resource-utils.js.map +1 -1
  189. package/dist/utils/user-preferences.d.ts +1 -11
  190. package/dist/utils/user-preferences.js +30 -13
  191. package/dist/utils/user-preferences.js.map +1 -1
  192. package/dist/utils/validate.d.ts +2 -3
  193. package/dist/utils/validate.js +2 -2
  194. package/dist/utils/validate.js.map +1 -1
  195. package/package.json +8 -6
  196. package/src/command-handler.ts +96 -17
  197. package/src/command-manager.ts +8 -8
  198. package/src/commands/calculate.ts +11 -525
  199. package/src/commands/create.ts +53 -16
  200. package/src/commands/edit.ts +53 -11
  201. package/src/commands/export.ts +108 -34
  202. package/src/commands/import.ts +31 -2
  203. package/src/commands/move.ts +12 -15
  204. package/src/commands/remove.ts +10 -19
  205. package/src/commands/rename.ts +3 -12
  206. package/src/commands/show.ts +121 -8
  207. package/src/commands/transition.ts +3 -7
  208. package/src/commands/update.ts +6 -0
  209. package/src/commands/validate.ts +39 -47
  210. package/src/containers/card-container.ts +74 -0
  211. package/src/containers/project/calculation-engine.ts +535 -0
  212. package/src/containers/project/resource-collector.ts +45 -26
  213. package/src/containers/project.ts +66 -84
  214. package/src/containers/template.ts +16 -0
  215. package/src/exceptions/index.ts +36 -0
  216. package/src/index.ts +13 -2
  217. package/src/interfaces/macros.ts +7 -1
  218. package/src/interfaces/project-interfaces.ts +27 -0
  219. package/src/interfaces/resource-interfaces.ts +1 -0
  220. package/src/macros/base-macro.ts +89 -25
  221. package/src/macros/common.ts +22 -9
  222. package/src/macros/createCards/index.ts +1 -2
  223. package/src/macros/graph/index.ts +17 -12
  224. package/src/macros/image/index.ts +121 -0
  225. package/src/macros/image/metadata.ts +25 -0
  226. package/src/macros/include/index.ts +147 -0
  227. package/src/macros/include/metadata.ts +22 -0
  228. package/src/macros/index.ts +179 -100
  229. package/src/macros/percentage/index.ts +54 -0
  230. package/src/macros/percentage/metadata.ts +22 -0
  231. package/src/macros/report/index.ts +22 -17
  232. package/src/macros/scoreCard/index.ts +23 -23
  233. package/src/macros/vega/index.ts +55 -0
  234. package/src/macros/vega/metadata.ts +21 -0
  235. package/src/macros/vegalite/index.ts +50 -0
  236. package/src/macros/vegalite/metadata.ts +21 -0
  237. package/src/macros/xref/index.ts +73 -0
  238. package/src/macros/xref/metadata.ts +22 -0
  239. package/src/module-manager.ts +241 -69
  240. package/src/permissions/action-guard.ts +3 -3
  241. package/src/project-settings.ts +2 -11
  242. package/src/resources/card-type-resource.ts +100 -0
  243. package/src/resources/file-resource.ts +16 -4
  244. package/src/resources/folder-resource.ts +59 -2
  245. package/src/resources/graph-model-resource.ts +1 -1
  246. package/src/resources/graph-view-resource.ts +1 -1
  247. package/src/resources/report-resource.ts +1 -1
  248. package/src/resources/resource-object.ts +14 -0
  249. package/src/resources/template-resource.ts +1 -1
  250. package/src/resources/workflow-resource.ts +68 -13
  251. package/src/svg/index.ts +15 -0
  252. package/src/svg/lib.ts +31 -0
  253. package/src/svg/percentage.ts +97 -0
  254. package/src/svg/scoreCard.ts +88 -0
  255. package/src/types/queries.ts +8 -7
  256. package/src/types/string-pixel-width.d.ts +23 -0
  257. package/src/utils/card-utils.ts +13 -0
  258. package/src/utils/clingo-facts.ts +65 -3
  259. package/src/utils/clingo-parser.ts +31 -144
  260. package/src/utils/constants.ts +16 -0
  261. package/src/utils/csv.ts +1 -1
  262. package/src/utils/report.ts +45 -4
  263. package/src/utils/resource-utils.ts +9 -0
  264. package/src/utils/user-preferences.ts +32 -14
  265. package/src/utils/validate.ts +3 -3
@@ -0,0 +1,97 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+ import { evaluateMacros, validateMacroContent } from '../index.js';
14
+ import macroMetadata from './metadata.js';
15
+ import BaseMacro from '../base-macro.js';
16
+ import { MAX_LEVEL_OFFSET } from '../../utils/constants.js';
17
+ export default class IncludeMacro extends BaseMacro {
18
+ constructor(tasksQueue) {
19
+ super(macroMetadata, tasksQueue);
20
+ }
21
+ handleValidate = (input) => {
22
+ this.validate(input);
23
+ };
24
+ handleStatic = async (context, input) => {
25
+ const options = this.validate(input);
26
+ if (!options.title) {
27
+ options.title = 'include';
28
+ }
29
+ if (!options.pageTitles) {
30
+ options.pageTitles = 'normal';
31
+ }
32
+ const card = await context.project.cardDetailsById(options.cardKey, {
33
+ content: true,
34
+ metadata: true,
35
+ });
36
+ if (!card) {
37
+ throw new Error(`Card key ${options.cardKey} not found`);
38
+ }
39
+ const newContext = {
40
+ ...context,
41
+ cardKey: options.cardKey,
42
+ };
43
+ const anchor = this.generateAnchor(options);
44
+ const title = this.generateTitle(options, card.metadata?.title);
45
+ const cardContent = await this.generateCardContent(options, card.content, newContext);
46
+ const content = `\n\n${anchor}${title}${cardContent}`;
47
+ let levelOffset = 0;
48
+ if (options.levelOffset) {
49
+ levelOffset = parseInt(options.levelOffset, 10);
50
+ if (isNaN(levelOffset)) {
51
+ throw new Error(`Invalid level offset: ${options.levelOffset}`);
52
+ }
53
+ levelOffset = Math.min(Math.max(levelOffset, -MAX_LEVEL_OFFSET), MAX_LEVEL_OFFSET);
54
+ }
55
+ const adjustedContent = this.adjustTitles(content, levelOffset, options.pageTitles === 'discrete');
56
+ return adjustedContent;
57
+ };
58
+ handleInject = async (context, input) => {
59
+ return this.handleStatic(context, input);
60
+ };
61
+ validate(input) {
62
+ return validateMacroContent(this.metadata, input);
63
+ }
64
+ generateAnchor(options) {
65
+ return options.title !== 'exclude' && options.pageTitles === 'normal'
66
+ ? `[[${options.cardKey}]]\n`
67
+ : '';
68
+ }
69
+ generateTitle(options, cardTitle) {
70
+ if (options.title === 'only' || options.title === 'include') {
71
+ return `= ${cardTitle}\n\n`;
72
+ }
73
+ return '';
74
+ }
75
+ async generateCardContent(options, cardContent, context) {
76
+ if (options.title !== 'only') {
77
+ return await evaluateMacros(cardContent ?? '', context, true);
78
+ }
79
+ return '';
80
+ }
81
+ // Adjust asciidoc titles to match the level offset
82
+ adjustTitles(content, levelOffset, discrete) {
83
+ const lines = content.split('\n');
84
+ const adjustedLines = lines.map((line) => {
85
+ const match = line.match(/^(\s*)([=#]+)(.*?)\s*$/);
86
+ if (match) {
87
+ const currentLevel = match[2].length;
88
+ const newLevel = Math.min(Math.max(1, currentLevel + levelOffset), MAX_LEVEL_OFFSET + 1);
89
+ const equals = '='.repeat(newLevel);
90
+ return `${discrete ? '[discrete]\n' : ''}${match[1]}${equals} ${match[3].trim()}`;
91
+ }
92
+ return line;
93
+ });
94
+ return adjustedLines.join('\n');
95
+ }
96
+ }
97
+ //# sourceM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AAO,GAAG,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACpF,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;QACH,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+ import type { MacroMetadata } from '../../interfaces/macros.js';
14
+ declare const macroMetadata: MacroMetadata;
15
+ export default macroMetadata;
@@ -0,0 +1,19 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+ const macroMetadata = {
14
+ name: 'include',
15
+ tagName: 'include',
16
+ schema: 'includeMacroSchema',
17
+ };
18
+ export default macroMetadata;
19
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/macros/include/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAIF,MAAM,aAAa,GAAkB;IACnC,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,oBAAoB;CAC7B,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,21 +1,21 @@
1
1
  /**
2
- Cyberismo
3
- Copyright © Cyberismo Ltd and contributors 2024
4
-
5
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
6
-
7
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
8
-
9
- You should have received a copy of the GNU Affero General Public
10
- License along with this program. If not, see <https://www.gnu.org/licenses/>.
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
11
12
  */
12
13
  import Handlebars from 'handlebars';
13
14
  import type { AdmonitionType } from '../interfaces/adoc.js';
14
- import type { Validator } from 'jsonschema';
15
15
  import type { MacroGenerationContext, MacroMetadata, MacroName } from '../interfaces/macros.js';
16
16
  import type BaseMacro from './base-macro.js';
17
17
  import TaskQueue from './task-queue.js';
18
- import type { Calculate } from '../commands/index.js';
18
+ import type { Schema } from 'jsonschema';
19
19
  /**
20
20
  * Constructor for all macros except report macros
21
21
  */
@@ -26,7 +26,7 @@ export interface SimpleMacroConstructor {
26
26
  * Constructor for report macros
27
27
  */
28
28
  export interface ReportMacroConstructor {
29
- new (tasks: TaskQueue, calculate: Calculate): BaseMacro;
29
+ new (tasks: TaskQueue): BaseMacro;
30
30
  }
31
31
  /**
32
32
  * Constructor for all macros
@@ -39,15 +39,14 @@ export declare const macros: {
39
39
  * Validates the content inside a macro
40
40
  * @param macro - The macro to validate the content of
41
41
  * @param data - The data to validate
42
- * @param validator - The validator to use
43
42
  * @returns The validated data
44
43
  */
45
- export declare function validateMacroContent<T>(macro: MacroMetadata, data: unknown, validator?: Validator): T;
44
+ export declare function validateMacroContent<T>(macro: MacroMetadata, data: unknown, schema?: Schema): T;
46
45
  /**
47
46
  * Registers the macros with Handlebars
48
47
  * @param {Mode} mode - The mode to register the macros in
49
48
  */
50
- export declare function registerMacros(instance: typeof Handlebars, context: MacroGenerationContext, tasks: TaskQueue, calculate: Calculate): BaseMacro[];
49
+ export declare function registerMacros(instance: typeof Handlebars, context: MacroGenerationContext, tasks: TaskQueue): BaseMacro[];
51
50
  /**
52
51
  * Calculate amount of handlebars templates inside a string
53
52
  * @param input
@@ -63,9 +62,11 @@ export declare function registerEmptyMacros(instance: typeof Handlebars): void;
63
62
  /**
64
63
  * Handle the macros in the content
65
64
  * @param content - The content to handle the macros in
66
- * @param mode - The mode to handle the macros in. Inject mode will generate injectable placeholders for the macros while static mode will generate valid adoc. Validate mode will only validate the macros syntax and throw errors in case of issues.
65
+ * @param context - The context for macro generation
66
+ * @param calculate - The calculate function
67
+ * @param preserveRawBlocks - If true, don't unescape raw blocks at the end (for nested evaluations)
67
68
  */
68
- export declare function evaluateMacros(content: string, context: MacroGenerationContext, calculate: Calculate, maxTries?: number): Promise<string>;
69
+ export declare function evaluateMacros(content: string, context: MacroGenerationContext, preserveRawBlocks?: boolean): Promise<string>;
69
70
  /**
70
71
  * This function assumes that tasks, which were started by macros, are complete.
71
72
  * It replaces the placeholders of the tasks with the actual results
@@ -83,20 +84,14 @@ export declare function applyMacroResults(input: string, tasks: TaskQueue, conte
83
84
  * @returns The error message that is valid adoc
84
85
  */
85
86
  export declare function handleMacroError(error: unknown, macro: string, context: MacroGenerationContext): string;
86
- type Value = string | number | boolean | undefined;
87
- /**
88
- * Macro options can be a flat object or a nested object
89
- * The nested object will be flattened into dot notation attributes
90
- */
91
- export type MacroOptions = {
92
- [key: string]: Value | MacroOptions;
93
- };
94
87
  /**
95
- * Creates an injectable placeholder for a macro
96
- * @param macro - The macro to create the placeholder for
97
- * @param options - Options will be passed to the html element as attributes
88
+ * Creates a placeholder for a macro
89
+ * Options are encoded as base64
90
+ * @param macro - The macro to create a placeholder for
91
+ * @param options - The options for the macro
92
+ * @returns The placeholder for the macro
98
93
  */
99
- export declare function createHtmlPlaceholder(macro: MacroMetadata, options: MacroOptions): string;
94
+ export declare function createHtmlPlaceholder(macro: MacroMetadata, options: unknown): string;
100
95
  /**
101
96
  * Creates an adoc admonition
102
97
  * @param type - The type of admonition
@@ -105,10 +100,23 @@ export declare function createHtmlPlaceholder(macro: MacroMetadata, options: Mac
105
100
  * @returns The adoc admonition as a string
106
101
  */
107
102
  export declare function createAdmonition(type: AdmonitionType, label: string, content: string): string;
103
+ /**
104
+ * Creates a code block
105
+ * @param content - The content of the code block
106
+ * @returns The code block as a string
107
+ */
108
+ export declare function createCodeBlock(content: string): string;
108
109
  /**
109
110
  * Helper function for including base64 encoded images for now
110
111
  * @param image base64 encoded image
111
112
  * @returns valid asciidoc with the image
112
113
  */
113
- export declare function createImage(image: string): string;
114
- export {};
114
+ export declare function createImage(image: string, controls?: boolean): string;
115
+ /**
116
+ * Creates a Handlebars macro block string with the given macro name and options.
117
+ *
118
+ * @param macro - The name of the macro to create (e.g., 'scoreCard', 'include').
119
+ * @param options - The options object to be stringified and inserted as macro content.
120
+ * @returns The Handlebars macro block as a string, e.g. {{#macro}}...{{/macro}}
121
+ */
122
+ export declare function createMacro(macro: MacroName, options: unknown): string;
@@ -1,45 +1,128 @@
1
1
  /**
2
- Cyberismo
3
- Copyright © Cyberismo Ltd and contributors 2024
4
-
5
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
6
-
7
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
8
-
9
- You should have received a copy of the GNU Affero General Public
10
- License along with this program. If not, see <https://www.gnu.org/licenses/>.
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
11
12
  */
12
13
  import Handlebars from 'handlebars';
13
14
  import createCards from './createCards/index.js';
14
15
  import graph from './graph/index.js';
16
+ import image from './image/index.js';
17
+ import include from './include/index.js';
15
18
  import report from './report/index.js';
16
19
  import scoreCard from './scoreCard/index.js';
20
+ import xref from './xref/index.js';
21
+ import percentage from './percentage/index.js';
22
+ import vega from './vega/index.js';
23
+ import vegaLite from './vegalite/index.js';
17
24
  import { validateJson } from '../utils/validate.js';
18
- import { DHValidationError } from '../exceptions/index.js';
25
+ import { DHValidationError, MacroError } from '../exceptions/index.js';
19
26
  import TaskQueue from './task-queue.js';
27
+ import { ClingoError } from '@cyberismo/node-clingo';
20
28
  const CURLY_LEFT = '&#123;';
21
29
  const CURLY_RIGHT = '&#125;';
30
+ const RAW_BLOCK_OPEN = '{{#raw}}';
31
+ const RAW_BLOCK_CLOSE = '{{/raw}}';
32
+ /**
33
+ * Pre-processes the content to handle {{#raw}} blocks by escaping all handlebars syntax inside them
34
+ * @param content The template content to process
35
+ * @returns The processed content with raw blocks escaped
36
+ * @throws Error if nested raw blocks are found or if a raw block is not properly closed
37
+ */
38
+ function preprocessRawBlocks(content) {
39
+ const result = [];
40
+ let i = 0;
41
+ // Helper function to check if a target string matches at a given position without creating substrings
42
+ const matchesAt = (pos, target) => {
43
+ if (pos + target.length > content.length)
44
+ return false;
45
+ for (let k = 0; k < target.length; k++) {
46
+ if (content[pos + k] !== target[k])
47
+ return false;
48
+ }
49
+ return true;
50
+ };
51
+ // Helper function to get line number at position
52
+ const getLineNumber = (pos) => {
53
+ let lineNum = 1;
54
+ for (let k = 0; k < pos; k++) {
55
+ if (content[k] === '\n') {
56
+ lineNum++;
57
+ }
58
+ }
59
+ return lineNum;
60
+ };
61
+ while (i < content.length) {
62
+ // Check for {{#raw}}
63
+ if (matchesAt(i, RAW_BLOCK_OPEN)) {
64
+ const openingLine = getLineNumber(i);
65
+ // Find the matching {{/raw}} - no nesting allowed
66
+ let j = i + RAW_BLOCK_OPEN.length;
67
+ while (j < content.length) {
68
+ if (matchesAt(j, RAW_BLOCK_OPEN)) {
69
+ // Found nested raw block - not supported
70
+ const nestedLine = getLineNumber(j);
71
+ throw new Error(`Nested ${RAW_BLOCK_OPEN} blocks are not supported. Found nested raw block inside another raw block on line ${nestedLine} (original raw block started on line ${openingLine}).`);
72
+ }
73
+ else if (matchesAt(j, RAW_BLOCK_CLOSE)) {
74
+ // Found matching closing tag
75
+ const rawContent = content.slice(i + RAW_BLOCK_OPEN.length, j);
76
+ const escapedContent = rawContent
77
+ .replaceAll('{', CURLY_LEFT)
78
+ .replaceAll('}', CURLY_RIGHT);
79
+ result.push(escapedContent);
80
+ i = j + RAW_BLOCK_CLOSE.length;
81
+ break;
82
+ }
83
+ else {
84
+ j++;
85
+ }
86
+ }
87
+ // If we reached the end without finding a closing tag
88
+ if (j >= content.length) {
89
+ throw new Error(`Unclosed ${RAW_BLOCK_OPEN} block found on line ${openingLine}. Every ${RAW_BLOCK_OPEN} must have a matching ${RAW_BLOCK_CLOSE}.`);
90
+ }
91
+ }
92
+ else {
93
+ // Not a raw block, keep as-is
94
+ result.push(content[i]);
95
+ i++;
96
+ }
97
+ }
98
+ return result.join('');
99
+ }
22
100
  export const macros = {
23
101
  createCards,
24
102
  graph,
103
+ image,
104
+ include,
25
105
  report,
26
106
  scoreCard,
107
+ xref,
108
+ percentage,
109
+ vega,
110
+ vegaLite,
27
111
  };
28
112
  /**
29
113
  * Validates the content inside a macro
30
114
  * @param macro - The macro to validate the content of
31
115
  * @param data - The data to validate
32
- * @param validator - The validator to use
33
116
  * @returns The validated data
34
117
  */
35
- export function validateMacroContent(macro, data, validator) {
118
+ export function validateMacroContent(macro, data, schema) {
36
119
  if (!macro.schema) {
37
120
  throw new Error(`Macro ${macro.name} does not have a schema`);
38
121
  }
39
122
  try {
40
123
  return validateJson(data, {
41
124
  schemaId: macro.schema,
42
- validator,
125
+ schema,
43
126
  });
44
127
  }
45
128
  catch (error) {
@@ -54,28 +137,16 @@ export function validateMacroContent(macro, data, validator) {
54
137
  * Registers the macros with Handlebars
55
138
  * @param {Mode} mode - The mode to register the macros in
56
139
  */
57
- export function registerMacros(instance, context, tasks, calculate) {
140
+ export function registerMacros(instance, context, tasks) {
58
141
  const macroInstances = [];
59
142
  for (const macro of Object.keys(macros)) {
60
143
  const MacroClass = macros[macro];
61
- const macroInstance = new MacroClass(tasks, calculate);
144
+ const macroInstance = new MacroClass(tasks);
62
145
  instance.registerHelper(macro, function (options) {
63
- if (this != null &&
64
- typeof this === 'object' &&
65
- '__isRaw' in this &&
66
- this.__isRaw) {
67
- // we use escaped chars so that they will not be re-run
68
- return `${CURLY_LEFT}${CURLY_LEFT}#${macro}${CURLY_RIGHT}${CURLY_RIGHT}${options.fn(this)}${CURLY_LEFT}${CURLY_LEFT}/${macro}${CURLY_RIGHT}${CURLY_RIGHT}`;
69
- }
70
146
  return macroInstance.invokeMacro(context, options);
71
147
  });
72
148
  macroInstances.push(macroInstance);
73
149
  }
74
- instance.registerHelper('raw', function (options) {
75
- return options.fn({
76
- __isRaw: true,
77
- });
78
- });
79
150
  return macroInstances;
80
151
  }
81
152
  /**
@@ -103,20 +174,22 @@ export function registerEmptyMacros(instance) {
103
174
  /**
104
175
  * Handle the macros in the content
105
176
  * @param content - The content to handle the macros in
106
- * @param mode - The mode to handle the macros in. Inject mode will generate injectable placeholders for the macros while static mode will generate valid adoc. Validate mode will only validate the macros syntax and throw errors in case of issues.
177
+ * @param context - The context for macro generation
178
+ * @param calculate - The calculate function
179
+ * @param preserveRawBlocks - If true, don't unescape raw blocks at the end (for nested evaluations)
107
180
  */
108
- export async function evaluateMacros(content, context, calculate, maxTries = 10) {
181
+ export async function evaluateMacros(content, context, preserveRawBlocks = false) {
109
182
  const handlebars = Handlebars.create();
110
183
  const tasks = new TaskQueue();
111
- registerMacros(handlebars, context, tasks, calculate);
184
+ registerMacros(handlebars, context, tasks);
112
185
  let result = content;
113
- while (maxTries-- > 0) {
186
+ while ((context.maxTries ?? 10) > 0) {
114
187
  tasks.reset();
115
- const compiled = handlebars.compile(result, {
116
- strict: true,
117
- });
118
188
  try {
119
- result = compiled({});
189
+ const compiled = handlebars.compile(preprocessRawBlocks(result), {
190
+ strict: true,
191
+ });
192
+ result = compiled({ cardKey: context.cardKey });
120
193
  await tasks.waitAll();
121
194
  result = applyMacroResults(result, tasks, context);
122
195
  if (macroCount(result) === 0) {
@@ -131,7 +204,10 @@ export async function evaluateMacros(content, context, calculate, maxTries = 10)
131
204
  if (macroCount(result) !== 0) {
132
205
  return handleMacroError(new Error(`Too many recursive macro evaluations.`), '', context);
133
206
  }
134
- return result.replaceAll(CURLY_LEFT, '{').replaceAll(CURLY_RIGHT, '}');
207
+ // Only unescape raw blocks if we're not preserving them for nested evaluations
208
+ return preserveRawBlocks
209
+ ? result
210
+ : result.replaceAll(CURLY_LEFT, '{').replaceAll(CURLY_RIGHT, '}');
135
211
  }
136
212
  /**
137
213
  * This function assumes that tasks, which were started by macros, are complete.
@@ -144,7 +220,11 @@ export async function evaluateMacros(content, context, calculate, maxTries = 10)
144
220
  */
145
221
  export function applyMacroResults(input, tasks, context) {
146
222
  for (const item of tasks) {
147
- if (item.promiseResult === null) {
223
+ if (item.error) {
224
+ input = input.replace(item.placeholder, handleMacroError(item.error, item.macro, context));
225
+ } // It should not be possible that promiseResult is null if there never was an error
226
+ // Unless the function itself returns null / undefined
227
+ else if (item.promiseResult == null) {
148
228
  input = handleMacroError(new Error(`Tried to access result before it was resolved for ${item.placeholder}`), item.macro, context);
149
229
  }
150
230
  else {
@@ -164,6 +244,16 @@ export function handleMacroError(error, macro, context) {
164
244
  if (error instanceof DHValidationError) {
165
245
  message = `Check json syntax of macro ${macro}: ${error.errors?.map((e) => e.message).join(', ')}`;
166
246
  }
247
+ else if (error instanceof MacroError) {
248
+ const { cardKey, macroName, dependency } = error.context;
249
+ message = `Macro error in card '${cardKey}' in macro '${macroName}':\n\n${error.message}.`;
250
+ if (dependency) {
251
+ message += `\n\nParameters:\n\n${context.mode === 'validate' ? dependency.parameters : createCodeBlock(dependency.parameters)}.\n\n${dependency.output ? `Output:\n\n${context.mode === 'validate' ? dependency.output : createCodeBlock(dependency.output)}` : ''}`;
252
+ }
253
+ }
254
+ else if (error instanceof ClingoError) {
255
+ message = `Error running logic program in macro '${macro}':${error.details.errors.join('\n')}`;
256
+ }
167
257
  if (typeof error === 'object' &&
168
258
  error != null &&
169
259
  'lineNumber' in error &&
@@ -180,38 +270,19 @@ export function handleMacroError(error, macro, context) {
180
270
  // This is used to generate unique keys for macros
181
271
  // There might be a better way to do this
182
272
  let macroCounter = 0;
273
+ function objectToBase64(obj) {
274
+ return Buffer.from(JSON.stringify(obj), 'utf-8').toString('base64');
275
+ }
183
276
  /**
184
- * Creates an injectable placeholder for a macro
185
- * @param macro - The macro to create the placeholder for
186
- * @param options - Options will be passed to the html element as attributes
277
+ * Creates a placeholder for a macro
278
+ * Options are encoded as base64
279
+ * @param macro - The macro to create a placeholder for
280
+ * @param options - The options for the macro
281
+ * @returns The placeholder for the macro
187
282
  */
188
283
  export function createHtmlPlaceholder(macro, options) {
189
- // Flatten nested objects into dot notation attributes
190
- const flattenedOptions = {};
191
- // Helper function to flatten nested objects
192
- const flatten = (obj, prefix = '') => {
193
- Object.entries(obj).forEach(([key, value]) => {
194
- const newKey = prefix ? `${prefix}.${key}` : key;
195
- if (value !== null &&
196
- typeof value === 'object' &&
197
- !Array.isArray(value)) {
198
- // Recursively flatten nested objects
199
- flatten(value, newKey);
200
- }
201
- else {
202
- // Add leaf values to flattened options
203
- flattenedOptions[newKey] = value;
204
- }
205
- });
206
- };
207
- flatten(options);
208
- // Convert flattened options to attribute strings
209
- const attributeStrings = Object.entries(flattenedOptions)
210
- .filter(([, value]) => value !== undefined)
211
- .map(([key, value]) => `${key}="${value}"`);
212
- const optionString = attributeStrings.join(' ');
213
- // start with a line change to ensure that inline passthrough +++ is on its own line
214
- return `\n+++\n<${macro.tagName}${optionString ? ` ${optionString}` : ''} key="macro-${macroCounter++}"></${macro.tagName}>\n+++\n`;
284
+ const optionsBase64 = objectToBase64(options);
285
+ return `\n\n++++\n<${macro.tagName} options="${optionsBase64}" key="macro-${macroCounter++}"></${macro.tagName}>\n++++\n\n`;
215
286
  }
216
287
  /**
217
288
  * Creates an adoc admonition
@@ -223,22 +294,45 @@ export function createHtmlPlaceholder(macro, options) {
223
294
  export function createAdmonition(type, label, content) {
224
295
  return `[${type}]\n.${label}\n====\n${content}\n====\n\n`;
225
296
  }
297
+ /**
298
+ * Creates a code block
299
+ * @param content - The content of the code block
300
+ * @returns The code block as a string
301
+ */
302
+ export function createCodeBlock(content) {
303
+ return `\n\n----\n${content}\n----\n\n`;
304
+ }
226
305
  /**
227
306
  * Helper function for including base64 encoded images for now
228
307
  * @param image base64 encoded image
229
308
  * @returns valid asciidoc with the image
230
309
  */
231
- export function createImage(image) {
310
+ export function createImage(image, controls = true) {
232
311
  if (process.env.EXPORT_FORMAT) {
233
312
  return `image::data:image/svg+xml;base64,${image}[]\n`;
234
313
  }
235
314
  else {
236
- return `++++
237
- <div class="cyberismo-svg-wrapper" data-type="cyberismo-svg-wrapper">
238
- ${Buffer.from(image, 'base64').toString('utf-8')}
239
- </div>
240
- ++++
241
- `;
315
+ const svg = Buffer.from(image, 'base64').toString('utf-8');
316
+ if (controls) {
317
+ return `++++\n<div class="cyberismo-svg-wrapper" data-type="cyberismo-svg-wrapper">\n${svg}\n</div>\n++++\n`;
318
+ }
319
+ else {
320
+ return `++++\n${svg}\n++++\n`;
321
+ }
322
+ }
323
+ }
324
+ /**
325
+ * Creates a Handlebars macro block string with the given macro name and options.
326
+ *
327
+ * @param macro - The name of the macro to create (e.g., 'scoreCard', 'include').
328
+ * @param options - The options object to be stringified and inserted as macro content.
329
+ * @returns The Handlebars macro block as a string, e.g. {{#macro}}...{{/macro}}
330
+ */
331
+ export function createMacro(macro, options) {
332
+ let optionsString = JSON.stringify(options, null, 0);
333
+ if (optionsString.length > 1) {
334
+ optionsString = optionsString.slice(1, -1);
242
335
  }
336
+ return `{{#${macro}}}${optionsString}{{/${macro}}}`;
243
337
  }
244
338
  //# sourceMappingURL=index.js.map