@cyberismo/data-handler 0.0.14 → 0.0.15

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 (240) hide show
  1. package/dist/card-metadata-updater.js +1 -3
  2. package/dist/card-metadata-updater.js.map +1 -1
  3. package/dist/command-handler.js +10 -16
  4. package/dist/command-handler.js.map +1 -1
  5. package/dist/command-manager.d.ts +1 -1
  6. package/dist/command-manager.js +4 -3
  7. package/dist/command-manager.js.map +1 -1
  8. package/dist/commands/create.js +13 -59
  9. package/dist/commands/create.js.map +1 -1
  10. package/dist/commands/edit.d.ts +1 -15
  11. package/dist/commands/edit.js +15 -89
  12. package/dist/commands/edit.js.map +1 -1
  13. package/dist/commands/export.js +4 -17
  14. package/dist/commands/export.js.map +1 -1
  15. package/dist/commands/import.js +3 -5
  16. package/dist/commands/import.js.map +1 -1
  17. package/dist/commands/move.d.ts +1 -2
  18. package/dist/commands/move.js +108 -146
  19. package/dist/commands/move.js.map +1 -1
  20. package/dist/commands/remove.js +9 -44
  21. package/dist/commands/remove.js.map +1 -1
  22. package/dist/commands/rename.js +2 -7
  23. package/dist/commands/rename.js.map +1 -1
  24. package/dist/commands/show.d.ts +7 -25
  25. package/dist/commands/show.js +38 -102
  26. package/dist/commands/show.js.map +1 -1
  27. package/dist/commands/transition.js +27 -30
  28. package/dist/commands/transition.js.map +1 -1
  29. package/dist/commands/update.d.ts +5 -3
  30. package/dist/commands/update.js +19 -5
  31. package/dist/commands/update.js.map +1 -1
  32. package/dist/commands/validate.d.ts +3 -3
  33. package/dist/commands/validate.js +19 -26
  34. package/dist/commands/validate.js.map +1 -1
  35. package/dist/containers/card-container.d.ts +87 -24
  36. package/dist/containers/card-container.js +183 -279
  37. package/dist/containers/card-container.js.map +1 -1
  38. package/dist/containers/project/calculation-engine.d.ts +6 -0
  39. package/dist/containers/project/calculation-engine.js +19 -12
  40. package/dist/containers/project/calculation-engine.js.map +1 -1
  41. package/dist/containers/project/card-cache.d.ts +146 -0
  42. package/dist/containers/project/card-cache.js +411 -0
  43. package/dist/containers/project/card-cache.js.map +1 -0
  44. package/dist/containers/project/resource-collector.d.ts +24 -1
  45. package/dist/containers/project/resource-collector.js +8 -1
  46. package/dist/containers/project/resource-collector.js.map +1 -1
  47. package/dist/containers/project.d.ts +117 -83
  48. package/dist/containers/project.js +418 -252
  49. package/dist/containers/project.js.map +1 -1
  50. package/dist/containers/template.d.ts +15 -31
  51. package/dist/containers/template.js +97 -104
  52. package/dist/containers/template.js.map +1 -1
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.js +1 -0
  55. package/dist/index.js.map +1 -1
  56. package/dist/interfaces/folder-content-interfaces.d.ts +2 -1
  57. package/dist/interfaces/folder-content-interfaces.js.map +1 -1
  58. package/dist/interfaces/macros.d.ts +1 -0
  59. package/dist/interfaces/macros.js +1 -1
  60. package/dist/interfaces/macros.js.map +1 -1
  61. package/dist/interfaces/project-interfaces.d.ts +5 -1
  62. package/dist/interfaces/project-interfaces.js.map +1 -1
  63. package/dist/interfaces/resource-interfaces.d.ts +11 -21
  64. package/dist/interfaces/resource-interfaces.js +3 -0
  65. package/dist/interfaces/resource-interfaces.js.map +1 -1
  66. package/dist/macros/common.d.ts +10 -10
  67. package/dist/macros/createCards/index.d.ts +0 -13
  68. package/dist/macros/createCards/index.js.map +1 -1
  69. package/dist/macros/createCards/types.d.ts +44 -0
  70. package/dist/macros/createCards/types.js +15 -0
  71. package/dist/macros/createCards/types.js.map +1 -0
  72. package/dist/macros/graph/index.d.ts +2 -6
  73. package/dist/macros/graph/index.js +2 -2
  74. package/dist/macros/graph/index.js.map +1 -1
  75. package/dist/macros/graph/types.d.ts +23 -0
  76. package/dist/macros/graph/types.js +15 -0
  77. package/dist/macros/graph/types.js.map +1 -0
  78. package/dist/macros/image/index.d.ts +8 -16
  79. package/dist/macros/image/index.js +36 -33
  80. package/dist/macros/image/index.js.map +1 -1
  81. package/dist/macros/image/types.d.ts +38 -0
  82. package/dist/macros/image/types.js +15 -0
  83. package/dist/macros/image/types.js.map +1 -0
  84. package/dist/macros/include/index.d.ts +1 -6
  85. package/dist/macros/include/index.js +4 -7
  86. package/dist/macros/include/index.js.map +1 -1
  87. package/dist/macros/include/types.d.ts +31 -0
  88. package/dist/macros/include/types.js +15 -0
  89. package/dist/macros/include/types.js.map +1 -0
  90. package/dist/macros/percentage/index.d.ts +0 -6
  91. package/dist/macros/percentage/index.js.map +1 -1
  92. package/dist/macros/percentage/types.d.ts +31 -0
  93. package/dist/macros/percentage/types.js +15 -0
  94. package/dist/macros/percentage/types.js.map +1 -0
  95. package/dist/macros/report/index.d.ts +0 -3
  96. package/dist/macros/report/index.js.map +1 -1
  97. package/dist/macros/report/types.d.ts +19 -0
  98. package/dist/macros/report/types.js +15 -0
  99. package/dist/macros/report/types.js.map +1 -0
  100. package/dist/macros/scoreCard/index.d.ts +0 -6
  101. package/dist/macros/scoreCard/index.js.map +1 -1
  102. package/dist/macros/scoreCard/types.d.ts +31 -0
  103. package/dist/macros/scoreCard/types.js +15 -0
  104. package/dist/macros/scoreCard/types.js.map +1 -0
  105. package/dist/macros/types.d.ts +25 -0
  106. package/dist/macros/types.js +2 -0
  107. package/dist/macros/types.js.map +1 -0
  108. package/dist/macros/vega/index.d.ts +0 -4
  109. package/dist/macros/vega/index.js.map +1 -1
  110. package/dist/macros/vega/types.d.ts +20 -0
  111. package/dist/macros/vega/types.js +2 -0
  112. package/dist/macros/vega/types.js.map +1 -0
  113. package/dist/macros/vegalite/index.d.ts +0 -4
  114. package/dist/macros/vegalite/index.js.map +1 -1
  115. package/dist/macros/vegalite/types.d.ts +20 -0
  116. package/dist/macros/vegalite/types.js +15 -0
  117. package/dist/macros/vegalite/types.js.map +1 -0
  118. package/dist/macros/xref/index.d.ts +0 -3
  119. package/dist/macros/xref/index.js +5 -14
  120. package/dist/macros/xref/index.js.map +1 -1
  121. package/dist/macros/xref/types.d.ts +19 -0
  122. package/dist/macros/xref/types.js +15 -0
  123. package/dist/macros/xref/types.js.map +1 -0
  124. package/dist/module-manager.js +4 -4
  125. package/dist/module-manager.js.map +1 -1
  126. package/dist/project-settings.js.map +1 -1
  127. package/dist/resources/calculation-resource.d.ts +4 -32
  128. package/dist/resources/calculation-resource.js +0 -55
  129. package/dist/resources/calculation-resource.js.map +1 -1
  130. package/dist/resources/card-type-resource.d.ts +4 -21
  131. package/dist/resources/card-type-resource.js +13 -44
  132. package/dist/resources/card-type-resource.js.map +1 -1
  133. package/dist/resources/field-type-resource.d.ts +4 -21
  134. package/dist/resources/field-type-resource.js +14 -38
  135. package/dist/resources/field-type-resource.js.map +1 -1
  136. package/dist/resources/file-resource.d.ts +12 -29
  137. package/dist/resources/file-resource.js +19 -293
  138. package/dist/resources/file-resource.js.map +1 -1
  139. package/dist/resources/folder-resource.d.ts +31 -50
  140. package/dist/resources/folder-resource.js +68 -96
  141. package/dist/resources/folder-resource.js.map +1 -1
  142. package/dist/resources/graph-model-resource.d.ts +5 -33
  143. package/dist/resources/graph-model-resource.js +8 -61
  144. package/dist/resources/graph-model-resource.js.map +1 -1
  145. package/dist/resources/graph-view-resource.d.ts +5 -28
  146. package/dist/resources/graph-view-resource.js +6 -45
  147. package/dist/resources/graph-view-resource.js.map +1 -1
  148. package/dist/resources/link-type-resource.d.ts +4 -21
  149. package/dist/resources/link-type-resource.js +6 -31
  150. package/dist/resources/link-type-resource.js.map +1 -1
  151. package/dist/resources/report-resource.d.ts +5 -17
  152. package/dist/resources/report-resource.js +6 -44
  153. package/dist/resources/report-resource.js.map +1 -1
  154. package/dist/resources/resource-object.d.ts +58 -23
  155. package/dist/resources/resource-object.js +293 -24
  156. package/dist/resources/resource-object.js.map +1 -1
  157. package/dist/resources/template-resource.d.ts +4 -15
  158. package/dist/resources/template-resource.js +10 -25
  159. package/dist/resources/template-resource.js.map +1 -1
  160. package/dist/resources/workflow-resource.d.ts +4 -23
  161. package/dist/resources/workflow-resource.js +12 -38
  162. package/dist/resources/workflow-resource.js.map +1 -1
  163. package/dist/utils/card-utils.d.ts +69 -19
  164. package/dist/utils/card-utils.js +179 -30
  165. package/dist/utils/card-utils.js.map +1 -1
  166. package/dist/utils/clingo-facts.js +11 -3
  167. package/dist/utils/clingo-facts.js.map +1 -1
  168. package/dist/utils/clingo-parser.js +1 -1
  169. package/dist/utils/clingo-parser.js.map +1 -1
  170. package/dist/utils/constants.d.ts +2 -0
  171. package/dist/utils/constants.js +4 -0
  172. package/dist/utils/constants.js.map +1 -1
  173. package/dist/utils/csv.js +1 -1
  174. package/dist/utils/csv.js.map +1 -1
  175. package/package.json +5 -5
  176. package/src/card-metadata-updater.ts +3 -5
  177. package/src/command-handler.ts +11 -18
  178. package/src/command-manager.ts +4 -3
  179. package/src/commands/create.ts +17 -83
  180. package/src/commands/edit.ts +16 -132
  181. package/src/commands/export.ts +8 -29
  182. package/src/commands/import.ts +4 -6
  183. package/src/commands/move.ts +144 -179
  184. package/src/commands/remove.ts +9 -52
  185. package/src/commands/rename.ts +2 -7
  186. package/src/commands/show.ts +50 -143
  187. package/src/commands/transition.ts +30 -33
  188. package/src/commands/update.ts +27 -9
  189. package/src/commands/validate.ts +21 -36
  190. package/src/containers/card-container.ts +200 -360
  191. package/src/containers/project/calculation-engine.ts +21 -13
  192. package/src/containers/project/card-cache.ts +497 -0
  193. package/src/containers/project/resource-collector.ts +9 -1
  194. package/src/containers/project.ts +529 -327
  195. package/src/containers/template.ts +109 -127
  196. package/src/index.ts +1 -0
  197. package/src/interfaces/folder-content-interfaces.ts +7 -1
  198. package/src/interfaces/macros.ts +2 -0
  199. package/src/interfaces/project-interfaces.ts +7 -1
  200. package/src/interfaces/resource-interfaces.ts +12 -24
  201. package/src/macros/createCards/index.ts +1 -12
  202. package/src/macros/createCards/types.ts +46 -0
  203. package/src/macros/graph/index.ts +3 -7
  204. package/src/macros/graph/types.ts +24 -0
  205. package/src/macros/image/index.ts +50 -61
  206. package/src/macros/image/types.ts +39 -0
  207. package/src/macros/include/index.ts +6 -15
  208. package/src/macros/include/types.ts +32 -0
  209. package/src/macros/percentage/index.ts +1 -7
  210. package/src/macros/percentage/types.ts +32 -0
  211. package/src/macros/report/index.ts +1 -4
  212. package/src/macros/report/types.ts +20 -0
  213. package/src/macros/scoreCard/index.ts +1 -7
  214. package/src/macros/scoreCard/types.ts +32 -0
  215. package/src/macros/types.ts +48 -0
  216. package/src/macros/vega/index.ts +1 -4
  217. package/src/macros/vega/types.ts +21 -0
  218. package/src/macros/vegalite/index.ts +1 -4
  219. package/src/macros/vegalite/types.ts +22 -0
  220. package/src/macros/xref/index.ts +6 -20
  221. package/src/macros/xref/types.ts +20 -0
  222. package/src/module-manager.ts +5 -5
  223. package/src/project-settings.ts +1 -1
  224. package/src/resources/calculation-resource.ts +6 -76
  225. package/src/resources/card-type-resource.ts +24 -59
  226. package/src/resources/field-type-resource.ts +22 -51
  227. package/src/resources/file-resource.ts +27 -409
  228. package/src/resources/folder-resource.ts +98 -124
  229. package/src/resources/graph-model-resource.ts +17 -74
  230. package/src/resources/graph-view-resource.ts +14 -54
  231. package/src/resources/link-type-resource.ts +13 -40
  232. package/src/resources/report-resource.ts +17 -57
  233. package/src/resources/resource-object.ts +435 -32
  234. package/src/resources/template-resource.ts +16 -29
  235. package/src/resources/workflow-resource.ts +26 -50
  236. package/src/utils/card-utils.ts +217 -31
  237. package/src/utils/clingo-facts.ts +13 -3
  238. package/src/utils/clingo-parser.ts +1 -1
  239. package/src/utils/constants.ts +6 -0
  240. package/src/utils/csv.ts +1 -1
