@cyberismo/data-handler 0.0.8 → 0.0.10

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 (258) 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 +6 -3
  10. package/dist/commands/create.js +27 -5
  11. package/dist/commands/create.js.map +1 -1
  12. package/dist/commands/edit.d.ts +15 -3
  13. package/dist/commands/edit.js +52 -9
  14. package/dist/commands/edit.js.map +1 -1
  15. package/dist/commands/export.d.ts +11 -9
  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 +13 -0
  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 +1 -3
  25. package/dist/commands/remove.js +4 -6
  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 +89 -8
  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 -0
  40. package/dist/commands/validate.js +31 -4
  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.js +9 -13
  49. package/dist/containers/project/resource-collector.js.map +1 -1
  50. package/dist/containers/project.d.ts +18 -1
  51. package/dist/containers/project.js +28 -55
  52. package/dist/containers/project.js.map +1 -1
  53. package/dist/containers/template.d.ts +5 -0
  54. package/dist/containers/template.js +9 -0
  55. package/dist/containers/template.js.map +1 -1
  56. package/dist/index.d.ts +5 -2
  57. package/dist/index.js +5 -1
  58. package/dist/index.js.map +1 -1
  59. package/dist/interfaces/macros.d.ts +4 -2
  60. package/dist/interfaces/project-interfaces.d.ts +21 -0
  61. package/dist/interfaces/project-interfaces.js +4 -0
  62. package/dist/interfaces/project-interfaces.js.map +1 -1
  63. package/dist/interfaces/resource-interfaces.d.ts +4 -2
  64. package/dist/interfaces/resource-interfaces.js.map +1 -1
  65. package/dist/macros/base-macro.d.ts +2 -1
  66. package/dist/macros/base-macro.js +14 -2
  67. package/dist/macros/base-macro.js.map +1 -1
  68. package/dist/macros/common.d.ts +16 -9
  69. package/dist/macros/common.js +22 -9
  70. package/dist/macros/common.js.map +1 -1
  71. package/dist/macros/createCards/index.d.ts +2 -2
  72. package/dist/macros/createCards/index.js +4 -0
  73. package/dist/macros/createCards/index.js.map +1 -1
  74. package/dist/macros/graph/index.d.ts +1 -3
  75. package/dist/macros/graph/index.js +1 -6
  76. package/dist/macros/graph/index.js.map +1 -1
  77. package/dist/macros/image/index.d.ts +39 -0
  78. package/dist/macros/image/index.js +82 -0
  79. package/dist/macros/image/index.js.map +1 -0
  80. package/dist/macros/image/metadata.d.ts +18 -0
  81. package/dist/macros/image/metadata.js +22 -0
  82. package/dist/macros/image/metadata.js.map +1 -0
  83. package/dist/macros/include/index.d.ts +31 -0
  84. package/dist/macros/include/index.js +94 -0
  85. package/dist/macros/include/index.js.map +1 -0
  86. package/dist/macros/include/metadata.d.ts +15 -0
  87. package/dist/macros/include/metadata.js +19 -0
  88. package/dist/macros/include/metadata.js.map +1 -0
  89. package/dist/macros/index.d.ts +33 -31
  90. package/dist/macros/index.js +142 -71
  91. package/dist/macros/index.js.map +1 -1
  92. package/dist/macros/percentage/index.d.ts +28 -0
  93. package/dist/macros/percentage/index.js +33 -0
  94. package/dist/macros/percentage/index.js.map +1 -0
  95. package/dist/macros/percentage/metadata.d.ts +15 -0
  96. package/dist/macros/percentage/metadata.js +19 -0
  97. package/dist/macros/percentage/metadata.js.map +1 -0
  98. package/dist/macros/report/index.d.ts +2 -6
  99. package/dist/macros/report/index.js +3 -7
  100. package/dist/macros/report/index.js.map +1 -1
  101. package/dist/macros/scoreCard/index.d.ts +14 -15
  102. package/dist/macros/scoreCard/index.js +14 -18
  103. package/dist/macros/scoreCard/index.js.map +1 -1
  104. package/dist/macros/vega/index.d.ts +28 -0
  105. package/dist/macros/vega/index.js +27 -0
  106. package/dist/macros/vega/index.js.map +1 -0
  107. package/dist/macros/vega/metadata.d.ts +15 -0
  108. package/dist/macros/vega/metadata.js +7 -0
  109. package/dist/macros/vega/metadata.js.map +1 -0
  110. package/dist/macros/vegalite/index.d.ts +26 -0
  111. package/dist/macros/vegalite/index.js +24 -0
  112. package/dist/macros/vegalite/index.js.map +1 -0
  113. package/dist/macros/vegalite/metadata.d.ts +15 -0
  114. package/dist/macros/vegalite/metadata.js +7 -0
  115. package/dist/macros/vegalite/metadata.js.map +1 -0
  116. package/dist/macros/xref/index.d.ts +26 -0
  117. package/dist/macros/xref/index.js +53 -0
  118. package/dist/macros/xref/index.js.map +1 -0
  119. package/dist/macros/xref/metadata.d.ts +15 -0
  120. package/dist/macros/xref/metadata.js +19 -0
  121. package/dist/macros/xref/metadata.js.map +1 -0
  122. package/dist/module-manager.d.ts +1 -0
  123. package/dist/module-manager.js +14 -4
  124. package/dist/module-manager.js.map +1 -1
  125. package/dist/permissions/action-guard.d.ts +2 -2
  126. package/dist/permissions/action-guard.js +1 -1
  127. package/dist/permissions/action-guard.js.map +1 -1
  128. package/dist/resources/card-type-resource.d.ts +2 -0
  129. package/dist/resources/card-type-resource.js +63 -0
  130. package/dist/resources/card-type-resource.js.map +1 -1
  131. package/dist/resources/file-resource.d.ts +2 -0
  132. package/dist/resources/file-resource.js +12 -4
  133. package/dist/resources/file-resource.js.map +1 -1
  134. package/dist/resources/folder-resource.d.ts +19 -0
  135. package/dist/resources/folder-resource.js +51 -2
  136. package/dist/resources/folder-resource.js.map +1 -1
  137. package/dist/resources/graph-model-resource.js +1 -1
  138. package/dist/resources/graph-model-resource.js.map +1 -1
  139. package/dist/resources/graph-view-resource.js +1 -1
  140. package/dist/resources/graph-view-resource.js.map +1 -1
  141. package/dist/resources/report-resource.js +1 -1
  142. package/dist/resources/report-resource.js.map +1 -1
  143. package/dist/resources/resource-object.d.ts +8 -0
  144. package/dist/resources/resource-object.js +10 -1
  145. package/dist/resources/resource-object.js.map +1 -1
  146. package/dist/resources/template-resource.js +1 -1
  147. package/dist/resources/template-resource.js.map +1 -1
  148. package/dist/resources/workflow-resource.d.ts +2 -0
  149. package/dist/resources/workflow-resource.js +53 -9
  150. package/dist/resources/workflow-resource.js.map +1 -1
  151. package/dist/svg/index.d.ts +15 -0
  152. package/dist/svg/index.js +16 -0
  153. package/dist/svg/index.js.map +1 -0
  154. package/dist/svg/lib.d.ts +9 -0
  155. package/dist/svg/lib.js +26 -0
  156. package/dist/svg/lib.js.map +1 -0
  157. package/dist/svg/percentage.d.ts +25 -0
  158. package/dist/svg/percentage.js +90 -0
  159. package/dist/svg/percentage.js.map +1 -0
  160. package/dist/svg/scoreCard.d.ts +19 -0
  161. package/dist/svg/scoreCard.js +55 -0
  162. package/dist/svg/scoreCard.js.map +1 -0
  163. package/dist/types/queries.d.ts +8 -7
  164. package/dist/types/queries.js.map +1 -1
  165. package/dist/utils/card-utils.d.ts +6 -0
  166. package/dist/utils/card-utils.js +12 -0
  167. package/dist/utils/card-utils.js.map +1 -1
  168. package/dist/utils/clingo-facts.d.ts +2 -1
  169. package/dist/utils/clingo-facts.js +19 -2
  170. package/dist/utils/clingo-facts.js.map +1 -1
  171. package/dist/utils/clingo-parser.d.ts +1 -0
  172. package/dist/utils/clingo-parser.js +22 -100
  173. package/dist/utils/clingo-parser.js.map +1 -1
  174. package/dist/utils/constants.d.ts +7 -0
  175. package/dist/utils/constants.js +14 -0
  176. package/dist/utils/constants.js.map +1 -1
  177. package/dist/utils/csv.js.map +1 -1
  178. package/dist/utils/report.d.ts +17 -3
  179. package/dist/utils/report.js +38 -2
  180. package/dist/utils/report.js.map +1 -1
  181. package/dist/utils/resource-utils.d.ts +2 -1
  182. package/dist/utils/resource-utils.js +12 -3
  183. package/dist/utils/resource-utils.js.map +1 -1
  184. package/dist/utils/user-preferences.d.ts +1 -11
  185. package/dist/utils/user-preferences.js +30 -13
  186. package/dist/utils/user-preferences.js.map +1 -1
  187. package/dist/utils/validate.d.ts +2 -3
  188. package/dist/utils/validate.js +2 -2
  189. package/dist/utils/validate.js.map +1 -1
  190. package/package.json +8 -6
  191. package/src/command-handler.ts +96 -17
  192. package/src/command-manager.ts +8 -8
  193. package/src/commands/calculate.ts +11 -525
  194. package/src/commands/create.ts +35 -6
  195. package/src/commands/edit.ts +94 -11
  196. package/src/commands/export.ts +104 -31
  197. package/src/commands/import.ts +16 -0
  198. package/src/commands/move.ts +12 -15
  199. package/src/commands/remove.ts +4 -8
  200. package/src/commands/rename.ts +3 -12
  201. package/src/commands/show.ts +126 -9
  202. package/src/commands/transition.ts +3 -7
  203. package/src/commands/update.ts +6 -0
  204. package/src/commands/validate.ts +41 -13
  205. package/src/containers/card-container.ts +74 -0
  206. package/src/containers/project/calculation-engine.ts +535 -0
  207. package/src/containers/project/resource-collector.ts +13 -15
  208. package/src/containers/project.ts +30 -66
  209. package/src/containers/template.ts +16 -0
  210. package/src/index.ts +13 -2
  211. package/src/interfaces/macros.ts +4 -1
  212. package/src/interfaces/project-interfaces.ts +27 -0
  213. package/src/interfaces/resource-interfaces.ts +5 -2
  214. package/src/macros/base-macro.ts +19 -4
  215. package/src/macros/common.ts +22 -9
  216. package/src/macros/createCards/index.ts +6 -2
  217. package/src/macros/graph/index.ts +6 -10
  218. package/src/macros/image/index.ts +128 -0
  219. package/src/macros/image/metadata.ts +25 -0
  220. package/src/macros/include/index.ts +143 -0
  221. package/src/macros/include/metadata.ts +22 -0
  222. package/src/macros/index.ts +150 -98
  223. package/src/macros/percentage/index.ts +50 -0
  224. package/src/macros/percentage/metadata.ts +22 -0
  225. package/src/macros/report/index.ts +4 -12
  226. package/src/macros/scoreCard/index.ts +21 -25
  227. package/src/macros/vega/index.ts +55 -0
  228. package/src/macros/vega/metadata.ts +21 -0
  229. package/src/macros/vegalite/index.ts +46 -0
  230. package/src/macros/vegalite/metadata.ts +21 -0
  231. package/src/macros/xref/index.ts +73 -0
  232. package/src/macros/xref/metadata.ts +22 -0
  233. package/src/module-manager.ts +15 -5
  234. package/src/permissions/action-guard.ts +3 -3
  235. package/src/resources/card-type-resource.ts +100 -0
  236. package/src/resources/file-resource.ts +16 -4
  237. package/src/resources/folder-resource.ts +59 -2
  238. package/src/resources/graph-model-resource.ts +1 -1
  239. package/src/resources/graph-view-resource.ts +1 -1
  240. package/src/resources/report-resource.ts +1 -1
  241. package/src/resources/resource-object.ts +19 -1
  242. package/src/resources/template-resource.ts +1 -1
  243. package/src/resources/workflow-resource.ts +68 -13
  244. package/src/svg/index.ts +15 -0
  245. package/src/svg/lib.ts +31 -0
  246. package/src/svg/percentage.ts +97 -0
  247. package/src/svg/scoreCard.ts +88 -0
  248. package/src/types/queries.ts +8 -7
  249. package/src/types/string-pixel-width.d.ts +23 -0
  250. package/src/utils/card-utils.ts +13 -0
  251. package/src/utils/clingo-facts.ts +65 -3
  252. package/src/utils/clingo-parser.ts +31 -144
  253. package/src/utils/constants.ts +16 -0
  254. package/src/utils/csv.ts +1 -1
  255. package/src/utils/report.ts +45 -4
  256. package/src/utils/resource-utils.ts +12 -2
  257. package/src/utils/user-preferences.ts +32 -14
  258. package/src/utils/validate.ts +3 -3
