@cyberismo/data-handler 0.0.11 → 0.0.13
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 -1
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +26 -39
- package/dist/command-handler.js +76 -31
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +2 -1
- package/dist/command-manager.js +4 -2
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/calculate.d.ts +7 -0
- package/dist/commands/calculate.js +9 -0
- package/dist/commands/calculate.js.map +1 -1
- package/dist/commands/create.d.ts +5 -0
- package/dist/commands/create.js +15 -8
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/fetch.d.ts +24 -0
- package/dist/commands/fetch.js +118 -0
- package/dist/commands/fetch.js.map +1 -0
- package/dist/commands/import.js +2 -2
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/index.d.ts +2 -1
- package/dist/commands/index.js +2 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/remove.d.ts +1 -0
- package/dist/commands/remove.js +16 -12
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.js +4 -6
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +22 -1
- package/dist/commands/show.js +56 -0
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/update.d.ts +11 -1
- package/dist/commands/update.js +14 -2
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +2 -1
- package/dist/commands/validate.js +10 -10
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/card-container.js +1 -1
- package/dist/containers/card-container.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +8 -0
- package/dist/containers/project/calculation-engine.js +21 -10
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project.d.ts +19 -8
- package/dist/containers/project.js +52 -34
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.js +1 -1
- package/dist/containers/template.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces/command-options.d.ts +81 -0
- package/dist/interfaces/command-options.js +14 -0
- package/dist/interfaces/command-options.js.map +1 -0
- package/dist/interfaces/folder-content-interfaces.d.ts +50 -0
- package/dist/interfaces/folder-content-interfaces.js +45 -0
- package/dist/interfaces/folder-content-interfaces.js.map +1 -0
- package/dist/interfaces/project-interfaces.d.ts +13 -2
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +28 -10
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/base-macro.d.ts +1 -1
- package/dist/macros/base-macro.js +1 -1
- package/dist/macros/base-macro.js.map +1 -1
- package/dist/macros/createCards/index.d.ts +1 -1
- package/dist/macros/createCards/index.js +1 -1
- package/dist/macros/createCards/index.js.map +1 -1
- package/dist/macros/graph/index.d.ts +1 -1
- package/dist/macros/graph/index.js +21 -29
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/image/index.d.ts +1 -1
- package/dist/macros/image/index.js +1 -7
- package/dist/macros/image/index.js.map +1 -1
- package/dist/macros/include/index.d.ts +1 -1
- package/dist/macros/include/index.js +1 -1
- package/dist/macros/include/index.js.map +1 -1
- package/dist/macros/index.d.ts +12 -5
- package/dist/macros/index.js +19 -7
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/percentage/index.d.ts +1 -1
- package/dist/macros/percentage/index.js +1 -1
- package/dist/macros/percentage/index.js.map +1 -1
- package/dist/macros/report/index.d.ts +1 -1
- package/dist/macros/report/index.js +5 -5
- package/dist/macros/report/index.js.map +1 -1
- package/dist/macros/scoreCard/index.d.ts +1 -1
- package/dist/macros/scoreCard/index.js +1 -1
- package/dist/macros/scoreCard/index.js.map +1 -1
- package/dist/macros/vega/index.d.ts +1 -1
- package/dist/macros/vega/index.js +1 -1
- package/dist/macros/vega/index.js.map +1 -1
- package/dist/macros/vegalite/index.d.ts +1 -1
- package/dist/macros/vegalite/index.js +1 -1
- package/dist/macros/vegalite/index.js.map +1 -1
- package/dist/macros/xref/index.d.ts +1 -1
- package/dist/macros/xref/index.js +1 -1
- package/dist/macros/xref/index.js.map +1 -1
- package/dist/project-settings.d.ts +14 -1
- package/dist/project-settings.js +51 -1
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/card-type-resource.js +11 -5
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +5 -0
- package/dist/resources/field-type-resource.js +9 -4
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +37 -9
- package/dist/resources/folder-resource.js +108 -12
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +7 -4
- package/dist/resources/graph-model-resource.js +12 -25
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +7 -4
- package/dist/resources/graph-view-resource.js +15 -31
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.js +1 -1
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +14 -10
- package/dist/resources/report-resource.js +41 -45
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +7 -0
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +5 -1
- package/dist/resources/template-resource.js +12 -7
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.js +12 -5
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/log-utils.js +1 -1
- package/dist/utils/log-utils.js.map +1 -1
- package/dist/utils/report.js +6 -0
- package/dist/utils/report.js.map +1 -1
- package/dist/utils/resource-utils.d.ts +8 -0
- package/dist/utils/resource-utils.js +11 -0
- package/dist/utils/resource-utils.js.map +1 -1
- package/package.json +11 -11
- package/src/card-metadata-updater.ts +1 -1
- package/src/command-handler.ts +129 -61
- package/src/command-manager.ts +4 -1
- package/src/commands/calculate.ts +18 -0
- package/src/commands/create.ts +31 -19
- package/src/commands/fetch.ts +152 -0
- package/src/commands/import.ts +2 -0
- package/src/commands/index.ts +2 -0
- package/src/commands/remove.ts +18 -12
- package/src/commands/rename.ts +11 -11
- package/src/commands/show.ts +72 -0
- package/src/commands/update.ts +20 -2
- package/src/commands/validate.ts +13 -10
- package/src/containers/card-container.ts +1 -1
- package/src/containers/project/calculation-engine.ts +27 -11
- package/src/containers/project.ts +71 -61
- package/src/containers/template.ts +1 -1
- package/src/index.ts +36 -2
- package/src/interfaces/command-options.ts +144 -0
- package/src/interfaces/folder-content-interfaces.ts +69 -0
- package/src/interfaces/project-interfaces.ts +18 -0
- package/src/interfaces/resource-interfaces.ts +41 -12
- package/src/macros/base-macro.ts +5 -2
- package/src/macros/createCards/index.ts +1 -1
- package/src/macros/graph/index.ts +47 -51
- package/src/macros/image/index.ts +1 -7
- package/src/macros/include/index.ts +1 -1
- package/src/macros/index.ts +19 -7
- package/src/macros/percentage/index.ts +1 -1
- package/src/macros/report/index.ts +5 -5
- package/src/macros/scoreCard/index.ts +1 -1
- package/src/macros/vega/index.ts +1 -1
- package/src/macros/vegalite/index.ts +1 -1
- package/src/macros/xref/index.ts +1 -1
- package/src/project-settings.ts +62 -1
- package/src/resources/card-type-resource.ts +12 -6
- package/src/resources/field-type-resource.ts +9 -4
- package/src/resources/folder-resource.ts +149 -19
- package/src/resources/graph-model-resource.ts +16 -27
- package/src/resources/graph-view-resource.ts +23 -33
- package/src/resources/link-type-resource.ts +1 -1
- package/src/resources/report-resource.ts +60 -62
- package/src/resources/resource-object.ts +11 -0
- package/src/resources/template-resource.ts +12 -7
- package/src/resources/workflow-resource.ts +11 -6
- package/src/utils/log-utils.ts +1 -1
- package/src/utils/report.ts +6 -0
- package/src/utils/resource-utils.ts +16 -0
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
// node
|
|
15
15
|
import { basename, join, resolve } from 'node:path';
|
|
16
|
-
import { readFile } from 'node:fs/promises';
|
|
16
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
17
17
|
|
|
18
18
|
import { sanitizeSvgBase64 } from '../../utils/sanitize-svg.js';
|
|
19
19
|
import { instance } from '@viz-js/viz';
|
|
@@ -57,6 +57,7 @@ import {
|
|
|
57
57
|
solve,
|
|
58
58
|
setProgram,
|
|
59
59
|
removeProgram,
|
|
60
|
+
buildProgram,
|
|
60
61
|
} from '@cyberismo/node-clingo';
|
|
61
62
|
import { generateReportContent } from '../../utils/report.js';
|
|
62
63
|
import { lpFiles, graphvizReport } from '@cyberismo/assets';
|
|
@@ -110,6 +111,22 @@ export class CalculationEngine {
|
|
|
110
111
|
return createCardFacts(card, this.project);
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Exports logic program to a given file
|
|
116
|
+
* @param destination Destination file path
|
|
117
|
+
* @param programs Programs or categories to export
|
|
118
|
+
* @param query Query to export, if not provided, all programs will be exported
|
|
119
|
+
*/
|
|
120
|
+
public async exportLogicProgram(
|
|
121
|
+
destination: string,
|
|
122
|
+
programs: string[],
|
|
123
|
+
query?: QueryName,
|
|
124
|
+
) {
|
|
125
|
+
let logicProgram = query ? this.queryContent(query) : '';
|
|
126
|
+
logicProgram += await buildProgram('', programs);
|
|
127
|
+
await writeFile(destination, logicProgram);
|
|
128
|
+
}
|
|
129
|
+
|
|
113
130
|
// // Wrapper to run onCreation query.
|
|
114
131
|
private async creationQuery(cardKeys: string[], context: Context) {
|
|
115
132
|
if (!cardKeys) return undefined;
|
|
@@ -449,9 +466,7 @@ export class CalculationEngine {
|
|
|
449
466
|
case 'templates':
|
|
450
467
|
return createTemplateFacts(resource as TemplateMetadata);
|
|
451
468
|
default:
|
|
452
|
-
|
|
453
|
-
`Resource ${resourceNameToString(resourceName)} does not have a logic program`,
|
|
454
|
-
);
|
|
469
|
+
return '';
|
|
455
470
|
}
|
|
456
471
|
}
|
|
457
472
|
|
|
@@ -503,6 +518,13 @@ export class CalculationEngine {
|
|
|
503
518
|
return this.parseClingoResult(clingoOutput);
|
|
504
519
|
}
|
|
505
520
|
|
|
521
|
+
private queryContent(queryName: QueryName, options?: unknown) {
|
|
522
|
+
const content = lpFiles.queries[queryName];
|
|
523
|
+
const handlebars = Handlebars.create();
|
|
524
|
+
const compiled = handlebars.compile(content);
|
|
525
|
+
return compiled(options || {});
|
|
526
|
+
}
|
|
527
|
+
|
|
506
528
|
/**
|
|
507
529
|
* Runs a pre-defined query.
|
|
508
530
|
* @param queryName Name of the query file without extension
|
|
@@ -514,13 +536,7 @@ export class CalculationEngine {
|
|
|
514
536
|
context: Context = 'localApp',
|
|
515
537
|
options?: unknown,
|
|
516
538
|
): Promise<QueryResult<T>[]> {
|
|
517
|
-
|
|
518
|
-
const handlebars = Handlebars.create();
|
|
519
|
-
const compiled = handlebars.compile(content);
|
|
520
|
-
content = compiled(options || {});
|
|
521
|
-
if (!content) {
|
|
522
|
-
throw new Error(`Query file ${queryName} not found`);
|
|
523
|
-
}
|
|
539
|
+
const content = this.queryContent(queryName, options);
|
|
524
540
|
|
|
525
541
|
this.logger.trace({ queryName }, 'Running query');
|
|
526
542
|
const clingoOutput = await this.run(content, context);
|
|
@@ -110,23 +110,25 @@ export class Project extends CardContainer {
|
|
|
110
110
|
this.resourceWatcher = new ContentWatcher(
|
|
111
111
|
ignoreRenameFileChanges,
|
|
112
112
|
this.paths.resourcesFolder,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
(fileName: string) => {
|
|
114
|
+
void (async () => {
|
|
115
|
+
let resource;
|
|
116
|
+
try {
|
|
117
|
+
resource = pathToResourceName(
|
|
118
|
+
this,
|
|
119
|
+
join(this.paths.resourcesFolder, fileName),
|
|
120
|
+
);
|
|
121
|
+
if (!resource) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
} catch {
|
|
125
|
+
// it wasn't a resource that changed, so ignore the change
|
|
121
126
|
return;
|
|
122
127
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
const resourceName = `${resource.prefix}/${resource.type}/${resource.identifier}`;
|
|
128
|
-
await this.replaceCacheValue(resourceName);
|
|
129
|
-
this.resources.collectLocalResources();
|
|
128
|
+
const resourceName = `${resource.prefix}/${resource.type}/${resource.identifier}`;
|
|
129
|
+
await this.replaceCacheValue(resourceName);
|
|
130
|
+
this.resources.collectLocalResources();
|
|
131
|
+
})();
|
|
130
132
|
},
|
|
131
133
|
);
|
|
132
134
|
}
|
|
@@ -164,6 +166,7 @@ export class Project extends CardContainer {
|
|
|
164
166
|
/**
|
|
165
167
|
* Add a given 'resource' to the local resource arrays.
|
|
166
168
|
* @param resource Resource to add.
|
|
169
|
+
* @param data JSON data for the resource.
|
|
167
170
|
*/
|
|
168
171
|
public addResource(resource: Resource, data: JSON) {
|
|
169
172
|
this.resources.add(resource);
|
|
@@ -193,6 +196,7 @@ export class Project extends CardContainer {
|
|
|
193
196
|
* Returns path to card's attachment folder.
|
|
194
197
|
* @param cardKey card key
|
|
195
198
|
* @returns path to card's attachment folder.
|
|
199
|
+
* @throws if card path cannot be found
|
|
196
200
|
*/
|
|
197
201
|
public async cardAttachmentFolder(cardKey: string): Promise<string> {
|
|
198
202
|
// Check if it is a template card.
|
|
@@ -202,9 +206,10 @@ export class Project extends CardContainer {
|
|
|
202
206
|
}
|
|
203
207
|
|
|
204
208
|
const pathToProjectCard = this.pathToCard(cardKey);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
if (!pathToProjectCard) {
|
|
210
|
+
throw new Error(`Card '${cardKey}' not found`);
|
|
211
|
+
}
|
|
212
|
+
return join(this.paths.cardRootFolder, pathToProjectCard, 'a');
|
|
208
213
|
}
|
|
209
214
|
|
|
210
215
|
/**
|
|
@@ -252,6 +257,7 @@ export class Project extends CardContainer {
|
|
|
252
257
|
* Returned parts are: prefix, card key, array of parents and template name. Template name is returned only for template cards.
|
|
253
258
|
* @param cardPath path to a card
|
|
254
259
|
* @returns card path logical parts
|
|
260
|
+
* @throws when called with wrong path, or wrong card owner
|
|
255
261
|
* todo: if prefix would be parameter; this could be static, or util method
|
|
256
262
|
*/
|
|
257
263
|
public cardPathParts(cardPath: string) {
|
|
@@ -458,7 +464,7 @@ export class Project extends CardContainer {
|
|
|
458
464
|
|
|
459
465
|
/**
|
|
460
466
|
* Returns an array of all the graph models in the project.
|
|
461
|
-
* @param from
|
|
467
|
+
* @param from Defines where resources are collected from.
|
|
462
468
|
* @returns array of all the graph models in the project.
|
|
463
469
|
*/
|
|
464
470
|
public async graphModels(
|
|
@@ -469,7 +475,7 @@ export class Project extends CardContainer {
|
|
|
469
475
|
|
|
470
476
|
/**
|
|
471
477
|
* Returns an array of all the graph views in the project.
|
|
472
|
-
* @param from
|
|
478
|
+
* @param from Defines where resources are collected from.
|
|
473
479
|
* @returns array of all the graph views in the project.
|
|
474
480
|
*/
|
|
475
481
|
public async graphViews(
|
|
@@ -513,7 +519,7 @@ export class Project extends CardContainer {
|
|
|
513
519
|
|
|
514
520
|
/**
|
|
515
521
|
* Adds a module from project.
|
|
516
|
-
* @param
|
|
522
|
+
* @param module Name of the module
|
|
517
523
|
*/
|
|
518
524
|
public async importModule(module: ModuleSetting) {
|
|
519
525
|
// Add module as a dependency.
|
|
@@ -534,6 +540,7 @@ export class Project extends CardContainer {
|
|
|
534
540
|
* Returns whether card is a template card or not
|
|
535
541
|
* @param cardKey card to check.
|
|
536
542
|
* @todo: This is only used from 'remove'. Could it use the static checker?
|
|
543
|
+
* @returns true, if card is template card; false otherwise
|
|
537
544
|
*/
|
|
538
545
|
public async isTemplateCard(cardKey: string): Promise<boolean> {
|
|
539
546
|
const templateCards = await this.allTemplateCards();
|
|
@@ -554,7 +561,7 @@ export class Project extends CardContainer {
|
|
|
554
561
|
/**
|
|
555
562
|
* Returns an array of cards in the project, in the templates or both.
|
|
556
563
|
* Cards don't have content and nor metadata.
|
|
557
|
-
* @param
|
|
564
|
+
* @param cardsFrom Where to return cards from (project, templates, or both)
|
|
558
565
|
* @returns all cards in the project.
|
|
559
566
|
*/
|
|
560
567
|
public async listCards(
|
|
@@ -603,7 +610,7 @@ export class Project extends CardContainer {
|
|
|
603
610
|
|
|
604
611
|
/**
|
|
605
612
|
* Return cardIDs of the cards in the project or from templates, or both.
|
|
606
|
-
* @param
|
|
613
|
+
* @param cardsFrom Where to return cards from (project, templates, or both)
|
|
607
614
|
* @returns Array of cardIDs.
|
|
608
615
|
* @note that cardIDs are not sorted.
|
|
609
616
|
*/
|
|
@@ -626,41 +633,35 @@ export class Project extends CardContainer {
|
|
|
626
633
|
cardsFrom === CardLocation.templatesOnly
|
|
627
634
|
) {
|
|
628
635
|
promises.push(
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
.
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
): result is PromiseFulfilledResult<TemplateResource> =>
|
|
642
|
-
result.status === 'fulfilled' && result.value !== null,
|
|
643
|
-
)
|
|
644
|
-
.map((result) => result.value),
|
|
636
|
+
(async () => {
|
|
637
|
+
const templates = await this.templates();
|
|
638
|
+
const templateResources = templates.map(
|
|
639
|
+
(template) =>
|
|
640
|
+
new TemplateResource(this, resourceName(template.name)),
|
|
641
|
+
);
|
|
642
|
+
const templateObjectsResults =
|
|
643
|
+
await Promise.allSettled(templateResources);
|
|
644
|
+
const templateObjects = templateObjectsResults
|
|
645
|
+
.filter(
|
|
646
|
+
(result): result is PromiseFulfilledResult<TemplateResource> =>
|
|
647
|
+
result.status === 'fulfilled' && result.value !== null,
|
|
645
648
|
)
|
|
646
|
-
.
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
649
|
+
.map((result) => result.value);
|
|
650
|
+
|
|
651
|
+
const listCardsResults = await Promise.allSettled(
|
|
652
|
+
templateObjects.map((obj) => obj.templateObject().listCards()),
|
|
653
|
+
);
|
|
654
|
+
const templateCardIds = new Set<string>();
|
|
655
|
+
listCardsResults
|
|
656
|
+
.filter(
|
|
657
|
+
(result): result is PromiseFulfilledResult<Card[]> =>
|
|
658
|
+
result.status === 'fulfilled',
|
|
650
659
|
)
|
|
651
|
-
.
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
result.status === 'fulfilled',
|
|
657
|
-
)
|
|
658
|
-
.forEach((result) => {
|
|
659
|
-
result.value.forEach((card) => templateCardIds.add(card.key));
|
|
660
|
-
});
|
|
661
|
-
return templateCardIds;
|
|
662
|
-
}),
|
|
663
|
-
),
|
|
660
|
+
.forEach((result) => {
|
|
661
|
+
result.value.forEach((card) => templateCardIds.add(card.key));
|
|
662
|
+
});
|
|
663
|
+
return templateCardIds;
|
|
664
|
+
})(),
|
|
664
665
|
);
|
|
665
666
|
}
|
|
666
667
|
const allCardIdSets = await Promise.all(promises);
|
|
@@ -682,6 +683,7 @@ export class Project extends CardContainer {
|
|
|
682
683
|
return {
|
|
683
684
|
name: moduleConfig.name,
|
|
684
685
|
modules: moduleConfig.modules,
|
|
686
|
+
hubs: moduleConfig.hubs,
|
|
685
687
|
path: modulePath,
|
|
686
688
|
cardKeyPrefix: moduleConfig.cardKeyPrefix,
|
|
687
689
|
calculations: [
|
|
@@ -754,6 +756,7 @@ export class Project extends CardContainer {
|
|
|
754
756
|
/**
|
|
755
757
|
* Returns a new unique card key with project prefix (e.g. test_x649it4x).
|
|
756
758
|
* Random part of string will be always 8 characters in base-36 (0-9a-z)
|
|
759
|
+
* @param cardIds map of card ids in use already
|
|
757
760
|
* @returns a new card key string
|
|
758
761
|
* @throws if a unique key could not be created within set number of attempts
|
|
759
762
|
*/
|
|
@@ -772,12 +775,14 @@ export class Project extends CardContainer {
|
|
|
772
775
|
return newKey;
|
|
773
776
|
}
|
|
774
777
|
|
|
775
|
-
throw 'Could not generate unique card key';
|
|
778
|
+
throw new Error('Could not generate unique card key');
|
|
776
779
|
}
|
|
777
780
|
|
|
778
781
|
/**
|
|
779
782
|
* Returns an array of new unique card keys with project prefix (e.g. test_x649it4x).
|
|
780
783
|
* Random part of string will be always 8 characters in base-36 (0-9a-z)
|
|
784
|
+
* @param keysToCreate How many new cards are to be created.
|
|
785
|
+
* @param cardIds map of card ids in use already
|
|
781
786
|
* @returns an array of new card key strings
|
|
782
787
|
* @throws if a unique key could not be created within set number of attempts
|
|
783
788
|
*/
|
|
@@ -809,7 +814,7 @@ export class Project extends CardContainer {
|
|
|
809
814
|
}
|
|
810
815
|
|
|
811
816
|
/**
|
|
812
|
-
*
|
|
817
|
+
* Returns a class that handles the project's paths.
|
|
813
818
|
*/
|
|
814
819
|
public get paths(): ProjectPaths {
|
|
815
820
|
return this.projectPaths;
|
|
@@ -828,14 +833,14 @@ export class Project extends CardContainer {
|
|
|
828
833
|
}
|
|
829
834
|
|
|
830
835
|
/**
|
|
831
|
-
*
|
|
836
|
+
* Returns project name.
|
|
832
837
|
*/
|
|
833
838
|
public get projectName(): string {
|
|
834
839
|
return this.settings.name;
|
|
835
840
|
}
|
|
836
841
|
|
|
837
842
|
/**
|
|
838
|
-
*
|
|
843
|
+
* Returns project prefix.
|
|
839
844
|
*/
|
|
840
845
|
public get projectPrefix(): string {
|
|
841
846
|
return this.settings.cardKeyPrefix;
|
|
@@ -869,7 +874,7 @@ export class Project extends CardContainer {
|
|
|
869
874
|
const configurationPrefixes = await Promise.all(configurationPromises);
|
|
870
875
|
prefixes.push(...configurationPrefixes);
|
|
871
876
|
} catch {
|
|
872
|
-
// do nothing if readdir throws
|
|
877
|
+
// do nothing if readdir throws // TODO: Log it
|
|
873
878
|
}
|
|
874
879
|
|
|
875
880
|
return prefixes;
|
|
@@ -937,6 +942,9 @@ export class Project extends CardContainer {
|
|
|
937
942
|
return data;
|
|
938
943
|
}
|
|
939
944
|
|
|
945
|
+
/**
|
|
946
|
+
* Returns resource cache.
|
|
947
|
+
*/
|
|
940
948
|
public get resourceCache(): Map<string, JSON> {
|
|
941
949
|
return this.createdResources;
|
|
942
950
|
}
|
|
@@ -1000,6 +1008,7 @@ export class Project extends CardContainer {
|
|
|
1000
1008
|
name: this.containerName,
|
|
1001
1009
|
path: this.basePath,
|
|
1002
1010
|
prefix: this.projectPrefix,
|
|
1011
|
+
hubs: this.configuration.hubs,
|
|
1003
1012
|
modules: (await this.modules()).map((item) => item.name),
|
|
1004
1013
|
numberOfCards: (await this.listCards(CardLocation.projectOnly))[0].cards
|
|
1005
1014
|
.length,
|
|
@@ -1131,6 +1140,7 @@ export class Project extends CardContainer {
|
|
|
1131
1140
|
/**
|
|
1132
1141
|
* Validates that card's data is valid.
|
|
1133
1142
|
* @param card Card to validate.
|
|
1143
|
+
* @returns validation errors, if any
|
|
1134
1144
|
*/
|
|
1135
1145
|
public async validateCard(card: Card): Promise<string> {
|
|
1136
1146
|
const invalidCustomData = await this.validator.validateCustomFields(
|
|
@@ -439,7 +439,7 @@ export class Template extends CardContainer {
|
|
|
439
439
|
public async cardAttachmentFolder(cardKey: string): Promise<string> {
|
|
440
440
|
const pathToCard = await this.cardFolder(cardKey);
|
|
441
441
|
if (!pathToCard) {
|
|
442
|
-
|
|
442
|
+
throw new Error(`Template card '${cardKey}' not found`);
|
|
443
443
|
}
|
|
444
444
|
return join(pathToCard, 'a');
|
|
445
445
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
|
-
CardsOptions,
|
|
15
14
|
Cmd,
|
|
15
|
+
CmdKey,
|
|
16
|
+
CmdValue,
|
|
16
17
|
Commands,
|
|
17
18
|
CommandManager,
|
|
18
19
|
ExportFormats,
|
|
@@ -21,6 +22,14 @@ import { Validate } from './commands/validate.js';
|
|
|
21
22
|
export * from './interfaces/project-interfaces.js';
|
|
22
23
|
import { requestStatus } from './interfaces/request-status-interfaces.js';
|
|
23
24
|
import { UpdateOperations } from './resources/resource-object.js';
|
|
25
|
+
export type {
|
|
26
|
+
Operation,
|
|
27
|
+
OperationFor,
|
|
28
|
+
AddOperation,
|
|
29
|
+
ChangeOperation,
|
|
30
|
+
RankOperation,
|
|
31
|
+
RemoveOperation,
|
|
32
|
+
} from './resources/resource-object.js';
|
|
24
33
|
import { evaluateMacros } from './macros/index.js';
|
|
25
34
|
import {
|
|
26
35
|
isResourceFolderType,
|
|
@@ -30,8 +39,9 @@ import {
|
|
|
30
39
|
import { moduleNameFromCardKey } from './utils/card-utils.js';
|
|
31
40
|
|
|
32
41
|
export {
|
|
33
|
-
CardsOptions,
|
|
34
42
|
Cmd,
|
|
43
|
+
CmdKey,
|
|
44
|
+
CmdValue,
|
|
35
45
|
CommandManager,
|
|
36
46
|
Commands,
|
|
37
47
|
ExportFormats,
|
|
@@ -44,3 +54,27 @@ export {
|
|
|
44
54
|
Validate,
|
|
45
55
|
evaluateMacros,
|
|
46
56
|
};
|
|
57
|
+
|
|
58
|
+
// Export command-specific option interfaces
|
|
59
|
+
export type {
|
|
60
|
+
CommandOptions,
|
|
61
|
+
AllCommandOptions,
|
|
62
|
+
AddCommandOptions,
|
|
63
|
+
CalcCommandOptions,
|
|
64
|
+
CreateCommandOptions,
|
|
65
|
+
EditCommandOptions,
|
|
66
|
+
ExportCommandOptions,
|
|
67
|
+
FetchCommandOptions,
|
|
68
|
+
ImportCommandOptions,
|
|
69
|
+
MoveCommandOptions,
|
|
70
|
+
RankCommandOptions,
|
|
71
|
+
RemoveCommandOptions,
|
|
72
|
+
RenameCommandOptions,
|
|
73
|
+
ReportCommandOptions,
|
|
74
|
+
ShowCommandOptions,
|
|
75
|
+
StartCommandOptions,
|
|
76
|
+
TransitionCommandOptions,
|
|
77
|
+
UpdateCommandOptions,
|
|
78
|
+
UpdateModulesCommandOptions,
|
|
79
|
+
ValidateCommandOptions,
|
|
80
|
+
} from './interfaces/command-options.js';
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
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
|
+
import type { Level } from 'pino';
|
|
15
|
+
import type { Context } from './project-interfaces.js';
|
|
16
|
+
import type { CmdKey } from '../command-handler.js';
|
|
17
|
+
|
|
18
|
+
// Base options shared across multiple commands
|
|
19
|
+
export interface BaseCommandOptions {
|
|
20
|
+
projectPath?: string;
|
|
21
|
+
logLevel?: Level;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Options for commands that need context
|
|
25
|
+
export interface ContextualCommandOptions extends BaseCommandOptions {
|
|
26
|
+
context?: Context;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Options for 'add' command
|
|
30
|
+
export interface AddCommandOptions extends BaseCommandOptions {
|
|
31
|
+
repeat?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Options for 'calc' command
|
|
35
|
+
export type CalcCommandOptions = ContextualCommandOptions;
|
|
36
|
+
|
|
37
|
+
// Options for 'create' command
|
|
38
|
+
export interface CreateCommandOptions extends BaseCommandOptions {
|
|
39
|
+
skipModuleImport?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Options for 'edit' command
|
|
43
|
+
export type EditCommandOptions = BaseCommandOptions;
|
|
44
|
+
|
|
45
|
+
// Options for the 'export' command
|
|
46
|
+
export interface ExportCommandOptions extends BaseCommandOptions {
|
|
47
|
+
recursive?: boolean;
|
|
48
|
+
title?: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
version?: string;
|
|
51
|
+
date?: string;
|
|
52
|
+
revremark?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Options for 'fetch' command
|
|
56
|
+
export type FetchCommandOptions = BaseCommandOptions;
|
|
57
|
+
|
|
58
|
+
// Options for 'import' command
|
|
59
|
+
export type ImportCommandOptions = BaseCommandOptions;
|
|
60
|
+
|
|
61
|
+
// Options for 'move' command
|
|
62
|
+
export type MoveCommandOptions = BaseCommandOptions;
|
|
63
|
+
|
|
64
|
+
// Options for 'rank' command
|
|
65
|
+
export type RankCommandOptions = BaseCommandOptions;
|
|
66
|
+
|
|
67
|
+
// Options for 'remove' command
|
|
68
|
+
export type RemoveCommandOptions = BaseCommandOptions;
|
|
69
|
+
|
|
70
|
+
// Options for 'rename' command
|
|
71
|
+
export type RenameCommandOptions = BaseCommandOptions;
|
|
72
|
+
|
|
73
|
+
// Options for 'report' command
|
|
74
|
+
export type ReportCommandOptions = ContextualCommandOptions;
|
|
75
|
+
|
|
76
|
+
// Options for 'show' command
|
|
77
|
+
export interface ShowCommandOptions extends BaseCommandOptions {
|
|
78
|
+
details?: boolean;
|
|
79
|
+
showAll?: boolean;
|
|
80
|
+
showUse?: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Options for 'start' command
|
|
84
|
+
export interface StartCommandOptions extends BaseCommandOptions {
|
|
85
|
+
forceStart?: boolean;
|
|
86
|
+
watchResourceChanges?: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Options for 'transition' command
|
|
90
|
+
export type TransitionCommandOptions = BaseCommandOptions;
|
|
91
|
+
|
|
92
|
+
// Options for 'update' command
|
|
93
|
+
export interface UpdateCommandOptions extends BaseCommandOptions {
|
|
94
|
+
mappingFile?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Options for 'updateModules' command
|
|
98
|
+
export type UpdateModulesCommandOptions = BaseCommandOptions;
|
|
99
|
+
|
|
100
|
+
// Options for 'validate' command
|
|
101
|
+
export type ValidateCommandOptions = BaseCommandOptions;
|
|
102
|
+
|
|
103
|
+
// All possible command options
|
|
104
|
+
export type AllCommandOptions =
|
|
105
|
+
| AddCommandOptions
|
|
106
|
+
| CalcCommandOptions
|
|
107
|
+
| CreateCommandOptions
|
|
108
|
+
| EditCommandOptions
|
|
109
|
+
| ExportCommandOptions
|
|
110
|
+
| FetchCommandOptions
|
|
111
|
+
| ImportCommandOptions
|
|
112
|
+
| MoveCommandOptions
|
|
113
|
+
| RankCommandOptions
|
|
114
|
+
| RemoveCommandOptions
|
|
115
|
+
| RenameCommandOptions
|
|
116
|
+
| ReportCommandOptions
|
|
117
|
+
| ShowCommandOptions
|
|
118
|
+
| StartCommandOptions
|
|
119
|
+
| TransitionCommandOptions
|
|
120
|
+
| UpdateCommandOptions
|
|
121
|
+
| UpdateModulesCommandOptions
|
|
122
|
+
| ValidateCommandOptions;
|
|
123
|
+
|
|
124
|
+
// Map command keys to their option types
|
|
125
|
+
export type CommandOptions<T extends CmdKey> = {
|
|
126
|
+
add: AddCommandOptions;
|
|
127
|
+
calc: CalcCommandOptions;
|
|
128
|
+
create: CreateCommandOptions;
|
|
129
|
+
edit: EditCommandOptions;
|
|
130
|
+
export: ExportCommandOptions;
|
|
131
|
+
fetch: FetchCommandOptions;
|
|
132
|
+
import: ImportCommandOptions;
|
|
133
|
+
move: MoveCommandOptions;
|
|
134
|
+
rank: RankCommandOptions;
|
|
135
|
+
remove: RemoveCommandOptions;
|
|
136
|
+
rename: RenameCommandOptions;
|
|
137
|
+
report: ReportCommandOptions;
|
|
138
|
+
show: ShowCommandOptions;
|
|
139
|
+
start: StartCommandOptions;
|
|
140
|
+
transition: TransitionCommandOptions;
|
|
141
|
+
update: UpdateCommandOptions;
|
|
142
|
+
updateModules: UpdateModulesCommandOptions;
|
|
143
|
+
validate: ValidateCommandOptions;
|
|
144
|
+
}[T];
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
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
|
+
import type { Schema } from 'jsonschema';
|
|
15
|
+
|
|
16
|
+
// All file mappings for lookup (filename -> property name)
|
|
17
|
+
export const ALL_FILE_MAPPINGS = {
|
|
18
|
+
'index.adoc.hbs': 'contentTemplate',
|
|
19
|
+
'query.lp.hbs': 'queryTemplate',
|
|
20
|
+
'parameterSchema.json': 'schema',
|
|
21
|
+
'model.lp': 'model',
|
|
22
|
+
'view.lp.hbs': 'viewTemplate',
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
// Reverse mappings from property names to filenames
|
|
26
|
+
export const REVERSE_FILE_MAPPINGS = {
|
|
27
|
+
contentTemplate: 'index.adoc.hbs',
|
|
28
|
+
queryTemplate: 'query.lp.hbs',
|
|
29
|
+
schema: 'parameterSchema.json',
|
|
30
|
+
model: 'model.lp',
|
|
31
|
+
viewTemplate: 'view.lp.hbs',
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
// Content interface for Graph Model resources
|
|
35
|
+
export interface GraphModelContent {
|
|
36
|
+
model?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Content interface for Graph View resources
|
|
40
|
+
export interface GraphViewContent {
|
|
41
|
+
viewTemplate?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Content interface for Report resources
|
|
45
|
+
export interface ReportContent {
|
|
46
|
+
contentTemplate: string;
|
|
47
|
+
queryTemplate: string;
|
|
48
|
+
schema?: Schema;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get filename with property name
|
|
53
|
+
* @param propertyName Property name.
|
|
54
|
+
* @returns filename that matches property name
|
|
55
|
+
*/
|
|
56
|
+
export function filename(propertyName: string): string | undefined {
|
|
57
|
+
return REVERSE_FILE_MAPPINGS[
|
|
58
|
+
propertyName as keyof typeof REVERSE_FILE_MAPPINGS
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get property name for a filename
|
|
64
|
+
* @param filename Filename.
|
|
65
|
+
* @returns property name that matches filename
|
|
66
|
+
*/
|
|
67
|
+
export function propertyName(filename: string): string | undefined {
|
|
68
|
+
return ALL_FILE_MAPPINGS[filename as keyof typeof ALL_FILE_MAPPINGS];
|
|
69
|
+
}
|