@cyberismo/data-handler 0.0.15 → 0.0.17

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 (191) 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 +22 -8
  5. package/dist/command-handler.js.map +1 -1
  6. package/dist/command-manager.d.ts +24 -1
  7. package/dist/command-manager.js +31 -7
  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/fetch.d.ts +8 -0
  16. package/dist/commands/fetch.js +101 -23
  17. package/dist/commands/fetch.js.map +1 -1
  18. package/dist/commands/import.d.ts +14 -3
  19. package/dist/commands/import.js +27 -10
  20. package/dist/commands/import.js.map +1 -1
  21. package/dist/commands/move.js +0 -1
  22. package/dist/commands/move.js.map +1 -1
  23. package/dist/commands/remove.d.ts +11 -2
  24. package/dist/commands/remove.js +15 -5
  25. package/dist/commands/remove.js.map +1 -1
  26. package/dist/commands/rename.d.ts +4 -9
  27. package/dist/commands/rename.js +37 -101
  28. package/dist/commands/rename.js.map +1 -1
  29. package/dist/commands/show.d.ts +20 -12
  30. package/dist/commands/show.js +79 -57
  31. package/dist/commands/show.js.map +1 -1
  32. package/dist/commands/transition.d.ts +9 -2
  33. package/dist/commands/transition.js +25 -17
  34. package/dist/commands/transition.js.map +1 -1
  35. package/dist/commands/update.d.ts +16 -12
  36. package/dist/commands/update.js +19 -17
  37. package/dist/commands/update.js.map +1 -1
  38. package/dist/commands/validate.d.ts +17 -9
  39. package/dist/commands/validate.js +94 -35
  40. package/dist/commands/validate.js.map +1 -1
  41. package/dist/containers/card-container.d.ts +7 -5
  42. package/dist/containers/card-container.js +30 -5
  43. package/dist/containers/card-container.js.map +1 -1
  44. package/dist/containers/project/calculation-engine.d.ts +7 -4
  45. package/dist/containers/project/calculation-engine.js +61 -66
  46. package/dist/containers/project/calculation-engine.js.map +1 -1
  47. package/dist/containers/project/project-paths.d.ts +7 -4
  48. package/dist/containers/project/project-paths.js +22 -12
  49. package/dist/containers/project/project-paths.js.map +1 -1
  50. package/dist/containers/project/resource-cache.d.ts +169 -0
  51. package/dist/containers/project/resource-cache.js +509 -0
  52. package/dist/containers/project/resource-cache.js.map +1 -0
  53. package/dist/containers/project/resource-handler.d.ts +129 -0
  54. package/dist/containers/project/resource-handler.js +206 -0
  55. package/dist/containers/project/resource-handler.js.map +1 -0
  56. package/dist/containers/project.d.ts +46 -152
  57. package/dist/containers/project.js +179 -409
  58. package/dist/containers/project.js.map +1 -1
  59. package/dist/containers/template.d.ts +8 -2
  60. package/dist/containers/template.js +24 -19
  61. package/dist/containers/template.js.map +1 -1
  62. package/dist/interfaces/command-options.d.ts +3 -1
  63. package/dist/interfaces/folder-content-interfaces.d.ts +5 -3
  64. package/dist/interfaces/folder-content-interfaces.js +3 -3
  65. package/dist/interfaces/folder-content-interfaces.js.map +1 -1
  66. package/dist/interfaces/project-interfaces.d.ts +7 -9
  67. package/dist/interfaces/project-interfaces.js.map +1 -1
  68. package/dist/interfaces/resource-interfaces.d.ts +14 -1
  69. package/dist/interfaces/resource-interfaces.js.map +1 -1
  70. package/dist/macros/graph/index.js +12 -26
  71. package/dist/macros/graph/index.js.map +1 -1
  72. package/dist/macros/index.d.ts +1 -1
  73. package/dist/macros/index.js +2 -2
  74. package/dist/macros/index.js.map +1 -1
  75. package/dist/macros/report/index.js +3 -6
  76. package/dist/macros/report/index.js.map +1 -1
  77. package/dist/module-manager.d.ts +16 -3
  78. package/dist/module-manager.js +51 -19
  79. package/dist/module-manager.js.map +1 -1
  80. package/dist/project-settings.d.ts +21 -3
  81. package/dist/project-settings.js +91 -14
  82. package/dist/project-settings.js.map +1 -1
  83. package/dist/resources/calculation-resource.d.ts +4 -3
  84. package/dist/resources/calculation-resource.js +11 -5
  85. package/dist/resources/calculation-resource.js.map +1 -1
  86. package/dist/resources/card-type-resource.d.ts +6 -1
  87. package/dist/resources/card-type-resource.js +34 -23
  88. package/dist/resources/card-type-resource.js.map +1 -1
  89. package/dist/resources/create-defaults.d.ts +3 -2
  90. package/dist/resources/create-defaults.js +3 -2
  91. package/dist/resources/create-defaults.js.map +1 -1
  92. package/dist/resources/field-type-resource.d.ts +4 -1
  93. package/dist/resources/field-type-resource.js +22 -23
  94. package/dist/resources/field-type-resource.js.map +1 -1
  95. package/dist/resources/file-resource.d.ts +5 -9
  96. package/dist/resources/file-resource.js +6 -11
  97. package/dist/resources/file-resource.js.map +1 -1
  98. package/dist/resources/folder-resource.d.ts +29 -32
  99. package/dist/resources/folder-resource.js +59 -78
  100. package/dist/resources/folder-resource.js.map +1 -1
  101. package/dist/resources/graph-model-resource.d.ts +4 -1
  102. package/dist/resources/graph-model-resource.js +11 -4
  103. package/dist/resources/graph-model-resource.js.map +1 -1
  104. package/dist/resources/graph-view-resource.d.ts +5 -2
  105. package/dist/resources/graph-view-resource.js +7 -3
  106. package/dist/resources/graph-view-resource.js.map +1 -1
  107. package/dist/resources/link-type-resource.d.ts +5 -2
  108. package/dist/resources/link-type-resource.js +5 -2
  109. package/dist/resources/link-type-resource.js.map +1 -1
  110. package/dist/resources/report-resource.d.ts +6 -7
  111. package/dist/resources/report-resource.js +14 -23
  112. package/dist/resources/report-resource.js.map +1 -1
  113. package/dist/resources/resource-object.d.ts +94 -8
  114. package/dist/resources/resource-object.js +212 -109
  115. package/dist/resources/resource-object.js.map +1 -1
  116. package/dist/resources/template-resource.d.ts +7 -3
  117. package/dist/resources/template-resource.js +10 -3
  118. package/dist/resources/template-resource.js.map +1 -1
  119. package/dist/resources/workflow-resource.d.ts +5 -2
  120. package/dist/resources/workflow-resource.js +18 -22
  121. package/dist/resources/workflow-resource.js.map +1 -1
  122. package/dist/utils/card-utils.d.ts +2 -2
  123. package/dist/utils/card-utils.js +1 -1
  124. package/dist/utils/clingo-fact-builder.d.ts +25 -14
  125. package/dist/utils/clingo-fact-builder.js +27 -5
  126. package/dist/utils/clingo-fact-builder.js.map +1 -1
  127. package/dist/utils/clingo-facts.js +3 -4
  128. package/dist/utils/clingo-facts.js.map +1 -1
  129. package/dist/utils/configuration-logger.d.ts +91 -0
  130. package/dist/utils/configuration-logger.js +151 -0
  131. package/dist/utils/configuration-logger.js.map +1 -0
  132. package/dist/utils/constants.d.ts +1 -1
  133. package/dist/utils/constants.js +5 -3
  134. package/dist/utils/constants.js.map +1 -1
  135. package/dist/utils/resource-utils.d.ts +1 -0
  136. package/dist/utils/resource-utils.js +2 -1
  137. package/dist/utils/resource-utils.js.map +1 -1
  138. package/package.json +9 -9
  139. package/src/card-metadata-updater.ts +6 -2
  140. package/src/command-handler.ts +39 -12
  141. package/src/command-manager.ts +33 -21
  142. package/src/commands/create.ts +43 -78
  143. package/src/commands/export.ts +63 -52
  144. package/src/commands/fetch.ts +143 -34
  145. package/src/commands/import.ts +37 -15
  146. package/src/commands/move.ts +0 -1
  147. package/src/commands/remove.ts +20 -7
  148. package/src/commands/rename.ts +58 -149
  149. package/src/commands/show.ts +123 -80
  150. package/src/commands/transition.ts +26 -28
  151. package/src/commands/update.ts +25 -22
  152. package/src/commands/validate.ts +104 -67
  153. package/src/containers/card-container.ts +37 -5
  154. package/src/containers/project/calculation-engine.ts +61 -93
  155. package/src/containers/project/project-paths.ts +29 -13
  156. package/src/containers/project/resource-cache.ts +651 -0
  157. package/src/containers/project/resource-handler.ts +265 -0
  158. package/src/containers/project.ts +250 -527
  159. package/src/containers/template.ts +28 -23
  160. package/src/interfaces/command-options.ts +3 -1
  161. package/src/interfaces/folder-content-interfaces.ts +7 -6
  162. package/src/interfaces/project-interfaces.ts +12 -11
  163. package/src/interfaces/resource-interfaces.ts +18 -3
  164. package/src/macros/graph/index.ts +26 -47
  165. package/src/macros/index.ts +2 -2
  166. package/src/macros/report/index.ts +3 -9
  167. package/src/module-manager.ts +74 -17
  168. package/src/project-settings.ts +96 -14
  169. package/src/resources/calculation-resource.ts +18 -18
  170. package/src/resources/card-type-resource.ts +50 -50
  171. package/src/resources/create-defaults.ts +3 -2
  172. package/src/resources/field-type-resource.ts +41 -55
  173. package/src/resources/file-resource.ts +10 -36
  174. package/src/resources/folder-resource.ts +69 -120
  175. package/src/resources/graph-model-resource.ts +20 -22
  176. package/src/resources/graph-view-resource.ts +15 -17
  177. package/src/resources/link-type-resource.ts +10 -13
  178. package/src/resources/report-resource.ts +21 -43
  179. package/src/resources/resource-object.ts +263 -149
  180. package/src/resources/template-resource.ts +17 -16
  181. package/src/resources/workflow-resource.ts +25 -44
  182. package/src/utils/card-utils.ts +2 -2
  183. package/src/utils/clingo-fact-builder.ts +28 -16
  184. package/src/utils/clingo-facts.ts +3 -4
  185. package/src/utils/configuration-logger.ts +206 -0
  186. package/src/utils/constants.ts +5 -3
  187. package/src/utils/resource-utils.ts +2 -1
  188. package/dist/containers/project/resource-collector.d.ts +0 -110
  189. package/dist/containers/project/resource-collector.js +0 -344
  190. package/dist/containers/project/resource-collector.js.map +0 -1
  191. package/src/containers/project/resource-collector.ts +0 -404
