@cyberismo/data-handler 0.0.2

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 (306) hide show
  1. package/LICENSE +702 -0
  2. package/dist/card-metadata-updater.d.ts +33 -0
  3. package/dist/card-metadata-updater.js +121 -0
  4. package/dist/card-metadata-updater.js.map +1 -0
  5. package/dist/command-handler.d.ts +96 -0
  6. package/dist/command-handler.js +557 -0
  7. package/dist/command-handler.js.map +1 -0
  8. package/dist/command-manager.d.ts +43 -0
  9. package/dist/command-manager.js +73 -0
  10. package/dist/command-manager.js.map +1 -0
  11. package/dist/commands/calculate.d.ts +86 -0
  12. package/dist/commands/calculate.js +444 -0
  13. package/dist/commands/calculate.js.map +1 -0
  14. package/dist/commands/create.d.ts +114 -0
  15. package/dist/commands/create.js +389 -0
  16. package/dist/commands/create.js.map +1 -0
  17. package/dist/commands/edit.d.ts +37 -0
  18. package/dist/commands/edit.js +99 -0
  19. package/dist/commands/edit.js.map +1 -0
  20. package/dist/commands/export-site.d.ts +45 -0
  21. package/dist/commands/export-site.js +301 -0
  22. package/dist/commands/export-site.js.map +1 -0
  23. package/dist/commands/export.d.ts +53 -0
  24. package/dist/commands/export.js +251 -0
  25. package/dist/commands/export.js.map +1 -0
  26. package/dist/commands/import.d.ts +53 -0
  27. package/dist/commands/import.js +133 -0
  28. package/dist/commands/import.js.map +1 -0
  29. package/dist/commands/index.d.ts +26 -0
  30. package/dist/commands/index.js +27 -0
  31. package/dist/commands/index.js.map +1 -0
  32. package/dist/commands/move.d.ts +55 -0
  33. package/dist/commands/move.js +341 -0
  34. package/dist/commands/move.js.map +1 -0
  35. package/dist/commands/remove.d.ts +38 -0
  36. package/dist/commands/remove.js +192 -0
  37. package/dist/commands/remove.js.map +1 -0
  38. package/dist/commands/rename.d.ts +46 -0
  39. package/dist/commands/rename.js +289 -0
  40. package/dist/commands/rename.js.map +1 -0
  41. package/dist/commands/show.d.ts +124 -0
  42. package/dist/commands/show.js +345 -0
  43. package/dist/commands/show.js.map +1 -0
  44. package/dist/commands/transition.d.ts +27 -0
  45. package/dist/commands/transition.js +92 -0
  46. package/dist/commands/transition.js.map +1 -0
  47. package/dist/commands/update.d.ts +29 -0
  48. package/dist/commands/update.js +64 -0
  49. package/dist/commands/update.js.map +1 -0
  50. package/dist/commands/validate.d.ts +143 -0
  51. package/dist/commands/validate.js +689 -0
  52. package/dist/commands/validate.js.map +1 -0
  53. package/dist/containers/card-container.d.ts +44 -0
  54. package/dist/containers/card-container.js +282 -0
  55. package/dist/containers/card-container.js.map +1 -0
  56. package/dist/containers/project/project-paths.d.ts +46 -0
  57. package/dist/containers/project/project-paths.js +105 -0
  58. package/dist/containers/project/project-paths.js.map +1 -0
  59. package/dist/containers/project/resource-collector.d.ts +86 -0
  60. package/dist/containers/project/resource-collector.js +331 -0
  61. package/dist/containers/project/resource-collector.js.map +1 -0
  62. package/dist/containers/project.d.ts +351 -0
  63. package/dist/containers/project.js +896 -0
  64. package/dist/containers/project.js.map +1 -0
  65. package/dist/containers/template.d.ts +108 -0
  66. package/dist/containers/template.js +433 -0
  67. package/dist/containers/template.js.map +1 -0
  68. package/dist/exceptions/index.d.ts +19 -0
  69. package/dist/exceptions/index.js +26 -0
  70. package/dist/exceptions/index.js.map +1 -0
  71. package/dist/index.d.ts +16 -0
  72. package/dist/index.js +15 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/interfaces/adoc.d.ts +12 -0
  75. package/dist/interfaces/adoc.js +13 -0
  76. package/dist/interfaces/adoc.js.map +1 -0
  77. package/dist/interfaces/macros.d.ts +45 -0
  78. package/dist/interfaces/macros.js +13 -0
  79. package/dist/interfaces/macros.js.map +1 -0
  80. package/dist/interfaces/project-interfaces.d.ts +121 -0
  81. package/dist/interfaces/project-interfaces.js +21 -0
  82. package/dist/interfaces/project-interfaces.js.map +1 -0
  83. package/dist/interfaces/request-status-interfaces.d.ts +28 -0
  84. package/dist/interfaces/request-status-interfaces.js +20 -0
  85. package/dist/interfaces/request-status-interfaces.js.map +1 -0
  86. package/dist/interfaces/resource-interfaces.d.ts +117 -0
  87. package/dist/interfaces/resource-interfaces.js +20 -0
  88. package/dist/interfaces/resource-interfaces.js.map +1 -0
  89. package/dist/macros/base-macro.d.ts +31 -0
  90. package/dist/macros/base-macro.js +126 -0
  91. package/dist/macros/base-macro.js.map +1 -0
  92. package/dist/macros/common.d.ts +17 -0
  93. package/dist/macros/common.js +23 -0
  94. package/dist/macros/common.js.map +1 -0
  95. package/dist/macros/createCards/index.d.ts +36 -0
  96. package/dist/macros/createCards/index.js +35 -0
  97. package/dist/macros/createCards/index.js.map +1 -0
  98. package/dist/macros/createCards/metadata.d.ts +14 -0
  99. package/dist/macros/createCards/metadata.js +18 -0
  100. package/dist/macros/createCards/metadata.js.map +1 -0
  101. package/dist/macros/graph/index.d.ts +29 -0
  102. package/dist/macros/graph/index.js +91 -0
  103. package/dist/macros/graph/index.js.map +1 -0
  104. package/dist/macros/graph/metadata.d.ts +14 -0
  105. package/dist/macros/graph/metadata.js +18 -0
  106. package/dist/macros/graph/metadata.js.map +1 -0
  107. package/dist/macros/index.d.ts +93 -0
  108. package/dist/macros/index.js +237 -0
  109. package/dist/macros/index.js.map +1 -0
  110. package/dist/macros/report/index.d.ts +26 -0
  111. package/dist/macros/report/index.js +70 -0
  112. package/dist/macros/report/index.js.map +1 -0
  113. package/dist/macros/report/metadata.d.ts +14 -0
  114. package/dist/macros/report/metadata.js +18 -0
  115. package/dist/macros/report/metadata.js.map +1 -0
  116. package/dist/macros/scoreCard/index.d.ts +30 -0
  117. package/dist/macros/scoreCard/index.js +38 -0
  118. package/dist/macros/scoreCard/index.js.map +1 -0
  119. package/dist/macros/scoreCard/metadata.d.ts +14 -0
  120. package/dist/macros/scoreCard/metadata.js +18 -0
  121. package/dist/macros/scoreCard/metadata.js.map +1 -0
  122. package/dist/macros/task-queue.d.ts +46 -0
  123. package/dist/macros/task-queue.js +69 -0
  124. package/dist/macros/task-queue.js.map +1 -0
  125. package/dist/module-manager.d.ts +62 -0
  126. package/dist/module-manager.js +350 -0
  127. package/dist/module-manager.js.map +1 -0
  128. package/dist/permissions/action-guard.d.ts +28 -0
  129. package/dist/permissions/action-guard.js +61 -0
  130. package/dist/permissions/action-guard.js.map +1 -0
  131. package/dist/project-settings.d.ts +42 -0
  132. package/dist/project-settings.js +120 -0
  133. package/dist/project-settings.js.map +1 -0
  134. package/dist/resources/array-handler.d.ts +28 -0
  135. package/dist/resources/array-handler.js +116 -0
  136. package/dist/resources/array-handler.js.map +1 -0
  137. package/dist/resources/card-type-resource.d.ts +72 -0
  138. package/dist/resources/card-type-resource.js +334 -0
  139. package/dist/resources/card-type-resource.js.map +1 -0
  140. package/dist/resources/create-defaults.d.ts +81 -0
  141. package/dist/resources/create-defaults.js +184 -0
  142. package/dist/resources/create-defaults.js.map +1 -0
  143. package/dist/resources/field-type-resource.d.ts +88 -0
  144. package/dist/resources/field-type-resource.js +411 -0
  145. package/dist/resources/field-type-resource.js.map +1 -0
  146. package/dist/resources/file-resource.d.ts +50 -0
  147. package/dist/resources/file-resource.js +301 -0
  148. package/dist/resources/file-resource.js.map +1 -0
  149. package/dist/resources/folder-resource.d.ts +66 -0
  150. package/dist/resources/folder-resource.js +100 -0
  151. package/dist/resources/folder-resource.js.map +1 -0
  152. package/dist/resources/graph-model-resource.d.ts +78 -0
  153. package/dist/resources/graph-model-resource.js +164 -0
  154. package/dist/resources/graph-model-resource.js.map +1 -0
  155. package/dist/resources/graph-view-resource.d.ts +78 -0
  156. package/dist/resources/graph-view-resource.js +163 -0
  157. package/dist/resources/graph-view-resource.js.map +1 -0
  158. package/dist/resources/link-type-resource.d.ts +62 -0
  159. package/dist/resources/link-type-resource.js +150 -0
  160. package/dist/resources/link-type-resource.js.map +1 -0
  161. package/dist/resources/report-resource.d.ts +77 -0
  162. package/dist/resources/report-resource.js +171 -0
  163. package/dist/resources/report-resource.js.map +1 -0
  164. package/dist/resources/resource-object.d.ts +108 -0
  165. package/dist/resources/resource-object.js +147 -0
  166. package/dist/resources/resource-object.js.map +1 -0
  167. package/dist/resources/template-resource.d.ts +82 -0
  168. package/dist/resources/template-resource.js +173 -0
  169. package/dist/resources/template-resource.js.map +1 -0
  170. package/dist/resources/workflow-resource.d.ts +67 -0
  171. package/dist/resources/workflow-resource.js +156 -0
  172. package/dist/resources/workflow-resource.js.map +1 -0
  173. package/dist/types/queries.d.ts +142 -0
  174. package/dist/types/queries.js +16 -0
  175. package/dist/types/queries.js.map +1 -0
  176. package/dist/utils/card-utils.d.ts +34 -0
  177. package/dist/utils/card-utils.js +78 -0
  178. package/dist/utils/card-utils.js.map +1 -0
  179. package/dist/utils/clingo-fact-builder.d.ts +58 -0
  180. package/dist/utils/clingo-fact-builder.js +126 -0
  181. package/dist/utils/clingo-fact-builder.js.map +1 -0
  182. package/dist/utils/clingo-facts.d.ts +97 -0
  183. package/dist/utils/clingo-facts.js +352 -0
  184. package/dist/utils/clingo-facts.js.map +1 -0
  185. package/dist/utils/clingo-parser.d.ts +59 -0
  186. package/dist/utils/clingo-parser.js +403 -0
  187. package/dist/utils/clingo-parser.js.map +1 -0
  188. package/dist/utils/clingo-program-builder.d.ts +39 -0
  189. package/dist/utils/clingo-program-builder.js +57 -0
  190. package/dist/utils/clingo-program-builder.js.map +1 -0
  191. package/dist/utils/common-utils.d.ts +24 -0
  192. package/dist/utils/common-utils.js +47 -0
  193. package/dist/utils/common-utils.js.map +1 -0
  194. package/dist/utils/constants.d.ts +18 -0
  195. package/dist/utils/constants.js +27 -0
  196. package/dist/utils/constants.js.map +1 -0
  197. package/dist/utils/csv.d.ts +18 -0
  198. package/dist/utils/csv.js +45 -0
  199. package/dist/utils/csv.js.map +1 -0
  200. package/dist/utils/file-utils.d.ts +69 -0
  201. package/dist/utils/file-utils.js +158 -0
  202. package/dist/utils/file-utils.js.map +1 -0
  203. package/dist/utils/json.d.ts +61 -0
  204. package/dist/utils/json.js +108 -0
  205. package/dist/utils/json.js.map +1 -0
  206. package/dist/utils/lexorank.d.ts +59 -0
  207. package/dist/utils/lexorank.js +159 -0
  208. package/dist/utils/lexorank.js.map +1 -0
  209. package/dist/utils/log-utils.d.ts +40 -0
  210. package/dist/utils/log-utils.js +109 -0
  211. package/dist/utils/log-utils.js.map +1 -0
  212. package/dist/utils/random.d.ts +19 -0
  213. package/dist/utils/random.js +34 -0
  214. package/dist/utils/random.js.map +1 -0
  215. package/dist/utils/resource-utils.d.ts +45 -0
  216. package/dist/utils/resource-utils.js +137 -0
  217. package/dist/utils/resource-utils.js.map +1 -0
  218. package/dist/utils/sanitize-svg.d.ts +18 -0
  219. package/dist/utils/sanitize-svg.js +38 -0
  220. package/dist/utils/sanitize-svg.js.map +1 -0
  221. package/dist/utils/user-preferences.d.ts +64 -0
  222. package/dist/utils/user-preferences.js +106 -0
  223. package/dist/utils/user-preferences.js.map +1 -0
  224. package/dist/utils/validate.d.ts +26 -0
  225. package/dist/utils/validate.js +53 -0
  226. package/dist/utils/validate.js.map +1 -0
  227. package/dist/utils/value-utils.d.ts +58 -0
  228. package/dist/utils/value-utils.js +181 -0
  229. package/dist/utils/value-utils.js.map +1 -0
  230. package/package.json +67 -0
  231. package/src/card-metadata-updater.ts +182 -0
  232. package/src/command-handler.ts +686 -0
  233. package/src/command-manager.ts +99 -0
  234. package/src/commands/calculate.ts +591 -0
  235. package/src/commands/create.ts +559 -0
  236. package/src/commands/edit.ts +123 -0
  237. package/src/commands/export-site.ts +356 -0
  238. package/src/commands/export.ts +315 -0
  239. package/src/commands/import.ts +169 -0
  240. package/src/commands/index.ts +42 -0
  241. package/src/commands/move.ts +451 -0
  242. package/src/commands/remove.ts +244 -0
  243. package/src/commands/rename.ts +378 -0
  244. package/src/commands/show.ts +442 -0
  245. package/src/commands/transition.ts +127 -0
  246. package/src/commands/update.ts +76 -0
  247. package/src/commands/validate.ts +962 -0
  248. package/src/containers/card-container.ts +378 -0
  249. package/src/containers/project/project-paths.ts +127 -0
  250. package/src/containers/project/resource-collector.ts +379 -0
  251. package/src/containers/project.ts +1135 -0
  252. package/src/containers/template.ts +573 -0
  253. package/src/exceptions/index.ts +29 -0
  254. package/src/index.ts +33 -0
  255. package/src/interfaces/adoc.ts +18 -0
  256. package/src/interfaces/macros.ts +54 -0
  257. package/src/interfaces/project-interfaces.ts +208 -0
  258. package/src/interfaces/request-status-interfaces.ts +30 -0
  259. package/src/interfaces/resource-interfaces.ts +179 -0
  260. package/src/macros/base-macro.ts +176 -0
  261. package/src/macros/common.ts +24 -0
  262. package/src/macros/createCards/index.ts +57 -0
  263. package/src/macros/createCards/metadata.ts +21 -0
  264. package/src/macros/graph/index.ts +130 -0
  265. package/src/macros/graph/metadata.ts +21 -0
  266. package/src/macros/index.ts +321 -0
  267. package/src/macros/report/index.ts +88 -0
  268. package/src/macros/report/metadata.ts +21 -0
  269. package/src/macros/scoreCard/index.ts +55 -0
  270. package/src/macros/scoreCard/metadata.ts +21 -0
  271. package/src/macros/task-queue.ts +79 -0
  272. package/src/module-manager.ts +443 -0
  273. package/src/permissions/action-guard.ts +77 -0
  274. package/src/project-settings.ts +140 -0
  275. package/src/resources/array-handler.ts +141 -0
  276. package/src/resources/card-type-resource.ts +455 -0
  277. package/src/resources/create-defaults.ts +216 -0
  278. package/src/resources/field-type-resource.ts +533 -0
  279. package/src/resources/file-resource.ts +433 -0
  280. package/src/resources/folder-resource.ts +140 -0
  281. package/src/resources/graph-model-resource.ts +205 -0
  282. package/src/resources/graph-view-resource.ts +199 -0
  283. package/src/resources/link-type-resource.ts +191 -0
  284. package/src/resources/report-resource.ts +224 -0
  285. package/src/resources/resource-object.ts +246 -0
  286. package/src/resources/template-resource.ts +210 -0
  287. package/src/resources/workflow-resource.ts +205 -0
  288. package/src/types/queries.ts +149 -0
  289. package/src/utils/card-utils.ts +83 -0
  290. package/src/utils/clingo-fact-builder.ts +167 -0
  291. package/src/utils/clingo-facts.ts +550 -0
  292. package/src/utils/clingo-parser.ts +519 -0
  293. package/src/utils/clingo-program-builder.ts +71 -0
  294. package/src/utils/common-utils.ts +54 -0
  295. package/src/utils/constants.ts +32 -0
  296. package/src/utils/csv.ts +53 -0
  297. package/src/utils/file-utils.ts +182 -0
  298. package/src/utils/json.ts +118 -0
  299. package/src/utils/lexorank.ts +180 -0
  300. package/src/utils/log-utils.ts +127 -0
  301. package/src/utils/random.ts +37 -0
  302. package/src/utils/resource-utils.ts +180 -0
  303. package/src/utils/sanitize-svg.ts +46 -0
  304. package/src/utils/user-preferences.ts +126 -0
  305. package/src/utils/validate.ts +66 -0
  306. package/src/utils/value-utils.ts +189 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+ import { writeJsonFile as atomicWrite } from 'write-json-file';
