@cyberismo/data-handler 0.0.12 → 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.
Files changed (78) hide show
  1. package/dist/command-handler.d.ts +24 -42
  2. package/dist/command-handler.js +30 -25
  3. package/dist/command-handler.js.map +1 -1
  4. package/dist/commands/import.js +2 -2
  5. package/dist/commands/import.js.map +1 -1
  6. package/dist/commands/show.d.ts +4 -0
  7. package/dist/commands/show.js +4 -0
  8. package/dist/commands/show.js.map +1 -1
  9. package/dist/commands/update.d.ts +11 -1
  10. package/dist/commands/update.js +14 -2
  11. package/dist/commands/update.js.map +1 -1
  12. package/dist/commands/validate.d.ts +2 -1
  13. package/dist/commands/validate.js +3 -2
  14. package/dist/commands/validate.js.map +1 -1
  15. package/dist/containers/card-container.js +1 -1
  16. package/dist/containers/card-container.js.map +1 -1
  17. package/dist/containers/project/calculation-engine.js +1 -1
  18. package/dist/containers/project/calculation-engine.js.map +1 -1
  19. package/dist/index.d.ts +4 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/interfaces/command-options.d.ts +81 -0
  22. package/dist/interfaces/command-options.js +14 -0
  23. package/dist/interfaces/command-options.js.map +1 -0
  24. package/dist/interfaces/folder-content-interfaces.d.ts +50 -0
  25. package/dist/interfaces/folder-content-interfaces.js +45 -0
  26. package/dist/interfaces/folder-content-interfaces.js.map +1 -0
  27. package/dist/interfaces/resource-interfaces.d.ts +28 -10
  28. package/dist/interfaces/resource-interfaces.js.map +1 -1
  29. package/dist/macros/report/index.js +4 -4
  30. package/dist/macros/report/index.js.map +1 -1
  31. package/dist/resources/card-type-resource.js +11 -5
  32. package/dist/resources/card-type-resource.js.map +1 -1
  33. package/dist/resources/field-type-resource.js +1 -1
  34. package/dist/resources/field-type-resource.js.map +1 -1
  35. package/dist/resources/folder-resource.d.ts +37 -9
  36. package/dist/resources/folder-resource.js +108 -12
  37. package/dist/resources/folder-resource.js.map +1 -1
  38. package/dist/resources/graph-model-resource.d.ts +7 -4
  39. package/dist/resources/graph-model-resource.js +12 -25
  40. package/dist/resources/graph-model-resource.js.map +1 -1
  41. package/dist/resources/graph-view-resource.d.ts +7 -4
  42. package/dist/resources/graph-view-resource.js +12 -26
  43. package/dist/resources/graph-view-resource.js.map +1 -1
  44. package/dist/resources/link-type-resource.js +1 -1
  45. package/dist/resources/link-type-resource.js.map +1 -1
  46. package/dist/resources/report-resource.d.ts +14 -10
  47. package/dist/resources/report-resource.js +41 -45
  48. package/dist/resources/report-resource.js.map +1 -1
  49. package/dist/resources/resource-object.d.ts +7 -0
  50. package/dist/resources/resource-object.js.map +1 -1
  51. package/dist/resources/template-resource.d.ts +5 -1
  52. package/dist/resources/template-resource.js +12 -7
  53. package/dist/resources/template-resource.js.map +1 -1
  54. package/dist/resources/workflow-resource.js +6 -0
  55. package/dist/resources/workflow-resource.js.map +1 -1
  56. package/package.json +9 -7
  57. package/src/command-handler.ts +71 -58
  58. package/src/commands/import.ts +2 -0
  59. package/src/commands/show.ts +4 -0
  60. package/src/commands/update.ts +20 -2
  61. package/src/commands/validate.ts +6 -2
  62. package/src/containers/card-container.ts +1 -1
  63. package/src/containers/project/calculation-engine.ts +1 -3
  64. package/src/index.ts +36 -2
  65. package/src/interfaces/command-options.ts +144 -0
  66. package/src/interfaces/folder-content-interfaces.ts +69 -0
  67. package/src/interfaces/resource-interfaces.ts +41 -12
  68. package/src/macros/report/index.ts +4 -4
  69. package/src/resources/card-type-resource.ts +12 -6
  70. package/src/resources/field-type-resource.ts +1 -1
  71. package/src/resources/folder-resource.ts +149 -19
  72. package/src/resources/graph-model-resource.ts +16 -27
  73. package/src/resources/graph-view-resource.ts +16 -28
  74. package/src/resources/link-type-resource.ts +1 -1
  75. package/src/resources/report-resource.ts +60 -62
  76. package/src/resources/resource-object.ts +11 -0
  77. package/src/resources/template-resource.ts +12 -7
  78. package/src/resources/workflow-resource.ts +4 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cyberismo/data-handler",
