@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
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
  // node
15
- import { existsSync, readFileSync } from 'node:fs';
15
+ import { readFileSync } from 'node:fs';
16
16
  import { homedir } from 'node:os';
17
17
  import { join, resolve } from 'node:path';
18
18
  import { spawn } from 'node:child_process';
@@ -20,66 +20,61 @@ import { writeFile } from 'node:fs/promises';
20
20
 
21
21
  import { MODULE_LIST_FULL_PATH } from './fetch.js';
22
22
 
23
- import mime from 'mime-types';
24
-
25
23
  import type { attachmentPayload } from '../interfaces/request-status-interfaces.js';
26
24
  import type {
27
- CardAttachment,
28
25
  Card,
26
+ CardAttachment,
29
27
  CardListContainer,
30
- ModuleContent,
28
+ CardLocation,
29
+ CardWithChildrenCards,
30
+ Context,
31
+ FetchCardDetails,
32
+ FileContentType,
31
33
  HubSetting,
34
+ ModuleContent,
32
35
  ModuleSettingFromHub,
33
- ProjectFetchCardDetails,
34
36
  ProjectMetadata,
35
- Resource,
36
- CardLocation,
37
- Context,
38
- ResourceFolderType,
37
+ ResourceType,
39
38
  } from '../interfaces/project-interfaces.js';
40
39
  import type {
40
+ AnyResourceContent,
41
41
  CardType,
42
42
  ResourceContent,
43
43
  TemplateConfiguration,
44
44
  Workflow,
45
45
  } from '../interfaces/resource-interfaces.js';
46
- import { Project, type ResourcesFrom } from '../containers/project.js';
47
- import {
48
- type ResourceName,
49
- resourceName,
50
- resourceNameToString,
51
- } from '../utils/resource-utils.js';
52
- import { TemplateResource } from '../resources/template-resource.js';
53
- import { UserPreferences } from '../utils/user-preferences.js';
46
+ import type { Project, ResourcesFrom } from '../containers/project.js';
47
+ import type { ResourceName } from '../utils/resource-utils.js';
48
+ import type { ResourceMap } from '../containers/project/resource-cache.js';
54
49
 
50
+ import { UserPreferences } from '../utils/user-preferences.js';
55
51
  import ReportMacro from '../macros/report/index.js';
56
52
  import TaskQueue from '../macros/task-queue.js';
57
53
  import { evaluateMacros } from '../macros/index.js';
58
- import { FolderResource } from '../resources/folder-resource.js';
59
54
  import { readJsonFile } from '../utils/json.js';
60
55
  import { getChildLogger } from '../utils/log-utils.js';
56
+ import { buildCardHierarchy, flattenCardArray } from '../utils/card-utils.js';
61
57
 
62
58
  /**
63
59
  * Show command.
64
60
  */
