@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,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* This function reverses the encoding made by the "encodeClingoValue" function
|
|
14
|
+
*/
|
|
15
|
+
export function decodeClingoValue(value) {
|
|
16
|
+
return value.replace(/\\([n\\"])/g, (_, char) => {
|
|
17
|
+
if (char === 'n') {
|
|
18
|
+
return '\n';
|
|
19
|
+
}
|
|
20
|
+
return char;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
class ClingoParser {
|
|
24
|
+
keywords = [
|
|
25
|
+
'queryError',
|
|
26
|
+
'result',
|
|
27
|
+
'childResult',
|
|
28
|
+
'field',
|
|
29
|
+
'enumField',
|
|
30
|
+
'listField',
|
|
31
|
+
'label',
|
|
32
|
+
'link',
|
|
33
|
+
'transitionDenied',
|
|
34
|
+
'movingCardDenied',
|
|
35
|
+
'deletingCardDenied',
|
|
36
|
+
'editingFieldDenied',
|
|
37
|
+
'editingContentDenied',
|
|
38
|
+
'notification',
|
|
39
|
+
'policyCheckFailure',
|
|
40
|
+
'policyCheckSuccess',
|
|
41
|
+
'order',
|
|
42
|
+
];
|
|
43
|
+
result = {
|
|
44
|
+
results: [],
|
|
45
|
+
error: null,
|
|
46
|
+
};
|
|
47
|
+
// The queue now stores the parameters instead of functions
|
|
48
|
+
resultQueue = [];
|
|
49
|
+
childResultQueue = [];
|
|
50
|
+
tempResults = {};
|
|
51
|
+
orderQueue = [];
|
|
52
|
+
collections = new Set();
|
|
53
|
+
reset() {
|
|
54
|
+
this.result = {
|
|
55
|
+
results: [],
|
|
56
|
+
error: null,
|
|
57
|
+
};
|
|
58
|
+
this.resultQueue = [];
|
|
59
|
+
this.childResultQueue = [];
|
|
60
|
+
this.tempResults = {};
|
|
61
|
+
this.orderQueue = [];
|
|
62
|
+
this.collections = new Set();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Command handlers for each possible keyword
|
|
66
|
+
* All of them will get parameters as strings
|
|
67
|
+
* You can trust that clingo will always provide the correct number of parameters / types
|
|
68
|
+
*/
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
70
|
+
commandHandlers = {
|
|
71
|
+
queryError: (message, ...params) => {
|
|
72
|
+
this.result.error = `${message}${params.length > 1 ? ` ${params.join(', ')}` : ''}`;
|
|
73
|
+
},
|
|
74
|
+
result: (key) => {
|
|
75
|
+
this.resultQueue.push({ key });
|
|
76
|
+
},
|
|
77
|
+
childResult: (parentKey, childKey, collection) => {
|
|
78
|
+
this.childResultQueue.push({ parentKey, childKey, collection });
|
|
79
|
+
this.collections.add(collection);
|
|
80
|
+
},
|
|
81
|
+
enumField: async (key, fieldName, fieldValue, index, displayValue) => {
|
|
82
|
+
const res = this.getOrInitResult(key);
|
|
83
|
+
const decoded = decodeClingoValue(fieldValue);
|
|
84
|
+
const parsedIndex = parseInt(index, 10);
|
|
85
|
+
res[fieldName] = {
|
|
86
|
+
value: decoded,
|
|
87
|
+
index: parsedIndex,
|
|
88
|
+
displayValue,
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
// NOTE: Must be tested in INTDEV-623
|
|
92
|
+
listField: async (key, fieldName, fieldValue, index, displayValue) => {
|
|
93
|
+
const res = this.getOrInitResult(key);
|
|
94
|
+
const decoded = decodeClingoValue(fieldValue);
|
|
95
|
+
if (!res[fieldName] || !Array.isArray(res[fieldName])) {
|
|
96
|
+
res[fieldName] = [];
|
|
97
|
+
}
|
|
98
|
+
const parsedIndex = parseInt(index, 10);
|
|
99
|
+
res[fieldName].push({
|
|
100
|
+
value: decoded,
|
|
101
|
+
index: parsedIndex,
|
|
102
|
+
displayValue,
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
field: async (key, fieldName, fieldValue, dataType) => {
|
|
106
|
+
const res = this.getOrInitResult(key);
|
|
107
|
+
const decoded = decodeClingoValue(fieldValue);
|
|
108
|
+
switch (dataType) {
|
|
109
|
+
case 'shortText':
|
|
110
|
+
case 'longText':
|
|
111
|
+
case 'person':
|
|
112
|
+
case 'date':
|
|
113
|
+
case 'dateTime':
|
|
114
|
+
res[fieldName] = decoded;
|
|
115
|
+
break;
|
|
116
|
+
case 'number':
|
|
117
|
+
res[fieldName] = parseFloat(decoded);
|
|
118
|
+
break;
|
|
119
|
+
case 'integer':
|
|
120
|
+
res[fieldName] = parseInt(decoded, 10);
|
|
121
|
+
break;
|
|
122
|
+
case 'boolean':
|
|
123
|
+
res[fieldName] = fieldValue === 'true';
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
label: (key, label) => {
|
|
128
|
+
const res = this.getOrInitResult(key);
|
|
129
|
+
res.labels.push(label);
|
|
130
|
+
},
|
|
131
|
+
link: (key, // key is the card itself
|
|
132
|
+
cardKey, // cardKey is otherCard this is being linked to
|
|
133
|
+
title, linkType, displayName, direction, linkSource, linkDescription) => {
|
|
134
|
+
const res = this.getOrInitResult(key);
|
|
135
|
+
res.links.push({
|
|
136
|
+
key: cardKey,
|
|
137
|
+
linkType,
|
|
138
|
+
displayName,
|
|
139
|
+
linkDescription,
|
|
140
|
+
direction,
|
|
141
|
+
linkSource,
|
|
142
|
+
title,
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
transitionDenied: (key, transitionName, errorMessage) => {
|
|
146
|
+
const res = this.getOrInitResult(key);
|
|
147
|
+
res.deniedOperations.transition.push({ transitionName, errorMessage });
|
|
148
|
+
},
|
|
149
|
+
movingCardDenied: (key, errorMessage) => {
|
|
150
|
+
const res = this.getOrInitResult(key);
|
|
151
|
+
res.deniedOperations.move.push({ errorMessage });
|
|
152
|
+
},
|
|
153
|
+
deletingCardDenied: (key, errorMessage) => {
|
|
154
|
+
const res = this.getOrInitResult(key);
|
|
155
|
+
res.deniedOperations.delete.push({ errorMessage });
|
|
156
|
+
},
|
|
157
|
+
editingFieldDenied: (key, fieldName, errorMessage) => {
|
|
158
|
+
const res = this.getOrInitResult(key);
|
|
159
|
+
res.deniedOperations.editField.push({ fieldName, errorMessage });
|
|
160
|
+
},
|
|
161
|
+
editingContentDenied: (key, errorMessage) => {
|
|
162
|
+
const res = this.getOrInitResult(key);
|
|
163
|
+
res.deniedOperations.editContent.push({ errorMessage });
|
|
164
|
+
},
|
|
165
|
+
notification: (key, category, title, message) => {
|
|
166
|
+
const res = this.getOrInitResult(key);
|
|
167
|
+
res.notifications.push({ key, category, title, message });
|
|
168
|
+
},
|
|
169
|
+
policyCheckFailure: (key, category, title, errorMessage, fieldName) => {
|
|
170
|
+
const res = this.getOrInitResult(key);
|
|
171
|
+
res.policyChecks.failures.push({
|
|
172
|
+
category,
|
|
173
|
+
title,
|
|
174
|
+
errorMessage,
|
|
175
|
+
fieldName,
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
policyCheckSuccess: (key, category, title) => {
|
|
179
|
+
const res = this.getOrInitResult(key);
|
|
180
|
+
res.policyChecks.successes.push({ category, title });
|
|
181
|
+
},
|
|
182
|
+
order: (level, collection, fieldIndex, field, direction) => {
|
|
183
|
+
const parsedLevel = parseInt(level, 10);
|
|
184
|
+
const parsedFieldIndex = parseInt(fieldIndex, 10);
|
|
185
|
+
this.orderQueue.push({
|
|
186
|
+
level: parsedLevel,
|
|
187
|
+
collection,
|
|
188
|
+
fieldIndex: parsedFieldIndex,
|
|
189
|
+
field,
|
|
190
|
+
direction,
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
getOrInitResult(key) {
|
|
195
|
+
if (!this.tempResults[key]) {
|
|
196
|
+
this.tempResults[key] = {
|
|
197
|
+
key,
|
|
198
|
+
labels: [],
|
|
199
|
+
links: [],
|
|
200
|
+
notifications: [],
|
|
201
|
+
policyChecks: { successes: [], failures: [] },
|
|
202
|
+
deniedOperations: {
|
|
203
|
+
transition: [],
|
|
204
|
+
move: [],
|
|
205
|
+
delete: [],
|
|
206
|
+
editField: [],
|
|
207
|
+
editContent: [],
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return this.tempResults[key];
|
|
212
|
+
}
|
|
213
|
+
sortByLevel(results, level = 1, currentCollection) {
|
|
214
|
+
const levelOrders = this.orderQueue
|
|
215
|
+
.filter((order) => order.level === level &&
|
|
216
|
+
(currentCollection ? order.collection === currentCollection : true))
|
|
217
|
+
.sort((a, b) => a.fieldIndex - b.fieldIndex);
|
|
218
|
+
// Apply sorting instructions for this level/collection if any
|
|
219
|
+
if (levelOrders.length > 0) {
|
|
220
|
+
results.sort((a, b) => {
|
|
221
|
+
for (const { field, direction } of levelOrders) {
|
|
222
|
+
const sortOrder = direction === 'ASC' ? -1 : 1;
|
|
223
|
+
const firstValue = this.getComparableValue(a[field]);
|
|
224
|
+
const secondValue = this.getComparableValue(b[field]);
|
|
225
|
+
if (firstValue == null && secondValue == null) {
|
|
226
|
+
continue; // both are null, move on to next field
|
|
227
|
+
}
|
|
228
|
+
else if (firstValue == null) {
|
|
229
|
+
return sortOrder; // first is considered less
|
|
230
|
+
}
|
|
231
|
+
else if (secondValue == null) {
|
|
232
|
+
return -sortOrder; // second is considered less
|
|
233
|
+
}
|
|
234
|
+
// Regular comparison
|
|
235
|
+
if (firstValue < secondValue)
|
|
236
|
+
return sortOrder;
|
|
237
|
+
if (firstValue > secondValue)
|
|
238
|
+
return -sortOrder;
|
|
239
|
+
// if equal, try next field
|
|
240
|
+
}
|
|
241
|
+
// if all fields equal
|
|
242
|
+
return 0;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
// Recursively sort all known child collections
|
|
246
|
+
for (const result of results) {
|
|
247
|
+
for (const childCollection of this.collections) {
|
|
248
|
+
const childResults = result[childCollection];
|
|
249
|
+
if (Array.isArray(childResults)) {
|
|
250
|
+
this.sortByLevel(childResults, level + 1, childCollection);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
getComparableValue(value) {
|
|
256
|
+
if (value == null) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
if (typeof value === 'object' &&
|
|
260
|
+
'index' in value &&
|
|
261
|
+
typeof value.index === 'number') {
|
|
262
|
+
return value.index;
|
|
263
|
+
}
|
|
264
|
+
if (Array.isArray(value)) {
|
|
265
|
+
const indeces = [];
|
|
266
|
+
for (const item of value) {
|
|
267
|
+
if (item != null &&
|
|
268
|
+
typeof item === 'object' &&
|
|
269
|
+
'index' in item &&
|
|
270
|
+
typeof item.index === 'number') {
|
|
271
|
+
indeces.push(item.index);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return Math.min(...indeces);
|
|
275
|
+
}
|
|
276
|
+
return value;
|
|
277
|
+
}
|
|
278
|
+
applyResultProcessing() {
|
|
279
|
+
// Process results and parent-child relationships
|
|
280
|
+
this.resultQueue.forEach(({ key }) => {
|
|
281
|
+
const res = this.getOrInitResult(key);
|
|
282
|
+
this.result.results.push(res); // Here we assume the query is correct and returns the data specified by the query
|
|
283
|
+
});
|
|
284
|
+
this.childResultQueue.forEach(({ parentKey, childKey, collection }) => {
|
|
285
|
+
const parent = this.getOrInitResult(parentKey);
|
|
286
|
+
const child = this.getOrInitResult(childKey);
|
|
287
|
+
if (!parent[collection] || !Array.isArray(parent[collection])) {
|
|
288
|
+
parent[collection] = [];
|
|
289
|
+
}
|
|
290
|
+
parent[collection].push(child);
|
|
291
|
+
});
|
|
292
|
+
this.sortByLevel(this.result.results);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* This methods is responsible for converting clingo output to a parsed object
|
|
296
|
+
* @param input clingo input to parse
|
|
297
|
+
* @returns
|
|
298
|
+
*/
|
|
299
|
+
async parseInput(input) {
|
|
300
|
+
let position = 0;
|
|
301
|
+
while (position < input.length) {
|
|
302
|
+
const keywordMatch = this.findKeyword(input, position);
|
|
303
|
+
if (!keywordMatch) {
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
const { keyword, endIndex } = keywordMatch;
|
|
307
|
+
position = endIndex;
|
|
308
|
+
const parsed = this.parseArguments(input, position);
|
|
309
|
+
if (parsed) {
|
|
310
|
+
// Apply the command handler with sanitized arguments
|
|
311
|
+
await this.commandHandlers[keyword](...parsed.args);
|
|
312
|
+
position = parsed.endPosition; // move position after the argument closing parenthesis
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
this.applyResultProcessing();
|
|
316
|
+
const result = this.result;
|
|
317
|
+
// Reset the parser state
|
|
318
|
+
this.reset();
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* This method finds the next keyword in a string after a specified point
|
|
323
|
+
* @param input The string which it being searched
|
|
324
|
+
* @param start The position from which to start the search from
|
|
325
|
+
* @returns
|
|
326
|
+
*/
|
|
327
|
+
findKeyword(input, start) {
|
|
328
|
+
// Create a regex dynamically from the keywords list
|
|
329
|
+
const regex = new RegExp(`(${this.keywords.join('|')})\\(`, 'g');
|
|
330
|
+
// Apply the regex starting from the current position
|
|
331
|
+
regex.lastIndex = start;
|
|
332
|
+
const match = regex.exec(input);
|
|
333
|
+
if (match) {
|
|
334
|
+
return {
|
|
335
|
+
keyword: match[1], // The matched keyword (first capture group)
|
|
336
|
+
startIndex: match.index, // Position of the matched keyword
|
|
337
|
+
endIndex: match.index + match[0].length, // Position after the keyword and opening parenthesis
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* This method is a custom parser, which takes in the whole clingo output and parses the arguments.
|
|
344
|
+
* Note: Do not decode in this function. It will be handled on a higher level.
|
|
345
|
+
* As long as this function returns valid clingo, it has done it's responsibility
|
|
346
|
+
* @param input Clingo output
|
|
347
|
+
* @param position Position of the command being parsed inside the string
|
|
348
|
+
* @returns
|
|
349
|
+
*/
|
|
350
|
+
parseArguments(input, position) {
|
|
351
|
+
let currentArg = '';
|
|
352
|
+
const args = [];
|
|
353
|
+
let insideQuote = false;
|
|
354
|
+
// calculates how deep into parenthesis we are
|
|
355
|
+
let insideParanthesis = 0;
|
|
356
|
+
for (let i = position; i < input.length; i++) {
|
|
357
|
+
const char = input[i];
|
|
358
|
+
if (char === '"') {
|
|
359
|
+
if (i !== 0 && input[i - 1] === '\\') {
|
|
360
|
+
currentArg += '"';
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (!insideQuote && insideParanthesis === 0) {
|
|
364
|
+
// We can ignore the chars, which are before a quoted string
|
|
365
|
+
currentArg = '';
|
|
366
|
+
}
|
|
367
|
+
insideQuote = !insideQuote; // Toggle inside/outside quotes
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (char === ',' && !insideQuote) {
|
|
371
|
+
if (insideParanthesis > 0) {
|
|
372
|
+
currentArg += char;
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
args.push(currentArg);
|
|
376
|
+
currentArg = '';
|
|
377
|
+
insideParanthesis = 0;
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (char === '(' && !insideQuote) {
|
|
381
|
+
if (insideParanthesis === 0) {
|
|
382
|
+
currentArg = '';
|
|
383
|
+
}
|
|
384
|
+
insideParanthesis++;
|
|
385
|
+
}
|
|
386
|
+
if (char === ')' && !insideQuote) {
|
|
387
|
+
if (insideParanthesis-- !== 0) {
|
|
388
|
+
currentArg += char;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
args.push(currentArg);
|
|
392
|
+
return {
|
|
393
|
+
args,
|
|
394
|
+
endPosition: i + 1,
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
currentArg += char;
|
|
398
|
+
}
|
|
399
|
+
return null; // No valid arguments found
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
export default ClingoParser;
|
|
403
|
+
//# sourceMappingURL=clingo-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clingo-parser.js","sourceRoot":"","sources":["../../src/utils/clingo-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;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;YAED,UAAU,IAAI,IAAI,CAAC;QACrB,CAAC;QAED,OAAO,IAAI,CAAC,CAAC,2BAA2B;IAC1C,CAAC;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
import { type ClingoArgument, ClingoFactBuilder } from './clingo-fact-builder.js';
|
|
13
|
+
export declare class ClingoProgramBuilder {
|
|
14
|
+
private rows;
|
|
15
|
+
/**
|
|
16
|
+
* Adds a new fact with a simple configuration.
|
|
17
|
+
* @param predicate - The fact's predicate
|
|
18
|
+
* @param args - The fact's arguments
|
|
19
|
+
*/
|
|
20
|
+
addFact(predicate: string, ...args: ClingoArgument[]): ClingoProgramBuilder;
|
|
21
|
+
/**
|
|
22
|
+
* Adds a custom fact allowing use of the builder methods directly for more control.
|
|
23
|
+
* @param predicate - The fact's predicate
|
|
24
|
+
* @param configure - Function to configure the fact with builder methods
|
|
25
|
+
*/
|
|
26
|
+
addCustomFact(predicate: string, configure: (builder: ClingoFactBuilder) => ClingoFactBuilder): ClingoProgramBuilder;
|
|
27
|
+
/**
|
|
28
|
+
* Adds an import to the clingo program
|
|
29
|
+
*/
|
|
30
|
+
addImport(path: string): ClingoProgramBuilder;
|
|
31
|
+
/**
|
|
32
|
+
* Adds a comment
|
|
33
|
+
*/
|
|
34
|
+
addComment(comment: string): ClingoProgramBuilder;
|
|
35
|
+
/**
|
|
36
|
+
* Builds all facts and returns them as a single string with each fact on a new line.
|
|
37
|
+
*/
|
|
38
|
+
buildAll(): string;
|
|
39
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 { ClingoFactBuilder, } from './clingo-fact-builder.js';
|
|
13
|
+
export class ClingoProgramBuilder {
|
|
14
|
+
rows = [];
|
|
15
|
+
/**
|
|
16
|
+
* Adds a new fact with a simple configuration.
|
|
17
|
+
* @param predicate - The fact's predicate
|
|
18
|
+
* @param args - The fact's arguments
|
|
19
|
+
*/
|
|
20
|
+
addFact(predicate, ...args) {
|
|
21
|
+
const fact = new ClingoFactBuilder(predicate).addArguments(...args);
|
|
22
|
+
this.rows.push(fact);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Adds a custom fact allowing use of the builder methods directly for more control.
|
|
27
|
+
* @param predicate - The fact's predicate
|
|
28
|
+
* @param configure - Function to configure the fact with builder methods
|
|
29
|
+
*/
|
|
30
|
+
addCustomFact(predicate, configure) {
|
|
31
|
+
const factBuilder = new ClingoFactBuilder(predicate);
|
|
32
|
+
// Allow configuration of the fact
|
|
33
|
+
this.rows.push(configure(factBuilder));
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Adds an import to the clingo program
|
|
38
|
+
*/
|
|
39
|
+
addImport(path) {
|
|
40
|
+
this.rows.push({ build: () => `#include "${path}".` });
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Adds a comment
|
|
45
|
+
*/
|
|
46
|
+
addComment(comment) {
|
|
47
|
+
this.rows.push({ build: () => `% ${comment}` });
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Builds all facts and returns them as a single string with each fact on a new line.
|
|
52
|
+
*/
|
|
53
|
+
buildAll() {
|
|
54
|
+
return this.rows.map((row) => row.build()).join('\n') + '\n';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=clingo-program-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clingo-program-builder.js","sourceRoot":"","sources":["../../src/utils/clingo-program-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAEL,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAMlC,MAAM,OAAO,oBAAoB;IACvB,IAAI,GAAe,EAAE,CAAC;IAE9B;;;;OAIG;IACH,OAAO,CAAC,SAAiB,EAAE,GAAG,IAAsB;QAClD,MAAM,IAAI,GAAG,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;QACpE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,aAAa,CACX,SAAiB,EACjB,SAA4D;QAE5D,MAAM,WAAW,GAAG,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACrD,kCAAkC;QAClC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IACD;;OAEG;IACH,SAAS,CAAC,IAAY;QACpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,aAAa,IAAI,IAAI,EAAE,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,OAAO,EAAE,EAAE,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC/D,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Makes deep comparison between two objects.
|
|
14
|
+
* @param arg1 First object to compare.
|
|
15
|
+
* @param arg2 Second object to compare.
|
|
16
|
+
* @returns true, if objects are the same, false otherwise.
|
|
17
|
+
*/
|
|
18
|
+
export declare function deepCompare(arg1: object, arg2: object): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if string could be represented as BigInt.
|
|
21
|
+
* @param value String value
|
|
22
|
+
* @returns true, if 'value' can be represented as BigInt; false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isBigInt(value: string): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Makes deep comparison between two objects.
|
|
14
|
+
* @param arg1 First object to compare.
|
|
15
|
+
* @param arg2 Second object to compare.
|
|
16
|
+
* @returns true, if objects are the same, false otherwise.
|
|
17
|
+
*/
|
|
18
|
+
export function deepCompare(arg1, arg2) {
|
|
19
|
+
if (Object.prototype.toString.call(arg1) ===
|
|
20
|
+
Object.prototype.toString.call(arg2)) {
|
|
21
|
+
if (Object.prototype.toString.call(arg1) === '[object Object]' ||
|
|
22
|
+
Object.prototype.toString.call(arg1) === '[object Array]') {
|
|
23
|
+
if (Object.keys(arg1).length !== Object.keys(arg2).length) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return Object.keys(arg1).every(function (key) {
|
|
27
|
+
return deepCompare(arg1[key], arg2[key]);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return arg1 === arg2;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks if string could be represented as BigInt.
|
|
36
|
+
* @param value String value
|
|
37
|
+
* @returns true, if 'value' can be represented as BigInt; false otherwise.
|
|
38
|
+
*/
|
|
39
|
+
export function isBigInt(value) {
|
|
40
|
+
try {
|
|
41
|
+
return BigInt(parseInt(value, 10)) !== BigInt(value);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=common-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-utils.js","sourceRoot":"","sources":["../../src/utils/common-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAY;IACpD,IACE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QACpC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EACpC,CAAC;QACD,IACE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,iBAAiB;YAC1D,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,gBAAgB,EACzD,CAAC;YACD,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC1D,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,UAAU,GAAG;gBAC1C,OAAO,WAAW,CAChB,IAAI,CAAC,GAAwB,CAAC,EAC9B,IAAI,CAAC,GAAwB,CAAC,CAC/B,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,KAAK,IAAI,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PredefinedCardMetadata } from '../interfaces/project-interfaces.js';
|
|
2
|
+
export declare const INT32_MAX = 2147483647;
|
|
3
|
+
/**
|
|
4
|
+
Cyberismo
|
|
5
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
You should have received a copy of the GNU Affero General Public
|
|
12
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* These are names of the fields that are non-custom fields that present in metadata
|
|
16
|
+
*/
|
|
17
|
+
export declare const PREDEFINED_FIELDS: ("title" | "cardType" | "workflowState" | "rank" | "lastTransitioned" | "lastUpdated")[];
|
|
18
|
+
export declare function isPredefinedField(value: string): value is keyof PredefinedCardMetadata;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const INT32_MAX = 2147483647; // 2^31-1
|
|
2
|
+
/**
|
|
3
|
+
Cyberismo
|
|
4
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
5
|
+
|
|
6
|
+
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.
|
|
7
|
+
|
|
8
|
+
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.
|
|
9
|
+
|
|
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
|
+
* These are names of the fields that are non-custom fields that present in metadata
|
|
15
|
+
*/
|
|
16
|
+
export const PREDEFINED_FIELDS = [
|
|
17
|
+
'rank',
|
|
18
|
+
'cardType',
|
|
19
|
+
'title',
|
|
20
|
+
'workflowState',
|
|
21
|
+
'lastUpdated',
|
|
22
|
+
'lastTransitioned',
|
|
23
|
+
];
|
|
24
|
+
export function isPredefinedField(value) {
|
|
25
|
+
return PREDEFINED_FIELDS.includes(value);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,SAAS;AAC9C;;;;;;;;;;EAUE;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM;IACN,UAAU;IACV,OAAO;IACP,eAAe;IACf,aAAa;IACb,kBAAkB;CACwB,CAAC;AAE7C,MAAM,UAAU,iBAAiB,CAC/B,KAAa;IAEb,OAAQ,iBAA8B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC"}
|