@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,550 @@
|
|
|
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
|
+
|
|
14
|
+
import {
|
|
15
|
+
type AllowedClingoType,
|
|
16
|
+
ClingoFactBuilder,
|
|
17
|
+
} from './clingo-fact-builder.js';
|
|
18
|
+
import type { Card, ModuleContent } from '../interfaces/project-interfaces.js';
|
|
19
|
+
import type {
|
|
20
|
+
CardType,
|
|
21
|
+
FieldType,
|
|
22
|
+
Link,
|
|
23
|
+
LinkType,
|
|
24
|
+
ReportMetadata,
|
|
25
|
+
TemplateMetadata,
|
|
26
|
+
Workflow,
|
|
27
|
+
} from '../interfaces/resource-interfaces.js';
|
|
28
|
+
import { ClingoProgramBuilder } from './clingo-program-builder.js';
|
|
29
|
+
import { isPredefinedField } from './constants.js';
|
|
30
|
+
import { isTemplateCard } from '../utils/card-utils.js';
|
|
31
|
+
import type { Project } from '../containers/project.js';
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
34
|
+
export namespace Facts {
|
|
35
|
+
export enum Card {
|
|
36
|
+
LABEL = 'label',
|
|
37
|
+
LINK = 'userLink',
|
|
38
|
+
PARENT = 'parent',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export enum Common {
|
|
42
|
+
FIELD = 'field',
|
|
43
|
+
MODULE = 'module',
|
|
44
|
+
PROJECT = 'project',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export enum CardType {
|
|
48
|
+
ALWAYS_VISIBLE_FIELD = 'alwaysVisibleField',
|
|
49
|
+
CALCULATED_FIELD = 'calculatedField',
|
|
50
|
+
CARD_TYPE = 'cardType',
|
|
51
|
+
CUSTOM_FIELD = 'customField',
|
|
52
|
+
OPTIONALLY_VISIBLE_FIELD = 'optionallyVisibleField',
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export enum FieldType {
|
|
56
|
+
ENUM_VALUE = 'enumValue',
|
|
57
|
+
FIELD_TYPE = 'fieldType',
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export enum LinkType {
|
|
61
|
+
LINK_DESTINATION_CARD_TYPE = 'linkDestinationCardType',
|
|
62
|
+
LINK_SOURCE_CARD_TYPE = 'linkSourceCardType',
|
|
63
|
+
LINK_TYPE = 'linkType',
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export enum Report {
|
|
67
|
+
REPORT = 'report',
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export enum Template {
|
|
71
|
+
TEMPLATE = 'template',
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export enum Workflow {
|
|
75
|
+
WORKFLOW = 'workflow',
|
|
76
|
+
WORKFLOW_STATE = 'workflowState',
|
|
77
|
+
WORKFLOW_TRANSITION = 'workflowTransition',
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Compares two index values.
|
|
82
|
+
function compareIndex(a: number, b: number): number {
|
|
83
|
+
if (a === -1 && b === -1) {
|
|
84
|
+
return 0;
|
|
85
|
+
} else if (a === -1) {
|
|
86
|
+
return 1;
|
|
87
|
+
} else if (b === -1) {
|
|
88
|
+
return -1;
|
|
89
|
+
}
|
|
90
|
+
return a - b;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Creates Clingo facts for a workflow.
|
|
95
|
+
* @param workflow Workflow metadata
|
|
96
|
+
* @returns clingo facts as a string
|
|
97
|
+
*/
|
|
98
|
+
export const createWorkflowFacts = (workflow: Workflow) => {
|
|
99
|
+
const builder = new ClingoProgramBuilder().addFact(
|
|
100
|
+
Facts.Workflow.WORKFLOW,
|
|
101
|
+
workflow.name,
|
|
102
|
+
);
|
|
103
|
+
// add states
|
|
104
|
+
for (const state of workflow.states) {
|
|
105
|
+
if (state.category) {
|
|
106
|
+
builder.addFact(
|
|
107
|
+
Facts.Workflow.WORKFLOW_STATE,
|
|
108
|
+
workflow.name,
|
|
109
|
+
state.name,
|
|
110
|
+
state.category,
|
|
111
|
+
);
|
|
112
|
+
} else {
|
|
113
|
+
builder.addFact(Facts.Workflow.WORKFLOW_STATE, workflow.name, state.name);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// add transitions
|
|
118
|
+
for (const transition of workflow.transitions) {
|
|
119
|
+
for (const from of transition.fromState) {
|
|
120
|
+
builder.addFact(
|
|
121
|
+
Facts.Workflow.WORKFLOW_TRANSITION,
|
|
122
|
+
workflow.name,
|
|
123
|
+
transition.name,
|
|
124
|
+
from,
|
|
125
|
+
transition.toState,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
if (transition.fromState.length === 0) {
|
|
129
|
+
builder.addFact(
|
|
130
|
+
Facts.Workflow.WORKFLOW_TRANSITION,
|
|
131
|
+
workflow.name,
|
|
132
|
+
transition.name,
|
|
133
|
+
'',
|
|
134
|
+
transition.toState,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return builder.buildAll();
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates Clingo facts for a card.
|
|
143
|
+
* @param card Card information
|
|
144
|
+
* @param project Project information
|
|
145
|
+
* @returns clingo facts as a string
|
|
146
|
+
*/
|
|
147
|
+
export const createCardFacts = async (card: Card, project: Project) => {
|
|
148
|
+
// Small helper to deduce parent path
|
|
149
|
+
function parentPath(cardPath: string) {
|
|
150
|
+
const pathParts = cardPath.split(sep);
|
|
151
|
+
if (pathParts.at(pathParts.length - 2) === 'cardRoot') {
|
|
152
|
+
return '';
|
|
153
|
+
} else {
|
|
154
|
+
return pathParts.at(pathParts.length - 3);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Helper to deduce template parent path.
|
|
159
|
+
function parentPathFromTemplate(card: Card) {
|
|
160
|
+
const cardPath = card.path;
|
|
161
|
+
const pathParts = cardPath.split(sep);
|
|
162
|
+
if (pathParts.length <= 6) {
|
|
163
|
+
// template or module template paths should have a minimum of seven parts.
|
|
164
|
+
return '';
|
|
165
|
+
}
|
|
166
|
+
if (isTemplateCard(card)) {
|
|
167
|
+
// Parent is a card
|
|
168
|
+
if (pathParts.at(pathParts.length - 4) === 'c') {
|
|
169
|
+
return pathParts.at(pathParts.length - 3);
|
|
170
|
+
}
|
|
171
|
+
// Parent is a template
|
|
172
|
+
const prefix =
|
|
173
|
+
pathParts.at(pathParts.length - 5) === 'local'
|
|
174
|
+
? project.projectPrefix
|
|
175
|
+
: pathParts.at(pathParts.length - 5);
|
|
176
|
+
const resourceType = pathParts.at(pathParts.length - 4);
|
|
177
|
+
const templateName = pathParts.at(pathParts.length - 3);
|
|
178
|
+
return `"${prefix}/${resourceType}/${templateName}"`;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const parentsPath = isTemplateCard(card)
|
|
183
|
+
? parentPathFromTemplate(card)
|
|
184
|
+
: parentPath(card.path);
|
|
185
|
+
const builder = new ClingoProgramBuilder().addComment(card.key);
|
|
186
|
+
|
|
187
|
+
if (card.metadata) {
|
|
188
|
+
for (const [field, value] of Object.entries(card.metadata)) {
|
|
189
|
+
if (field === 'labels') {
|
|
190
|
+
for (const label of value as Array<string>) {
|
|
191
|
+
builder.addCustomFact(Facts.Card.LABEL, (b) =>
|
|
192
|
+
b.addLiteralArgument(card.key).addArgument(label),
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
} else if (field === 'links') {
|
|
196
|
+
for (const link of value as Link[]) {
|
|
197
|
+
builder.addCustomFact(Facts.Card.LINK, (b) =>
|
|
198
|
+
b
|
|
199
|
+
.addLiteralArguments(card.key, link.cardKey)
|
|
200
|
+
.addArguments(link.linkType, link.linkDescription ?? null),
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
// Do not write null values
|
|
205
|
+
if (value == null) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
// field might be a non-custom field, which cannot use the fieldType method
|
|
209
|
+
|
|
210
|
+
let clingoValue: AllowedClingoType = value.toString();
|
|
211
|
+
|
|
212
|
+
if (!isPredefinedField(field)) {
|
|
213
|
+
// field is a custom field, find it
|
|
214
|
+
const fieldType = await project.resource<FieldType>(field);
|
|
215
|
+
if (!fieldType) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// if it's a list, let's generate multiple values
|
|
220
|
+
if (fieldType.dataType === 'list') {
|
|
221
|
+
if (!Array.isArray(value)) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
for (const listValue of value) {
|
|
225
|
+
builder.addCustomFact(Facts.Common.FIELD, (b) =>
|
|
226
|
+
b
|
|
227
|
+
.addLiteralArgument(card.key)
|
|
228
|
+
.addArguments(field, listValue.toString()),
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
clingoValue =
|
|
235
|
+
fieldType.dataType === 'integer'
|
|
236
|
+
? (value as number)
|
|
237
|
+
: value.toString();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
builder.addCustomFact(Facts.Common.FIELD, (b) =>
|
|
241
|
+
b.addLiteralArgument(card.key).addArguments(field, clingoValue),
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (parentsPath !== undefined && parentsPath !== '') {
|
|
248
|
+
builder.addCustomFact(Facts.Card.PARENT, (b) =>
|
|
249
|
+
b.addLiteralArguments(card.key, parentsPath),
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return builder.buildAll();
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Creates Clingo facts for a field type.
|
|
258
|
+
* @param fieldType Field type metadata
|
|
259
|
+
* @returns clingo facts as a string
|
|
260
|
+
*/
|
|
261
|
+
export const createFieldTypeFacts = (fieldType: FieldType) => {
|
|
262
|
+
const builder = new ClingoProgramBuilder();
|
|
263
|
+
builder.addFact(Facts.FieldType.FIELD_TYPE, fieldType.name);
|
|
264
|
+
|
|
265
|
+
if (fieldType.displayName)
|
|
266
|
+
builder.addFact(
|
|
267
|
+
Facts.Common.FIELD,
|
|
268
|
+
fieldType.name,
|
|
269
|
+
'displayName',
|
|
270
|
+
fieldType.displayName,
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
if (fieldType.fieldDescription)
|
|
274
|
+
builder.addFact(
|
|
275
|
+
Facts.Common.FIELD,
|
|
276
|
+
fieldType.name,
|
|
277
|
+
'fieldDescription',
|
|
278
|
+
fieldType.fieldDescription,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
builder.addFact(
|
|
282
|
+
Facts.Common.FIELD,
|
|
283
|
+
fieldType.name,
|
|
284
|
+
'dataType',
|
|
285
|
+
fieldType.dataType,
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
if (fieldType.enumValues) {
|
|
289
|
+
let index = 1;
|
|
290
|
+
for (const enumValue of fieldType.enumValues) {
|
|
291
|
+
builder.addFact(
|
|
292
|
+
Facts.FieldType.ENUM_VALUE,
|
|
293
|
+
fieldType.name,
|
|
294
|
+
enumValue.enumValue,
|
|
295
|
+
);
|
|
296
|
+
builder.addCustomFact(Facts.Common.FIELD, (b) =>
|
|
297
|
+
b
|
|
298
|
+
.addArgument((key) =>
|
|
299
|
+
key.addArguments(fieldType.name, enumValue.enumValue),
|
|
300
|
+
)
|
|
301
|
+
.addArguments('index', index++),
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const keyTuple = new ClingoFactBuilder('', '').addArguments(
|
|
305
|
+
fieldType.name,
|
|
306
|
+
enumValue.enumValue,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
if (enumValue.enumDisplayValue)
|
|
310
|
+
builder.addCustomFact(Facts.Common.FIELD, (b) =>
|
|
311
|
+
b
|
|
312
|
+
.addArgument(keyTuple)
|
|
313
|
+
.addArguments('enumDisplayValue', enumValue.enumDisplayValue!),
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
if (enumValue.enumDescription)
|
|
317
|
+
builder.addCustomFact(Facts.Common.FIELD, (b) =>
|
|
318
|
+
b
|
|
319
|
+
.addArgument(keyTuple)
|
|
320
|
+
.addArguments('enumDescription', enumValue.enumDescription!),
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return builder.buildAll();
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Creates Clingo facts for a card type.
|
|
329
|
+
* @param cardType Card type metadata
|
|
330
|
+
* @returns clingo facts as a string
|
|
331
|
+
*/
|
|
332
|
+
export const createCardTypeFacts = (cardType: CardType) => {
|
|
333
|
+
const builder = new ClingoProgramBuilder();
|
|
334
|
+
|
|
335
|
+
builder.addFact(Facts.CardType.CARD_TYPE, cardType.name);
|
|
336
|
+
|
|
337
|
+
builder.addFact(
|
|
338
|
+
Facts.Common.FIELD,
|
|
339
|
+
cardType.name,
|
|
340
|
+
'workflow',
|
|
341
|
+
cardType.workflow,
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
const customFields = cardType.customFields.toSorted((a, b) => {
|
|
345
|
+
const aFirstIndex = cardType.alwaysVisibleFields.indexOf(a.name);
|
|
346
|
+
const bFirstIndex = cardType.alwaysVisibleFields.indexOf(b.name);
|
|
347
|
+
|
|
348
|
+
const aSecondIndex = cardType.optionallyVisibleFields.indexOf(a.name);
|
|
349
|
+
const bSecondIndex = cardType.optionallyVisibleFields.indexOf(b.name);
|
|
350
|
+
|
|
351
|
+
return compareIndex(aFirstIndex, bFirstIndex) === 0
|
|
352
|
+
? compareIndex(aSecondIndex, bSecondIndex)
|
|
353
|
+
: compareIndex(aFirstIndex, bFirstIndex);
|
|
354
|
+
});
|
|
355
|
+
let index = 1;
|
|
356
|
+
for (const customField of customFields) {
|
|
357
|
+
builder.addFact(
|
|
358
|
+
Facts.CardType.CUSTOM_FIELD,
|
|
359
|
+
cardType.name,
|
|
360
|
+
customField.name,
|
|
361
|
+
);
|
|
362
|
+
const keyTuple = new ClingoFactBuilder('', '').addArguments(
|
|
363
|
+
cardType.name,
|
|
364
|
+
customField.name,
|
|
365
|
+
);
|
|
366
|
+
if (customField.displayName) {
|
|
367
|
+
builder.addCustomFact(Facts.Common.FIELD, (b) =>
|
|
368
|
+
b.addArgument(keyTuple).addArguments(
|
|
369
|
+
'displayName',
|
|
370
|
+
customField.displayName as string, // not sure why type check doesn't get this
|
|
371
|
+
),
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
if (customField.isCalculated) {
|
|
375
|
+
builder.addFact(
|
|
376
|
+
Facts.CardType.CALCULATED_FIELD,
|
|
377
|
+
cardType.name,
|
|
378
|
+
customField.name,
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
let visible = false;
|
|
383
|
+
if (cardType.alwaysVisibleFields.includes(customField.name)) {
|
|
384
|
+
builder.addFact(
|
|
385
|
+
Facts.CardType.ALWAYS_VISIBLE_FIELD,
|
|
386
|
+
cardType.name,
|
|
387
|
+
customField.name,
|
|
388
|
+
);
|
|
389
|
+
visible = true;
|
|
390
|
+
}
|
|
391
|
+
if (cardType.optionallyVisibleFields.includes(customField.name)) {
|
|
392
|
+
builder.addFact(
|
|
393
|
+
Facts.CardType.OPTIONALLY_VISIBLE_FIELD,
|
|
394
|
+
cardType.name,
|
|
395
|
+
customField.name,
|
|
396
|
+
);
|
|
397
|
+
visible = true;
|
|
398
|
+
}
|
|
399
|
+
if (visible) {
|
|
400
|
+
builder.addCustomFact(Facts.Common.FIELD, (b) =>
|
|
401
|
+
b
|
|
402
|
+
.addArgument((key) =>
|
|
403
|
+
key.addArguments(cardType.name, customField.name),
|
|
404
|
+
)
|
|
405
|
+
.addArguments('index', index++),
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return builder.buildAll();
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Creates Clingo facts for a link type.
|
|
414
|
+
* @param linkType Link type metadata
|
|
415
|
+
* @returns clingo facts as a string
|
|
416
|
+
*/
|
|
417
|
+
export const createLinkTypeFacts = (linkType: LinkType) => {
|
|
418
|
+
const builder = new ClingoProgramBuilder()
|
|
419
|
+
.addFact(Facts.LinkType.LINK_TYPE, linkType.name)
|
|
420
|
+
.addFact(
|
|
421
|
+
Facts.Common.FIELD,
|
|
422
|
+
linkType.name,
|
|
423
|
+
'outboundDisplayName',
|
|
424
|
+
linkType.outboundDisplayName,
|
|
425
|
+
)
|
|
426
|
+
.addFact(
|
|
427
|
+
Facts.Common.FIELD,
|
|
428
|
+
linkType.name,
|
|
429
|
+
'inboundDisplayName',
|
|
430
|
+
linkType.inboundDisplayName,
|
|
431
|
+
)
|
|
432
|
+
.addFact(
|
|
433
|
+
Facts.Common.FIELD,
|
|
434
|
+
linkType.name,
|
|
435
|
+
'enableLinkDescription',
|
|
436
|
+
linkType.enableLinkDescription,
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
for (const sourceCardType of linkType.sourceCardTypes) {
|
|
440
|
+
builder.addFact(
|
|
441
|
+
Facts.LinkType.LINK_SOURCE_CARD_TYPE,
|
|
442
|
+
linkType.name,
|
|
443
|
+
sourceCardType,
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
for (const destinationCardType of linkType.destinationCardTypes) {
|
|
448
|
+
builder.addFact(
|
|
449
|
+
Facts.LinkType.LINK_DESTINATION_CARD_TYPE,
|
|
450
|
+
linkType.name,
|
|
451
|
+
destinationCardType,
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return builder.buildAll();
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Creates Clingo facts for a module.
|
|
460
|
+
* @param module Module metadata
|
|
461
|
+
* @returns clingo facts as a string
|
|
462
|
+
*/
|
|
463
|
+
export const createModuleFacts = (module: ModuleContent) => {
|
|
464
|
+
const builder = new ClingoProgramBuilder();
|
|
465
|
+
builder.addFact(Facts.Common.MODULE, module.cardKeyPrefix);
|
|
466
|
+
builder.addFact(
|
|
467
|
+
Facts.Common.FIELD,
|
|
468
|
+
module.cardKeyPrefix,
|
|
469
|
+
'name',
|
|
470
|
+
module.name,
|
|
471
|
+
);
|
|
472
|
+
return builder.buildAll();
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Creates Clingo facts for a project.
|
|
477
|
+
* @param projectPrefix Card prefix of the project
|
|
478
|
+
* @returns clingo facts as a string
|
|
479
|
+
*/
|
|
480
|
+
export const createProjectFacts = (projectPrefix: string) => {
|
|
481
|
+
const builder = new ClingoProgramBuilder();
|
|
482
|
+
builder.addFact(Facts.Common.PROJECT, projectPrefix);
|
|
483
|
+
return builder.buildAll();
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Creates Clingo facts for a report.
|
|
488
|
+
* @param report Report metadata
|
|
489
|
+
* @returns clingo facts as a string
|
|
490
|
+
*/
|
|
491
|
+
export const createReportFacts = (report: ReportMetadata) => {
|
|
492
|
+
const builder = new ClingoProgramBuilder();
|
|
493
|
+
builder.addFact(Facts.Report.REPORT, report.name);
|
|
494
|
+
|
|
495
|
+
if (report.displayName)
|
|
496
|
+
builder.addFact(
|
|
497
|
+
Facts.Common.FIELD,
|
|
498
|
+
report.name,
|
|
499
|
+
'displayName',
|
|
500
|
+
report.displayName,
|
|
501
|
+
);
|
|
502
|
+
if (report.description)
|
|
503
|
+
builder.addFact(
|
|
504
|
+
Facts.Common.FIELD,
|
|
505
|
+
report.name,
|
|
506
|
+
'description',
|
|
507
|
+
report.description,
|
|
508
|
+
);
|
|
509
|
+
if (report.category)
|
|
510
|
+
builder.addFact(
|
|
511
|
+
Facts.Common.FIELD,
|
|
512
|
+
report.name,
|
|
513
|
+
'category',
|
|
514
|
+
report.category,
|
|
515
|
+
);
|
|
516
|
+
return builder.buildAll();
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Creates Clingo facts about template.
|
|
521
|
+
* @param template Template metadata
|
|
522
|
+
* @returns clingo facts as a string
|
|
523
|
+
*/
|
|
524
|
+
export const createTemplateFacts = (template: TemplateMetadata) => {
|
|
525
|
+
const builder = new ClingoProgramBuilder();
|
|
526
|
+
builder.addFact(Facts.Template.TEMPLATE, template.name);
|
|
527
|
+
|
|
528
|
+
if (template.displayName)
|
|
529
|
+
builder.addFact(
|
|
530
|
+
Facts.Common.FIELD,
|
|
531
|
+
template.name,
|
|
532
|
+
'displayName',
|
|
533
|
+
template.displayName,
|
|
534
|
+
);
|
|
535
|
+
if (template.description)
|
|
536
|
+
builder.addFact(
|
|
537
|
+
Facts.Common.FIELD,
|
|
538
|
+
template.name,
|
|
539
|
+
'description',
|
|
540
|
+
template.description,
|
|
541
|
+
);
|
|
542
|
+
if (template.category)
|
|
543
|
+
builder.addFact(
|
|
544
|
+
Facts.Common.FIELD,
|
|
545
|
+
template.name,
|
|
546
|
+
'category',
|
|
547
|
+
template.category,
|
|
548
|
+
);
|
|
549
|
+
return builder.buildAll();
|
|
550
|
+
};
|