@@ -61,7 +61,7 @@ export class ProjectConfiguration implements ProjectSettings {
61
61
 
62
62
  // Sets configuration values from file.
63
63
  private readSettings() {
64
- const settings = readJsonFileSync(this.settingPath) as ProjectConfiguration;
64
+ const settings = readJsonFileSync(this.settingPath);
65
65
  if (!settings) {
66
66
  throw new Error(`File at '${this.settingPath}' is not a valid JSON file`);
67
67
  }
@@ -22,31 +22,23 @@ import {
22
22
  } from './folder-resource.js';
23
23
  import { writeFileSafe } from '../utils/file-utils.js';
24
24
 
25
- import type {
26
- Calculation,
27
- CalculationMetadata,
28
- CalculationUpdateKey,
29
- } from '../interfaces/resource-interfaces.js';
25
+ import { type CalculationMetadata } from '../interfaces/resource-interfaces.js';
30
26
  import type { CalculationContent } from '../interfaces/folder-content-interfaces.js';
31
- import type {
32
- Card,
33
- Operation,
34
- Project,
35
- ResourceName,
36
- } from './file-resource.js';
27
+ import type { Card, Project, ResourceName } from './file-resource.js';
37
28
 
38
29
  /**
39
30
  * Calculation resource class.
40
31
  */
41
- export class CalculationResource extends FolderResource {
32
+ export class CalculationResource extends FolderResource<
33
+ CalculationMetadata,
34
+ CalculationContent
35
+ > {
42
36
  private calculationsFile = 'calculation.lp';
43
37
  constructor(project: Project, name: ResourceName) {
44
38
  super(project, name, 'calculations');
45
39
 
46
40
  this.contentSchemaId = 'calculationSchema';
47
41
  this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
48
-
49
- this.initialize();
50
42
  }
51
43
 
52
44
  // When resource name changes
@@ -78,21 +70,6 @@ export class CalculationResource extends FolderResource {
78
70
  },
79
71
  );
80
72
  }
81
-
82
- /**
83
- * Returns content data.
84
- */
85
- public get data(): CalculationMetadata {
86
- return super.data as CalculationMetadata;
87
- }
88
-
89
- /**
90
- * Deletes files from disk and clears out the memory resident object.
91
- */
92
- public async delete() {
93
- await super.delete();
94
- }
95
-
96
73
  /**
97
74
  * Renames resource metadata file and renames memory resident object 'name'.
98
75
  * @param newName New name for the resource.
@@ -103,45 +80,6 @@ export class CalculationResource extends FolderResource {
103
80
  return this.onNameChange(existingName);
104
81
  }
105
82
 
106
- /**
107
- * Shows metadata of the resource.
108
- * @returns calculation metadata.
109
- */
110
- public async show(): Promise<Calculation> {
111
- const baseData = (await super.show()) as CalculationMetadata;
112
- const fileContents = await super.contentData();
113
- const content: CalculationContent = {
114
- calculation: fileContents.calculation as string,
115
- };
116
- return {
117
- ...baseData,
118
- content: content,
119
- };
120
- }
121
-
122
- /**
123
- * Updates calculation resource.
124
- * @template Type The type of the operation being operated on for the given key.
125
- * @param key Key to modify
126
- * @param op Operation to perform on 'key'
127
- * @example
128
- * // Update the description
129
- * await calculation.update('description', { name: 'change', to: 'New description' });
130
- * await calculation.update({ key: 'content', subKey: 'calculation' }, { name: 'change', to: 'new content' });
131
- */
132
- public async update<Type>(key: CalculationUpdateKey, op: Operation<Type>) {
133
- if (
134
- typeof key === 'object' &&
135
- key.key === 'content' &&
136
- key.subKey === 'calculation'
137
- ) {
138
- const calculationContent = super.handleScalar(op) as string;
139
- await this.updateFile(this.calculationsFile, calculationContent);
140
- return;
141
- }
142
- await super.update(key, op);
143
- }
144
-
145
83
  /**
146
84
  * List where calculation resource is used in cards, or other calculation resources.
147
85
  * Always returns card key references first, then calculation references.
@@ -160,12 +98,4 @@ export class CalculationResource extends FolderResource {
160
98
  const cardReferences = cardContentReferences.sort(sortCards);
161
99
  return [...new Set([...cardReferences, ...calculations])];
162
100
  }
163
-
164
- /**
165
- * Validates the resource. If object is invalid, throws.
166
- * @param content Content to validate
167
- */
168
- public async validate(content?: object) {
169
- return super.validate(content);
170
- }
171
101
  }
@@ -16,6 +16,7 @@ import type {
16
16
  CardType,
17
17
  CustomField,
18
18
  LinkType,
19
+ UpdateKey,
19
20
  Workflow,
20
21
  } from '../interfaces/resource-interfaces.js';
21
22
  import { FieldTypeResource } from './field-type-resource.js';
@@ -40,19 +41,18 @@ import { Validate } from '../commands/index.js';
40
41
  /**
41
42
  * Card type resource class.
42
43
  */
43
- export class CardTypeResource extends FileResource {
44
+ export class CardTypeResource extends FileResource<CardType> {
44
45
  constructor(project: Project, name: ResourceName) {
45
46
  super(project, name, 'cardTypes');
46
47
 
47
48
  this.contentSchemaId = 'cardTypeSchema';
48
49
  this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
49
50
 
50
- this.initialize();
51
51
  this.setContainerValues();
52
52
  }
53
53
 
54
54
  // Returns cards that have this card type.
55
- private async cardsWithCardType(cards: Card[]): Promise<string[]> {
55
+ private cardsWithCardType(cards: Card[]): string[] {
56
56
  const resourceName = resourceNameToString(this.resourceName);
57
57
  return cards
58
58
  .filter((card) => card.metadata?.cardType === resourceName)
@@ -72,13 +72,7 @@ export class CardTypeResource extends FileResource {
72
72
  if (op && op.name === 'rank') return;
73
73
 
74
74
  // Collect both project cards and template cards.
75
- const cards = await this.collectCards(
76
- {
77
- metadata: true,
78
- content: true,
79
- },
80
- this.content.name,
81
- );
75
+ const cards = await this.collectCards(this.content.name);
82
76
 
83
77
  if (op && op.name === 'change') {
84
78
  const from = (op as ChangeOperation<string>).target;
@@ -113,7 +107,7 @@ export class CardTypeResource extends FileResource {
113
107
 
114
108
  // When resource name changes.
115
109
  private async handleNameChange(existingName: string) {
116
- const current = this.content as CardType;
110
+ const current = this.content;
117
111
  const prefixes = await this.project.projectPrefixes();
118
112
  if (current.customFields) {
119
113
  current.customFields.map(
@@ -160,20 +154,14 @@ export class CardTypeResource extends FileResource {
160
154
  op: ChangeOperation<Type>,
161
155
  ) {
162
156
  await this.verifyStateMapping(stateMapping, op);
163
- const cards = await this.collectCards(
164
- {
165
- metadata: true,
166
- content: true,
167
- },
168
- this.content.name,
169
- );
157
+ const cards = await this.collectCards(this.content.name);
170
158
 
171
159
  const unmappedStates: string[] = [];
172
160
 
173
161
  // Update each card's workflowState if it has a mapping
174
162
  const updatePromises = cards.map(async (card) => {
175
163
  if (card.metadata && card.metadata.workflowState) {
176
- const currentState = card.metadata.workflowState as string;
164
+ const currentState = card.metadata.workflowState;
177
165
  const newState = stateMapping[currentState];
178
166
 
179
167
  if (newState && newState !== currentState) {
@@ -198,8 +186,10 @@ export class CardTypeResource extends FileResource {
198
186
  }
199
187
 
200
188
  // Checks if field type exists in this card type.
201
- private async hasFieldType(field: Partial<CustomField>): Promise<boolean> {
202
- return this.data.customFields.some((item) => item.name === field.name);
189
+ private hasFieldType(field: Partial<CustomField>): boolean {
190
+ return (
191
+ this.data?.customFields.some((item) => item.name === field.name) || false
192
+ );
203
193
  }
204
194
 
205
195
  // Remove value from array.
@@ -251,7 +241,7 @@ export class CardTypeResource extends FileResource {
251
241
 
252
242
  // Sets content container values to be either '[]' or with proper values.
253
243
  private setContainerValues() {
254
- const content = this.content as CardType;
244
+ const content = this.content;
255
245
  if (content.customFields) {
256
246
  for (const item of content.customFields) {
257
247
  // Set "isCalculated" if it is missing; default = false
@@ -311,7 +301,7 @@ export class CardTypeResource extends FileResource {
311
301
  target: oldName,
312
302
  to: this.content.name,
313
303
  } as ChangeOperation<string>;
314
- updates.push(object.update(field, op));
304
+ updates.push(object.update({ key: field }, op));
315
305
  }
316
306
  }
317
307
 
@@ -423,7 +413,7 @@ export class CardTypeResource extends FileResource {
423
413
  `Cannot create cardType without providing workflow for it`,
424
414
  );
425
415
  }
426
- const validWorkflowName = await Validate.getInstance().validResourceName(
416
+ const validWorkflowName = Validate.getInstance().validResourceName(
427
417
  'workflows',
428
418
  resourceNameToString(resourceName(workflowName)),
429
419
  await this.project.projectPrefixes(),
@@ -441,20 +431,6 @@ export class CardTypeResource extends FileResource {
441
431
  return super.create(content);
442
432
  }
443
433
 
444
- /**
445
- * Returns content data.
446
- */
447
- public get data(): CardType {
448
- return super.data as CardType;
449
- }
450
-
451
- /**
452
- * Deletes file(s) from disk and clears out the memory resident object.
453
- */
454
- public async delete() {
455
- return super.delete();
456
- }
457
-
458
434
  /**
459
435
  * Renames resource metadata file and renames memory resident object 'name'.
460
436
  * @param newName New name for the resource.
@@ -465,26 +441,22 @@ export class CardTypeResource extends FileResource {
465
441
  return this.handleNameChange(existingName);
466
442
  }
467
443
 
468
- /**
469
- * Shows metadata of the resource.
470
- * @returns card type metadata.
471
- */
472
- public async show(): Promise<CardType> {
473
- return super.show() as Promise<CardType>;
474
- }
475
-
476
444
  /**
477
445
  * Updates card type resource.
478
- * @param key Key to modify
446
+ * @param updateKey Key to modify
479
447
  * @param op Operation to perform on 'key'
480
448
  */
481
- public async update<Type>(key: string, op: Operation<Type>) {
449
+ public async update<Type, K extends string>(
450
+ updateKey: UpdateKey<K>,
451
+ op: Operation<Type>,
452
+ ) {
453
+ const { key } = updateKey;
482
454
  const nameChange = key === 'name';
483
455
  const customFieldsChange = key === 'customFields';
484
456
  const existingName = this.content.name;
485
- await super.update(key, op);
457
+ await super.update(updateKey, op);
486
458
 
487
- const content = structuredClone(this.content) as CardType;
459
+ const content = structuredClone(this.content);
488
460
  if (key === 'name') {
489
461
  content.name = super.handleScalar(op) as string;
490
462
  } else if (key === 'alwaysVisibleFields') {
@@ -525,7 +497,7 @@ export class CardTypeResource extends FileResource {
525
497
  } else {
526
498
  throw new Error(`Unknown property '${key}' for CardType`);
527
499
  }
528
- await super.postUpdate(content, key, op);
500
+ await super.postUpdate(content, updateKey, op);
529
501
 
530
502
  // Renaming this card type causes that references to its name must be updated.
531
503
  if (nameChange) {
@@ -544,7 +516,7 @@ export class CardTypeResource extends FileResource {
544
516
  * @returns array of card keys, resource names and calculation filenames that refer this resource.
545
517
  */
546
518
  public async usage(cards?: Card[]): Promise<string[]> {
547
- const allCards = cards ?? (await super.cards());
519
+ const allCards = cards ?? super.cards();
548
520
  const [
549
521
  cardsWithCardType,
550
522
  cardContentReferences,
@@ -566,11 +538,4 @@ export class CardTypeResource extends FileResource {
566
538
  ...new Set([...cardReferences, ...relevantLinkTypes, ...calculations]),
567
539
  ];
568
540
  }
569
-
570
- /**
571
- * Validates the resource. If object is invalid, throws.
572
- */
573
- public async validate(content?: object) {
574
- return super.validate(content);
575
- }
576
541
  }
@@ -33,6 +33,7 @@ import type {
33
33
  DataType,
34
34
  EnumDefinition,
35
35
  FieldType,
36
+ UpdateKey,
36
37
  } from '../interfaces/resource-interfaces.js';
37
38
  import { CardTypeResource } from './card-type-resource.js';
38
39
  import {
@@ -48,7 +49,7 @@ const SHORT_TEXT_MAX_LENGTH = 80;
48
49
  /**
49
50
  * Field type resource class.
50
51
  */
51
- export class FieldTypeResource extends FileResource {
52
+ export class FieldTypeResource extends FileResource<FieldType> {
52
53
  // Initialize data type change helpers (fromType, toType) to some values.
53
54
  // The actual types are set, if this Field Type's dataType is changed.
54
55
  private fromType: DataType = 'integer';
@@ -59,8 +60,6 @@ export class FieldTypeResource extends FileResource {
59
60
 
60
61
  this.contentSchemaId = 'fieldTypeSchema';
61
62
  this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
62
-
63
- this.initialize();
64
63
  }
65
64
 
66
65
  // Cards from given array that include this field type.
@@ -130,7 +129,7 @@ export class FieldTypeResource extends FileResource {
130
129
  function affectedCard(card: Card): boolean {
131
130
  if (!card.metadata) return false;
132
131
  return cardTypesThatUseThisFieldType.some(
133
- (item) => item === card.metadata!.cardType,
132
+ (item) => item === card.metadata?.cardType,
134
133
  );
135
134
  }
136
135
 
@@ -139,12 +138,11 @@ export class FieldTypeResource extends FileResource {
139
138
  cardTypesThatUseThisFieldType.push(...cardTypes);
140
139
 
141
140
  // Then collect cards (both project and local template) that use those card types.
142
- const projectCards = (
143
- await this.project.cards(this.project.paths.cardRootFolder, {
144
- metadata: true,
145
- })
146
- ).filter((card) => affectedCard(card));
147
- const templateCards = (await this.project.allTemplateCards())
141
+ const projectCards = this.project
142
+ .cards(this.project.paths.cardRootFolder)
143
+ .filter((card) => affectedCard(card));
144
+ const templateCards = this.project
145
+ .allTemplateCards()
148
146
  .filter((card) => !card.path.includes('modules'))
149
147
  .filter((card) => affectedCard(card));
150
148
  const allCards = [...projectCards, ...templateCards];
@@ -213,9 +211,7 @@ export class FieldTypeResource extends FileResource {
213
211
  const removedValue = (op.target as EnumDefinition).enumValue;
214
212
  const cardTypes = await this.relevantCardTypes(ResourcesFrom.localOnly);
215
213
  const allCards = await Promise.all(
216
- cardTypes.map((cardType) =>
217
- this.collectCards({ metadata: true }, cardType),
218
- ),
214
+ cardTypes.map((cardType) => this.collectCards(cardType)),
219
215
  );
220
216
  const cardsToUpdate = allCards
221
217
  .flat()
@@ -290,13 +286,13 @@ export class FieldTypeResource extends FileResource {
290
286
  this.project,
291
287
  resourceName(cardType.name),
292
288
  );
293
- const data = object.data as CardType;
289
+ const data = object.data;
294
290
  if (data) {
295
291
  const found = data.customFields
296
292
  ? data.customFields.find((item) => item.name === oldName)
297
293
  : undefined;
298
294
  if (found) {
299
- await object.update('customFields', op);
295
+ await object.update({ key: 'customFields' }, op);
300
296
  }
301
297
  }
302
298
  }
@@ -322,20 +318,6 @@ export class FieldTypeResource extends FileResource {
322
318
  return super.create(content);
323
319
  }
324
320
 
325
- /**
326
- * Returns content data.
327
- */
328
- public get data(): FieldType {
329
- return super.data as FieldType;
330
- }
331
-
332
- /**
333
- * Deletes file(s) from disk and clears out the memory resident object.
334
- */
335
- public async delete() {
336
- return super.delete();
337
- }
338
-
339
321
  /**
340
322
  * Returns all possible field types.
341
323
  * @returns all possible field types.
@@ -407,33 +389,29 @@ export class FieldTypeResource extends FileResource {
407
389
  return this.handleNameChange(existingName);
408
390
  }
409
391
 
410
- /**
411
- * Shows metadata of the resource.
412
- * @returns field type metadata.
413
- */
414
- public async show(): Promise<FieldType> {
415
- return super.show() as Promise<FieldType>;
416
- }
417
-
418
392
  /**
419
393
  * Updates field type resource.
420
- * @param key Key to modify
394
+ * @param updateKey Key to modify
421
395
  * @param op Operation to perform on 'key'
422
396
  * @throws
423
397
  * - when called with unknown data type
424
398
  * - when called with data type conversion that cannot be done
425
399
  * - when called with unknown property to update
426
400
  */
427
- public async update<Type>(key: string, op: Operation<Type>) {
401
+ public async update<Type, K extends string>(
402
+ updateKey: UpdateKey<K>,
403
+ op: Operation<Type>,
404
+ ) {
405
+ const { key } = updateKey;
428
406
  const nameChange = key === 'name';
429
407
  const typeChange = key === 'dataType';
430
408
  const enumChange = key === 'enumValues';
431
409
  const existingName = this.content.name;
432
- const existingType = (this.content as FieldType).dataType;
410
+ const existingType = this.content.dataType;
433
411
 
434
- await super.update(key, op);
412
+ await super.update(updateKey, op);
435
413
 
436
- const content = structuredClone(this.content) as FieldType;
414
+ const content = structuredClone(this.content);
437
415
  if (key === 'name') {
438
416
  content.name = super.handleScalar(op) as string;
439
417
  } else if (key === 'dataType') {
@@ -473,7 +451,7 @@ export class FieldTypeResource extends FileResource {
473
451
  throw new Error(`Unknown property '${key}' for FieldType`);
474
452
  }
475
453
 
476
- await super.postUpdate(content, key, op);
454
+ await super.postUpdate(content, updateKey, op);
477
455
 
478
456
  if (nameChange) {
479
457
  // Renaming this field type causes that references to its name must be updated.
@@ -494,7 +472,7 @@ export class FieldTypeResource extends FileResource {
494
472
  * @returns array of card keys, resource names and calculation filenames that refer this resource.
495
473
  */
496
474
  public async usage(cards?: Card[]): Promise<string[]> {
497
- const allCards = cards ?? (await super.cards());
475
+ const allCards = cards ?? super.cards();
498
476
 
499
477
  const [cardContentReferences, relevantLinkTypes, calculations] =
500
478
  await Promise.all([
@@ -513,11 +491,4 @@ export class FieldTypeResource extends FileResource {
513
491
  ...new Set([...cardReferences, ...relevantLinkTypes, ...calculations]),
514
492
  ];
515
493
  }
516
-
517
- /**
518
- * Validates the resource. If object is invalid, throws.
519
- */
520
- public async validate(content?: object) {
521
- return super.validate(content);
522
- }
523
494
  }