@cyberismo/data-handler 0.0.14 → 0.0.16
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/dist/card-metadata-updater.js +8 -4
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +4 -0
- package/dist/command-handler.js +29 -19
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +25 -2
- package/dist/command-manager.js +30 -5
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +45 -93
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/edit.d.ts +1 -15
- package/dist/commands/edit.js +15 -89
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/export.d.ts +11 -2
- package/dist/commands/export.js +58 -58
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +9 -1
- package/dist/commands/import.js +17 -11
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.d.ts +1 -2
- package/dist/commands/move.js +107 -146
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +8 -1
- package/dist/commands/remove.js +17 -48
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +4 -9
- package/dist/commands/rename.js +34 -108
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +22 -34
- package/dist/commands/show.js +103 -151
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.d.ts +9 -2
- package/dist/commands/transition.js +49 -44
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +18 -12
- package/dist/commands/update.js +34 -18
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +18 -10
- package/dist/commands/validate.js +101 -47
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/card-container.d.ts +87 -24
- package/dist/containers/card-container.js +183 -279
- package/dist/containers/card-container.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +13 -4
- package/dist/containers/project/calculation-engine.js +79 -77
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project/card-cache.d.ts +146 -0
- package/dist/containers/project/card-cache.js +411 -0
- package/dist/containers/project/card-cache.js.map +1 -0
- package/dist/containers/project/project-paths.d.ts +5 -4
- package/dist/containers/project/project-paths.js +16 -12
- package/dist/containers/project/project-paths.js.map +1 -1
- package/dist/containers/project/resource-cache.d.ts +169 -0
- package/dist/containers/project/resource-cache.js +507 -0
- package/dist/containers/project/resource-cache.js.map +1 -0
- package/dist/containers/project/resource-handler.d.ts +129 -0
- package/dist/containers/project/resource-handler.js +206 -0
- package/dist/containers/project/resource-handler.js.map +1 -0
- package/dist/containers/project.d.ts +114 -195
- package/dist/containers/project.js +425 -535
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +22 -32
- package/dist/containers/template.js +113 -115
- package/dist/containers/template.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/folder-content-interfaces.d.ts +7 -4
- package/dist/interfaces/folder-content-interfaces.js +3 -3
- package/dist/interfaces/folder-content-interfaces.js.map +1 -1
- package/dist/interfaces/macros.d.ts +1 -0
- package/dist/interfaces/macros.js +1 -1
- package/dist/interfaces/macros.js.map +1 -1
- package/dist/interfaces/project-interfaces.d.ts +7 -5
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +25 -22
- package/dist/interfaces/resource-interfaces.js +3 -0
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/common.d.ts +10 -10
- package/dist/macros/createCards/index.d.ts +0 -13
- package/dist/macros/createCards/index.js.map +1 -1
- package/dist/macros/createCards/types.d.ts +44 -0
- package/dist/macros/createCards/types.js +15 -0
- package/dist/macros/createCards/types.js.map +1 -0
- package/dist/macros/graph/index.d.ts +2 -6
- package/dist/macros/graph/index.js +14 -28
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/graph/types.d.ts +23 -0
- package/dist/macros/graph/types.js +15 -0
- package/dist/macros/graph/types.js.map +1 -0
- package/dist/macros/image/index.d.ts +8 -16
- package/dist/macros/image/index.js +36 -33
- package/dist/macros/image/index.js.map +1 -1
- package/dist/macros/image/types.d.ts +38 -0
- package/dist/macros/image/types.js +15 -0
- package/dist/macros/image/types.js.map +1 -0
- package/dist/macros/include/index.d.ts +1 -6
- package/dist/macros/include/index.js +4 -7
- package/dist/macros/include/index.js.map +1 -1
- package/dist/macros/include/types.d.ts +31 -0
- package/dist/macros/include/types.js +15 -0
- package/dist/macros/include/types.js.map +1 -0
- package/dist/macros/index.d.ts +1 -1
- package/dist/macros/index.js +2 -2
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/percentage/index.d.ts +0 -6
- package/dist/macros/percentage/index.js.map +1 -1
- package/dist/macros/percentage/types.d.ts +31 -0
- package/dist/macros/percentage/types.js +15 -0
- package/dist/macros/percentage/types.js.map +1 -0
- package/dist/macros/report/index.d.ts +0 -3
- package/dist/macros/report/index.js +3 -6
- package/dist/macros/report/index.js.map +1 -1
- package/dist/macros/report/types.d.ts +19 -0
- package/dist/macros/report/types.js +15 -0
- package/dist/macros/report/types.js.map +1 -0
- package/dist/macros/scoreCard/index.d.ts +0 -6
- package/dist/macros/scoreCard/index.js.map +1 -1
- package/dist/macros/scoreCard/types.d.ts +31 -0
- package/dist/macros/scoreCard/types.js +15 -0
- package/dist/macros/scoreCard/types.js.map +1 -0
- package/dist/macros/types.d.ts +25 -0
- package/dist/macros/types.js +2 -0
- package/dist/macros/types.js.map +1 -0
- package/dist/macros/vega/index.d.ts +0 -4
- package/dist/macros/vega/index.js.map +1 -1
- package/dist/macros/vega/types.d.ts +20 -0
- package/dist/macros/vega/types.js +2 -0
- package/dist/macros/vega/types.js.map +1 -0
- package/dist/macros/vegalite/index.d.ts +0 -4
- package/dist/macros/vegalite/index.js.map +1 -1
- package/dist/macros/vegalite/types.d.ts +20 -0
- package/dist/macros/vegalite/types.js +15 -0
- package/dist/macros/vegalite/types.js.map +1 -0
- package/dist/macros/xref/index.d.ts +0 -3
- package/dist/macros/xref/index.js +5 -14
- package/dist/macros/xref/index.js.map +1 -1
- package/dist/macros/xref/types.d.ts +19 -0
- package/dist/macros/xref/types.js +15 -0
- package/dist/macros/xref/types.js.map +1 -0
- package/dist/module-manager.d.ts +16 -3
- package/dist/module-manager.js +55 -23
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.d.ts +16 -3
- package/dist/project-settings.js +79 -14
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/calculation-resource.d.ts +6 -33
- package/dist/resources/calculation-resource.js +11 -60
- package/dist/resources/calculation-resource.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +10 -22
- package/dist/resources/card-type-resource.js +46 -66
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.d.ts +3 -2
- package/dist/resources/create-defaults.js +3 -2
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +8 -22
- package/dist/resources/field-type-resource.js +35 -60
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +14 -35
- package/dist/resources/file-resource.js +22 -301
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +44 -66
- package/dist/resources/folder-resource.js +102 -149
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +9 -34
- package/dist/resources/graph-model-resource.js +18 -64
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +9 -29
- package/dist/resources/graph-view-resource.js +13 -48
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +9 -23
- package/dist/resources/link-type-resource.js +11 -33
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +10 -23
- package/dist/resources/report-resource.js +20 -67
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +143 -23
- package/dist/resources/resource-object.js +369 -48
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +10 -17
- package/dist/resources/template-resource.js +19 -27
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +9 -25
- package/dist/resources/workflow-resource.js +25 -55
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/card-utils.d.ts +69 -19
- package/dist/utils/card-utils.js +179 -30
- package/dist/utils/card-utils.js.map +1 -1
- package/dist/utils/clingo-fact-builder.d.ts +25 -14
- package/dist/utils/clingo-fact-builder.js +27 -5
- package/dist/utils/clingo-fact-builder.js.map +1 -1
- package/dist/utils/clingo-facts.js +14 -7
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/clingo-parser.js +1 -1
- package/dist/utils/clingo-parser.js.map +1 -1
- package/dist/utils/constants.d.ts +2 -0
- package/dist/utils/constants.js +4 -0
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/csv.js +1 -1
- package/dist/utils/csv.js.map +1 -1
- package/dist/utils/resource-utils.d.ts +1 -0
- package/dist/utils/resource-utils.js +2 -1
- package/dist/utils/resource-utils.js.map +1 -1
- package/package.json +11 -11
- package/src/card-metadata-updater.ts +9 -7
- package/src/command-handler.ts +35 -23
- package/src/command-manager.ts +32 -19
- package/src/commands/create.ts +59 -160
- package/src/commands/edit.ts +16 -132
- package/src/commands/export.ts +71 -81
- package/src/commands/import.ts +26 -18
- package/src/commands/move.ts +143 -179
- package/src/commands/remove.ts +20 -59
- package/src/commands/rename.ts +45 -156
- package/src/commands/show.ts +153 -211
- package/src/commands/transition.ts +53 -58
- package/src/commands/update.ts +44 -23
- package/src/commands/validate.ts +108 -82
- package/src/containers/card-container.ts +200 -360
- package/src/containers/project/calculation-engine.ts +81 -105
- package/src/containers/project/card-cache.ts +497 -0
- package/src/containers/project/project-paths.ts +21 -13
- package/src/containers/project/resource-cache.ts +648 -0
- package/src/containers/project/resource-handler.ts +265 -0
- package/src/containers/project.ts +551 -693
- package/src/containers/template.ts +129 -142
- package/src/index.ts +1 -0
- package/src/interfaces/folder-content-interfaces.ts +14 -7
- package/src/interfaces/macros.ts +2 -0
- package/src/interfaces/project-interfaces.ts +14 -7
- package/src/interfaces/resource-interfaces.ts +30 -27
- package/src/macros/createCards/index.ts +1 -12
- package/src/macros/createCards/types.ts +46 -0
- package/src/macros/graph/index.ts +27 -52
- package/src/macros/graph/types.ts +24 -0
- package/src/macros/image/index.ts +50 -61
- package/src/macros/image/types.ts +39 -0
- package/src/macros/include/index.ts +6 -15
- package/src/macros/include/types.ts +32 -0
- package/src/macros/index.ts +2 -2
- package/src/macros/percentage/index.ts +1 -7
- package/src/macros/percentage/types.ts +32 -0
- package/src/macros/report/index.ts +4 -13
- package/src/macros/report/types.ts +20 -0
- package/src/macros/scoreCard/index.ts +1 -7
- package/src/macros/scoreCard/types.ts +32 -0
- package/src/macros/types.ts +48 -0
- package/src/macros/vega/index.ts +1 -4
- package/src/macros/vega/types.ts +21 -0
- package/src/macros/vegalite/index.ts +1 -4
- package/src/macros/vegalite/types.ts +22 -0
- package/src/macros/xref/index.ts +6 -20
- package/src/macros/xref/types.ts +20 -0
- package/src/module-manager.ts +79 -22
- package/src/project-settings.ts +84 -15
- package/src/resources/calculation-resource.ts +21 -91
- package/src/resources/card-type-resource.ts +74 -109
- package/src/resources/create-defaults.ts +3 -2
- package/src/resources/field-type-resource.ts +61 -104
- package/src/resources/file-resource.ts +33 -441
- package/src/resources/folder-resource.ts +130 -207
- package/src/resources/graph-model-resource.ts +36 -95
- package/src/resources/graph-view-resource.ts +28 -70
- package/src/resources/link-type-resource.ts +23 -53
- package/src/resources/report-resource.ts +34 -96
- package/src/resources/resource-object.ts +511 -66
- package/src/resources/template-resource.ts +32 -44
- package/src/resources/workflow-resource.ts +42 -85
- package/src/utils/card-utils.ts +217 -31
- package/src/utils/clingo-fact-builder.ts +28 -16
- package/src/utils/clingo-facts.ts +16 -7
- package/src/utils/clingo-parser.ts +1 -1
- package/src/utils/constants.ts +6 -0
- package/src/utils/csv.ts +1 -1
- package/src/utils/resource-utils.ts +2 -1
- package/dist/containers/project/resource-collector.d.ts +0 -87
- package/dist/containers/project/resource-collector.js +0 -337
- package/dist/containers/project/resource-collector.js.map +0 -1
- package/src/containers/project/resource-collector.ts +0 -396
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
GraphViewContent,
|
|
18
18
|
ReportContent,
|
|
19
19
|
} from './folder-content-interfaces.js';
|
|
20
|
+
import type { ResourceType } from './project-interfaces.js';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Each resource represents a file (or a folder in some cases) with metadata stored
|
|
@@ -46,12 +47,6 @@ export interface CardType extends ResourceBaseMetadata {
|
|
|
46
47
|
optionallyVisibleFields: string[];
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
// Base content update key interface
|
|
50
|
-
export interface ContentUpdateKey {
|
|
51
|
-
key: 'content';
|
|
52
|
-
subKey: string; // Resource-specific types should narrow this
|
|
53
|
-
}
|
|
54
|
-
|
|
55
50
|
// Custom field
|
|
56
51
|
// todo: merge with FieldType.
|
|
57
52
|
export interface CustomField {
|
|
@@ -95,11 +90,6 @@ export interface GraphModel extends GraphModelMetadata {
|
|
|
95
90
|
content: GraphModelContent;
|
|
96
91
|
}
|
|
97
92
|
export type GraphModelContentPropertyName = 'model';
|
|
98
|
-
export interface GraphModelContentUpdateKey {
|
|
99
|
-
key: 'content';
|
|
100
|
-
subKey: GraphModelContentPropertyName;
|
|
101
|
-
}
|
|
102
|
-
export type GraphModelUpdateKey = string | GraphModelContentUpdateKey;
|
|
103
93
|
|
|
104
94
|
// Graph view content.
|
|
105
95
|
export interface GraphViewMetadata extends ResourceBaseMetadata {
|
|
@@ -109,11 +99,6 @@ export type GraphViewContentPropertyName = 'viewTemplate';
|
|
|
109
99
|
export interface GraphView extends GraphViewMetadata {
|
|
110
100
|
content: GraphViewContent;
|
|
111
101
|
}
|
|
112
|
-
export interface GraphViewContentUpdateKey {
|
|
113
|
-
key: 'content';
|
|
114
|
-
subKey: GraphViewContentPropertyName;
|
|
115
|
-
}
|
|
116
|
-
export type GraphViewUpdateKey = string | GraphViewContentUpdateKey;
|
|
117
102
|
|
|
118
103
|
// Link content.
|
|
119
104
|
export interface Link {
|
|
@@ -132,7 +117,7 @@ export interface LinkType extends ResourceBaseMetadata {
|
|
|
132
117
|
}
|
|
133
118
|
|
|
134
119
|
// Report resource.
|
|
135
|
-
export interface Report extends
|
|
120
|
+
export interface Report extends ReportMetadata {
|
|
136
121
|
content: ReportContent;
|
|
137
122
|
}
|
|
138
123
|
|
|
@@ -141,11 +126,6 @@ export type ReportContentPropertyName =
|
|
|
141
126
|
| 'contentTemplate'
|
|
142
127
|
| 'queryTemplate'
|
|
143
128
|
| 'schema';
|
|
144
|
-
export interface ReportContentUpdateKey {
|
|
145
|
-
key: 'content';
|
|
146
|
-
subKey: ReportContentPropertyName;
|
|
147
|
-
}
|
|
148
|
-
export type ReportUpdateKey = string | ReportContentUpdateKey;
|
|
149
129
|
|
|
150
130
|
// Metadata for report
|
|
151
131
|
export interface ReportMetadata extends ResourceBaseMetadata {
|
|
@@ -161,17 +141,31 @@ export interface ResourceBaseMetadata {
|
|
|
161
141
|
}
|
|
162
142
|
|
|
163
143
|
// All resources metadata content.
|
|
164
|
-
export type
|
|
165
|
-
|
|
|
144
|
+
export type AnyResourceContent =
|
|
145
|
+
| Calculation
|
|
166
146
|
| CardType
|
|
167
147
|
| FieldType
|
|
168
148
|
| GraphModel
|
|
169
149
|
| GraphView
|
|
170
150
|
| LinkType
|
|
171
|
-
|
|
|
151
|
+
| Report
|
|
172
152
|
| TemplateMetadata
|
|
173
153
|
| Workflow;
|
|
174
154
|
|
|
155
|
+
export type ResourceContent<T extends ResourceType> = ResourceContentMap[T];
|
|
156
|
+
|
|
157
|
+
export type ResourceContentMap = {
|
|
158
|
+
calculations: Calculation;
|
|
159
|
+
cardTypes: CardType;
|
|
160
|
+
fieldTypes: FieldType;
|
|
161
|
+
graphModels: GraphModel;
|
|
162
|
+
graphViews: GraphView;
|
|
163
|
+
linkTypes: LinkType;
|
|
164
|
+
reports: Report;
|
|
165
|
+
templates: TemplateMetadata;
|
|
166
|
+
workflows: Workflow;
|
|
167
|
+
};
|
|
168
|
+
|
|
175
169
|
// Template configuration details.
|
|
176
170
|
export interface TemplateConfiguration extends TemplateMetadata {
|
|
177
171
|
path: string;
|
|
@@ -182,9 +176,18 @@ export interface TemplateConfiguration extends TemplateMetadata {
|
|
|
182
176
|
export interface TemplateMetadata extends ResourceBaseMetadata {
|
|
183
177
|
category?: string;
|
|
184
178
|
}
|
|
179
|
+
type ContentUpdateKey = { key: 'content'; subKey: string };
|
|
180
|
+
type PropertyUpdateKey<K extends string = string> = {
|
|
181
|
+
key: Exclude<K, 'content'>;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export type UpdateKey<K extends string = string> =
|
|
185
|
+
| ContentUpdateKey
|
|
186
|
+
| PropertyUpdateKey<K>;
|
|
185
187
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
export function isContentKey(key: UpdateKey): key is ContentUpdateKey {
|
|
189
|
+
return key.key === 'content';
|
|
190
|
+
}
|
|
188
191
|
|
|
189
192
|
// Workflow's json file content.
|
|
190
193
|
export interface Workflow extends ResourceBaseMetadata {
|
|
@@ -12,23 +12,12 @@
|
|
|
12
12
|
|
|
13
13
|
import { createHtmlPlaceholder, validateMacroContent } from '../index.js';
|
|
14
14
|
|
|
15
|
+
import type { CreateCardsOptions } from './types.js';
|
|
15
16
|
import type { MacroGenerationContext } from '../../interfaces/macros.js';
|
|
16
17
|
import macroMetadata from './metadata.js';
|
|
17
18
|
import BaseMacro from '../base-macro.js';
|
|
18
19
|
import type TaskQueue from '../task-queue.js';
|
|
19
20
|
|
|
20
|
-
export interface CreateCardsOptions {
|
|
21
|
-
buttonLabel: string;
|
|
22
|
-
template: string;
|
|
23
|
-
cardKey?: string;
|
|
24
|
-
link?: {
|
|
25
|
-
linkType: string;
|
|
26
|
-
direction: string;
|
|
27
|
-
cardKey: string;
|
|
28
|
-
};
|
|
29
|
-
[key: string]: string | undefined | { [key: string]: string | undefined };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
21
|
class CreateCardsMacro extends BaseMacro {
|
|
33
22
|
constructor(tasksQueue: TaskQueue) {
|
|
34
23
|
super(macroMetadata, tasksQueue);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
|
+
the Free Software Foundation. This program is distributed in the hope that it
|
|
8
|
+
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
9
|
+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
10
|
+
See the GNU Affero General Public License for more details.
|
|
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
|
+
export interface CreateCardsOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Label of the button
|
|
18
|
+
*/
|
|
19
|
+
buttonLabel: string;
|
|
20
|
+
/**
|
|
21
|
+
* Template to create cards from
|
|
22
|
+
*/
|
|
23
|
+
template: string;
|
|
24
|
+
/**
|
|
25
|
+
* Allows forcing card creation under a certain card
|
|
26
|
+
*/
|
|
27
|
+
cardKey?: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Allows creating a link at the same time
|
|
31
|
+
*/
|
|
32
|
+
link?: {
|
|
33
|
+
/**
|
|
34
|
+
* Type of the link to create
|
|
35
|
+
*/
|
|
36
|
+
linkType: string;
|
|
37
|
+
/**
|
|
38
|
+
* Direction of the link to create
|
|
39
|
+
*/
|
|
40
|
+
direction: string;
|
|
41
|
+
/**
|
|
42
|
+
* Card key of target card of the link
|
|
43
|
+
*/
|
|
44
|
+
cardKey: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -14,23 +14,14 @@
|
|
|
14
14
|
import BaseMacro from '../base-macro.js';
|
|
15
15
|
import { createImage, validateMacroContent } from '../index.js';
|
|
16
16
|
import Handlebars from 'handlebars';
|
|
17
|
-
import type { MacroGenerationContext } from '../../interfaces/macros.js';
|
|
18
17
|
import macroMetadata from './metadata.js';
|
|
19
|
-
import { pathExists } from '../../utils/file-utils.js';
|
|
20
|
-
import { readFile } from 'node:fs/promises';
|
|
21
|
-
import { readFileSync } from 'node:fs';
|
|
22
|
-
import type { Schema } from 'jsonschema';
|
|
23
|
-
import type TaskQueue from '../task-queue.js';
|
|
24
18
|
import { ClingoError } from '@cyberismo/node-clingo';
|
|
25
|
-
import { resourceFilePath } from '../../utils/resource-utils.js';
|
|
26
|
-
import { resourceName } from '../../utils/resource-utils.js';
|
|
27
19
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
20
|
+
import type { GraphOptions } from './types.js';
|
|
21
|
+
import type { MacroGenerationContext } from '../../interfaces/macros.js';
|
|
22
|
+
import type TaskQueue from '../task-queue.js';
|
|
32
23
|
|
|
33
|
-
class
|
|
24
|
+
class GraphMacro extends BaseMacro {
|
|
34
25
|
constructor(tasksQueue: TaskQueue) {
|
|
35
26
|
super(macroMetadata, tasksQueue);
|
|
36
27
|
}
|
|
@@ -42,40 +33,35 @@ class ReportMacro extends BaseMacro {
|
|
|
42
33
|
handleStatic = async (context: MacroGenerationContext, input: unknown) => {
|
|
43
34
|
const options = this.parseOptions(input, context);
|
|
44
35
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
'model.lp',
|
|
49
|
-
);
|
|
50
|
-
const viewLocation = resourceFilePath(
|
|
51
|
-
context.project,
|
|
52
|
-
resourceName(options.view),
|
|
53
|
-
'view.lp.hbs',
|
|
36
|
+
const modelResource = context.project.resources.byType(
|
|
37
|
+
options.model,
|
|
38
|
+
'graphModels',
|
|
54
39
|
);
|
|
40
|
+
const modelContent = modelResource.contentData();
|
|
55
41
|
|
|
56
|
-
|
|
57
|
-
|
|
42
|
+
const viewResource = context.project.resources.byType(
|
|
43
|
+
options.view,
|
|
44
|
+
'graphViews',
|
|
45
|
+
);
|
|
46
|
+
const viewContent = viewResource.contentData();
|
|
47
|
+
if (!viewContent.viewTemplate) {
|
|
48
|
+
throw new Error(`Graph: View ${options.view} has no view template`);
|
|
58
49
|
}
|
|
59
50
|
|
|
60
|
-
let viewContent = '';
|
|
61
|
-
try {
|
|
62
|
-
viewContent = await readFile(viewLocation, { encoding: 'utf-8' });
|
|
63
|
-
} catch {
|
|
64
|
-
throw new Error(`Graph: View ${options.view} does not exist`);
|
|
65
|
-
}
|
|
66
51
|
const handlebarsContext = {
|
|
67
52
|
cardKey: context.cardKey,
|
|
68
53
|
...options,
|
|
69
54
|
};
|
|
70
55
|
|
|
71
56
|
const handlebars = Handlebars.create();
|
|
72
|
-
const view = handlebars.compile(viewContent)(
|
|
57
|
+
const view = handlebars.compile(viewContent.viewTemplate)(
|
|
58
|
+
handlebarsContext,
|
|
59
|
+
);
|
|
73
60
|
|
|
74
|
-
const modelContent = await readFile(modelLocation, { encoding: 'utf-8' });
|
|
75
61
|
let result: string;
|
|
76
62
|
try {
|
|
77
63
|
result = await context.project.calculationEngine.runGraph(
|
|
78
|
-
modelContent,
|
|
64
|
+
modelContent.model,
|
|
79
65
|
view,
|
|
80
66
|
context.context,
|
|
81
67
|
);
|
|
@@ -102,24 +88,13 @@ class ReportMacro extends BaseMacro {
|
|
|
102
88
|
): GraphOptions {
|
|
103
89
|
const options = validateMacroContent<GraphOptions>(this.metadata, input);
|
|
104
90
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
'parameterSchema.json',
|
|
113
|
-
),
|
|
114
|
-
{ encoding: 'utf-8' },
|
|
115
|
-
),
|
|
116
|
-
);
|
|
117
|
-
} catch (err) {
|
|
118
|
-
this.logger.trace(
|
|
119
|
-
err,
|
|
120
|
-
'Graph schema not found or failed to read, skipping validation',
|
|
121
|
-
);
|
|
122
|
-
}
|
|
91
|
+
// Get schema from view resource content if available
|
|
92
|
+
const resource = context.project.resources.byType(
|
|
93
|
+
options.view,
|
|
94
|
+
'graphViews',
|
|
95
|
+
);
|
|
96
|
+
const content = resource.contentData();
|
|
97
|
+
const schema = content.schema;
|
|
123
98
|
|
|
124
99
|
if (schema) {
|
|
125
100
|
validateMacroContent(this.metadata, input, schema);
|
|
@@ -129,4 +104,4 @@ class ReportMacro extends BaseMacro {
|
|
|
129
104
|
}
|
|
130
105
|
}
|
|
131
106
|
|
|
132
|
-
export default
|
|
107
|
+
export default GraphMacro;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
|
+
the Free Software Foundation. This program is distributed in the hope that it
|
|
8
|
+
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
9
|
+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
10
|
+
See the GNU Affero General Public License for more details.
|
|
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
|
+
export interface GraphOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Reference to the model that defines graph
|
|
18
|
+
*/
|
|
19
|
+
model: string;
|
|
20
|
+
/**
|
|
21
|
+
* Reference to the view that defines the graph
|
|
22
|
+
*/
|
|
23
|
+
view: string;
|
|
24
|
+
}
|
|
@@ -11,39 +11,64 @@
|
|
|
11
11
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { readFileSync } from 'node:fs';
|
|
15
15
|
import { join } from 'node:path';
|
|
16
|
-
import mime from 'mime-types';
|
|
17
16
|
|
|
17
|
+
import BaseMacro from '../base-macro.js';
|
|
18
|
+
import macroMetadata from './metadata.js';
|
|
18
19
|
import { validateMacroContent } from '../index.js';
|
|
19
20
|
|
|
21
|
+
import type { ImageMacroOptions } from './types.js';
|
|
20
22
|
import type { MacroGenerationContext } from '../../interfaces/macros.js';
|
|
21
|
-
import macroMetadata from './metadata.js';
|
|
22
|
-
import BaseMacro from '../base-macro.js';
|
|
23
23
|
import type TaskQueue from '../task-queue.js';
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Options for the image macro.
|
|
27
|
-
* @param fileName - Name of the file to include.
|
|
28
|
-
* @param cardKey - Key of the card to include the file from.
|
|
29
|
-
* @param alt - Alternative text for the image.
|
|
30
|
-
* @param title - Title of the image.
|
|
31
|
-
*/
|
|
32
|
-
export interface ImageMacroOptions {
|
|
33
|
-
fileName: string;
|
|
34
|
-
cardKey?: string;
|
|
35
|
-
alt?: string;
|
|
36
|
-
title?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
25
|
/**
|
|
40
26
|
* Macro for including images in the content
|
|
41
27
|
*/
|
|
42
28
|
export default class ImageMacro extends BaseMacro {
|
|
29
|
+
/**
|
|
30
|
+
* Constructs ImageMacro instance.
|
|
31
|
+
* @param tasksQueue Tasks queue
|
|
32
|
+
*/
|
|
43
33
|
constructor(tasksQueue: TaskQueue) {
|
|
44
34
|
super(macroMetadata, tasksQueue);
|
|
45
35
|
}
|
|
46
36
|
|
|
37
|
+
// Gets card attachment.
|
|
38
|
+
private attachment(
|
|
39
|
+
context: MacroGenerationContext,
|
|
40
|
+
cardKey: string,
|
|
41
|
+
filename: string,
|
|
42
|
+
) {
|
|
43
|
+
const card = context.project.findCard(cardKey);
|
|
44
|
+
const attachment =
|
|
45
|
+
card.attachments?.find((a) => a.fileName === filename) ?? undefined;
|
|
46
|
+
if (!attachment) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Attachment file '${filename}' not found in card '${cardKey}'`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return attachment;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private buildImageAttributes(options: ImageMacroOptions): string {
|
|
55
|
+
const attributes: string[] = [];
|
|
56
|
+
|
|
57
|
+
if (options.alt !== undefined) {
|
|
58
|
+
attributes.push(`alt="${options.alt}"`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (options.title !== undefined) {
|
|
62
|
+
attributes.push(`title="${options.title}"`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return attributes.join(',');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private validate(input: unknown): ImageMacroOptions {
|
|
69
|
+
return validateMacroContent<ImageMacroOptions>(this.metadata, input);
|
|
70
|
+
}
|
|
71
|
+
|
|
47
72
|
handleValidate = (_: MacroGenerationContext, input: unknown) => {
|
|
48
73
|
this.validate(input);
|
|
49
74
|
};
|
|
@@ -55,45 +80,27 @@ export default class ImageMacro extends BaseMacro {
|
|
|
55
80
|
const options = this.validate(input);
|
|
56
81
|
const cardKey = options.cardKey || context.cardKey;
|
|
57
82
|
|
|
58
|
-
// Get the attachment
|
|
59
|
-
const
|
|
60
|
-
await context.project.cardAttachmentFolder(cardKey);
|
|
61
|
-
|
|
62
|
-
// Read the file and convert to base64
|
|
63
|
-
const attachmentPath = join(attachmentFolder, options.fileName);
|
|
64
|
-
if (!existsSync(attachmentPath)) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`Attachment file '${options.fileName}' not found in card '${cardKey}'`,
|
|
67
|
-
);
|
|
68
|
-
}
|
|
83
|
+
// Get the attachment
|
|
84
|
+
const cardAttachment = this.attachment(context, cardKey, options.fileName);
|
|
69
85
|
|
|
86
|
+
// Convert to base64
|
|
87
|
+
const attachmentPath = join(cardAttachment?.path, cardAttachment?.fileName);
|
|
70
88
|
const fileBuffer = readFileSync(attachmentPath);
|
|
71
89
|
const base64Data = fileBuffer.toString('base64');
|
|
72
90
|
|
|
73
|
-
// Get mime type
|
|
74
|
-
const mimeType = mime.lookup(attachmentPath) || 'application/octet-stream';
|
|
75
|
-
|
|
76
91
|
// Build image attributes
|
|
77
92
|
const attributes = this.buildImageAttributes(options);
|
|
78
93
|
|
|
79
94
|
// Return as data URI for static mode (for export/PDF generation)
|
|
80
|
-
return `image::data:${mimeType};base64,${base64Data}[${attributes}]`;
|
|
95
|
+
return `image::data:${cardAttachment.mimeType};base64,${base64Data}[${attributes}]`;
|
|
81
96
|
};
|
|
82
97
|
|
|
83
98
|
handleInject = async (context: MacroGenerationContext, input: unknown) => {
|
|
84
99
|
const options = this.validate(input);
|
|
85
100
|
const cardKey = options.cardKey || context.cardKey;
|
|
86
101
|
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
await context.project.cardAttachmentFolder(cardKey);
|
|
90
|
-
|
|
91
|
-
const attachmentPath = join(attachmentFolder, options.fileName);
|
|
92
|
-
if (!existsSync(attachmentPath)) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
`Attachment file '${options.fileName}' not found in card '${cardKey}'`,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
102
|
+
// Just verify that the attachment exists.
|
|
103
|
+
this.attachment(context, cardKey, options.fileName);
|
|
97
104
|
|
|
98
105
|
// Build image attributes
|
|
99
106
|
const attributes = this.buildImageAttributes(options);
|
|
@@ -101,22 +108,4 @@ export default class ImageMacro extends BaseMacro {
|
|
|
101
108
|
// In inject mode, always use the API path for consistency
|
|
102
109
|
return `image::/api/cards/${cardKey}/a/${options.fileName}[${attributes}]`;
|
|
103
110
|
};
|
|
104
|
-
|
|
105
|
-
private buildImageAttributes(options: ImageMacroOptions): string {
|
|
106
|
-
const attributes: string[] = [];
|
|
107
|
-
|
|
108
|
-
if (options.alt !== undefined) {
|
|
109
|
-
attributes.push(`alt="${options.alt}"`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (options.title !== undefined) {
|
|
113
|
-
attributes.push(`title="${options.title}"`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return attributes.join(',');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private validate(input: unknown): ImageMacroOptions {
|
|
120
|
-
return validateMacroContent<ImageMacroOptions>(this.metadata, input);
|
|
121
|
-
}
|
|
122
111
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
|
+
the Free Software Foundation. This program is distributed in the hope that it
|
|
8
|
+
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
9
|
+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
10
|
+
See the GNU Affero General Public License for more details.
|
|
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
|
+
/**
|
|
16
|
+
* Options for the image macro.
|
|
17
|
+
* @param fileName - Name of the file to include.
|
|
18
|
+
* @param cardKey - Key of the card to include the file from.
|
|
19
|
+
* @param alt - Alternative text for the image.
|
|
20
|
+
* @param title - Title of the image.
|
|
21
|
+
*/
|
|
22
|
+
export interface ImageMacroOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Filename of the image
|
|
25
|
+
*/
|
|
26
|
+
fileName: string;
|
|
27
|
+
/**
|
|
28
|
+
* By default, image is assumed to be under the current card. You can override this behaviour
|
|
29
|
+
*/
|
|
30
|
+
cardKey?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Alt text
|
|
33
|
+
*/
|
|
34
|
+
alt?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Title for the image
|
|
37
|
+
*/
|
|
38
|
+
title?: string;
|
|
39
|
+
}
|
|
@@ -13,19 +13,13 @@
|
|
|
13
13
|
|
|
14
14
|
import { evaluateMacros, validateMacroContent } from '../index.js';
|
|
15
15
|
|
|
16
|
+
import type { IncludeMacroOptions } from './types.js';
|
|
16
17
|
import type { MacroGenerationContext } from '../../interfaces/macros.js';
|
|
17
18
|
import macroMetadata from './metadata.js';
|
|
18
19
|
import BaseMacro from '../base-macro.js';
|
|
19
20
|
import type TaskQueue from '../task-queue.js';
|
|
20
21
|
import { MAX_LEVEL_OFFSET } from '../../utils/constants.js';
|
|
21
22
|
|
|
22
|
-
export interface IncludeMacroOptions {
|
|
23
|
-
cardKey: string;
|
|
24
|
-
levelOffset?: string;
|
|
25
|
-
title?: 'include' | 'exclude' | 'only';
|
|
26
|
-
pageTitles?: 'normal' | 'discrete';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
23
|
export default class IncludeMacro extends BaseMacro {
|
|
30
24
|
constructor(tasksQueue: TaskQueue) {
|
|
31
25
|
super(macroMetadata, tasksQueue);
|
|
@@ -46,18 +40,11 @@ export default class IncludeMacro extends BaseMacro {
|
|
|
46
40
|
if (!options.pageTitles) {
|
|
47
41
|
options.pageTitles = 'normal';
|
|
48
42
|
}
|
|
49
|
-
const card = await context.project.cardDetailsById(options.cardKey, {
|
|
50
|
-
content: true,
|
|
51
|
-
metadata: true,
|
|
52
|
-
});
|
|
53
|
-
if (!card) {
|
|
54
|
-
throw new Error(`Card key ${options.cardKey} not found`);
|
|
55
|
-
}
|
|
56
43
|
const newContext = {
|
|
57
44
|
...context,
|
|
58
45
|
cardKey: options.cardKey,
|
|
59
46
|
};
|
|
60
|
-
|
|
47
|
+
const card = this.getCard(options.cardKey, context);
|
|
61
48
|
const anchor = this.generateAnchor(options);
|
|
62
49
|
const title = this.generateTitle(options, card.metadata?.title);
|
|
63
50
|
const cardContent = await this.generateCardContent(
|
|
@@ -118,6 +105,10 @@ export default class IncludeMacro extends BaseMacro {
|
|
|
118
105
|
return '';
|
|
119
106
|
}
|
|
120
107
|
|
|
108
|
+
private getCard(cardKey: string, context: MacroGenerationContext) {
|
|
109
|
+
return context.project.findCard(cardKey);
|
|
110
|
+
}
|
|
111
|
+
|
|
121
112
|
// Adjust asciidoc titles to match the level offset
|
|
122
113
|
private adjustTitles(
|
|
123
114
|
content: string,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
|
+
the Free Software Foundation. This program is distributed in the hope that it
|
|
8
|
+
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
9
|
+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
10
|
+
See the GNU Affero General Public License for more details.
|
|
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
|
+
export interface IncludeMacroOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Card key of the card being included
|
|
18
|
+
*/
|
|
19
|
+
cardKey: string;
|
|
20
|
+
/**
|
|
21
|
+
* A positive number wil increase the level of headings and a negative alue will the level of headings in the included content
|
|
22
|
+
*/
|
|
23
|
+
levelOffset?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Determines behaviour with the title that is in card metadata
|
|
26
|
+
* include --> includes the title
|
|
27
|
+
* exclude --> excludes the title
|
|
28
|
+
* only --> includes title but does not import content
|
|
29
|
+
*/
|
|
30
|
+
title?: 'include' | 'exclude' | 'only';
|
|
31
|
+
pageTitles?: 'normal' | 'discrete';
|
|
32
|
+
}
|
package/src/macros/index.ts
CHANGED
|
@@ -186,7 +186,7 @@ export function validateMacroContent<T>(
|
|
|
186
186
|
* @param tasks - Tasks to register
|
|
187
187
|
* @returns macro instances
|
|
188
188
|
*/
|
|
189
|
-
export function registerMacros(
|
|
189
|
+
export async function registerMacros(
|
|
190
190
|
instance: typeof Handlebars,
|
|
191
191
|
context: MacroGenerationContext,
|
|
192
192
|
tasks: TaskQueue,
|
|
@@ -242,7 +242,7 @@ export async function evaluateMacros(
|
|
|
242
242
|
) {
|
|
243
243
|
const handlebars = Handlebars.create();
|
|
244
244
|
const tasks = new TaskQueue();
|
|
245
|
-
registerMacros(handlebars, context, tasks);
|
|
245
|
+
await registerMacros(handlebars, context, tasks);
|
|
246
246
|
let result = content;
|
|
247
247
|
while ((context.maxTries ?? 10) > 0) {
|
|
248
248
|
await tasks.reset();
|
|
@@ -15,17 +15,11 @@ import { createImage, validateMacroContent } from '../index.js';
|
|
|
15
15
|
|
|
16
16
|
import type { MacroGenerationContext } from '../../interfaces/macros.js';
|
|
17
17
|
import macroMetadata from './metadata.js';
|
|
18
|
+
import type { PercentageOptions } from './types.js';
|
|
18
19
|
import BaseMacro from '../base-macro.js';
|
|
19
20
|
import type TaskQueue from '../task-queue.js';
|
|
20
21
|
import { percentage } from '../../svg/index.js';
|
|
21
22
|
|
|
22
|
-
export interface PercentageOptions {
|
|
23
|
-
title: string;
|
|
24
|
-
value: number;
|
|
25
|
-
legend: string;
|
|
26
|
-
colour?: 'blue' | 'green' | 'yellow' | 'red' | 'orange' | 'purple';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
23
|
class PercentageMacro extends BaseMacro {
|
|
30
24
|
constructor(tasksQueue: TaskQueue) {
|
|
31
25
|
super(macroMetadata, tasksQueue);
|