@cyberismo/data-handler 0.0.12 → 0.0.14

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 (130) hide show
  1. package/dist/command-handler.d.ts +24 -42
  2. package/dist/command-handler.js +33 -26
  3. package/dist/command-handler.js.map +1 -1
  4. package/dist/commands/create.d.ts +3 -3
  5. package/dist/commands/create.js +7 -22
  6. package/dist/commands/create.js.map +1 -1
  7. package/dist/commands/edit.d.ts +12 -11
  8. package/dist/commands/edit.js +41 -16
  9. package/dist/commands/edit.js.map +1 -1
  10. package/dist/commands/fetch.js +2 -1
  11. package/dist/commands/fetch.js.map +1 -1
  12. package/dist/commands/import.js +2 -2
  13. package/dist/commands/import.js.map +1 -1
  14. package/dist/commands/remove.js +6 -5
  15. package/dist/commands/remove.js.map +1 -1
  16. package/dist/commands/rename.d.ts +1 -0
  17. package/dist/commands/rename.js +11 -0
  18. package/dist/commands/rename.js.map +1 -1
  19. package/dist/commands/show.d.ts +4 -0
  20. package/dist/commands/show.js +6 -12
  21. package/dist/commands/show.js.map +1 -1
  22. package/dist/commands/update.d.ts +11 -1
  23. package/dist/commands/update.js +14 -2
  24. package/dist/commands/update.js.map +1 -1
  25. package/dist/commands/validate.d.ts +2 -1
  26. package/dist/commands/validate.js +4 -3
  27. package/dist/commands/validate.js.map +1 -1
  28. package/dist/containers/card-container.js +1 -1
  29. package/dist/containers/card-container.js.map +1 -1
  30. package/dist/containers/project/calculation-engine.js +18 -18
  31. package/dist/containers/project/calculation-engine.js.map +1 -1
  32. package/dist/containers/project.d.ts +2 -1
  33. package/dist/containers/project.js +5 -1
  34. package/dist/containers/project.js.map +1 -1
  35. package/dist/index.d.ts +4 -2
  36. package/dist/index.js.map +1 -1
  37. package/dist/interfaces/command-options.d.ts +81 -0
  38. package/dist/interfaces/command-options.js +14 -0
  39. package/dist/interfaces/command-options.js.map +1 -0
  40. package/dist/interfaces/folder-content-interfaces.d.ts +56 -0
  41. package/dist/interfaces/folder-content-interfaces.js +47 -0
  42. package/dist/interfaces/folder-content-interfaces.js.map +1 -0
  43. package/dist/interfaces/project-interfaces.d.ts +11 -9
  44. package/dist/interfaces/project-interfaces.js +10 -8
  45. package/dist/interfaces/project-interfaces.js.map +1 -1
  46. package/dist/interfaces/resource-interfaces.d.ts +37 -10
  47. package/dist/interfaces/resource-interfaces.js.map +1 -1
  48. package/dist/macros/report/index.js +4 -4
  49. package/dist/macros/report/index.js.map +1 -1
  50. package/dist/resources/calculation-resource.d.ts +71 -0
  51. package/dist/resources/calculation-resource.js +130 -0
  52. package/dist/resources/calculation-resource.js.map +1 -0
  53. package/dist/resources/card-type-resource.js +11 -5
  54. package/dist/resources/card-type-resource.js.map +1 -1
  55. package/dist/resources/create-defaults.d.ts +13 -6
  56. package/dist/resources/create-defaults.js +19 -5
  57. package/dist/resources/create-defaults.js.map +1 -1
  58. package/dist/resources/field-type-resource.js +1 -1
  59. package/dist/resources/field-type-resource.js.map +1 -1
  60. package/dist/resources/file-resource.js +9 -3
  61. package/dist/resources/file-resource.js.map +1 -1
  62. package/dist/resources/folder-resource.d.ts +38 -10
  63. package/dist/resources/folder-resource.js +108 -12
  64. package/dist/resources/folder-resource.js.map +1 -1
  65. package/dist/resources/graph-model-resource.d.ts +7 -4
  66. package/dist/resources/graph-model-resource.js +12 -25
  67. package/dist/resources/graph-model-resource.js.map +1 -1
  68. package/dist/resources/graph-view-resource.d.ts +7 -4
  69. package/dist/resources/graph-view-resource.js +12 -26
  70. package/dist/resources/graph-view-resource.js.map +1 -1
  71. package/dist/resources/link-type-resource.js +1 -1
  72. package/dist/resources/link-type-resource.js.map +1 -1
  73. package/dist/resources/report-resource.d.ts +14 -10
  74. package/dist/resources/report-resource.js +41 -45
  75. package/dist/resources/report-resource.js.map +1 -1
  76. package/dist/resources/resource-object.d.ts +7 -0
  77. package/dist/resources/resource-object.js +14 -2
  78. package/dist/resources/resource-object.js.map +1 -1
  79. package/dist/resources/template-resource.d.ts +5 -1
  80. package/dist/resources/template-resource.js +12 -7
  81. package/dist/resources/template-resource.js.map +1 -1
  82. package/dist/resources/workflow-resource.js +6 -0
  83. package/dist/resources/workflow-resource.js.map +1 -1
  84. package/dist/utils/constants.js +1 -0
  85. package/dist/utils/constants.js.map +1 -1
  86. package/dist/utils/error-utils.d.ts +34 -0
  87. package/dist/utils/error-utils.js +56 -0
  88. package/dist/utils/error-utils.js.map +1 -0
  89. package/dist/utils/log-utils.d.ts +0 -27
  90. package/dist/utils/log-utils.js +0 -58
  91. package/dist/utils/log-utils.js.map +1 -1
  92. package/dist/utils/user-preferences.js +6 -3
  93. package/dist/utils/user-preferences.js.map +1 -1
  94. package/package.json +9 -7
  95. package/src/command-handler.ts +74 -59
  96. package/src/commands/create.ts +10 -28
  97. package/src/commands/edit.ts +51 -26
  98. package/src/commands/fetch.ts +2 -1
  99. package/src/commands/import.ts +2 -0
  100. package/src/commands/remove.ts +3 -2
  101. package/src/commands/rename.ts +20 -0
  102. package/src/commands/show.ts +5 -13
  103. package/src/commands/update.ts +20 -2
  104. package/src/commands/validate.ts +7 -3
  105. package/src/containers/card-container.ts +1 -1
  106. package/src/containers/project/calculation-engine.ts +23 -23
  107. package/src/containers/project.ts +4 -1
  108. package/src/index.ts +36 -2
  109. package/src/interfaces/command-options.ts +144 -0
  110. package/src/interfaces/folder-content-interfaces.ts +81 -0
  111. package/src/interfaces/project-interfaces.ts +12 -9
  112. package/src/interfaces/resource-interfaces.ts +51 -12
  113. package/src/macros/report/index.ts +4 -4
  114. package/src/resources/calculation-resource.ts +171 -0
  115. package/src/resources/card-type-resource.ts +12 -6
  116. package/src/resources/create-defaults.ts +21 -5
  117. package/src/resources/field-type-resource.ts +1 -1
  118. package/src/resources/file-resource.ts +9 -3
  119. package/src/resources/folder-resource.ts +150 -20
  120. package/src/resources/graph-model-resource.ts +16 -27
  121. package/src/resources/graph-view-resource.ts +16 -28
  122. package/src/resources/link-type-resource.ts +1 -1
  123. package/src/resources/report-resource.ts +60 -62
  124. package/src/resources/resource-object.ts +30 -7
  125. package/src/resources/template-resource.ts +12 -7
  126. package/src/resources/workflow-resource.ts +4 -0
  127. package/src/utils/constants.ts +1 -0
  128. package/src/utils/error-utils.ts +62 -0
  129. package/src/utils/log-utils.ts +0 -68
  130. package/src/utils/user-preferences.ts +7 -3
