@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
@@ -11,23 +11,33 @@
11
11
  License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
12
  */
13
13
 
14
- import type { CardType } from '../interfaces/resource-interfaces.js';
15
- import { type Create, Validate } from './index.js';
16
14
  import { ModuleManager } from '../module-manager.js';
15
+ import { readCsvFile } from '../utils/csv.js';
16
+ import { Validate } from './validate.js';
17
+
18
+ import type { Create } from './create.js';
17
19
  import type {
18
20
  Credentials,
19
21
  ModuleSettingOptions,
20
22
  } from '../interfaces/project-interfaces.js';
23
+ import type { Fetch } from './fetch.js';
21
24
  import type { Project } from '../containers/project.js';
22
- import { readCsvFile } from '../utils/csv.js';
23
- import { resourceName } from '../utils/resource-utils.js';
24
- import { TemplateResource } from '../resources/template-resource.js';
25
25
 
26
+ /**
27
+ * Handles all import commands.
28
+ */
26
29
  export class Import {
27
30
  private moduleManager: ModuleManager;
31
+
32
+ /**
33
+ * Creates an instance of Import.
34
+ * @param project Project to use.
35
+ * @param createCmd Instance of Create to use.
36
+ */
28
37
  constructor(
29
38
  private project: Project,
30
39
  private createCmd: Create,
40
+ private fetchCmd: Fetch,
31
41
  ) {
32
42
  this.moduleManager = new ModuleManager(this.project);
33
43
  }
@@ -53,9 +63,9 @@ export class Import {
53
63
 
54
64
  for (const row of csv) {
55
65
  const { title, template, description, labels, ...customFields } = row;
56
- const templateResource = new TemplateResource(
57
- this.project,
58
- resourceName(template),
66
+ const templateResource = this.project.resources.byType(
67
+ template,
68
+ 'templates',
59
69
  );
60
70
  const templateObject = templateResource.templateObject();
61
71
  if (!templateObject) {
@@ -78,13 +88,12 @@ export class Import {
78
88
  }
79
89
  const cardKey = cards[0].key;
80
90
  const card = this.project.findCard(cardKey);
81
- const cardType = this.project.resource<CardType>(
82
- card.metadata?.cardType || '',
83
- );
84
-
85
- if (!cardType) {
91
+ if (!card.metadata?.cardType) {
86
92
  throw new Error(`Card type not found for card ${cardKey}`);
87
93
  }
94
+ const cardType = this.project.resources
95
+ .byType(card.metadata?.cardType, 'cardTypes')
96
+ .show();
88
97
 
89
98
  if (description) {
90
99
  await this.project.updateCardContent(cardKey, description);
@@ -126,12 +135,17 @@ export class Import {
126
135
  * @param options Additional options for module import. Optional.
127
136
  * branch: Git branch for module from Git.
128
137
  * private: If true, uses credentials to clone the repository
138
+ * @param skipMigrationLog If true, skip logging to migration log (used during project creation)
129
139
  */
130
140
  public async importModule(
131
141
  source: string,
132
142
  destination?: string,
133
143
  options?: ModuleSettingOptions,
144
+ skipMigrationLog = false,
134
145
  ) {
146
+ // Ensure module list is up to date before importing
147
+ await this.fetchCmd.ensureModuleListUpToDate();
148
+
135
149
  const beforeImportValidateErrors = await Validate.getInstance().validate(
136
150
  this.project.basePath,
137
151
  () => this.project,
@@ -155,10 +169,13 @@ export class Import {
155
169
  };
156
170
 
157
171
  // Fetch module dependencies.
158
- await this.moduleManager.updateModule(moduleSettings, options?.credentials);
172
+ await this.moduleManager.updateDependencies(
173
+ moduleSettings,
174
+ options?.credentials,
175
+ );
159
176
 
160
177
  // Add module as a dependency.
161
- await this.project.importModule(moduleSettings);
178
+ await this.project.importModule(moduleSettings, skipMigrationLog);
162
179
 
163
180
  // Validate the project after module has been imported
164
181
  const afterImportValidateErrors = await Validate.getInstance().validate(
@@ -179,6 +196,9 @@ export class Import {
179
196
  * @throws if module is not part of the project
180
197
  */
181
198
  public async updateModule(moduleName: string, credentials?: Credentials) {
199
+ // Ensure module list is up to date before updating
200
+ await this.fetchCmd.ensureModuleListUpToDate();
201
+
182
202
  const module = this.project.configuration.modules.find(
183
203
  (item) => item.name === moduleName,
184
204
  );
@@ -193,6 +213,8 @@ export class Import {
193
213
  * @param credentials Optional credentials for private modules.
194
214
  */
195
215
  public async updateAllModules(credentials?: Credentials) {
216
+ // Ensure module list is up to date before updating all modules
217
+ await this.fetchCmd.ensureModuleListUpToDate();
196
218
  return this.moduleManager.updateModules(credentials);
197
219
  }
198
220
  }
@@ -197,7 +197,6 @@ export class Move {
197
197
  sourceCard.parent = movingToRoot ? ROOT : destination;
198
198
  if (sourceCard.metadata) {
199
199
  sourceCard.metadata.rank = rank;
200
- sourceCard.metadata.parent = movingToRoot ? ROOT : destination;
201
200
  }
202
201
 
203
202
  // Handle cache update and persistence
@@ -14,16 +14,23 @@
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 { Fetch } from './fetch.js';
18
+ import type { Project } from '../containers/project.js';
18
19
  import type { RemovableResourceTypes } from '../interfaces/project-interfaces.js';
19
- import { resourceName } from '../utils/resource-utils.js';
20
20
 
21
21
  /**
22
22
  * Remove command.
23
23
  */
24
24
  export class Remove {
25
25
  private moduleManager: ModuleManager;
26
- constructor(private project: Project) {
26
+ /**
27
+ * Creates a new instance of Remove command.
28
+ * @param project Project instance to use
29
+ */
30
+ constructor(
31
+ private project: Project,
32
+ private fetchCmd: Fetch,
33
+ ) {
27
34
  this.moduleManager = new ModuleManager(this.project);
28
35
  }
29
36
 
@@ -152,13 +159,19 @@ export class Remove {
152
159
  * @param rest Additional arguments
153
160
  * @note removing attachment requires card id and attachment filename
154
161
  * @note removing link requires card ids of source card, and optionally link type and link description
162
+ * @throws when removing an attachment, but attachment parameter is missing, or
163
+ * when removing link, some of the mandatory parameters are missing, or
164
+ * when trying to remove unknown type
155
165
  */
156
166
  public async remove(
157
167
  type: RemovableResourceTypes,
158
168
  targetName: string,
159
169
  ...rest: any[] // eslint-disable-line @typescript-eslint/no-explicit-any
160
170
  ) {
161
- const strictNameCheck = true;
171
+ // Ensure module list is up to date when removing modules
172
+ if (type === 'module') {
173
+ await this.fetchCmd.ensureModuleListUpToDate();
174
+ }
162
175
 
163
176
  if (type === 'attachment' && rest.length !== 1 && !rest[0]) {
164
177
  throw new Error(
@@ -177,9 +190,9 @@ export class Remove {
177
190
  );
178
191
  }
179
192
  if (this.projectResource(type)) {
180
- const resource = Project.resourceObject(
181
- this.project,
182
- resourceName(targetName, strictNameCheck),
193
+ const resource = this.project.resources.byType(
194
+ targetName,
195
+ this.project.resources.resourceTypeFromSingularType(type),
183
196
  );
184
197
  return resource?.delete();
185
198
  } else {
@@ -17,20 +17,13 @@ import { join } from 'node:path';
17
17
  import { rename, readdir, readFile, writeFile } from 'node:fs/promises';
18
18
 
19
19
  import type { Card } from '../interfaces/project-interfaces.js';
20
+ import {
21
+ ConfigurationLogger,
22
+ ConfigurationOperation,
23
+ } from '../utils/configuration-logger.js';
20
24
  import { isTemplateCard } from '../utils/card-utils.js';
21
25
  import { type Project, ResourcesFrom } from '../containers/project.js';
22
26
  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
27
 
35
28
  const FILE_TYPES_WITH_PREFIX_REFERENCES = ['adoc', 'hbs', 'json', 'lp'];
36
29
 
@@ -41,6 +34,10 @@ export class Rename {
41
34
  private from: string = '';
42
35
  private to: string = '';
43
36
 
37
+ /**
38
+ * Creates an instance of Rename command.
39
+ * @param project Project instance to use.
40
+ */
44
41
  constructor(private project: Project) {}
45
42
 
46
43
  // Renames a card and all of its attachments (if it is a project card).
@@ -183,93 +180,6 @@ export class Rename {
183
180
  : name;
184
181
  }
185
182
 
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
183
  /**
274
184
  * Renames project prefix.
275
185
  * @throws if trying to use empty 'to'
@@ -294,72 +204,60 @@ export class Rename {
294
204
  await this.project.configuration.setCardPrefix(to);
295
205
  console.info(`Rename: New prefix: '${this.project.projectPrefix}'`);
296
206
  // Update the resources collection, since project prefix has changed.
297
- this.project.collectLocalResources();
207
+ this.project.resources.changed();
298
208
 
299
209
  // Rename local resources.
300
- // It is better to rename the resources in this order: card types, field types, then others
210
+ // It is better to rename the resources in this order: card types, workflows, field types, then the rest
301
211
 
302
212
  // 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);
213
+ for (const cardType of this.project.resources.cardTypes(
214
+ ResourcesFrom.localOnly,
215
+ )) {
216
+ const name = this.updateResourceName(cardType.data?.name || '');
217
+ await cardType.rename(resourceName(name));
306
218
  }
307
219
  console.info('Updated card types');
308
220
 
309
- const workflows = await this.project.workflows(ResourcesFrom.localOnly);
310
- for (const workflow of workflows) {
311
- await this.updateWorkflowMetadata(workflow.name);
221
+ for (const workflow of this.project.resources.workflows(
222
+ ResourcesFrom.localOnly,
223
+ )) {
224
+ const name = this.updateResourceName(workflow.data?.name || '');
225
+ await workflow.rename(resourceName(name));
312
226
  }
313
227
  console.info('Updated workflows');
314
228
 
315
- const fieldTypes = await this.project.fieldTypes(ResourcesFrom.localOnly);
316
- for (const fieldType of fieldTypes) {
317
- await this.updateFieldTypeMetadata(fieldType.name);
229
+ for (const fieldType of this.project.resources.fieldTypes(
230
+ ResourcesFrom.localOnly,
231
+ )) {
232
+ const name = this.updateResourceName(fieldType.data?.name || '');
233
+ await fieldType.rename(resourceName(name));
318
234
  }
319
235
  console.info('Updated field types');
320
236
 
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);
237
+ const restOfResourceTypes = [
238
+ 'graphModels',
239
+ 'graphViews',
240
+ 'linkTypes',
241
+ 'reports',
242
+ 'templates',
243
+ 'calculations',
244
+ ] as const;
245
+
246
+ for (const resourceType of restOfResourceTypes) {
247
+ for (const resource of this.project.resources.resourceTypes(
248
+ resourceType,
249
+ ResourcesFrom.localOnly,
250
+ )) {
251
+ const name = this.updateResourceName(resource.data?.name || '');
252
+ await resource.rename(resourceName(name));
253
+ }
348
254
  }
349
- console.info('Updated templates');
350
255
 
351
- const calculations = await this.project.calculations(
256
+ // Rename all local template cards. This must be done after calculations have been renamed.
257
+ for (const template of this.project.resources.templates(
352
258
  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);
259
+ )) {
260
+ const templateObject = template.templateObject();
363
261
  await this.renameCards(templateObject.cards());
364
262
  }
365
263
  console.info('Renamed template cards and updated the content');
@@ -376,9 +274,20 @@ export class Rename {
376
274
  console.info('Renamed all remaining references in .cards folder');
377
275
 
378
276
  // It is best that the resources are re-collected after all the renaming has occurred.
379
- this.project.collectLocalResources();
277
+ this.project.resources.changed();
380
278
  console.info('Collected renamed resources');
381
279
 
280
+ // Remove these when operations properly update card cache
281
+ this.project.cardsCache.clear();
282
+ await this.project.populateCaches();
283
+
284
+ await ConfigurationLogger.log(
285
+ this.project.basePath,
286
+ ConfigurationOperation.PROJECT_RENAME,
287
+ this.to,
288
+ {},
289
+ );
290
+
382
291
  return this.project.calculationEngine.generate();
383
292
  }
384
293
  }