@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.
- package/LICENSE +702 -0
- package/dist/card-metadata-updater.d.ts +33 -0
- package/dist/card-metadata-updater.js +121 -0
- package/dist/card-metadata-updater.js.map +1 -0
- package/dist/command-handler.d.ts +96 -0
- package/dist/command-handler.js +557 -0
- package/dist/command-handler.js.map +1 -0
- package/dist/command-manager.d.ts +43 -0
- package/dist/command-manager.js +73 -0
- package/dist/command-manager.js.map +1 -0
- package/dist/commands/calculate.d.ts +86 -0
- package/dist/commands/calculate.js +444 -0
- package/dist/commands/calculate.js.map +1 -0
- package/dist/commands/create.d.ts +114 -0
- package/dist/commands/create.js +389 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/edit.d.ts +37 -0
- package/dist/commands/edit.js +99 -0
- package/dist/commands/edit.js.map +1 -0
- package/dist/commands/export-site.d.ts +45 -0
- package/dist/commands/export-site.js +301 -0
- package/dist/commands/export-site.js.map +1 -0
- package/dist/commands/export.d.ts +53 -0
- package/dist/commands/export.js +251 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/import.d.ts +53 -0
- package/dist/commands/import.js +133 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/index.d.ts +26 -0
- package/dist/commands/index.js +27 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/move.d.ts +55 -0
- package/dist/commands/move.js +341 -0
- package/dist/commands/move.js.map +1 -0
- package/dist/commands/remove.d.ts +38 -0
- package/dist/commands/remove.js +192 -0
- package/dist/commands/remove.js.map +1 -0
- package/dist/commands/rename.d.ts +46 -0
- package/dist/commands/rename.js +289 -0
- package/dist/commands/rename.js.map +1 -0
- package/dist/commands/show.d.ts +124 -0
- package/dist/commands/show.js +345 -0
- package/dist/commands/show.js.map +1 -0
- package/dist/commands/transition.d.ts +27 -0
- package/dist/commands/transition.js +92 -0
- package/dist/commands/transition.js.map +1 -0
- package/dist/commands/update.d.ts +29 -0
- package/dist/commands/update.js +64 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/validate.d.ts +143 -0
- package/dist/commands/validate.js +689 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/containers/card-container.d.ts +44 -0
- package/dist/containers/card-container.js +282 -0
- package/dist/containers/card-container.js.map +1 -0
- package/dist/containers/project/project-paths.d.ts +46 -0
- package/dist/containers/project/project-paths.js +105 -0
- package/dist/containers/project/project-paths.js.map +1 -0
- package/dist/containers/project/resource-collector.d.ts +86 -0
- package/dist/containers/project/resource-collector.js +331 -0
- package/dist/containers/project/resource-collector.js.map +1 -0
- package/dist/containers/project.d.ts +351 -0
- package/dist/containers/project.js +896 -0
- package/dist/containers/project.js.map +1 -0
- package/dist/containers/template.d.ts +108 -0
- package/dist/containers/template.js +433 -0
- package/dist/containers/template.js.map +1 -0
- package/dist/exceptions/index.d.ts +19 -0
- package/dist/exceptions/index.js +26 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/adoc.d.ts +12 -0
- package/dist/interfaces/adoc.js +13 -0
- package/dist/interfaces/adoc.js.map +1 -0
- package/dist/interfaces/macros.d.ts +45 -0
- package/dist/interfaces/macros.js +13 -0
- package/dist/interfaces/macros.js.map +1 -0
- package/dist/interfaces/project-interfaces.d.ts +121 -0
- package/dist/interfaces/project-interfaces.js +21 -0
- package/dist/interfaces/project-interfaces.js.map +1 -0
- package/dist/interfaces/request-status-interfaces.d.ts +28 -0
- package/dist/interfaces/request-status-interfaces.js +20 -0
- package/dist/interfaces/request-status-interfaces.js.map +1 -0
- package/dist/interfaces/resource-interfaces.d.ts +117 -0
- package/dist/interfaces/resource-interfaces.js +20 -0
- package/dist/interfaces/resource-interfaces.js.map +1 -0
- package/dist/macros/base-macro.d.ts +31 -0
- package/dist/macros/base-macro.js +126 -0
- package/dist/macros/base-macro.js.map +1 -0
- package/dist/macros/common.d.ts +17 -0
- package/dist/macros/common.js +23 -0
- package/dist/macros/common.js.map +1 -0
- package/dist/macros/createCards/index.d.ts +36 -0
- package/dist/macros/createCards/index.js +35 -0
- package/dist/macros/createCards/index.js.map +1 -0
- package/dist/macros/createCards/metadata.d.ts +14 -0
- package/dist/macros/createCards/metadata.js +18 -0
- package/dist/macros/createCards/metadata.js.map +1 -0
- package/dist/macros/graph/index.d.ts +29 -0
- package/dist/macros/graph/index.js +91 -0
- package/dist/macros/graph/index.js.map +1 -0
- package/dist/macros/graph/metadata.d.ts +14 -0
- package/dist/macros/graph/metadata.js +18 -0
- package/dist/macros/graph/metadata.js.map +1 -0
- package/dist/macros/index.d.ts +93 -0
- package/dist/macros/index.js +237 -0
- package/dist/macros/index.js.map +1 -0
- package/dist/macros/report/index.d.ts +26 -0
- package/dist/macros/report/index.js +70 -0
- package/dist/macros/report/index.js.map +1 -0
- package/dist/macros/report/metadata.d.ts +14 -0
- package/dist/macros/report/metadata.js +18 -0
- package/dist/macros/report/metadata.js.map +1 -0
- package/dist/macros/scoreCard/index.d.ts +30 -0
- package/dist/macros/scoreCard/index.js +38 -0
- package/dist/macros/scoreCard/index.js.map +1 -0
- package/dist/macros/scoreCard/metadata.d.ts +14 -0
- package/dist/macros/scoreCard/metadata.js +18 -0
- package/dist/macros/scoreCard/metadata.js.map +1 -0
- package/dist/macros/task-queue.d.ts +46 -0
- package/dist/macros/task-queue.js +69 -0
- package/dist/macros/task-queue.js.map +1 -0
- package/dist/module-manager.d.ts +62 -0
- package/dist/module-manager.js +350 -0
- package/dist/module-manager.js.map +1 -0
- package/dist/permissions/action-guard.d.ts +28 -0
- package/dist/permissions/action-guard.js +61 -0
- package/dist/permissions/action-guard.js.map +1 -0
- package/dist/project-settings.d.ts +42 -0
- package/dist/project-settings.js +120 -0
- package/dist/project-settings.js.map +1 -0
- package/dist/resources/array-handler.d.ts +28 -0
- package/dist/resources/array-handler.js +116 -0
- package/dist/resources/array-handler.js.map +1 -0
- package/dist/resources/card-type-resource.d.ts +72 -0
- package/dist/resources/card-type-resource.js +334 -0
- package/dist/resources/card-type-resource.js.map +1 -0
- package/dist/resources/create-defaults.d.ts +81 -0
- package/dist/resources/create-defaults.js +184 -0
- package/dist/resources/create-defaults.js.map +1 -0
- package/dist/resources/field-type-resource.d.ts +88 -0
- package/dist/resources/field-type-resource.js +411 -0
- package/dist/resources/field-type-resource.js.map +1 -0
- package/dist/resources/file-resource.d.ts +50 -0
- package/dist/resources/file-resource.js +301 -0
- package/dist/resources/file-resource.js.map +1 -0
- package/dist/resources/folder-resource.d.ts +66 -0
- package/dist/resources/folder-resource.js +100 -0
- package/dist/resources/folder-resource.js.map +1 -0
- package/dist/resources/graph-model-resource.d.ts +78 -0
- package/dist/resources/graph-model-resource.js +164 -0
- package/dist/resources/graph-model-resource.js.map +1 -0
- package/dist/resources/graph-view-resource.d.ts +78 -0
- package/dist/resources/graph-view-resource.js +163 -0
- package/dist/resources/graph-view-resource.js.map +1 -0
- package/dist/resources/link-type-resource.d.ts +62 -0
- package/dist/resources/link-type-resource.js +150 -0
- package/dist/resources/link-type-resource.js.map +1 -0
- package/dist/resources/report-resource.d.ts +77 -0
- package/dist/resources/report-resource.js +171 -0
- package/dist/resources/report-resource.js.map +1 -0
- package/dist/resources/resource-object.d.ts +108 -0
- package/dist/resources/resource-object.js +147 -0
- package/dist/resources/resource-object.js.map +1 -0
- package/dist/resources/template-resource.d.ts +82 -0
- package/dist/resources/template-resource.js +173 -0
- package/dist/resources/template-resource.js.map +1 -0
- package/dist/resources/workflow-resource.d.ts +67 -0
- package/dist/resources/workflow-resource.js +156 -0
- package/dist/resources/workflow-resource.js.map +1 -0
- package/dist/types/queries.d.ts +142 -0
- package/dist/types/queries.js +16 -0
- package/dist/types/queries.js.map +1 -0
- package/dist/utils/card-utils.d.ts +34 -0
- package/dist/utils/card-utils.js +78 -0
- package/dist/utils/card-utils.js.map +1 -0
- package/dist/utils/clingo-fact-builder.d.ts +58 -0
- package/dist/utils/clingo-fact-builder.js +126 -0
- package/dist/utils/clingo-fact-builder.js.map +1 -0
- package/dist/utils/clingo-facts.d.ts +97 -0
- package/dist/utils/clingo-facts.js +352 -0
- package/dist/utils/clingo-facts.js.map +1 -0
- package/dist/utils/clingo-parser.d.ts +59 -0
- package/dist/utils/clingo-parser.js +403 -0
- package/dist/utils/clingo-parser.js.map +1 -0
- package/dist/utils/clingo-program-builder.d.ts +39 -0
- package/dist/utils/clingo-program-builder.js +57 -0
- package/dist/utils/clingo-program-builder.js.map +1 -0
- package/dist/utils/common-utils.d.ts +24 -0
- package/dist/utils/common-utils.js +47 -0
- package/dist/utils/common-utils.js.map +1 -0
- package/dist/utils/constants.d.ts +18 -0
- package/dist/utils/constants.js +27 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/csv.d.ts +18 -0
- package/dist/utils/csv.js +45 -0
- package/dist/utils/csv.js.map +1 -0
- package/dist/utils/file-utils.d.ts +69 -0
- package/dist/utils/file-utils.js +158 -0
- package/dist/utils/file-utils.js.map +1 -0
- package/dist/utils/json.d.ts +61 -0
- package/dist/utils/json.js +108 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/lexorank.d.ts +59 -0
- package/dist/utils/lexorank.js +159 -0
- package/dist/utils/lexorank.js.map +1 -0
- package/dist/utils/log-utils.d.ts +40 -0
- package/dist/utils/log-utils.js +109 -0
- package/dist/utils/log-utils.js.map +1 -0
- package/dist/utils/random.d.ts +19 -0
- package/dist/utils/random.js +34 -0
- package/dist/utils/random.js.map +1 -0
- package/dist/utils/resource-utils.d.ts +45 -0
- package/dist/utils/resource-utils.js +137 -0
- package/dist/utils/resource-utils.js.map +1 -0
- package/dist/utils/sanitize-svg.d.ts +18 -0
- package/dist/utils/sanitize-svg.js +38 -0
- package/dist/utils/sanitize-svg.js.map +1 -0
- package/dist/utils/user-preferences.d.ts +64 -0
- package/dist/utils/user-preferences.js +106 -0
- package/dist/utils/user-preferences.js.map +1 -0
- package/dist/utils/validate.d.ts +26 -0
- package/dist/utils/validate.js +53 -0
- package/dist/utils/validate.js.map +1 -0
- package/dist/utils/value-utils.d.ts +58 -0
- package/dist/utils/value-utils.js +181 -0
- package/dist/utils/value-utils.js.map +1 -0
- package/package.json +67 -0
- package/src/card-metadata-updater.ts +182 -0
- package/src/command-handler.ts +686 -0
- package/src/command-manager.ts +99 -0
- package/src/commands/calculate.ts +591 -0
- package/src/commands/create.ts +559 -0
- package/src/commands/edit.ts +123 -0
- package/src/commands/export-site.ts +356 -0
- package/src/commands/export.ts +315 -0
- package/src/commands/import.ts +169 -0
- package/src/commands/index.ts +42 -0
- package/src/commands/move.ts +451 -0
- package/src/commands/remove.ts +244 -0
- package/src/commands/rename.ts +378 -0
- package/src/commands/show.ts +442 -0
- package/src/commands/transition.ts +127 -0
- package/src/commands/update.ts +76 -0
- package/src/commands/validate.ts +962 -0
- package/src/containers/card-container.ts +378 -0
- package/src/containers/project/project-paths.ts +127 -0
- package/src/containers/project/resource-collector.ts +379 -0
- package/src/containers/project.ts +1135 -0
- package/src/containers/template.ts +573 -0
- package/src/exceptions/index.ts +29 -0
- package/src/index.ts +33 -0
- package/src/interfaces/adoc.ts +18 -0
- package/src/interfaces/macros.ts +54 -0
- package/src/interfaces/project-interfaces.ts +208 -0
- package/src/interfaces/request-status-interfaces.ts +30 -0
- package/src/interfaces/resource-interfaces.ts +179 -0
- package/src/macros/base-macro.ts +176 -0
- package/src/macros/common.ts +24 -0
- package/src/macros/createCards/index.ts +57 -0
- package/src/macros/createCards/metadata.ts +21 -0
- package/src/macros/graph/index.ts +130 -0
- package/src/macros/graph/metadata.ts +21 -0
- package/src/macros/index.ts +321 -0
- package/src/macros/report/index.ts +88 -0
- package/src/macros/report/metadata.ts +21 -0
- package/src/macros/scoreCard/index.ts +55 -0
- package/src/macros/scoreCard/metadata.ts +21 -0
- package/src/macros/task-queue.ts +79 -0
- package/src/module-manager.ts +443 -0
- package/src/permissions/action-guard.ts +77 -0
- package/src/project-settings.ts +140 -0
- package/src/resources/array-handler.ts +141 -0
- package/src/resources/card-type-resource.ts +455 -0
- package/src/resources/create-defaults.ts +216 -0
- package/src/resources/field-type-resource.ts +533 -0
- package/src/resources/file-resource.ts +433 -0
- package/src/resources/folder-resource.ts +140 -0
- package/src/resources/graph-model-resource.ts +205 -0
- package/src/resources/graph-view-resource.ts +199 -0
- package/src/resources/link-type-resource.ts +191 -0
- package/src/resources/report-resource.ts +224 -0
- package/src/resources/resource-object.ts +246 -0
- package/src/resources/template-resource.ts +210 -0
- package/src/resources/workflow-resource.ts +205 -0
- package/src/types/queries.ts +149 -0
- package/src/utils/card-utils.ts +83 -0
- package/src/utils/clingo-fact-builder.ts +167 -0
- package/src/utils/clingo-facts.ts +550 -0
- package/src/utils/clingo-parser.ts +519 -0
- package/src/utils/clingo-program-builder.ts +71 -0
- package/src/utils/common-utils.ts +54 -0
- package/src/utils/constants.ts +32 -0
- package/src/utils/csv.ts +53 -0
- package/src/utils/file-utils.ts +182 -0
- package/src/utils/json.ts +118 -0
- package/src/utils/lexorank.ts +180 -0
- package/src/utils/log-utils.ts +127 -0
- package/src/utils/random.ts +37 -0
- package/src/utils/resource-utils.ts +180 -0
- package/src/utils/sanitize-svg.ts +46 -0
- package/src/utils/user-preferences.ts +126 -0
- package/src/utils/validate.ts +66 -0
- package/src/utils/value-utils.ts +189 -0
|
@@ -0,0 +1,78 @@
|
|
|
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 { sep } from 'node:path';
|
|
13
|
+
// Helper function to find the parent path from a card path
|
|
14
|
+
export const findParentPath = (cardPath) => {
|
|
15
|
+
const pathParts = cardPath.split(sep);
|
|
16
|
+
const hasChildren = pathParts.lastIndexOf('c');
|
|
17
|
+
if (hasChildren <= 0)
|
|
18
|
+
return null;
|
|
19
|
+
const parentPathParts = [...pathParts];
|
|
20
|
+
parentPathParts.splice(hasChildren, 1);
|
|
21
|
+
return parentPathParts.slice(0, hasChildren).join(sep);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Flattens card tree so that children are shown on same level regardless of nesting level.
|
|
25
|
+
* @param array card tree
|
|
26
|
+
* @returns flattened card tree.
|
|
27
|
+
*/
|
|
28
|
+
export const flattenCardArray = (array) => {
|
|
29
|
+
const result = [];
|
|
30
|
+
array.forEach((item) => {
|
|
31
|
+
const { key, path, children, attachments, metadata } = item;
|
|
32
|
+
result.push({ key, path, children, attachments, metadata });
|
|
33
|
+
if (children) {
|
|
34
|
+
result.push(...flattenCardArray(children));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Checks if given card is in some template.
|
|
41
|
+
* @param card card object to check
|
|
42
|
+
* @returns true if card exists in a template; false otherwise
|
|
43
|
+
*/
|
|
44
|
+
export const isTemplateCard = (card) => {
|
|
45
|
+
return (card.path.includes(`${sep}templates${sep}`) ||
|
|
46
|
+
card.path.includes(`${sep}modules${sep}`));
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Sorts array of cards first using prefix and then using ID.
|
|
50
|
+
* Prefixes are returned in alphabetical order, and then in numeric order within same prefix.
|
|
51
|
+
* For example, test_za1, test_aa7 and demo_aaa are sorted to: demo_aaa, test_aa7, test_za1.
|
|
52
|
+
* @param a First card to be sorted
|
|
53
|
+
* @param b Second card to be sorted
|
|
54
|
+
* @returns Cards ordered; first by prefixes, then by ID.
|
|
55
|
+
*/
|
|
56
|
+
export const sortCards = (a, b) => {
|
|
57
|
+
const aParts = a.split('_');
|
|
58
|
+
const bParts = b.split('_');
|
|
59
|
+
if (aParts[0] !== bParts[0]) {
|
|
60
|
+
if (aParts[0] > bParts[0])
|
|
61
|
+
return 1;
|
|
62
|
+
if (aParts[0] < bParts[0])
|
|
63
|
+
return -1;
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
if (a.length > b.length) {
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
if (a.length < b.length) {
|
|
70
|
+
return -1;
|
|
71
|
+
}
|
|
72
|
+
if (aParts[1] > bParts[1])
|
|
73
|
+
return 1;
|
|
74
|
+
if (aParts[1] < bParts[1])
|
|
75
|
+
return -1;
|
|
76
|
+
return 0;
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=card-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-utils.js","sourceRoot":"","sources":["../../src/utils/card-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAIhC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAiB,EAAE;IAChE,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAE/C,IAAI,WAAW,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAElC,MAAM,eAAe,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC;IACvC,eAAe,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACvC,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CA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;YAAE,OAAO,CAAC,CAAC;QACpC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC,CAAC;QACrC,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IACD,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IACpC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;IACrC,OAAO,CAAC,CAAC;AACX,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
export type AllowedClingoType = string | number | boolean;
|
|
13
|
+
export type NestedBuilder = (builder: ClingoFactBuilder) => ClingoFactBuilder;
|
|
14
|
+
type ClingoArgumentInternal = AllowedClingoType | AllowedClingoType[] | ClingoFactBuilder;
|
|
15
|
+
export type ClingoArgument = ClingoArgumentInternal | NestedBuilder;
|
|
16
|
+
/**
|
|
17
|
+
* This function takes care of encoding chars, which might produce issues in clingo
|
|
18
|
+
* This should be done for user provided values
|
|
19
|
+
*/
|
|
20
|
+
export declare function encodeClingoValue(value: string): string;
|
|
21
|
+
export declare class ClingoFactBuilder {
|
|
22
|
+
protected predicate: string;
|
|
23
|
+
private end;
|
|
24
|
+
private arguments;
|
|
25
|
+
constructor(predicate: string, end?: string);
|
|
26
|
+
/**
|
|
27
|
+
* Adds an argument to the fact
|
|
28
|
+
* @param arg Argument to add. If null, skipped
|
|
29
|
+
* @returns this for chaining
|
|
30
|
+
*/
|
|
31
|
+
addArgument(arg: ClingoArgument | null): ClingoFactBuilder;
|
|
32
|
+
/**
|
|
33
|
+
* Helper for adding multiple arguments, because it's common
|
|
34
|
+
* @param args
|
|
35
|
+
* @returns this for chaining
|
|
36
|
+
*/
|
|
37
|
+
addArguments(...args: (ClingoArgument | null)[]): ClingoFactBuilder;
|
|
38
|
+
/**
|
|
39
|
+
* Adds a literal argument, which means that it will not have quotes
|
|
40
|
+
* @param literal The literal argument to add
|
|
41
|
+
* @returns this for chaining
|
|
42
|
+
*/
|
|
43
|
+
addLiteralArgument(literal: string): ClingoFactBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Helper for adding multiple literal arguments, because it's common
|
|
46
|
+
* @param literal
|
|
47
|
+
* @returns this for chaining
|
|
48
|
+
*/
|
|
49
|
+
addLiteralArguments(...literals: string[]): ClingoFactBuilder;
|
|
50
|
+
/**
|
|
51
|
+
* Builds the clingo fact
|
|
52
|
+
* @returns The clingo fact as a string
|
|
53
|
+
*/
|
|
54
|
+
build(): string;
|
|
55
|
+
private getValue;
|
|
56
|
+
private encodeArgument;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { INT32_MAX } from './constants.js';
|
|
2
|
+
import { logger } from './log-utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* This function takes care of encoding chars, which might produce issues in clingo
|
|
5
|
+
* This should be done for user provided values
|
|
6
|
+
*/
|
|
7
|
+
export function encodeClingoValue(value) {
|
|
8
|
+
return value.replace(/[\n\\"]/g, (char) => {
|
|
9
|
+
if (char === '\n') {
|
|
10
|
+
return '\\n';
|
|
11
|
+
}
|
|
12
|
+
return `\\${char}`;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export class ClingoFactBuilder {
|
|
16
|
+
predicate;
|
|
17
|
+
end;
|
|
18
|
+
arguments = [];
|
|
19
|
+
constructor(predicate, end = '.') {
|
|
20
|
+
this.predicate = predicate;
|
|
21
|
+
this.end = end;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Adds an argument to the fact
|
|
25
|
+
* @param arg Argument to add. If null, skipped
|
|
26
|
+
* @returns this for chaining
|
|
27
|
+
*/
|
|
28
|
+
addArgument(arg) {
|
|
29
|
+
if (arg === null) {
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
if (typeof arg === 'function') {
|
|
33
|
+
const nestedBuilder = new ClingoFactBuilder('', '');
|
|
34
|
+
this.arguments.push(arg(nestedBuilder));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.arguments.push(arg);
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Helper for adding multiple arguments, because it's common
|
|
43
|
+
* @param args
|
|
44
|
+
* @returns this for chaining
|
|
45
|
+
*/
|
|
46
|
+
addArguments(...args) {
|
|
47
|
+
args.forEach((arg) => this.addArgument(arg));
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Adds a literal argument, which means that it will not have quotes
|
|
52
|
+
* @param literal The literal argument to add
|
|
53
|
+
* @returns this for chaining
|
|
54
|
+
*/
|
|
55
|
+
addLiteralArgument(literal) {
|
|
56
|
+
this.arguments.push(new LiteralBuilder(literal));
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Helper for adding multiple literal arguments, because it's common
|
|
61
|
+
* @param literal
|
|
62
|
+
* @returns this for chaining
|
|
63
|
+
*/
|
|
64
|
+
addLiteralArguments(...literals) {
|
|
65
|
+
literals.forEach((literal) => this.addLiteralArgument(literal));
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Builds the clingo fact
|
|
70
|
+
* @returns The clingo fact as a string
|
|
71
|
+
*/
|
|
72
|
+
build() {
|
|
73
|
+
const encodedArguments = this.arguments
|
|
74
|
+
.map((arg) => arg instanceof ClingoFactBuilder
|
|
75
|
+
? arg.build()
|
|
76
|
+
: this.encodeArgument(arg))
|
|
77
|
+
.join(', ');
|
|
78
|
+
return `${this.predicate}(${encodedArguments})${this.end}`;
|
|
79
|
+
}
|
|
80
|
+
// Function to get the raw value of the argument without encoding or quoting
|
|
81
|
+
getValue(value) {
|
|
82
|
+
if (typeof value === 'boolean') {
|
|
83
|
+
return value ? 'true' : 'false';
|
|
84
|
+
}
|
|
85
|
+
else if (Array.isArray(value)) {
|
|
86
|
+
// Array case, call getValue on each item without quotes
|
|
87
|
+
return value.map((item) => this.getValue(item)).join(',');
|
|
88
|
+
}
|
|
89
|
+
else if (typeof value === 'number') {
|
|
90
|
+
let floored = Math.floor(value);
|
|
91
|
+
if (floored !== value) {
|
|
92
|
+
logger.warn({
|
|
93
|
+
value,
|
|
94
|
+
}, 'Expected a whole number, when transforming a number value to a clingo equivalent. Decimal part removed.');
|
|
95
|
+
}
|
|
96
|
+
const exceedsInt32Max = floored > INT32_MAX;
|
|
97
|
+
if (exceedsInt32Max || floored < -INT32_MAX) {
|
|
98
|
+
logger.warn({
|
|
99
|
+
value,
|
|
100
|
+
}, `Value exceeds the 32-bit signed integer range. The value is too ${exceedsInt32Max ? 'large' : 'small'} to be represented as a 32-bit integer. Using ${exceedsInt32Max ? INT32_MAX : -INT32_MAX} instead.`);
|
|
101
|
+
floored = exceedsInt32Max ? INT32_MAX : -INT32_MAX;
|
|
102
|
+
}
|
|
103
|
+
return floored.toString();
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Main encoding function, handling encoding and adding quotes if necessary
|
|
110
|
+
encodeArgument(arg) {
|
|
111
|
+
let processedValue = this.getValue(arg);
|
|
112
|
+
if (typeof arg === 'string') {
|
|
113
|
+
processedValue = encodeClingoValue(processedValue);
|
|
114
|
+
}
|
|
115
|
+
if (typeof arg === 'boolean' || typeof arg === 'number') {
|
|
116
|
+
return processedValue;
|
|
117
|
+
}
|
|
118
|
+
return `"${processedValue}"`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
class LiteralBuilder extends ClingoFactBuilder {
|
|
122
|
+
build() {
|
|
123
|
+
return this.predicate;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=clingo-fact-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clingo-fact-builder.js","sourceRoot":"","sources":["../../src/utils/clingo-fact-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAwBxC;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;QACxC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,KAAK,IAAI,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,OAAO,iBAAiB;IAClB,SAAS,CAAS;IACpB,GAAG,CAAS;IACZ,SAAS,GAA6B,EAAE,CAAC;IAEjD,YAAY,SAAiB,EAAE,MAAc,GAAG;QAC9C,IAAI,CAAC,S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C,CAAC,CAAC,SAAS,CAAC;YACrD,CAAC;YACD,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,2EAA2E;IACnE,cAAc,CAAC,GAA4C;QACjE,IAAI,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAExC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,cAAc,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAC;QACrD,CAAC;QAED,IAAI,OAAO,GAAG,KAAK,SAAS,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACxD,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,OAAO,IAAI,cAAc,GAAG,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,cAAe,SAAQ,iBAAiB;IAC5C,KAAK;QACH,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Card, ModuleContent } from '../interfaces/project-interfaces.js';
|
|
2
|
+
import type { CardType, FieldType, LinkType, ReportMetadata, TemplateMetadata, Workflow } from '../interfaces/resource-interfaces.js';
|
|
3
|
+
import type { Project } from '../containers/project.js';
|
|
4
|
+
export declare namespace Facts {
|
|
5
|
+
enum Card {
|
|
6
|
+
LABEL = "label",
|
|
7
|
+
LINK = "userLink",
|
|
8
|
+
PARENT = "parent"
|
|
9
|
+
}
|
|
10
|
+
enum Common {
|
|
11
|
+
FIELD = "field",
|
|
12
|
+
MODULE = "module",
|
|
13
|
+
PROJECT = "project"
|
|
14
|
+
}
|
|
15
|
+
enum CardType {
|
|
16
|
+
ALWAYS_VISIBLE_FIELD = "alwaysVisibleField",
|
|
17
|
+
CALCULATED_FIELD = "calculatedField",
|
|
18
|
+
CARD_TYPE = "cardType",
|
|
19
|
+
CUSTOM_FIELD = "customField",
|
|
20
|
+
OPTIONALLY_VISIBLE_FIELD = "optionallyVisibleField"
|
|
21
|
+
}
|
|
22
|
+
enum FieldType {
|
|
23
|
+
ENUM_VALUE = "enumValue",
|
|
24
|
+
FIELD_TYPE = "fieldType"
|
|
25
|
+
}
|
|
26
|
+
enum LinkType {
|
|
27
|
+
LINK_DESTINATION_CARD_TYPE = "linkDestinationCardType",
|
|
28
|
+
LINK_SOURCE_CARD_TYPE = "linkSourceCardType",
|
|
29
|
+
LINK_TYPE = "linkType"
|
|
30
|
+
}
|
|
31
|
+
enum Report {
|
|
32
|
+
REPORT = "report"
|
|
33
|
+
}
|
|
34
|
+
enum Template {
|
|
35
|
+
TEMPLATE = "template"
|
|
36
|
+
}
|
|
37
|
+
enum Workflow {
|
|
38
|
+
WORKFLOW = "workflow",
|
|
39
|
+
WORKFLOW_STATE = "workflowState",
|
|
40
|
+
WORKFLOW_TRANSITION = "workflowTransition"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates Clingo facts for a workflow.
|
|
45
|
+
* @param workflow Workflow metadata
|
|
46
|
+
* @returns clingo facts as a string
|
|
47
|
+
*/
|
|
48
|
+
export declare const createWorkflowFacts: (workflow: Workflow) => string;
|
|
49
|
+
/**
|
|
50
|
+
* Creates Clingo facts for a card.
|
|
51
|
+
* @param card Card information
|
|
52
|
+
* @param project Project information
|
|
53
|
+
* @returns clingo facts as a string
|
|
54
|
+
*/
|
|
55
|
+
export declare const createCardFacts: (card: Card, project: Project) => Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates Clingo facts for a field type.
|
|
58
|
+
* @param fieldType Field type metadata
|
|
59
|
+
* @returns clingo facts as a string
|
|
60
|
+
*/
|
|
61
|
+
export declare const createFieldTypeFacts: (fieldType: FieldType) => string;
|
|
62
|
+
/**
|
|
63
|
+
* Creates Clingo facts for a card type.
|
|
64
|
+
* @param cardType Card type metadata
|
|
65
|
+
* @returns clingo facts as a string
|
|
66
|
+
*/
|
|
67
|
+
export declare const createCardTypeFacts: (cardType: CardType) => string;
|
|
68
|
+
/**
|
|
69
|
+
* Creates Clingo facts for a link type.
|
|
70
|
+
* @param linkType Link type metadata
|
|
71
|
+
* @returns clingo facts as a string
|
|
72
|
+
*/
|
|
73
|
+
export declare const createLinkTypeFacts: (linkType: LinkType) => string;
|
|
74
|
+
/**
|
|
75
|
+
* Creates Clingo facts for a module.
|
|
76
|
+
* @param module Module metadata
|
|
77
|
+
* @returns clingo facts as a string
|
|
78
|
+
*/
|
|
79
|
+
export declare const createModuleFacts: (module: ModuleContent) => string;
|
|
80
|
+
/**
|
|
81
|
+
* Creates Clingo facts for a project.
|
|
82
|
+
* @param projectPrefix Card prefix of the project
|
|
83
|
+
* @returns clingo facts as a string
|
|
84
|
+
*/
|
|
85
|
+
export declare const createProjectFacts: (projectPrefix: string) => string;
|
|
86
|
+
/**
|
|
87
|
+
* Creates Clingo facts for a report.
|
|
88
|
+
* @param report Report metadata
|
|
89
|
+
* @returns clingo facts as a string
|
|
90
|
+
*/
|
|
91
|
+
export declare const createReportFacts: (report: ReportMetadata) => string;
|
|
92
|
+
/**
|
|
93
|
+
* Creates Clingo facts about template.
|
|
94
|
+
* @param template Template metadata
|
|
95
|
+
* @returns clingo facts as a string
|
|
96
|
+
*/
|
|
97
|
+
export declare const createTemplateFacts: (template: TemplateMetadata) => string;
|