14
+ import { readJsonFileSync } from './utils/json.js';
15
+ import { Validate } from './commands/index.js';
16
+ /**
17
+ * Represents Project's cardsConfig.json file.
18
+ */
19
+ export class ProjectConfiguration {
20
+ static instance;
21
+ name;
22
+ cardKeyPrefix;
23
+ modules;
24
+ settingPath;
25
+ constructor(path) {
26
+ this.name = '';
27
+ this.settingPath = path;
28
+ this.cardKeyPrefix = '';
29
+ this.modules = [];
30
+ this.readSettings();
31
+ }
32
+ // Persists configuration file to disk.
33
+ async save() {
34
+ if (this.cardKeyPrefix === '') {
35
+ throw new Error('wrong configuration');
36
+ }
37
+ try {
38
+ await atomicWrite(this.settingPath, this.toJSON(), { indent: 4 });
39
+ }
40
+ catch (error) {
41
+ if (error instanceof Error) {
42
+ console.error(error.message);
43
+ }
44
+ }
45
+ }
46
+ // Sets configuration values from file.
47
+ readSettings() {
48
+ let settings;
49
+ try {
50
+ settings = readJsonFileSync(this.settingPath);
51
+ }
52
+ catch {
53
+ throw new Error(`Invalid path '${this.settingPath}' to configuration file`);
54
+ }
55
+ if (!settings) {
56
+ throw new Error(`Invalid path '${this.settingPath}' to configuration file`);
57
+ }
58
+ const valid = Object.prototype.hasOwnProperty.call(settings, 'cardKeyPrefix') &&
59
+ Object.prototype.hasOwnProperty.call(settings, 'name');
60
+ if (valid) {
61
+ this.cardKeyPrefix = settings.cardKeyPrefix;
62
+ this.name = settings.name;
63
+ this.modules = settings.modules || [];
64
+ }
65
+ else {
66
+ throw new Error(`Invalid configuration file '${this.settingPath}'`);
67
+ }
68
+ }
69
+ // Return the configuration as object
70
+ toJSON() {
71
+ return {
72
+ cardKeyPrefix: this.cardKeyPrefix,
73
+ name: this.name,
74
+ modules: this.modules,
75
+ };
76
+ }
77
+ /**
78
+ * Adds new module to imported modules property.
79
+ * @param module Module to add as dependency
80
+ */
81
+ async addModule(module) {
82
+ if (!module) {
83
+ throw new Error(`Module must have 'name' and 'url'`);
84
+ }
85
+ const exists = this.modules.find((item) => item.name === module.name);
86
+ if (exists) {
87
+ throw new Error(`Module '${module.name}' already imported`);
88
+ }
89
+ this.modules.push(module);
90
+ return this.save();
91
+ }
92
+ /**
93
+ * Removes module from imported modules property.
94
+ * @param moduleName Name of the module to remove.
95
+ */
96
+ async removeModule(moduleName) {
97
+ if (!moduleName) {
98
+ throw new Error(`Name must be provided to remove module`);
99
+ }
100
+ const exists = this.modules.find((item) => item.name === moduleName);
101
+ if (!exists) {
102
+ throw new Error(`Module '${moduleName}' is not imported`);
103
+ }
104
+ this.modules = this.modules.filter((item) => item.name !== moduleName);
105
+ return this.save();
106
+ }
107
+ /**
108
+ * Changes project prefix.
109
+ * @param newPrefix New prefix to use in the project
110
+ */
111
+ async setCardPrefix(newPrefix) {
112
+ const isValid = Validate.validatePrefix(newPrefix);
113
+ if (isValid) {
114
+ this.cardKeyPrefix = newPrefix;
115
+ return this.save();
116
+ }
117
+ throw new Error(`Prefix '${newPrefix}' is not valid prefix. Prefix should be in lowercase and contain letters from a to z (max length 10).`);
118
+ }
119
+ }
120
+ //# sourceMappingURL=project-settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-settings.js","sourceRoot":"","sources":["../src/project-settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAEF,OAAO,EAAE,aAAa,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAM/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACvB,MAAM,CAAC,QAAQ,CAAuB;IAE9C,IAAI,CAAS;IACb,aAAa,CAAS;IACtB,OAAO,CAAkB;IACjB,WAAW,CAAS;IAE5B,YAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,uCAAuC;IAChC,KAAK,CAAC,IAAI;QACf,IAAI,IAAI,CAAC,aAAa,KAAK,EAAE,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QACD,IAAI,CAAC;YACH,MAAM,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;QACpE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,OAAO,CAAC,KAAK,CA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;QACrB,CAAC;QACD,MAAM,IAAI,KAAK,CACb,WAAW,SAAS,uGAAuG,CAC5H,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
6
+
7
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
8
+
9
+ You should have received a copy of the GNU Affero General Public
10
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
11
+ */
12
+ import type { Operation } from './resource-object.js';
13
+ export declare class ArrayHandler<T> {
14
+ private isValidIndex;
15
+ private tryParseJSON;
16
+ private findItemIndex;
17
+ private handleAdd;
18
+ private handleChange;
19
+ private handleRank;
20
+ private handleRemove;
21
+ /**
22
+ * Handles operation to an array.
23
+ * @param operation Operation to perform on array.
24
+ * @param array Array to operate on.
25
+ * @returns Changed array after the operation.
26
+ */
27
+ handleArray(operation: Operation<T>, array: T[]): T[];
28
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
6
+
7
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
8
+
9
+ You should have received a copy of the GNU Affero General Public
10
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
11
+ */
12
+ import { deepCompare } from '../utils/common-utils.js';
13
+ export class ArrayHandler {
14
+ isValidIndex(index, array) {
15
+ return index >= 0 && index < array.length;
16
+ }
17
+ tryParseJSON(value) {
18
+ if (typeof value !== 'string')
19
+ return value;
20
+ try {
21
+ const trimmed = value.trim();
22
+ if (trimmed.startsWith('[') || trimmed.startsWith('{')) {
23
+ return JSON.parse(trimmed);
24
+ }
25
+ }
26
+ catch {
27
+ // Ignore parse errors
28
+ }
29
+ return value;
30
+ }
31
+ findItemIndex(item, array) {
32
+ if (!array)
33
+ return -1;
34
+ let index = array.findIndex((element) => {
35
+ return deepCompare(element, item);
36
+ });
37
+ // Special case 1: change was provided with object that has 'name' only (not full object)
38
+ if (index === -1) {
39
+ index = array.findIndex((element) => {
40
+ const nameOnlyElement = { name: element['name'] };
41
+ if (nameOnlyElement.name === undefined)
42
+ return false;
43
+ return deepCompare(nameOnlyElement, item);
44
+ });
45
+ }
46
+ // Special case 2: change was provided with string (name) only. Try to find with string as 'name'.
47
+ if (index === -1) {
48
+ for (const element of array) {
49
+ if (element['name'] === item) {
50
+ index = array.indexOf(element);
51
+ break;
52
+ }
53
+ }
54
+ }
55
+ return index;
56
+ }
57
+ handleAdd(operation, array) {
58
+ const parsedItem = this.tryParseJSON(operation.target);
59
+ const index = this.findItemIndex(parsedItem, array);
60
+ if (index !== -1) {
61
+ throw new Error(`Item '${JSON.stringify(parsedItem)}' already exists`);
62
+ }
63
+ return [...array, parsedItem];
64
+ }
65
+ handleChange(operation, array) {
66
+ const { target, to } = operation;
67
+ const parsedTarget = this.tryParseJSON(operation.target);
68
+ const targetIndex = this.findItemIndex(parsedTarget, array);
69
+ if (targetIndex === -1) {
70
+ throw new Error(`Item '${JSON.stringify(target)}' not found`);
71
+ }
72
+ const parsedTo = this.tryParseJSON(to);
73
+ if (typeof to === 'string' && (to.startsWith('[') || to.startsWith('{'))) {
74
+ return parsedTo;
75
+ }
76
+ return array.map((item) => deepCompare(item, target) ? parsedTo : item);
77
+ }
78
+ handleRank(operation, array) {
79
+ const { target, newIndex } = operation;
80
+ const fromIndex = this.findItemIndex(target, array);
81
+ if (fromIndex === -1) {
82
+ throw new Error(`Item '${JSON.stringify(target)}' not found`);
83
+ }
84
+ if (!this.isValidIndex(newIndex, array)) {
85
+ throw new Error(`Invalid target index: ${newIndex}`);
86
+ }
87
+ const result = [...array];
88
+ const [removed] = result.splice(fromIndex, 1);
89
+ result.splice(newIndex, 0, removed);
90
+ return result;
91
+ }
92
+ handleRemove(operation, array) {
93
+ const index = this.findItemIndex(operation.target, array);
94
+ if (index === -1) {
95
+ throw new Error(`Item '${JSON.stringify(operation.target)}' not found`);
96
+ }
97
+ return array.filter((_, i) => i !== index);
98
+ }
99
+ /**
100
+ * Handles operation to an array.
101
+ * @param operation Operation to perform on array.
102
+ * @param array Array to operate on.
103
+ * @returns Changed array after the operation.
104
+ */
105
+ handleArray(operation, array) {
106
+ const handlers = {
107
+ add: (op) => this.handleAdd(op, array),
108
+ change: (op) => this.handleChange(op, array),
109
+ rank: (op) => this.handleRank(op, array),
110
+ remove: (op) => this.handleRemove(op, array),
111
+ };
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ return handlers[operation.name](operation);
114
+ }
115
+ }
116
+ //# sourceMappingURL=array-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-handler.js","sourceRoot":"","sources":["../../src/resources/array-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAUvD,MAAM,OAAO,YAAY;IACf,YAAY,CAAC,KAAa,EAAE,KAAU;QAC5C,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5C,CAAC;IAEO,YAAY,CAAI,KAAQ;QAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC5C,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;YAC7B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACvD,OAAO,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AC,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC;YAChE,IAAI,EAAE,CAAC,EAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC;YAC1D,MAAM,EAAE,CAAC,EAAsB,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC;SACjE,CAAC;QAEF,8DAA8D;QAC9D,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,SAAgB,CAAC,CAAC;IACpD,CAAC;CACF"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
6
+
7
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
8
+
9
+ You should have received a copy of the GNU Affero General Public
10
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
11
+ */
12
+ import type { CardType } from '../interfaces/resource-interfaces.js';
13
+ import { type Card, FileResource, type Operation, type Project, type ResourceName } from './file-resource.js';
14
+ /**
15
+ * Card type resource class.
16
+ */
17
+ export declare class CardTypeResource extends FileResource {
18
+ constructor(project: Project, name: ResourceName);
19
+ private cardsWithCardType;
20
+ private collectCards;
21
+ private handleCustomFieldsChange;
22
+ private handleAddNewField;
23
+ private handleNameChange;
24
+ private handleRemoveField;
25
+ private removeValue;
26
+ private relevantLinkTypes;
27
+ private removeValueFromOtherArrays;
28
+ private setContainerValues;
29
+ private updateLinkTypes;
30
+ private updateCardMetadata;
31
+ /**
32
+ * Creates a new card type object. Base class writes the object to disk automatically.
33
+ * @param workflowName Workflow name that this card type uses.
34
+ */
35
+ createCardType(workflowName: string): Promise<void>;
36
+ /**
37
+ * Returns content data.
38
+ */
39
+ get data(): CardType;
40
+ /**
41
+ * Deletes file(s) from disk and clears out the memory resident object.
42
+ */
43
+ delete(): Promise<void>;
44
+ /**
45
+ * Renames resource metadata file and renames memory resident object 'name'.
46
+ * @param newName New name for the resource.
47
+ */
48
+ rename(newName: ResourceName): Promise<void>;
49
+ /**
50
+ * Shows metadata of the resource.
51
+ * @returns card type metadata.
52
+ */
53
+ show(): Promise<CardType>;
54
+ /**
55
+ * Updates card type resource.
56
+ * @param key Key to modify
57
+ * @param op Operation to perform on 'key'
58
+ */
59
+ update<Type>(key: string, op: Operation<Type>): Promise<void>;
60
+ /**
61
+ * List where card type is used. This includes card metadata, card content, calculations and link type resources.
62
+ * Always returns card key references first, then any resource references and finally calculation references.
63
+ *
64
+ * @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
65
+ * @returns array of card keys, resource names and calculation filenames that refer this resource.
66
+ */
67
+ usage(cards?: Card[]): Promise<string[]>;
68
+ /**
69
+ * Validates the resource. If object is invalid, throws.
70
+ */
71
+ validate(content?: object): Promise<void>;
72
+ }