@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,18 @@
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 { CSVRowRaw } from '../interfaces/project-interfaces.js';
13
+ /**
14
+ * Reads a CSV file and returns its content as an array of objects.
15
+ * @param file Path to the CSV file.
16
+ * @returns Array of objects. Each object represents a row in the CSV file.
17
+ */
18
+ export declare function readCsvFile(file: string): Promise<CSVRowRaw[]>;
@@ -0,0 +1,45 @@
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 { readFile } from 'fs/promises';
13
+ import { parse } from 'csv-parse/sync';
14
+ /**
15
+ * Reads a CSV file and returns its content as an array of objects.
16
+ * @param file Path to the CSV file.
17
+ * @returns Array of objects. Each object represents a row in the CSV file.
18
+ */
19
+ export async function readCsvFile(file) {
20
+ const content = await readFile(file, {
21
+ encoding: 'utf-8',
22
+ });
23
+ const records = parse(content, {
24
+ bom: true,
25
+ });
26
+ if (!Array.isArray(records) || records.length < 2) {
27
+ throw new Error('CSV file must have headers');
28
+ }
29
+ const [headers, ...data] = records;
30
+ if (!Array.isArray(headers) ||
31
+ new Set(headers).size !== headers.length ||
32
+ headers.length === 0) {
33
+ throw new Error('Error parsing header');
34
+ }
35
+ return data.map((row) => {
36
+ if (!Array.isArray(row)) {
37
+ throw new Error('Row is not an array');
38
+ }
39
+ return headers.reduce((acc, header, index) => {
40
+ acc[header] = row[index];
41
+ return acc;
42
+ }, {});
43
+ });
44
+ }
45
+ //# sourceMappingURL=csv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv.js","sourceRoot":"","sources":["../../src/utils/csv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY;IAC5C,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE;QACnC,QAAQ,EAAE,OAAO;KAClB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE;QAC7B,GAAG,EAAE,IAAI;KACV,CAAC,CAAC;IAEH,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC;IAEnC,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QACvB,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,MAAM;QACxC,OAAO,CAAC,MAAM,KAAK,CAAC,EACpB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACtB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;YAC3C,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;YACzB,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,69 @@
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 { writeFile } from 'node:fs/promises';
15
+ /**
16
+ * Works like the writeFile method, but ensures that the directory exists
17
+ * There is only one difference: This method only supports a string as the filePath
18
+ */
19
+ export declare function writeFileSafe(filePath: string, data: Parameters<typeof writeFile>[1], options?: Parameters<typeof writeFile>[2]): Promise<void>;
20
+ /**
21
+ * Copies directory content (subdirectories and files) to destination.
22
+ * Note that it won't create 'source', but copies all that is inside of 'source'.
23
+ * @param source path to start from
24
+ * @param destination path where to copy to
25
+ */
26
+ export declare function copyDir(source: string, destination: string): Promise<void>;
27
+ /**
28
+ * Delete directory.
29
+ * @param path path to be deleted
30
+ */
31
+ export declare function deleteDir(path: string): Promise<void>;
32
+ /**
33
+ * Delete file.
34
+ * @param path path to file to be deleted
35
+ * @returns true, if file was deleted; false otherwise.
36
+ */
37
+ export declare function deleteFile(path: string): Promise<boolean>;
38
+ /**
39
+ * Removes extension from filename.
40
+ * @param filename Filename
41
+ * @returns filename without extension. If there was no extension, returns the original filename.
42
+ */
43
+ export declare function stripExtension(filename: string): string;
44
+ /**
45
+ * Lists all files from a folder.
46
+ * @param path path to folder
47
+ * @param pathPrefix relative adjustment to 'path', if any; optional; by default empty.
48
+ * @param files currently collected files; optional; by default empty.
49
+ * @returns array of filenames that are in the folder or in one of its subfolders.
50
+ * @note that 'pathPrefix' and 'files' are generally only used in internal recursion.
51
+ * When calling this from code, do not pass the parameters.
52
+ */
53
+ export declare function getFilesSync(path: string, pathPrefix?: string, files?: string[]): string[];
54
+ /**
55
+ * Checks if file or folder exists.
56
+ * @param path file or folder path
57
+ * @returns true if file exists, otherwise false
58
+ */
59
+ export declare function pathExists(path: string): boolean;
60
+ /**
61
+ * Handles tilde from a path (ie. appends user home to its place).
62
+ * @param filePath Path to handle tilde from.
63
+ * @returns Path with tilde resolved.
64
+ */
65
+ export declare function resolveTilde(filePath: string): string;
66
+ /**
67
+ * Path separator RE.
68
+ */
69
+ export declare const sepRegex: RegExp;
@@ -0,0 +1,158 @@
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 { copyFile, mkdir, readdir, rm, unlink, writeFile, } from 'node:fs/promises';
15
+ import { existsSync, readdirSync } from 'node:fs';
16
+ import { dirname, join, sep } from 'node:path';
17
+ import { homedir } from 'node:os';
18
+ /**
19
+ * Works like the writeFile method, but ensures that the directory exists
20
+ * There is only one difference: This method only supports a string as the filePath
21
+ */
22
+ export async function writeFileSafe(filePath, data, options) {
23
+ const dir = dirname(filePath);
24
+ await mkdir(dir, {
25
+ recursive: true,
26
+ });
27
+ return writeFile(filePath, data, options);
28
+ }
29
+ /**
30
+ * Copies directory content (subdirectories and files) to destination.
31
+ * Note that it won't create 'source', but copies all that is inside of 'source'.
32
+ * @param source path to start from
33
+ * @param destination path where to copy to
34
+ */
35
+ export async function copyDir(source, destination) {
36
+ const entries = await readdir(source, { withFileTypes: true });
37
+ for (const entry of entries) {
38
+ const sourcePath = join(source, entry.name);
39
+ const destinationPath = join(destination, entry.name);
40
+ if (entry.isDirectory()) {
41
+ await mkdir(destinationPath, { recursive: true });
42
+ await copyDir(sourcePath, destinationPath);
43
+ }
44
+ else {
45
+ await mkdir(destination, { recursive: true });
46
+ await copyFile(sourcePath, destinationPath);
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Delete directory.
52
+ * @param path path to be deleted
53
+ */
54
+ export async function deleteDir(path) {
55
+ await rm(resolveTilde(path), { recursive: true, force: true });
56
+ }
57
+ /**
58
+ * Delete file.
59
+ * @param path path to file to be deleted
60
+ * @returns true, if file was deleted; false otherwise.
61
+ */
62
+ export async function deleteFile(path) {
63
+ if (!path) {
64
+ return false;
65
+ }
66
+ try {
67
+ await unlink(path);
68
+ }
69
+ catch {
70
+ console.error(`Cannot delete file '${path}'`);
71
+ return false;
72
+ }
73
+ return true;
74
+ }
75
+ /**
76
+ * Removes extension from filename.
77
+ * @param filename Filename
78
+ * @returns filename without extension. If there was no extension, returns the original filename.
79
+ */
80
+ export function stripExtension(filename) {
81
+ // First handle special cases. Just return the filename in all of these cases.
82
+ // 1) If the filename ends to "."" or ".." (e.g. ".cards/local/..")
83
+ const parts = filename.split(sep);
84
+ if (parts.at(parts.length - 1) === '..' ||
85
+ parts.at(parts.length - 1) === '.') {
86
+ return filename;
87
+ }
88
+ const dotLocation = filename.lastIndexOf('.');
89
+ const sepLocation = filename.lastIndexOf(sep);
90
+ // 2) If there is a dot in the filename before sep (e.g. ".cards/local")
91
+ if (dotLocation < sepLocation) {
92
+ return filename;
93
+ }
94
+ // 3) If there is a dot in filename but it is not an actual extension (e.g. "test/.filename", or ".filename")
95
+ if (dotLocation === 0 || filename.at(dotLocation - 1) === sep) {
96
+ return filename;
97
+ }
98
+ const noExtension = filename.split('.').slice(0, -1).join('.');
99
+ // if there was no extension at all, return the original file name.
100
+ return noExtension ? noExtension : filename;
101
+ }
102
+ /**
103
+ * Lists all files from a folder.
104
+ * @param path path to folder
105
+ * @param pathPrefix relative adjustment to 'path', if any; optional; by default empty.
106
+ * @param files currently collected files; optional; by default empty.
107
+ * @returns array of filenames that are in the folder or in one of its subfolders.
108
+ * @note that 'pathPrefix' and 'files' are generally only used in internal recursion.
109
+ * When calling this from code, do not pass the parameters.
110
+ */
111
+ export function getFilesSync(path, pathPrefix = '', files = []) {
112
+ try {
113
+ for (const entry of readdirSync(path, { withFileTypes: true })) {
114
+ const relativePath = pathPrefix
115
+ ? join(pathPrefix, entry.name)
116
+ : entry.name;
117
+ if (entry.isFile()) {
118
+ files.push(relativePath);
119
+ }
120
+ else if (entry.isDirectory()) {
121
+ getFilesSync(join(path, entry.name), relativePath, files);
122
+ }
123
+ }
124
+ }
125
+ catch {
126
+ // do nothing, wrong path, or no permissions to read the files
127
+ }
128
+ return files;
129
+ }
130
+ /**
131
+ * Checks if file or folder exists.
132
+ * @param path file or folder path
133
+ * @returns true if file exists, otherwise false
134
+ */
135
+ export function pathExists(path) {
136
+ path = resolveTilde(path);
137
+ return existsSync(path);
138
+ }
139
+ /**
140
+ * Handles tilde from a path (ie. appends user home to its place).
141
+ * @param filePath Path to handle tilde from.
142
+ * @returns Path with tilde resolved.
143
+ */
144
+ export function resolveTilde(filePath) {
145
+ if (!filePath || typeof filePath !== 'string') {
146
+ return '';
147
+ }
148
+ // '~/folder/path' or '~' not '~alias/folder/path'
149
+ if (filePath.startsWith('~/') || filePath === '~') {
150
+ return filePath.replace('~', homedir());
151
+ }
152
+ return filePath;
153
+ }
154
+ /**
155
+ * Path separator RE.
156
+ */
157
+ export const sepRegex = /[/\\]/;
158
+ //# sourceMappingURL=file-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-utils.js","sourceRoot":"","sources":["../../src/utils/file-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EACL,QAAQ,EACR,KAAK,EACL,OAAO,EACP,EAAE,EACF,MAAM,EACN,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAAgB,EAChB,IAAqC,EACrC,OAAyC;IAEzC,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,KAAK,CAAC,GAAG,EAAE;QACf,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;IACH,OAAO,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;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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 { type FileHandle } from 'node:fs/promises';
15
+ /**
16
+ * Handles reading of a JSON file.
17
+ * @param file file name (and path) to read.
18
+ * @returns Parsed JSON content.
19
+ * @throws if file is not found, or file is not a JSON file.
20
+ */
21
+ export declare function readJsonFileSync(file: string): any;
22
+ /**
23
+ * Handles reading of a JSON file.
24
+ * @param file file name (and path) to read.
25
+ * @returns Parsed JSON content.
26
+ * @throws if file is not found, or file is not a JSON file.
27
+ */
28
+ export declare function readJsonFile(file: string): Promise<any>;
29
+ /**
30
+ * Reads ADOC file.
31
+ * @param file file name (and path) to read.
32
+ * @returns ADOC file content.
33
+ * @throws if file is not found.
34
+ */
35
+ export declare function readADocFileSync(file: string): string;
36
+ /**
37
+ * Removes leading or trailing whitespace
38
+ * Can be passed to JSON.stringify method
39
+ * @param _ First parameter is key of object, but it is not used
40
+ * @param value Value of the json object
41
+ * @returns JSON object with values trimmed for leading or trailing white space.
42
+ */
43
+ export declare function trimReplacer(_: string, value: unknown): unknown;
44
+ /**
45
+ * Format an object with JSON.stringify
46
+ *
47
+ * The purpose of this function is to format the JSON output in a centralised function
48
+ * so that the format can be controlled in a single location.
49
+ *
50
+ * @param json JSON object to format.
51
+ * @returns Formatted JSON string
52
+ */
53
+ export declare function formatJson(json: object): string;
54
+ /**
55
+ * Writes and formats a JSON file.
56
+ * @param filename file name (and path) to write.
57
+ * @param json JSON object to format.
58
+ * @param options Optional, write options
59
+ * @return true if write succeeded, false otherwise.
60
+ */
61
+ export declare function writeJsonFile(filename: string | FileHandle, json: object, options?: object): Promise<boolean>;
@@ -0,0 +1,108 @@
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 { readFileSync } from 'node:fs';
15
+ import { readFile, writeFile } from 'node:fs/promises';
16
+ /**
17
+ * Handles reading of a JSON file.
18
+ * @param file file name (and path) to read.
19
+ * @returns Parsed JSON content.
20
+ * @throws if file is not found, or file is not a JSON file.
21
+ */
22
+ export function readJsonFileSync(file) {
23
+ try {
24
+ const raw = readFileSync(file, { flag: 'rs', encoding: 'utf-8' });
25
+ const returnValue = JSON.parse(raw);
26
+ return returnValue;
27
+ }
28
+ catch (error) {
29
+ if (error instanceof Error) {
30
+ throw new Error(`Error while handling JSON file '${file}' : ${error.message}`);
31
+ }
32
+ }
33
+ }
34
+ /**
35
+ * Handles reading of a JSON file.
36
+ * @param file file name (and path) to read.
37
+ * @returns Parsed JSON content.
38
+ * @throws if file is not found, or file is not a JSON file.
39
+ */
40
+ export async function readJsonFile(file) {
41
+ try {
42
+ const raw = await readFile(file, { encoding: 'utf-8' });
43
+ return JSON.parse(raw);
44
+ }
45
+ catch (error) {
46
+ if (error instanceof Error) {
47
+ throw new Error(`Error while handling JSON file '${file}' : ${error.message}`);
48
+ }
49
+ }
50
+ }
51
+ /**
52
+ * Reads ADOC file.
53
+ * @param file file name (and path) to read.
54
+ * @returns ADOC file content.
55
+ * @throws if file is not found.
56
+ */
57
+ export function readADocFileSync(file) {
58
+ try {
59
+ const raw = readFileSync(file, { encoding: 'utf-8' });
60
+ return raw;
61
+ }
62
+ catch {
63
+ throw new Error(`Adoc file '${file}' not found`);
64
+ }
65
+ }
66
+ /**
67
+ * Removes leading or trailing whitespace
68
+ * Can be passed to JSON.stringify method
69
+ * @param _ First parameter is key of object, but it is not used
70
+ * @param value Value of the json object
71
+ * @returns JSON object with values trimmed for leading or trailing white space.
72
+ */
73
+ export function trimReplacer(_, value) {
74
+ if (typeof value === 'string') {
75
+ return value.trim();
76
+ }
77
+ return value;
78
+ }
79
+ /**
80
+ * Format an object with JSON.stringify
81
+ *
82
+ * The purpose of this function is to format the JSON output in a centralised function
83
+ * so that the format can be controlled in a single location.
84
+ *
85
+ * @param json JSON object to format.
86
+ * @returns Formatted JSON string
87
+ */
88
+ export function formatJson(json) {
89
+ return JSON.stringify(json, trimReplacer, 4);
90
+ }
91
+ /**
92
+ * Writes and formats a JSON file.
93
+ * @param filename file name (and path) to write.
94
+ * @param json JSON object to format.
95
+ * @param options Optional, write options
96
+ * @return true if write succeeded, false otherwise.
97
+ */
98
+ export async function writeJsonFile(filename, json, options) {
99
+ try {
100
+ await writeFile(filename, formatJson(json), options);
101
+ return true;
102
+ }
103
+ catch {
104
+ // do nothing, file didn't exist, or no permissions to write
105
+ }
106
+ return false;
107
+ }
108
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAmB,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAExE;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAClE,MAAM,WAAW,GAAG,IAAI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,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAA6B,EAC7B,IAAY,EACZ,OAAgB;IAEhB,IAAI,CAAC;QACH,MAAM,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,4DAA4D;IAC9D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,59 @@
1
+ export declare const FIRST_RANK: string;
2
+ export declare const LAST_RANK: string;
3
+ export declare const EMPTY_RANK: string;
4
+ type Rank = string;
5
+ /**
6
+ * Convert a number to base 26
7
+ * @param num number to convert to base 26
8
+ * @returns the string representation of the number in base 26
9
+ */
10
+ export declare function enbase(num: number): string;
11
+ /**
12
+ * Convert a rank to a number
13
+ * @param str rank to convert to a number
14
+ * @returns the number representation of the rank
15
+ */
16
+ export declare function debase(str: string): number;
17
+ /**
18
+ * Returns the next available rank after the given rank
19
+ * @param rank rank to get the next rank after
20
+ * @returns the next available rank after the given rank
21
+ */
22
+ export declare function getRankAfter(rank: Rank): Rank;
23
+ /**
24
+ * Returns the previous available rank before the given rank
25
+ * if the rank is already the first rank, it throws an error
26
+ * @param rank rank to get the previous rank before
27
+ * @returns the previous available rank before the given rank
28
+ */
29
+ export declare function getRankBefore(rank: Rank): Rank;
30
+ /**
31
+ * Get the rank between two ranks
32
+ * Rank is a string that represents a number in base 26
33
+ * Rank must be a string of lowercase letters
34
+ * @param rank1 first rank
35
+ * @param rank2 second rank
36
+ * @returns the rank between the two ranks
37
+ */
38
+ export declare function getRankBetween(rank1: string, rank2: string): string;
39
+ /**
40
+ * Rebalance the ranks so that the distance between each rank is equal
41
+ * @param rankAmount number of ranks to rebalance
42
+ * @returns rebalanced ranks
43
+ */
44
+ export declare function rebalanceRanks(rankAmount: number): string[];
45
+ /**
46
+ * Sort items based on lexorank
47
+ * @param items items to sort
48
+ * @param rankGetter should return the lexorank of the item
49
+ * @returns sorted items
50
+ */
51
+ export declare function sortItems<T>(items: T[], rankGetter: (item: T) => string): T[];
52
+ /**
53
+ * default compare function
54
+ * @param a first string
55
+ * @param b second string
56
+ * @returns -1 if a < b, 0 if a === b, 1 if a > b
57
+ */
58
+ export declare function compare(a: string, b: string): number;
59
+ export {};