@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,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,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAenD,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAClD,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAEzC,MAAM,mBAAmB,GAAG,MAAM,sBAAsB,EAAE,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,cAGnC;IACS,YAAY,CAAS;IAC7B,YAAY,OAAgB,EAAE,IAAkB;QAC9C,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QAEhC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAEtE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,kB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AAG,CAAC;YACtD,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC;YACrB,KAAK,CAAC,YAAY,EAAE;SACrB,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,QAAQ,CAAC,OAAgB;QACpC,MAAM,eAAe,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3C,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC,YAAY,CAChD,eAAe,CAAC,MAAM,EACtB,mBAAmB,CACpB,CAAC;YACF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;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,61 @@ 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
+ protected logResourceOperation<Type>(operationType: 'create' | 'delete' | 'update' | 'rename', op?: Operation<Type>, key?: string): Promise<void>;
156
+ /**
157
+ * Called after inherited class has finished 'update' operation.
158
+ * @param content New content for resource
159
+ * @param updateKey Which property to change
160
+ * @param op What kind of operation is performed to updateKey
161
+ * @throws if validation fails after the update
162
+ */
121
163
  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>;
164
+ /**
165
+ * Reads content from file to memory.
166
+ */
123
167
  protected read(): Promise<void>;
168
+ /**
169
+ * Renames resource.
170
+ * @param newName New name for the resource.
171
+ * @throws if trying to rename module resource, or
172
+ * if resource does not exist,
173
+ * if trying to rename so that type changes
174
+ */
124
175
  protected rename(newName: ResourceName): Promise<void>;
176
+ /**
177
+ * Update resource; the base class makes some checks only.
178
+ * @template type Resource type
179
+ * @template K Resource key
180
+ * @throws if resource does not exist, or
181
+ * if trying to update module content, or
182
+ * if key is empty
183
+ */
184
+ protected update<Type, K extends string>(key: UpdateKey<K>, _op: Operation<Type>): Promise<void>;
185
+ /**
186
+ * Validates resource identifier to prevent filesystem operations with invalid names
187
+ * todo: To Validate?
188
+ */
189
+ protected validateResourceIdentifier(): void;
125
190
  /**
126
191
  * Update calculation files.
127
192
  * @param from Resource name to update
128
193
  * @param to New name for resource
194
+ * @throws if 'from' or 'to' is empty string, or
195
+ * if there was error accessing calculation files.
129
196
  */
130
197
  protected updateCalculations(from: string, to: string): Promise<void>;
131
198
  /**
@@ -133,10 +200,26 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
133
200
  * @param from Resource name to update
134
201
  * @param to New name for resource
135
202
  * @param handleBarFiles Optional. List of handlebar files. If omitted, affects all handlebar files in the project.
203
+ * @throws if 'from' or 'to' is empty string
136
204
  */
137
205
  protected updateHandleBars(from: string, to: string, handleBarFiles?: string[]): Promise<void>;
206
+ /**
207
+ * Check if there are references to the resource in the card content.
208
+ * @note that this needs to be async, since inherited classes need to async operations
209
+ * @param cards cards to check
210
+ * @throws if resource does not exist
211
+ */
138
212
  protected usage(cards?: Card[]): Promise<string[]>;
213
+ /**
214
+ * Checks if resource name is valid.
215
+ * @param newName New name for resource.
216
+ * @returns valid name
217
+ */
139
218
  protected validName(newName: ResourceName): Promise<string>;
219
+ /**
220
+ * Write the content from memory to disk.
221
+ * @throws if trying to write a module resource.
222
+ */
140
223
  protected write(): Promise<void>;
141
224
  /**
142
225
  * Returns memory resident data as JSON.
@@ -146,12 +229,15 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
146
229
  get data(): T | undefined;
147
230
  /**
148
231
  * 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.
232
+ * @throws if resource is a module resource, or
233
+ * if resource does not exist, or
234
+ * if resource is used by other resources.
150
235
  */
151
236
  delete(): Promise<void>;
152
237
  /**
153
238
  * Validates the content of the resource.
154
239
  * @param content Content to be validated.
240
+ * @throws if content is invalid.
155
241
  */
156
242
  validate(content?: object): Promise<void>;
157
243
  }