@cyberismo/data-handler 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/card-metadata-updater.js +7 -1
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +4 -0
- package/dist/command-handler.js +19 -3
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +24 -1
- package/dist/command-manager.js +27 -3
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +34 -36
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/export.d.ts +11 -2
- package/dist/commands/export.js +54 -41
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +9 -1
- package/dist/commands/import.js +15 -7
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.js +0 -1
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +8 -1
- package/dist/commands/remove.js +8 -4
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +4 -9
- package/dist/commands/rename.js +32 -101
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +16 -10
- package/dist/commands/show.js +71 -55
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.d.ts +9 -2
- package/dist/commands/transition.js +25 -17
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +16 -12
- package/dist/commands/update.js +19 -17
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +17 -9
- package/dist/commands/validate.js +96 -35
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +7 -4
- package/dist/containers/project/calculation-engine.js +61 -66
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project/project-paths.d.ts +5 -4
- package/dist/containers/project/project-paths.js +16 -12
- package/dist/containers/project/project-paths.js.map +1 -1
- package/dist/containers/project/resource-cache.d.ts +169 -0
- package/dist/containers/project/resource-cache.js +507 -0
- package/dist/containers/project/resource-cache.js.map +1 -0
- package/dist/containers/project/resource-handler.d.ts +129 -0
- package/dist/containers/project/resource-handler.js +206 -0
- package/dist/containers/project/resource-handler.js.map +1 -0
- package/dist/containers/project.d.ts +38 -153
- package/dist/containers/project.js +129 -405
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +8 -2
- package/dist/containers/template.js +20 -15
- package/dist/containers/template.js.map +1 -1
- package/dist/interfaces/folder-content-interfaces.d.ts +5 -3
- package/dist/interfaces/folder-content-interfaces.js +3 -3
- package/dist/interfaces/folder-content-interfaces.js.map +1 -1
- package/dist/interfaces/project-interfaces.d.ts +2 -4
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +14 -1
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/graph/index.js +12 -26
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/index.d.ts +1 -1
- package/dist/macros/index.js +2 -2
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/report/index.js +3 -6
- package/dist/macros/report/index.js.map +1 -1
- package/dist/module-manager.d.ts +16 -3
- package/dist/module-manager.js +51 -19
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.d.ts +16 -3
- package/dist/project-settings.js +79 -14
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/calculation-resource.d.ts +4 -3
- package/dist/resources/calculation-resource.js +11 -5
- package/dist/resources/calculation-resource.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +6 -1
- package/dist/resources/card-type-resource.js +34 -23
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.d.ts +3 -2
- package/dist/resources/create-defaults.js +3 -2
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +4 -1
- package/dist/resources/field-type-resource.js +22 -23
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +5 -9
- package/dist/resources/file-resource.js +6 -11
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +29 -32
- package/dist/resources/folder-resource.js +59 -78
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +4 -1
- package/dist/resources/graph-model-resource.js +11 -4
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +5 -2
- package/dist/resources/graph-view-resource.js +7 -3
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +5 -2
- package/dist/resources/link-type-resource.js +5 -2
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +6 -7
- package/dist/resources/report-resource.js +14 -23
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +93 -8
- package/dist/resources/resource-object.js +162 -110
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +7 -3
- package/dist/resources/template-resource.js +10 -3
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +5 -2
- package/dist/resources/workflow-resource.js +18 -22
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/card-utils.d.ts +2 -2
- package/dist/utils/card-utils.js +1 -1
- package/dist/utils/clingo-fact-builder.d.ts +25 -14
- package/dist/utils/clingo-fact-builder.js +27 -5
- package/dist/utils/clingo-fact-builder.js.map +1 -1
- package/dist/utils/clingo-facts.js +3 -4
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/resource-utils.d.ts +1 -0
- package/dist/utils/resource-utils.js +2 -1
- package/dist/utils/resource-utils.js.map +1 -1
- package/package.json +8 -8
- package/src/card-metadata-updater.ts +6 -2
- package/src/command-handler.ts +24 -5
- package/src/command-manager.ts +29 -17
- package/src/commands/create.ts +43 -78
- package/src/commands/export.ts +63 -52
- package/src/commands/import.ts +24 -14
- package/src/commands/move.ts +0 -1
- package/src/commands/remove.ts +11 -7
- package/src/commands/rename.ts +43 -149
- package/src/commands/show.ts +113 -78
- package/src/commands/transition.ts +26 -28
- package/src/commands/update.ts +25 -22
- package/src/commands/validate.ts +108 -67
- package/src/containers/project/calculation-engine.ts +61 -93
- package/src/containers/project/project-paths.ts +21 -13
- package/src/containers/project/resource-cache.ts +648 -0
- package/src/containers/project/resource-handler.ts +265 -0
- package/src/containers/project.ts +178 -522
- package/src/containers/template.ts +24 -19
- package/src/interfaces/folder-content-interfaces.ts +7 -6
- package/src/interfaces/project-interfaces.ts +7 -6
- package/src/interfaces/resource-interfaces.ts +18 -3
- package/src/macros/graph/index.ts +26 -47
- package/src/macros/index.ts +2 -2
- package/src/macros/report/index.ts +3 -9
- package/src/module-manager.ts +74 -17
- package/src/project-settings.ts +83 -14
- package/src/resources/calculation-resource.ts +18 -18
- package/src/resources/card-type-resource.ts +50 -50
- package/src/resources/create-defaults.ts +3 -2
- package/src/resources/field-type-resource.ts +41 -55
- package/src/resources/file-resource.ts +10 -36
- package/src/resources/folder-resource.ts +69 -120
- package/src/resources/graph-model-resource.ts +20 -22
- package/src/resources/graph-view-resource.ts +15 -17
- package/src/resources/link-type-resource.ts +10 -13
- package/src/resources/report-resource.ts +21 -43
- package/src/resources/resource-object.ts +194 -152
- package/src/resources/template-resource.ts +17 -16
- package/src/resources/workflow-resource.ts +25 -44
- package/src/utils/card-utils.ts +2 -2
- package/src/utils/clingo-fact-builder.ts +28 -16
- package/src/utils/clingo-facts.ts +3 -4
- package/src/utils/resource-utils.ts +2 -1
- package/dist/containers/project/resource-collector.d.ts +0 -110
- package/dist/containers/project/resource-collector.js +0 -344
- package/dist/containers/project/resource-collector.js.map +0 -1
- package/src/containers/project/resource-collector.ts +0 -404
package/src/command-handler.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { join, resolve } from 'node:path';
|
|
|
15
15
|
import { execFileSync } from 'node:child_process';
|
|
16
16
|
import { readFileSync } from 'node:fs';
|
|
17
17
|
|
|
18
|
+
import { SCHEMA_VERSION } from '@cyberismo/assets';
|
|
18
19
|
import type {
|
|
19
20
|
Card,
|
|
20
21
|
CardAttachment,
|
|
@@ -28,7 +29,7 @@ import type {
|
|
|
28
29
|
} from './interfaces/project-interfaces.js';
|
|
29
30
|
import type {
|
|
30
31
|
DataType,
|
|
31
|
-
|
|
32
|
+
AnyResourceContent,
|
|
32
33
|
} from './interfaces/resource-interfaces.js';
|
|
33
34
|
import type {
|
|
34
35
|
AddCommandOptions,
|
|
@@ -43,7 +44,8 @@ import type {
|
|
|
43
44
|
|
|
44
45
|
import type { requestStatus } from './interfaces/request-status-interfaces.js';
|
|
45
46
|
|
|
46
|
-
import { Create
|
|
47
|
+
import { Create } from './commands/create.js';
|
|
48
|
+
import { Validate } from './commands/validate.js';
|
|
47
49
|
import { CommandManager } from './command-manager.js';
|
|
48
50
|
import type { UpdateOperations } from './resources/resource-object.js';
|
|
49
51
|
import { Project } from './containers/project.js';
|
|
@@ -178,6 +180,12 @@ export class Commands {
|
|
|
178
180
|
if (!this.commands) {
|
|
179
181
|
throw new Error('Cannot get instance of CommandManager');
|
|
180
182
|
}
|
|
183
|
+
|
|
184
|
+
// Check schema version and log warning if there's a mismatch
|
|
185
|
+
const versionCheck = this.commands.checkSchemaVersion();
|
|
186
|
+
if (!versionCheck.isCompatible) {
|
|
187
|
+
console.error(versionCheck.message);
|
|
188
|
+
}
|
|
181
189
|
}
|
|
182
190
|
|
|
183
191
|
// Handles actual command. Sets returns values correctly.
|
|
@@ -439,6 +447,13 @@ export class Commands {
|
|
|
439
447
|
return { statusCode: 200 };
|
|
440
448
|
}
|
|
441
449
|
|
|
450
|
+
/**
|
|
451
|
+
* Returns the current schema version.
|
|
452
|
+
*/
|
|
453
|
+
public getSchemaVersion(): number {
|
|
454
|
+
return SCHEMA_VERSION;
|
|
455
|
+
}
|
|
456
|
+
|
|
442
457
|
/**
|
|
443
458
|
* Returns project path, if running operation within project folder.
|
|
444
459
|
* @param path Initial path from where the project path search is started.
|
|
@@ -709,7 +724,7 @@ export class Commands {
|
|
|
709
724
|
| ModuleContent
|
|
710
725
|
| ModuleSettingFromHub[]
|
|
711
726
|
| ProjectMetadata
|
|
712
|
-
|
|
|
727
|
+
| AnyResourceContent
|
|
713
728
|
| string[]
|
|
714
729
|
| undefined
|
|
715
730
|
>;
|
|
@@ -769,7 +784,10 @@ export class Commands {
|
|
|
769
784
|
payload: this.commands!.showCmd.showHubs(),
|
|
770
785
|
};
|
|
771
786
|
case 'modules':
|
|
772
|
-
|
|
787
|
+
return {
|
|
788
|
+
statusCode: 200,
|
|
789
|
+
payload: this.commands!.showCmd.showModules(),
|
|
790
|
+
};
|
|
773
791
|
break;
|
|
774
792
|
case 'project':
|
|
775
793
|
promise = this.commands!.showCmd.showProject();
|
|
@@ -787,7 +805,8 @@ export class Commands {
|
|
|
787
805
|
// Starts the Cyberismo app by running npm start in the app project folder
|
|
788
806
|
private async startApp(forceStart: boolean = false): Promise<requestStatus> {
|
|
789
807
|
// __dirname when running cards ends with /tools/data-handler/dist - use that to navigate to app path
|
|
790
|
-
const baseDir =
|
|
808
|
+
const baseDir =
|
|
809
|
+
import.meta.dirname ?? new URL('.', import.meta.url).pathname;
|
|
791
810
|
const appPath = resolve(baseDir, '../../app');
|
|
792
811
|
|
|
793
812
|
// since current working directory changes, we need to resolve the project path
|
package/src/command-manager.ts
CHANGED
|
@@ -10,21 +10,19 @@
|
|
|
10
10
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Validate,
|
|
27
|
-
} from './commands/index.js';
|
|
13
|
+
import { Calculate } from './commands/calculate.js';
|
|
14
|
+
import { Create } from './commands/create.js';
|
|
15
|
+
import { Edit } from './commands/edit.js';
|
|
16
|
+
import { Export } from './commands/export.js';
|
|
17
|
+
import { Fetch } from './commands/fetch.js';
|
|
18
|
+
import { Import } from './commands/import.js';
|
|
19
|
+
import { Move } from './commands/move.js';
|
|
20
|
+
import { Remove } from './commands/remove.js';
|
|
21
|
+
import { Rename } from './commands/rename.js';
|
|
22
|
+
import { Show } from './commands/show.js';
|
|
23
|
+
import { Transition } from './commands/transition.js';
|
|
24
|
+
import { Update } from './commands/update.js';
|
|
25
|
+
import { Validate } from './commands/validate.js';
|
|
28
26
|
import { Project } from './containers/project.js';
|
|
29
27
|
import { ProjectPaths } from './containers/project/project-paths.js';
|
|
30
28
|
import pino, { type Level, type TransportTargetOptions } from 'pino';
|
|
@@ -32,6 +30,7 @@ import { setLogger } from './utils/log-utils.js';
|
|
|
32
30
|
|
|
33
31
|
export interface CommandManagerOptions {
|
|
34
32
|
watchResourceChanges?: boolean;
|
|
33
|
+
autoSaveConfiguration?: boolean;
|
|
35
34
|
logLevel?: Level;
|
|
36
35
|
}
|
|
37
36
|
|
|
@@ -57,7 +56,10 @@ export class CommandManager {
|
|
|
57
56
|
private pathHandler: ProjectPaths;
|
|
58
57
|
|
|
59
58
|
constructor(path: string, options?: CommandManagerOptions) {
|
|
60
|
-
this.project = new Project(path,
|
|
59
|
+
this.project = new Project(path, {
|
|
60
|
+
autoSave: options?.autoSaveConfiguration,
|
|
61
|
+
watchResourceChanges: options?.watchResourceChanges,
|
|
62
|
+
});
|
|
61
63
|
this.validateCmd = Validate.getInstance();
|
|
62
64
|
|
|
63
65
|
this.calculateCmd = new Calculate(this.project);
|
|
@@ -75,12 +77,22 @@ export class CommandManager {
|
|
|
75
77
|
this.pathHandler = new ProjectPaths(path);
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Checks the schema version compatibility.
|
|
82
|
+
* @returns
|
|
83
|
+
* isCompatible - true if compatible; false otherwise
|
|
84
|
+
* message - optional message related to compatibility.
|
|
85
|
+
*/
|
|
86
|
+
public checkSchemaVersion(): { isCompatible: boolean; message?: string } {
|
|
87
|
+
return this.project.configuration.checkSchemaVersion();
|
|
88
|
+
}
|
|
89
|
+
|
|
78
90
|
/**
|
|
79
91
|
* Some commands needs initialization that cannot be performed inside constructor.
|
|
80
92
|
* Add such calls here.
|
|
81
93
|
*/
|
|
82
94
|
public async initialize() {
|
|
83
|
-
this.project.
|
|
95
|
+
this.project.resources.changedModules();
|
|
84
96
|
await this.project.populateCaches();
|
|
85
97
|
}
|
|
86
98
|
|
package/src/commands/create.ts
CHANGED
|
@@ -15,31 +15,18 @@
|
|
|
15
15
|
import { join, resolve } from 'node:path';
|
|
16
16
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
17
17
|
|
|
18
|
+
import { SCHEMA_VERSION } from '@cyberismo/assets';
|
|
18
19
|
import { errorFunction } from '../utils/error-utils.js';
|
|
19
20
|
import { Project } from '../containers/project.js';
|
|
20
|
-
import { Validate } from './
|
|
21
|
+
import { Validate } from './validate.js';
|
|
21
22
|
|
|
22
23
|
import { EMPTY_RANK, sortItems } from '../utils/lexorank.js';
|
|
23
24
|
import { isModulePath } from '../utils/card-utils.js';
|
|
24
|
-
import type {
|
|
25
|
-
DataType,
|
|
26
|
-
Link,
|
|
27
|
-
LinkType,
|
|
28
|
-
} from '../interfaces/resource-interfaces.js';
|
|
25
|
+
import type { DataType } from '../interfaces/resource-interfaces.js';
|
|
29
26
|
import type { Card, ProjectFile } from '../interfaces/project-interfaces.js';
|
|
30
27
|
import { resourceName, resourceNameToString } from '../utils/resource-utils.js';
|
|
31
28
|
import { writeJsonFile } from '../utils/json.js';
|
|
32
29
|
|
|
33
|
-
import { CalculationResource } from '../resources/calculation-resource.js';
|
|
34
|
-
import { CardTypeResource } from '../resources/card-type-resource.js';
|
|
35
|
-
import { FieldTypeResource } from '../resources/field-type-resource.js';
|
|
36
|
-
import { GraphModelResource } from '../resources/graph-model-resource.js';
|
|
37
|
-
import { GraphViewResource } from '../resources/graph-view-resource.js';
|
|
38
|
-
import { LinkTypeResource } from '../resources/link-type-resource.js';
|
|
39
|
-
import { ReportResource } from '../resources/report-resource.js';
|
|
40
|
-
import { TemplateResource } from '../resources/template-resource.js';
|
|
41
|
-
import { WorkflowResource } from '../resources/workflow-resource.js';
|
|
42
|
-
|
|
43
30
|
// todo: Is there a easy to way to make JSON schema into a TypeScript interface/type?
|
|
44
31
|
// Check this out: https://www.npmjs.com/package/json-schema-to-ts
|
|
45
32
|
|
|
@@ -58,6 +45,7 @@ export class Create {
|
|
|
58
45
|
{
|
|
59
46
|
path: '.cards/local',
|
|
60
47
|
content: {
|
|
48
|
+
schemaVersion: SCHEMA_VERSION,
|
|
61
49
|
cardKeyPrefix: '$PROJECT-PREFIX',
|
|
62
50
|
name: '$PROJECT-NAME',
|
|
63
51
|
modules: [],
|
|
@@ -107,9 +95,9 @@ export class Create {
|
|
|
107
95
|
if (cardTypeName === undefined) {
|
|
108
96
|
throw new Error(`Input validation error: card type cannot be empty`);
|
|
109
97
|
}
|
|
110
|
-
const templateResource =
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
const templateResource = this.project.resources.byType(
|
|
99
|
+
templateName,
|
|
100
|
+
'templates',
|
|
113
101
|
);
|
|
114
102
|
const templateObject = templateResource.templateObject();
|
|
115
103
|
const specificCard = card ? templateObject.findCard(card) : undefined;
|
|
@@ -181,11 +169,9 @@ export class Create {
|
|
|
181
169
|
* @param calculationName name for the calculation resource
|
|
182
170
|
*/
|
|
183
171
|
public async createCalculation(calculationName: string) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
);
|
|
188
|
-
await calculation.create();
|
|
172
|
+
return this.project.resources
|
|
173
|
+
.byType(calculationName, 'calculations')
|
|
174
|
+
.create();
|
|
189
175
|
}
|
|
190
176
|
|
|
191
177
|
/**
|
|
@@ -198,15 +184,15 @@ export class Create {
|
|
|
198
184
|
templateName: string,
|
|
199
185
|
parentCardKey?: string,
|
|
200
186
|
): Promise<Card[]> {
|
|
201
|
-
const templateResource =
|
|
202
|
-
|
|
203
|
-
|
|
187
|
+
const templateResource = this.project.resources.byType(
|
|
188
|
+
templateName,
|
|
189
|
+
'templates',
|
|
204
190
|
);
|
|
205
191
|
|
|
206
192
|
Validate.getInstance().validResourceName(
|
|
207
193
|
'templates',
|
|
208
194
|
resourceNameToString(resourceName(templateName)),
|
|
209
|
-
|
|
195
|
+
this.project.projectPrefixes(),
|
|
210
196
|
);
|
|
211
197
|
|
|
212
198
|
await templateResource.validate();
|
|
@@ -236,12 +222,9 @@ export class Create {
|
|
|
236
222
|
* @param workflowName workflow name to use in the card type.
|
|
237
223
|
*/
|
|
238
224
|
public async createCardType(cardTypeName: string, workflowName: string) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
await cardType.createCardType(workflowName);
|
|
225
|
+
return this.project.resources
|
|
226
|
+
.byType(cardTypeName, 'cardTypes')
|
|
227
|
+
.createCardType(workflowName);
|
|
245
228
|
}
|
|
246
229
|
|
|
247
230
|
/**
|
|
@@ -250,11 +233,9 @@ export class Create {
|
|
|
250
233
|
* @param dataType data type for the field type
|
|
251
234
|
*/
|
|
252
235
|
public async createFieldType(fieldTypeName: string, dataType: DataType) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
);
|
|
257
|
-
await fieldType.createFieldType(dataType);
|
|
236
|
+
return this.project.resources
|
|
237
|
+
.byType(fieldTypeName, 'fieldTypes')
|
|
238
|
+
.createFieldType(dataType);
|
|
258
239
|
}
|
|
259
240
|
|
|
260
241
|
/**
|
|
@@ -262,23 +243,17 @@ export class Create {
|
|
|
262
243
|
* @param graphModelName name for the graph model.
|
|
263
244
|
*/
|
|
264
245
|
public async createGraphModel(graphModelName: string) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
);
|
|
269
|
-
await graphModel.create();
|
|
246
|
+
return this.project.resources
|
|
247
|
+
.byType(graphModelName, 'graphModels')
|
|
248
|
+
.create();
|
|
270
249
|
}
|
|
271
250
|
|
|
272
251
|
/**
|
|
273
252
|
* Creates a new graph view.
|
|
274
|
-
* @param
|
|
253
|
+
* @param graphViewName name for the graph view.
|
|
275
254
|
*/
|
|
276
255
|
public async createGraphView(graphViewName: string) {
|
|
277
|
-
|
|
278
|
-
this.project,
|
|
279
|
-
resourceName(graphViewName),
|
|
280
|
-
);
|
|
281
|
-
await graphView.create();
|
|
256
|
+
return this.project.resources.byType(graphViewName, 'graphViews').create();
|
|
282
257
|
}
|
|
283
258
|
|
|
284
259
|
/**
|
|
@@ -307,11 +282,7 @@ export class Create {
|
|
|
307
282
|
* @param linkTypeName name for the link type.
|
|
308
283
|
*/
|
|
309
284
|
public async createLinkType(linkTypeName: string) {
|
|
310
|
-
|
|
311
|
-
this.project,
|
|
312
|
-
resourceName(linkTypeName),
|
|
313
|
-
);
|
|
314
|
-
await linkType.create();
|
|
285
|
+
return this.project.resources.byType(linkTypeName, 'linkTypes').create();
|
|
315
286
|
}
|
|
316
287
|
|
|
317
288
|
/**
|
|
@@ -335,10 +306,9 @@ export class Create {
|
|
|
335
306
|
const card = this.project.findCard(cardKey);
|
|
336
307
|
const destinationCard = this.project.findCard(destinationCardKey);
|
|
337
308
|
// make sure the link type exists
|
|
338
|
-
const linkTypeObject = this.project.
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
309
|
+
const linkTypeObject = this.project.resources
|
|
310
|
+
.byType(linkType, 'linkTypes')
|
|
311
|
+
.show();
|
|
342
312
|
|
|
343
313
|
// make sure that if linkDescription is not enabled, linkDescription is not provided
|
|
344
314
|
if (
|
|
@@ -387,7 +357,7 @@ export class Create {
|
|
|
387
357
|
);
|
|
388
358
|
}
|
|
389
359
|
|
|
390
|
-
const links
|
|
360
|
+
const links = card.metadata?.links || [];
|
|
391
361
|
links.push({
|
|
392
362
|
linkType,
|
|
393
363
|
cardKey: destinationCardKey,
|
|
@@ -416,6 +386,12 @@ export class Create {
|
|
|
416
386
|
|
|
417
387
|
const projectFolders: string[] = ['.cards/local', 'cardRoot'];
|
|
418
388
|
|
|
389
|
+
if (!Validate.validateFolder(projectPath)) {
|
|
390
|
+
throw new Error(
|
|
391
|
+
`Input validation error: folder name '${projectPath}' is invalid`,
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
419
395
|
if (
|
|
420
396
|
projectPrefix === undefined ||
|
|
421
397
|
projectPrefix.length < 3 ||
|
|
@@ -486,8 +462,7 @@ export class Create {
|
|
|
486
462
|
* @param name name of the report
|
|
487
463
|
*/
|
|
488
464
|
public async createReport(name: string) {
|
|
489
|
-
|
|
490
|
-
await report.createReport();
|
|
465
|
+
return this.project.resources.byType(name, 'reports').createReport();
|
|
491
466
|
}
|
|
492
467
|
|
|
493
468
|
/**
|
|
@@ -496,14 +471,9 @@ export class Create {
|
|
|
496
471
|
* @param templateContent JSON content for the template file.
|
|
497
472
|
*/
|
|
498
473
|
public async createTemplate(templateName: string, templateContent: string) {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
);
|
|
503
|
-
|
|
504
|
-
await template.create(
|
|
505
|
-
templateContent ? JSON.parse(templateContent) : undefined,
|
|
506
|
-
);
|
|
474
|
+
return this.project.resources
|
|
475
|
+
.byType(templateName, 'templates')
|
|
476
|
+
.create(templateContent ? JSON.parse(templateContent) : undefined);
|
|
507
477
|
}
|
|
508
478
|
|
|
509
479
|
/**
|
|
@@ -512,13 +482,8 @@ export class Create {
|
|
|
512
482
|
* @param workflowContent workflow content JSON
|
|
513
483
|
*/
|
|
514
484
|
public async createWorkflow(workflowName: string, workflowContent: string) {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
);
|
|
519
|
-
|
|
520
|
-
await workflow.create(
|
|
521
|
-
workflowContent ? JSON.parse(workflowContent) : undefined,
|
|
522
|
-
);
|
|
485
|
+
return this.project.resources
|
|
486
|
+
.byType(workflowName, 'workflows')
|
|
487
|
+
.create(workflowContent ? JSON.parse(workflowContent) : undefined);
|
|
523
488
|
}
|
|
524
489
|
}
|
package/src/commands/export.ts
CHANGED
|
@@ -31,12 +31,20 @@ import { generateReportContent } from '../utils/report.js';
|
|
|
31
31
|
import { getStaticDirectoryPath, pdfReport } from '@cyberismo/assets';
|
|
32
32
|
import { Project } from '../containers/project.js';
|
|
33
33
|
import type { QueryResult } from '../types/queries.js';
|
|
34
|
-
import type { Show } from './
|
|
34
|
+
import type { Show } from './show.js';
|
|
35
35
|
import { sortItems } from '../utils/lexorank.js';
|
|
36
36
|
|
|
37
37
|
const attachmentFolder: string = 'a';
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Handles all export commands.
|
|
41
|
+
*/
|
|
39
42
|
export class Export {
|
|
43
|
+
/**
|
|
44
|
+
* Creates an instance of export.
|
|
45
|
+
* @param project Project to use
|
|
46
|
+
* @param showCmd Instance of Export command to use.
|
|
47
|
+
*/
|
|
40
48
|
constructor(
|
|
41
49
|
protected project: Project,
|
|
42
50
|
protected showCmd: Show,
|
|
@@ -97,6 +105,56 @@ export class Export {
|
|
|
97
105
|
return content;
|
|
98
106
|
}
|
|
99
107
|
|
|
108
|
+
// Runs Ascii Doctor converter --> to PDF
|
|
109
|
+
private async runAsciidoctorPdf(content: string): Promise<Buffer> {
|
|
110
|
+
const staticRootDir = await getStaticDirectoryPath();
|
|
111
|
+
const proc = spawn(
|
|
112
|
+
'asciidoctor-pdf',
|
|
113
|
+
[
|
|
114
|
+
'-a',
|
|
115
|
+
'pdf-theme=cyberismo',
|
|
116
|
+
'-a',
|
|
117
|
+
`pdf-themesdir=${join(staticRootDir, 'pdf-themes')}`,
|
|
118
|
+
'-a',
|
|
119
|
+
`pdf-fontsdir=${join(staticRootDir, 'pdf-themes', 'fonts')};GEM_FONTS_DIR`,
|
|
120
|
+
'-',
|
|
121
|
+
],
|
|
122
|
+
{
|
|
123
|
+
timeout: 100000,
|
|
124
|
+
shell: process.platform === 'win32',
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
proc.stdin.end(content);
|
|
128
|
+
const result = await new Promise<Buffer>((resolve, reject) => {
|
|
129
|
+
const chunks: Buffer[] = [];
|
|
130
|
+
proc.stdout.on('data', (chunk) => {
|
|
131
|
+
chunks.push(chunk);
|
|
132
|
+
});
|
|
133
|
+
proc.stderr.on('data', (chunk) => {
|
|
134
|
+
process.stderr.write(chunk);
|
|
135
|
+
});
|
|
136
|
+
proc.on('error', (error) => {
|
|
137
|
+
if ('code' in error && error.code === 'ENOENT') {
|
|
138
|
+
reject(
|
|
139
|
+
new Error(
|
|
140
|
+
'Asciidoctor-pdf not found. Please install asciidoctor-pdf to use this feature.',
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
reject(error);
|
|
145
|
+
});
|
|
146
|
+
proc.on('close', (code) => {
|
|
147
|
+
if (code === 0) {
|
|
148
|
+
resolve(Buffer.concat(chunks));
|
|
149
|
+
} else {
|
|
150
|
+
reject(new Error(`Asciidoctor-pdf failed with code ${code}`));
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Adds cards to an ADOC file as additional content.
|
|
100
158
|
private async toAdocFileAsContent(path: string, cards: Card[]) {
|
|
101
159
|
for (const card of cards) {
|
|
102
160
|
let fileContent = '';
|
|
@@ -108,9 +166,9 @@ export class Export {
|
|
|
108
166
|
}
|
|
109
167
|
|
|
110
168
|
if (card.metadata) {
|
|
111
|
-
const cardTypeForCard =
|
|
112
|
-
card.metadata?.cardType,
|
|
113
|
-
|
|
169
|
+
const cardTypeForCard = this.project.resources
|
|
170
|
+
.byType(card.metadata?.cardType, 'cardTypes')
|
|
171
|
+
.show();
|
|
114
172
|
const metaDataContent = this.metaToAdoc(card, cardTypeForCard);
|
|
115
173
|
fileContent += metaDataContent;
|
|
116
174
|
}
|
|
@@ -177,6 +235,7 @@ export class Export {
|
|
|
177
235
|
* Convert treeQueryResult object into a Card object and add content, metadata & attachments
|
|
178
236
|
* Handles card children recursively
|
|
179
237
|
* @param treeQueryResult tree query result object
|
|
238
|
+
* @returns Tree query result as a Card.
|
|
180
239
|
*/
|
|
181
240
|
protected async treeQueryResultToCard(
|
|
182
241
|
treeQueryResult: QueryResult<'tree'>,
|
|
@@ -218,54 +277,6 @@ export class Export {
|
|
|
218
277
|
return card;
|
|
219
278
|
}
|
|
220
279
|
|
|
221
|
-
private async runAsciidoctorPdf(content: string): Promise<Buffer> {
|
|
222
|
-
const staticRootDir = await getStaticDirectoryPath();
|
|
223
|
-
const proc = spawn(
|
|
224
|
-
'asciidoctor-pdf',
|
|
225
|
-
[
|
|
226
|
-
'-a',
|
|
227
|
-
'pdf-theme=cyberismo',
|
|
228
|
-
'-a',
|
|
229
|
-
`pdf-themesdir=${join(staticRootDir, 'pdf-themes')}`,
|
|
230
|
-
'-a',
|
|
231
|
-
`pdf-fontsdir=${join(staticRootDir, 'pdf-themes', 'fonts')};GEM_FONTS_DIR`,
|
|
232
|
-
'-',
|
|
233
|
-
],
|
|
234
|
-
{
|
|
235
|
-
timeout: 100000,
|
|
236
|
-
shell: process.platform === 'win32',
|
|
237
|
-
},
|
|
238
|
-
);
|
|
239
|
-
proc.stdin.end(content);
|
|
240
|
-
const result = await new Promise<Buffer>((resolve, reject) => {
|
|
241
|
-
const chunks: Buffer[] = [];
|
|
242
|
-
proc.stdout.on('data', (chunk) => {
|
|
243
|
-
chunks.push(chunk);
|
|
244
|
-
});
|
|
245
|
-
proc.stderr.on('data', (chunk) => {
|
|
246
|
-
process.stderr.write(chunk);
|
|
247
|
-
});
|
|
248
|
-
proc.on('error', (error) => {
|
|
249
|
-
if ('code' in error && error.code === 'ENOENT') {
|
|
250
|
-
reject(
|
|
251
|
-
new Error(
|
|
252
|
-
'Asciidoctor-pdf not found. Please install asciidoctor-pdf to use this feature.',
|
|
253
|
-
),
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
reject(error);
|
|
257
|
-
});
|
|
258
|
-
proc.on('close', (code) => {
|
|
259
|
-
if (code === 0) {
|
|
260
|
-
resolve(Buffer.concat(chunks));
|
|
261
|
-
} else {
|
|
262
|
-
reject(new Error(`Asciidoctor-pdf failed with code ${code}`));
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
return result;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
280
|
/**
|
|
270
281
|
* Exports the card(s) to pdf.
|
|
271
282
|
* @param destination Path to where the resulting file(s) will be created.
|
package/src/commands/import.ts
CHANGED
|
@@ -11,20 +11,28 @@
|
|
|
11
11
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import type { CardType } from '../interfaces/resource-interfaces.js';
|
|
15
|
-
import { type Create, Validate } from './index.js';
|
|
16
14
|
import { ModuleManager } from '../module-manager.js';
|
|
15
|
+
import { readCsvFile } from '../utils/csv.js';
|
|
16
|
+
import { Validate } from './validate.js';
|
|
17
|
+
|
|
18
|
+
import type { Create } from './create.js';
|
|
17
19
|
import type {
|
|
18
20
|
Credentials,
|
|
19
21
|
ModuleSettingOptions,
|
|
20
22
|
} from '../interfaces/project-interfaces.js';
|
|
21
23
|
import type { Project } from '../containers/project.js';
|
|
22
|
-
import { readCsvFile } from '../utils/csv.js';
|
|
23
|
-
import { resourceName } from '../utils/resource-utils.js';
|
|
24
|
-
import { TemplateResource } from '../resources/template-resource.js';
|
|
25
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Handles all import commands.
|
|
27
|
+
*/
|
|
26
28
|
export class Import {
|
|
27
29
|
private moduleManager: ModuleManager;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates an instance of Import.
|
|
33
|
+
* @param project Project to use.
|
|
34
|
+
* @param createCmd Instance of Create to use.
|
|
35
|
+
*/
|
|
28
36
|
constructor(
|
|
29
37
|
private project: Project,
|
|
30
38
|
private createCmd: Create,
|
|
@@ -53,9 +61,9 @@ export class Import {
|
|
|
53
61
|
|
|
54
62
|
for (const row of csv) {
|
|
55
63
|
const { title, template, description, labels, ...customFields } = row;
|
|
56
|
-
const templateResource =
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
const templateResource = this.project.resources.byType(
|
|
65
|
+
template,
|
|
66
|
+
'templates',
|
|
59
67
|
);
|
|
60
68
|
const templateObject = templateResource.templateObject();
|
|
61
69
|
if (!templateObject) {
|
|
@@ -78,13 +86,12 @@ export class Import {
|
|
|
78
86
|
}
|
|
79
87
|
const cardKey = cards[0].key;
|
|
80
88
|
const card = this.project.findCard(cardKey);
|
|
81
|
-
|
|
82
|
-
card.metadata?.cardType || '',
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
if (!cardType) {
|
|
89
|
+
if (!card.metadata?.cardType) {
|
|
86
90
|
throw new Error(`Card type not found for card ${cardKey}`);
|
|
87
91
|
}
|
|
92
|
+
const cardType = this.project.resources
|
|
93
|
+
.byType(card.metadata?.cardType, 'cardTypes')
|
|
94
|
+
.show();
|
|
88
95
|
|
|
89
96
|
if (description) {
|
|
90
97
|
await this.project.updateCardContent(cardKey, description);
|
|
@@ -155,7 +162,10 @@ export class Import {
|
|
|
155
162
|
};
|
|
156
163
|
|
|
157
164
|
// Fetch module dependencies.
|
|
158
|
-
await this.moduleManager.
|
|
165
|
+
await this.moduleManager.updateDependencies(
|
|
166
|
+
moduleSettings,
|
|
167
|
+
options?.credentials,
|
|
168
|
+
);
|
|
159
169
|
|
|
160
170
|
// Add module as a dependency.
|
|
161
171
|
await this.project.importModule(moduleSettings);
|
package/src/commands/move.ts
CHANGED
|
@@ -197,7 +197,6 @@ export class Move {
|
|
|
197
197
|
sourceCard.parent = movingToRoot ? ROOT : destination;
|
|
198
198
|
if (sourceCard.metadata) {
|
|
199
199
|
sourceCard.metadata.rank = rank;
|
|
200
|
-
sourceCard.metadata.parent = movingToRoot ? ROOT : destination;
|
|
201
200
|
}
|
|
202
201
|
|
|
203
202
|
// Handle cache update and persistence
|