65
61
  export class Show {
66
- private resourceFunction: Map<
62
+ private readonly resourceFunctions: Record<
67
63
  string,
68
- (from?: ResourcesFrom) => Promise<Resource[]>
69
- >;
70
- constructor(private project: Project) {
71
- this.resourceFunction = new Map([
72
- ['calculations', this.project.calculations.bind(this.project)],
73
- ['cardTypes', this.project.cardTypes.bind(this.project)],
74
- ['fieldTypes', this.project.fieldTypes.bind(this.project)],
75
- ['graphModels', this.project.graphModels.bind(this.project)],
76
- ['graphViews', this.project.graphViews.bind(this.project)],
77
- ['linkTypes', this.project.linkTypes.bind(this.project)],
78
- ['reports', this.project.reports.bind(this.project)],
79
- ['templates', this.project.templates.bind(this.project)],
80
- ['workflows', this.project.workflows.bind(this.project)],
81
- ]);
82
- }
64
+ (from?: ResourcesFrom) => string[]
65
+ > = {
66
+ calculations: (from) => this.resourceNames('calculations', from),
67
+ cardTypes: (from) => this.resourceNames('cardTypes', from),
68
+ fieldTypes: (from) => this.resourceNames('fieldTypes', from),
69
+ graphModels: (from) => this.resourceNames('graphModels', from),
70
+ graphViews: (from) => this.resourceNames('graphViews', from),
71
+ linkTypes: (from) => this.resourceNames('linkTypes', from),
72
+ reports: (from) => this.resourceNames('reports', from),
73
+ templates: (from) => this.resourceNames('templates', from),
74
+ workflows: (from) => this.resourceNames('workflows', from),
75
+ };
76
+
77
+ constructor(private project: Project) {}
83
78
 
84
79
  private get logger() {
85
80
  return getChildLogger({
@@ -87,6 +82,29 @@ export class Show {
87
82
  });
88
83
  }
89
84
 
85
+ // Gets all template attachments
86
+ private async attachmentsFromTemplates() {
87
+ const templateAttachments: CardAttachment[] = [];
88
+ const templates = this.project.resources.templates();
89
+ for (const template of templates) {
90
+ const templateObject = template.templateObject();
91
+ if (templateObject) {
92
+ templateAttachments.push(...templateObject.attachments());
93
+ }
94
+ }
95
+ return templateAttachments;
96
+ }
97
+
98
+ // Fetch resource names as a list
99
+ private resourceNames<T extends keyof ResourceMap>(
100
+ resourceType: T,
101
+ from?: ResourcesFrom,
102
+ ): string[] {
103
+ return this.project.resources
104
+ .resourceTypes(resourceType, from)
105
+ .map((item) => item.data?.name || '');
106
+ }
107
+
90
108
  // Collect all labels from cards.
91
109
  private collectLabels = (cards: Card[]): string[] => {
92
110
  return cards.reduce<string[]>((labels, card) => {
@@ -94,28 +112,13 @@ export class Show {
94
112
  if (card.metadata?.labels) {
95
113
  labels.push(...card.metadata.labels);
96
114
  }
97
- // Recursively collect labels from subcards, if they exist
98
- if (card.children) {
99
- labels.push(...this.collectLabels(card.children));
100
- }
101
115
  return labels;
102
116
  }, []);
103
117
  };
104
118
 
105
119
  // Returns attachment details
106
- private async getAttachment(cardKey: string, filename: string) {
107
- const details = {
108
- content: false,
109
- metadata: true,
110
- children: false,
111
- parent: false,
112
- attachments: true,
113
- };
114
- const card = await this.project.cardDetailsById(cardKey, details);
115
- if (card === undefined) {
116
- throw new Error(`Card '${cardKey}' does not exist in the project`);
117
- }
118
-
120
+ private getAttachment(cardKey: string, filename: string) {
121
+ const card = this.project.findCard(cardKey);
119
122
  const attachment =
120
123
  card.attachments?.find((a) => a.fileName === filename) ?? undefined;
121
124
  return attachment;
@@ -140,21 +143,19 @@ export class Show {
140
143
  * Shows all template cards in a project.
141
144
  * @returns all template cards in a project.
142
145
  */
143
- public async showAllTemplateCards(): Promise<
144
- { name: string; cards: Card[] }[]
145
- > {
146
- return Promise.all(
147
- (await this.project.templates()).map(async (template) => {
148
- const templateResource = new TemplateResource(
149
- this.project,
150
- resourceName(template.name),
151
- );
152
- return {
153
- name: template.name,
154
- cards: await templateResource.templateObject().showTemplateCards(),
155
- };
156
- }),
157
- );
146
+ public showAllTemplateCards(): {
147
+ name: string;
148
+ cards: CardWithChildrenCards[];
149
+ }[] {
150
+ return this.project.resources.templates().map((template) => {
151
+ const cards = template.templateObject().listCards();
152
+ const buildCards = buildCardHierarchy(cards);
153
+
154
+ return {
155
+ name: template.data?.name || '',
156
+ cards: buildCards,
157
+ };
158
+ });
158
159
  }
159
160
 
160
161
  /**
@@ -162,20 +163,8 @@ export class Show {
162
163
  * @returns array of card attachments
163
164
  */
164
165
  public async showAttachments(): Promise<CardAttachment[]> {
165
- const attachments: CardAttachment[] = await this.project.attachments();
166
- const templateAttachments: CardAttachment[] = [];
167
- const templates = await this.project.templates();
168
- for (const template of templates) {
169
- const templateResource = new TemplateResource(
170
- this.project,
171
- resourceName(template.name),
172
- );
173
- const templateObject = templateResource.templateObject();
174
- if (templateObject) {
175
- templateAttachments.push(...(await templateObject.attachments()));
176
- }
177
- }
178
-
166
+ const attachments = this.project.attachments();
167
+ const templateAttachments = await this.attachmentsFromTemplates();
179
168
  attachments.push(...templateAttachments);
180
169
  return attachments;
181
170
  }
@@ -186,32 +175,22 @@ export class Show {
186
175
  * @param filename attachment filename
187
176
  * @returns attachment details
188
177
  */
189
- public async showAttachment(
190
- cardKey: string,
191
- filename: string,
192
- ): Promise<attachmentPayload> {
178
+ public showAttachment(cardKey: string, filename: string): attachmentPayload {
193
179
  if (!cardKey) {
194
180
  throw new Error(`Mandatory parameter 'cardKey' missing`);
195
181
  }
196
182
 
197
- const attachment = await this.getAttachment(cardKey, filename);
198
-
199
- let attachmentPath: string = '';
200
- if (attachment) {
201
- attachmentPath = `${attachment.path}/${attachment.fileName}`;
202
- }
183
+ const attachment = this.getAttachment(cardKey, filename);
203
184
 
204
- if (!attachment || !existsSync(attachmentPath)) {
185
+ if (!attachment) {
205
186
  throw new Error(`Attachment '${filename}' not found for card ${cardKey}`);
206
- } else {
207
- const fileBuffer = readFileSync(attachmentPath);
208
- let mimeType = mime.lookup(attachmentPath);
209
- if (mimeType === false) {
210
- mimeType = 'application/octet-stream';
211
- }
212
- const payload: attachmentPayload = { fileBuffer, mimeType };
213
- return payload;
214
187
  }
188
+
189
+ const attachmentPath = `${attachment.path}/${attachment.fileName}`;
190
+ const fileBuffer = readFileSync(attachmentPath);
191
+ const mimeType = attachment.mimeType || 'application/octet-stream';
192
+ const payload: attachmentPayload = { fileBuffer, mimeType };
193
+ return payload;
215
194
  }
216
195
 
217
196
  /**
@@ -226,7 +205,7 @@ export class Show {
226
205
  filename: string,
227
206
  waitDelay: number = 1000,
228
207
  ) {
229
- const attachment = await this.getAttachment(cardKey, filename);
208
+ const attachment = this.getAttachment(cardKey, filename);
230
209
 
231
210
  if (!attachment) {
232
211
  throw new Error(`Attachment '${filename}' not found for card ${cardKey}`);
@@ -273,22 +252,29 @@ export class Show {
273
252
  /**
274
253
  * Shows details of a particular card (template card, or project card)
275
254
  * @note Note that parameter 'cardKey' is optional due to technical limitations of class calling this class. It must be defined to get valid results.
276
- * @param details card details to show
277
255
  * @param cardKey card key to find
256
+ * @param contentType Content format in which content is to be shown
278
257
  * @returns card details
279
258
  */
280
- public async showCardDetails(
281
- details: ProjectFetchCardDetails,
259
+ public showCardDetails(
282
260
  cardKey?: string,
283
- ): Promise<Card> {
261
+ contentType?: FileContentType,
262
+ ): Card {
284
263
  if (!cardKey) {
285
264
  throw new Error(`Mandatory parameter 'cardKey' missing`);
286
265
  }
287
- const cardDetails = await this.project.cardDetailsById(cardKey, details);
288
- if (cardDetails === undefined) {
289
- throw new Error(`Card '${cardKey}' does not exist in the project`);
266
+ // todo: Make a constant about this
267
+ const details: FetchCardDetails = {
268
+ parent: true,
269
+ metadata: true,
270
+ children: true,
271
+ attachments: true,
272
+ content: true,
273
+ };
274
+ if (contentType) {
275
+ details.contentType = contentType;
290
276
  }
291
- return cardDetails;
277
+ return this.project.findCard(cardKey, details);
292
278
  }
293
279
 
294
280
  /**
@@ -316,73 +302,13 @@ export class Show {
316
302
  * @returns array of card type details
317
303
  */
318
304
  public async showCardTypesWithDetails(): Promise<(CardType | undefined)[]> {
319
- const promiseContainer = [];
320
- for (const cardType of await this.project.cardTypes()) {
321
- const cardTypeDetails = await this.project.resource<CardType>(
322
- cardType.name,
323
- );
324
- if (cardTypeDetails) {
325
- promiseContainer.push(cardTypeDetails);
305
+ const container = [];
306
+ for (const cardType of this.project.resources.cardTypes()) {
307
+ if (cardType.data) {
308
+ container.push(cardType.data);
326
309
  }
327
310
  }
328
- const results = await Promise.all(promiseContainer);
329
- return results.filter((item) => item);
330
- }
331
-
332
- /**
333
- * Shows the content of a file in a resource.
334
- * TODO: To be removed
335
- * @deprecated
336
- * @param resourceName Name of the resource.
337
- * @param fileName Name of the file to show.
338
- * @returns the content of the file.
339
- */
340
- public async showFile(
341
- resourceName: ResourceName,
342
- fileName: string,
343
- ): Promise<string> {
344
- const resourceNameStr = resourceNameToString(resourceName);
345
- if (
346
- !(await this.project.resourceExists(
347
- resourceName.type as ResourceFolderType,
348
- resourceNameStr,
349
- ))
350
- ) {
351
- throw new Error(
352
- `Resource '${resourceNameStr}' does not exist in the project`,
353
- );
354
- }
355
- const resource = Project.resourceObject(this.project, resourceName);
356
- if (!(resource instanceof FolderResource)) {
357
- throw new Error(`Resource '${resourceNameStr}' is not a folder resource`);
358
- }
359
- return resource.showFile(fileName);
360
- }
361
-
362
- /**
363
- * Shows all file names in a folder resource.
364
- * TODO: To be removed
365
- * @deprecated
366
- * @param resourceName Name of the resource.
367
- * @returns all file names in the resource.
368
- */
369
- public async showFileNames(resourceName: ResourceName): Promise<string[]> {
370
- const resourceNameStr = resourceNameToString(resourceName);
371
- if (
372
- !(await this.project.resourceExists(
373
- resourceName.type as ResourceFolderType,
374
- resourceNameStr,
375
- ))
376
- ) {
377
- throw new Error(
378
- `Resource '${resourceNameStr}' does not exist in the project`,
379
- );
380
- }
381
- const resource = Project.resourceObject(this.project, resourceName);
382
- if (!(resource instanceof FolderResource)) {
383
- throw new Error(`Resource '${resourceNameStr}' is not a folder resource`);
384
- }
385
- return resource.showFileNames();
311
+ return container;
386
312
  }
387
313
 
388
314
  /**
@@ -405,10 +331,10 @@ export class Show {
405
331
  resolve(this.project.basePath, MODULE_LIST_FULL_PATH),
406
332
  )
407
333
  ).modules;
408
- const currentModules = await this.project.modules();
334
+ const currentModules = this.project.resources.moduleNames();
409
335
  const nonImportedModules = moduleList.filter(
410
336
  (item: ModuleSettingFromHub) => {
411
- return !currentModules.some((module) => item.name === module.name);
337
+ return !currentModules.some((module) => item.name === module);
412
338
  },
413
339
  );
414
340
 
@@ -436,12 +362,12 @@ export class Show {
436
362
  * Returns all unique labels in a project
437
363
  * @returns labels in a list
438
364
  */
439
- public async showLabels(): Promise<string[]> {
440
- const cards = await this.project.showProjectCards();
441
- const templateCards = await this.project.allTemplateCards({
442
- metadata: true,
443
- children: true,
444
- });
365
+ public showLabels(): string[] {
366
+ const cards = flattenCardArray(
367
+ this.project.showProjectCards(),
368
+ this.project,
369
+ );
370
+ const templateCards = this.project.allTemplateCards();
445
371
 
446
372
  const labels = this.collectLabels([...cards, ...templateCards]);
447
373
  return Array.from(new Set(labels));
@@ -479,20 +405,18 @@ export class Show {
479
405
 
480
406
  /**
481
407
  * Returns all project cards in the project. Cards don't have content and nor metadata.
482
- * @note AppUi uses this method.
483
408
  * @returns array of cards
484
409
  */
485
- public async showProjectCards(): Promise<Card[]> {
486
- const projectCards = await this.project.showProjectCards();
487
- return projectCards;
410
+ public showProjectCards(): Card[] {
411
+ return this.project.showProjectCards();
488
412
  }
489
413
 
490
414
  /**
491
415
  * Shows all modules (if any) in a project.
492
416
  * @returns all modules in a project.
493
417
  */
494
- public async showModules(): Promise<string[]> {
495
- return (await this.project.modules()).map((item) => item.name).sort();
418
+ public showModules(): string[] {
419
+ return this.project.resources.moduleNames().sort();
496
420
  }
497
421
 
498
422
  /**
@@ -508,6 +432,7 @@ export class Show {
508
432
  * @param reportName Name of the report to show
509
433
  * @param cardKey Card key to use for the report
510
434
  * @param parameters Additional parameters for the report
435
+ * @param context Context for resource (includes a project instance)
511
436
  * @param outputPath Optional output path for the report
512
437
  * @returns Report results as a string
513
438
  * @throws Error if the report does not exist
@@ -520,9 +445,9 @@ export class Show {
520
445
  outputPath?: string,
521
446
  ): Promise<string> {
522
447
  if (
523
- !(await this.project.reports()).some(
524
- (report) => report.name === reportName,
525
- )
448
+ !this.project.resources
449
+ .reports()
450
+ .some((report) => report.data?.name === reportName)
526
451
  ) {
527
452
  throw new Error(`Report '${reportName}' does not exist`);
528
453
  }
@@ -564,17 +489,35 @@ export class Show {
564
489
  /**
565
490
  * Shows details of certain resource.
566
491
  * @param name Name of resource.
492
+ * @param showUse If true, shows also where resource is used.
493
+ * @param resourceType If specified, checks that the resource is given type.
567
494
  * @returns resource metadata as JSON.
568
495
  */
569
496
  public async showResource(
570
497
  name: string,
571
- showUse: boolean = false,
572
- ): Promise<ResourceContent | undefined> {
573
- const strictNameCheck = true;
574
- const resource = Project.resourceObject(
575
- this.project,
576
- resourceName(name, strictNameCheck),
577
- );
498
+ showUse?: boolean,
499
+ ): Promise<AnyResourceContent>;
500
+ public async showResource<T extends ResourceType>(
501
+ name: string,
502
+ resourceType: T,
503
+ showUse?: boolean,
504
+ ): Promise<ResourceContent<T>>;
505
+ public async showResource(
506
+ name: string,
507
+ arg2?: boolean | ResourceType,
508
+ arg3?: boolean,
509
+ ): Promise<AnyResourceContent> {
510
+ const hasResourceType = typeof arg2 === 'string';
511
+ const resourceType = hasResourceType ? arg2 : null;
512
+ const showUse = hasResourceType ? arg3 : arg2;
513
+
514
+ const type = this.project.resources.extractType(name);
515
+ if (resourceType !== null && resourceType !== type) {
516
+ throw new Error(
517
+ `While fetching '${name}': Expected type '${resourceType}', but got '${type}' instead`,
518
+ );
519
+ }
520
+ const resource = this.project.resources.byType(name, type);
578
521
  const [details, usage] = await Promise.all([
579
522
  resource?.show(),
580
523
  showUse ? resource?.usage() : [],
@@ -595,9 +538,9 @@ export class Show {
595
538
  * @returns sorted array of resources
596
539
  */
597
540
  public async showResources(type: string): Promise<string[]> {
598
- const func = this.resourceFunction.get(type);
541
+ const func = this.resourceFunctions[type];
599
542
  if (!func) return [];
600
- return (await func()).map((item) => item.name).sort();
543
+ return func().sort();
601
544
  }
602
545
 
603
546
  /**
@@ -605,23 +548,22 @@ export class Show {
605
548
  * @returns all templates in a project.
606
549
  */
607
550
  public async showTemplatesWithDetails(): Promise<TemplateConfiguration[]> {
608
- const promiseContainer = (await this.project.templates()).map((template) =>
609
- new TemplateResource(this.project, resourceName(template.name)).show(),
610
- );
611
- const result = await Promise.all(promiseContainer);
612
- return result.filter(Boolean) as TemplateConfiguration[];
551
+ const templates = [];
552
+ for (const template of this.project.resources.templates()) {
553
+ templates.push(template.show());
554
+ }
555
+ return templates;
613
556
  }
614
557
 
615
558
  /**
616
559
  * Shows all workflows with full details in a project.
617
560
  * @returns workflows with full details
618
561
  */
619
- public async showWorkflowsWithDetails(): Promise<(Workflow | undefined)[]> {
620
- const promiseContainer = [];
621
- for (const workflow of await this.project.workflows()) {
622
- promiseContainer.push(this.project.resource<Workflow>(workflow.name));
562
+ public showWorkflowsWithDetails(): (Workflow | undefined)[] {
563
+ const workflows = [];
564
+ for (const workflow of this.project.resources.workflows()) {
565
+ workflows.push(workflow.data);
623
566
  }
624
- const results = await Promise.all(promiseContainer);
625
- return results.filter((item) => item);
567
+ return workflows;
626
568
  }
627
569
  }