@oml/cli 0.13.0 → 0.14.1

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 (77) hide show
  1. package/README.md +28 -21
  2. package/out/{auth.d.ts → auth/auth.d.ts} +7 -0
  3. package/out/{auth.js → auth/auth.js} +42 -3
  4. package/out/auth/auth.js.map +1 -0
  5. package/out/{platform-constants.js → auth/constants.js} +1 -1
  6. package/out/auth/constants.js.map +1 -0
  7. package/out/{platform.d.ts → auth/platform.d.ts} +5 -7
  8. package/out/{platform.js → auth/platform.js} +13 -19
  9. package/out/auth/platform.js.map +1 -0
  10. package/out/cli.d.ts +6 -0
  11. package/out/cli.js +175 -62
  12. package/out/cli.js.map +1 -1
  13. package/out/commands/export.d.ts +8 -0
  14. package/out/commands/export.js +27 -0
  15. package/out/commands/export.js.map +1 -0
  16. package/out/commands/lint.d.ts +22 -2
  17. package/out/commands/lint.js +64 -18
  18. package/out/commands/lint.js.map +1 -1
  19. package/out/commands/reason.d.ts +2 -9
  20. package/out/commands/reason.js +52 -48
  21. package/out/commands/reason.js.map +1 -1
  22. package/out/commands/render.d.ts +1 -9
  23. package/out/commands/render.js +15 -726
  24. package/out/commands/render.js.map +1 -1
  25. package/out/commands/server/actions.d.ts +22 -0
  26. package/out/commands/server/actions.js +394 -0
  27. package/out/commands/server/actions.js.map +1 -0
  28. package/out/commands/server/require.d.ts +1 -0
  29. package/out/commands/server/require.js +89 -0
  30. package/out/commands/server/require.js.map +1 -0
  31. package/out/commands/server/rest.d.ts +2 -0
  32. package/out/commands/server/rest.js +117 -0
  33. package/out/commands/server/rest.js.map +1 -0
  34. package/out/commands/validate.d.ts +3 -3
  35. package/out/commands/validate.js +35 -171
  36. package/out/commands/validate.js.map +1 -1
  37. package/package.json +5 -7
  38. package/src/{auth.ts → auth/auth.ts} +54 -3
  39. package/src/{platform.ts → auth/platform.ts} +13 -19
  40. package/src/cli.ts +207 -63
  41. package/src/commands/export.ts +54 -0
  42. package/src/commands/lint.ts +88 -18
  43. package/src/commands/reason.ts +69 -56
  44. package/src/commands/render.ts +23 -995
  45. package/src/commands/server/actions.ts +480 -0
  46. package/src/commands/server/require.ts +99 -0
  47. package/src/commands/server/rest.ts +135 -0
  48. package/src/commands/validate.ts +46 -207
  49. package/out/auth.js.map +0 -1
  50. package/out/backend/backend-types.d.ts +0 -21
  51. package/out/backend/backend-types.js +0 -3
  52. package/out/backend/backend-types.js.map +0 -1
  53. package/out/backend/create-backend.d.ts +0 -2
  54. package/out/backend/create-backend.js +0 -6
  55. package/out/backend/create-backend.js.map +0 -1
  56. package/out/backend/direct-backend.d.ts +0 -20
  57. package/out/backend/direct-backend.js +0 -150
  58. package/out/backend/direct-backend.js.map +0 -1
  59. package/out/backend/reasoned-output.d.ts +0 -38
  60. package/out/backend/reasoned-output.js +0 -568
  61. package/out/backend/reasoned-output.js.map +0 -1
  62. package/out/commands/closure.d.ts +0 -33
  63. package/out/commands/closure.js +0 -537
  64. package/out/commands/closure.js.map +0 -1
  65. package/out/commands/compile.d.ts +0 -11
  66. package/out/commands/compile.js +0 -63
  67. package/out/commands/compile.js.map +0 -1
  68. package/out/platform-constants.js.map +0 -1
  69. package/out/platform.js.map +0 -1
  70. package/src/backend/backend-types.ts +0 -27
  71. package/src/backend/create-backend.ts +0 -8
  72. package/src/backend/direct-backend.ts +0 -169
  73. package/src/backend/reasoned-output.ts +0 -697
  74. package/src/commands/closure.ts +0 -624
  75. package/src/commands/compile.ts +0 -88
  76. /package/out/{platform-constants.d.ts → auth/constants.d.ts} +0 -0
  77. /package/src/{platform-constants.ts → auth/constants.ts} +0 -0
