@cyberismo/data-handler 0.0.6 → 0.0.8
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/README.md +1 -0
- package/dist/card-metadata-updater.d.ts +1 -0
- package/dist/card-metadata-updater.js +7 -2
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +6 -1
- package/dist/command-handler.js +16 -15
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +15 -4
- package/dist/command-manager.js +41 -9
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/calculate.d.ts +4 -10
- package/dist/commands/calculate.js +67 -78
- package/dist/commands/calculate.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +15 -10
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/export.js +3 -3
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +3 -8
- package/dist/commands/import.js +17 -15
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/index.d.ts +1 -2
- package/dist/commands/index.js +1 -2
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/remove.d.ts +1 -1
- package/dist/commands/remove.js +4 -10
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/show.d.ts +6 -3
- package/dist/commands/show.js +8 -5
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/validate.d.ts +0 -8
- package/dist/commands/validate.js +6 -36
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/project/project-content-watcher.d.ts +28 -0
- package/dist/containers/project/project-content-watcher.js +54 -0
- package/dist/containers/project/project-content-watcher.js.map +1 -0
- package/dist/containers/project/project-paths.js +1 -1
- package/dist/containers/project/project-paths.js.map +1 -1
- package/dist/containers/project/resource-collector.d.ts +2 -1
- package/dist/containers/project/resource-collector.js +33 -23
- package/dist/containers/project/resource-collector.js.map +1 -1
- package/dist/containers/project.d.ts +9 -7
- package/dist/containers/project.js +58 -18
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +1 -0
- package/dist/containers/template.js +7 -2
- package/dist/containers/template.js.map +1 -1
- package/dist/exceptions/index.d.ts +20 -0
- package/dist/exceptions/index.js +16 -0
- package/dist/exceptions/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/macros.d.ts +5 -1
- package/dist/interfaces/project-interfaces.d.ts +5 -0
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +14 -22
- package/dist/interfaces/resource-interfaces.js +10 -9
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/base-macro.d.ts +2 -0
- package/dist/macros/base-macro.js +66 -19
- package/dist/macros/base-macro.js.map +1 -1
- package/dist/macros/graph/index.d.ts +0 -1
- package/dist/macros/graph/index.js +16 -12
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/index.d.ts +30 -3
- package/dist/macros/index.js +36 -6
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/report/index.d.ts +13 -10
- package/dist/macros/report/index.js +35 -38
- package/dist/macros/report/index.js.map +1 -1
- package/dist/module-manager.d.ts +32 -11
- package/dist/module-manager.js +301 -147
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.js +8 -8
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/array-handler.js +6 -1
- package/dist/resources/array-handler.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +13 -9
- package/dist/resources/card-type-resource.js +47 -23
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.d.ts +10 -9
- package/dist/resources/create-defaults.js +15 -12
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +0 -1
- package/dist/resources/field-type-resource.js +2 -10
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +7 -7
- package/dist/resources/file-resource.js +32 -7
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +10 -9
- package/dist/resources/folder-resource.js +10 -9
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +5 -6
- package/dist/resources/report-resource.js +16 -7
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/template-resource.d.ts +5 -6
- package/dist/resources/template-resource.js +7 -6
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +15 -8
- package/dist/resources/workflow-resource.js +124 -8
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/types/queries.d.ts +11 -10
- package/dist/types/queries.js +10 -9
- package/dist/types/queries.js.map +1 -1
- package/dist/utils/clingo-fact-builder.d.ts +1 -0
- package/dist/utils/clingo-fact-builder.js +8 -3
- package/dist/utils/clingo-fact-builder.js.map +1 -1
- package/dist/utils/clingo-facts.js +15 -11
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/constants.d.ts +18 -12
- package/dist/utils/constants.js +18 -11
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/log-utils.d.ts +15 -2
- package/dist/utils/log-utils.js +20 -37
- package/dist/utils/log-utils.js.map +1 -1
- package/dist/utils/report.d.ts +27 -0
- package/dist/utils/report.js +60 -0
- package/dist/utils/report.js.map +1 -0
- package/dist/utils/resource-utils.js +3 -0
- package/dist/utils/resource-utils.js.map +1 -1
- package/dist/utils/sanitize-svg.d.ts +3 -4
- package/dist/utils/sanitize-svg.js +4 -7
- package/dist/utils/sanitize-svg.js.map +1 -1
- package/dist/utils/validate.js +2 -1
- package/dist/utils/validate.js.map +1 -1
- package/package.json +9 -11
- package/src/card-metadata-updater.ts +7 -2
- package/src/command-handler.ts +23 -13
- package/src/command-manager.ts +54 -13
- package/src/commands/calculate.ts +90 -106
- package/src/commands/create.ts +18 -10
- package/src/commands/export.ts +3 -2
- package/src/commands/import.ts +30 -17
- package/src/commands/index.ts +0 -2
- package/src/commands/remove.ts +7 -12
- package/src/commands/show.ts +13 -5
- package/src/commands/validate.ts +14 -44
- package/src/containers/project/project-content-watcher.ts +65 -0
- package/src/containers/project/project-paths.ts +1 -1
- package/src/containers/project/resource-collector.ts +33 -14
- package/src/containers/project.ts +96 -19
- package/src/containers/template.ts +7 -2
- package/src/exceptions/index.ts +36 -0
- package/src/index.ts +2 -0
- package/src/interfaces/macros.ts +5 -1
- package/src/interfaces/project-interfaces.ts +8 -0
- package/src/interfaces/resource-interfaces.ts +15 -22
- package/src/macros/base-macro.ts +89 -25
- package/src/macros/graph/index.ts +22 -12
- package/src/macros/index.ts +61 -8
- package/src/macros/report/index.ts +42 -43
- package/src/module-manager.ts +383 -177
- package/src/project-settings.ts +9 -11
- package/src/resources/array-handler.ts +7 -2
- package/src/resources/card-type-resource.ts +61 -46
- package/src/resources/create-defaults.ts +15 -12
- package/src/resources/field-type-resource.ts +2 -17
- package/src/resources/file-resource.ts +46 -8
- package/src/resources/folder-resource.ts +11 -10
- package/src/resources/report-resource.ts +19 -7
- package/src/resources/template-resource.ts +7 -6
- package/src/resources/workflow-resource.ts +155 -8
- package/src/types/queries.ts +11 -10
- package/src/utils/clingo-fact-builder.ts +8 -3
- package/src/utils/clingo-facts.ts +18 -12
- package/src/utils/constants.ts +20 -12
- package/src/utils/log-utils.ts +24 -45
- package/src/utils/report.ts +86 -0
- package/src/utils/resource-utils.ts +4 -0
- package/src/utils/sanitize-svg.ts +4 -9
- package/src/utils/validate.ts +3 -2
- package/dist/commands/export-site.d.ts +0 -45
- package/dist/commands/export-site.js +0 -301
- package/dist/commands/export-site.js.map +0 -1
- package/src/commands/export-site.ts +0 -356
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
6
|
+
the Free Software Foundation.
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
8
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
9
|
+
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
10
|
+
details. 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/>.
|
|
11
12
|
*/
|
|
12
13
|
import type { Schema } from 'jsonschema';
|
|
13
14
|
/**
|
|
@@ -35,23 +36,17 @@ export interface EnumDefinition {
|
|
|
35
36
|
enumDescription?: string;
|
|
36
37
|
}
|
|
37
38
|
export interface FieldType extends ResourceBaseMetadata {
|
|
38
|
-
displayName?: string;
|
|
39
|
-
fieldDescription?: string;
|
|
40
39
|
dataType: DataType;
|
|
41
40
|
enumValues?: Array<EnumDefinition>;
|
|
42
41
|
}
|
|
43
42
|
export interface GraphModelMetadata extends ResourceBaseMetadata {
|
|
44
43
|
category?: string;
|
|
45
|
-
description?: string;
|
|
46
|
-
displayName: string;
|
|
47
44
|
}
|
|
48
45
|
export interface GraphModel extends GraphModelMetadata {
|
|
49
46
|
calculationFile: string;
|
|
50
47
|
}
|
|
51
48
|
export interface GraphViewMetadata extends ResourceBaseMetadata {
|
|
52
49
|
category?: string;
|
|
53
|
-
description?: string;
|
|
54
|
-
displayName: string;
|
|
55
50
|
}
|
|
56
51
|
export interface GraphView extends GraphViewMetadata {
|
|
57
52
|
handleBarFile: string;
|
|
@@ -68,7 +63,7 @@ export interface LinkType extends ResourceBaseMetadata {
|
|
|
68
63
|
destinationCardTypes: string[];
|
|
69
64
|
enableLinkDescription: boolean;
|
|
70
65
|
}
|
|
71
|
-
export interface Report {
|
|
66
|
+
export interface Report extends ResourceBaseMetadata {
|
|
72
67
|
name: string;
|
|
73
68
|
metadata: ReportMetadata;
|
|
74
69
|
contentTemplate: string;
|
|
@@ -76,24 +71,21 @@ export interface Report {
|
|
|
76
71
|
schema?: Schema;
|
|
77
72
|
}
|
|
78
73
|
export interface ReportMetadata extends ResourceBaseMetadata {
|
|
79
|
-
displayName: string;
|
|
80
|
-
description: string;
|
|
81
74
|
category: string;
|
|
82
75
|
}
|
|
83
76
|
export interface ResourceBaseMetadata {
|
|
84
77
|
name: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
displayName: string;
|
|
85
80
|
usedIn?: string[];
|
|
86
81
|
}
|
|
87
82
|
export type ResourceContent = CardType | FieldType | GraphModel | GraphView | LinkType | ReportMetadata | TemplateMetadata | Workflow;
|
|
88
|
-
export interface TemplateConfiguration {
|
|
89
|
-
name: string;
|
|
83
|
+
export interface TemplateConfiguration extends ResourceBaseMetadata {
|
|
90
84
|
path: string;
|
|
91
85
|
numberOfCards: number;
|
|
92
86
|
metadata: TemplateMetadata;
|
|
93
87
|
}
|
|
94
88
|
export interface TemplateMetadata extends ResourceBaseMetadata {
|
|
95
|
-
displayName?: string;
|
|
96
|
-
description?: string;
|
|
97
89
|
category?: string;
|
|
98
90
|
}
|
|
99
91
|
export interface Workflow extends ResourceBaseMetadata {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
6
|
+
the Free Software Foundation.
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
8
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
9
|
+
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
10
|
+
details. 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/>.
|
|
11
12
|
*/
|
|
12
13
|
// Workflow state categories.
|
|
13
14
|
export var WorkflowCategory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-interfaces.js","sourceRoot":"","sources":["../../src/interfaces/resource-interfaces.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"resource-interfaces.js","sourceRoot":"","sources":["../../src/interfaces/resource-interfaces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AA6IF,6BAA6B;AAC7B,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,uCAAmB,CAAA;IACnB,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,iCAAa,CAAA;AACf,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B"}
|
|
@@ -16,6 +16,7 @@ declare abstract class BaseMacro {
|
|
|
16
16
|
private readonly tasks;
|
|
17
17
|
private globalId;
|
|
18
18
|
private localCounter;
|
|
19
|
+
protected get logger(): import("pino").Logger;
|
|
19
20
|
constructor(macroMetadata: MacroMetadata, tasks: TaskQueue);
|
|
20
21
|
protected abstract handleInject(context: MacroGenerationContext, input: unknown): Promise<string>;
|
|
21
22
|
protected abstract handleStatic(context: MacroGenerationContext, input: unknown): Promise<string>;
|
|
@@ -23,6 +24,7 @@ declare abstract class BaseMacro {
|
|
|
23
24
|
get metadata(): MacroMetadata;
|
|
24
25
|
private findDependencies;
|
|
25
26
|
private generatePlaceholder;
|
|
27
|
+
private findTask;
|
|
26
28
|
/**
|
|
27
29
|
* Function responsible for starting the promise and storing it along with its localId.
|
|
28
30
|
*/
|
|
@@ -10,12 +10,21 @@
|
|
|
10
10
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
11
|
*/
|
|
12
12
|
import { generateRandomString } from '../utils/random.js';
|
|
13
|
-
import {
|
|
13
|
+
import { MacroError } from '../exceptions/index.js';
|
|
14
|
+
import { ClingoError } from '@cyberismo/node-clingo';
|
|
15
|
+
import { getChildLogger } from '../utils/log-utils.js';
|
|
14
16
|
class BaseMacro {
|
|
15
17
|
macroMetadata;
|
|
16
18
|
tasks;
|
|
17
19
|
globalId;
|
|
18
20
|
localCounter = 0;
|
|
21
|
+
// Macros share the same logger
|
|
22
|
+
get logger() {
|
|
23
|
+
return getChildLogger({
|
|
24
|
+
module: 'macro',
|
|
25
|
+
macro: this.macroMetadata.name,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
19
28
|
constructor(macroMetadata, tasks) {
|
|
20
29
|
this.macroMetadata = macroMetadata;
|
|
21
30
|
this.tasks = tasks;
|
|
@@ -38,7 +47,7 @@ class BaseMacro {
|
|
|
38
47
|
dependencies.push(task);
|
|
39
48
|
}
|
|
40
49
|
else {
|
|
41
|
-
|
|
50
|
+
this.logger.warn(`Dependency not found for placeholder: ${placeholder} (globalId: ${globalId}, localId: ${localId})`);
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
return dependencies;
|
|
@@ -50,6 +59,13 @@ class BaseMacro {
|
|
|
50
59
|
placeholder: `<<macro::${this.globalId}::${localId}>>`,
|
|
51
60
|
};
|
|
52
61
|
}
|
|
62
|
+
findTask(globalId, localId) {
|
|
63
|
+
const task = this.tasks.find(globalId, localId);
|
|
64
|
+
if (!task) {
|
|
65
|
+
this.logger.warn(`Task not found for global id ${globalId}, local id ${localId}.`);
|
|
66
|
+
}
|
|
67
|
+
return task;
|
|
68
|
+
}
|
|
53
69
|
/**
|
|
54
70
|
* Function responsible for starting the promise and storing it along with its localId.
|
|
55
71
|
*/
|
|
@@ -74,39 +90,68 @@ class BaseMacro {
|
|
|
74
90
|
// Extract dependencies
|
|
75
91
|
const dependencies = this.findDependencies(rawInput);
|
|
76
92
|
// Create a promise to resolve dependencies, execute the macro, and handle the results
|
|
77
|
-
const promise = Promise.
|
|
93
|
+
const promise = Promise.allSettled(dependencies.map((dep) => dep.promise))
|
|
78
94
|
.then(() => {
|
|
79
95
|
for (const dependency of dependencies) {
|
|
96
|
+
if (dependency.error) {
|
|
97
|
+
const task = this.findTask(this.globalId, localId);
|
|
98
|
+
if (task) {
|
|
99
|
+
// There could be a better way, but multi-nested macros are rare
|
|
100
|
+
task.error = new MacroError(dependency.error.message, context.cardKey, this.metadata.name, dependency.error.context.parameters, {
|
|
101
|
+
macroName: dependency.macro,
|
|
102
|
+
parameters: dependency.parameters,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
80
107
|
input = input.replace(dependency.placeholder, dependency.promiseResult || '');
|
|
108
|
+
// parse json after each dep, so we know the exact macro which produced the error
|
|
109
|
+
try {
|
|
110
|
+
JSON.parse(input);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
const task = this.findTask(this.globalId, localId);
|
|
114
|
+
if (task) {
|
|
115
|
+
task.error = new MacroError('Invalid JSON produced by macro dependency', context.cardKey, this.metadata.name, input, {
|
|
116
|
+
macroName: dependency.macro,
|
|
117
|
+
parameters: dependency.parameters,
|
|
118
|
+
output: input,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
81
123
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
parsed = JSON.parse(input);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
return 'Invalid JSON';
|
|
88
|
-
}
|
|
124
|
+
// This will never throw in practice, thus no need to catch
|
|
125
|
+
const parsed = JSON.parse(input);
|
|
89
126
|
// Select the function to execute based on context mode
|
|
90
127
|
const functionToCall = context.mode === 'inject' ? this.handleInject : this.handleStatic;
|
|
91
128
|
// Execute the function and handle its result
|
|
92
129
|
return functionToCall(context, parsed);
|
|
93
130
|
})
|
|
94
131
|
.then((result) => {
|
|
95
|
-
|
|
132
|
+
// undefined is used to indicate that the macro did not run for some reason
|
|
133
|
+
if (result === undefined) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const task = this.findTask(this.globalId, localId);
|
|
96
137
|
if (task) {
|
|
97
138
|
task.promiseResult = result;
|
|
98
139
|
}
|
|
99
|
-
else {
|
|
100
|
-
console.error(`Task not found after execution: macro ${this.metadata.name}, local id ${localId}.`);
|
|
101
|
-
}
|
|
102
140
|
})
|
|
103
141
|
.catch((err) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
142
|
+
if (!(err instanceof Error)) {
|
|
143
|
+
this.logger.error(err, 'Unknown error');
|
|
144
|
+
err = new Error('Unknown error');
|
|
107
145
|
}
|
|
108
|
-
|
|
109
|
-
|
|
146
|
+
const message = err instanceof ClingoError
|
|
147
|
+
? err.details.errors.join('\n')
|
|
148
|
+
: err.message;
|
|
149
|
+
const error = err instanceof MacroError
|
|
150
|
+
? err
|
|
151
|
+
: new MacroError(message, context.cardKey, this.metadata.name, input);
|
|
152
|
+
const task = this.findTask(this.globalId, localId);
|
|
153
|
+
if (task) {
|
|
154
|
+
task.error = error;
|
|
110
155
|
}
|
|
111
156
|
});
|
|
112
157
|
// Store the task
|
|
@@ -117,6 +162,8 @@ class BaseMacro {
|
|
|
117
162
|
placeholder,
|
|
118
163
|
promiseResult: null,
|
|
119
164
|
macro: this.macroMetadata.name,
|
|
165
|
+
parameters: rawInput,
|
|
166
|
+
error: null,
|
|
120
167
|
});
|
|
121
168
|
// Return the placeholder
|
|
122
169
|
return placeholder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-macro.js","sourceRoot":"","sources":["../../src/macros/base-macro.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAQF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"base-macro.js","sourceRoot":"","sources":["../../src/macros/base-macro.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAQF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM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O,GACX,GAAG,YAAY,WAAW;gBACxB,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC/B,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;YAClB,MAAM,KAAK,GACT,GAAG,YAAY,UAAU;gBACvB,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,IAAI,UAAU,CACZ,OAAO,EACP,OAAO,CAAC,OAAO,EACf,IAAI,CAAC,QAAQ,CAAC,IAAI,EAClB,KAAK,CACN,CAAC;YAER,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACnD,IAAI,IAAI,EAAE,CAAC;gBACT,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;QAEL,iBAAiB;QACjB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACd,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO;YACP,OAAO;YACP,WAAW;YACX,aAAa,EAAE,IAAI;YACnB,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI;YAC9B,UAAU,EAAE,QAAQ;YACpB,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;QACH,yBAAyB;QACzB,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;CACH;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
Cyberismo
|
|
3
3
|
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
-
|
|
5
4
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
5
|
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
6
|
the Free Software Foundation. This program is distributed in the hope that it
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
Cyberismo
|
|
3
3
|
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
-
|
|
5
4
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
5
|
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
6
|
the Free Software Foundation. This program is distributed in the hope that it
|
|
@@ -16,13 +15,12 @@ import { Calculate } from '../../commands/index.js';
|
|
|
16
15
|
import { createImage, validateMacroContent } from '../index.js';
|
|
17
16
|
import Handlebars from 'handlebars';
|
|
18
17
|
import { join } from 'node:path';
|
|
19
|
-
import { logger } from '../../utils/log-utils.js';
|
|
20
18
|
import macroMetadata from './metadata.js';
|
|
21
19
|
import { pathExists } from '../../utils/file-utils.js';
|
|
22
|
-
import { Project } from '../../containers/project.js';
|
|
23
20
|
import { readFile } from 'node:fs/promises';
|
|
24
21
|
import { resourceName } from '../../utils/resource-utils.js';
|
|
25
22
|
import { validateJson } from '../../utils/validate.js';
|
|
23
|
+
import { ClingoError } from '@cyberismo/node-clingo';
|
|
26
24
|
class ReportMacro extends BaseMacro {
|
|
27
25
|
constructor(tasksQueue) {
|
|
28
26
|
super(macroMetadata, tasksQueue);
|
|
@@ -34,14 +32,13 @@ class ReportMacro extends BaseMacro {
|
|
|
34
32
|
return this.handleInject(context, input);
|
|
35
33
|
};
|
|
36
34
|
handleInject = async (context, input) => {
|
|
37
|
-
const
|
|
38
|
-
const calculate = new Calculate(project);
|
|
35
|
+
const calculate = new Calculate(context.project);
|
|
39
36
|
const resourceNameToPath = (name, fileName) => {
|
|
40
37
|
const { identifier, prefix, type } = resourceName(name);
|
|
41
|
-
if (prefix === project.projectPrefix) {
|
|
42
|
-
return join(project.paths.resourcesFolder, type, identifier, fileName);
|
|
38
|
+
if (prefix === context.project.projectPrefix) {
|
|
39
|
+
return join(context.project.paths.resourcesFolder, type, identifier, fileName);
|
|
43
40
|
}
|
|
44
|
-
return join(project.paths.modulesFolder, prefix, type, identifier, fileName);
|
|
41
|
+
return join(context.project.paths.modulesFolder, prefix, type, identifier, fileName);
|
|
45
42
|
};
|
|
46
43
|
const options = this.parseOptions(input);
|
|
47
44
|
let schema = null;
|
|
@@ -49,7 +46,7 @@ class ReportMacro extends BaseMacro {
|
|
|
49
46
|
schema = JSON.parse(await readFile(resourceNameToPath(options.view, 'parameterSchema.json'), { encoding: 'utf-8' }));
|
|
50
47
|
}
|
|
51
48
|
catch (err) {
|
|
52
|
-
logger.trace(err, 'Graph schema not found or failed to read, skipping validation');
|
|
49
|
+
this.logger.trace(err, 'Graph schema not found or failed to read, skipping validation');
|
|
53
50
|
}
|
|
54
51
|
if (schema) {
|
|
55
52
|
validateJson(options, {
|
|
@@ -75,9 +72,16 @@ class ReportMacro extends BaseMacro {
|
|
|
75
72
|
const handlebars = Handlebars.create();
|
|
76
73
|
const view = handlebars.compile(viewContent)(handlebarsContext);
|
|
77
74
|
const modelContent = await readFile(modelLocation, { encoding: 'utf-8' });
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
let result;
|
|
76
|
+
try {
|
|
77
|
+
result = await calculate.runGraph(modelContent, view);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error instanceof ClingoError) {
|
|
81
|
+
throw new Error(`Error running graph in view '${options.view}' in model '${options.model}': ${error.details.errors.join('\n')}`);
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
81
85
|
if (typeof result !== 'string') {
|
|
82
86
|
throw new Error('Graph macro expected a string from clingo, but received an object');
|
|
83
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/macros/graph/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/macros/graph/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAEF,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,aAAa,CA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BAAiB,GAAG;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,GAAG,OAAO;SACX,CAAC;QAEF,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,iBAAiB,CAAC,CAAC;QAEhE,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1E,IAAI,MAAc,CAAC;QACnB,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CACb,gCAAgC,OAAO,CAAC,IAAI,eAAe,OAAO,CAAC,KAAK,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAChH,CAAC;YACJ,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;QACJ,CAAC;QACD,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEM,YAAY,CAAC,KAAc;QACjC,OAAO,oBAAoB,CAAe,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAClE,CAAC;CACF;AAED,eAAe,WAAW,CAAC"}
|
package/dist/macros/index.d.ts
CHANGED
|
@@ -15,18 +15,39 @@ import type { Validator } from 'jsonschema';
|
|
|
15
15
|
import type { MacroGenerationContext, MacroMetadata, MacroName } from '../interfaces/macros.js';
|
|
16
16
|
import type BaseMacro from './base-macro.js';
|
|
17
17
|
import TaskQueue from './task-queue.js';
|
|
18
|
-
|
|
18
|
+
import type { Calculate } from '../commands/index.js';
|
|
19
|
+
/**
|
|
20
|
+
* Constructor for all macros except report macros
|
|
21
|
+
*/
|
|
22
|
+
export interface SimpleMacroConstructor {
|
|
19
23
|
new (tasks: TaskQueue): BaseMacro;
|
|
20
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Constructor for report macros
|
|
27
|
+
*/
|
|
28
|
+
export interface ReportMacroConstructor {
|
|
29
|
+
new (tasks: TaskQueue, calculate: Calculate): BaseMacro;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Constructor for all macros
|
|
33
|
+
*/
|
|
34
|
+
export type MacroConstructor = SimpleMacroConstructor | ReportMacroConstructor;
|
|
21
35
|
export declare const macros: {
|
|
22
36
|
[K in MacroName]: MacroConstructor;
|
|
23
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Validates the content inside a macro
|
|
40
|
+
* @param macro - The macro to validate the content of
|
|
41
|
+
* @param data - The data to validate
|
|
42
|
+
* @param validator - The validator to use
|
|
43
|
+
* @returns The validated data
|
|
44
|
+
*/
|
|
24
45
|
export declare function validateMacroContent<T>(macro: MacroMetadata, data: unknown, validator?: Validator): T;
|
|
25
46
|
/**
|
|
26
47
|
* Registers the macros with Handlebars
|
|
27
48
|
* @param {Mode} mode - The mode to register the macros in
|
|
28
49
|
*/
|
|
29
|
-
export declare function registerMacros(instance: typeof Handlebars, context: MacroGenerationContext, tasks: TaskQueue): BaseMacro[];
|
|
50
|
+
export declare function registerMacros(instance: typeof Handlebars, context: MacroGenerationContext, tasks: TaskQueue, calculate: Calculate): BaseMacro[];
|
|
30
51
|
/**
|
|
31
52
|
* Calculate amount of handlebars templates inside a string
|
|
32
53
|
* @param input
|
|
@@ -44,7 +65,7 @@ export declare function registerEmptyMacros(instance: typeof Handlebars): void;
|
|
|
44
65
|
* @param content - The content to handle the macros in
|
|
45
66
|
* @param mode - The mode to handle the macros in. Inject mode will generate injectable placeholders for the macros while static mode will generate valid adoc. Validate mode will only validate the macros syntax and throw errors in case of issues.
|
|
46
67
|
*/
|
|
47
|
-
export declare function evaluateMacros(content: string, context: MacroGenerationContext, maxTries?: number): Promise<string>;
|
|
68
|
+
export declare function evaluateMacros(content: string, context: MacroGenerationContext, calculate: Calculate, maxTries?: number): Promise<string>;
|
|
48
69
|
/**
|
|
49
70
|
* This function assumes that tasks, which were started by macros, are complete.
|
|
50
71
|
* It replaces the placeholders of the tasks with the actual results
|
|
@@ -84,6 +105,12 @@ export declare function createHtmlPlaceholder(macro: MacroMetadata, options: Mac
|
|
|
84
105
|
* @returns The adoc admonition as a string
|
|
85
106
|
*/
|
|
86
107
|
export declare function createAdmonition(type: AdmonitionType, label: string, content: string): string;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a code block
|
|
110
|
+
* @param content - The content of the code block
|
|
111
|
+
* @returns The code block as a string
|
|
112
|
+
*/
|
|
113
|
+
export declare function createCodeBlock(content: string): string;
|
|
87
114
|
/**
|
|
88
115
|
* Helper function for including base64 encoded images for now
|
|
89
116
|
* @param image base64 encoded image
|
package/dist/macros/index.js
CHANGED
|
@@ -15,8 +15,9 @@ import graph from './graph/index.js';
|
|
|
15
15
|
import report from './report/index.js';
|
|
16
16
|
import scoreCard from './scoreCard/index.js';
|
|
17
17
|
import { validateJson } from '../utils/validate.js';
|
|
18
|
-
import { DHValidationError } from '../exceptions/index.js';
|
|
18
|
+
import { DHValidationError, MacroError } from '../exceptions/index.js';
|
|
19
19
|
import TaskQueue from './task-queue.js';
|
|
20
|
+
import { ClingoError } from '@cyberismo/node-clingo';
|
|
20
21
|
const CURLY_LEFT = '{';
|
|
21
22
|
const CURLY_RIGHT = '}';
|
|
22
23
|
export const macros = {
|
|
@@ -25,6 +26,13 @@ export const macros = {
|
|
|
25
26
|
report,
|
|
26
27
|
scoreCard,
|
|
27
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Validates the content inside a macro
|
|
31
|
+
* @param macro - The macro to validate the content of
|
|
32
|
+
* @param data - The data to validate
|
|
33
|
+
* @param validator - The validator to use
|
|
34
|
+
* @returns The validated data
|
|
35
|
+
*/
|
|
28
36
|
export function validateMacroContent(macro, data, validator) {
|
|
29
37
|
if (!macro.schema) {
|
|
30
38
|
throw new Error(`Macro ${macro.name} does not have a schema`);
|
|
@@ -47,11 +55,11 @@ export function validateMacroContent(macro, data, validator) {
|
|
|
47
55
|
* Registers the macros with Handlebars
|
|
48
56
|
* @param {Mode} mode - The mode to register the macros in
|
|
49
57
|
*/
|
|
50
|
-
export function registerMacros(instance, context, tasks) {
|
|
58
|
+
export function registerMacros(instance, context, tasks, calculate) {
|
|
51
59
|
const macroInstances = [];
|
|
52
60
|
for (const macro of Object.keys(macros)) {
|
|
53
61
|
const MacroClass = macros[macro];
|
|
54
|
-
const macroInstance = new MacroClass(tasks);
|
|
62
|
+
const macroInstance = new MacroClass(tasks, calculate);
|
|
55
63
|
instance.registerHelper(macro, function (options) {
|
|
56
64
|
if (this != null &&
|
|
57
65
|
typeof this === 'object' &&
|
|
@@ -98,10 +106,10 @@ export function registerEmptyMacros(instance) {
|
|
|
98
106
|
* @param content - The content to handle the macros in
|
|
99
107
|
* @param mode - The mode to handle the macros in. Inject mode will generate injectable placeholders for the macros while static mode will generate valid adoc. Validate mode will only validate the macros syntax and throw errors in case of issues.
|
|
100
108
|
*/
|
|
101
|
-
export async function evaluateMacros(content, context, maxTries = 10) {
|
|
109
|
+
export async function evaluateMacros(content, context, calculate, maxTries = 10) {
|
|
102
110
|
const handlebars = Handlebars.create();
|
|
103
111
|
const tasks = new TaskQueue();
|
|
104
|
-
registerMacros(handlebars, context, tasks);
|
|
112
|
+
registerMacros(handlebars, context, tasks, calculate);
|
|
105
113
|
let result = content;
|
|
106
114
|
while (maxTries-- > 0) {
|
|
107
115
|
tasks.reset();
|
|
@@ -137,7 +145,11 @@ export async function evaluateMacros(content, context, maxTries = 10) {
|
|
|
137
145
|
*/
|
|
138
146
|
export function applyMacroResults(input, tasks, context) {
|
|
139
147
|
for (const item of tasks) {
|
|
140
|
-
if (item.
|
|
148
|
+
if (item.error) {
|
|
149
|
+
input = input.replace(item.placeholder, handleMacroError(item.error, item.macro, context));
|
|
150
|
+
} // It should not be possible that promiseResult is null if there never was an error
|
|
151
|
+
// Unless the function itself returns null / undefined
|
|
152
|
+
else if (item.promiseResult == null) {
|
|
141
153
|
input = handleMacroError(new Error(`Tried to access result before it was resolved for ${item.placeholder}`), item.macro, context);
|
|
142
154
|
}
|
|
143
155
|
else {
|
|
@@ -157,6 +169,16 @@ export function handleMacroError(error, macro, context) {
|
|
|
157
169
|
if (error instanceof DHValidationError) {
|
|
158
170
|
message = `Check json syntax of macro ${macro}: ${error.errors?.map((e) => e.message).join(', ')}`;
|
|
159
171
|
}
|
|
172
|
+
else if (error instanceof MacroError) {
|
|
173
|
+
const { cardKey, macroName, dependency } = error.context;
|
|
174
|
+
message = `Macro error in card '${cardKey}' in macro '${macroName}':\n\n${error.message}.`;
|
|
175
|
+
if (dependency) {
|
|
176
|
+
message += `\n\nParameters:\n\n${context.mode === 'validate' ? dependency.parameters : createCodeBlock(dependency.parameters)}.\n\n${dependency.output ? `Output:\n\n${context.mode === 'validate' ? dependency.output : createCodeBlock(dependency.output)}` : ''}`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (error instanceof ClingoError) {
|
|
180
|
+
message = `Error running logic program in macro '${macro}':${error.details.errors.join('\n')}`;
|
|
181
|
+
}
|
|
160
182
|
if (typeof error === 'object' &&
|
|
161
183
|
error != null &&
|
|
162
184
|
'lineNumber' in error &&
|
|
@@ -216,6 +238,14 @@ export function createHtmlPlaceholder(macro, options) {
|
|
|
216
238
|
export function createAdmonition(type, label, content) {
|
|
217
239
|
return `[${type}]\n.${label}\n====\n${content}\n====\n\n`;
|
|
218
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Creates a code block
|
|
243
|
+
* @param content - The content of the code block
|
|
244
|
+
* @returns The code block as a string
|
|
245
|
+
*/
|
|
246
|
+
export function createCodeBlock(content) {
|
|
247
|
+
return `\n\n----\n${content}\n----\n\n`;
|
|
248
|
+
}
|
|
219
249
|
/**
|
|
220
250
|
* Helper function for including base64 encoded images for now
|
|
221
251
|
* @param image base64 encoded image
|
package/dist/macros/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/macros/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/macros/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AASvE,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,MAAM,UAAU,GAAG,QAAQ,CAAC;AAC5B,MAAM,WAAW,GAAG,QAAQ,CAAC;AAqB7B,MAAM,CAAC,MAAM,MAAM,GAEf;IACF,WAAW;IACX,KAAK;IACL,M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C,CAAC,EAAE,eAAe,YAAY,EAAE,OAAO,KAAK,CAAC,OAAO,UAAU,CAAC;AACtI,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAoB,EACpB,KAAa,EACb,OAAe;IAEf,OAAO,IAAI,IAAI,OAAO,KAAK,WAAW,OAAO,YAAY,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,OAAO,aAAa,OAAO,YAAY,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAC9B,OAAO,oCAAoC,KAAK,MAAM,CAAC;IACzD,CAAC;SAAM,CAAC;QACN,OAAO;;EAET,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;;;CAG/C,CAAC;IACA,CAAC;AACH,CAAC"}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
6
|
+
the Free Software Foundation. This program is distributed in the hope that it
|
|
7
|
+
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
8
|
+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
9
|
+
See the GNU Affero General Public License for more details.
|
|
10
|
+
You should have received a copy of the GNU Affero General Public
|
|
11
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
12
|
*/
|
|
12
13
|
import type { MacroOptions } from '../index.js';
|
|
13
14
|
import type { MacroGenerationContext } from '../../interfaces/macros.js';
|
|
15
|
+
import type { Calculate } from '../../commands/index.js';
|
|
14
16
|
import BaseMacro from '../base-macro.js';
|
|
15
17
|
import type TaskQueue from '../task-queue.js';
|
|
16
18
|
export interface ReportOptions extends MacroOptions {
|
|
17
19
|
name: string;
|
|
18
20
|
}
|
|
19
21
|
declare class ReportMacro extends BaseMacro {
|
|
20
|
-
|
|
22
|
+
private readonly calculate;
|
|
23
|
+
constructor(tasks: TaskQueue, calculate: Calculate);
|
|
21
24
|
handleValidate: (input: unknown) => void;
|
|
22
25
|
handleStatic: (context: MacroGenerationContext, data: unknown) => Promise<string>;
|
|
23
26
|
handleInject: (context: MacroGenerationContext, data: unknown) => Promise<string>;
|