@cyberismo/data-handler 0.0.14 → 0.0.15
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 +1 -3
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.js +10 -16
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +1 -1
- package/dist/command-manager.js +4 -3
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.js +13 -59
- 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.js +4 -17
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.js +3 -5
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.d.ts +1 -2
- package/dist/commands/move.js +108 -146
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.js +9 -44
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.js +2 -7
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +7 -25
- package/dist/commands/show.js +38 -102
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.js +27 -30
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +5 -3
- package/dist/commands/update.js +19 -5
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +3 -3
- package/dist/commands/validate.js +19 -26
- 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 +6 -0
- package/dist/containers/project/calculation-engine.js +19 -12
- 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/resource-collector.d.ts +24 -1
- package/dist/containers/project/resource-collector.js +8 -1
- package/dist/containers/project/resource-collector.js.map +1 -1
- package/dist/containers/project.d.ts +117 -83
- package/dist/containers/project.js +418 -252
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +15 -31
- package/dist/containers/template.js +97 -104
- 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 +2 -1
- 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 +5 -1
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +11 -21
- 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 +2 -2
- 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/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.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.js +4 -4
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/calculation-resource.d.ts +4 -32
- package/dist/resources/calculation-resource.js +0 -55
- package/dist/resources/calculation-resource.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +4 -21
- package/dist/resources/card-type-resource.js +13 -44
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +4 -21
- package/dist/resources/field-type-resource.js +14 -38
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +12 -29
- package/dist/resources/file-resource.js +19 -293
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +31 -50
- package/dist/resources/folder-resource.js +68 -96
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +5 -33
- package/dist/resources/graph-model-resource.js +8 -61
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +5 -28
- package/dist/resources/graph-view-resource.js +6 -45
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +4 -21
- package/dist/resources/link-type-resource.js +6 -31
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +5 -17
- package/dist/resources/report-resource.js +6 -44
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +58 -23
- package/dist/resources/resource-object.js +293 -24
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +4 -15
- package/dist/resources/template-resource.js +10 -25
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +4 -23
- package/dist/resources/workflow-resource.js +12 -38
- 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-facts.js +11 -3
- 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/package.json +5 -5
- package/src/card-metadata-updater.ts +3 -5
- package/src/command-handler.ts +11 -18
- package/src/command-manager.ts +4 -3
- package/src/commands/create.ts +17 -83
- package/src/commands/edit.ts +16 -132
- package/src/commands/export.ts +8 -29
- package/src/commands/import.ts +4 -6
- package/src/commands/move.ts +144 -179
- package/src/commands/remove.ts +9 -52
- package/src/commands/rename.ts +2 -7
- package/src/commands/show.ts +50 -143
- package/src/commands/transition.ts +30 -33
- package/src/commands/update.ts +27 -9
- package/src/commands/validate.ts +21 -36
- package/src/containers/card-container.ts +200 -360
- package/src/containers/project/calculation-engine.ts +21 -13
- package/src/containers/project/card-cache.ts +497 -0
- package/src/containers/project/resource-collector.ts +9 -1
- package/src/containers/project.ts +529 -327
- package/src/containers/template.ts +109 -127
- package/src/index.ts +1 -0
- package/src/interfaces/folder-content-interfaces.ts +7 -1
- package/src/interfaces/macros.ts +2 -0
- package/src/interfaces/project-interfaces.ts +7 -1
- package/src/interfaces/resource-interfaces.ts +12 -24
- package/src/macros/createCards/index.ts +1 -12
- package/src/macros/createCards/types.ts +46 -0
- package/src/macros/graph/index.ts +3 -7
- 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/percentage/index.ts +1 -7
- package/src/macros/percentage/types.ts +32 -0
- package/src/macros/report/index.ts +1 -4
- 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 +5 -5
- package/src/project-settings.ts +1 -1
- package/src/resources/calculation-resource.ts +6 -76
- package/src/resources/card-type-resource.ts +24 -59
- package/src/resources/field-type-resource.ts +22 -51
- package/src/resources/file-resource.ts +27 -409
- package/src/resources/folder-resource.ts +98 -124
- package/src/resources/graph-model-resource.ts +17 -74
- package/src/resources/graph-view-resource.ts +14 -54
- package/src/resources/link-type-resource.ts +13 -40
- package/src/resources/report-resource.ts +17 -57
- package/src/resources/resource-object.ts +435 -32
- package/src/resources/template-resource.ts +16 -29
- package/src/resources/workflow-resource.ts +26 -50
- package/src/utils/card-utils.ts +217 -31
- package/src/utils/clingo-facts.ts +13 -3
- package/src/utils/clingo-parser.ts +1 -1
- package/src/utils/constants.ts +6 -0
- package/src/utils/csv.ts +1 -1
|
@@ -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
|
+
}
|
|
@@ -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);
|
|
@@ -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 PercentageOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Title of percentage macro
|
|
18
|
+
*/
|
|
19
|
+
title: string;
|
|
20
|
+
/**
|
|
21
|
+
* Percentage value
|
|
22
|
+
*/
|
|
23
|
+
value: number;
|
|
24
|
+
/**
|
|
25
|
+
* Legend text below the macro
|
|
26
|
+
*/
|
|
27
|
+
legend: string;
|
|
28
|
+
/**
|
|
29
|
+
* Color of the bar the represents the percentage
|
|
30
|
+
*/
|
|
31
|
+
colour?: 'blue' | 'green' | 'yellow' | 'red' | 'orange' | 'purple';
|
|
32
|
+
}
|
|
@@ -22,10 +22,7 @@ import { ReportResource } from '../../resources/report-resource.js';
|
|
|
22
22
|
import { resourceName } from '../../utils/resource-utils.js';
|
|
23
23
|
import { generateReportContent } from '../../utils/report.js';
|
|
24
24
|
import { ClingoError } from '@cyberismo/node-clingo';
|
|
25
|
-
|
|
26
|
-
export interface ReportOptions {
|
|
27
|
-
name: string;
|
|
28
|
-
}
|
|
25
|
+
import type { ReportOptions } from './types.js';
|
|
29
26
|
|
|
30
27
|
class ReportMacro extends BaseMacro {
|
|
31
28
|
constructor(tasks: TaskQueue) {
|
|
@@ -0,0 +1,20 @@
|
|
|
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 ReportOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Name of the report
|
|
18
|
+
*/
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
@@ -19,13 +19,7 @@ import macroMetadata from './metadata.js';
|
|
|
19
19
|
import BaseMacro from '../base-macro.js';
|
|
20
20
|
import type TaskQueue from '../task-queue.js';
|
|
21
21
|
import { scoreCard } from '../../svg/index.js';
|
|
22
|
-
|
|
23
|
-
export interface ScoreCardOptions {
|
|
24
|
-
value: number;
|
|
25
|
-
legend?: string;
|
|
26
|
-
title?: string;
|
|
27
|
-
unit?: string;
|
|
28
|
-
}
|
|
22
|
+
import type { ScoreCardOptions } from './types.js';
|
|
29
23
|
|
|
30
24
|
class ScoreCardMacro extends BaseMacro {
|
|
31
25
|
constructor(tasksQueue: TaskQueue) {
|
|
@@ -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 ScoreCardOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Value shown in score card
|
|
18
|
+
*/
|
|
19
|
+
value: number;
|
|
20
|
+
/**
|
|
21
|
+
* Optional legend text
|
|
22
|
+
*/
|
|
23
|
+
legend?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Option title text
|
|
26
|
+
*/
|
|
27
|
+
title?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Option unit that is next to the value
|
|
30
|
+
*/
|
|
31
|
+
unit?: string;
|
|
32
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
import { CreateCardsOptions } from './createCards/types.js';
|
|
15
|
+
import { GraphOptions } from './graph/types.js';
|
|
16
|
+
import { ImageMacroOptions } from './image/types.js';
|
|
17
|
+
import { IncludeMacroOptions } from './include/types.js';
|
|
18
|
+
import { PercentageOptions } from './percentage/types.js';
|
|
19
|
+
import { ReportOptions } from './report/types.js';
|
|
20
|
+
import { ScoreCardOptions } from './scoreCard/types.js';
|
|
21
|
+
import { VegaMacroInput } from './vega/types.js';
|
|
22
|
+
import { VegaLiteMacroInput } from './vegalite/types.js';
|
|
23
|
+
import { XrefMacroOptions } from './xref/types.js';
|
|
24
|
+
|
|
25
|
+
export type AnyMacroOption =
|
|
26
|
+
| CreateCardsOptions
|
|
27
|
+
| GraphOptions
|
|
28
|
+
| ImageMacroOptions
|
|
29
|
+
| IncludeMacroOptions
|
|
30
|
+
| PercentageOptions
|
|
31
|
+
| ReportOptions
|
|
32
|
+
| ScoreCardOptions
|
|
33
|
+
| VegaMacroInput
|
|
34
|
+
| VegaLiteMacroInput
|
|
35
|
+
| XrefMacroOptions;
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
CreateCardsOptions,
|
|
39
|
+
GraphOptions,
|
|
40
|
+
ImageMacroOptions,
|
|
41
|
+
IncludeMacroOptions,
|
|
42
|
+
PercentageOptions,
|
|
43
|
+
ReportOptions,
|
|
44
|
+
ScoreCardOptions,
|
|
45
|
+
VegaMacroInput,
|
|
46
|
+
VegaLiteMacroInput,
|
|
47
|
+
XrefMacroOptions,
|
|
48
|
+
};
|
package/src/macros/vega/index.ts
CHANGED
|
@@ -21,10 +21,7 @@ import {
|
|
|
21
21
|
validateMacroContent,
|
|
22
22
|
} from '../index.js';
|
|
23
23
|
import * as vega from 'vega';
|
|
24
|
-
|
|
25
|
-
export interface VegaMacroInput {
|
|
26
|
-
spec: vega.Spec;
|
|
27
|
-
}
|
|
24
|
+
import type { VegaMacroInput } from './types.js';
|
|
28
25
|
|
|
29
26
|
class VegaMacro extends BaseMacro {
|
|
30
27
|
constructor(tasksQueue: TaskQueue) {
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
import type { Spec } from 'vega';
|
|
15
|
+
|
|
16
|
+
export interface VegaMacroInput {
|
|
17
|
+
/**
|
|
18
|
+
* Defines spec for vega
|
|
19
|
+
*/
|
|
20
|
+
spec: Spec;
|
|
21
|
+
}
|
|
@@ -16,10 +16,7 @@ import macroMetadata from './metadata.js';
|
|
|
16
16
|
import type TaskQueue from '../task-queue.js';
|
|
17
17
|
import * as vegaLite from 'vega-lite';
|
|
18
18
|
import { createMacro, validateMacroContent } from '../index.js';
|
|
19
|
-
|
|
20
|
-
export interface VegaLiteMacroInput {
|
|
21
|
-
spec: vegaLite.TopLevelSpec;
|
|
22
|
-
}
|
|
19
|
+
import type { VegaLiteMacroInput } from './types.js';
|
|
23
20
|
|
|
24
21
|
class VegaLiteMacro extends BaseMacro {
|
|
25
22
|
constructor(tasksQueue: TaskQueue) {
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
import type { TopLevelSpec } from 'vega-lite';
|
|
16
|
+
|
|
17
|
+
export interface VegaLiteMacroInput {
|
|
18
|
+
/**
|
|
19
|
+
* Defines spec for vega-lite
|
|
20
|
+
*/
|
|
21
|
+
spec: TopLevelSpec;
|
|
22
|
+
}
|
package/src/macros/xref/index.ts
CHANGED
|
@@ -17,10 +17,7 @@ import type { MacroGenerationContext } from '../../interfaces/macros.js';
|
|
|
17
17
|
import macroMetadata from './metadata.js';
|
|
18
18
|
import BaseMacro from '../base-macro.js';
|
|
19
19
|
import type TaskQueue from '../task-queue.js';
|
|
20
|
-
|
|
21
|
-
export interface XrefMacroOptions {
|
|
22
|
-
cardKey: string;
|
|
23
|
-
}
|
|
20
|
+
import type { XrefMacroOptions } from './types.js';
|
|
24
21
|
|
|
25
22
|
export default class XrefMacro extends BaseMacro {
|
|
26
23
|
constructor(tasksQueue: TaskQueue) {
|
|
@@ -36,7 +33,7 @@ export default class XrefMacro extends BaseMacro {
|
|
|
36
33
|
input: unknown,
|
|
37
34
|
): Promise<string> => {
|
|
38
35
|
const options = this.validate(input);
|
|
39
|
-
const card =
|
|
36
|
+
const card = this.getCard(options.cardKey, context);
|
|
40
37
|
|
|
41
38
|
if (!card || !card.metadata) {
|
|
42
39
|
throw new Error(`Card key ${options.cardKey} not found`);
|
|
@@ -48,23 +45,12 @@ export default class XrefMacro extends BaseMacro {
|
|
|
48
45
|
|
|
49
46
|
handleInject = async (context: MacroGenerationContext, input: unknown) => {
|
|
50
47
|
const options = this.validate(input);
|
|
51
|
-
const card =
|
|
52
|
-
|
|
53
|
-
if (!card || !card.metadata) {
|
|
54
|
-
throw new Error(`Card key ${options.cardKey} not found`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return `xref:${options.cardKey}.adoc[${card.metadata.title}]`;
|
|
48
|
+
const card = this.getCard(options.cardKey, context);
|
|
49
|
+
return `xref:${options.cardKey}.adoc[${card?.metadata?.title}]`;
|
|
58
50
|
};
|
|
59
51
|
|
|
60
|
-
private
|
|
61
|
-
|
|
62
|
-
metadata: true,
|
|
63
|
-
});
|
|
64
|
-
if (!card || !card.metadata) {
|
|
65
|
-
throw new Error(`Card key ${cardKey} not found`);
|
|
66
|
-
}
|
|
67
|
-
return card;
|
|
52
|
+
private getCard(cardKey: string, context: MacroGenerationContext) {
|
|
53
|
+
return context.project.findCard(cardKey);
|
|
68
54
|
}
|
|
69
55
|
|
|
70
56
|
private validate(input: unknown): XrefMacroOptions {
|
|
@@ -0,0 +1,20 @@
|
|
|
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 XrefMacroOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Card of the card being referenced
|
|
18
|
+
*/
|
|
19
|
+
cardKey: string;
|
|
20
|
+
}
|
package/src/module-manager.ts
CHANGED
|
@@ -309,10 +309,10 @@ export class ModuleManager {
|
|
|
309
309
|
|
|
310
310
|
// Collect modules that could be removed from .cards/modules when
|
|
311
311
|
// 'moduleName' is removed.
|
|
312
|
-
private
|
|
312
|
+
private orphanedModules(
|
|
313
313
|
dependencies: DependencyGraph,
|
|
314
314
|
moduleName: string,
|
|
315
|
-
):
|
|
315
|
+
): string[] {
|
|
316
316
|
const projectModules = this.project.configuration.modules;
|
|
317
317
|
const removableTransientModules: string[] = [];
|
|
318
318
|
if (dependencies.has(moduleName)) {
|
|
@@ -558,6 +558,7 @@ export class ModuleManager {
|
|
|
558
558
|
);
|
|
559
559
|
}
|
|
560
560
|
const sourceProject = new Project(source);
|
|
561
|
+
await sourceProject.populateCaches();
|
|
561
562
|
const modulePrefix = sourceProject.projectPrefix;
|
|
562
563
|
const destinationPath = join(
|
|
563
564
|
this.project.paths.modulesFolder,
|
|
@@ -625,7 +626,7 @@ export class ModuleManager {
|
|
|
625
626
|
// but modules under .cards/modules must be checked not to be used by
|
|
626
627
|
// other modules.
|
|
627
628
|
if (this.canBeRemoved(dependencies, moduleName)) {
|
|
628
|
-
const orphans =
|
|
629
|
+
const orphans = this.orphanedModules(dependencies, moduleName);
|
|
629
630
|
await deleteDir(module.path);
|
|
630
631
|
for (const moduleToDelete of orphans) {
|
|
631
632
|
const modulePath = join(
|
|
@@ -634,9 +635,8 @@ export class ModuleManager {
|
|
|
634
635
|
);
|
|
635
636
|
await deleteDir(modulePath);
|
|
636
637
|
}
|
|
637
|
-
await this.project.collectModuleResources();
|
|
638
638
|
}
|
|
639
|
-
await this.project.
|
|
639
|
+
await this.project.removeModule(moduleName);
|
|
640
640
|
}
|
|
641
641
|
|
|
642
642
|
/**
|