@@ -1,77 +1,90 @@
1
1
  // Copyright (c) 2026 Modelware. All rights reserved.
2
2
 
3
- import { createOmlServices } from '@oml/language';
4
3
  import chalk from 'chalk';
5
- import { NodeFileSystem } from 'langium/node';
6
- import { URI } from 'langium';
7
- import * as fs from 'node:fs/promises';
8
4
  import * as path from 'node:path';
9
- import { buildWorkspaceDocuments, collectWorkspaceOntologyEntries, normalizeFormatExtension, OntologyInconsistencyError, reasonWorkspaceOntologies } from '../backend/reasoned-output.js';
10
5
  import { failCli } from '../cli-error.js';
11
6
  import { formatDuration } from '../util.js';
12
- import { compileAction, resolveCompileOutputRoot, resolveCompileWorkspaceRoot } from './compile.js';
7
+ import { restPost } from './server/rest.js';
8
+ import { formatLintSummary, printLintDiagnostics, type LintPayload } from './lint.js';
13
9
 
14
10
  export type ReasonOptions = {
15
- workspace?: string,
16
- owl?: string,
17
- format?: string,
18
- clean?: boolean,
19
- pretty?: boolean,
20
11
  only?: boolean,
21
- checkOnly?: boolean,
22
- uniqueNamesAssumption?: boolean,
23
- explanations?: boolean,
24
- profile?: boolean
12
+ explanation?: boolean,
13
+ authToken?: string
25
14
  };
26
15
 