@@ -18,7 +18,7 @@ import { join, resolve } from 'node:path';
18
18
  import { spawn } from 'node:child_process';
19
19
  import { writeFile } from 'node:fs/promises';
20
20
 
21
- import { MODULE_LIST_FULL_PATH } from './fetch.js';
21
+ import { type Fetch, MODULE_LIST_FULL_PATH } from './fetch.js';
22
22
 
23
23
  import type { attachmentPayload } from '../interfaces/request-status-interfaces.js';
24
24
  import type {
@@ -34,47 +34,50 @@ 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(
78
+ private project: Project,
79
+ private fetchCmd: Fetch,
80
+ ) {}
78
81
 
79
82
  private get logger() {
80
83
  return getChildLogger({
@@ -82,6 +85,29 @@ export class Show {
82
85
  });
83
86
  }
84
87
 
88
+ // Gets all template attachments
89
+ private async attachmentsFromTemplates() {
90
+ const templateAttachments: CardAttachment[] = [];
91
+ const templates = this.project.resources.templates();
92
+ for (const template of templates) {
93
+ const templateObject = template.templateObject();
94
+ if (templateObject) {
95
+ templateAttachments.push(...templateObject.attachments());
96
+ }
97
+ }
98
+ return templateAttachments;
99
+ }
100
+
101
+ // Fetch resource names as a list
102
+ private resourceNames<T extends keyof ResourceMap>(
103
+ resourceType: T,
104
+ from?: ResourcesFrom,
105
+ ): string[] {
106
+ return this.project.resources
107
+ .resourceTypes(resourceType, from)
108
+ .map((item) => item.data?.name || '');
109
+ }
110
+
85
111
  // Collect all labels from cards.
86
112
  private collectLabels = (cards: Card[]): string[] => {
87
113
  return cards.reduce<string[]>((labels, card) => {
@@ -120,24 +146,19 @@ export class Show {
120
146
  * Shows all template cards in a project.
121
147
  * @returns all template cards in a project.
122
148
  */
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
- );
149
+ public showAllTemplateCards(): {
150
+ name: string;
151
+ cards: CardWithChildrenCards[];
152
+ }[] {
153
+ return this.project.resources.templates().map((template) => {
154
+ const cards = template.templateObject().listCards();
155
+ const buildCards = buildCardHierarchy(cards);
156
+
157
+ return {
158
+ name: template.data?.name || '',
159
+ cards: buildCards,
160
+ };
161
+ });
141
162
  }
142
163
 
143
164
  /**
@@ -146,7 +167,7 @@ export class Show {
146
167
  */
147
168
  public async showAttachments(): Promise<CardAttachment[]> {
148
169
  const attachments = this.project.attachments();
149
- const templateAttachments = await this.project.attachmentsFromTemplates();
170
+ const templateAttachments = await this.attachmentsFromTemplates();
150
171
  attachments.push(...templateAttachments);
151
172
  return attachments;
152
173
  }
@@ -284,17 +305,13 @@ export class Show {
284
305
  * @returns array of card type details
285
306
  */
286
307
  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);
308
+ const container = [];
309
+ for (const cardType of this.project.resources.cardTypes()) {
310
+ if (cardType.data) {
311
+ container.push(cardType.data);
294
312
  }
295
313
  }
296
- const results = await Promise.all(promiseContainer);
297
- return results.filter((item) => item);
314
+ return container;
298
315
  }
299
316
 
300
317
  /**
@@ -312,15 +329,18 @@ export class Show {
312
329
  showDetails?: boolean,
313
330
  ): Promise<ModuleSettingFromHub[]> {
314
331
  try {
332
+ // Ensure module list is up to date before showing
333
+ await this.fetchCmd.ensureModuleListUpToDate();
334
+
315
335
  const moduleList = (
316
336
  await readJsonFile(
317
337
  resolve(this.project.basePath, MODULE_LIST_FULL_PATH),
318
338
  )
319
339
  ).modules;
320
- const currentModules = await this.project.modules();
340
+ const currentModules = this.project.resources.moduleNames();
321
341
  const nonImportedModules = moduleList.filter(
322
342
  (item: ModuleSettingFromHub) => {
323
- return !currentModules.some((module) => item.name === module.name);
343
+ return !currentModules.some((module) => item.name === module);
324
344
  },
325
345
  );
326
346
 
@@ -349,7 +369,10 @@ export class Show {
349
369
  * @returns labels in a list
350
370
  */
351
371
  public showLabels(): string[] {
352
- const cards = this.project.showProjectCards();
372
+ const cards = flattenCardArray(
373
+ this.project.showProjectCards(),
374
+ this.project,
375
+ );
353
376
  const templateCards = this.project.allTemplateCards();
354
377
 
355
378
  const labels = this.collectLabels([...cards, ...templateCards]);
@@ -382,7 +405,9 @@ export class Show {
382
405
  * Shows hubs of the project.
383
406
  * @returns list of hubs.
384
407
  */
385
- public showHubs(): HubSetting[] {
408
+ public async showHubs(): Promise<HubSetting[]> {
409
+ // Ensure module list is up to date before showing
410
+ await this.fetchCmd.ensureModuleListUpToDate();
386
411
  return this.project.configuration.hubs;
387
412
  }
388
413
 
@@ -398,8 +423,8 @@ export class Show {
398
423
  * Shows all modules (if any) in a project.
399
424
  * @returns all modules in a project.
400
425
  */
401
- public async showModules(): Promise<string[]> {
402
- return (await this.project.modules()).map((item) => item.name).sort();
426
+ public showModules(): string[] {
427
+ return this.project.resources.moduleNames().sort();
403
428
  }
404
429
 
405
430
  /**
@@ -415,6 +440,7 @@ export class Show {
415
440
  * @param reportName Name of the report to show
416
441
  * @param cardKey Card key to use for the report
417
442
  * @param parameters Additional parameters for the report
443
+ * @param context Context for resource (includes a project instance)
418
444
  * @param outputPath Optional output path for the report
419
445
  * @returns Report results as a string
420
446
  * @throws Error if the report does not exist
@@ -427,9 +453,9 @@ export class Show {
427
453
  outputPath?: string,
428
454
  ): Promise<string> {
429
455
  if (
430
- !(await this.project.reports()).some(
431
- (report) => report.name === reportName,
432
- )
456
+ !this.project.resources
457
+ .reports()
458
+ .some((report) => report.data?.name === reportName)
433
459
  ) {
434
460
  throw new Error(`Report '${reportName}' does not exist`);
435
461
  }
@@ -471,17 +497,35 @@ export class Show {
471
497
  /**
472
498
  * Shows details of certain resource.
473
499
  * @param name Name of resource.
500
+ * @param showUse If true, shows also where resource is used.
501
+ * @param resourceType If specified, checks that the resource is given type.
474
502
  * @returns resource metadata as JSON.
475
503
  */
476
504
  public async showResource(
477
505
  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
- );
506
+ showUse?: boolean,
507
+ ): Promise<AnyResourceContent>;
508
+ public async showResource<T extends ResourceType>(
509
+ name: string,
510
+ resourceType: T,
511
+ showUse?: boolean,
512
+ ): Promise<ResourceContent<T>>;
513
+ public async showResource(
514
+ name: string,
515
+ arg2?: boolean | ResourceType,
516
+ arg3?: boolean,
517
+ ): Promise<AnyResourceContent> {
518
+ const hasResourceType = typeof arg2 === 'string';
519
+ const resourceType = hasResourceType ? arg2 : null;
520
+ const showUse = hasResourceType ? arg3 : arg2;
521
+
522
+ const type = this.project.resources.extractType(name);
523
+ if (resourceType !== null && resourceType !== type) {
524
+ throw new Error(
525
+ `While fetching '${name}': Expected type '${resourceType}', but got '${type}' instead`,
526
+ );
527
+ }
528
+ const resource = this.project.resources.byType(name, type);
485
529
  const [details, usage] = await Promise.all([
486
530
  resource?.show(),
487
531
  showUse ? resource?.usage() : [],
@@ -502,9 +546,9 @@ export class Show {
502
546
  * @returns sorted array of resources
503
547
  */
504
548
  public async showResources(type: string): Promise<string[]> {
505
- const func = this.resourceFunction.get(type);
549
+ const func = this.resourceFunctions[type];
506
550
  if (!func) return [];
507
- return (await func()).map((item) => item.name).sort();
551
+ return func().sort();
508
552
  }
509
553
 
510
554
  /**
@@ -512,23 +556,22 @@ export class Show {
512
556
  * @returns all templates in a project.
513
557
  */
514
558
  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[];
559
+ const templates = [];
560
+ for (const template of this.project.resources.templates()) {
561
+ templates.push(template.show());
562
+ }
563
+ return templates;
520
564
  }
521
565
 
522
566
  /**
523
567
  * Shows all workflows with full details in a project.
524
568
  * @returns workflows with full details
525
569
  */
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));
570
+ public showWorkflowsWithDetails(): (Workflow | undefined)[] {
571
+ const workflows = [];
572
+ for (const workflow of this.project.resources.workflows()) {
573
+ workflows.push(workflow.data);
530
574
  }
531
- const results = await Promise.all(promiseContainer);
532
- return results.filter((item) => item);
575
+ return workflows;
533
576
  }
534
577
  }
@@ -12,17 +12,29 @@
12
12
  */
13
13
 
14
14
  import { ActionGuard } from '../permissions/action-guard.js';
15
- import type {
16
- CardType,
17
- Workflow,
18
- WorkflowState,
19
- } from '../interfaces/resource-interfaces.js';
20
15
  import { CardMetadataUpdater } from '../card-metadata-updater.js';
21
16
  import type { Project } from '../containers/project.js';
17
+ import type { WorkflowState } from '../interfaces/resource-interfaces.js';
22
18
 
19
+ /**
20
+ * Handles transitions.
21
+ */
23
22
  export class Transition {
23
+ /**
24
+ * Creates an instance of Transition command.
25
+ * @param project Project to use.
26
+ */
24
27
  constructor(private project: Project) {}
25
28
 
29
+ // Wrapper to run onTransition query.
30
+ private async transitionChangesQuery(cardKey: string, transition: string) {
31
+ if (!cardKey || !transition) return undefined;
32
+ return this.project.calculationEngine.runQuery('onTransition', 'localApp', {
33
+ cardKey,
34
+ transition,
35
+ });
36
+ }
37
+
26
38
  /**
27
39
  * Transitions a card from its current state to a new state.
28
40
  * @param cardKey card key
@@ -31,23 +43,18 @@ export class Transition {
31
43
  public async cardTransition(cardKey: string, transition: WorkflowState) {
32
44
  const card = this.project.findCard(cardKey);
33
45
 
34
- // Card type
35
- const cardType = this.project.resource<CardType>(
36
- card.metadata?.cardType || '',
37
- );
38
- if (cardType === undefined) {
39
- throw new Error(
40
- `Card's card type '${card.metadata?.cardType}' does not exist in the project`,
41
- );
46
+ if (!card.metadata?.cardType) {
47
+ throw new Error(`Card does not have card type`);
42
48
  }
49
+ // Card type
50
+ const cardType = this.project.resources
51
+ .byType(card.metadata?.cardType, 'cardTypes')
52
+ .show();
43
53
 
44
54
  // Workflow
45
- const workflow = await this.project.resource<Workflow>(cardType.workflow);
46
- if (workflow === undefined) {
47
- throw new Error(
48
- `Card's workflow '${cardType.workflow}' does not exist in the project`,
49
- );
50
- }
55
+ const workflow = this.project.resources
56
+ .byType(cardType.workflow, 'workflows')
57
+ .show();
51
58
 
52
59
  // Check that the state transition can be made "from".
53
60
  const foundFrom = workflow.transitions.find(
@@ -108,13 +115,4 @@ export class Transition {
108
115
  .catch((error) => console.error(error));
109
116
  }
110
117
  }
111
-
112
- // Wrapper to run onTransition query.
113
- private async transitionChangesQuery(cardKey: string, transition: string) {
114
- if (!cardKey || !transition) return undefined;
115
- return this.project.calculationEngine.runQuery('onTransition', 'localApp', {
116
- cardKey,
117
- transition,
118
- });
119
- }
120
118
  }
@@ -19,16 +19,39 @@ import type {
19
19
  RemoveOperation,
20
20
  UpdateOperations,
21
21
  } from '../resources/resource-object.js';
22
- import { Project } from '../containers/project.js';
23
- import { resourceName } from '../utils/resource-utils.js';
22
+ import type { Project } from '../containers/project.js';
24
23
  import type { UpdateKey } from '../interfaces/resource-interfaces.js';
25
24
 
26
25
  /**
27
26
  * Class that handles 'update' commands.
28
27
  */
29
28
  export class Update {
29
+ /**
30
+ * Creates an instance of Update command.
31
+ * @param project Project to use.
32
+ */
30
33
  constructor(private project: Project) {}
31
34
 
35
+ /**
36
+ * Update single resource property
37
+ * This is similar to updateValue, but allows the operation to be fully specified
38
+ * @param name Name of the resource to operate on.
39
+ * @param updateKey Property to change in resource or in resource content.
40
+ * @param operation The full operation object
41
+ * @template Type Type of the target of the operation
42
+ * @template T Type of operation ('add', 'remove', 'change', 'rank')
43
+ * @template K Type of the key to change
44
+ */
45
+ public async applyResourceOperation<
46
+ Type,
47
+ T extends UpdateOperations,
48
+ K extends string,
49
+ >(name: string, updateKey: UpdateKey<K>, operation: OperationFor<Type, T>) {
50
+ const type = this.project.resources.extractType(name);
51
+ const resource = this.project.resources.byType(name, type);
52
+ await resource?.update(updateKey, operation);
53
+ }
54
+
32
55
  /**
33
56
  * Updates single resource property.
34
57
  * @param name Name of the resource to operate on.
@@ -95,24 +118,4 @@ export class Update {
95
118
  await this.applyResourceOperation(name, { key: parsedKey }, op);
96
119
  }
97
120
  }
98
-
99
- /**
100
- * Update single resource property
101
- * This is similar to updateValue, but allows the operation to be fully specified
102
- * @param name Name of the resource to operate on.
103
- * @param updateKey Property to change in resource or in resource content.
104
- * @param operation The full operation object
105
- * @template Type Type of the target of the operation
106
- * @template T Type of operation ('add', 'remove', 'change', 'rank')
107
- * @template K Type of the key to change
108
- */
109
- public async applyResourceOperation<
110
- Type,
111
- T extends UpdateOperations,
112
- K extends string,
113
- >(name: string, updateKey: UpdateKey<K>, operation: OperationFor<Type, T>) {
114
- const resource = Project.resourceObject(this.project, resourceName(name));
115
- await resource?.update(updateKey, operation);
116
- this.project.collectLocalResources();
117
- }
118
121
  }