@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
@@ -16,18 +16,62 @@ import { homedir } from 'node:os';
16
16
  import { spawnSync } from 'node:child_process';
17
17
 
18
18
  import { ActionGuard } from '../permissions/action-guard.js';
19
- import type { Calculate } from './index.js';
20
- import type { MetadataContent } from '../interfaces/project-interfaces.js';
19
+ import type {
20
+ MetadataContent,
21
+ ResourceFolderType,
22
+ } from '../interfaces/project-interfaces.js';
21
23
  import { Project } from '../containers/project.js';
22
24
  import { UserPreferences } from '../utils/user-preferences.js';
25
+ import {
26
+ type ResourceName,
27
+ resourceNameToString,
28
+ } from '../utils/resource-utils.js';
29
+ import { FolderResource } from '../resources/folder-resource.js';
30
+ import { writeFile } from 'node:fs/promises';
23
31
 
24
32
  export class Edit {
25
33
  private project: Project;
26
- private calculateCmd: Calculate;
27
34
 
28
- constructor(project: Project, calculateCmd: Calculate) {
35
+ constructor(project: Project) {
29
36
  this.project = project;
30
- this.calculateCmd = calculateCmd;
37
+ }
38
+
39
+ /**
40
+ * Updates a calculation file.
41
+ * @param resourceName The name of the resource to update.
42
+ * @param changedContent The new content for the calculation.
43
+ */
44
+ public async editCalculation(
45
+ resourceName: ResourceName,
46
+ changedContent: string,
47
+ ) {
48
+ if (resourceName.prefix !== this.project.projectPrefix) {
49
+ throw new Error(
50
+ `Resource '${resourceName.identifier}' is not a local resource`,
51
+ );
52
+ }
53
+ const resourceNameString = resourceNameToString(resourceName);
54
+ if (
55
+ !(await this.project.resourceExists(
56
+ resourceName.type as ResourceFolderType,
57
+ resourceNameString,
58
+ ))
59
+ ) {
60
+ throw new Error(
61
+ `Resource '${resourceNameString}' does not exist in the project`,
62
+ );
63
+ }
64
+ await writeFile(
65
+ join(
66
+ this.project.paths.calculationProjectFolder,
67
+ resourceName.identifier + '.lp',
68
+ ),
69
+ changedContent,
70
+ {
71
+ encoding: 'utf-8',
72
+ flag: 'r+',
73
+ },
74
+ );
31
75
  }
32
76
 
33
77
  /**
@@ -83,13 +127,16 @@ export class Edit {
83
127
  * @param changedContent New content for the card.
84
128
  */
85
129
  public async editCardContent(cardKey: string, changedContent: string) {
86
- // Determine the card path
130
+ const isTemplateCard = await this.project.isTemplateCard(cardKey);
131
+ if (isTemplateCard) {
132
+ return this.project.updateCardContent(cardKey, changedContent);
133
+ }
87
134
  const cardPath = this.project.pathToCard(cardKey);
88
135
  if (!cardPath) {
89
136
  throw new Error(`Card '${cardKey}' does not exist in the project`);
90
137
  }
91
138
 
92
- const actionGuard = new ActionGuard(this.calculateCmd);
139
+ const actionGuard = new ActionGuard(this.project.calculationEngine);
93
140
  await actionGuard.checkPermission('editContent', cardKey);
94
141
 
95
142
  await this.project.updateCardContent(cardKey, changedContent);
@@ -106,18 +153,54 @@ export class Edit {
106
153
  changedKey: string,
107
154
  newValue: MetadataContent,
108
155
  ) {
156
+ if (!changedKey) {
157
+ throw new Error(`Changed key cannot be empty`);
158
+ }
159
+ const isTemplateCard = await this.project.isTemplateCard(cardKey);
160
+ if (isTemplateCard) {
161
+ return this.project.updateCardMetadataKey(cardKey, changedKey, newValue);
162
+ }
163
+
109
164
  // Determine the card path
110
165
  const cardPath = this.project.pathToCard(cardKey);
111
166
  if (!cardPath) {
112
167
  throw new Error(`Card '${cardKey}' does not exist in the project`);
113
168
  }
114
- if (!changedKey) {
115
- throw new Error(`Changed key cannot be empty`);
116
- }
117
169
 
118
170
  // check for editing rights
119
- const actionGuard = new ActionGuard(this.calculateCmd);
171
+ const actionGuard = new ActionGuard(this.project.calculationEngine);
120
172
  await actionGuard.checkPermission('editField', cardKey, changedKey);
121
173
  await this.project.updateCardMetadataKey(cardKey, changedKey, newValue);
122
174
  }
175
+
176
+ /**
177
+ * Update a file of a folder resource. Cannot be used to create a new file.
178
+ * @param resourceName The name of the resource to update.
179
+ * @param fileName The name of the file to update.
180
+ * @param changedContent The new content for the file.
181
+ */
182
+ public async editResourceContent(
183
+ resourceName: ResourceName,
184
+ fileName: string,
185
+ changedContent: string,
186
+ ) {
187
+ const resourceNameString = resourceNameToString(resourceName);
188
+ if (
189
+ !(await this.project.resourceExists(
190
+ resourceName.type as ResourceFolderType,
191
+ resourceNameString,
192
+ ))
193
+ ) {
194
+ throw new Error(
195
+ `Resource '${resourceNameString}' does not exist in the project`,
196
+ );
197
+ }
198
+ const resource = Project.resourceObject(this.project, resourceName);
199
+ if (!(resource instanceof FolderResource)) {
200
+ throw new Error(
201
+ `Resource '${resourceNameString}' is not a folder resource`,
202
+ );
203
+ }
204
+ return resource.updateFile(fileName, changedContent);
205
+ }
123
206
  }
@@ -13,19 +13,28 @@
13
13
  */
14
14
 
15
15
  // node
16
- import { appendFile, copyFile, mkdir, truncate } from 'node:fs/promises';
16
+ import {
17
+ appendFile,
18
+ copyFile,
19
+ mkdir,
20
+ truncate,
21
+ writeFile,
22
+ } from 'node:fs/promises';
17
23
  import { dirname, join } from 'node:path';
24
+ import { spawn } from 'node:child_process';
18
25
 
19
- // asciidoctor
20
- import Processor from '@asciidoctor/core';
21
- import type { Calculate, Show } from './index.js';
22
26
  import type {
23
27
  Card,
24
28
  FetchCardDetails,
25
29
  } from '../interfaces/project-interfaces.js';
26
30
  import type { CardType } from '../interfaces/resource-interfaces.js';
31
+ import { evaluateMacros } from '../macros/index.js';
32
+ import type { ExportPdfOptions } from '../interfaces/project-interfaces.js';
33
+ import { generateReportContent } from '../utils/report.js';
34
+ import { getStaticDirectoryPath, pdfReport } from '@cyberismo/assets';
27
35
  import { Project } from '../containers/project.js';
28
36
  import type { QueryResult } from '../types/queries.js';
37
+ import type { Show } from './index.js';
29
38
  import { sortItems } from '../utils/lexorank.js';
30
39
 
31
40
  const attachmentFolder: string = 'a';
@@ -33,7 +42,6 @@ const attachmentFolder: string = 'a';
33
42
  export class Export {
34
43
  constructor(
35
44
  protected project: Project,
36
- protected calculateCmd: Calculate,
37
45
  protected showCmd: Show,
38
46
  ) {}
39
47
 
@@ -202,11 +210,11 @@ export class Export {
202
210
  asciiDocContent = await evaluateMacros(
203
211
  cardDetailsResponse.content || '',
204
212
  {
213
+ context: 'exportedDocument',
205
214
  mode: 'static',
206
215
  project,
207
216
  cardKey: card.key,
208
217
  },
209
- this.calculateCmd,
210
218
  );
211
219
  } catch (error) {
212
220
  asciiDocContent = `Macro error: ${error instanceof Error ? error.message : 'Unknown error'}\n\n${asciiDocContent}`;
@@ -225,6 +233,91 @@ export class Export {
225
233
  return card;
226
234
  }
227
235
 
236
+ private async runAsciidoctorPdf(content: string): Promise<Buffer> {
237
+ const staticRootDir = await getStaticDirectoryPath();
238
+ const proc = spawn(
239
+ 'asciidoctor-pdf',
240
+ [
241
+ '-a',
242
+ 'pdf-theme=cyberismo',
243
+ '-a',
244
+ `pdf-themesdir=${join(staticRootDir, 'pdf-themes')}`,
245
+ '-a',
246
+ `pdf-fontsdir=${join(staticRootDir, 'pdf-themes', 'fonts')};GEM_FONTS_DIR`,
247
+ '-',
248
+ ],
249
+ {
250
+ timeout: 100000,
251
+ shell: process.platform === 'win32',
252
+ },
253
+ );
254
+ proc.stdin.end(content);
255
+ const result = await new Promise<Buffer>((resolve, reject) => {
256
+ const chunks: Buffer[] = [];
257
+ proc.stdout.on('data', (chunk) => {
258
+ chunks.push(chunk);
259
+ });
260
+ proc.stderr.on('data', (chunk) => {
261
+ process.stderr.write(chunk);
262
+ });
263
+ proc.on('error', (error) => {
264
+ if ('code' in error && error.code === 'ENOENT') {
265
+ reject(
266
+ new Error(
267
+ 'Asciidoctor-pdf not found. Please install asciidoctor-pdf to use this feature.',
268
+ ),
269
+ );
270
+ }
271
+ reject(error);
272
+ });
273
+ proc.on('close', (code) => {
274
+ if (code === 0) {
275
+ resolve(Buffer.concat(chunks));
276
+ } else {
277
+ reject(new Error(`Asciidoctor-pdf failed with code ${code}`));
278
+ }
279
+ });
280
+ });
281
+ return result;
282
+ }
283
+
284
+ /**
285
+ * Exports the card(s) to pdf.
286
+ * @param destination Path to where the resulting file(s) will be created.
287
+ * @param options Export options.
288
+ * @returns status message
289
+ */
290
+ public async exportPdf(
291
+ destination: string,
292
+ options: ExportPdfOptions,
293
+ ): Promise<string> {
294
+ const opts = {
295
+ ...options,
296
+ date: options.date?.toISOString().split('T')[0],
297
+ recursive: options.recursive ?? false,
298
+ };
299
+
300
+ await this.project.calculationEngine.generate();
301
+
302
+ const result = await generateReportContent({
303
+ calculate: this.project.calculationEngine,
304
+ contentTemplate: pdfReport.content,
305
+ queryTemplate: pdfReport.query,
306
+ context: 'exportedDocument',
307
+ options: opts,
308
+ });
309
+
310
+ const evaluated = await evaluateMacros(result, {
311
+ context: 'exportedDocument',
312
+ mode: 'static',
313
+ project: this.project,
314
+ cardKey: '', // top level report does not contain any macros that use cardKey
315
+ });
316
+ const pdf = await this.runAsciidoctorPdf(evaluated);
317
+ await writeFile(destination, pdf);
318
+ return `Content exported as PDF to ${destination}`;
319
+ }
320
+
228
321
  /**
229
322
  * Exports the card(s) to ascii doc.
230
323
  * @param destination Path to where the resulting file(s) will be created.
@@ -254,8 +347,11 @@ export class Export {
254
347
  });
255
348
  }
256
349
 
257
- await this.calculateCmd.generate();
258
- const tree = await this.calculateCmd.runQuery('tree');
350
+ await this.project.calculationEngine.generate();
351
+ const tree = await this.project.calculationEngine.runQuery(
352
+ 'tree',
353
+ 'exportedDocument',
354
+ );
259
355
 
260
356
  if (cardKey) {
261
357
  const targetCard = this.findCardInTree(tree, cardKey);
@@ -290,27 +386,4 @@ export class Export {
290
386
  await this.toAdocFile(resultDocumentPath, cards);
291
387
  return message;
292
388
  }
293
-
294
- /**
295
- * Exports the card(s) to HTML and opens the browser.
296
- * @param destination Path to where the resulting file(s) will be created.
297
- * @param cardKey Optional; If not exporting the whole card tree, card key of parent card.
298
- */
299
- public async exportToHTML(
300
- destination: string,
301
- cardKey?: string,
302
- ): Promise<string> {
303
- let message = '';
304
- await this.exportToADoc(destination, cardKey).then((msg) => {
305
- message = msg;
306
- const asciiDocProcessor = Processor();
307
- const adocFile = join(destination, Project.cardContentFile);
308
- asciiDocProcessor.convertFile(adocFile, {
309
- safe: 'safe',
310
- base_dir: '/',
311
- standalone: true,
312
- });
313
- });
314
- return message;
315
- }
316
389
  }
@@ -172,6 +172,22 @@ export class Import {
172
172
  }
173
173
  }
174
174
 
175
+ /**
176
+ * Updates a specific imported module.
177
+ * @param moduleName Name (prefix) of module to update.
178
+ * @param credentials Optional credentials for a private module.
179
+ * @throws if module is not part of the project
180
+ */
181
+ public async updateModule(moduleName: string, credentials?: Credentials) {
182
+ const module = this.project.configuration.modules.find(
183
+ (item) => item.name === moduleName,
184
+ );
185
+ if (!module) {
186
+ throw new Error(`Module '${moduleName}' is not part of the project`);
187
+ }
188
+ return this.moduleManager.updateModule(module, credentials);
189
+ }
190
+
175
191
  /**
176
192
  * Updates all imported modules.
177
193
  * @param credentials Optional credentials for private modules.
@@ -1,13 +1,14 @@
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
 
13
14
  // node
@@ -15,7 +16,6 @@ import { join, sep } from 'node:path';
15
16
 
16
17
  import { ActionGuard } from '../permissions/action-guard.js';
17
18
  import { copyDir, deleteDir } from '../utils/file-utils.js';
18
- import type { Calculate } from './index.js';
19
19
  import type {
20
20
  Card,
21
21
  FetchCardDetails,
@@ -37,10 +37,7 @@ import { TemplateResource } from '../resources/template-resource.js';
37
37
  const ROOT: string = 'root';
38
38
 
39
39
  export class Move {
40
- constructor(
41
- private project: Project,
42
- private calculateCmd: Calculate,
43
- ) {}
40
+ constructor(private project: Project) {}
44
41
 
45
42
  // Fetches a card (either template or project card).
46
43
  private async getCard(cardKey: string, options: FetchCardDetails) {
@@ -192,7 +189,7 @@ export class Move {
192
189
  }
193
190
 
194
191
  // if both are project cards, make sure source card can be moved
195
- const actionGuard = new ActionGuard(this.calculateCmd);
192
+ const actionGuard = new ActionGuard(this.project.calculationEngine);
196
193
  await actionGuard.checkPermission('move', source);
197
194
 
198
195
  // rerank the card in the new location
@@ -15,7 +15,6 @@
15
15
  import { join, sep } from 'node:path';
16
16
 
17
17
  import { ActionGuard } from '../permissions/action-guard.js';
18
- import type { Calculate } from './index.js';
19
18
  import { deleteDir, deleteFile } from '../utils/file-utils.js';
20
19
  import { ModuleManager } from '../module-manager.js';
21
20
  import { Project } from '../containers/project.js';
@@ -29,10 +28,7 @@ const MODULES_PATH = `${sep}modules${sep}`;
29
28
  */
30
29
  export class Remove {
31
30
  private moduleManager: ModuleManager;
32
- constructor(
33
- private project: Project,
34
- private calculateCmd: Calculate,
35
- ) {
31
+ constructor(private project: Project) {
36
32
  this.moduleManager = new ModuleManager(this.project);
37
33
  }
38
34
 
@@ -87,7 +83,7 @@ export class Remove {
87
83
 
88
84
  // Make sure card can be removed if it's a project card
89
85
  if (!(await this.project.isTemplateCard(cardKey))) {
90
- const actionGuard = new ActionGuard(this.calculateCmd);
86
+ const actionGuard = new ActionGuard(this.project.calculationEngine);
91
87
  await actionGuard.checkPermission('delete', cardKey);
92
88
  }
93
89
 
@@ -115,10 +111,10 @@ export class Remove {
115
111
  content: false,
116
112
  parent: false,
117
113
  });
114
+ await deleteDir(cardFolder);
118
115
  if (card) {
119
- await this.calculateCmd.handleDeleteCard(card);
116
+ await this.project.handleDeleteCard(card);
120
117
  }
121
- await deleteDir(cardFolder);
122
118
  }
123
119
 
124
120
  // removes label from project
@@ -16,7 +16,6 @@ import { assert } from 'node:console';
16
16
  import { join } from 'node:path';
17
17
  import { rename, readdir, readFile, writeFile } from 'node:fs/promises';
18
18
 
19
- import type { Calculate } from './index.js';
20
19
  import type { Card } from '../interfaces/project-interfaces.js';
21
20
  import { isTemplateCard } from '../utils/card-utils.js';
22
21
  import { type Project, ResourcesFrom } from '../containers/project.js';
@@ -41,10 +40,7 @@ export class Rename {
41
40
  private from: string = '';
42
41
  private to: string = '';
43
42
 
44
- constructor(
45
- private project: Project,
46
- private calculateCmd: Calculate,
47
- ) {}
43
+ constructor(private project: Project) {}
48
44
 
49
45
  // Renames a card and all of its attachments (if it is a project card).
50
46
  private async renameCard(re: RegExp, card: Card): Promise<void> {
@@ -110,12 +106,7 @@ export class Rename {
110
106
  join(attachment.path, attachment.fileName),
111
107
  join(attachment.path, newAttachmentFileName),
112
108
  );
113
-
114
- const attachmentRe = new RegExp(`image::${attachment.fileName}`, 'g');
115
- card.content = card.content?.replace(
116
- attachmentRe,
117
- `image::${newAttachmentFileName}`,
118
- );
109
+ // NOTE: content is renamed by updateFiles method
119
110
  }),
120
111
  );
121
112
  }
@@ -373,6 +364,6 @@ export class Rename {
373
364
  this.project.collectLocalResources();
374
365
  console.info('Collected renamed resources');
375
366
 
376
- return this.calculateCmd.generate();
367
+ return this.project.calculationEngine.generate();
377
368
  }
378
369
  }