@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,173 @@
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
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
+ import { basename, dirname, join } from 'node:path';
15
+ import { mkdir } from 'node:fs/promises';
16
+ import { DefaultContent, FolderResource, resourceNameToString, sortCards, } from './folder-resource.js';
17
+ import { Template } from '../containers/template.js';
18
+ import { writeJsonFile } from '../utils/json.js';
19
+ /**
20
+ * Template resource class.
21
+ */
22
+ export class TemplateResource extends FolderResource {
23
+ cardContainer;
24
+ cardsFolder = '';
25
+ cardsSchema = super.contentSchemaContent('cardBaseSchema');
26
+ constructor(project, name) {
27
+ super(project, name, 'templates');
28
+ this.contentSchemaId = 'templateSchema';
29
+ this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
30
+ this.initialize();
31
+ this.cardsFolder = join(this.internalFolder, 'c');
32
+ // Each template resource contains a template card container (with template cards).
33
+ this.cardContainer = new Template(this.project, {
34
+ name: basename(this.fileName),
35
+ path: dirname(this.fileName),
36
+ });
37
+ }
38
+ // When resource name changes.
39
+ async handleNameChange(existingName) {
40
+ await Promise.all([
41
+ super.updateHandleBars(existingName, this.content.name),
42
+ super.updateCalculations(existingName, this.content.name),
43
+ ]);
44
+ // Finally, write updated content.
45
+ await this.write();
46
+ }
47
+ /**
48
+ * Sets new metadata into the template object.
49
+ * @param newContent metadata content for the template.
50
+ * @throws if 'newContent' is not valid.
51
+ */
52
+ async create(newContent) {
53
+ if (!newContent) {
54
+ newContent = DefaultContent.template(resourceNameToString(this.resourceName));
55
+ }
56
+ else {
57
+ await this.validate(newContent);
58
+ }
59
+ return super.create(newContent);
60
+ }
61
+ /**
62
+ * Returns content data.
63
+ */
64
+ get data() {
65
+ return super.data;
66
+ }
67
+ /**
68
+ * Deletes file and folder that this resource is based on.
69
+ */
70
+ async delete() {
71
+ return super.delete();
72
+ }
73
+ /**
74
+ * Renames the object and the file.
75
+ * @param newName New name for the resource.
76
+ */
77
+ async rename(newName) {
78
+ const existingName = this.content.name;
79
+ await super.rename(newName);
80
+ return this.handleNameChange(existingName);
81
+ }
82
+ /**
83
+ * Shows metadata of the resource.
84
+ * @returns template metadata.
85
+ */
86
+ async show() {
87
+ const templateMetadata = (await super.show());
88
+ const container = this.templateObject();
89
+ return {
90
+ metadata: templateMetadata,
91
+ name: resourceNameToString(this.resourceName),
92
+ path: this.fileName,
93
+ numberOfCards: (await container.listCards()).length,
94
+ };
95
+ }
96
+ /**
97
+ * Returns template card container object.
98
+ * @returns template container object
99
+ */
100
+ templateObject() {
101
+ return this.cardContainer;
102
+ }
103
+ /**
104
+ * Updates template resource.
105
+ * @param key Key to modify
106
+ * @param op Operation to perform on 'key'
107
+ * @throws if key is unknown.
108
+ */
109
+ async update(key, op) {
110
+ const nameChange = key === 'name';
111
+ const existingName = this.content.name;
112
+ await super.update(key, op);
113
+ const content = { ...this.content };
114
+ if (key === 'name') {
115
+ content.name = super.handleScalar(op);
116
+ }
117
+ else if (key === 'displayName') {
118
+ content.displayName = super.handleScalar(op);
119
+ }
120
+ else if (key === 'description') {
121
+ content.description = super.handleScalar(op);
122
+ }
123
+ else if (key === 'category') {
124
+ content.category = super.handleScalar(op);
125
+ }
126
+ else {
127
+ throw new Error(`Unknown property '${key}' for Template`);
128
+ }
129
+ await super.postUpdate(content, key, op);
130
+ // Renaming this template causes that references to its name must be updated.
131
+ if (nameChange) {
132
+ await this.handleNameChange(existingName);
133
+ }
134
+ }
135
+ /**
136
+ * List where template is used.
137
+ * Always returns card key references first, then calculation references.
138
+ *
139
+ * @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
140
+ * @returns array of card keys, and calculation filenames that refer this resource.
141
+ */
142
+ async usage(cards) {
143
+ const allCards = cards ?? (await super.cards());
144
+ const [relevantCards, calculations] = await Promise.all([
145
+ super.usage(allCards),
146
+ super.calculations(),
147
+ ]);
148
+ return [...relevantCards.sort(sortCards), ...calculations];
149
+ }
150
+ /**
151
+ * Validates template.
152
+ * @throws when there are validation errors.
153
+ * @param content Content to be validated.
154
+ * @note If content is not provided, base class validation will use resource's current content.
155
+ */
156
+ async validate(content) {
157
+ return super.validate(content);
158
+ }
159
+ /**
160
+ * Create the template's cards folder.
161
+ */
162
+ async write() {
163
+ await super.write();
164
+ this.cardsFolder = join(this.internalFolder, 'c');
165
+ // Create folder for cards and put proper content schema file there
166
+ const schemaContentFile = join(this.cardsFolder, '.schema');
167
+ await mkdir(this.cardsFolder, { recursive: true });
168
+ await writeJsonFile(schemaContentFile, this.cardsSchema, {
169
+ flag: 'wx',
170
+ });
171
+ }
172
+ }
173
+ //# sourceMappingURL=template-resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-resource.js","sourceRoot":"","sources":["../../src/resources/template-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MA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,CAAC,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAChD,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,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,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QAChB,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;QAElD,mEAAmE;QACnE,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAC5D,MAAM,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACnD,MAAM,aAAa,CAAC,iBAAiB,EAAE,IAAI,CAAC,WAAW,EAAE;YACvD,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,67 @@
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 { Workflow } from '../interfaces/resource-interfaces.js';
13
+ import type { Card, Operation, Project, ResourceName } from './file-resource.js';
14
+ import { FileResource } from './folder-resource.js';
15
+ /**
16
+ * Workflow resource class.
17
+ */
18
+ export declare class WorkflowResource extends FileResource {
19
+ constructor(project: Project, name: ResourceName);
20
+ private handleNameChange;
21
+ private updateCardTypes;
22
+ /**
23
+ * Sets new metadata into the workflow object.
24
+ * @param newContent metadata content for the workflow.
25
+ * @throws if 'newContent' is not valid.
26
+ */
27
+ create(newContent?: Workflow): Promise<void>;
28
+ /**
29
+ * Returns content data.
30
+ */
31
+ get data(): Workflow;
32
+ /**
33
+ * Deletes file that this object is based on.
34
+ * If there are card types that depended on this workflow, they are now invalid.
35
+ */
36
+ delete(): Promise<void>;
37
+ /**
38
+ * Renames the object and the file.
39
+ * @param newName New name for the resource.
40
+ */
41
+ rename(newName: ResourceName): Promise<void>;
42
+ /**
43
+ * Shows metadata of the resource.
44
+ * @returns workflow metadata.
45
+ */
46
+ show(): Promise<Workflow>;
47
+ /**
48
+ * Updates workflow resource.
49
+ * @param key Key to modify
50
+ * @param op Operation to perform on 'key'
51
+ * @throws if key is unknown.
52
+ */
53
+ update<Type>(key: string, op: Operation<Type>): Promise<void>;
54
+ /**
55
+ * List where workflow is used.
56
+ * Always returns card key references first, then any resource references and finally calculation references.
57
+ *
58
+ * @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
59
+ * @returns array of card keys, resource names and calculation filenames that refer this resource.
60
+ */
61
+ usage(cards?: Card[]): Promise<string[]>;
62
+ /**
63
+ * Validates workflow.
64
+ * @throws when there are validation errors.
65
+ */
66
+ validate(content?: object): Promise<void>;
67
+ }
@@ -0,0 +1,156 @@
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 { CardTypeResource } from './card-type-resource.js';
13
+ import { DefaultContent, FileResource, resourceNameToString, sortCards, } from './folder-resource.js';
14
+ import { ResourcesFrom } from '../containers/project.js';
15
+ import { resourceName } from './file-resource.js';
16
+ /**
17
+ * Workflow resource class.
18
+ */
19
+ export class WorkflowResource extends FileResource {
20
+ constructor(project, name) {
21
+ super(project, name, 'workflows');
22
+ this.contentSchemaId = 'workflowSchema';
23
+ this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
24
+ this.initialize();
25
+ }
26
+ // When resource name changes.
27
+ async handleNameChange(existingName) {
28
+ await Promise.all([
29
+ super.updateHandleBars(existingName, this.content.name),
30
+ super.updateCalculations(existingName, this.content.name),
31
+ ]);
32
+ // Finally, write updated content.
33
+ await this.write();
34
+ }
35
+ // Update dependant card types.
36
+ async updateCardTypes(oldName) {
37
+ const cardTypes = await this.project.cardTypes(ResourcesFrom.localOnly);
38
+ const op = {
39
+ name: 'change',
40
+ target: oldName,
41
+ to: this.content.name,
42
+ };
43
+ for (const cardType of cardTypes) {
44
+ const object = new CardTypeResource(this.project, resourceName(cardType.name));
45
+ if (object.data && object.data.workflow === oldName) {
46
+ await object.update('workflow', op);
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Sets new metadata into the workflow object.
52
+ * @param newContent metadata content for the workflow.
53
+ * @throws if 'newContent' is not valid.
54
+ */
55
+ async create(newContent) {
56
+ if (!newContent) {
57
+ newContent = DefaultContent.workflow(resourceNameToString(this.resourceName));
58
+ }
59
+ else {
60
+ await this.validate(newContent);
61
+ }
62
+ return super.create(newContent);
63
+ }
64
+ /**
65
+ * Returns content data.
66
+ */
67
+ get data() {
68
+ return super.data;
69
+ }
70
+ /**
71
+ * Deletes file that this object is based on.
72
+ * If there are card types that depended on this workflow, they are now invalid.
73
+ */
74
+ async delete() {
75
+ return super.delete();
76
+ }
77
+ /**
78
+ * Renames the object and the file.
79
+ * @param newName New name for the resource.
80
+ */
81
+ async rename(newName) {
82
+ const existingName = this.content.name;
83
+ await super.rename(newName);
84
+ return this.handleNameChange(existingName);
85
+ }
86
+ /**
87
+ * Shows metadata of the resource.
88
+ * @returns workflow metadata.
89
+ */
90
+ async show() {
91
+ return super.show();
92
+ }
93
+ /**
94
+ * Updates workflow resource.
95
+ * @param key Key to modify
96
+ * @param op Operation to perform on 'key'
97
+ * @throws if key is unknown.
98
+ */
99
+ async update(key, op) {
100
+ const nameChange = key === 'name';
101
+ const existingName = this.content.name;
102
+ await super.update(key, op);
103
+ const content = { ...this.content };
104
+ if (key === 'name') {
105
+ content.name = super.handleScalar(op);
106
+ }
107
+ else if (key === 'states') {
108
+ content.states = super.handleArray(op, key, content.states);
109
+ }
110
+ else if (key === 'transitions') {
111
+ content.transitions = super.handleArray(op, key, content.transitions);
112
+ }
113
+ else {
114
+ throw new Error(`Unknown property '${key}' for Workflow`);
115
+ }
116
+ await super.postUpdate(content, key, op);
117
+ // Renaming this workflow causes that references to its name must be updated.
118
+ if (nameChange) {
119
+ await this.handleNameChange(existingName);
120
+ await this.updateCardTypes(existingName);
121
+ }
122
+ }
123
+ /**
124
+ * List where workflow is used.
125
+ * Always returns card key references first, then any resource references and finally calculation references.
126
+ *
127
+ * @param cards Optional. Check these cards for usage of this resource. If undefined, will check all cards.
128
+ * @returns array of card keys, resource names and calculation filenames that refer this resource.
129
+ */
130
+ async usage(cards) {
131
+ const resourceName = resourceNameToString(this.resourceName);
132
+ const allCards = cards ?? (await super.cards());
133
+ const cardTypes = await this.project.cardTypes(ResourcesFrom.all);
134
+ const cardTypeReferences = await Promise.all(cardTypes.map(async (cardType) => {
135
+ const metadata = await this.project.resource(cardType.name);
136
+ return metadata?.workflow === resourceName ? cardType.name : null;
137
+ }));
138
+ const [relevantCards, calculations] = await Promise.all([
139
+ super.usage(allCards),
140
+ super.calculations(),
141
+ ]);
142
+ return [
143
+ ...relevantCards.sort(sortCards),
144
+ ...cardTypeReferences.filter((name) => name !== null),
145
+ ...calculations,
146
+ ];
147
+ }
148
+ /**
149
+ * Validates workflow.
150
+ * @throws when there are validation errors.
151
+ */
152
+ validate(content) {
153
+ return super.validate(content);
154
+ }
155
+ }
156
+ //# sourceMappingURL=workflow-resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-resource.js","sourceRoot":"","sources":["../../src/resources/workflow-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAQF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAQ3D,OAAO,EACL,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAChD,YAAY,OAAgB,EAAE,IAAkB;QAC9C,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAElC,IAAI,CAAC,eAAe,GAAG,gBAAgB,CAAC;QACxC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAEtE,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED,8BAA8B;IACtB,KAAK,CAAC,gBAAgB,CAAC,YAAoB;QACjD,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,KAAK,CAAC,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YACvD,KAAK,CAAC,kBAAkB,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI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;;;OAGG;IACI,QAAQ,CAAC,OAAgB;QAC9B,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,142 @@
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
+ /**
13
+ * Types for query result
14
+ */
15
+ import type { DataType, WorkflowCategory } from '../interfaces/resource-interfaces.js';
16
+ export type LinkDirection = 'inbound' | 'outbound';
17
+ export type StatusIndicator = WorkflowCategory | 'error';
18
+ export interface CalculationLink {
19
+ displayName: string;
20
+ key: string;
21
+ linkType: string;
22
+ title: string;
23
+ linkDescription?: string;
24
+ direction: LinkDirection;
25
+ linkSource: 'user' | 'calculated';
26
+ }
27
+ export interface Notification {
28
+ key: string;
29
+ category: string;
30
+ title: string;
31
+ message: string;
32
+ }
33
+ export interface PolicyCheckCollection {
34
+ successes: {
35
+ category: string;
36
+ title: string;
37
+ }[];
38
+ failures: {
39
+ category: string;
40
+ title: string;
41
+ errorMessage: string;
42
+ fieldName?: string;
43
+ }[];
44
+ }
45
+ export interface DeniedOperationCollection {
46
+ transition: {
47
+ transitionName: string;
48
+ errorMessage: string;
49
+ }[];
50
+ move: {
51
+ errorMessage: string;
52
+ }[];
53
+ delete: {
54
+ errorMessage: string;
55
+ }[];
56
+ editField: {
57
+ fieldName: string;
58
+ errorMessage: string;
59
+ }[];
60
+ editContent: {
61
+ errorMessage: string;
62
+ }[];
63
+ }
64
+ export interface BaseResult extends Record<string, unknown> {
65
+ key: string;
66
+ labels: string[];
67
+ links: CalculationLink[];
68
+ notifications: Notification[];
69
+ policyChecks: PolicyCheckCollection;
70
+ deniedOperations: DeniedOperationCollection;
71
+ }
72
+ export interface ParseResult<T extends BaseResult> {
73
+ results: T[];
74
+ error: string | null;
75
+ }
76
+ /**
77
+ * Generic types for named queries
78
+ */
79
+ export declare const queries: readonly ["card", "onCreation", "onTransition", "tree"];
80
+ export type QueryName = (typeof queries)[number];
81
+ export type QueryMap = {
82
+ card: CardQueryResult;
83
+ onCreation: FieldsToUpdateQueryResult;
84
+ onTransition: FieldsToUpdateQueryResult;
85
+ tree: TreeQueryResult;
86
+ };
87
+ export type QueryResult<T extends QueryName> = QueryMap[T];
88
+ /**
89
+ * Define all the queries below
90
+ */
91
+ interface CardQueryResult extends BaseResult {
92
+ progress?: string;
93
+ rank: string;
94
+ title: string;
95
+ cardType: string;
96
+ workflowState: string;
97
+ lastUpdated: string;
98
+ fields?: CardQueryField[];
99
+ }
100
+ interface FieldsToUpdateQueryResult extends BaseResult {
101
+ updateFields: UpdateField[];
102
+ }
103
+ interface TreeQueryResult extends BaseResult {
104
+ progress?: string;
105
+ rank: string;
106
+ title: string;
107
+ cardType: string;
108
+ statusIndicator?: StatusIndicator;
109
+ children?: TreeQueryResult[];
110
+ }
111
+ export interface UpdateField {
112
+ card: string;
113
+ field: string;
114
+ newValue: string;
115
+ }
116
+ interface EnumValue {
117
+ index?: number;
118
+ displayValue?: string;
119
+ value: string;
120
+ }
121
+ interface ListValueItem {
122
+ index?: number;
123
+ displayValue?: string;
124
+ value: string;
125
+ }
126
+ interface CardQueryField extends BaseResult {
127
+ visibility: 'always' | 'optional';
128
+ index: number;
129
+ fieldDisplayName: string;
130
+ fieldDescription: string;
131
+ dataType: DataType;
132
+ isCalculated: boolean;
133
+ value: string | number | boolean | null | EnumValue | ListValueItem[];
134
+ enumValues: EnumDefinition[];
135
+ }
136
+ export interface EnumDefinition extends BaseResult {
137
+ index: number;
138
+ enumDisplayValue: string;
139
+ enumDescription: string;
140
+ enumValue: string;
141
+ }
142
+ export {};
@@ -0,0 +1,16 @@
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
+ /**
13
+ * Generic types for named queries
14
+ */
15
+ export const queries = ['card', 'onCreation', 'onTransition', 'tree'];
16
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/types/queries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAgEF;;GAEG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,CAAU,CAAC"}
@@ -0,0 +1,34 @@
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 { Card } from '../interfaces/project-interfaces.js';
13
+ export declare const findParentPath: (cardPath: string) => string | null;
14
+ /**
15
+ * Flattens card tree so that children are shown on same level regardless of nesting level.
16
+ * @param array card tree
17
+ * @returns flattened card tree.
18
+ */
19
+ export declare const flattenCardArray: (array: Card[]) => Card[];
20
+ /**
21
+ * Checks if given card is in some template.
22
+ * @param card card object to check
23
+ * @returns true if card exists in a template; false otherwise
24
+ */
25
+ export declare const isTemplateCard: (card: Card) => boolean;
26
+ /**
27
+ * Sorts array of cards first using prefix and then using ID.
28
+ * Prefixes are returned in alphabetical order, and then in numeric order within same prefix.
29
+ * For example, test_za1, test_aa7 and demo_aaa are sorted to: demo_aaa, test_aa7, test_za1.
30
+ * @param a First card to be sorted
31
+ * @param b Second card to be sorted
32
+ * @returns Cards ordered; first by prefixes, then by ID.
33
+ */
34
+ export declare const sortCards: (a: string, b: string) => 0 | 1 | -1;