27
16
  export const reasonAction = async (opts: ReasonOptions): Promise<void> => {
28
- const workspaceRoot = resolveCompileWorkspaceRoot(opts.workspace);
29
- const outputRoot = resolveCompileOutputRoot(workspaceRoot, opts.owl);
30
- const format = normalizeFormatExtension(opts.format);
31
- if (opts.only && opts.clean) {
32
- failCli(chalk.red('Cannot combine --only with --clean for reason.'));
33
- }
17
+ const startedAt = Date.now();
18
+ const result = await restPost<{
19
+ success: boolean;
20
+ ontologiesReasoned: number;
21
+ elapsedMs?: number;
22
+ totalElapsedMs?: number;
23
+ inconsistent: Array<{ modelUri: string; validationWarnings: string[] }>;
24
+ failed: Array<{ modelUri: string; error: string }>;
25
+ validate?: {
26
+ success: boolean;
27
+ filesChecked: number;
28
+ errors: number;
29
+ warnings: number;
30
+ elapsedMs?: number;
31
+ lint?: LintPayload;
32
+ error?: string;
33
+ };
34
+ }>('/v0/reason', opts as unknown as Record<string, unknown>, opts.authToken);
34
35
 
35
- if (!opts.only) {
36
- await compileAction({
37
- workspace: workspaceRoot,
38
- owl: outputRoot,
39
- format,
40
- clean: opts.clean,
41
- pretty: opts.pretty
42
- });
36
+ if (result.validate?.lint) {
37
+ const lint = result.validate.lint;
38
+ if (lint.filesChecked <= 0) {
39
+ console.log(chalk.yellow('No .oml files found in server workspace.'));
40
+ } else {
41
+ printLintDiagnostics(lint);
42
+ const lintElapsedMs = typeof lint.elapsedMs === 'number' && Number.isFinite(lint.elapsedMs) && lint.elapsedMs >= 0
43
+ ? lint.elapsedMs
44
+ : Date.now() - startedAt;
45
+ const lintSummary = formatLintSummary(lint, lintElapsedMs);
46
+ if (lint.errors > 0) {
47
+ failCli(chalk.red(lintSummary));
48
+ }
49
+ if (lint.warnings > 0) {
50
+ failCli(chalk.yellow(lintSummary));
51
+ }
52
+ console.log(chalk.green(lintSummary));
53
+ }
43
54
  }
44
55
 
45
- const outputStat = await fs.stat(outputRoot).catch(() => undefined);
46
- if (!outputStat || !outputStat.isDirectory()) {
47
- failCli(chalk.red(`OWL output folder does not exist: ${outputRoot}`));
56
+ if (result.validate && result.validate.success) {
57
+ if (result.validate.filesChecked === 0) {
58
+ console.log(chalk.yellow('No markdown/table-editor targets found in server workspace.'));
59
+ } else {
60
+ const validateElapsedMs = typeof result.validate.elapsedMs === 'number'
61
+ && Number.isFinite(result.validate.elapsedMs)
62
+ && result.validate.elapsedMs >= 0
63
+ ? result.validate.elapsedMs
64
+ : Date.now() - startedAt;
65
+ console.log(chalk.green(`validate: ${result.validate.filesChecked} item(s) checked. [${formatDuration(validateElapsedMs)}]`));
66
+ }
48
67
  }
49
68
 
50
- const startedAt = Date.now();
51
- const servicesBundle = createOmlServices(NodeFileSystem);
52
- await servicesBundle.Oml.shared.workspace.WorkspaceManager.initializeWorkspace([
53
- { uri: URI.file(workspaceRoot).toString(), name: path.basename(workspaceRoot) }
54
- ]);
55
- const documents = await buildWorkspaceDocuments(servicesBundle.Oml, workspaceRoot, true);
56
- const entries = collectWorkspaceOntologyEntries(documents, outputRoot, format);
57
- let result;
58
- try {
59
- result = await reasonWorkspaceOntologies(entries, {
60
- outputRoot,
61
- format,
62
- pretty: opts.pretty ?? false,
63
- explanations: opts.explanations ?? true,
64
- uniqueNamesAssumption: opts.uniqueNamesAssumption ?? true,
65
- checkOnly: opts.checkOnly ?? false,
66
- profile: opts.profile ?? false,
67
- });
68
- } catch (error) {
69
- if (error instanceof OntologyInconsistencyError) {
70
- failCli(chalk.red(error.message));
69
+ if (!result.success) {
70
+ for (const item of result.failed) {
71
+ const modelUri = String(item.modelUri ?? '').trim();
72
+ console.log(chalk.red(`reason failed: ${modelUri || '<workspace>'}: ${item.error}`));
73
+ }
74
+ for (const item of result.inconsistent) {
75
+ const warnings = item.validationWarnings.length > 0 ? ` warnings=${item.validationWarnings.join('; ')}` : '';
76
+ console.log(chalk.red(`reason inconsistency detected: ${item.modelUri}.${warnings}`));
71
77
  }
72
- throw error;
78
+ failCli(chalk.red(result.validate?.error?.trim() || 'reason failed.'));
79
+ }
80
+
81
+ if (result.ontologiesReasoned === 0) {
82
+ console.log(chalk.yellow(`No .oml files found under ${path.resolve('.')}.`));
83
+ return;
73
84
  }
74
85
 
75
- const action = opts.checkOnly ? 'checked in' : 'generated in';
76
- console.log(chalk.green(`reason: ${result.ontologiesReasoned} ontology file(s) ${action} ${path.relative(process.cwd(), outputRoot) || outputRoot} [${formatDuration(Date.now() - startedAt)}]`));
86
+ const reasonElapsedMs = typeof result.elapsedMs === 'number' && Number.isFinite(result.elapsedMs) && result.elapsedMs >= 0
87
+ ? result.elapsedMs
88
+ : Date.now() - startedAt;
89
+ console.log(chalk.green(`reason: ${result.ontologiesReasoned} ontology file(s) checked [${formatDuration(reasonElapsedMs)}]`));
77
90
  };