@@ -1,46 +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
25
  import { DHValidationError, MacroError } from '../exceptions/index.js';
19
26
  import TaskQueue from './task-queue.js';
20
27
  import { ClingoError } from '@cyberismo/node-clingo';
21
28
  const CURLY_LEFT = '&#123;';
22
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
+ }
23
100
  export const macros = {
24
101
  createCards,
25
102
  graph,
103
+ image,
104
+ include,
26
105
  report,
27
106
  scoreCard,
107
+ xref,
108
+ percentage,
109
+ vega,
110
+ vegaLite,
28
111
  };
29
112
  /**
30
113
  * Validates the content inside a macro
31
114
  * @param macro - The macro to validate the content of
32
115
  * @param data - The data to validate
33
- * @param validator - The validator to use
34
116
  * @returns The validated data
35
117
  */
36
- export function validateMacroContent(macro, data, validator) {
118
+ export function validateMacroContent(macro, data, schema) {
37
119
  if (!macro.schema) {
38
120
  throw new Error(`Macro ${macro.name} does not have a schema`);
39
121
  }
40
122
  try {
41
123
  return validateJson(data, {
42
124
  schemaId: macro.schema,
43
- validator,
125
+ schema,
44
126
  });
45
127
  }
46
128
  catch (error) {
@@ -55,28 +137,16 @@ export function validateMacroContent(macro, data, validator) {
55
137
  * Registers the macros with Handlebars
56
138
  * @param {Mode} mode - The mode to register the macros in
57
139
  */
58
- export function registerMacros(instance, context, tasks, calculate) {
140
+ export function registerMacros(instance, context, tasks) {
59
141
  const macroInstances = [];
60
142
  for (const macro of Object.keys(macros)) {
61
143
  const MacroClass = macros[macro];
62
- const macroInstance = new MacroClass(tasks, calculate);
144
+ const macroInstance = new MacroClass(tasks);
63
145
  instance.registerHelper(macro, function (options) {
64
- if (this != null &&
65
- typeof this === 'object' &&
66
- '__isRaw' in this &&
67
- this.__isRaw) {
68
- // we use escaped chars so that they will not be re-run
69
- return `${CURLY_LEFT}${CURLY_LEFT}#${macro}${CURLY_RIGHT}${CURLY_RIGHT}${options.fn(this)}${CURLY_LEFT}${CURLY_LEFT}/${macro}${CURLY_RIGHT}${CURLY_RIGHT}`;
70
- }
71
146
  return macroInstance.invokeMacro(context, options);
72
147
  });
73
148
  macroInstances.push(macroInstance);
74
149
  }
75
- instance.registerHelper('raw', function (options) {
76
- return options.fn({
77
- __isRaw: true,
78
- });
79
- });
80
150
  return macroInstances;
81
151
  }
82
152
  /**
@@ -104,20 +174,22 @@ export function registerEmptyMacros(instance) {
104
174
  /**
105
175
  * Handle the macros in the content
106
176
  * @param content - The content to handle the macros in
107
- * @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)
108
180
  */
109
- export async function evaluateMacros(content, context, calculate, maxTries = 10) {
181
+ export async function evaluateMacros(content, context, preserveRawBlocks = false) {
110
182
  const handlebars = Handlebars.create();
111
183
  const tasks = new TaskQueue();
112
- registerMacros(handlebars, context, tasks, calculate);
184
+ registerMacros(handlebars, context, tasks);
113
185
  let result = content;
114
- while (maxTries-- > 0) {
186
+ while ((context.maxTries ?? 10) > 0) {
115
187
  tasks.reset();
116
- const compiled = handlebars.compile(result, {
117
- strict: true,
118
- });
119
188
  try {
120
- result = compiled({});
189
+ const compiled = handlebars.compile(preprocessRawBlocks(result), {
190
+ strict: true,
191
+ });
192
+ result = compiled({ cardKey: context.cardKey });
121
193
  await tasks.waitAll();
122
194
  result = applyMacroResults(result, tasks, context);
123
195
  if (macroCount(result) === 0) {
@@ -132,7 +204,10 @@ export async function evaluateMacros(content, context, calculate, maxTries = 10)
132
204
  if (macroCount(result) !== 0) {
133
205
  return handleMacroError(new Error(`Too many recursive macro evaluations.`), '', context);
134
206
  }
135
- 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, '}');
136
211
  }
137
212
  /**
138
213
  * This function assumes that tasks, which were started by macros, are complete.
@@ -195,38 +270,19 @@ export function handleMacroError(error, macro, context) {
195
270
  // This is used to generate unique keys for macros
196
271
  // There might be a better way to do this
197
272
  let macroCounter = 0;
273
+ function objectToBase64(obj) {
274
+ return Buffer.from(JSON.stringify(obj), 'utf-8').toString('base64');
275
+ }
198
276
  /**
199
- * Creates an injectable placeholder for a macro
200
- * @param macro - The macro to create the placeholder for
201
- * @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
202
282
  */
203
283
  export function createHtmlPlaceholder(macro, options) {
204
- // Flatten nested objects into dot notation attributes
205
- const flattenedOptions = {};
206
- // Helper function to flatten nested objects
207
- const flatten = (obj, prefix = '') => {
208
- Object.entries(obj).forEach(([key, value]) => {
209
- const newKey = prefix ? `${prefix}.${key}` : key;
210
- if (value !== null &&
211
- typeof value === 'object' &&
212
- !Array.isArray(value)) {
213
- // Recursively flatten nested objects
214
- flatten(value, newKey);
215
- }
216
- else {
217
- // Add leaf values to flattened options
218
- flattenedOptions[newKey] = value;
219
- }
220
- });
221
- };
222
- flatten(options);
223
- // Convert flattened options to attribute strings
224
- const attributeStrings = Object.entries(flattenedOptions)
225
- .filter(([, value]) => value !== undefined)
226
- .map(([key, value]) => `${key}="${value}"`);
227
- const optionString = attributeStrings.join(' ');
228
- // start with a line change to ensure that inline passthrough +++ is on its own line
229
- 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`;
230
286
  }
231
287
  /**
232
288
  * Creates an adoc admonition
@@ -251,17 +307,32 @@ export function createCodeBlock(content) {
251
307
  * @param image base64 encoded image
252
308
  * @returns valid asciidoc with the image
253
309
  */
254
- export function createImage(image) {
310
+ export function createImage(image, controls = true) {
255
311
  if (process.env.EXPORT_FORMAT) {
256
312
  return `image::data:image/svg+xml;base64,${image}[]\n`;
257
313
  }
258
314
  else {
259
- return `++++
260
- <div class="cyberismo-svg-wrapper" data-type="cyberismo-svg-wrapper">
261
- ${Buffer.from(image, 'base64').toString('utf-8')}
262
- </div>
263
- ++++
264
- `;
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);
265
335
  }
336
+ return `{{#${macro}}}${optionsString}{{/${macro}}}`;
266
337
  }
267
338
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/macros/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAE7C,OAA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C/G,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,GAAG,UAAU,CAAC;QAChC,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,KAAgB,EAAE,OAAgB;IAC5D,IAAI,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACrD,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,MAAM,KAAK,KAAK,aAAa,MAAM,KAAK,IAAI,CAAC;AACtD,CAAC"}
@@ -0,0 +1,28 @@
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. This program is distributed in the hope that it
7
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
8
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ See the GNU Affero General Public License for more details.
10
+ 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 { MacroGenerationContext } from '../../interfaces/macros.js';
14
+ import BaseMacro from '../base-macro.js';
15
+ import type TaskQueue from '../task-queue.js';
16
+ export interface PercentageOptions {
17
+ title: string;
18
+ value: number;
19
+ legend: string;
20
+ colour?: 'blue' | 'green' | 'yellow' | 'red' | 'orange' | 'purple';
21
+ }
22
+ declare class PercentageMacro extends BaseMacro {
23
+ constructor(tasksQueue: TaskQueue);
24
+ handleValidate: (data: string) => void;
25
+ handleStatic: (_: MacroGenerationContext, input: unknown) => Promise<string>;
26
+ private validate;
27
+ }
28
+ export default PercentageMacro;
@@ -0,0 +1,33 @@
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. This program is distributed in the hope that it
7
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
8
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ See the GNU Affero General Public License for more details.
10
+ 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 { createImage, validateMacroContent } from '../index.js';
14
+ import macroMetadata from './metadata.js';
15
+ import BaseMacro from '../base-macro.js';
16
+ import { percentage } from '../../svg/index.js';
17
+ class PercentageMacro extends BaseMacro {
18
+ constructor(tasksQueue) {
19
+ super(macroMetadata, tasksQueue);
20
+ }
21
+ handleValidate = (data) => {
22
+ this.validate(data);
23
+ };
24
+ handleStatic = async (_, input) => {
25
+ const options = this.validate(input);
26
+ return createImage(Buffer.from(percentage(options)).toString('base64'), false);
27
+ };
28
+ validate(input) {
29
+ return validateMacroContent(this.metadata, input);
30
+ }
31
+ }
32
+ export default PercentageMacro;
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/macros/percentage/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAEF,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGhE,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAShD,MAAM,eAAgB,SAAQ,SAAS;IACrC,YAAY,UAAqB;QAC/B,KAAK,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IACnC,CAAC;IACD,cAAc,GAAG,CAAC,IAAY,EAAE,EAAE;QAChC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC,CAAC;IAEF,YAAY,GAAG,KAAK,EAAE,CAAyB,EAAE,KAAc,EAAE,EAAE;QACjE,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,WAAW,CAChB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACnD,KAAK,CACN,CAAC;IACJ,CAAC,CAAC;IAEM,QAAQ,CAAC,KAAc;QAC7B,OAAO,oBAAoB,CAAoB,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACvE,CAAC;CACF;AAED,eAAe,eAAe,CAAC"}
@@ -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. This program is distributed in the hope that it
7
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
8
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ See the GNU Affero General Public License for more details.
10
+ 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. This program is distributed in the hope that it
7
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
8
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ See the GNU Affero General Public License for more details.
10
+ 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: 'percentage',
15
+ tagName: 'percentage',
16
+ schema: 'percentageMacroSchema',
17
+ };
18
+ export default macroMetadata;
19
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/macros/percentage/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAIF,MAAM,aAAa,GAAkB;IACnC,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,uBAAuB;CAChC,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -10,20 +10,16 @@
10
10
  You should have received a copy of the GNU Affero General Public
11
11
  License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
12
  */
13
- import type { MacroOptions } from '../index.js';
14
13
  import type { MacroGenerationContext } from '../../interfaces/macros.js';
15
- import type { Calculate } from '../../commands/index.js';
16
14
  import BaseMacro from '../base-macro.js';
17
15
  import type TaskQueue from '../task-queue.js';
18
- export interface ReportOptions extends MacroOptions {
16
+ export interface ReportOptions {
19
17
  name: string;
20
18
  }
21
19
  declare class ReportMacro extends BaseMacro {
22
- private readonly calculate;
23
- constructor(tasks: TaskQueue, calculate: Calculate);
20
+ constructor(tasks: TaskQueue);
24
21
  handleValidate: (input: unknown) => void;
25
22
  handleStatic: (context: MacroGenerationContext, data: unknown) => Promise<string>;
26
- handleInject: (context: MacroGenerationContext, data: unknown) => Promise<string>;
27
23
  private validate;
28
24
  }
29
25
  export default ReportMacro;
@@ -19,18 +19,13 @@ import { resourceName } from '../../utils/resource-utils.js';
19
19
  import { generateReportContent } from '../../utils/report.js';
20
20
  import { ClingoError } from '@cyberismo/node-clingo';
21
21
  class ReportMacro extends BaseMacro {
22
- calculate;
23
- constructor(tasks, calculate) {
22
+ constructor(tasks) {
24
23
  super(macroMetadata, tasks);
25
- this.calculate = calculate;
26
24
  }
27
25
  handleValidate = (input) => {
28
26
  this.validate(input);
29
27
  };
30
28
  handleStatic = async (context, data) => {
31
- return this.handleInject(context, data);
32
- };
33
- handleInject = async (context, data) => {
34
29
  const options = this.validate(data);
35
30
  const resource = new ReportResource(context.project, resourceName(options.name));
36
31
  const report = await resource.show();
@@ -43,13 +38,14 @@ class ReportMacro extends BaseMacro {
43
38
  }
44
39
  try {
45
40
  return await generateReportContent({
46
- calculate: this.calculate,
41
+ calculate: context.project.calculationEngine,
47
42
  contentTemplate: report.contentTemplate,
48
43
  queryTemplate: report.queryTemplate,
49
44
  options: {
50
45
  cardKey: context.cardKey,
51
46
  ...options,
52
47
  },
48
+ context: context.context,
53
49
  });
54
50
  }
55
51
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/macros/report/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAEF,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAInD,OAAO,aAAa,MAAM,eAAe,CAAC;AAE1C,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAMrD,MAAM,WAAY,SAAQ,SAAS;IAGd;IAFnB,YACE,KAAgB,EACC,SAAoB;QAErC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QAFX,cAAS,GAAT,SAAS,CAAW;IAGvC,CAAC;IACD,cAAc,GAAG,CAAC,KAAc,EAAE,EAAE;QAClC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,YAAY,GAAG,KAAK,EAAE,OAA+B,EAAE,IAAa,EAAE,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C;YAClB,YAAY,CAAC,OAAO,EAAE;gBACpB,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC;YACH,OAAO,MAAM,qBAAqB,CAAC;gBACjC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,iBAAiB;gBAC5C,eAAe,EAAE,MAAM,CAAC,eAAe;gBACvC,aAAa,EAAE,MAAM,CAAC,aAAa;gBACnC,OAAO,EAAE;oBACP,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,GAAG,OAAO;iBACX;gBACD,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CACb,0CAA0C,OAAO,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC7F,CAAC;YACJ,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC;IAEM,QAAQ,CAAC,IAAa;QAC5B,OAAO,oBAAoB,CAAgB,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;CACF;AAED,eAAe,WAAW,CAAC"}
@@ -1,30 +1,29 @@
1
1
  /**
2
- Cyberismo
3
- Copyright © Cyberismo Ltd and contributors 2024
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
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/>.
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/>.
11
13
  */
12
- import type { MacroOptions } from '../index.js';
13
14
  import type { MacroGenerationContext } from '../../interfaces/macros.js';
14
15
  import BaseMacro from '../base-macro.js';
15
16
  import type TaskQueue from '../task-queue.js';
16
- export interface ScoreCardOptions extends MacroOptions {
17
- title?: string;
17
+ export interface ScoreCardOptions {
18
18
  value: number;
19
- unit?: string;
20
19
  legend?: string;
20
+ title?: string;
21
+ unit?: string;
21
22
  }
22
23
  declare class ScoreCardMacro extends BaseMacro {
23
24
  constructor(tasksQueue: TaskQueue);
24
25
  handleValidate: (data: string) => void;
25
- handleStatic: (context: MacroGenerationContext, input: unknown) => Promise<string>;
26
- handleInject: (_: MacroGenerationContext, input: unknown) => Promise<string>;
26
+ handleStatic: (_: MacroGenerationContext, input: unknown) => Promise<string>;
27
27
  private validate;
28
- private createAsciidocElement;
29
28
  }
30
29
  export default ScoreCardMacro;
@@ -1,17 +1,20 @@
1
1
  /**
2
- Cyberismo
3
- Copyright © Cyberismo Ltd and contributors 2024
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
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/>.
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/>.
11
13
  */
12
- import { createHtmlPlaceholder, validateMacroContent } from '../index.js';
14
+ import { createImage, validateMacroContent } from '../index.js';
13
15
  import macroMetadata from './metadata.js';
14
16
  import BaseMacro from '../base-macro.js';
17
+ import { scoreCard } from '../../svg/index.js';
15
18
  class ScoreCardMacro extends BaseMacro {
16
19
  constructor(tasksQueue) {
17
20
  super(macroMetadata, tasksQueue);
@@ -19,20 +22,13 @@ class ScoreCardMacro extends BaseMacro {
19
22
  handleValidate = (data) => {
20
23
  this.validate(data);
21
24
  };
22
- handleStatic = async (context, input) => {
25
+ handleStatic = async (_, input) => {
23
26
  const options = this.validate(input);
24
- return this.createAsciidocElement(options);
25
- };
26
- handleInject = async (_, input) => {
27
- const options = this.validate(input);
28
- return createHtmlPlaceholder(this.metadata, options);
27
+ return createImage(Buffer.from(scoreCard(options)).toString('base64'), false);
29
28
  };
30
29
  validate(input) {
31
30
  return validateMacroContent(this.metadata, input);
32
31
  }
33
- createAsciidocElement(options) {
34
- return `\n----\n${options.title}: ${options.value} ${options.unit ?? ''} ${options.legend ?? ''}\n----\n`;
35
- }
36
32
  }
37
33
  export default ScoreCardMacro;
38
34
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/macros/scoreCard/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAGF,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAG1E,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAUzC,MAAM,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