@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
@@ -22,24 +22,22 @@ import {
22
22
  resourceNameToString,
23
23
  sortCards,
24
24
  } from './folder-resource.js';
25
- import type { LinkType } from '../interfaces/resource-interfaces.js';
25
+ import type { LinkType, UpdateKey } from '../interfaces/resource-interfaces.js';
26
26
 
27
27
  /**
28
28
  * Link Type resource class.
29
29
  */
30
- export class LinkTypeResource extends FileResource {
30
+ export class LinkTypeResource extends FileResource<LinkType> {
31
31
  constructor(project: Project, name: ResourceName) {
32
32
  super(project, name, 'linkTypes');
33
33
 
34
34
  this.contentSchemaId = 'linkTypeSchema';
35
35
  this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
36
-
37
- this.initialize();
38
36
  }
39
37
 
40
38
  // When resource name changes.
41
39
  private async handleNameChange(existingName: string) {
42
- const current = this.content as LinkType;
40
+ const current = this.content;
43
41
  const prefixes = await this.project.projectPrefixes();
44
42
  if (current.sourceCardTypes) {
45
43
  current.sourceCardTypes = current.sourceCardTypes.map((item) =>
@@ -74,20 +72,6 @@ export class LinkTypeResource extends FileResource {
74
72
  return super.create(newContent);
75
73
  }
76
74
 
77
- /**
78
- * Returns content data.
79
- */
80
- public get data() {
81
- return super.data as LinkType;
82
- }
83
-
84
- /**
85
- * Deletes file(s) from disk and clears out the memory resident object.
86
- */
87
- public async delete() {
88
- return super.delete();
89
- }
90
-
91
75
  /**
92
76
  * Renames resource metadata file and renames memory resident object 'name'.
93
77
  * @param newName New name for the resource.
@@ -98,26 +82,22 @@ export class LinkTypeResource extends FileResource {
98
82
  return this.handleNameChange(existingName);
99
83
  }
100
84
 
101
- /**
102
- * Shows metadata of the resource.
103
- * @returns link type metadata.
104
- */
105
- public async show(): Promise<LinkType> {
106
- return super.show() as Promise<LinkType>;
107
- }
108
-
109
85
  /**
110
86
  * Updates link type resource.
111
- * @param key Key to modify
87
+ * @param updateKey Key to modify
112
88
  * @param op Operation to perform on 'key'
113
89
  */
114
- public async update<Type>(key: string, op: Operation<Type>) {
90
+ public async update<Type, K extends string>(
91
+ updateKey: UpdateKey<K>,
92
+ op: Operation<Type>,
93
+ ) {
94
+ const { key } = updateKey;
115
95
  const nameChange = key === 'name';
116
96
  const existingName = this.content.name;
117
97
 
118
- await super.update(key, op);
98
+ await super.update(updateKey, op);
119
99
 
120
- const content = structuredClone(this.content) as LinkType;
100
+ const content = structuredClone(this.content);
121
101
  if (key === 'name') {
122
102
  content.name = super.handleScalar(op) as string;
123
103
  } else if (key === 'destinationCardTypes') {
@@ -142,7 +122,7 @@ export class LinkTypeResource extends FileResource {
142
122
  throw new Error(`Unknown property '${key}' for FieldType`);
143
123
  }
144
124
 
145
- await super.postUpdate(content, key, op);
125
+ await super.postUpdate(content, updateKey, op);
146
126
 
147
127
  // Renaming this card type causes that references to its name must be updated.
148
128
  if (nameChange) {
@@ -159,7 +139,7 @@ export class LinkTypeResource extends FileResource {
159
139
  */
160
140
  public async usage(cards?: Card[]): Promise<string[]> {
161
141
  const resourceName = resourceNameToString(this.resourceName);
162
- const allCards = cards || (await super.cards());
142
+ const allCards = cards || super.cards();
163
143
 
164
144
  const cardsThatUseLinkType = allCards
165
145
  .filter((card) =>
@@ -181,11 +161,4 @@ export class LinkTypeResource extends FileResource {
181
161
  // Using Set to avoid duplicate cards
182
162
  return [...new Set([...cardReferences, ...calculations])];
183
163
  }
184
-
185
- /**
186
- * Validates the resource. If object is invalid, throws.
187
- */
188
- public async validate(content?: object) {
189
- return super.validate(content);
190
- }
191
164
  }
@@ -24,7 +24,6 @@ import {
24
24
  sortCards,
25
25
  } from './folder-resource.js';
26
26
  import { getStaticDirectoryPath } from '@cyberismo/assets';
27
- import { filename } from '../interfaces/folder-content-interfaces.js';
28
27
  import { Validate } from '../commands/validate.js';
29
28
 
30
29
  import type {
@@ -33,10 +32,9 @@ import type {
33
32
  Project,
34
33
  ResourceName,
35
34
  } from './folder-resource.js';
36
- import type {
37
- Report,
38
- ReportMetadata,
39
- ReportUpdateKey,
35
+ import {
36
+ type ReportMetadata,
37
+ type UpdateKey,
40
38
  } from '../interfaces/resource-interfaces.js';
41
39
  import type { ReportContent } from '../interfaces/folder-content-interfaces.js';
42
40
  import type { Schema } from 'jsonschema';
@@ -49,7 +47,10 @@ const staticDirectoryPath = await getStaticDirectoryPath();
49
47
  /**
50
48
  * Report resource class.
51
49
  */
52
- export class ReportResource extends FolderResource {
50
+ export class ReportResource extends FolderResource<
51
+ ReportMetadata,
52
+ ReportContent
53
+ > {
53
54
  private reportSchema: Schema;
54
55
  constructor(project: Project, name: ResourceName) {
55
56
  super(project, name, 'reports');
@@ -57,8 +58,6 @@ export class ReportResource extends FolderResource {
57
58
  this.contentSchemaId = 'reportSchema';
58
59
  this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
59
60
 
60
- this.initialize();
61
-
62
61
  const schemaPath = join(this.internalFolder, REPORT_SCHEMA_FILE);
63
62
  this.reportSchema = this.readSchemaFile(schemaPath);
64
63
  }
@@ -113,20 +112,6 @@ export class ReportResource extends FolderResource {
113
112
  await copyDir(this.defaultReportLocation, this.internalFolder);
114
113
  }
115
114
 
116
- /**
117
- * Returns resource content.
118
- */
119
- public get data(): ReportMetadata {
120
- return super.data as ReportMetadata;
121
- }
122
-
123
- /**
124
- * Deletes file and folder that this resource is based on.
125
- */
126
- public async delete() {
127
- return super.delete();
128
- }
129
-
130
115
  /**
131
116
  * Returns list of handlebar filenames that this report has.
132
117
  * @returns list of handlebar filenames that this report has.
@@ -152,49 +137,24 @@ export class ReportResource extends FolderResource {
152
137
  return this.onNameChange(existingName);
153
138
  }
154
139
 
155
- /**
156
- * Shows metadata of the resource.
157
- * @returns report metadata.
158
- */
159
- public async show(): Promise<Report> {
160
- const baseData = (await super.show()) as ReportMetadata;
161
- const fileContents = await super.contentData();
162
- const content: ReportContent = {
163
- contentTemplate: fileContents.contentTemplate as string,
164
- queryTemplate: fileContents.queryTemplate as string,
165
- schema: fileContents.schema ? (fileContents.schema as Schema) : undefined,
166
- };
167
- return {
168
- ...baseData,
169
- content: content,
170
- };
171
- }
172
-
173
140
  /**
174
141
  * Updates report resource.
175
- * @param key Key to modify
142
+ * @param updateKey Key to modify
176
143
  * @param op Operation to perform on 'key'
177
144
  */
178
- public async update<Type>(key: ReportUpdateKey, op: Operation<Type>) {
179
- if (
180
- typeof key === 'object' &&
181
- key.key === 'content' &&
182
- key.subKey === 'schema'
183
- ) {
184
- const fileContent = JSON.stringify(super.handleScalar(op), null, 2);
185
- await this.updateFile(filename(key.subKey)!, fileContent);
186
- return;
187
- }
188
-
189
- if (key === 'category') {
190
- const content = structuredClone(this.content) as ReportMetadata;
145
+ public async update<Type, K extends string>(
146
+ updateKey: UpdateKey<K>,
147
+ op: Operation<Type>,
148
+ ) {
149
+ if (updateKey.key === 'category') {
150
+ const content = structuredClone(this.content);
191
151
  content.category = super.handleScalar(op) as string;
192
152
 
193
- await super.postUpdate(content, key, op);
153
+ await super.postUpdate(content, updateKey, op);
194
154
  return;
195
155
  }
196
156
 
197
- await super.update(key, op);
157
+ await super.update(updateKey, op);
198
158
  }
199
159
 
200
160
  /**
@@ -205,7 +165,7 @@ export class ReportResource extends FolderResource {
205
165
  * @returns array of card keys and calculation filenames that refer this resource.
206
166
  */
207
167
  public async usage(cards?: Card[]): Promise<string[]> {
208
- const allCards = cards ?? (await super.cards());
168
+ const allCards = cards ?? super.cards();
209
169
  const [relevantCards, calculations] = await Promise.all([
210
170
  super.usage(allCards),
211
171
  super.calculations(),