@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
@@ -0,0 +1,265 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+
15
+ import {
16
+ ResourceCache,
17
+ ResourcesFrom,
18
+ type ResourceMap,
19
+ } from './resource-cache.js';
20
+ import { resourceName } from '../../utils/resource-utils.js';
21
+ import type { Project } from '../project.js';
22
+ import type { ResourceFolderType } from '../../interfaces/project-interfaces.js';
23
+ import type { ResourceName } from '../../utils/resource-utils.js';
24
+
25
+ // Convert singular forms to plural. Uses real type, so cannot be general.
26
+ export const singularToPluralResourceType: Record<string, keyof ResourceMap> = {
27
+ template: 'templates',
28
+ workflow: 'workflows',
29
+ report: 'reports',
30
+ calculation: 'calculations',
31
+ cardType: 'cardTypes',
32
+ fieldType: 'fieldTypes',
33
+ graphModel: 'graphModels',
34
+ graphView: 'graphViews',
35
+ linkType: 'linkTypes',
36
+ };
37
+
38
+ /**
39
+ * ResourceHandler manages resource access for a project.
40
+ * It owns the ResourceCache and provides APIs for accessing resources.
41
+ */
42
+ export class ResourceHandler {
43
+ private cache: ResourceCache;
44
+
45
+ /**
46
+ * Creates instance of ResourceHandler.
47
+ * @param project Project to use in cache
48
+ */
49
+ constructor(project: Project) {
50
+ this.cache = ResourceCache.create(project);
51
+ }
52
+
53
+ /**
54
+ * Add a resource to the cache.
55
+ * @param name Name of the resource to add
56
+ * @param instance Resource instance
57
+ */
58
+ public add(name: string | ResourceName, instance: unknown): void {
59
+ this.cache.addResource(name, instance);
60
+ }
61
+
62
+ public byType<T extends keyof ResourceMap>(
63
+ name: string,
64
+ type: T,
65
+ ): ResourceMap[T];
66
+
67
+ /**
68
+ * Overload to the above: Accept resource name
69
+ * @param resourceName Name of resource as a resource name (prefix/type/identifier)
70
+ * @template T Resource type
71
+ * @returns resource with inferred actual type.
72
+ */
73
+ public byType<T extends keyof ResourceMap>(
74
+ resourceName: ResourceName,
75
+ ): ResourceMap[T];
76
+
77
+ /**
78
+ * Returns type of resource.
79
+ * @param nameOrResourceName Name of resource
80
+ * @param type Name of resource as string matching Resource map element.
81
+ * @template T Resource type as part of ResourceMap
82
+ * @returns resource with inferred actual type.
83
+ */
84
+ public byType<T extends keyof ResourceMap>(
85
+ nameOrResourceName: string | ResourceName,
86
+ type?: T,
87
+ ): ResourceMap[T] {
88
+ if (typeof nameOrResourceName === 'string') {
89
+ if (!type) {
90
+ throw new Error('Type parameter required when using string name');
91
+ }
92
+ return this.cache.resourceByType(nameOrResourceName, type);
93
+ } else {
94
+ return this.cache.resourceByName(nameOrResourceName);
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Get resource by ResourceName object.
100
+ * @param name Resource name
101
+ * @template T Resource type
102
+ * @returns Typed resource that matches the name
103
+ */
104
+ public byName<T extends keyof ResourceMap>(
105
+ name: ResourceName,
106
+ ): ResourceMap[T] {
107
+ return this.cache.resourceByName(name);
108
+ }
109
+
110
+ /**
111
+ * Refresh local resources in the cache.
112
+ */
113
+ public changed(): void {
114
+ this.cache.changed();
115
+ }
116
+
117
+ /**
118
+ * Refresh module resources in the cache.
119
+ * @param moduleName Name of the module. If given, will only update this module's resources.
120
+ */
121
+ public changedModules(moduleName?: string): void {
122
+ this.cache.changedModules(moduleName);
123
+ }
124
+
125
+ /**
126
+ * Check if a resource exists.
127
+ * @param name Resource name to check
128
+ * @returns true if resource exists, false otherwise
129
+ */
130
+ public exists(name: string | ResourceName): boolean {
131
+ return this.cache.has(name);
132
+ }
133
+
134
+ /**
135
+ * Get module names.
136
+ * @returns Array of module names
137
+ */
138
+ public moduleNames(): string[] {
139
+ return this.cache.moduleNames();
140
+ }
141
+
142
+ /**
143
+ * Get certain types of resources from a specific module.
144
+ * @param type Type of resource to fetch
145
+ * @param moduleName Name of the module
146
+ * @returns Resource names from a specific module
147
+ */
148
+ public moduleResourceNames(
149
+ type: ResourceFolderType,
150
+ moduleName: string,
151
+ ): string[] {
152
+ return this.cache.moduleResourceNames(type, moduleName);
153
+ }
154
+
155
+ /**
156
+ * Remove a resource from cache.
157
+ * @param name Resource to remove
158
+ */
159
+ public remove(name: string | ResourceName): void {
160
+ this.cache.removeResource(name);
161
+ }
162
+
163
+ /**
164
+ * Removes all resources from a specific module.
165
+ * @param moduleName Name of the module
166
+ */
167
+ public removeModule(moduleName: string): void {
168
+ this.cache.removeModule(moduleName);
169
+ }
170
+
171
+ /**
172
+ * Change resource name in cache, but keep instance information.
173
+ * @param oldName Old name of the resource
174
+ * @param newName New name of the resource
175
+ */
176
+ public rename(oldName: string, newName: string): void {
177
+ this.cache.changeResourceName(oldName, newName);
178
+ }
179
+
180
+ /**
181
+ * Get resources of a specific type.
182
+ * @param type Type of resources to get
183
+ * @param from Where to return resources from (all, local, imported modules)
184
+ * @template T Resource type
185
+ * @returns Array of resources
186
+ */
187
+ public resourceTypes<T extends keyof ResourceMap>(
188
+ type: T,
189
+ from: ResourcesFrom = ResourcesFrom.all,
190
+ ): Array<ResourceMap[T]> {
191
+ return this.cache.resources(type, from);
192
+ }
193
+
194
+ // The following are just helpers to get specific resource types
195
+ public calculations(from: ResourcesFrom = ResourcesFrom.all) {
196
+ return this.cache.resources('calculations', from);
197
+ }
198
+
199
+ public cardTypes(from: ResourcesFrom = ResourcesFrom.all) {
200
+ return this.cache.resources('cardTypes', from);
201
+ }
202
+
203
+ public fieldTypes(from: ResourcesFrom = ResourcesFrom.all) {
204
+ return this.cache.resources('fieldTypes', from);
205
+ }
206
+
207
+ public graphViews(from: ResourcesFrom = ResourcesFrom.all) {
208
+ return this.cache.resources('graphViews', from);
209
+ }
210
+
211
+ public graphModels(from: ResourcesFrom = ResourcesFrom.all) {
212
+ return this.cache.resources('graphModels', from);
213
+ }
214
+
215
+ public linkTypes(from: ResourcesFrom = ResourcesFrom.all) {
216
+ return this.cache.resources('linkTypes', from);
217
+ }
218
+
219
+ public reports(from: ResourcesFrom = ResourcesFrom.all) {
220
+ return this.cache.resources('reports', from);
221
+ }
222
+
223
+ public templates(from: ResourcesFrom = ResourcesFrom.all) {
224
+ return this.cache.resources('templates', from);
225
+ }
226
+
227
+ public workflows(from: ResourcesFrom = ResourcesFrom.all) {
228
+ return this.cache.resources('workflows', from);
229
+ }
230
+
231
+ /**
232
+ * Extract resource type from a resource name string.
233
+ * @param name Resource name
234
+ * @returns Resource type
235
+ * @throws when resource type is invalid
236
+ */
237
+ public extractType(name: string): keyof ResourceMap {
238
+ const type = resourceName(name).type;
239
+ if (!type) {
240
+ throw new Error(`Invalid resource type: ${type}`);
241
+ }
242
+ return type as keyof ResourceMap;
243
+ }
244
+
245
+ /**
246
+ * Handle file system changes.
247
+ * @param fileName A changed file in the file system
248
+ */
249
+ public handleFileSystemChange(fileName: string): void {
250
+ this.cache.handleFileSystemChange(fileName);
251
+ }
252
+
253
+ /**
254
+ * Get plural resource type name from singular type name.
255
+ * @param singular Resource type as singular name
256
+ * @returns Resource type as plural name
257
+ */
258
+ public resourceTypeFromSingularType(singular: string): keyof ResourceMap {
259
+ const plural = singularToPluralResourceType[singular];
260
+ if (!plural) {
261
+ throw new Error(`Unknown singular resource type: ${singular}`);
262
+ }
263
+ return plural;
264
+ }
265
+ }