@cyberismo/data-handler 0.0.15 → 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 (173) hide show
  1. package/dist/card-metadata-updater.js +7 -1
  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 +19 -3
  5. package/dist/command-handler.js.map +1 -1
  6. package/dist/command-manager.d.ts +24 -1
  7. package/dist/command-manager.js +27 -3
  8. package/dist/command-manager.js.map +1 -1
  9. package/dist/commands/create.d.ts +1 -1
  10. package/dist/commands/create.js +34 -36
  11. package/dist/commands/create.js.map +1 -1
  12. package/dist/commands/export.d.ts +11 -2
  13. package/dist/commands/export.js +54 -41
  14. package/dist/commands/export.js.map +1 -1
  15. package/dist/commands/import.d.ts +9 -1
  16. package/dist/commands/import.js +15 -7
  17. package/dist/commands/import.js.map +1 -1
  18. package/dist/commands/move.js +0 -1
  19. package/dist/commands/move.js.map +1 -1
  20. package/dist/commands/remove.d.ts +8 -1
  21. package/dist/commands/remove.js +8 -4
  22. package/dist/commands/remove.js.map +1 -1
  23. package/dist/commands/rename.d.ts +4 -9
  24. package/dist/commands/rename.js +32 -101
  25. package/dist/commands/rename.js.map +1 -1
  26. package/dist/commands/show.d.ts +16 -10
  27. package/dist/commands/show.js +71 -55
  28. package/dist/commands/show.js.map +1 -1
  29. package/dist/commands/transition.d.ts +9 -2
  30. package/dist/commands/transition.js +25 -17
  31. package/dist/commands/transition.js.map +1 -1
  32. package/dist/commands/update.d.ts +16 -12
  33. package/dist/commands/update.js +19 -17
  34. package/dist/commands/update.js.map +1 -1
  35. package/dist/commands/validate.d.ts +17 -9
  36. package/dist/commands/validate.js +96 -35
  37. package/dist/commands/validate.js.map +1 -1
  38. package/dist/containers/project/calculation-engine.d.ts +7 -4
  39. package/dist/containers/project/calculation-engine.js +61 -66
  40. package/dist/containers/project/calculation-engine.js.map +1 -1
  41. package/dist/containers/project/project-paths.d.ts +5 -4
  42. package/dist/containers/project/project-paths.js +16 -12
  43. package/dist/containers/project/project-paths.js.map +1 -1
  44. package/dist/containers/project/resource-cache.d.ts +169 -0
  45. package/dist/containers/project/resource-cache.js +507 -0
  46. package/dist/containers/project/resource-cache.js.map +1 -0
  47. package/dist/containers/project/resource-handler.d.ts +129 -0
  48. package/dist/containers/project/resource-handler.js +206 -0
  49. package/dist/containers/project/resource-handler.js.map +1 -0
  50. package/dist/containers/project.d.ts +38 -153
  51. package/dist/containers/project.js +129 -405
  52. package/dist/containers/project.js.map +1 -1
  53. package/dist/containers/template.d.ts +8 -2
  54. package/dist/containers/template.js +20 -15
  55. package/dist/containers/template.js.map +1 -1
  56. package/dist/interfaces/folder-content-interfaces.d.ts +5 -3
  57. package/dist/interfaces/folder-content-interfaces.js +3 -3
  58. package/dist/interfaces/folder-content-interfaces.js.map +1 -1
  59. package/dist/interfaces/project-interfaces.d.ts +2 -4
  60. package/dist/interfaces/project-interfaces.js.map +1 -1
  61. package/dist/interfaces/resource-interfaces.d.ts +14 -1
  62. package/dist/interfaces/resource-interfaces.js.map +1 -1
  63. package/dist/macros/graph/index.js +12 -26
  64. package/dist/macros/graph/index.js.map +1 -1
  65. package/dist/macros/index.d.ts +1 -1
  66. package/dist/macros/index.js +2 -2
  67. package/dist/macros/index.js.map +1 -1
  68. package/dist/macros/report/index.js +3 -6
  69. package/dist/macros/report/index.js.map +1 -1
  70. package/dist/module-manager.d.ts +16 -3
  71. package/dist/module-manager.js +51 -19
  72. package/dist/module-manager.js.map +1 -1
  73. package/dist/project-settings.d.ts +16 -3
  74. package/dist/project-settings.js +79 -14
  75. package/dist/project-settings.js.map +1 -1
  76. package/dist/resources/calculation-resource.d.ts +4 -3
  77. package/dist/resources/calculation-resource.js +11 -5
  78. package/dist/resources/calculation-resource.js.map +1 -1
  79. package/dist/resources/card-type-resource.d.ts +6 -1
  80. package/dist/resources/card-type-resource.js +34 -23
  81. package/dist/resources/card-type-resource.js.map +1 -1
  82. package/dist/resources/create-defaults.d.ts +3 -2
  83. package/dist/resources/create-defaults.js +3 -2
  84. package/dist/resources/create-defaults.js.map +1 -1
  85. package/dist/resources/field-type-resource.d.ts +4 -1
  86. package/dist/resources/field-type-resource.js +22 -23
  87. package/dist/resources/field-type-resource.js.map +1 -1
  88. package/dist/resources/file-resource.d.ts +5 -9
  89. package/dist/resources/file-resource.js +6 -11
  90. package/dist/resources/file-resource.js.map +1 -1
  91. package/dist/resources/folder-resource.d.ts +29 -32
  92. package/dist/resources/folder-resource.js +59 -78
  93. package/dist/resources/folder-resource.js.map +1 -1
  94. package/dist/resources/graph-model-resource.d.ts +4 -1
  95. package/dist/resources/graph-model-resource.js +11 -4
  96. package/dist/resources/graph-model-resource.js.map +1 -1
  97. package/dist/resources/graph-view-resource.d.ts +5 -2
  98. package/dist/resources/graph-view-resource.js +7 -3
  99. package/dist/resources/graph-view-resource.js.map +1 -1
  100. package/dist/resources/link-type-resource.d.ts +5 -2
  101. package/dist/resources/link-type-resource.js +5 -2
  102. package/dist/resources/link-type-resource.js.map +1 -1
  103. package/dist/resources/report-resource.d.ts +6 -7
  104. package/dist/resources/report-resource.js +14 -23
  105. package/dist/resources/report-resource.js.map +1 -1
  106. package/dist/resources/resource-object.d.ts +93 -8
  107. package/dist/resources/resource-object.js +162 -110
  108. package/dist/resources/resource-object.js.map +1 -1
  109. package/dist/resources/template-resource.d.ts +7 -3
  110. package/dist/resources/template-resource.js +10 -3
  111. package/dist/resources/template-resource.js.map +1 -1
  112. package/dist/resources/workflow-resource.d.ts +5 -2
  113. package/dist/resources/workflow-resource.js +18 -22
  114. package/dist/resources/workflow-resource.js.map +1 -1
  115. package/dist/utils/card-utils.d.ts +2 -2
  116. package/dist/utils/card-utils.js +1 -1
  117. package/dist/utils/clingo-fact-builder.d.ts +25 -14
  118. package/dist/utils/clingo-fact-builder.js +27 -5
  119. package/dist/utils/clingo-fact-builder.js.map +1 -1
  120. package/dist/utils/clingo-facts.js +3 -4
  121. package/dist/utils/clingo-facts.js.map +1 -1
  122. package/dist/utils/resource-utils.d.ts +1 -0
  123. package/dist/utils/resource-utils.js +2 -1
  124. package/dist/utils/resource-utils.js.map +1 -1
  125. package/package.json +8 -8
  126. package/src/card-metadata-updater.ts +6 -2
  127. package/src/command-handler.ts +24 -5
  128. package/src/command-manager.ts +29 -17
  129. package/src/commands/create.ts +43 -78
  130. package/src/commands/export.ts +63 -52
  131. package/src/commands/import.ts +24 -14
  132. package/src/commands/move.ts +0 -1
  133. package/src/commands/remove.ts +11 -7
  134. package/src/commands/rename.ts +43 -149
  135. package/src/commands/show.ts +113 -78
  136. package/src/commands/transition.ts +26 -28
  137. package/src/commands/update.ts +25 -22
  138. package/src/commands/validate.ts +108 -67
  139. package/src/containers/project/calculation-engine.ts +61 -93
  140. package/src/containers/project/project-paths.ts +21 -13
  141. package/src/containers/project/resource-cache.ts +648 -0
  142. package/src/containers/project/resource-handler.ts +265 -0
  143. package/src/containers/project.ts +178 -522
  144. package/src/containers/template.ts +24 -19
  145. package/src/interfaces/folder-content-interfaces.ts +7 -6
  146. package/src/interfaces/project-interfaces.ts +7 -6
  147. package/src/interfaces/resource-interfaces.ts +18 -3
  148. package/src/macros/graph/index.ts +26 -47
  149. package/src/macros/index.ts +2 -2
  150. package/src/macros/report/index.ts +3 -9
  151. package/src/module-manager.ts +74 -17
  152. package/src/project-settings.ts +83 -14
  153. package/src/resources/calculation-resource.ts +18 -18
  154. package/src/resources/card-type-resource.ts +50 -50
  155. package/src/resources/create-defaults.ts +3 -2
  156. package/src/resources/field-type-resource.ts +41 -55
  157. package/src/resources/file-resource.ts +10 -36
  158. package/src/resources/folder-resource.ts +69 -120
  159. package/src/resources/graph-model-resource.ts +20 -22
  160. package/src/resources/graph-view-resource.ts +15 -17
  161. package/src/resources/link-type-resource.ts +10 -13
  162. package/src/resources/report-resource.ts +21 -43
  163. package/src/resources/resource-object.ts +194 -152
  164. package/src/resources/template-resource.ts +17 -16
  165. package/src/resources/workflow-resource.ts +25 -44
  166. package/src/utils/card-utils.ts +2 -2
  167. package/src/utils/clingo-fact-builder.ts +28 -16
  168. package/src/utils/clingo-facts.ts +3 -4
  169. package/src/utils/resource-utils.ts +2 -1
  170. package/dist/containers/project/resource-collector.d.ts +0 -110
  171. package/dist/containers/project/resource-collector.js +0 -344
  172. package/dist/containers/project/resource-collector.js.map +0 -1
  173. package/src/containers/project/resource-collector.ts +0 -404
