@cyberismo/data-handler 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/dist/card-metadata-updater.js +7 -1
  2. package/dist/card-metadata-updater.js.map +1 -1
  3. package/dist/command-handler.d.ts +4 -0
  4. package/dist/command-handler.js +19 -3
  5. package/dist/command-handler.js.map +1 -1
  6. package/dist/command-manager.d.ts +24 -1
  7. package/dist/command-manager.js +27 -3
  8. package/dist/command-manager.js.map +1 -1
  9. package/dist/commands/create.d.ts +1 -1
  10. package/dist/commands/create.js +34 -36
  11. package/dist/commands/create.js.map +1 -1
  12. package/dist/commands/export.d.ts +11 -2
  13. package/dist/commands/export.js +54 -41
  14. package/dist/commands/export.js.map +1 -1
  15. package/dist/commands/import.d.ts +9 -1
  16. package/dist/commands/import.js +15 -7
  17. package/dist/commands/import.js.map +1 -1
  18. package/dist/commands/move.js +0 -1
  19. package/dist/commands/move.js.map +1 -1
  20. package/dist/commands/remove.d.ts +8 -1
  21. package/dist/commands/remove.js +8 -4
  22. package/dist/commands/remove.js.map +1 -1
  23. package/dist/commands/rename.d.ts +4 -9
  24. package/dist/commands/rename.js +32 -101
  25. package/dist/commands/rename.js.map +1 -1
  26. package/dist/commands/show.d.ts +16 -10
  27. package/dist/commands/show.js +71 -55
  28. package/dist/commands/show.js.map +1 -1
  29. package/dist/commands/transition.d.ts +9 -2
  30. package/dist/commands/transition.js +25 -17
  31. package/dist/commands/transition.js.map +1 -1
  32. package/dist/commands/update.d.ts +16 -12
  33. package/dist/commands/update.js +19 -17
  34. package/dist/commands/update.js.map +1 -1
  35. package/dist/commands/validate.d.ts +17 -9
  36. package/dist/commands/validate.js +96 -35
  37. package/dist/commands/validate.js.map +1 -1
  38. package/dist/containers/project/calculation-engine.d.ts +7 -4
  39. package/dist/containers/project/calculation-engine.js +61 -66
  40. package/dist/containers/project/calculation-engine.js.map +1 -1
  41. package/dist/containers/project/project-paths.d.ts +5 -4
  42. package/dist/containers/project/project-paths.js +16 -12
  43. package/dist/containers/project/project-paths.js.map +1 -1
  44. package/dist/containers/project/resource-cache.d.ts +169 -0
  45. package/dist/containers/project/resource-cache.js +507 -0
  46. package/dist/containers/project/resource-cache.js.map +1 -0
  47. package/dist/containers/project/resource-handler.d.ts +129 -0
  48. package/dist/containers/project/resource-handler.js +206 -0
  49. package/dist/containers/project/resource-handler.js.map +1 -0
  50. package/dist/containers/project.d.ts +38 -153
  51. package/dist/containers/project.js +129 -405
  52. package/dist/containers/project.js.map +1 -1
  53. package/dist/containers/template.d.ts +8 -2
  54. package/dist/containers/template.js +20 -15
  55. package/dist/containers/template.js.map +1 -1
  56. package/dist/interfaces/folder-content-interfaces.d.ts +5 -3
  57. package/dist/interfaces/folder-content-interfaces.js +3 -3
  58. package/dist/interfaces/folder-content-interfaces.js.map +1 -1
  59. package/dist/interfaces/project-interfaces.d.ts +2 -4
  60. package/dist/interfaces/project-interfaces.js.map +1 -1
  61. package/dist/interfaces/resource-interfaces.d.ts +14 -1
  62. package/dist/interfaces/resource-interfaces.js.map +1 -1
  63. package/dist/macros/graph/index.js +12 -26
  64. package/dist/macros/graph/index.js.map +1 -1
  65. package/dist/macros/index.d.ts +1 -1
  66. package/dist/macros/index.js +2 -2
  67. package/dist/macros/index.js.map +1 -1
  68. package/dist/macros/report/index.js +3 -6
  69. package/dist/macros/report/index.js.map +1 -1
  70. package/dist/module-manager.d.ts +16 -3
  71. package/dist/module-manager.js +51 -19
  72. package/dist/module-manager.js.map +1 -1
  73. package/dist/project-settings.d.ts +16 -3
  74. package/dist/project-settings.js +79 -14
  75. package/dist/project-settings.js.map +1 -1
  76. package/dist/resources/calculation-resource.d.ts +4 -3
  77. package/dist/resources/calculation-resource.js +11 -5
  78. package/dist/resources/calculation-resource.js.map +1 -1
  79. package/dist/resources/card-type-resource.d.ts +6 -1
  80. package/dist/resources/card-type-resource.js +34 -23
  81. package/dist/resources/card-type-resource.js.map +1 -1
  82. package/dist/resources/create-defaults.d.ts +3 -2
  83. package/dist/resources/create-defaults.js +3 -2
  84. package/dist/resources/create-defaults.js.map +1 -1
  85. package/dist/resources/field-type-resource.d.ts +4 -1
  86. package/dist/resources/field-type-resource.js +22 -23
  87. package/dist/resources/field-type-resource.js.map +1 -1
  88. package/dist/resources/file-resource.d.ts +5 -9
  89. package/dist/resources/file-resource.js +6 -11
  90. package/dist/resources/file-resource.js.map +1 -1
  91. package/dist/resources/folder-resource.d.ts +29 -32
  92. package/dist/resources/folder-resource.js +59 -78
  93. package/dist/resources/folder-resource.js.map +1 -1
  94. package/dist/resources/graph-model-resource.d.ts +4 -1
  95. package/dist/resources/graph-model-resource.js +11 -4
  96. package/dist/resources/graph-model-resource.js.map +1 -1
  97. package/dist/resources/graph-view-resource.d.ts +5 -2
  98. package/dist/resources/graph-view-resource.js +7 -3
  99. package/dist/resources/graph-view-resource.js.map +1 -1
  100. package/dist/resources/link-type-resource.d.ts +5 -2
  101. package/dist/resources/link-type-resource.js +5 -2
  102. package/dist/resources/link-type-resource.js.map +1 -1
  103. package/dist/resources/report-resource.d.ts +6 -7
  104. package/dist/resources/report-resource.js +14 -23
  105. package/dist/resources/report-resource.js.map +1 -1
  106. package/dist/resources/resource-object.d.ts +93 -8
  107. package/dist/resources/resource-object.js +162 -110
  108. package/dist/resources/resource-object.js.map +1 -1
  109. package/dist/resources/template-resource.d.ts +7 -3
  110. package/dist/resources/template-resource.js +10 -3
  111. package/dist/resources/template-resource.js.map +1 -1
  112. package/dist/resources/workflow-resource.d.ts +5 -2
  113. package/dist/resources/workflow-resource.js +18 -22
  114. package/dist/resources/workflow-resource.js.map +1 -1
  115. package/dist/utils/card-utils.d.ts +2 -2
  116. package/dist/utils/card-utils.js +1 -1
  117. package/dist/utils/clingo-fact-builder.d.ts +25 -14
  118. package/dist/utils/clingo-fact-builder.js +27 -5
  119. package/dist/utils/clingo-fact-builder.js.map +1 -1
  120. package/dist/utils/clingo-facts.js +3 -4
  121. package/dist/utils/clingo-facts.js.map +1 -1
  122. package/dist/utils/resource-utils.d.ts +1 -0
  123. package/dist/utils/resource-utils.js +2 -1
  124. package/dist/utils/resource-utils.js.map +1 -1
  125. package/package.json +8 -8
  126. package/src/card-metadata-updater.ts +6 -2
  127. package/src/command-handler.ts +24 -5
  128. package/src/command-manager.ts +29 -17
  129. package/src/commands/create.ts +43 -78
  130. package/src/commands/export.ts +63 -52
  131. package/src/commands/import.ts +24 -14
  132. package/src/commands/move.ts +0 -1
  133. package/src/commands/remove.ts +11 -7
  134. package/src/commands/rename.ts +43 -149
  135. package/src/commands/show.ts +113 -78
  136. package/src/commands/transition.ts +26 -28
  137. package/src/commands/update.ts +25 -22
  138. package/src/commands/validate.ts +108 -67
  139. package/src/containers/project/calculation-engine.ts +61 -93
  140. package/src/containers/project/project-paths.ts +21 -13
  141. package/src/containers/project/resource-cache.ts +648 -0
  142. package/src/containers/project/resource-handler.ts +265 -0
  143. package/src/containers/project.ts +178 -522
  144. package/src/containers/template.ts +24 -19
  145. package/src/interfaces/folder-content-interfaces.ts +7 -6
  146. package/src/interfaces/project-interfaces.ts +7 -6
  147. package/src/interfaces/resource-interfaces.ts +18 -3
  148. package/src/macros/graph/index.ts +26 -47
  149. package/src/macros/index.ts +2 -2
  150. package/src/macros/report/index.ts +3 -9
  151. package/src/module-manager.ts +74 -17
  152. package/src/project-settings.ts +83 -14
  153. package/src/resources/calculation-resource.ts +18 -18
  154. package/src/resources/card-type-resource.ts +50 -50
  155. package/src/resources/create-defaults.ts +3 -2
  156. package/src/resources/field-type-resource.ts +41 -55
  157. package/src/resources/file-resource.ts +10 -36
  158. package/src/resources/folder-resource.ts +69 -120
  159. package/src/resources/graph-model-resource.ts +20 -22
  160. package/src/resources/graph-view-resource.ts +15 -17
  161. package/src/resources/link-type-resource.ts +10 -13
  162. package/src/resources/report-resource.ts +21 -43
  163. package/src/resources/resource-object.ts +194 -152
  164. package/src/resources/template-resource.ts +17 -16
  165. package/src/resources/workflow-resource.ts +25 -44
  166. package/src/utils/card-utils.ts +2 -2
  167. package/src/utils/clingo-fact-builder.ts +28 -16
  168. package/src/utils/clingo-facts.ts +3 -4
  169. package/src/utils/resource-utils.ts +2 -1
  170. package/dist/containers/project/resource-collector.d.ts +0 -110
  171. package/dist/containers/project/resource-collector.js +0 -344
  172. package/dist/containers/project/resource-collector.js.map +0 -1
  173. package/src/containers/project/resource-collector.ts +0 -404