3
3
  "description": "Command handler for cards and web service",
4
- "version": "0.0.12",
4
+ "version": "0.0.13",
5
5
  "author": "sami.merila@cyberismo.com",
6
6
  "license": "AGPL-3.0",
7
7
  "homepage": "https://github.com/CyberismoCom/cyberismo",
@@ -27,6 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@asciidoctor/core": "^3.0.4",
30
+ "@types/mime-types": "^3.0.1",
30
31
  "@viz-js/viz": "^3.17.0",
31
32
  "async-mutex": "^0.5.0",
32
33
  "csv-parse": "^6.1.0",
@@ -34,18 +35,19 @@
34
35
  "dompurify": "^3.2.6",
35
36
  "email-validator": "^2.0.4",
36
37
  "handlebars": "^4.7.8",
37
- "jsdom": "^26.1.0",
38
+ "jsdom": "^27.0.0",
38
39
  "json-schema": "^0.4.0",
39
40
  "jsonschema": "^1.5.0",
40
- "pino": "^9.9.4",
41
+ "mime-types": "^3.0.1",
42
+ "pino": "^9.9.5",
41
43
  "simple-git": "^3.28.0",
42
44
  "string-pixel-width": "^1.11.0",
43
45
  "tslib": "^2.6.2",
44
46
  "vega": "^6.1.2",
45
- "vega-lite": "^6.2.0",
46
- "write-json-file": "^6.0.0",
47
- "@cyberismo/assets": "0.0.12",
48
- "@cyberismo/node-clingo": "1.2.0"
47
+ "vega-lite": "^6.3.1",
48
+ "write-json-file": "^7.0.0",
49
+ "@cyberismo/assets": "0.0.13",
50
+ "@cyberismo/node-clingo": "1.3.0"
49
51
  },
50
52
  "type": "module",
