@cyberismo/data-handler 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/dist/card-metadata-updater.js +8 -4
  2. package/dist/card-metadata-updater.js.map +1 -1
  3. package/dist/command-handler.d.ts +4 -0
  4. package/dist/command-handler.js +29 -19
  5. package/dist/command-handler.js.map +1 -1
  6. package/dist/command-manager.d.ts +25 -2
  7. package/dist/command-manager.js +30 -5
  8. package/dist/command-manager.js.map +1 -1
  9. package/dist/commands/create.d.ts +1 -1
  10. package/dist/commands/create.js +45 -93
  11. package/dist/commands/create.js.map +1 -1
  12. package/dist/commands/edit.d.ts +1 -15
  13. package/dist/commands/edit.js +15 -89
  14. package/dist/commands/edit.js.map +1 -1
  15. package/dist/commands/export.d.ts +11 -2
  16. package/dist/commands/export.js +58 -58
  17. package/dist/commands/export.js.map +1 -1
  18. package/dist/commands/import.d.ts +9 -1
  19. package/dist/commands/import.js +17 -11
  20. package/dist/commands/import.js.map +1 -1
  21. package/dist/commands/move.d.ts +1 -2
  22. package/dist/commands/move.js +107 -146
  23. package/dist/commands/move.js.map +1 -1
  24. package/dist/commands/remove.d.ts +8 -1
  25. package/dist/commands/remove.js +17 -48
  26. package/dist/commands/remove.js.map +1 -1
  27. package/dist/commands/rename.d.ts +4 -9
  28. package/dist/commands/rename.js +34 -108
  29. package/dist/commands/rename.js.map +1 -1
  30. package/dist/commands/show.d.ts +22 -34
  31. package/dist/commands/show.js +103 -151
  32. package/dist/commands/show.js.map +1 -1
  33. package/dist/commands/transition.d.ts +9 -2
  34. package/dist/commands/transition.js +49 -44
  35. package/dist/commands/transition.js.map +1 -1
  36. package/dist/commands/update.d.ts +18 -12
  37. package/dist/commands/update.js +34 -18
  38. package/dist/commands/update.js.map +1 -1
  39. package/dist/commands/validate.d.ts +18 -10
  40. package/dist/commands/validate.js +101 -47
  41. package/dist/commands/validate.js.map +1 -1
  42. package/dist/containers/card-container.d.ts +87 -24
  43. package/dist/containers/card-container.js +183 -279
  44. package/dist/containers/card-container.js.map +1 -1
  45. package/dist/containers/project/calculation-engine.d.ts +13 -4
  46. package/dist/containers/project/calculation-engine.js +79 -77
  47. package/dist/containers/project/calculation-engine.js.map +1 -1
  48. package/dist/containers/project/card-cache.d.ts +146 -0
  49. package/dist/containers/project/card-cache.js +411 -0
  50. package/dist/containers/project/card-cache.js.map +1 -0
  51. package/dist/containers/project/project-paths.d.ts +5 -4
  52. package/dist/containers/project/project-paths.js +16 -12
  53. package/dist/containers/project/project-paths.js.map +1 -1
  54. package/dist/containers/project/resource-cache.d.ts +169 -0
  55. package/dist/containers/project/resource-cache.js +507 -0
  56. package/dist/containers/project/resource-cache.js.map +1 -0
  57. package/dist/containers/project/resource-handler.d.ts +129 -0
  58. package/dist/containers/project/resource-handler.js +206 -0
  59. package/dist/containers/project/resource-handler.js.map +1 -0
  60. package/dist/containers/project.d.ts +114 -195
  61. package/dist/containers/project.js +425 -535
  62. package/dist/containers/project.js.map +1 -1
  63. package/dist/containers/template.d.ts +22 -32
  64. package/dist/containers/template.js +113 -115
  65. package/dist/containers/template.js.map +1 -1
  66. package/dist/index.d.ts +1 -0
  67. package/dist/index.js +1 -0
  68. package/dist/index.js.map +1 -1
  69. package/dist/interfaces/folder-content-interfaces.d.ts +7 -4
  70. package/dist/interfaces/folder-content-interfaces.js +3 -3
  71. package/dist/interfaces/folder-content-interfaces.js.map +1 -1
  72. package/dist/interfaces/macros.d.ts +1 -0
  73. package/dist/interfaces/macros.js +1 -1
  74. package/dist/interfaces/macros.js.map +1 -1
  75. package/dist/interfaces/project-interfaces.d.ts +7 -5
  76. package/dist/interfaces/project-interfaces.js.map +1 -1
  77. package/dist/interfaces/resource-interfaces.d.ts +25 -22
  78. package/dist/interfaces/resource-interfaces.js +3 -0
  79. package/dist/interfaces/resource-interfaces.js.map +1 -1
  80. package/dist/macros/common.d.ts +10 -10
  81. package/dist/macros/createCards/index.d.ts +0 -13
  82. package/dist/macros/createCards/index.js.map +1 -1
  83. package/dist/macros/createCards/types.d.ts +44 -0
  84. package/dist/macros/createCards/types.js +15 -0
  85. package/dist/macros/createCards/types.js.map +1 -0
  86. package/dist/macros/graph/index.d.ts +2 -6
  87. package/dist/macros/graph/index.js +14 -28
  88. package/dist/macros/graph/index.js.map +1 -1
  89. package/dist/macros/graph/types.d.ts +23 -0
  90. package/dist/macros/graph/types.js +15 -0
  91. package/dist/macros/graph/types.js.map +1 -0
  92. package/dist/macros/image/index.d.ts +8 -16
  93. package/dist/macros/image/index.js +36 -33
  94. package/dist/macros/image/index.js.map +1 -1
  95. package/dist/macros/image/types.d.ts +38 -0
  96. package/dist/macros/image/types.js +15 -0
  97. package/dist/macros/image/types.js.map +1 -0
  98. package/dist/macros/include/index.d.ts +1 -6
  99. package/dist/macros/include/index.js +4 -7
  100. package/dist/macros/include/index.js.map +1 -1
  101. package/dist/macros/include/types.d.ts +31 -0
  102. package/dist/macros/include/types.js +15 -0
  103. package/dist/macros/include/types.js.map +1 -0
  104. package/dist/macros/index.d.ts +1 -1
  105. package/dist/macros/index.js +2 -2
  106. package/dist/macros/index.js.map +1 -1
  107. package/dist/macros/percentage/index.d.ts +0 -6
  108. package/dist/macros/percentage/index.js.map +1 -1
  109. package/dist/macros/percentage/types.d.ts +31 -0
  110. package/dist/macros/percentage/types.js +15 -0
  111. package/dist/macros/percentage/types.js.map +1 -0
  112. package/dist/macros/report/index.d.ts +0 -3
  113. package/dist/macros/report/index.js +3 -6
  114. package/dist/macros/report/index.js.map +1 -1
  115. package/dist/macros/report/types.d.ts +19 -0
  116. package/dist/macros/report/types.js +15 -0
  117. package/dist/macros/report/types.js.map +1 -0
  118. package/dist/macros/scoreCard/index.d.ts +0 -6
  119. package/dist/macros/scoreCard/index.js.map +1 -1
  120. package/dist/macros/scoreCard/types.d.ts +31 -0
  121. package/dist/macros/scoreCard/types.js +15 -0
  122. package/dist/macros/scoreCard/types.js.map +1 -0
  123. package/dist/macros/types.d.ts +25 -0
  124. package/dist/macros/types.js +2 -0
  125. package/dist/macros/types.js.map +1 -0
  126. package/dist/macros/vega/index.d.ts +0 -4
  127. package/dist/macros/vega/index.js.map +1 -1
  128. package/dist/macros/vega/types.d.ts +20 -0
  129. package/dist/macros/vega/types.js +2 -0
  130. package/dist/macros/vega/types.js.map +1 -0
  131. package/dist/macros/vegalite/index.d.ts +0 -4
  132. package/dist/macros/vegalite/index.js.map +1 -1
  133. package/dist/macros/vegalite/types.d.ts +20 -0
  134. package/dist/macros/vegalite/types.js +15 -0
  135. package/dist/macros/vegalite/types.js.map +1 -0
  136. package/dist/macros/xref/index.d.ts +0 -3
  137. package/dist/macros/xref/index.js +5 -14
  138. package/dist/macros/xref/index.js.map +1 -1
  139. package/dist/macros/xref/types.d.ts +19 -0
  140. package/dist/macros/xref/types.js +15 -0
  141. package/dist/macros/xref/types.js.map +1 -0
  142. package/dist/module-manager.d.ts +16 -3
  143. package/dist/module-manager.js +55 -23
  144. package/dist/module-manager.js.map +1 -1
  145. package/dist/project-settings.d.ts +16 -3
  146. package/dist/project-settings.js +79 -14
  147. package/dist/project-settings.js.map +1 -1
  148. package/dist/resources/calculation-resource.d.ts +6 -33
  149. package/dist/resources/calculation-resource.js +11 -60
  150. package/dist/resources/calculation-resource.js.map +1 -1
  151. package/dist/resources/card-type-resource.d.ts +10 -22
  152. package/dist/resources/card-type-resource.js +46 -66
  153. package/dist/resources/card-type-resource.js.map +1 -1
  154. package/dist/resources/create-defaults.d.ts +3 -2
  155. package/dist/resources/create-defaults.js +3 -2
  156. package/dist/resources/create-defaults.js.map +1 -1
  157. package/dist/resources/field-type-resource.d.ts +8 -22
  158. package/dist/resources/field-type-resource.js +35 -60
  159. package/dist/resources/field-type-resource.js.map +1 -1
  160. package/dist/resources/file-resource.d.ts +14 -35
  161. package/dist/resources/file-resource.js +22 -301
  162. package/dist/resources/file-resource.js.map +1 -1
  163. package/dist/resources/folder-resource.d.ts +44 -66
  164. package/dist/resources/folder-resource.js +102 -149
  165. package/dist/resources/folder-resource.js.map +1 -1
  166. package/dist/resources/graph-model-resource.d.ts +9 -34
  167. package/dist/resources/graph-model-resource.js +18 -64
  168. package/dist/resources/graph-model-resource.js.map +1 -1
  169. package/dist/resources/graph-view-resource.d.ts +9 -29
  170. package/dist/resources/graph-view-resource.js +13 -48
  171. package/dist/resources/graph-view-resource.js.map +1 -1
  172. package/dist/resources/link-type-resource.d.ts +9 -23
  173. package/dist/resources/link-type-resource.js +11 -33
  174. package/dist/resources/link-type-resource.js.map +1 -1
  175. package/dist/resources/report-resource.d.ts +10 -23
  176. package/dist/resources/report-resource.js +20 -67
  177. package/dist/resources/report-resource.js.map +1 -1
  178. package/dist/resources/resource-object.d.ts +143 -23
  179. package/dist/resources/resource-object.js +369 -48
  180. package/dist/resources/resource-object.js.map +1 -1
  181. package/dist/resources/template-resource.d.ts +10 -17
  182. package/dist/resources/template-resource.js +19 -27
  183. package/dist/resources/template-resource.js.map +1 -1
  184. package/dist/resources/workflow-resource.d.ts +9 -25
  185. package/dist/resources/workflow-resource.js +25 -55
  186. package/dist/resources/workflow-resource.js.map +1 -1
  187. package/dist/utils/card-utils.d.ts +69 -19
  188. package/dist/utils/card-utils.js +179 -30
  189. package/dist/utils/card-utils.js.map +1 -1
  190. package/dist/utils/clingo-fact-builder.d.ts +25 -14
  191. package/dist/utils/clingo-fact-builder.js +27 -5
  192. package/dist/utils/clingo-fact-builder.js.map +1 -1
  193. package/dist/utils/clingo-facts.js +14 -7
  194. package/dist/utils/clingo-facts.js.map +1 -1
  195. package/dist/utils/clingo-parser.js +1 -1
  196. package/dist/utils/clingo-parser.js.map +1 -1
  197. package/dist/utils/constants.d.ts +2 -0
  198. package/dist/utils/constants.js +4 -0
  199. package/dist/utils/constants.js.map +1 -1
  200. package/dist/utils/csv.js +1 -1
  201. package/dist/utils/csv.js.map +1 -1
  202. package/dist/utils/resource-utils.d.ts +1 -0
  203. package/dist/utils/resource-utils.js +2 -1
  204. package/dist/utils/resource-utils.js.map +1 -1
  205. package/package.json +11 -11
  206. package/src/card-metadata-updater.ts +9 -7
  207. package/src/command-handler.ts +35 -23
  208. package/src/command-manager.ts +32 -19
  209. package/src/commands/create.ts +59 -160
  210. package/src/commands/edit.ts +16 -132
  211. package/src/commands/export.ts +71 -81
  212. package/src/commands/import.ts +26 -18
  213. package/src/commands/move.ts +143 -179
  214. package/src/commands/remove.ts +20 -59
  215. package/src/commands/rename.ts +45 -156
  216. package/src/commands/show.ts +153 -211
  217. package/src/commands/transition.ts +53 -58
  218. package/src/commands/update.ts +44 -23
  219. package/src/commands/validate.ts +108 -82
  220. package/src/containers/card-container.ts +200 -360
  221. package/src/containers/project/calculation-engine.ts +81 -105
  222. package/src/containers/project/card-cache.ts +497 -0
  223. package/src/containers/project/project-paths.ts +21 -13
  224. package/src/containers/project/resource-cache.ts +648 -0
  225. package/src/containers/project/resource-handler.ts +265 -0
  226. package/src/containers/project.ts +551 -693
  227. package/src/containers/template.ts +129 -142
  228. package/src/index.ts +1 -0
  229. package/src/interfaces/folder-content-interfaces.ts +14 -7
  230. package/src/interfaces/macros.ts +2 -0
  231. package/src/interfaces/project-interfaces.ts +14 -7
  232. package/src/interfaces/resource-interfaces.ts +30 -27
  233. package/src/macros/createCards/index.ts +1 -12
  234. package/src/macros/createCards/types.ts +46 -0
  235. package/src/macros/graph/index.ts +27 -52
  236. package/src/macros/graph/types.ts +24 -0
  237. package/src/macros/image/index.ts +50 -61
  238. package/src/macros/image/types.ts +39 -0
  239. package/src/macros/include/index.ts +6 -15
  240. package/src/macros/include/types.ts +32 -0
  241. package/src/macros/index.ts +2 -2
  242. package/src/macros/percentage/index.ts +1 -7
  243. package/src/macros/percentage/types.ts +32 -0
  244. package/src/macros/report/index.ts +4 -13
  245. package/src/macros/report/types.ts +20 -0
  246. package/src/macros/scoreCard/index.ts +1 -7
  247. package/src/macros/scoreCard/types.ts +32 -0
  248. package/src/macros/types.ts +48 -0
  249. package/src/macros/vega/index.ts +1 -4
  250. package/src/macros/vega/types.ts +21 -0
  251. package/src/macros/vegalite/index.ts +1 -4
  252. package/src/macros/vegalite/types.ts +22 -0
  253. package/src/macros/xref/index.ts +6 -20
  254. package/src/macros/xref/types.ts +20 -0
  255. package/src/module-manager.ts +79 -22
  256. package/src/project-settings.ts +84 -15
  257. package/src/resources/calculation-resource.ts +21 -91
  258. package/src/resources/card-type-resource.ts +74 -109
  259. package/src/resources/create-defaults.ts +3 -2
  260. package/src/resources/field-type-resource.ts +61 -104
  261. package/src/resources/file-resource.ts +33 -441
  262. package/src/resources/folder-resource.ts +130 -207
  263. package/src/resources/graph-model-resource.ts +36 -95
  264. package/src/resources/graph-view-resource.ts +28 -70
  265. package/src/resources/link-type-resource.ts +23 -53
  266. package/src/resources/report-resource.ts +34 -96
  267. package/src/resources/resource-object.ts +511 -66
  268. package/src/resources/template-resource.ts +32 -44
  269. package/src/resources/workflow-resource.ts +42 -85
  270. package/src/utils/card-utils.ts +217 -31
  271. package/src/utils/clingo-fact-builder.ts +28 -16
  272. package/src/utils/clingo-facts.ts +16 -7
  273. package/src/utils/clingo-parser.ts +1 -1
  274. package/src/utils/constants.ts +6 -0
  275. package/src/utils/csv.ts +1 -1
  276. package/src/utils/resource-utils.ts +2 -1
  277. package/dist/containers/project/resource-collector.d.ts +0 -87
  278. package/dist/containers/project/resource-collector.js +0 -337
  279. package/dist/containers/project/resource-collector.js.map +0 -1
  280. package/src/containers/project/resource-collector.ts +0 -396