@@ -11,40 +11,30 @@
11
11
  You should have received a copy of the GNU Affero General Public
12
12
  License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
13
  */
14
- import { readdir } from 'node:fs/promises';
15
- import { readFileSync } from 'node:fs';
16
14
  import { extname, join } from 'node:path';
15
+ import { readdir } from 'node:fs/promises';
17
16
  import { copyDir } from '../utils/file-utils.js';
18
- import { DefaultContent, FolderResource, resourceNameToString, sortCards, } from './folder-resource.js';
17
+ import { DefaultContent } from './create-defaults.js';
18
+ import { FolderResource } from './folder-resource.js';
19
19
  import { getStaticDirectoryPath } from '@cyberismo/assets';
20
+ import { resourceNameToString } from '../utils/resource-utils.js';
21
+ import { sortCards } from '../utils/card-utils.js';
20
22
  import { Validate } from '../commands/validate.js';
21
- const REPORT_SCHEMA_FILE = 'parameterSchema.json';
22
23
  const PARAMETER_SCHEMA_ID = 'jsonSchema';
23
- const staticDirectoryPath = await getStaticDirectoryPath();
24
24
  /**
25
25
  * Report resource class.
26
26
  */
27
27
  export class ReportResource extends FolderResource {
28
- reportSchema;
29
28
  constructor(project, name) {
30
29
  super(project, name, 'reports');
31
30
  this.contentSchemaId = 'reportSchema';
32
31
  this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
33
- const schemaPath = join(this.internalFolder, REPORT_SCHEMA_FILE);
34
- this.reportSchema = this.readSchemaFile(schemaPath);
35
32
  }
36
33
  // Path to content folder.
37
34
  // @todo: create the files' content dynamically.
38
- defaultReportLocation = join(staticDirectoryPath, 'defaultReport');
39
- // Try to read schema file content
40
- readSchemaFile(path) {
41
- try {
42
- const schema = readFileSync(path);
43
- return JSON.parse(schema.toString());
44
- }
45
- catch {
46
- return undefined;
47
- }
35
+ async getDefaultReportLocation() {
36
+ const staticDirectoryPath = await getStaticDirectoryPath();
37
+ return join(staticDirectoryPath, 'defaultReport');
48
38
  }
49
39
  /**
50
40
  * Handle name changes for reports
@@ -60,14 +50,14 @@ export class ReportResource extends FolderResource {
60
50
  }
61
51
  /**
62
52
  * Sets new metadata into the report object.
63
- * @param newContent metadata content for the report.
64
- * @throws if 'newContent' is not valid.
65
53
  */
66
54
  async createReport() {
67
55
  const defaultContent = DefaultContent.report(resourceNameToString(this.resourceName));
68
56
  await super.create(defaultContent);
69
57
  // Copy report default structure to destination.
70
- await copyDir(this.defaultReportLocation, this.internalFolder);
58
+ const defaultReportLocation = await this.getDefaultReportLocation();
59
+ await copyDir(defaultReportLocation, this.internalFolder);
60
+ await this.loadContentFiles();
71
61
  }
72
62
  /**
73
63
  * Returns list of handlebar filenames that this report has.
@@ -126,8 +116,9 @@ export class ReportResource extends FolderResource {
126
116
  * @note If content is not provided, base class validation will use resource's current content.
127
117
  */
128
118
  async validate(content) {
129
- if (this.reportSchema) {
130
- const errors = Validate.getInstance().validateJson(this.reportSchema, PARAMETER_SCHEMA_ID);
119
+ const resourceContent = this.contentData();
120
+ if (resourceContent.schema) {
121
+ const errors = Validate.getInstance().validateJson(resourceContent.schema, PARAMETER_SCHEMA_ID);
131
122
  if (errors.length > 0) {
132
123
  throw new Error(`Invalid parameter schema: ${errors}`);
133
124
  }
@@ -1 +1 @@
1
- {"version":3,"file":"report-resource.js","sourceRoot":"","sources":["../../src/resources/report-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,O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C;gBACtB,MAAM,IAAI,KAAK,CAAC,6BAA6B,MAAM,EAAE,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;CACF"}
@@ -9,11 +9,11 @@
9
9
  You should have received a copy of the GNU Affero General Public
10
10
  License along with this program. If not, see <https://www.gnu.org/licenses/>.
11
11
  */
12
+ import { type ResourceName } from '../utils/resource-utils.js';
12
13
  import type { Card, ResourceFolderType } from '../interfaces/project-interfaces.js';
13
14
  import type { Logger } from 'pino';
14
15
  import type { Project } from '../containers/project.js';
15
16
  import type { ResourceBaseMetadata, UpdateKey } from '../interfaces/resource-interfaces.js';
16
- import { type ResourceName } from '../utils/resource-utils.js';
17
17
  export type UpdateOperations = 'add' | 'change' | 'rank' | 'remove';
18
18
  type BaseOperation<T> = {
19
19
  name: 'add' | 'change' | 'rank' | 'remove';
@@ -57,7 +57,7 @@ export declare abstract class AbstractResource<T extends ResourceBaseMetadata, U
57
57
  protected abstract delete(): Promise<void>;
58
58
  protected abstract read(): Promise<void>;
59
59
  protected abstract rename(newName: ResourceName): Promise<void>;
60
- protected abstract show(): Promise<ShowReturnType<T, U>>;
60
+ protected abstract show(): ShowReturnType<T, U>;
61
61
  protected abstract update<Type, K extends string>(updateKey: UpdateKey<K>, operation: Operation<Type>): Promise<void>;
62
62
  protected abstract usage(cards?: Card[]): Promise<string[]>;
63
63
  protected abstract validate(content?: object): Promise<void>;
@@ -68,7 +68,6 @@ export declare abstract class AbstractResource<T extends ResourceBaseMetadata, U
68
68
  export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U> extends AbstractResource<T, U> {
69
69
  protected project: Project;
70
70
  protected resourceName: ResourceName;
71
- private cache;
72
71
  private static validateInstancePromise?;
73
72
  protected content: T;
74
73
  protected moduleResource: boolean;
@@ -81,18 +80,35 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
81
80
  * Path to the resource metadata file (the .json file).
82
81
  */
83
82
  fileName: string;
83
+ /**
84
+ * Constructs a ResourceObject instance
85
+ * @param project Project where this resource is
86
+ * @param resourceName Name for the resource
87
+ * @param type Type of resource
88
+ */
84
89
  constructor(project: Project, resourceName: ResourceName, type: ResourceFolderType);
90
+ private exists;
85
91
  private static getValidate;
86
- private resourceObjectToResource;
92
+ private reportHandlerBarFiles;
87
93
  private resourceType;
88
- private toCache;
89
94
  /**
90
- * Checks if resource exists
95
+ * Checks if resource exists.
96
+ * This should only throw, if someone creates resources directly; ie. not through the cache
91
97
  * @throws if resource does not exist
92
98
  */
93
99
  protected assertResourceExists(): void;
100
+ /**
101
+ * Calculate; empty implementation.
102
+ */
94
103
  protected calculate(): Promise<void>;
104
+ /**
105
+ * Calculations that use this resource.
106
+ * @throws if accessing calculations files failed
107
+ */
95
108
  protected calculations(): Promise<string[]>;
109
+ /**
110
+ * Cards from project.
111
+ */
96
112
  protected cards(): Card[];
97
113
  /**
98
114
  * Returns .schema content file.
@@ -100,8 +116,21 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
100
116
  * @returns .schema content.
101
117
  */
102
118
  protected contentSchemaContent(schemaId: string): JSON;
119
+ /**
120
+ * Creates resource.
121
+ * @param newContent Content for resource.
122
+ * @throws when resource already exists in the project.
123
+ */
103
124
  protected create(newContent?: T): Promise<void>;
125
+ /**
126
+ * Gets a logger instance.
127
+ * @param loggerName
128
+ * @returns logger instance
129
+ */
104
130
  protected getLogger(loggerName: string): Logger;
131
+ /**
132
+ * Returns type of this resource.
133
+ */
105
134
  protected get getType(): string;
106
135
  /**
107
136
  * Handles operation to an array.
@@ -109,23 +138,60 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
109
138
  * @param arrayName Name of the array, for error messages.
110
139
  * @param array Array to be updated.
111
140
  * @returns Changed array after the operation.
141
+ * @throws when operation cannot be done.
112
142
  */
113
143
  protected handleArray<Type>(operation: Operation<Type>, arrayName: string, array: Type[]): Type[];
114
144
  /**
115
145
  * Updates scalar value. The only accepted operation is 'change'
116
146
  * @param operation Operation to perform on scalar.
117
147
  * @returns What the scalar should be changed to.
148
+ * @throws when operation cannot be done
118
149
  */
119
150
  protected handleScalar<Type>(operation: Operation<Type>): Type;
151
+ /**
152
+ * Initialize the resource.
153
+ */
120
154
  protected initialize(): void;
155
+ /**
156
+ * Called after inherited class has finished 'update' operation.
157
+ * @param content New content for resource
158
+ * @param updateKey Which property to change
159
+ * @param op What kind of operation is performed to updateKey
160
+ * @throws if validation fails after the update
161
+ */
121
162
  protected postUpdate<Type, K extends string>(content: T, updateKey: UpdateKey<K>, op: Operation<Type>): Promise<void>;
122
- protected update<Type, K extends string>(key: UpdateKey<K>, _op: Operation<Type>): Promise<void>;
163
+ /**
164
+ * Reads content from file to memory.
165
+ */
123
166
  protected read(): Promise<void>;
167
+ /**
168
+ * Renames resource.
169
+ * @param newName New name for the resource.
170
+ * @throws if trying to rename module resource, or
171
+ * if resource does not exist,
172
+ * if trying to rename so that type changes
173
+ */
124
174
  protected rename(newName: ResourceName): Promise<void>;
175
+ /**
176
+ * Update resource; the base class makes some checks only.
177
+ * @template type Resource type
178
+ * @template K Resource key
179
+ * @throws if resource does not exist, or
180
+ * if trying to update module content, or
181
+ * if key is empty
182
+ */
183
+ protected update<Type, K extends string>(key: UpdateKey<K>, _op: Operation<Type>): Promise<void>;
184
+ /**
185
+ * Validates resource identifier to prevent filesystem operations with invalid names
186
+ * todo: To Validate?
187
+ */
188
+ protected validateResourceIdentifier(): void;
125
189
  /**
126
190
  * Update calculation files.
127
191
  * @param from Resource name to update
128
192
  * @param to New name for resource
193
+ * @throws if 'from' or 'to' is empty string, or
194
+ * if there was error accessing calculation files.
129
195
  */
130
196
  protected updateCalculations(from: string, to: string): Promise<void>;
131
197
  /**
@@ -133,10 +199,26 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
133
199
  * @param from Resource name to update
134
200
  * @param to New name for resource
135
201
  * @param handleBarFiles Optional. List of handlebar files. If omitted, affects all handlebar files in the project.
202
+ * @throws if 'from' or 'to' is empty string
136
203
  */
137
204
  protected updateHandleBars(from: string, to: string, handleBarFiles?: string[]): Promise<void>;
205
+ /**
206
+ * Check if there are references to the resource in the card content.
207
+ * @note that this needs to be async, since inherited classes need to async operations
208
+ * @param cards cards to check
209
+ * @throws if resource does not exist
210
+ */
138
211
  protected usage(cards?: Card[]): Promise<string[]>;
212
+ /**
213
+ * Checks if resource name is valid.
214
+ * @param newName New name for resource.
215
+ * @returns valid name
216
+ */
139
217
  protected validName(newName: ResourceName): Promise<string>;
218
+ /**
219
+ * Write the content from memory to disk.
220
+ * @throws if trying to write a module resource.
221
+ */
140
222
  protected write(): Promise<void>;
141
223
  /**
142
224
  * Returns memory resident data as JSON.
@@ -146,12 +228,15 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
146
228
  get data(): T | undefined;
147
229
  /**
148
230
  * Deletes the file and removes the resource from project.
149
- * @throws if resource is a module resource or does not exist or is used by other resources.
231
+ * @throws if resource is a module resource, or
232
+ * if resource does not exist, or
233
+ * if resource is used by other resources.
150
234
  */
151
235
  delete(): Promise<void>;
152
236
  /**
153
237
  * Validates the content of the resource.
154
238
  * @param content Content to be validated.
239
+ * @throws if content is invalid.
155
240
  */
156
241
  validate(content?: object): Promise<void>;
157
242
  }