51
53
  "files": [
@@ -31,6 +31,16 @@ import type {
31
31
  DataType,
32
32
  ResourceContent,
33
33
  } from './interfaces/resource-interfaces.js';
34
+ import type {
35
+ AddCommandOptions,
36
+ AllCommandOptions,
37
+ CalcCommandOptions,
38
+ ExportCommandOptions,
39
+ ReportCommandOptions,
40
+ ShowCommandOptions,
41
+ StartCommandOptions,
42
+ UpdateCommandOptions,
43
+ } from './interfaces/command-options.js';
34
44
 
35
45
  import type { requestStatus } from './interfaces/request-status-interfaces.js';
36
46
 
@@ -48,49 +58,30 @@ import { type Level } from 'pino';
48
58
  import { type Context } from './interfaces/project-interfaces.js';
49
59
  import { type QueryName } from './types/queries.js';
50
60
 
51
- // Generic options interface
52
- export interface CardsOptions {
53
- context?: Context;
54
- date?: string;
55
- details?: boolean;
56
- forceStart?: boolean;
57
- logLevel?: Level;
58
- mappingFile?: string;
59
- name?: string;
60
- projectPath?: string;
61
- recursive?: boolean;
62
- repeat?: number;
63
- revremark?: string;
64
- showAll?: boolean;
65
- showUse?: boolean;
66
- skipModuleImport?: boolean;
67
- title?: string;
68
- version?: string;
69
- watchResourceChanges?: boolean;
70
- }
71
-
72
61
  // Commands that this class supports.
73
- // todo: Could be inside the `CommandHandler` ?
74
- export enum Cmd {
75
- add = 'add',
76
- calc = 'calc',
77
- create = 'create',
78
- edit = 'edit',
79
- export = 'export',
80
- fetch = 'fetch',
81
- import = 'import',
82
- move = 'move',
83
- rank = 'rank',
84
- remove = 'remove',
85
- rename = 'rename',
86
- report = 'report',
87
- show = 'show',
88
- start = 'start',
89
- transition = 'transition',
90
- update = 'update',
91
- updateModules = 'update-modules',
92
- validate = 'validate',
93
- }
62
+ export const Cmd = {
63
+ add: 'add',
64
+ calc: 'calc',
65
+ create: 'create',
66
+ edit: 'edit',
67
+ export: 'export',
68
+ fetch: 'fetch',
69
+ import: 'import',
70
+ move: 'move',
71
+ rank: 'rank',
72
+ remove: 'remove',
73
+ rename: 'rename',
74
+ report: 'report',
75
+ show: 'show',
76
+ start: 'start',
77
+ transition: 'transition',
78
+ update: 'update',
79
+ updateModules: 'update-modules',
80
+ validate: 'validate',
81
+ };
82
+
83
+ export type CmdKey = keyof typeof Cmd;
84
+ export type CmdValue = (typeof Cmd)[CmdKey];
94
85
 
95
86
  // To what format the content can be exported to.
96
87
  export enum ExportFormats {
@@ -128,9 +119,9 @@ export class Commands {
128
119
  * @returns request status; 200 if success; 400 in handled error; 500 in unknown error
129
120
  */
130
121
  public async command(
131
- command: Cmd,
122
+ command: CmdValue,
132
123
  args: string[],
133
- options: CardsOptions,
124
+ options: AllCommandOptions,
134
125
  credentials?: Credentials,
135
126
  ): Promise<requestStatus> {
136
127
  // Set project path and validate it.
@@ -163,7 +154,7 @@ export class Commands {
163
154
  }
164
155
 
165
156
  // Handles initializing the project so that it can be used in the class.
166
- private async doSetProject(options: CardsOptions) {
157
+ private async doSetProject(options: AllCommandOptions) {
167
158
  const path = options.projectPath || '';
168
159
  this.projectPath = resolveTilde(await this.setProjectPath(path));
169
160
  if (!Validate.validateFolder(this.projectPath)) {
@@ -182,7 +173,8 @@ export class Commands {
182
173
 
183
174
  this.commands = await CommandManager.getInstance(this.projectPath, {
184
175
  logLevel: options.logLevel,
185
- watchResourceChanges: options.watchResourceChanges,
176
+ watchResourceChanges: (options as StartCommandOptions)
177
+ .watchResourceChanges,
186
178
  });
187
179
  if (!this.commands) {
188
180
  throw new Error('Cannot get instance of CommandManager');
@@ -192,16 +184,21 @@ export class Commands {
192
184
 
193
185
  // Handles actual command. Sets returns values correctly.
194
186
  private async doHandleCommand(
195
- command: Cmd,
187
+ command: CmdValue,
196
188
  args: string[],
197
- options: CardsOptions,
189
+ options: AllCommandOptions,
198
190
  credentials?: Credentials,
199
191
  ) {
200
192
  try {
201
193
  if (command === Cmd.add) {
202
194
  const [type, target, cardType, cardKey] = args;
203
195
  if (type === 'card') {
204
- return await this.addCard(target, cardType, cardKey, options.repeat);
196
+ return await this.addCard(
197
+ target,
198
+ cardType,
199
+ cardKey,
200
+ (options as AddCommandOptions).repeat,
201
+ );
205
202
  }
206
203
  if (type === 'hub') {
207
204
  return await this.addHub(target);
@@ -214,7 +211,10 @@ export class Commands {
214
211
  return { statusCode: 400, message: 'File path is missing' };
215
212
  }
216
213
  await this.generateLogicProgram();
217
- return this.runLogicProgram(cardKey, options.context || 'localApp');
214
+ return this.runLogicProgram(
215
+ cardKey,
216
+ (options as CalcCommandOptions).context || 'localApp',
217
+ );
218
218
  }
219
219
  if (command === 'generate') {
220
220
  const [destination, query] = rest;
@@ -356,11 +356,11 @@ export class Commands {
356
356
  const [parameters, outputPath] = args;
357
357
  return this.runReport(
358
358
  parameters,
359
- options.context || 'localApp',
359
+ (options as ReportCommandOptions).context || 'localApp',
360
360
  outputPath,
361
361
  );
362
362
  } else if (command === Cmd.start) {
363
- return this.startApp(options.forceStart);
363
+ return this.startApp((options as StartCommandOptions).forceStart);
364
364
  } else if (command === Cmd.transition) {
365
365
  const [cardKey, state] = args;
366
366
  await this.commands?.transitionCmd.cardTransition(cardKey, {
@@ -378,13 +378,13 @@ export class Commands {
378
378
  // Handle mapping file for workflow changes
379
379
  let mappingTable: { stateMapping: Record<string, string> } | undefined;
380
380
  if (
381
- options.mappingFile &&
381
+ (options as UpdateCommandOptions).mappingFile &&
382
382
  operation === 'change' &&
383
383
  key === 'workflow'
384
384
  ) {
385
385
  try {
386
386
  const mappingData = await readJsonFile(
387
- resolveTilde(options.mappingFile),
387
+ resolveTilde((options as UpdateCommandOptions).mappingFile!),
388
388
  );
389
389
  if (
390
390
  mappingData &&
@@ -537,7 +537,7 @@ export class Commands {
537
537
  destination: string = 'output',
538
538
  format: ExportFormats,
539
539
  parentCardKey?: string,
540
- pdfOptions?: CardsOptions,
540
+ pdfOptions?: ExportCommandOptions,
541
541
  ): Promise<requestStatus> {
542
542
  if (!this.commands) {
543
543
  return { statusCode: 500 };
@@ -701,7 +701,7 @@ export class Commands {
701
701
  private async show(
702
702
  type: ResourceTypes,
703
703
  typeDetail: string,
704
- options: CardsOptions,
704
+ options: ShowCommandOptions,
705
705
  ): Promise<requestStatus> {
706
706
  const detail = typeDetail || '';
707
707
  let promise: Promise<
@@ -798,8 +798,15 @@ export class Commands {
798
798
  // since current working directory changes, we need to resolve the project path
799
799
  const projectPath = resolve(this.projectPath);
800
800
 
801
+ if (!this.commands) {
802
+ return { statusCode: 500, message: 'Commands not initialized' };
803
+ }
804
+
801
805
  if (!forceStart) {
802
- const validationErrors = await this.validateCmd.validate(projectPath);
806
+ const validationErrors = await this.validateCmd.validate(
807
+ projectPath,
808
+ () => this.commands!.project,
809
+ );
803
810
  if (validationErrors) {
804
811
  return { statusCode: 400, message: validationErrors };
805
812
  }
@@ -821,7 +828,13 @@ export class Commands {
821
828
 
822
829
  // Validates that a given path conforms to schema. Validates both file/folder structure and file content.
823
830
  private async validate(): Promise<requestStatus> {
824
- const result = await this.validateCmd.validate(this.projectPath);
831
+ if (!this.commands) {
832
+ return { statusCode: 500, message: 'Commands not initialized' };
833
+ }
834
+ const result = await this.validateCmd.validate(
835
+ this.projectPath,
836
+ () => this.commands!.project,
837
+ );
825
838
  return {
826
839
  statusCode: 200,
827
840
  message: result.length ? result : 'Project structure validated',
@@ -136,6 +136,7 @@ export class Import {
136
136
  ) {
137
137
  const beforeImportValidateErrors = await Validate.getInstance().validate(
138
138
  this.project.basePath,
139
+ () => this.project,
139
140
  );
140
141
  const gitModule = source.startsWith('https') || source.startsWith('git@');
141
142
  const modulePrefix = gitModule
@@ -164,6 +165,7 @@ export class Import {
164
165
  // Validate the project after module has been imported
165
166
  const afterImportValidateErrors = await Validate.getInstance().validate(
166
167
  this.project.basePath,
168
+ () => this.project,
167
169
  );
168
170
  if (afterImportValidateErrors.length > beforeImportValidateErrors.length) {
169
171
  console.error(
@@ -332,6 +332,8 @@ export class Show {
332
332
 
333
333
  /**
334
334
  * Shows the content of a file in a resource.
335
+ * TODO: To be removed
336
+ * @deprecated
335
337
  * @param resourceName Name of the resource.
336
338
  * @param fileName Name of the file to show.
337
339
  * @returns the content of the file.
@@ -360,6 +362,8 @@ export class Show {
360
362
 
361
363
  /**
362
364
  * Shows all file names in a folder resource.
365
+ * TODO: To be removed
366
+ * @deprecated
363
367
  * @param resourceName Name of the resource.
364
368
  * @returns all file names in the resource.
365
369
  */
@@ -14,6 +14,7 @@ import type {
14
14
  AddOperation,
15
15
  ChangeOperation,
16
16
  Operation,
17
+ OperationFor,
17
18
  RankOperation,
18
19
  RemoveOperation,
19
20
  UpdateOperations,
@@ -44,7 +45,6 @@ export class Update {
44
45
  optionalDetail?: Type, // todo: for 'rank' it might be reasonable to accept also 'number'
45
46
  mappingTable?: { stateMapping: Record<string, string> },
46
47
  ) {
47
- const resource = Project.resourceObject(this.project, resourceName(name));
48
48
  const op: Operation<Type> = {
49
49
  name: operation,
50
50
  target: '' as Type,
@@ -76,7 +76,25 @@ export class Update {
76
76
  : undefined;
77
77
  }
78
78
 
79
- await resource?.update(key, op);
79
+ await this.applyResourceOperation(name, key, op);
80
+ }
81
+
82
+ /**
83
+ * Update single resource property
84
+ * This is similar to updateValue, but allows the operation to be fully specified
85
+ * @param name Name of the resource to operate on.
86
+ * @param key Property to change in resource JSON
87
+ * @param operation The full operation object
88
+ * @template Type Type of the target of the operation
89
+ * @template T Type of operation ('add', 'remove', 'change', 'rank')
90
+ */
91
+ public async applyResourceOperation<Type, T extends UpdateOperations>(
92
+ name: string,
93
+ key: string,
94
+ operation: OperationFor<Type, T>,
95
+ ) {
96
+ const resource = Project.resourceObject(this.project, resourceName(name));
97
+ await resource?.update(key, operation);
80
98
  this.project.collectLocalResources();
81
99
  }
82
100
  }
@@ -521,9 +521,13 @@ export class Validate {
521
521
  * Validates that a given directory path (and its children) conform to a JSON schema.
522
522
  * @note Validates also content in the directory tree, if .schema file is found.
523
523
  * @param projectPath path to validate.
524
+ * @param projectFn function that returns a Project instance.
524
525
  * @returns string containing all validation errors
525
526
  */
526
- public async validate(projectPath: string): Promise<string> {
527
+ public async validate(
528
+ projectPath: string,
529
+ projectFn: () => Project,
530
+ ): Promise<string> {
527
531
  let validationErrors = '';
528
532
  this.validatedFieldTypes.clear();
529
533
  this.validatedWorkflows.clear();
@@ -545,7 +549,7 @@ export class Validate {
545
549
  return validationErrors;
546
550
  } else {
547
551
  const errorMsg: string[] = [];
548
- const project = new Project(projectPath);
552
+ const project = projectFn();
549
553
 
550
554
  // Then, validate that each 'contentSchema' children as well.
551
555
  const result = await this.readAndValidateContentFiles(
@@ -18,9 +18,9 @@ import type { Dirent } from 'node:fs';
18
18
  import { readdir, readFile, writeFile } from 'node:fs/promises';
19
19
 
20
20
  import { findParentPath } from '../utils/card-utils.js';
21
+ import { getFilesSync } from '../utils/file-utils.js';
21
22
  import { readJsonFile } from '../utils/json.js';
22
23
  import { writeJsonFile } from '../utils/json.js';
23
- import { getFilesSync } from '../utils/file-utils.js';
24
24
 
25
25
  // interfaces
26
26
  import {
@@ -466,9 +466,7 @@ export class CalculationEngine {
466
466
  case 'templates':
467
467
  return createTemplateFacts(resource as TemplateMetadata);
468
468
  default:
469
- throw new Error(
470
- `Resource ${resourceNameToString(resourceName)} does not have a logic program`,
471
- );
469
+ return '';
472
470
  }
473
471
  }
474
472
 
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
+ }