@@ -27,7 +27,7 @@ import type { Card, Context } from '../../interfaces/project-interfaces.js';
27
27
  import ClingoParser from '../../utils/clingo-parser.js';
28
28
  import { Mutex } from 'async-mutex';
29
29
  import Handlebars from 'handlebars';
30
- import { type Project, ResourcesFrom } from '../../containers/project.js';
30
+ import type { Project } from '../../containers/project.js';
31
31
  import { getChildLogger } from '../../utils/log-utils.js';
32
32
  import {
33
33
  createCardFacts,
@@ -50,7 +50,6 @@ import type {
50
50
  TemplateMetadata,
51
51
  Workflow,
52
52
  } from '../../interfaces/resource-interfaces.js';
53
- import { CalculationResource } from '../../resources/calculation-resource.js';
54
53
  import {
55
54
  removeAllPrograms,
56
55
  solve,
@@ -61,7 +60,6 @@ import {
61
60
  import { generateReportContent } from '../../utils/report.js';
62
61
  import { lpFiles, graphvizReport } from '@cyberismo/assets';
63
62
  import {
64
- resourceName,
65
63
  type ResourceName,
66
64
  resourceNameToString,
67
65
  } from '../../utils/resource-utils.js';
@@ -102,12 +100,7 @@ export class CalculationEngine {
102
100
  * @returns The logic program content for the card
103
101
  */
104
102
  public async cardLogicProgram(cardKey: string): Promise<string> {
105
- const card = await this.project.findSpecificCard(cardKey, {
106
- metadata: true,
107
- });
108
- if (!card) {
109
- throw new Error(`Card '${cardKey}' does not exist in the project`);
110
- }
103
+ const card = this.project.findCard(cardKey);
111
104
  return createCardFacts(card, this.project);
112
105
  }
113
106
 
@@ -127,7 +120,7 @@ export class CalculationEngine {
127
120
  await writeFile(destination, logicProgram);
128
121
  }
129
122
 
130
- // // Wrapper to run onCreation query.
123
+ // Wrapper to run onCreation query.
131
124
  private async creationQuery(cardKeys: string[], context: Context) {
132
125
  if (!cardKeys) return undefined;
133
126
  return this.runQuery('onCreation', context, {
@@ -137,8 +130,7 @@ export class CalculationEngine {
137
130
 
138
131
  // Generate card tree content
139
132
  private async setCardTreeContent() {
140
- const cards = await this.getCards(undefined);
141
-
133
+ const cards = this.getCards(undefined);
142
134
  for (const card of cards) {
143
135
  await this.setCardContent(card);
144
136
  }
@@ -151,10 +143,10 @@ export class CalculationEngine {
151
143
 
152
144
  // Generates logic programs related to modules (and project itself).
153
145
  private async generateModules() {
154
- const modules = await this.project.modules();
146
+ const modules = this.project.resources.moduleNames();
155
147
  let content = '';
156
148
  for (const module of await Promise.all(
157
- modules.map((mod) => this.project.module(mod.name)),
149
+ modules.map((mod) => this.project.module(mod)),
158
150
  )) {
159
151
  if (!module) continue;
160
152
  const moduleContent = createModuleFacts(module);
@@ -167,129 +159,93 @@ export class CalculationEngine {
167
159
 
168
160
  // Sets individual CardType programs
169
161
  private async setCardTypesPrograms() {
170
- const cardTypes = await this.project.cardTypes();
171
-
172
- for (const cardType of await Promise.all(
173
- cardTypes.map((c) => this.project.resource<CardType>(c.name)),
174
- )) {
175
- if (!cardType) continue;
176
-
177
- const cardTypeContent = createCardTypeFacts(cardType);
178
- setProgram(cardType.name, cardTypeContent, [ALL_CATEGORY]);
162
+ const cardTypes = this.project.resources.cardTypes();
163
+ for (const cardType of cardTypes) {
164
+ const ct = cardType.show();
165
+ const cardTypeContent = createCardTypeFacts(ct);
166
+ setProgram(ct.name, cardTypeContent, [ALL_CATEGORY]);
179
167
  }
180
168
  }
181
169
 
182
170
  // Sets individual FieldType programs
183
171
  private async setFieldTypesPrograms() {
184
- const fieldTypes = await this.project.fieldTypes();
185
-
186
- for (const fieldType of await Promise.all(
187
- fieldTypes.map((m) => this.project.resource<FieldType>(m.name)),
188
- )) {
189
- if (!fieldType) continue;
190
-
191
- const fieldTypeContent = createFieldTypeFacts(fieldType);
192
- setProgram(fieldType.name, fieldTypeContent, [ALL_CATEGORY]);
172
+ const fieldTypes = this.project.resources.fieldTypes();
173
+ for (const fieldType of fieldTypes) {
174
+ const ft = fieldType.show();
175
+ const fieldTypeContent = createFieldTypeFacts(ft);
176
+ setProgram(ft.name, fieldTypeContent, [ALL_CATEGORY]);
193
177
  }
194
178
  }
195
179
 
196
180
  // Sets individual LinkType programs
197
181
  private async setLinkTypesPrograms() {
198
- const linkTypes = await this.project.linkTypes();
199
-
200
- for (const linkType of await Promise.all(
201
- linkTypes.map((c) => this.project.resource<LinkType>(c.name)),
202
- )) {
203
- if (!linkType) continue;
204
-
205
- const linkTypeContent = createLinkTypeFacts(linkType);
206
- setProgram(linkType.name, linkTypeContent, [ALL_CATEGORY]);
182
+ const linkTypes = this.project.resources.linkTypes();
183
+ for (const linkType of linkTypes) {
184
+ const lt = linkType.show();
185
+ const linkTypeContent = createLinkTypeFacts(lt);
186
+ setProgram(lt.name, linkTypeContent, [ALL_CATEGORY]);
207
187
  }
208
188
  }
209
189
 
210
190
  // Sets individual Workflow programs
211
191
  private async setWorkflowsPrograms() {
212
- const workflows = await this.project.workflows();
213
-
214
- for (const workflow of await Promise.all(
215
- workflows.map((m) => this.project.resource<Workflow>(m.name)),
216
- )) {
217
- if (!workflow) continue;
218
-
219
- const workflowContent = createWorkflowFacts(workflow);
220
- setProgram(workflow.name, workflowContent, [ALL_CATEGORY]);
192
+ const workflows = this.project.resources.workflows();
193
+ for (const workflow of workflows) {
194
+ const wf = workflow.show();
195
+ const workflowContent = createWorkflowFacts(wf);
196
+ setProgram(wf.name, workflowContent, [ALL_CATEGORY]);
221
197
  }
222
198
  }
223
199
 
224
200
  // Sets individual Report programs
225
201
  private async setReportsPrograms() {
226
- const reports = await this.project.reports();
227
-
228
- for (const report of await Promise.all(
229
- reports.map((r) => this.project.resource<ReportMetadata>(r.name)),
230
- )) {
231
- if (!report) continue;
232
-
233
- const reportContent = createReportFacts(report);
234
- setProgram(report.name, reportContent, [ALL_CATEGORY]);
202
+ const reports = this.project.resources.reports();
203
+ for (const report of reports) {
204
+ const rep = report.show();
205
+ const reportContent = createReportFacts(rep);
206
+ setProgram(rep.name, reportContent, [ALL_CATEGORY]);
235
207
  }
236
208
  }
237
209
 
238
210
  // Sets individual Template programs
239
211
  private async setTemplatesPrograms() {
240
- const templates = await this.project.templates();
241
-
242
- for (const template of await Promise.all(
243
- templates.map((r) => this.project.resource<TemplateMetadata>(r.name)),
244
- )) {
245
- if (!template) continue;
246
-
247
- const templateContent = createTemplateFacts(template);
248
- const cards = await this.getCards(template.name);
212
+ const templates = this.project.resources.templates();
213
+ for (const template of templates) {
214
+ const tem = template.show();
215
+ const templateContent = createTemplateFacts(tem);
216
+ const cards = this.getCards(tem.name);
249
217
  for (const card of cards) {
250
218
  const cardContent = await createCardFacts(card, this.project);
251
219
  setProgram(card.key, cardContent, [ALL_CATEGORY]);
252
220
  }
253
- setProgram(template.name, templateContent, [ALL_CATEGORY]);
221
+ setProgram(tem.name, templateContent, [ALL_CATEGORY]);
254
222
  }
255
223
  }
256
224
 
257
225
  // Sets individual Calculation programs
258
226
  private async setCalculationsPrograms() {
259
- const calculations = await this.project.calculations(ResourcesFrom.all);
260
-
261
- for (const calculationFile of calculations) {
227
+ const calculations = this.project.resources.calculations();
228
+ for (const calculation of calculations) {
262
229
  try {
263
- const calculationResource = new CalculationResource(
264
- this.project,
265
- resourceName(calculationFile.name),
266
- );
267
- if (calculationResource) {
268
- const resource = await calculationResource.show();
269
- if (!resource?.content.calculation) {
270
- this.logger.info(
271
- `Calculation resource '${resource.name}' does not have calculation file`,
272
- );
273
- continue;
274
- }
275
- setProgram(calculationFile.name, resource.content.calculation, [
276
- ALL_CATEGORY,
277
- ]);
278
- }
230
+ const content = calculation.contentData();
231
+ const calc = calculation.show();
232
+ setProgram(calc.name, content.calculation, [ALL_CATEGORY]);
279
233
  } catch (error) {
280
234
  this.logger.warn(
281
235
  error,
282
- `Failed to read calculation ${calculationFile.name}`,
236
+ `Failed to read calculation ${calculation.data!.name}`,
283
237
  );
284
238
  }
285
239
  }
286
240
  }
287
241
 
288
242
  // Gets either all the cards (no parent), or a subtree.
289
- private async getCards(templateName?: string): Promise<Card[]> {
290
- return templateName
291
- ? this.project.templateCards(templateName)
292
- : this.project.cards();
243
+ private getCards(templateName?: string): Card[] {
244
+ if (templateName) {
245
+ return this.project.templateCards(templateName);
246
+ }
247
+
248
+ return this.project.cards();
293
249
  }
294
250
 
295
251
  // Checks that Clingo successfully returned result.
@@ -300,6 +256,15 @@ export class CalculationEngine {
300
256
  return parser.parseInput(data.join('\n'));
301
257
  }
302
258
 
259
+ //
260
+ private queryContent(queryName: QueryName, options?: unknown) {
261
+ const content = lpFiles.queries[queryName];
262
+ const handlebars = Handlebars.create();
263
+ const compiled = handlebars.compile(content);
264
+ return compiled(options || {});
265
+ }
266
+
267
+ //
303
268
  private async run(query: string, context: Context): Promise<string[]> {
304
269
  try {
305
270
  const res = await CalculationEngine.mutex.runExclusive(async () => {
@@ -387,6 +352,18 @@ export class CalculationEngine {
387
352
  });
388
353
  }
389
354
 
355
+ /**
356
+ * When card is moved, rebuild the entire card tree structure.
357
+ * Moving cards changes parent-child relationships, so we need to rebuild
358
+ * the complete card tree facts to ensure consistency.
359
+ */
360
+ public async handleCardMoved() {
361
+ await CalculationEngine.mutex.runExclusive(async () => {
362
+ // Rebuild entire tree structure from scratch to ensure all relationships are correct
363
+ await this.setCardTreeContent();
364
+ });
365
+ }
366
+
390
367
  /**
391
368
  * When cards are removed, automatically remove card-specific calculations.
392
369
  * @param deletedCard Card that is to be removed.
@@ -445,9 +422,12 @@ export class CalculationEngine {
445
422
  public async resourceLogicProgram(
446
423
  resourceName: ResourceName,
447
424
  ): Promise<string> {
448
- const resource = await this.project.resource(
449
- resourceNameToString(resourceName),
450
- );
425
+ let resource;
426
+ try {
427
+ resource = this.project.resources.byType(resourceName).data;
428
+ } catch {
429
+ resource = undefined;
430
+ }
451
431
  if (!resource) {
452
432
  throw new Error(
453
433
  `Resource '${resourceNameToString(resourceName)}' does not exist in the project`,
@@ -474,8 +454,9 @@ export class CalculationEngine {
474
454
 
475
455
  /**
476
456
  * Runs given logic program and creates a graph using clingraph
477
- * @param data Provide a query or/and a file which can be given to clingraph
478
- * @param timeout Maximum amount of milliseconds clingraph is allowed to run
457
+ * @param model Graph model to use.
458
+ * @param view Graph view to use.
459
+ * @param context In which type of context the query is run.
479
460
  * @returns a base64 encoded image as a string
480
461
  */
481
462
  public async runGraph(model: string, view: string, context: Context) {
@@ -513,6 +494,7 @@ export class CalculationEngine {
513
494
  /**
514
495
  * Runs a logic program using clingo.
515
496
  * @param query Logic program to be run
497
+ * @param context In which type of context the query is run.
516
498
  * @returns parsed program output
517
499
  */
518
500
  public async runLogicProgram(query: string, context: Context = 'localApp') {
@@ -520,16 +502,10 @@ export class CalculationEngine {
520
502
  return this.parseClingoResult(clingoOutput);
521
503
  }
522
504
 
523
- private queryContent(queryName: QueryName, options?: unknown) {
524
- const content = lpFiles.queries[queryName];
525
- const handlebars = Handlebars.create();
526
- const compiled = handlebars.compile(content);
527
- return compiled(options || {});
528
- }
529
-
530
505
  /**
531
506
  * Runs a pre-defined query.
532
507
  * @param queryName Name of the query file without extension
508
+ * @param context In which type of context the query is run.
533
509
  * @param options Any object that contains state for handlebars
534
510
  * @returns parsed program output
535
511
  */