@@ -0,0 +1,34 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
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. This program is distributed in the hope that it
7
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
8
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ See the GNU Affero General Public License for more details.
10
+ 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
+ /**
14
+ * Returns error message string from an Error object.
15
+ * @param error Error object
16
+ * @returns Error message.
17
+ */
18
+ export declare function errorFunction(error: unknown): string;
19
+ /**
20
+ * Same as 'errorFunction' but can do automatic replacement of the error message string.
21
+ * @param message Error message
22
+ * @param toReplace replacement substring
23
+ * @param replaceWith string that 'toReplace' is replaced with.
24
+ * @returns Modified error message.
25
+ */
26
+ export declare function errorMessage(message: string, toReplace?: string, replaceWith?: string): string;
27
+ /**
28
+ * Type guard to check if an error object has a code property.
29
+ * @param error The error object to check
30
+ * @returns true if the error has a code property
31
+ */
32
+ export declare function hasCode(error: unknown): error is Error & {
33
+ code: string;
34
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
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. This program is distributed in the hope that it
7
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
8
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ See the GNU Affero General Public License for more details.
10
+ 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
+ /**
14
+ * Returns error message string from an Error object.
15
+ * @param error Error object
16
+ * @returns Error message.
17
+ */
18
+ export function errorFunction(error) {
19
+ if (error instanceof Error) {
20
+ const err = error;
21
+ return errorMessage(`${err.message}`);
22
+ }
23
+ else if (typeof error === 'string') {
24
+ return errorMessage(`${error}`);
25
+ }
26
+ else {
27
+ return `errorFunction called without an error object. Actual object is ${JSON.stringify(error)}`;
28
+ }
29
+ }
30
+ /**
31
+ * Same as 'errorFunction' but can do automatic replacement of the error message string.
32
+ * @param message Error message
33
+ * @param toReplace replacement substring
34
+ * @param replaceWith string that 'toReplace' is replaced with.
35
+ * @returns Modified error message.
36
+ */
37
+ export function errorMessage(message, toReplace, replaceWith) {
38
+ let errorMessage = message;
39
+ if (toReplace && replaceWith) {
40
+ errorMessage = message.replace(toReplace, replaceWith);
41
+ }
42
+ return `${errorMessage}`;
43
+ }
44
+ /**
45
+ * Type guard to check if an error object has a code property.
46
+ * @param error The error object to check
47
+ * @returns true if the error has a code property
48
+ */
49
+ export function hasCode(error) {
50
+ return (error instanceof Error &&
51
+ typeof error === 'object' &&
52
+ error !== null &&
53
+ 'code' in error &&
54
+ typeof error.code === 'string');
55
+ }
56
+ //# sourceMappingURL=error-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-utils.js","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAEF;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAU,KAAK,CAAC;QACzB,OAAO,YAAY,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACxC,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,YAAY,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,OAAO,kEAAkE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;IACnG,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAe,EACf,SAAkB,EAClB,WAAoB;IAEpB,IAAI,YAAY,GAAG,OAAO,CAAC;IAC3B,IAAI,SAAS,IAAI,WAAW,EAAE,CAAC;QAC7B,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,GAAG,YAAY,EAAE,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC/B,CAAC;AACJ,CAAC"}
@@ -24,30 +24,3 @@ export declare function getLogger(): Logger;
24
24
  export declare function getChildLogger(context: {
25
25
  module: string;
26
26
  } & Record<string, unknown>, options?: ChildLoggerOptions): Logger;
27
- /**
28
- * Returns error message string from an Error object.
29
- * @param error Error object
30
- * @returns Error message.
31
- */
32
- export declare function errorFunction(error: unknown): string;
33
- /**
34
- * Same as 'errorFunction' but can do automatic replacement fof the error message string.
35
- * @param message Error message
36
- * @param toReplace replacement substring
37
- * @param replaceWith string that 'toReplace' is replaced with.
38
- * @returns Modified error message.
39
- */
40
- export declare function errorMessage(message: string, toReplace?: string, replaceWith?: string): string;
41
- /**
42
- * Logs error from Error object.
43
- * @param error potentially an Error object. When exceptions are raised, they are typically Error objects.
44
- */
45
- export declare function logError(error: unknown): void;
46
- /**
47
- * Log error message in RED. Certain parts of messages can be replaced.
48
- * This is useful, if including a message from external sources, and want to reduce the verbosity of the message.
49
- * @param message Error message to log.
50
- * @param toReplace String to look for.
51
- * @param replaceWith Replace 'toReplace' with this. Only replaces first instance of 'toReplace'.
52
- */
53
- export declare function logErrorMessage(message: string, toReplace?: string, replaceWith?: string): void;
@@ -31,62 +31,4 @@ export function getLogger() {
31
31
  export function getChildLogger(context, options) {
32
32
  return _logger.child(context, options);
33
33
  }
34
- /**
35
- * Returns error message string from an Error object.
36
- * @param error Error object
37
- * @returns Error message.
38
- */
39
- export function errorFunction(error) {
40
- if (error instanceof Error) {
41
- const err = error;
42
- return errorMessage(`${err.message}`);
43
- }
44
- else if (typeof error === 'string') {
45
- return errorMessage(`${error}`);
46
- }
47
- else {
48
- return `${logError.name} called without an error object. Actual object is ${JSON.stringify(error)}`;
49
- }
50
- }
51
- /**
52
- * Same as 'errorFunction' but can do automatic replacement fof the error message string.
53
- * @param message Error message
54
- * @param toReplace replacement substring
55
- * @param replaceWith string that 'toReplace' is replaced with.
56
- * @returns Modified error message.
57
- */
58
- export function errorMessage(message, toReplace, replaceWith) {
59
- let errorMessage = message;
60
- if (toReplace && replaceWith) {
61
- errorMessage = message.replace(toReplace, replaceWith);
62
- }
63
- return `${errorMessage}`;
64
- }
65
- /**
66
- * Logs error from Error object.
67
- * @param error potentially an Error object. When exceptions are raised, they are typically Error objects.
68
- */
69
- export function logError(error) {
70
- if (error instanceof Error) {
71
- const err = error;
72
- logErrorMessage(`${err.message}`);
73
- }
74
- else {
75
- console.error(`${logError.name} called without an error object. Actual object is ${JSON.stringify(error)}`);
76
- }
77
- }
78
- /**
79
- * Log error message in RED. Certain parts of messages can be replaced.
80
- * This is useful, if including a message from external sources, and want to reduce the verbosity of the message.
81
- * @param message Error message to log.
82
- * @param toReplace String to look for.
83
- * @param replaceWith Replace 'toReplace' with this. Only replaces first instance of 'toReplace'.
84
- */
85
- export function logErrorMessage(message, toReplace, replaceWith) {
86
- let errorMessage = message;
87
- if (toReplace && replaceWith) {
88
- errorMessage = message.replace(toReplace, replaceWith);
89
- }
90
- console.error(`${errorMessage}`);
91
- }
92
34
  //# sourceMappingURL=log-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"log-utils.js","sourceRoot":"","sources":["../../src/utils/log-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,IAA8C,MAAM,MAAM,CAAC;AAElE,2HAA2H;AAC3H,2BAA2B;AAC3B,IAAI,OAAO,GAAW,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEhD,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,OAAO,GAAG,MAAM,CAAC;AACnB,CAAC;AACD;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,OAAO,CAAC;AACjB,CAAC;AACD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAqD,EACrD,OAA4B;IAE5B,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AACD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAU,KAAK,CAAC;QACzB,OAAO,YAAY,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACxC,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,YAAY,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,QAAQ,CAAC,IAAI,qDAAqD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;IACtG,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAe,EACf,SAAkB,EAClB,WAAoB;IAEpB,IAAI,YAAY,GAAG,OAAO,CAAC;IAC3B,IAAI,SAAS,IAAI,WAAW,EAAE,CAA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cAAc,CAC5B,OAAqD,EACrD,OAA4B;IAE5B,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC"}
@@ -11,6 +11,7 @@
11
11
  */
12
12
  import { dirname } from 'node:path';
13
13
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
14
+ import { hasCode } from './error-utils.js';
14
15
  import { formatJson } from './json.js';
15
16
  import { getChildLogger } from '../utils/log-utils.js';
16
17
  /**
@@ -93,16 +94,18 @@ export class UserPreferences {
93
94
  });
94
95
  }
95
96
  catch (error) {
96
- if (error instanceof Error) {
97
- const err = error;
97
+ if (hasCode(error)) {
98
98
  // If file already exists (EEXIST), that's fine - we'll use the existing file
99
- if (err?.code !== 'EEXIST') {
99
+ if (error.code !== 'EEXIST') {
100
100
  throw new Error(`Error creating preferences file '${this.prefsFilePath}': ${error}`);
101
101
  }
102
102
  else {
103
103
  this.logger.warn('Preferences file already exists');
104
104
  }
105
105
  }
106
+ else {
107
+ throw new Error(`Error creating preferences file '${this.prefsFilePath}': ${error}`);
108
+ }
106
109
  }
107
110
  }
108
111
  get logger() {
@@ -1 +1 @@
1
- {"version":3,"file":"user-preferences.js","sourceRoot":"","sources":["../../src/utils/user-preferences.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAgBvD;;;GAGG;AACH,MAAM,OAAO,eAAe;IA8DN;IA7DpB,oDAAoD;IACpD,uBAAuB;IACvB,MAAM,CAAC,QAAQ,GAAG;QAChB,WAAW,EAAE;YACX,MAAM,EAAE;gBACN,OAAO,EAAE,MAAM;gBACf,IAAI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,CAAC;QACJ,CAAC;IACH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cyberismo/data-handler",
3
3
  "description": "Command handler for cards and web service",
4
- "version": "0.0.12",
4
+ "version": "0.0.14",
5
5
  "author": "sami.merila@cyberismo.com",
6
6
  "license": "AGPL-3.0",
7
7
  "homepage": "https://github.com/CyberismoCom/cyberismo",
@@ -27,6 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@asciidoctor/core": "^3.0.4",
30
+ "@types/mime-types": "^3.0.1",
30
31
  "@viz-js/viz": "^3.17.0",
31
32
  "async-mutex": "^0.5.0",
32
33
  "csv-parse": "^6.1.0",
@@ -34,18 +35,19 @@
34
35
  "dompurify": "^3.2.6",
35
36
  "email-validator": "^2.0.4",
36
37
  "handlebars": "^4.7.8",
37
- "jsdom": "^26.1.0",
38
+ "jsdom": "^27.0.0",
38
39
  "json-schema": "^0.4.0",
39
40
  "jsonschema": "^1.5.0",
40
- "pino": "^9.9.4",
41
+ "mime-types": "^3.0.1",
42
+ "pino": "^9.9.5",
41
43
  "simple-git": "^3.28.0",
42
44
  "string-pixel-width": "^1.11.0",
43
45
  "tslib": "^2.6.2",
44
46
  "vega": "^6.1.2",
45
- "vega-lite": "^6.2.0",
46
- "write-json-file": "^6.0.0",
47
- "@cyberismo/assets": "0.0.12",
48
- "@cyberismo/node-clingo": "1.2.0"
47
+ "vega-lite": "^6.3.1",
48
+ "write-json-file": "^7.0.0",
49
+ "@cyberismo/assets": "0.0.14",
50
+ "@cyberismo/node-clingo": "1.3.0"
49
51
  },
50
52
  "type": "module",
51
53
  "files": [
@@ -31,6 +31,16 @@ import type {
31
31
  DataType,
32
32
  ResourceContent,
33
33
  } from './interfaces/resource-interfaces.js';
34
+ import type {
35
+ AddCommandOptions,
36
+ AllCommandOptions,
37
+ CalcCommandOptions,
38
+ ExportCommandOptions,
39
+ ReportCommandOptions,
40
+ ShowCommandOptions,
41
+ StartCommandOptions,
42
+ UpdateCommandOptions,
43
+ } from './interfaces/command-options.js';
34
44
 
35
45
  import type { requestStatus } from './interfaces/request-status-interfaces.js';
36
46
 
@@ -40,7 +50,7 @@ import type { UpdateOperations } from './resources/resource-object.js';
40
50
  import { Project } from './containers/project.js';
41
51
 
42
52
  import { pathExists, resolveTilde } from './utils/file-utils.js';
43
- import { errorFunction } from './utils/log-utils.js';
53
+ import { errorFunction } from './utils/error-utils.js';
44
54
  import { readJsonFile } from './utils/json.js';
45
55
  import { resourceName } from './utils/resource-utils.js';
46
56
 
@@ -48,49 +58,30 @@ import { type Level } from 'pino';
48
58
  import { type Context } from './interfaces/project-interfaces.js';
49
59
  import { type QueryName } from './types/queries.js';
50
60
 
51
- // Generic options interface
52
- export interface CardsOptions {
53
- context?: Context;
54
- date?: string;
55
- details?: boolean;
56
- forceStart?: boolean;
57
- logLevel?: Level;
58
- mappingFile?: string;
59
- name?: string;
60
- projectPath?: string;
61
- recursive?: boolean;
62
- repeat?: number;
63
- revremark?: string;
64
- showAll?: boolean;
65
- showUse?: boolean;
66
- skipModuleImport?: boolean;
67
- title?: string;
68
- version?: string;
69
- watchResourceChanges?: boolean;
70
- }
71
-
72
61
  // Commands that this class supports.
73
- // todo: Could be inside the `CommandHandler` ?
74
- export enum Cmd {
75
- add = 'add',
76
- calc = 'calc',
77
- create = 'create',
78
- edit = 'edit',
79
- export = 'export',
80
- fetch = 'fetch',
81
- import = 'import',
82
- move = 'move',
83
- rank = 'rank',
84
- remove = 'remove',
85
- rename = 'rename',
86
- report = 'report',
87
- show = 'show',
88
- start = 'start',
89
- transition = 'transition',
90
- update = 'update',
91
- updateModules = 'update-modules',
92
- validate = 'validate',
93
- }
62
+ export const Cmd = {
63
+ add: 'add',
64
+ calc: 'calc',
65
+ create: 'create',
66
+ edit: 'edit',
67
+ export: 'export',
68
+ fetch: 'fetch',
69
+ import: 'import',
70
+ move: 'move',
71
+ rank: 'rank',
72
+ remove: 'remove',
73
+ rename: 'rename',
74
+ report: 'report',
75
+ show: 'show',
76
+ start: 'start',
77
+ transition: 'transition',
78
+ update: 'update',
79
+ updateModules: 'update-modules',
80
+ validate: 'validate',
81
+ };
82
+
83
+ export type CmdKey = keyof typeof Cmd;
84
+ export type CmdValue = (typeof Cmd)[CmdKey];
94
85
 
95
86
  // To what format the content can be exported to.
96
87
  export enum ExportFormats {
@@ -128,9 +119,9 @@ export class Commands {
128
119
  * @returns request status; 200 if success; 400 in handled error; 500 in unknown error
129
120
  */
130
121
  public async command(
131
- command: Cmd,
122
+ command: CmdValue,
132
123
  args: string[],
133
- options: CardsOptions,
124
+ options: AllCommandOptions,
134
125
  credentials?: Credentials,
135
126
  ): Promise<requestStatus> {
136
127
  // Set project path and validate it.
@@ -163,7 +154,7 @@ export class Commands {
163
154
  }
164
155
 
165
156
  // Handles initializing the project so that it can be used in the class.
166
- private async doSetProject(options: CardsOptions) {
157
+ private async doSetProject(options: AllCommandOptions) {
167
158
  const path = options.projectPath || '';
168
159
  this.projectPath = resolveTilde(await this.setProjectPath(path));
169
160
  if (!Validate.validateFolder(this.projectPath)) {
@@ -182,7 +173,8 @@ export class Commands {
182
173
 
183
174
  this.commands = await CommandManager.getInstance(this.projectPath, {
184
175
  logLevel: options.logLevel,
185
- watchResourceChanges: options.watchResourceChanges,
176
+ watchResourceChanges: (options as StartCommandOptions)
177
+ .watchResourceChanges,
186
178
  });
187
179
  if (!this.commands) {
188
180
  throw new Error('Cannot get instance of CommandManager');
@@ -192,16 +184,21 @@ export class Commands {
192
184
 
193
185
  // Handles actual command. Sets returns values correctly.
194
186
  private async doHandleCommand(
195
- command: Cmd,
187
+ command: CmdValue,
196
188
  args: string[],
197
- options: CardsOptions,
189
+ options: AllCommandOptions,
198
190
  credentials?: Credentials,
199
191
  ) {
200
192
  try {
201
193
  if (command === Cmd.add) {
202
194
  const [type, target, cardType, cardKey] = args;
203
195
  if (type === 'card') {
204
- return await this.addCard(target, cardType, cardKey, options.repeat);
196
+ return await this.addCard(
197
+ target,
198
+ cardType,
199
+ cardKey,
200
+ (options as AddCommandOptions).repeat,
201
+ );
205
202
  }
206
203
  if (type === 'hub') {
207
204
  return await this.addHub(target);
@@ -214,7 +211,10 @@ export class Commands {
214
211
  return { statusCode: 400, message: 'File path is missing' };
215
212
  }
216
213
  await this.generateLogicProgram();
217
- return this.runLogicProgram(cardKey, options.context || 'localApp');
214
+ return this.runLogicProgram(
215
+ cardKey,
216
+ (options as CalcCommandOptions).context || 'localApp',
217
+ );
218
218
  }
219
219
  if (command === 'generate') {
220
220
  const [destination, query] = rest;
@@ -356,11 +356,11 @@ export class Commands {
356
356
  const [parameters, outputPath] = args;
357
357
  return this.runReport(
358
358
  parameters,
359
- options.context || 'localApp',
359
+ (options as ReportCommandOptions).context || 'localApp',
360
360
  outputPath,
361
361
  );
362
362
  } else if (command === Cmd.start) {
363
- return this.startApp(options.forceStart);
363
+ return this.startApp((options as StartCommandOptions).forceStart);
364
364
  } else if (command === Cmd.transition) {
365
365
  const [cardKey, state] = args;
366
366
  await this.commands?.transitionCmd.cardTransition(cardKey, {
@@ -378,13 +378,13 @@ export class Commands {
378
378
  // Handle mapping file for workflow changes
379
379
  let mappingTable: { stateMapping: Record<string, string> } | undefined;
380
380
  if (
381
- options.mappingFile &&
381
+ (options as UpdateCommandOptions).mappingFile &&
382
382
  operation === 'change' &&
383
383
  key === 'workflow'
384
384
  ) {
385
385
  try {
386
386
  const mappingData = await readJsonFile(
387
- resolveTilde(options.mappingFile),
387
+ resolveTilde((options as UpdateCommandOptions).mappingFile!),
388
388
  );
389
389
  if (
390
390
  mappingData &&
@@ -537,7 +537,7 @@ export class Commands {
537
537
  destination: string = 'output',
538
538
  format: ExportFormats,
539
539
  parentCardKey?: string,
540
- pdfOptions?: CardsOptions,
540
+ pdfOptions?: ExportCommandOptions,
541
541
  ): Promise<requestStatus> {
542
542
  if (!this.commands) {
543
543
  return { statusCode: 500 };
@@ -701,7 +701,7 @@ export class Commands {
701
701
  private async show(
702
702
  type: ResourceTypes,
703
703
  typeDetail: string,
704
- options: CardsOptions,
704
+ options: ShowCommandOptions,
705
705
  ): Promise<requestStatus> {
706
706
  const detail = typeDetail || '';
707
707
  let promise: Promise<
@@ -736,6 +736,7 @@ export class Commands {
736
736
  case 'cards':
737
737
  promise = this.commands!.showCmd.showCards();
738
738
  break;
739
+ case 'calculation':
739
740
  case 'cardType':
740
741
  case 'fieldType':
741
742
  case 'graphView':
@@ -746,6 +747,7 @@ export class Commands {
746
747
  case 'workflow':
747
748
  promise = this.commands!.showCmd.showResource(detail, options.showUse);
748
749
  break;
750
+ case 'calculations':
749
751
  case 'cardTypes':
750
752
  case 'fieldTypes':
751
753
  case 'graphModels':
@@ -798,8 +800,15 @@ export class Commands {
798
800
  // since current working directory changes, we need to resolve the project path
799
801
  const projectPath = resolve(this.projectPath);
800
802
 
803
+ if (!this.commands) {
804
+ return { statusCode: 500, message: 'Commands not initialized' };
805
+ }
806
+
801
807
  if (!forceStart) {
802
- const validationErrors = await this.validateCmd.validate(projectPath);
808
+ const validationErrors = await this.validateCmd.validate(
809
+ projectPath,
810
+ () => this.commands!.project,
811
+ );
803
812
  if (validationErrors) {
804
813
  return { statusCode: 400, message: validationErrors };
805
814
  }
@@ -821,7 +830,13 @@ export class Commands {
821
830
 
822
831
  // Validates that a given path conforms to schema. Validates both file/folder structure and file content.
823
832
  private async validate(): Promise<requestStatus> {
824
- const result = await this.validateCmd.validate(this.projectPath);
833
+ if (!this.commands) {
834
+ return { statusCode: 500, message: 'Commands not initialized' };
835
+ }
836
+ const result = await this.validateCmd.validate(
837
+ this.projectPath,
838
+ () => this.commands!.project,
839
+ );
825
840
  return {
826
841
  statusCode: 200,
827
842
  message: result.length ? result : 'Project structure validated',
@@ -20,7 +20,7 @@ import {
20
20
  writeFile,
21
21
  } from 'node:fs/promises';
22
22
 
23
- import { errorFunction } from '../utils/log-utils.js';
23
+ import { errorFunction } from '../utils/error-utils.js';
24
24
  import { Project } from '../containers/project.js';
25
25
  import { Validate } from './index.js';
26
26
 
@@ -35,6 +35,7 @@ import type { Card, ProjectFile } from '../interfaces/project-interfaces.js';
35
35
  import { resourceName, resourceNameToString } from '../utils/resource-utils.js';
36
36
  import { writeJsonFile } from '../utils/json.js';
37
37
 
38
+ import { CalculationResource } from '../resources/calculation-resource.js';
38
39
  import { CardTypeResource } from '../resources/card-type-resource.js';
39
40
  import { FieldTypeResource } from '../resources/field-type-resource.js';
40
41
  import { GraphModelResource } from '../resources/graph-model-resource.js';
@@ -213,34 +214,15 @@ export class Create {
213
214
  }
214
215
 
215
216
  /**
216
- * Creates a calculation file.
217
- * @param fileName name for the calculation file (without .lp extension)
217
+ * Creates a calculation resource.
218
+ * @param calculationName name for the calculation resource
218
219
  */
219
- public async createCalculation(fileName: string) {
220
- const calculationFolder = this.project.paths.calculationProjectFolder;
221
-
222
- await mkdir(calculationFolder, { recursive: true });
223
-
224
- const calculationFileName = fileName.endsWith('.lp')
225
- ? fileName
226
- : `${fileName}.lp`;
227
- const calculationFilePath = join(calculationFolder, calculationFileName);
228
-
229
- const calculationContent = `% Calculation file: ${calculationFileName}
230
- % Add your logic programming rules here
231
- `;
232
-
233
- await writeFile(calculationFilePath, calculationContent, { flag: 'wx' });
234
-
235
- // add to cache manually
236
- // TODO: remove once calculations are a proper resource
237
- const resourceName = `${this.project.projectPrefix}/calculations/${fileName.replace('.lp', '')}`;
238
- const resource = {
239
- name: resourceName,
240
- path: calculationFolder,
241
- };
242
-
243
- this.project.addResource(resource, {} as JSON);
220
+ public async createCalculation(calculationName: string) {
221
+ const calculation = new CalculationResource(
222
+ this.project,
223
+ resourceName(calculationName),
224
+ );
225
+ await calculation.create();
244
226
  }
245
227
 
246
228
  /**