@@ -14,15 +14,18 @@
14
14
  import { ActionGuard } from '../permissions/action-guard.js';
15
15
  import { isModuleCard } from '../utils/card-utils.js';
16
16
  import { ModuleManager } from '../module-manager.js';
17
- import { Project } from '../containers/project.js';
17
+ import type { Project } from '../containers/project.js';
18
18
  import type { RemovableResourceTypes } from '../interfaces/project-interfaces.js';
19
- import { resourceName } from '../utils/resource-utils.js';
20
19
 
21
20
  /**
22
21
  * Remove command.
23
22
  */
24
23
  export class Remove {
25
24
  private moduleManager: ModuleManager;
25
+ /**
26
+ * Creates a new instance of Remove command.
27
+ * @param project Project instance to use
28
+ */
26
29
  constructor(private project: Project) {
27
30
  this.moduleManager = new ModuleManager(this.project);
28
31
  }
@@ -152,14 +155,15 @@ export class Remove {
152
155
  * @param rest Additional arguments
153
156
  * @note removing attachment requires card id and attachment filename
154
157
  * @note removing link requires card ids of source card, and optionally link type and link description
158
+ * @throws when removing an attachment, but attachment parameter is missing, or
159
+ * when removing link, some of the mandatory parameters are missing, or
160
+ * when trying to remove unknown type
155
161
  */
156
162
  public async remove(
157
163
  type: RemovableResourceTypes,
158
164
  targetName: string,
159
165
  ...rest: any[] // eslint-disable-line @typescript-eslint/no-explicit-any
160
166
  ) {
161
- const strictNameCheck = true;
162
-
163
167
  if (type === 'attachment' && rest.length !== 1 && !rest[0]) {
164
168
  throw new Error(
165
169
  `Input validation error: must pass argument 'detail' if requesting to remove attachment`,
@@ -177,9 +181,9 @@ export class Remove {
177
181
  );
178
182
  }
179
183
  if (this.projectResource(type)) {
180
- const resource = Project.resourceObject(
181
- this.project,
182
- resourceName(targetName, strictNameCheck),
184
+ const resource = this.project.resources.byType(
185
+ targetName,
186
+ this.project.resources.resourceTypeFromSingularType(type),
183
187
  );
184
188
  return resource?.delete();
185
189
  } else {
@@ -20,17 +20,6 @@ import type { Card } from '../interfaces/project-interfaces.js';
20
20
  import { isTemplateCard } from '../utils/card-utils.js';
21
21
  import { type Project, ResourcesFrom } from '../containers/project.js';
22
22
  import { resourceName } from '../utils/resource-utils.js';
23
- import { Template } from '../containers/template.js';
24
-
25
- import { CalculationResource } from '../resources/calculation-resource.js';
26
- import { CardTypeResource } from '../resources/card-type-resource.js';
27
- import { FieldTypeResource } from '../resources/field-type-resource.js';
28
- import { GraphModelResource } from '../resources/graph-model-resource.js';
29
- import { GraphViewResource } from '../resources/graph-view-resource.js';
30
- import { LinkTypeResource } from '../resources/link-type-resource.js';
31
- import { ReportResource } from '../resources/report-resource.js';
32
- import { TemplateResource } from '../resources/template-resource.js';
33
- import { WorkflowResource } from '../resources/workflow-resource.js';
34
23
 
35
24
  const FILE_TYPES_WITH_PREFIX_REFERENCES = ['adoc', 'hbs', 'json', 'lp'];
36
25
 
@@ -41,6 +30,10 @@ export class Rename {
41
30
  private from: string = '';
42
31
  private to: string = '';
43
32
 
33
+ /**
34
+ * Creates an instance of Rename command.
35
+ * @param project Project instance to use.
36
+ */
44
37
  constructor(private project: Project) {}
45
38
 
46
39
  // Renames a card and all of its attachments (if it is a project card).
@@ -183,93 +176,6 @@ export class Rename {
183
176
  : name;
184
177
  }
185
178
 
186
- // @todo: merge all update-functions
187
- // Updates card type's metadata.
188
- private async updateCardTypeMetadata(cardTypeName: string) {
189
- const cardType = new CardTypeResource(
190
- this.project,
191
- resourceName(cardTypeName),
192
- );
193
- return cardType.rename(resourceName(this.updateResourceName(cardTypeName)));
194
- }
195
-
196
- // Rename calculations.
197
- private async updateCalculation(calculationName: string) {
198
- const calculation = new CalculationResource(
199
- this.project,
200
- resourceName(calculationName),
201
- );
202
- return calculation.rename(
203
- resourceName(this.updateResourceName(calculationName)),
204
- );
205
- }
206
-
207
- // Updates field type's metadata.
208
- private async updateFieldTypeMetadata(fieldTypeName: string) {
209
- const fieldType = new FieldTypeResource(
210
- this.project,
211
- resourceName(fieldTypeName),
212
- );
213
- return fieldType.rename(
214
- resourceName(this.updateResourceName(fieldTypeName)),
215
- );
216
- }
217
-
218
- // Updates graph model's metadata.
219
- private async updateGraphModelMetadata(graphModelName: string) {
220
- const graphModel = new GraphModelResource(
221
- this.project,
222
- resourceName(graphModelName),
223
- );
224
- return graphModel.rename(
225
- resourceName(this.updateResourceName(graphModelName)),
226
- );
227
- }
228
-
229
- // Updates graph view's metadata.
230
- private async updateGraphViewMetadata(graphViewName: string) {
231
- const graphView = new GraphViewResource(
232
- this.project,
233
- resourceName(graphViewName),
234
- );
235
- return graphView.rename(
236
- resourceName(this.updateResourceName(graphViewName)),
237
- );
238
- }
239
-
240
- // Updates link type's metadata.
241
- private async updateLinkTypeMetadata(linkTypeName: string) {
242
- const linkType = new LinkTypeResource(
243
- this.project,
244
- resourceName(linkTypeName),
245
- );
246
- return linkType.rename(resourceName(this.updateResourceName(linkTypeName)));
247
- }
248
-
249
- // Updates reports' metadata.
250
- private async updateReport(reportName: string) {
251
- const report = new ReportResource(this.project, resourceName(reportName));
252
- return report.rename(resourceName(this.updateResourceName(reportName)));
253
- }
254
-
255
- // Rename templates.
256
- private async updateTemplate(templateName: string) {
257
- const template = new TemplateResource(
258
- this.project,
259
- resourceName(templateName),
260
- );
261
- return template.rename(resourceName(this.updateResourceName(templateName)));
262
- }
263
-
264
- // Rename workflows.
265
- private async updateWorkflowMetadata(workflowName: string) {
266
- const workflow = new WorkflowResource(
267
- this.project,
268
- resourceName(workflowName),
269
- );
270
- return workflow.rename(resourceName(this.updateResourceName(workflowName)));
271
- }
272
-
273
179
  /**
274
180
  * Renames project prefix.
275
181
  * @throws if trying to use empty 'to'
@@ -294,72 +200,60 @@ export class Rename {
294
200
  await this.project.configuration.setCardPrefix(to);
295
201
  console.info(`Rename: New prefix: '${this.project.projectPrefix}'`);
296
202
  // Update the resources collection, since project prefix has changed.
297
- this.project.collectLocalResources();
203
+ this.project.resources.changed();
298
204
 
299
205
  // Rename local resources.
300
- // It is better to rename the resources in this order: card types, field types, then others
206
+ // It is better to rename the resources in this order: card types, workflows, field types, then the rest
301
207
 
302
208
  // Rename all card types and custom fields in them.
303
- const cardTypes = await this.project.cardTypes(ResourcesFrom.localOnly);
304
- for (const cardType of cardTypes) {
305
- await this.updateCardTypeMetadata(cardType.name);
209
+ for (const cardType of this.project.resources.cardTypes(
210
+ ResourcesFrom.localOnly,
211
+ )) {
212
+ const name = this.updateResourceName(cardType.data?.name || '');
213
+ await cardType.rename(resourceName(name));
306
214
  }
307
215
  console.info('Updated card types');
308
216
 
309
- const workflows = await this.project.workflows(ResourcesFrom.localOnly);
310
- for (const workflow of workflows) {
311
- await this.updateWorkflowMetadata(workflow.name);
217
+ for (const workflow of this.project.resources.workflows(
218
+ ResourcesFrom.localOnly,
219
+ )) {
220
+ const name = this.updateResourceName(workflow.data?.name || '');
221
+ await workflow.rename(resourceName(name));
312
222
  }
313
223
  console.info('Updated workflows');
314
224
 
315
- const fieldTypes = await this.project.fieldTypes(ResourcesFrom.localOnly);
316
- for (const fieldType of fieldTypes) {
317
- await this.updateFieldTypeMetadata(fieldType.name);
225
+ for (const fieldType of this.project.resources.fieldTypes(
226
+ ResourcesFrom.localOnly,
227
+ )) {
228
+ const name = this.updateResourceName(fieldType.data?.name || '');
229
+ await fieldType.rename(resourceName(name));
318
230
  }
319
231
  console.info('Updated field types');
320
232
 
321
- const graphModels = await this.project.graphModels(ResourcesFrom.localOnly);
322
- for (const graphModel of graphModels) {
323
- await this.updateGraphModelMetadata(graphModel.name);
324
- }
325
- console.info('Updated graph models');
326
-
327
- const graphViews = await this.project.graphViews(ResourcesFrom.localOnly);
328
- for (const graphView of graphViews) {
329
- await this.updateGraphViewMetadata(graphView.name);
330
- }
331
- console.info('Updated graph views');
332
-
333
- const linkTypes = await this.project.linkTypes(ResourcesFrom.localOnly);
334
- for (const linkType of linkTypes) {
335
- await this.updateLinkTypeMetadata(linkType.name);
336
- }
337
- console.info('Updated link types');
338
-
339
- const reports = await this.project.reports(ResourcesFrom.localOnly);
340
- for (const report of reports) {
341
- await this.updateReport(report.name);
342
- }
343
- console.info('Updated reports');
344
-
345
- let templates = await this.project.templates(ResourcesFrom.localOnly);
346
- for (const template of templates) {
347
- await this.updateTemplate(template.name);
233
+ const restOfResourceTypes = [
234
+ 'graphModels',
235
+ 'graphViews',
236
+ 'linkTypes',
237
+ 'reports',
238
+ 'templates',
239
+ 'calculations',
240
+ ] as const;
241
+
242
+ for (const resourceType of restOfResourceTypes) {
243
+ for (const resource of this.project.resources.resourceTypes(
244
+ resourceType,
245
+ ResourcesFrom.localOnly,
246
+ )) {
247
+ const name = this.updateResourceName(resource.data?.name || '');
248
+ await resource.rename(resourceName(name));
249
+ }
348
250
  }
349
- console.info('Updated templates');
350
251
 
351
- const calculations = await this.project.calculations(
252
+ // Rename all local template cards. This must be done after calculations have been renamed.
253
+ for (const template of this.project.resources.templates(
352
254
  ResourcesFrom.localOnly,
353
- );
354
- for (const calculation of calculations) {
355
- await this.updateCalculation(calculation.name);
356
- }
357
- console.info('Updated calculations');
358
-
359
- // Rename all local template cards.
360
- templates = await this.project.templates(ResourcesFrom.localOnly);
361
- for (const template of templates) {
362
- const templateObject = new Template(this.project, template);
255
+ )) {
256
+ const templateObject = template.templateObject();
363
257
  await this.renameCards(templateObject.cards());
364
258
  }
365
259
  console.info('Renamed template cards and updated the content');
@@ -376,7 +270,7 @@ export class Rename {
376
270
  console.info('Renamed all remaining references in .cards folder');
377
271
 
378
272
  // It is best that the resources are re-collected after all the renaming has occurred.
379
- this.project.collectLocalResources();
273
+ this.project.resources.changed();
380
274
  console.info('Collected renamed resources');
381
275
 
382
276
  return this.project.calculationEngine.generate();
@@ -34,47 +34,47 @@ import type {
34
34
  ModuleContent,
35
35
  ModuleSettingFromHub,
36
36
  ProjectMetadata,
37
- Resource,
37
+ ResourceType,
38
38
  } from '../interfaces/project-interfaces.js';
39
39
  import type {
40
+ AnyResourceContent,
40
41
  CardType,
41
42
  ResourceContent,
42
43
  TemplateConfiguration,
43
44
  Workflow,
44
45
  } from '../interfaces/resource-interfaces.js';
45
- import { Project, type ResourcesFrom } from '../containers/project.js';
46
- import { type ResourceName, resourceName } from '../utils/resource-utils.js';
47
- import { TemplateResource } from '../resources/template-resource.js';
48
- 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';
49
49
 
50
+ import { UserPreferences } from '../utils/user-preferences.js';
50
51
  import ReportMacro from '../macros/report/index.js';
51
52
  import TaskQueue from '../macros/task-queue.js';
52
53
  import { evaluateMacros } from '../macros/index.js';
53
54
  import { readJsonFile } from '../utils/json.js';
54
55
  import { getChildLogger } from '../utils/log-utils.js';
55
- import { buildCardHierarchy } from '../utils/card-utils.js';
56
+ import { buildCardHierarchy, flattenCardArray } from '../utils/card-utils.js';
56
57
 
57
58
  /**
58
59
  * Show command.
59
60
  */
60
61
  export class Show {
61
- private resourceFunction: Map<
62
+ private readonly resourceFunctions: Record<
62
63
  string,
63
- (from?: ResourcesFrom) => Promise<Resource[]>
64
- >;
65
- constructor(private project: Project) {
66
- this.resourceFunction = new Map([
67
- ['calculations', this.project.calculations.bind(this.project)],
68
- ['cardTypes', this.project.cardTypes.bind(this.project)],
69
- ['fieldTypes', this.project.fieldTypes.bind(this.project)],
70
- ['graphModels', this.project.graphModels.bind(this.project)],
71
- ['graphViews', this.project.graphViews.bind(this.project)],
72
- ['linkTypes', this.project.linkTypes.bind(this.project)],
73
- ['reports', this.project.reports.bind(this.project)],
74
- ['templates', this.project.templates.bind(this.project)],
75
- ['workflows', this.project.workflows.bind(this.project)],
76
- ]);
77
- }
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) {}
78
78
 
79
79
  private get logger() {
80
80
  return getChildLogger({
@@ -82,6 +82,29 @@ export class Show {
82
82
  });
83
83
  }
84
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
+
85
108
  // Collect all labels from cards.
86
109
  private collectLabels = (cards: Card[]): string[] => {
87
110
  return cards.reduce<string[]>((labels, card) => {
@@ -120,24 +143,19 @@ export class Show {
120
143
  * Shows all template cards in a project.
121
144
  * @returns all template cards in a project.
122
145
  */
123
- public async showAllTemplateCards(): Promise<
124
- { name: string; cards: CardWithChildrenCards[] }[]
125
- > {
126
- return Promise.all(
127
- (await this.project.templates()).map((template) => {
128
- const templateResource = new TemplateResource(
129
- this.project,
130
- resourceName(template.name),
131
- );
132
- const cards = templateResource.templateObject().listCards();
133
- const buildCards = buildCardHierarchy(cards);
134
-
135
- return {
136
- name: template.name,
137
- cards: buildCards,
138
- };
139
- }),
140
- );
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
+ });
141
159
  }
142
160
 
143
161
  /**
@@ -146,7 +164,7 @@ export class Show {
146
164
  */
147
165
  public async showAttachments(): Promise<CardAttachment[]> {
148
166
  const attachments = this.project.attachments();
149
- const templateAttachments = await this.project.attachmentsFromTemplates();
167
+ const templateAttachments = await this.attachmentsFromTemplates();
150
168
  attachments.push(...templateAttachments);
151
169
  return attachments;
152
170
  }
@@ -284,17 +302,13 @@ export class Show {
284
302
  * @returns array of card type details
285
303
  */
286
304
  public async showCardTypesWithDetails(): Promise<(CardType | undefined)[]> {
287
- const promiseContainer = [];
288
- for (const cardType of await this.project.cardTypes()) {
289
- const cardTypeDetails = await this.project.resource<CardType>(
290
- cardType.name,
291
- );
292
- if (cardTypeDetails) {
293
- promiseContainer.push(cardTypeDetails);
305
+ const container = [];
306
+ for (const cardType of this.project.resources.cardTypes()) {
307
+ if (cardType.data) {
308
+ container.push(cardType.data);
294
309
  }
295
310
  }
296
- const results = await Promise.all(promiseContainer);
297
- return results.filter((item) => item);
311
+ return container;
298
312
  }
299
313
 
300
314
  /**
@@ -317,10 +331,10 @@ export class Show {
317
331
  resolve(this.project.basePath, MODULE_LIST_FULL_PATH),
318
332
  )
319
333
  ).modules;
320
- const currentModules = await this.project.modules();
334
+ const currentModules = this.project.resources.moduleNames();
321
335
  const nonImportedModules = moduleList.filter(
322
336
  (item: ModuleSettingFromHub) => {
323
- return !currentModules.some((module) => item.name === module.name);
337
+ return !currentModules.some((module) => item.name === module);
324
338
  },
325
339
  );
326
340
 
@@ -349,7 +363,10 @@ export class Show {
349
363
  * @returns labels in a list
350
364
  */
351
365
  public showLabels(): string[] {
352
- const cards = this.project.showProjectCards();
366
+ const cards = flattenCardArray(
367
+ this.project.showProjectCards(),
368
+ this.project,
369
+ );
353
370
  const templateCards = this.project.allTemplateCards();
354
371
 
355
372
  const labels = this.collectLabels([...cards, ...templateCards]);
@@ -398,8 +415,8 @@ export class Show {
398
415
  * Shows all modules (if any) in a project.
399
416
  * @returns all modules in a project.
400
417
  */
401
- public async showModules(): Promise<string[]> {
402
- return (await this.project.modules()).map((item) => item.name).sort();
418
+ public showModules(): string[] {
419
+ return this.project.resources.moduleNames().sort();
403
420
  }
404
421
 
405
422
  /**
@@ -415,6 +432,7 @@ export class Show {
415
432
  * @param reportName Name of the report to show
416
433
  * @param cardKey Card key to use for the report
417
434
  * @param parameters Additional parameters for the report
435
+ * @param context Context for resource (includes a project instance)
418
436
  * @param outputPath Optional output path for the report
419
437
  * @returns Report results as a string
420
438
  * @throws Error if the report does not exist
@@ -427,9 +445,9 @@ export class Show {
427
445
  outputPath?: string,
428
446
  ): Promise<string> {
429
447
  if (
430
- !(await this.project.reports()).some(
431
- (report) => report.name === reportName,
432
- )
448
+ !this.project.resources
449
+ .reports()
450
+ .some((report) => report.data?.name === reportName)
433
451
  ) {
434
452
  throw new Error(`Report '${reportName}' does not exist`);
435
453
  }
@@ -471,17 +489,35 @@ export class Show {
471
489
  /**
472
490
  * Shows details of certain resource.
473
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.
474
494
  * @returns resource metadata as JSON.
475
495
  */
476
496
  public async showResource(
477
497
  name: string,
478
- showUse: boolean = false,
479
- ): Promise<ResourceContent | undefined> {
480
- const strictNameCheck = true;
481
- const resource = Project.resourceObject(
482
- this.project,
483
- resourceName(name, strictNameCheck),
484
- );
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);
485
521
  const [details, usage] = await Promise.all([
486
522
  resource?.show(),
487
523
  showUse ? resource?.usage() : [],
@@ -502,9 +538,9 @@ export class Show {
502
538
  * @returns sorted array of resources
503
539
  */
504
540
  public async showResources(type: string): Promise<string[]> {
505
- const func = this.resourceFunction.get(type);
541
+ const func = this.resourceFunctions[type];
506
542
  if (!func) return [];
507
- return (await func()).map((item) => item.name).sort();
543
+ return func().sort();
508
544
  }
509
545
 
510
546
  /**
@@ -512,23 +548,22 @@ export class Show {
512
548
  * @returns all templates in a project.
513
549
  */
514
550
  public async showTemplatesWithDetails(): Promise<TemplateConfiguration[]> {
515
- const promiseContainer = (await this.project.templates()).map((template) =>
516
- new TemplateResource(this.project, resourceName(template.name)).show(),
517
- );
518
- const result = await Promise.all(promiseContainer);
519
- 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;
520
556
  }
521
557
 
522
558
  /**
523
559
  * Shows all workflows with full details in a project.
524
560
  * @returns workflows with full details
525
561
  */
526
- public async showWorkflowsWithDetails(): Promise<(Workflow | undefined)[]> {
527
- const promiseContainer = [];
528
- for (const workflow of await this.project.workflows()) {
529
- 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);
530
566
  }
531
- const results = await Promise.all(promiseContainer);
532
- return results.filter((item) => item);
567
+ return workflows;
533
568
  }
534
569
  }