@cyberismo/data-handler 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +702 -0
- package/dist/card-metadata-updater.d.ts +33 -0
- package/dist/card-metadata-updater.js +121 -0
- package/dist/card-metadata-updater.js.map +1 -0
- package/dist/command-handler.d.ts +96 -0
- package/dist/command-handler.js +557 -0
- package/dist/command-handler.js.map +1 -0
- package/dist/command-manager.d.ts +43 -0
- package/dist/command-manager.js +73 -0
- package/dist/command-manager.js.map +1 -0
- package/dist/commands/calculate.d.ts +86 -0
- package/dist/commands/calculate.js +444 -0
- package/dist/commands/calculate.js.map +1 -0
- package/dist/commands/create.d.ts +114 -0
- package/dist/commands/create.js +389 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/edit.d.ts +37 -0
- package/dist/commands/edit.js +99 -0
- package/dist/commands/edit.js.map +1 -0
- package/dist/commands/export-site.d.ts +45 -0
- package/dist/commands/export-site.js +301 -0
- package/dist/commands/export-site.js.map +1 -0
- package/dist/commands/export.d.ts +53 -0
- package/dist/commands/export.js +251 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/import.d.ts +53 -0
- package/dist/commands/import.js +133 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/index.d.ts +26 -0
- package/dist/commands/index.js +27 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/move.d.ts +55 -0
- package/dist/commands/move.js +341 -0
- package/dist/commands/move.js.map +1 -0
- package/dist/commands/remove.d.ts +38 -0
- package/dist/commands/remove.js +192 -0
- package/dist/commands/remove.js.map +1 -0
- package/dist/commands/rename.d.ts +46 -0
- package/dist/commands/rename.js +289 -0
- package/dist/commands/rename.js.map +1 -0
- package/dist/commands/show.d.ts +124 -0
- package/dist/commands/show.js +345 -0
- package/dist/commands/show.js.map +1 -0
- package/dist/commands/transition.d.ts +27 -0
- package/dist/commands/transition.js +92 -0
- package/dist/commands/transition.js.map +1 -0
- package/dist/commands/update.d.ts +29 -0
- package/dist/commands/update.js +64 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/validate.d.ts +143 -0
- package/dist/commands/validate.js +689 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/containers/card-container.d.ts +44 -0
- package/dist/containers/card-container.js +282 -0
- package/dist/containers/card-container.js.map +1 -0
- package/dist/containers/project/project-paths.d.ts +46 -0
- package/dist/containers/project/project-paths.js +105 -0
- package/dist/containers/project/project-paths.js.map +1 -0
- package/dist/containers/project/resource-collector.d.ts +86 -0
- package/dist/containers/project/resource-collector.js +331 -0
- package/dist/containers/project/resource-collector.js.map +1 -0
- package/dist/containers/project.d.ts +351 -0
- package/dist/containers/project.js +896 -0
- package/dist/containers/project.js.map +1 -0
- package/dist/containers/template.d.ts +108 -0
- package/dist/containers/template.js +433 -0
- package/dist/containers/template.js.map +1 -0
- package/dist/exceptions/index.d.ts +19 -0
- package/dist/exceptions/index.js +26 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/adoc.d.ts +12 -0
- package/dist/interfaces/adoc.js +13 -0
- package/dist/interfaces/adoc.js.map +1 -0
- package/dist/interfaces/macros.d.ts +45 -0
- package/dist/interfaces/macros.js +13 -0
- package/dist/interfaces/macros.js.map +1 -0
- package/dist/interfaces/project-interfaces.d.ts +121 -0
- package/dist/interfaces/project-interfaces.js +21 -0
- package/dist/interfaces/project-interfaces.js.map +1 -0
- package/dist/interfaces/request-status-interfaces.d.ts +28 -0
- package/dist/interfaces/request-status-interfaces.js +20 -0
- package/dist/interfaces/request-status-interfaces.js.map +1 -0
- package/dist/interfaces/resource-interfaces.d.ts +117 -0
- package/dist/interfaces/resource-interfaces.js +20 -0
- package/dist/interfaces/resource-interfaces.js.map +1 -0
- package/dist/macros/base-macro.d.ts +31 -0
- package/dist/macros/base-macro.js +126 -0
- package/dist/macros/base-macro.js.map +1 -0
- package/dist/macros/common.d.ts +17 -0
- package/dist/macros/common.js +23 -0
- package/dist/macros/common.js.map +1 -0
- package/dist/macros/createCards/index.d.ts +36 -0
- package/dist/macros/createCards/index.js +35 -0
- package/dist/macros/createCards/index.js.map +1 -0
- package/dist/macros/createCards/metadata.d.ts +14 -0
- package/dist/macros/createCards/metadata.js +18 -0
- package/dist/macros/createCards/metadata.js.map +1 -0
- package/dist/macros/graph/index.d.ts +29 -0
- package/dist/macros/graph/index.js +91 -0
- package/dist/macros/graph/index.js.map +1 -0
- package/dist/macros/graph/metadata.d.ts +14 -0
- package/dist/macros/graph/metadata.js +18 -0
- package/dist/macros/graph/metadata.js.map +1 -0
- package/dist/macros/index.d.ts +93 -0
- package/dist/macros/index.js +237 -0
- package/dist/macros/index.js.map +1 -0
- package/dist/macros/report/index.d.ts +26 -0
- package/dist/macros/report/index.js +70 -0
- package/dist/macros/report/index.js.map +1 -0
- package/dist/macros/report/metadata.d.ts +14 -0
- package/dist/macros/report/metadata.js +18 -0
- package/dist/macros/report/metadata.js.map +1 -0
- package/dist/macros/scoreCard/index.d.ts +30 -0
- package/dist/macros/scoreCard/index.js +38 -0
- package/dist/macros/scoreCard/index.js.map +1 -0
- package/dist/macros/scoreCard/metadata.d.ts +14 -0
- package/dist/macros/scoreCard/metadata.js +18 -0
- package/dist/macros/scoreCard/metadata.js.map +1 -0
- package/dist/macros/task-queue.d.ts +46 -0
- package/dist/macros/task-queue.js +69 -0
- package/dist/macros/task-queue.js.map +1 -0
- package/dist/module-manager.d.ts +62 -0
- package/dist/module-manager.js +350 -0
- package/dist/module-manager.js.map +1 -0
- package/dist/permissions/action-guard.d.ts +28 -0
- package/dist/permissions/action-guard.js +61 -0
- package/dist/permissions/action-guard.js.map +1 -0
- package/dist/project-settings.d.ts +42 -0
- package/dist/project-settings.js +120 -0
- package/dist/project-settings.js.map +1 -0
- package/dist/resources/array-handler.d.ts +28 -0
- package/dist/resources/array-handler.js +116 -0
- package/dist/resources/array-handler.js.map +1 -0
- package/dist/resources/card-type-resource.d.ts +72 -0
- package/dist/resources/card-type-resource.js +334 -0
- package/dist/resources/card-type-resource.js.map +1 -0
- package/dist/resources/create-defaults.d.ts +81 -0
- package/dist/resources/create-defaults.js +184 -0
- package/dist/resources/create-defaults.js.map +1 -0
- package/dist/resources/field-type-resource.d.ts +88 -0
- package/dist/resources/field-type-resource.js +411 -0
- package/dist/resources/field-type-resource.js.map +1 -0
- package/dist/resources/file-resource.d.ts +50 -0
- package/dist/resources/file-resource.js +301 -0
- package/dist/resources/file-resource.js.map +1 -0
- package/dist/resources/folder-resource.d.ts +66 -0
- package/dist/resources/folder-resource.js +100 -0
- package/dist/resources/folder-resource.js.map +1 -0
- package/dist/resources/graph-model-resource.d.ts +78 -0
- package/dist/resources/graph-model-resource.js +164 -0
- package/dist/resources/graph-model-resource.js.map +1 -0
- package/dist/resources/graph-view-resource.d.ts +78 -0
- package/dist/resources/graph-view-resource.js +163 -0
- package/dist/resources/graph-view-resource.js.map +1 -0
- package/dist/resources/link-type-resource.d.ts +62 -0
- package/dist/resources/link-type-resource.js +150 -0
- package/dist/resources/link-type-resource.js.map +1 -0
- package/dist/resources/report-resource.d.ts +77 -0
- package/dist/resources/report-resource.js +171 -0
- package/dist/resources/report-resource.js.map +1 -0
- package/dist/resources/resource-object.d.ts +108 -0
- package/dist/resources/resource-object.js +147 -0
- package/dist/resources/resource-object.js.map +1 -0
- package/dist/resources/template-resource.d.ts +82 -0
- package/dist/resources/template-resource.js +173 -0
- package/dist/resources/template-resource.js.map +1 -0
- package/dist/resources/workflow-resource.d.ts +67 -0
- package/dist/resources/workflow-resource.js +156 -0
- package/dist/resources/workflow-resource.js.map +1 -0
- package/dist/types/queries.d.ts +142 -0
- package/dist/types/queries.js +16 -0
- package/dist/types/queries.js.map +1 -0
- package/dist/utils/card-utils.d.ts +34 -0
- package/dist/utils/card-utils.js +78 -0
- package/dist/utils/card-utils.js.map +1 -0
- package/dist/utils/clingo-fact-builder.d.ts +58 -0
- package/dist/utils/clingo-fact-builder.js +126 -0
- package/dist/utils/clingo-fact-builder.js.map +1 -0
- package/dist/utils/clingo-facts.d.ts +97 -0
- package/dist/utils/clingo-facts.js +352 -0
- package/dist/utils/clingo-facts.js.map +1 -0
- package/dist/utils/clingo-parser.d.ts +59 -0
- package/dist/utils/clingo-parser.js +403 -0
- package/dist/utils/clingo-parser.js.map +1 -0
- package/dist/utils/clingo-program-builder.d.ts +39 -0
- package/dist/utils/clingo-program-builder.js +57 -0
- package/dist/utils/clingo-program-builder.js.map +1 -0
- package/dist/utils/common-utils.d.ts +24 -0
- package/dist/utils/common-utils.js +47 -0
- package/dist/utils/common-utils.js.map +1 -0
- package/dist/utils/constants.d.ts +18 -0
- package/dist/utils/constants.js +27 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/csv.d.ts +18 -0
- package/dist/utils/csv.js +45 -0
- package/dist/utils/csv.js.map +1 -0
- package/dist/utils/file-utils.d.ts +69 -0
- package/dist/utils/file-utils.js +158 -0
- package/dist/utils/file-utils.js.map +1 -0
- package/dist/utils/json.d.ts +61 -0
- package/dist/utils/json.js +108 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/lexorank.d.ts +59 -0
- package/dist/utils/lexorank.js +159 -0
- package/dist/utils/lexorank.js.map +1 -0
- package/dist/utils/log-utils.d.ts +40 -0
- package/dist/utils/log-utils.js +109 -0
- package/dist/utils/log-utils.js.map +1 -0
- package/dist/utils/random.d.ts +19 -0
- package/dist/utils/random.js +34 -0
- package/dist/utils/random.js.map +1 -0
- package/dist/utils/resource-utils.d.ts +45 -0
- package/dist/utils/resource-utils.js +137 -0
- package/dist/utils/resource-utils.js.map +1 -0
- package/dist/utils/sanitize-svg.d.ts +18 -0
- package/dist/utils/sanitize-svg.js +38 -0
- package/dist/utils/sanitize-svg.js.map +1 -0
- package/dist/utils/user-preferences.d.ts +64 -0
- package/dist/utils/user-preferences.js +106 -0
- package/dist/utils/user-preferences.js.map +1 -0
- package/dist/utils/validate.d.ts +26 -0
- package/dist/utils/validate.js +53 -0
- package/dist/utils/validate.js.map +1 -0
- package/dist/utils/value-utils.d.ts +58 -0
- package/dist/utils/value-utils.js +181 -0
- package/dist/utils/value-utils.js.map +1 -0
- package/package.json +67 -0
- package/src/card-metadata-updater.ts +182 -0
- package/src/command-handler.ts +686 -0
- package/src/command-manager.ts +99 -0
- package/src/commands/calculate.ts +591 -0
- package/src/commands/create.ts +559 -0
- package/src/commands/edit.ts +123 -0
- package/src/commands/export-site.ts +356 -0
- package/src/commands/export.ts +315 -0
- package/src/commands/import.ts +169 -0
- package/src/commands/index.ts +42 -0
- package/src/commands/move.ts +451 -0
- package/src/commands/remove.ts +244 -0
- package/src/commands/rename.ts +378 -0
- package/src/commands/show.ts +442 -0
- package/src/commands/transition.ts +127 -0
- package/src/commands/update.ts +76 -0
- package/src/commands/validate.ts +962 -0
- package/src/containers/card-container.ts +378 -0
- package/src/containers/project/project-paths.ts +127 -0
- package/src/containers/project/resource-collector.ts +379 -0
- package/src/containers/project.ts +1135 -0
- package/src/containers/template.ts +573 -0
- package/src/exceptions/index.ts +29 -0
- package/src/index.ts +33 -0
- package/src/interfaces/adoc.ts +18 -0
- package/src/interfaces/macros.ts +54 -0
- package/src/interfaces/project-interfaces.ts +208 -0
- package/src/interfaces/request-status-interfaces.ts +30 -0
- package/src/interfaces/resource-interfaces.ts +179 -0
- package/src/macros/base-macro.ts +176 -0
- package/src/macros/common.ts +24 -0
- package/src/macros/createCards/index.ts +57 -0
- package/src/macros/createCards/metadata.ts +21 -0
- package/src/macros/graph/index.ts +130 -0
- package/src/macros/graph/metadata.ts +21 -0
- package/src/macros/index.ts +321 -0
- package/src/macros/report/index.ts +88 -0
- package/src/macros/report/metadata.ts +21 -0
- package/src/macros/scoreCard/index.ts +55 -0
- package/src/macros/scoreCard/metadata.ts +21 -0
- package/src/macros/task-queue.ts +79 -0
- package/src/module-manager.ts +443 -0
- package/src/permissions/action-guard.ts +77 -0
- package/src/project-settings.ts +140 -0
- package/src/resources/array-handler.ts +141 -0
- package/src/resources/card-type-resource.ts +455 -0
- package/src/resources/create-defaults.ts +216 -0
- package/src/resources/field-type-resource.ts +533 -0
- package/src/resources/file-resource.ts +433 -0
- package/src/resources/folder-resource.ts +140 -0
- package/src/resources/graph-model-resource.ts +205 -0
- package/src/resources/graph-view-resource.ts +199 -0
- package/src/resources/link-type-resource.ts +191 -0
- package/src/resources/report-resource.ts +224 -0
- package/src/resources/resource-object.ts +246 -0
- package/src/resources/template-resource.ts +210 -0
- package/src/resources/workflow-resource.ts +205 -0
- package/src/types/queries.ts +149 -0
- package/src/utils/card-utils.ts +83 -0
- package/src/utils/clingo-fact-builder.ts +167 -0
- package/src/utils/clingo-facts.ts +550 -0
- package/src/utils/clingo-parser.ts +519 -0
- package/src/utils/clingo-program-builder.ts +71 -0
- package/src/utils/common-utils.ts +54 -0
- package/src/utils/constants.ts +32 -0
- package/src/utils/csv.ts +53 -0
- package/src/utils/file-utils.ts +182 -0
- package/src/utils/json.ts +118 -0
- package/src/utils/lexorank.ts +180 -0
- package/src/utils/log-utils.ts +127 -0
- package/src/utils/random.ts +37 -0
- package/src/utils/resource-utils.ts +180 -0
- package/src/utils/sanitize-svg.ts +46 -0
- package/src/utils/user-preferences.ts +126 -0
- package/src/utils/validate.ts +66 -0
- package/src/utils/value-utils.ts +189 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
/**
|
|
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/>.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// node
|
|
15
|
+
import { basename, join, resolve, sep } from 'node:path';
|
|
16
|
+
import { copyFile, mkdir, readdir, rm, writeFile } from 'node:fs/promises';
|
|
17
|
+
import { type Dirent, readdirSync } from 'node:fs';
|
|
18
|
+
|
|
19
|
+
// Base class
|
|
20
|
+
import { CardContainer } from './card-container.js';
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
type Card,
|
|
24
|
+
type CardAttachment,
|
|
25
|
+
CardNameRegEx,
|
|
26
|
+
type FetchCardDetails,
|
|
27
|
+
type FileContentType,
|
|
28
|
+
type Resource,
|
|
29
|
+
} from '../interfaces/project-interfaces.js';
|
|
30
|
+
import type { CardType, Workflow } from '../interfaces/resource-interfaces.js';
|
|
31
|
+
import { pathExists, stripExtension } from '../utils/file-utils.js';
|
|
32
|
+
import { DefaultContent } from '../resources/create-defaults.js';
|
|
33
|
+
|
|
34
|
+
import {
|
|
35
|
+
EMPTY_RANK,
|
|
36
|
+
FIRST_RANK,
|
|
37
|
+
getRankAfter,
|
|
38
|
+
sortItems,
|
|
39
|
+
} from '../utils/lexorank.js';
|
|
40
|
+
import { logger } from '../utils/log-utils.js';
|
|
41
|
+
import { readJsonFile } from '../utils/json.js';
|
|
42
|
+
import { Project } from './project.js';
|
|
43
|
+
import { resourceName } from '../utils/resource-utils.js';
|
|
44
|
+
|
|
45
|
+
// creates template instance based on a project path and name
|
|
46
|
+
export class Template extends CardContainer {
|
|
47
|
+
private templatePath: string;
|
|
48
|
+
private templateCardsPath: string;
|
|
49
|
+
private project: Project;
|
|
50
|
+
|
|
51
|
+
constructor(project: Project, template: Resource) {
|
|
52
|
+
// Templates might come from modules. Remove module name from template name.
|
|
53
|
+
const templateName = stripExtension(basename(template.name));
|
|
54
|
+
super(template.path!, templateName);
|
|
55
|
+
|
|
56
|
+
// prevent constructing a new project object, if one is passed to this class.
|
|
57
|
+
this.project = project;
|
|
58
|
+
// optimization - if template.path is set - use it
|
|
59
|
+
this.templatePath =
|
|
60
|
+
template.path && template.path.length > 0
|
|
61
|
+
? join(template.path, templateName)
|
|
62
|
+
: this.setTemplatePath(template.name);
|
|
63
|
+
this.templateCardsPath = join(this.templatePath, 'c');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Fetches project top level cards only.
|
|
67
|
+
// Top level cards are those that have parent as 'root'.
|
|
68
|
+
// todo: This should be in 'project' or 'card-container'
|
|
69
|
+
private async rootLevelProjectCards(): Promise<Card[]> {
|
|
70
|
+
const entries = (
|
|
71
|
+
await readdir(this.project.paths.cardRootFolder, {
|
|
72
|
+
withFileTypes: true,
|
|
73
|
+
})
|
|
74
|
+
).filter((entry) => entry.isDirectory() && CardNameRegEx.test(entry.name));
|
|
75
|
+
const cardPromises = entries.map(async (entry) => {
|
|
76
|
+
const currentPath = join(entry.parentPath, entry.name);
|
|
77
|
+
return {
|
|
78
|
+
key: entry.name,
|
|
79
|
+
path: currentPath,
|
|
80
|
+
metadata: await readJsonFile(
|
|
81
|
+
join(currentPath, CardContainer.cardMetadataFile),
|
|
82
|
+
),
|
|
83
|
+
children: [],
|
|
84
|
+
attachments: [],
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
return Promise.all(cardPromises);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Creates card(s) as project cards from template.
|
|
91
|
+
private async doCreateCards(
|
|
92
|
+
cards: Card[],
|
|
93
|
+
parentCard?: Card,
|
|
94
|
+
): Promise<Card[]> {
|
|
95
|
+
const templateIDMap = new Map<string, string>();
|
|
96
|
+
// Create ID mapping and update ranks
|
|
97
|
+
const createMappingAndRanks = async () => {
|
|
98
|
+
const cardIds = await this.project.listCardIds();
|
|
99
|
+
const newCardIds = this.project.newCardKeys(cards.length, cardIds);
|
|
100
|
+
|
|
101
|
+
// Create mapping table
|
|
102
|
+
cards.forEach((card, index) => {
|
|
103
|
+
templateIDMap.set(card.key, newCardIds.at(index) || '');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Handle ranking for parent cards
|
|
107
|
+
const parentCards = sortItems(
|
|
108
|
+
cards.filter((c) => c.parent === 'root'),
|
|
109
|
+
(c) => c?.metadata?.rank || '',
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const futureSiblings = parentCard
|
|
113
|
+
? parentCard.children || []
|
|
114
|
+
: await this.rootLevelProjectCards();
|
|
115
|
+
|
|
116
|
+
let latestRank =
|
|
117
|
+
sortItems(
|
|
118
|
+
futureSiblings.filter((c) => c.metadata?.rank !== undefined),
|
|
119
|
+
(c) => c.metadata?.rank || '',
|
|
120
|
+
).pop()?.metadata?.rank || FIRST_RANK;
|
|
121
|
+
|
|
122
|
+
// Update ranks
|
|
123
|
+
parentCards.forEach((card) => {
|
|
124
|
+
latestRank = getRankAfter(latestRank);
|
|
125
|
+
if (card.metadata) {
|
|
126
|
+
card.metadata.rank = latestRank;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return parentCards;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Update paths and keys
|
|
134
|
+
const updateCardPaths = (
|
|
135
|
+
card: Card,
|
|
136
|
+
templateIDMap: Map<string, string>,
|
|
137
|
+
templatesFolder: string,
|
|
138
|
+
) => {
|
|
139
|
+
const updatePathPart = (part: string) =>
|
|
140
|
+
CardNameRegEx.test(part)
|
|
141
|
+
? `${sep}${templateIDMap.get(part) || part}`
|
|
142
|
+
: `${sep}${part}`;
|
|
143
|
+
|
|
144
|
+
card.path = card.path
|
|
145
|
+
.split(sep)
|
|
146
|
+
.map(updatePathPart)
|
|
147
|
+
.join('')
|
|
148
|
+
.substring(1);
|
|
149
|
+
|
|
150
|
+
if (card.path.includes(`${sep}c${sep}`) && !parentCard) {
|
|
151
|
+
card.path = card.path.replace(
|
|
152
|
+
`${templatesFolder}${sep}c`,
|
|
153
|
+
this.project.paths.cardRootFolder,
|
|
154
|
+
);
|
|
155
|
+
} else {
|
|
156
|
+
card.path = card.path.replace(
|
|
157
|
+
templatesFolder,
|
|
158
|
+
parentCard ? parentCard.path : this.project.paths.cardRootFolder,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
card.key = templateIDMap.get(card.key) || card.key;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// Process attachments
|
|
166
|
+
const processAttachments = async (card: Card) => {
|
|
167
|
+
if (!card.attachments.length) return card;
|
|
168
|
+
|
|
169
|
+
const attachmentsFolder = join(card.path, 'a');
|
|
170
|
+
await mkdir(attachmentsFolder, { recursive: true });
|
|
171
|
+
|
|
172
|
+
let content = card.content;
|
|
173
|
+
await Promise.all(
|
|
174
|
+
card.attachments.map(async (attachment) => {
|
|
175
|
+
const attachmentUniqueName = `${card.key}-${attachment.fileName}`;
|
|
176
|
+
content = content?.replace(
|
|
177
|
+
new RegExp(`image::${attachment.fileName}`, 'g'),
|
|
178
|
+
`image::${attachmentUniqueName}`,
|
|
179
|
+
);
|
|
180
|
+
await copyFile(
|
|
181
|
+
join(attachment.path, attachment.fileName),
|
|
182
|
+
join(card.path, 'a', attachmentUniqueName),
|
|
183
|
+
);
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
return { ...card, content };
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// Process metadata
|
|
190
|
+
const processMetadata = async (card: Card, parentCards: Card[]) => {
|
|
191
|
+
if (!card.metadata) return card;
|
|
192
|
+
|
|
193
|
+
const cardType = await this.project.resource<CardType>(
|
|
194
|
+
card.metadata.cardType || '',
|
|
195
|
+
);
|
|
196
|
+
if (!cardType) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
`Card type '${card.metadata.cardType}' of card ${card.key} cannot be found`,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const workflow = await this.project.resource<Workflow>(cardType.workflow);
|
|
203
|
+
if (!workflow) {
|
|
204
|
+
throw new Error(`Workflow '${cardType.workflow}' cannot be found`);
|
|
205
|
+
}
|
|
206
|
+
const initialWorkflowState = workflow.transitions.find(
|
|
207
|
+
(item) => item.fromState.includes('') || item.fromState.length === 0,
|
|
208
|
+
);
|
|
209
|
+
if (!initialWorkflowState) {
|
|
210
|
+
throw new Error(
|
|
211
|
+
`Workflow '${cardType.workflow}' initial state cannot be found`,
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const cardWithRank = parentCards.find((c) => c.key === card.key);
|
|
216
|
+
const customFields = cardType.customFields
|
|
217
|
+
.filter((item) => !item.isCalculated)
|
|
218
|
+
.reduce(
|
|
219
|
+
(acc, field) => ({
|
|
220
|
+
...acc,
|
|
221
|
+
[field.name]: card.metadata?.[field.name] || null,
|
|
222
|
+
}),
|
|
223
|
+
{},
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const newMetadata = {
|
|
227
|
+
...card.metadata,
|
|
228
|
+
...customFields,
|
|
229
|
+
templateCardKey: [...templateIDMap]
|
|
230
|
+
.find(([, value]) => value === card.key)!
|
|
231
|
+
.at(0),
|
|
232
|
+
workflowState: initialWorkflowState.toState,
|
|
233
|
+
cardType: cardType.name,
|
|
234
|
+
rank: cardWithRank?.metadata?.rank || card.metadata.rank || EMPTY_RANK,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
return { ...card, metadata: newMetadata };
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
// Create mapping and handle ranks
|
|
242
|
+
const parentCards = await createMappingAndRanks();
|
|
243
|
+
const templatesFolder = this.templateFolder();
|
|
244
|
+
|
|
245
|
+
// Process all cards in parallel
|
|
246
|
+
const processedCards = await Promise.all(
|
|
247
|
+
cards.map(async (card) => {
|
|
248
|
+
// Update paths and keys
|
|
249
|
+
updateCardPaths(card, templateIDMap, templatesFolder);
|
|
250
|
+
|
|
251
|
+
// Process metadata and attachments in parallel
|
|
252
|
+
const [processedCard, processedAttachments] = await Promise.all([
|
|
253
|
+
processMetadata(card, parentCards),
|
|
254
|
+
processAttachments(card),
|
|
255
|
+
]);
|
|
256
|
+
|
|
257
|
+
// Create directory and write files
|
|
258
|
+
await mkdir(processedCard.path, { recursive: true });
|
|
259
|
+
|
|
260
|
+
await Promise.all([
|
|
261
|
+
processedCard.metadata && this.saveCardMetadata(processedCard),
|
|
262
|
+
writeFile(
|
|
263
|
+
join(processedCard.path, Project.cardContentFile),
|
|
264
|
+
processedAttachments.content || '',
|
|
265
|
+
),
|
|
266
|
+
]);
|
|
267
|
+
return processedCard;
|
|
268
|
+
}),
|
|
269
|
+
);
|
|
270
|
+
return processedCards;
|
|
271
|
+
} catch (error) {
|
|
272
|
+
await this.removeCards(templateIDMap);
|
|
273
|
+
if (error instanceof Error) {
|
|
274
|
+
throw new Error(`Failed to create cards: ${error.message}`);
|
|
275
|
+
}
|
|
276
|
+
throw error;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// fetches path to module.
|
|
281
|
+
private moduleTemplatePath(templateName: string): string {
|
|
282
|
+
// If template path has already been deduced, return it.
|
|
283
|
+
if (pathExists(this.templatePath)) {
|
|
284
|
+
return this.templatePath;
|
|
285
|
+
}
|
|
286
|
+
let modules: Dirent[] = [];
|
|
287
|
+
try {
|
|
288
|
+
modules = readdirSync(this.project.paths.modulesFolder, {
|
|
289
|
+
withFileTypes: true,
|
|
290
|
+
}).filter((item) => item.isDirectory());
|
|
291
|
+
} catch {
|
|
292
|
+
// do nothing, if modules folder does not exist
|
|
293
|
+
}
|
|
294
|
+
for (const module of modules) {
|
|
295
|
+
const templateFolderInModule = join(
|
|
296
|
+
module.parentPath,
|
|
297
|
+
module.name,
|
|
298
|
+
'templates',
|
|
299
|
+
templateName,
|
|
300
|
+
);
|
|
301
|
+
const exists = pathExists(templateFolderInModule);
|
|
302
|
+
if (exists) {
|
|
303
|
+
return templateFolderInModule;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return '';
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Removes cards
|
|
310
|
+
private async removeCards(cardMap: Map<string, string>) {
|
|
311
|
+
const tasks: Promise<Card | undefined>[] = [];
|
|
312
|
+
// Find all cards that need to be removed.
|
|
313
|
+
cardMap.forEach((createdCard) => {
|
|
314
|
+
tasks.push(this.project.findSpecificCard(createdCard));
|
|
315
|
+
});
|
|
316
|
+
// Remove empty results.
|
|
317
|
+
const cards = (await Promise.all(tasks)).filter(
|
|
318
|
+
(item) => item !== undefined,
|
|
319
|
+
);
|
|
320
|
+
// Delete card folders.
|
|
321
|
+
const deleteAll: Promise<void>[] = [];
|
|
322
|
+
cards.forEach((card) => {
|
|
323
|
+
deleteAll.push(rm(card.path, { force: true, recursive: true }));
|
|
324
|
+
});
|
|
325
|
+
await Promise.all(deleteAll);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Set path to template location.
|
|
329
|
+
private setTemplatePath(templateName: string): string {
|
|
330
|
+
const { prefix, identifier } = resourceName(templateName);
|
|
331
|
+
const localTemplate = join(this.project.paths.templatesFolder, identifier);
|
|
332
|
+
|
|
333
|
+
// Template can either be local ...
|
|
334
|
+
if (prefix === this.project.projectPrefix) {
|
|
335
|
+
const localTemplate = join(
|
|
336
|
+
this.project.paths.templatesFolder,
|
|
337
|
+
identifier,
|
|
338
|
+
);
|
|
339
|
+
const createdLocalTemplate = pathExists(resolve(localTemplate));
|
|
340
|
+
if (createdLocalTemplate) {
|
|
341
|
+
return resolve(localTemplate);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ... or from module ...
|
|
346
|
+
const createdModuleTemplatePath = this.moduleTemplatePath(identifier);
|
|
347
|
+
if (createdModuleTemplatePath !== '') {
|
|
348
|
+
return resolve(createdModuleTemplatePath);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ... or not created yet; in case assume it will be 'local' (you cannot create templates to modules)
|
|
352
|
+
return resolve(localTemplate);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Adds a new card to template.
|
|
357
|
+
* @param cardTypeName card type
|
|
358
|
+
* @param parentCard parent card; optional - if missing will create a top-level card
|
|
359
|
+
* @returns next available card key ID
|
|
360
|
+
*/
|
|
361
|
+
public async addCard(
|
|
362
|
+
cardTypeName: string,
|
|
363
|
+
parentCard?: Card,
|
|
364
|
+
): Promise<string> {
|
|
365
|
+
const destinationCardPath = parentCard
|
|
366
|
+
? join(await this.cardFolder(parentCard.key), 'c')
|
|
367
|
+
: this.templateCardsPath;
|
|
368
|
+
let newCardKey = '';
|
|
369
|
+
|
|
370
|
+
try {
|
|
371
|
+
if (!pathExists(this.templateFolder())) {
|
|
372
|
+
throw new Error(`Template '${this.containerName}' does not exist`);
|
|
373
|
+
}
|
|
374
|
+
const cardType = await this.project.resource<CardType>(cardTypeName);
|
|
375
|
+
if (cardType === undefined) {
|
|
376
|
+
throw new Error(`Card type '${cardTypeName}' does not exist`);
|
|
377
|
+
}
|
|
378
|
+
if (parentCard && !this.hasCard(parentCard.key)) {
|
|
379
|
+
throw new Error(
|
|
380
|
+
`Card '${parentCard.key}' does not exist in template '${this.containerName}'`,
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const cardIds = await this.project.listCardIds();
|
|
385
|
+
newCardKey = this.project.newCardKey(cardIds);
|
|
386
|
+
const templateCardToCreate = parentCard
|
|
387
|
+
? join(destinationCardPath, newCardKey)
|
|
388
|
+
: join(this.templateCardsPath, newCardKey);
|
|
389
|
+
|
|
390
|
+
const templateCards = parentCard
|
|
391
|
+
? parentCard.children || []
|
|
392
|
+
: await this.cards();
|
|
393
|
+
const defaultContent = DefaultContent.card(cardType, templateCards);
|
|
394
|
+
|
|
395
|
+
await mkdir(templateCardToCreate, { recursive: true });
|
|
396
|
+
const defaultCard: Card = {
|
|
397
|
+
key: basename(templateCardToCreate),
|
|
398
|
+
path: templateCardToCreate,
|
|
399
|
+
metadata: defaultContent,
|
|
400
|
+
children: [],
|
|
401
|
+
attachments: [],
|
|
402
|
+
content: '',
|
|
403
|
+
};
|
|
404
|
+
await this.saveCard(defaultCard);
|
|
405
|
+
} catch (error) {
|
|
406
|
+
if (error instanceof Error) {
|
|
407
|
+
throw new Error(error.message);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return newCardKey;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Return all attachment in the template.
|
|
415
|
+
* @returns all attachments in the template.
|
|
416
|
+
*/
|
|
417
|
+
public async attachments(): Promise<CardAttachment[]> {
|
|
418
|
+
return super.attachments(this.templateCardsPath);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Returns path to card's attachment folder.
|
|
423
|
+
* @param cardKey card key
|
|
424
|
+
* @returns path to card's attachment folder.
|
|
425
|
+
*/
|
|
426
|
+
public async cardAttachmentFolder(cardKey: string): Promise<string> {
|
|
427
|
+
const pathToCard = await this.cardFolder(cardKey);
|
|
428
|
+
if (!pathToCard) {
|
|
429
|
+
return '';
|
|
430
|
+
}
|
|
431
|
+
return join(pathToCard, 'a');
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Returns details (as defined by cardDetails) of a card.
|
|
436
|
+
* @param cardKey card key (project prefix and a number, e.g. test_1)
|
|
437
|
+
* @param cardDetails which card details are returned.
|
|
438
|
+
* @returns Card details, or undefined if the card cannot be found.
|
|
439
|
+
*/
|
|
440
|
+
public async cardDetailsById(
|
|
441
|
+
cardKey: string,
|
|
442
|
+
cardDetails: FetchCardDetails,
|
|
443
|
+
): Promise<Card | undefined> {
|
|
444
|
+
return super.findCard(this.templateCardsPath, cardKey, cardDetails);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* returns path to card's folder.
|
|
449
|
+
* @param cardKey card key
|
|
450
|
+
* @returns path to card's folder.
|
|
451
|
+
*/
|
|
452
|
+
public async cardFolder(cardKey: string): Promise<string> {
|
|
453
|
+
const found = await super.findCard(this.templateCardsPath, cardKey);
|
|
454
|
+
return found ? found.path : '';
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Returns all cards in the template. Cards have content and metadata.
|
|
459
|
+
* @param placeHolderPath This is not used. Needed to be compatible with base class.
|
|
460
|
+
* @param details Optional. Which details are returned for each card. If missing, default value will be used.
|
|
461
|
+
* @returns Template cards in the template.
|
|
462
|
+
*/
|
|
463
|
+
public async cards(
|
|
464
|
+
placeHolderPath?: string,
|
|
465
|
+
details?: FetchCardDetails,
|
|
466
|
+
): Promise<Card[]> {
|
|
467
|
+
if (placeHolderPath) {
|
|
468
|
+
logger.warn('A non-used variable was used in the cards method');
|
|
469
|
+
}
|
|
470
|
+
const cardDetails = details
|
|
471
|
+
? details
|
|
472
|
+
: {
|
|
473
|
+
content: true,
|
|
474
|
+
contentType: 'adoc' as FileContentType,
|
|
475
|
+
metadata: true,
|
|
476
|
+
};
|
|
477
|
+
return super.cards(this.templateCardsPath, cardDetails);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Creates cards from a template. If parent card is specified, then cards are created to underneath a parent.
|
|
482
|
+
* @param parentCard parent card
|
|
483
|
+
* @returns array of created card keys
|
|
484
|
+
*/
|
|
485
|
+
public async createCards(parentCard?: Card): Promise<Card[]> {
|
|
486
|
+
const cards = await this.cards('', {
|
|
487
|
+
content: true,
|
|
488
|
+
contentType: 'adoc',
|
|
489
|
+
metadata: true,
|
|
490
|
+
attachments: true,
|
|
491
|
+
parent: true,
|
|
492
|
+
});
|
|
493
|
+
if (cards.length === 0) {
|
|
494
|
+
throw new Error(
|
|
495
|
+
`No cards in template '${this.containerName}'. Please add template cards with 'add' command first.`,
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
return this.doCreateCards(cards, parentCard);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Returns specific card.
|
|
503
|
+
* @param cardKey Card key to find from template.
|
|
504
|
+
* @param details Card details to include in return value.
|
|
505
|
+
* @returns specific card details
|
|
506
|
+
*/
|
|
507
|
+
public async findSpecificCard(
|
|
508
|
+
cardKey: string,
|
|
509
|
+
details: FetchCardDetails = {},
|
|
510
|
+
): Promise<Card | undefined> {
|
|
511
|
+
const cardPrefix = cardKey.split('_').at(0);
|
|
512
|
+
const moduleCardFromProject =
|
|
513
|
+
this.basePath.includes('local') &&
|
|
514
|
+
this.project.projectPrefix !== cardPrefix;
|
|
515
|
+
const projectCardFromModule =
|
|
516
|
+
this.basePath.includes('modules') &&
|
|
517
|
+
this.project.projectPrefix === cardPrefix;
|
|
518
|
+
// If the result is impossible, return undefined.
|
|
519
|
+
if (moduleCardFromProject || projectCardFromModule) {
|
|
520
|
+
return undefined;
|
|
521
|
+
}
|
|
522
|
+
return super.findCard(this.templateCardsPath, cardKey, details);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Checks if a specific card key exists in a template.
|
|
527
|
+
* @param cardKey Card key to find from template.
|
|
528
|
+
* @return true if card with a given card key exists in the template, false otherwise.
|
|
529
|
+
*/
|
|
530
|
+
public hasCard(cardKey: string): boolean {
|
|
531
|
+
return super.hasCard(cardKey, this.templateCardsPath);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Check if template name exists already in the project.
|
|
536
|
+
* @returns true, if template is exists in project; false otherwise
|
|
537
|
+
*/
|
|
538
|
+
public isCreated(): boolean {
|
|
539
|
+
return pathExists(this.templateCardsPath);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Returns an array of all the cards in the project. Cards don't have content nor metadata.
|
|
544
|
+
* @returns all cards in the project.
|
|
545
|
+
*/
|
|
546
|
+
public async listCards(): Promise<Card[]> {
|
|
547
|
+
return super.cards(this.templateCardsPath);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Returns path to 'templates/<name>/c' folder.
|
|
552
|
+
* @returns path to the template's folder for cards.
|
|
553
|
+
*/
|
|
554
|
+
public templateCardsFolder(): string {
|
|
555
|
+
return this.templateCardsPath;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Path to template configuration json file.
|
|
560
|
+
* @returns path to the template's configuration file.
|
|
561
|
+
*/
|
|
562
|
+
public templateConfigurationFilePath(): string {
|
|
563
|
+
return join(this.templatePath, '..', this.containerName + '.json');
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Returns path to 'templates' folder.
|
|
568
|
+
* @returns path to the project's folder that contains templates.
|
|
569
|
+
*/
|
|
570
|
+
public templateFolder(): string {
|
|
571
|
+
return this.templatePath;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { ValidationError } from 'json-schema';
|
|
14
|
+
|
|
15
|
+
export class DHValidationError extends Error {
|
|
16
|
+
public errors?: ValidationError[];
|
|
17
|
+
constructor(message: string, errors?: ValidationError[]) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'DHValidationError';
|
|
20
|
+
this.errors = errors;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class SchemaNotFound extends Error {
|
|
25
|
+
constructor(message: string) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = 'SchemaNotFound';
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
CardsOptions,
|
|
15
|
+
Cmd,
|
|
16
|
+
Commands,
|
|
17
|
+
CommandManager,
|
|
18
|
+
ExportFormats,
|
|
19
|
+
} from './command-handler.js';
|
|
20
|
+
import { requestStatus } from './interfaces/request-status-interfaces.js';
|
|
21
|
+
import { UpdateOperations } from './resources/resource-object.js';
|
|
22
|
+
import { evaluateMacros } from './macros/index.js';
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
CardsOptions,
|
|
26
|
+
Cmd,
|
|
27
|
+
CommandManager,
|
|
28
|
+
Commands,
|
|
29
|
+
ExportFormats,
|
|
30
|
+
requestStatus,
|
|
31
|
+
UpdateOperations,
|
|
32
|
+
evaluateMacros,
|
|
33
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export type AdmonitionType =
|
|
14
|
+
| 'NOTE'
|
|
15
|
+
| 'TIP'
|
|
16
|
+
| 'IMPORTANT'
|
|
17
|
+
| 'CAUTION'
|
|
18
|
+
| 'WARNING';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { macroMetadata } from '../macros/common.js';
|
|
14
|
+
|
|
15
|
+
type Mode = 'validate' | 'static' | 'inject';
|
|
16
|
+
|
|
17
|
+
export interface MacroGenerationContext {
|
|
18
|
+
projectPath: string;
|
|
19
|
+
mode: Mode;
|
|
20
|
+
cardKey: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MacroMetadata {
|
|
24
|
+
/**
|
|
25
|
+
* The name of the macro. This is the name that will be used in the content
|
|
26
|
+
*/
|
|
27
|
+
name: string;
|
|
28
|
+
/**
|
|
29
|
+
* The tag name of the macro. This is the name that will be used in the HTML. This is separated for clarity since tags cannot have uppercase letters
|
|
30
|
+
*/
|
|
31
|
+
tagName: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The schema of the macro. This is used to validate the data passed to the macro
|
|
35
|
+
*/
|
|
36
|
+
schema?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface MacroTaskState {
|
|
40
|
+
globalId: string;
|
|
41
|
+
localId: number;
|
|
42
|
+
promise: Promise<void>;
|
|
43
|
+
placeholder: string;
|
|
44
|
+
promiseResult: string | null;
|
|
45
|
+
macro: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Handlebars options is not documented
|
|
49
|
+
// It contains various context specific parameters
|
|
50
|
+
export interface HandlebarsOptions {
|
|
51
|
+
fn: (arg0: unknown) => string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type MacroName = keyof typeof macroMetadata;
|